postgresql/src/backend/commands
Michael Paquier a904abe2e2 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
2020-01-22 09:49:18 +09:00
..
aggregatecmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
alter.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
amcmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
analyze.c Report progress of ANALYZE commands 2020-01-15 11:14:39 -03:00
async.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
cluster.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
collationcmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
comment.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
constraint.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
conversioncmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
copy.c Fix problems with "read only query" checks, and refactor the code. 2020-01-16 12:11:31 -05:00
createas.c Make better use of ParseState in ProcessUtility 2020-01-04 13:12:41 +01:00
dbcommands.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
define.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
discard.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
dropcmds.c Revert "Forbid DROP SCHEMA on temporary namespaces" 2020-01-08 10:36:12 +09:00
event_trigger.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
explain.c Make better use of ParseState in ProcessUtility 2020-01-04 13:12:41 +01:00
extension.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
foreigncmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
functioncmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
indexcmds.c Fix concurrent indexing operations with temporary tables 2020-01-22 09:49:18 +09:00
lockcmds.c Fix problems with "read only query" checks, and refactor the code. 2020-01-16 12:11:31 -05:00
Makefile Split all OBJS style lines in makefiles into one-line-per-entry style. 2019-11-05 14:41:07 -08:00
matview.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
opclasscmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
operatorcmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
policy.c Make parser rely more heavily on the ParseNamespaceItem data structure. 2020-01-02 11:29:01 -05:00
portalcmds.c Make better use of ParseState in ProcessUtility 2020-01-04 13:12:41 +01:00
prepare.c Make better use of ParseState in ProcessUtility 2020-01-04 13:12:41 +01:00
proclang.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
publicationcmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
schemacmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
seclabel.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
sequence.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
statscmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
subscriptioncmds.c Make lsn argument of walrcv_create_slot() optional 2020-01-11 09:07:14 +01:00
tablecmds.c Fix concurrent indexing operations with temporary tables 2020-01-22 09:49:18 +09:00
tablespace.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
trigger.c Make parser rely more heavily on the ParseNamespaceItem data structure. 2020-01-02 11:29:01 -05:00
tsearchcmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
typecmds.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
user.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
vacuum.c Allow vacuum command to process indexes in parallel. 2020-01-20 07:57:49 +05:30
variable.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
view.c Restructure ALTER TABLE execution to fix assorted bugs. 2020-01-15 18:49:24 -05:00