postgresql/src/backend/commands
Alvaro Herrera 8aba932251
Fix relcache inconsistency hazard in partition detach
During queries coming from ri_triggers.c, we need to omit partitions
that are marked pending detach -- otherwise, the RI query is tricked
into allowing a row into the referencing table whose corresponding row
is in the detached partition.  Which is bogus: once the detach operation
completes, the row becomes an orphan.

However, the code was not doing that in repeatable-read transactions,
because relcache kept a copy of the partition descriptor that included
the partition, and used it in the RI query.  This commit changes the
partdesc cache code to only keep descriptors that aren't dependent on
a snapshot (namely: those where no detached partition exist, and those
where detached partitions are included).  When a partdesc-without-
detached-partitions is requested, we create one afresh each time; also,
those partdescs are stored in PortalContext instead of
CacheMemoryContext.

find_inheritance_children gets a new output *detached_exist boolean,
which indicates whether any partition marked pending-detach is found.
Its "include_detached" input flag is changed to "omit_detached", because
that name captures desired the semantics more naturally.
CreatePartitionDirectory() and RelationGetPartitionDesc() arguments are
identically renamed.

This was noticed because a buildfarm member that runs with relcache
clobbering, which would not keep the improperly cached partdesc, broke
one test, which led us to realize that the expected output of that test
was bogus.  This commit also corrects that expected output.

Author: Amit Langote <amitlangote09@gmail.com>
Author: Álvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://postgr.es/m/3269784.1617215412@sss.pgh.pa.us
2021-04-22 15:13:25 -04:00
..
aggregatecmds.c SQL-standard function body 2021-04-07 21:47:55 +02:00
alter.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
amcmds.c Fix some typos, grammar and style in docs and comments 2021-02-24 16:13:17 +09:00
analyze.c Fix typos and grammar in comments and docs 2021-04-19 11:32:30 +09:00
async.c Remove server and libpq support for old FE/BE protocol version 2. 2021-03-04 10:45:55 +02:00
cluster.c Fix typos and grammar in documentation and code comments 2021-04-09 13:53:07 +09:00
collationcmds.c Fix typo in collationcmds.c 2021-04-05 11:18:12 +09:00
comment.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
constraint.c Pass down "logically unchanged index" hint. 2021-01-13 08:11:00 -08:00
conversioncmds.c Add 'noError' argument to encoding conversion functions. 2021-04-01 11:45:22 +03:00
copy.c Rename Default Roles to Predefined Roles 2021-04-01 15:32:06 -04:00
copyfrom.c Fix typos and grammar in documentation and code comments 2021-04-09 13:53:07 +09:00
copyfromparse.c Do COPY FROM encoding conversion/verification in larger chunks. 2021-04-01 12:23:40 +03:00
copyto.c doc: Improve hyphenation consistency 2021-04-21 08:14:43 +02:00
createas.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
dbcommands.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
define.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
discard.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
dropcmds.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
event_trigger.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
explain.c Fix wrong units in two ExplainPropertyFloat calls. 2021-04-16 11:30:27 -04:00
extension.c Add mbverifystr() functions specific to each encoding. 2021-01-28 14:40:07 +02:00
foreigncmds.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
functioncmds.c doc: Improve hyphenation consistency 2021-04-21 08:14:43 +02:00
indexcmds.c Fix relcache inconsistency hazard in partition detach 2021-04-22 15:13:25 -04:00
lockcmds.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
Makefile Split copy.c into four files. 2020-11-23 10:50:50 +02:00
matview.c Enable parallelism in REFRESH MATERIALIZED VIEW. 2021-03-17 15:04:17 +13:00
opclasscmds.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
operatorcmds.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
policy.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
portalcmds.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
prepare.c Improve performance of repeated CALLs within plpgsql procedures. 2021-01-25 22:28:29 -05:00
proclang.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
publicationcmds.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
schemacmds.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
seclabel.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
sequence.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
statscmds.c Extended statistics on expressions 2021-03-27 00:01:11 +01:00
subscriptioncmds.c ALTER SUBSCRIPTION ... ADD/DROP PUBLICATION 2021-04-06 11:49:51 +02:00
tablecmds.c Fix relcache inconsistency hazard in partition detach 2021-04-22 15:13:25 -04:00
tablespace.c Prevent drop of tablespaces used by partitioned relations 2021-01-14 15:32:14 -03:00
trigger.c Fix relcache inconsistency hazard in partition detach 2021-04-22 15:13:25 -04:00
tsearchcmds.c Update copyright for 2021 2021-01-02 13:06:25 -05:00
typecmds.c SQL-standard function body 2021-04-07 21:47:55 +02:00
user.c Standardize pg_authid oid_symbol values. 2021-04-10 12:01:41 -07:00
vacuum.c Add wraparound failsafe to VACUUM. 2021-04-07 12:37:45 -07:00
variable.c Fix some inappropriately-disallowed uses of ALTER ROLE/DATABASE SET. 2021-04-13 15:10:18 -04:00
view.c Update copyright for 2021 2021-01-02 13:06:25 -05:00