]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix concurrent indexing operations with temporary tables
authorMichael Paquier <michael@paquier.xyz>
Wed, 22 Jan 2020 00:49:18 +0000 (09:49 +0900)
committerMichael Paquier <michael@paquier.xyz>
Wed, 22 Jan 2020 00:49:18 +0000 (09:49 +0900)
commita904abe2e284f570168839e52e18ef0b7f26179d
tree73d75ddca5398a2307754a6f0c4fa92f3c54f8c0
parent9b9c5f279e8261ab90dc64559911d2578288b7e9
Fix concurrent indexing operations with temporary tables

Attempting to use CREATE INDEX, DROP INDEX or REINDEX with CONCURRENTLY
on a temporary relation with ON COMMIT actions triggered unexpected
errors because those operations use multiple transactions internally to
complete their work.  Here is for example one confusing error when using
ON COMMIT DELETE ROWS:
ERROR:  index "foo" already contains data

Issues related to temporary relations and concurrent indexing are fixed
in this commit by enforcing the non-concurrent path to be taken for
temporary relations even if using CONCURRENTLY, transparently to the
user.  Using a non-concurrent path does not matter in practice as locks
cannot be taken on a temporary relation by a session different than the
one owning the relation, and the non-concurrent operation is more
effective.

The problem exists with REINDEX since v12 with the introduction of
CONCURRENTLY, and with CREATE/DROP INDEX since CONCURRENTLY exists for
those commands.  In all supported versions, this caused only confusing
error messages to be generated.  Note that with REINDEX, it was also
possible to issue a REINDEX CONCURRENTLY for a temporary relation owned
by a different session, leading to a server crash.

The idea to enforce transparently the non-concurrent code path for
temporary relations comes originally from Andres Freund.

Reported-by: Manuel Rigger
Author: Michael Paquier, Heikki Linnakangas
Reviewed-by: Andres Freund, Álvaro Herrera, Heikki Linnakangas
Discussion: https://postgr.es/m/CA+u7OA6gP7YAeCguyseusYcc=uR8+ypjCcgDDCTzjQ+k6S9ksQ@mail.gmail.com
Backpatch-through: 9.4
doc/src/sgml/ref/create_index.sgml
doc/src/sgml/ref/drop_index.sgml
doc/src/sgml/ref/reindex.sgml
src/backend/catalog/index.c
src/backend/commands/indexcmds.c
src/backend/commands/tablecmds.c
src/test/regress/expected/create_index.out
src/test/regress/sql/create_index.sql