pgsql: Disallow CREATE INDEX if table is already in use in current sess

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Disallow CREATE INDEX if table is already in use in current sess
Date: 2017-06-04 16:02:52
Message-ID: E1dHXzQ-0007a9-KG@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Disallow CREATE INDEX if table is already in use in current session.

If we allow this, whatever outer command has the table open will not know
about the new index and may fail to update it as needed, as shown in a
report from Laurenz Albe. We already had such a prohibition in place for
ALTER TABLE, but the CREATE INDEX syntax missed the check.

Fixing it requires an API change for DefineIndex(), which conceivably
would break third-party extensions if we were to back-patch it. Given
how long this problem has existed without being noticed, fixing it in
the back branches doesn't seem worth that risk.

Discussion: https://postgr.es/m/A737B7A37273E048B164557ADEF4A58B53A4DC9A@ntex2010i.host.magwien.gv.at

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/0d1885266630eee1de5c43af463fe2b921451932

Modified Files
--------------
src/backend/bootstrap/bootparse.y | 2 ++
src/backend/commands/indexcmds.c | 13 +++++++++++++
src/backend/commands/tablecmds.c | 1 +
src/backend/tcop/utility.c | 1 +
src/include/commands/defrem.h | 1 +
src/test/regress/expected/triggers.out | 29 +++++++++++++++++++++++++++++
src/test/regress/sql/triggers.sql | 31 +++++++++++++++++++++++++++++++
7 files changed, 78 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2017-06-04 17:34:15 pgsql: #ifdef out assorted unused GEQO code.
Previous Message Alvaro Herrera 2017-06-04 15:48:32 pgsql: Assorted translatable string fixes