Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ddHAY-0002kf-Rl for pgsql-bugs@arkaria.postgresql.org; Thu, 03 Aug 2017 14:32:11 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1ddHAY-0005pB-Ee for pgsql-bugs@arkaria.postgresql.org; Thu, 03 Aug 2017 14:32:10 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ddFMK-0004v6-J0 for pgsql-bugs@postgresql.org; Thu, 03 Aug 2017 12:36:12 +0000 Received: from mail-wm0-x229.google.com ([2a00:1450:400c:c09::229]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1ddFMH-0000P4-0A for pgsql-bugs@postgresql.org; Thu, 03 Aug 2017 12:36:10 +0000 Received: by mail-wm0-x229.google.com with SMTP id t201so14066326wmt.1 for ; Thu, 03 Aug 2017 05:36:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adspert.de; s=google; h=from:mime-version:subject:message-id:date:to; bh=nMuk1NIfPuNcC838f9hV6/kEXMzUPKcDjXdbK+pkPOw=; b=JV+5nlkslPtWfM9BAcCArH2nZMO7LYFjABqB6n+XfttbS+tgmpZBVZa6RJTWLpLgSJ XId3fLQ/MIzyfify4Q6cu0WMmyETcmDccbjajX3p5Od/e6o4w6SstFI+YA8M+TTFNJ8s wq0Lp4bzEwYKuxy19hxMYHkke/6VgrSYdJsd8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:message-id:date:to; bh=nMuk1NIfPuNcC838f9hV6/kEXMzUPKcDjXdbK+pkPOw=; b=jpIyGPLudgt/Q8a7MKv74O7OMxVVc/rGfdtaL2YWAlAfKUGpwDPlbEMQfjMYknb6kX hBuRUYU8i2HL6YWErwgp/KXRHwHozFwxBw3YU6us4pKuz5mTHVoEbu68HNbhyq16Sqah 9yRbLEzQ3icz9qPQIFCOPSkMGTP0two8JF978VjXzgpIJ+sc/9EPBx+KCzvuIoSUJo0k 80uUTLNqVchLyorDe6+0opGF33IrrFiz66r3T4fXxYNBKeDwm8iRxk0yEgWmraSAyENf +MpPWZZ2fbVr0Ha7wm86Qu8tTNDnSRA8zQnvUn+OO1OD0VG/Z2uaG9oii00zoELRy/Uw f4bw== X-Gm-Message-State: AIVw113yRMOtiNwbWtBD4tq7DS5jZMgPlgN/4ANT9mUF1VnPVVYBxU76 Pvhvx81s01RbMjlUJ/pQQg== X-Received: by 10.80.177.12 with SMTP id k12mr1718565edd.187.1501763766289; Thu, 03 Aug 2017 05:36:06 -0700 (PDT) Received: from [192.168.10.190] (ip5b405dcd.dynamic.kabel-deutschland.de. [91.64.93.205]) by smtp.gmail.com with ESMTPSA id w14sm918686eda.63.2017.08.03.05.35.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Aug 2017 05:35:58 -0700 (PDT) From: Krystian Szladewski Content-Type: multipart/alternative; boundary="Apple-Mail=_E0F766FA-0CA7-49D3-873E-60548556184D" Mime-Version: 1.0 (Mac OS X Mail 10.2 \(3259\)) Subject: "could not open relation with OID XXX" when using recreated index in sql function Message-Id: <4FF21730-A69B-4582-8D02-F3BE795677F3@adspert.de> Date: Thu, 3 Aug 2017 14:35:57 +0200 To: pgsql-bugs@postgresql.org X-Mailer: Apple Mail (2.3259) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --Apple-Mail=_E0F766FA-0CA7-49D3-873E-60548556184D Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi guys, I think I found a bug in sql (not plpgsql) functions.=20 This is the error I=E2=80=99m getting: ERROR: XX000: could not open relation with OID 13053550 CONTEXT: SQL function "fail" statement 3 LOCATION: relation_open, heapam.c:1130 It happens when I try to recreate an index and use it afterwards (both = within the function). My postgres version: PostgreSQL 9.6.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.2 = 20140120 (Red Hat 4.8.2-16), 64-bit Here is some sql to reproduce it: BEGIN; CREATE TABLE test_1 ( test_id BIGINT PRIMARY KEY, other_id BIGINT NOT NULL ); CREATE INDEX test_1_other_idx ON test_1(other_id); =E2=80=94 Make sure query planner uses the index scan SET enable_seqscan=3Doff; CREATE OR REPLACE FUNCTION fail() RETURNS bigint LANGUAGE sql AS $$ -- Re-create the index DROP INDEX IF EXISTS test_1_other_idx; CREATE INDEX test_1_other_idx ON test_1(other_id); -- Fail! SELECT test_id FROM test_1 WHERE other_id =3D 1000; $$; SELECT fail(); ROLLBACK; If you modify this function to use plpgsql, it won=E2=80=99t fail = anymore: CREATE OR REPLACE FUNCTION ok() RETURNS bigint LANGUAGE plpgsql AS $$ BEGIN -- Re-create the index DROP INDEX IF EXISTS test_1_other_idx; CREATE INDEX test_1_other_idx ON test_1(other_id); RETURN (SELECT test_id FROM test_1 WHERE other_id =3D 1); END $$; SELECT ok(); It also works fine when you paste contents of fail() function into psql = session. Best Regards, Krystian Szladewski --Apple-Mail=_E0F766FA-0CA7-49D3-873E-60548556184D Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Hi guys,

I = think I found a bug in sql (not plpgsql) functions. 
This is the error I=E2=80=99m getting:
ERROR:  XX000: = could not open relation with OID 13053550
CONTEXT: =  SQL function "fail" statement 3
LOCATION: =  relation_open, heapam.c:1130

It happens when I try to recreate an = index and use it afterwards (both within the function).

My postgres = version:
PostgreSQL 9.6.2 on = x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.2 20140120 (Red Hat = 4.8.2-16), 64-bit

Here is some sql to reproduce it:

BEGIN;

CREATE TABLE test_1 = (
    test_id     BIGINT = PRIMARY KEY,
    other_id   =  BIGINT NOT NULL
);
CREATE = INDEX test_1_other_idx ON test_1(other_id);

=E2=80=94 Make sure query planner uses = the index scan
SET enable_seqscan=3Doff;

CREATE OR REPLACE FUNCTION fail() RETURNS bigint
LANGUAGE sql AS
$$
    -- Re-create the index
    DROP INDEX IF EXISTS = test_1_other_idx;
    CREATE INDEX = test_1_other_idx ON test_1(other_id);

    -- Fail!
    SELECT test_id FROM test_1 WHERE other_id =3D = 1000;
$$;

SELECT fail();

ROLLBACK;


If you modify this function to use plpgsql, it won=E2=80=99t = fail anymore:

CREATE OR REPLACE FUNCTION ok() RETURNS = bigint
LANGUAGE plpgsql AS
$$
    BEGIN

    -- = Re-create the index
    DROP INDEX IF = EXISTS test_1_other_idx;
    CREATE INDEX = test_1_other_idx ON test_1(other_id);

    RETURN (SELECT test_id = FROM test_1 WHERE other_id =3D 1);

    END
$$;

SELECT ok();


It = also works fine when you paste contents of fail() function into psql = session.


Best Regards,
Krystian Szladewski


= --Apple-Mail=_E0F766FA-0CA7-49D3-873E-60548556184D--