postgresql/src/backend
Michael Paquier f3b141c482 Fix relation leak for subscribers firing triggers in logical replication
Creating a trigger on a relation to which an apply operation is
triggered would cause a relation leak once the change gets committed,
as the executor would miss that the relation needs to be closed
beforehand.  This issue got introduced with the refactoring done in
1375422c, where it becomes necessary to track relations within
es_opened_result_relations to make sure that they are closed.

We have discussed using ExecInitResultRelation() coupled with
ExecCloseResultRelations() for the relations in need of tracking by the
apply operations in the subscribers, which would simplify greatly the
opening and closing of indexes, but this requires a larger rework and
reorganization of the worker code, particularly for the tuple routing
part.  And that's not really welcome post feature freeze.  So, for now,
settle down to the same solution as TRUNCATE which is to fill in
es_opened_result_relations with the relation opened, to make sure that
ExecGetTriggerResultRel() finds them and that they get closed.

The code is lightly refactored so as a relation is not registered three
times for each DML code path, making the whole a bit easier to follow.

Reported-by: Tang Haiying, Shi Yu, Hou Zhijie
Author: Amit Langote, Masahiko Sawada, Hou Zhijie
Reviewed-by: Amit Kapila, Michael Paquier
Discussion: https://postgr.es/m/OS0PR01MB611383FA0FE92EB9DE21946AFB769@OS0PR01MB6113.jpnprd01.prod.outlook.com
2021-04-22 12:48:54 +09:00
..
access Fix typo 2021-04-21 08:07:37 +02:00
bootstrap Split backend status and progress related functionality out of pgstat.c. 2021-04-03 11:42:52 -07:00
catalog Add DISTINCT to information schema usage views 2021-04-21 11:54:47 +02:00
commands Don't add a redundant constraint when detaching a partition 2021-04-21 18:12:05 -04:00
executor doc: Improve hyphenation consistency 2021-04-21 08:14:43 +02:00
foreign Update copyright for 2021 2021-01-02 13:06:25 -05:00
jit Speedup ScalarArrayOpExpr evaluation 2021-04-08 23:51:22 +12:00
lib Fix typo in comment 2021-04-20 14:35:16 +02:00
libpq Refactor hba_authname 2021-04-07 14:24:47 +02:00
main Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodes Improve slightly misleading comments in nodeFuncs.c 2021-04-10 19:19:45 +12:00
optimizer doc: Improve hyphenation consistency 2021-04-21 08:14:43 +02:00
parser adjust query id feature to use pg_stat_activity.query_id 2021-04-20 12:22:26 -04:00
partitioning Speedup ScalarArrayOpExpr evaluation 2021-04-08 23:51:22 +12:00
po Translation updates 2020-05-18 12:49:30 +02:00
port Use errmsg_internal for debug messages 2021-02-17 11:33:25 +01:00
postmaster Add comment about extract_autovac_opts not holding lock 2021-04-21 18:36:12 -04:00
regex Further tweak memory management for regex DFAs. 2021-03-08 16:32:29 -05:00
replication Fix relation leak for subscribers firing triggers in logical replication 2021-04-22 12:48:54 +09:00
rewrite doc: Improve hyphenation consistency 2021-04-21 08:14:43 +02:00
snowball Update snowball 2021-02-19 08:10:15 +01:00
statistics Fix typos and grammar in comments and docs 2021-04-19 11:32:30 +09:00
storage Fix typos and grammar in comments and docs 2021-04-19 11:32:30 +09:00
tcop adjust query id feature to use pg_stat_activity.query_id 2021-04-20 12:22:26 -04:00
tsearch Fix typos and grammar in comments and docs 2021-04-19 11:32:30 +09:00
utils Fix interaction of log_line_prefix's query_id and log_statement 2021-04-20 12:57:59 -04:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
Makefile Use sort_template.h for qsort_tuple() and qsort_ssup(). 2021-03-03 17:02:32 +13:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
nls.mk Add missing gettext triggers 2020-04-28 13:35:40 +02:00