Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 81fcf23

Browse files
author
Commitfest Bot
committed
[CF 52/3478] AcquireExecutorLocks() and run-time pruning
This commit was automatically generated by a robot at cfbot.cputube.org. It is based on patches submitted to the PostgreSQL mailing lists and registered in the PostgreSQL Commitfest application. This branch will be overwritten each time a new patch version is posted to the email thread, and also periodically to check for bitrot caused by changes on the master branch. Commitfest entry: https://commitfest.postgresql.org/52/3478 Patch(es): https://www.postgresql.org/message-id/CA+HiwqG=gZZCmpR5VMnXYCm0JDxH3dOwiPngnMLCYTj1unWh0w@mail.gmail.com Author(s): Amit Langote
2 parents 2a8a006 + 33ad36e commit 81fcf23

File tree

4 files changed

+72
-6
lines changed

4 files changed

+72
-6
lines changed

src/backend/executor/nodeModifyTable.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3667,14 +3667,14 @@ ExecInitMerge(ModifyTableState *mtstate, EState *estate)
36673667
* anything here, do so there too.
36683668
*/
36693669
i = 0;
3670-
foreach(lc, node->mergeActionLists)
3670+
foreach(lc, mtstate->mt_mergeActionLists)
36713671
{
36723672
List *mergeActionList = lfirst(lc);
36733673
Node *joinCondition;
36743674
TupleDesc relationDesc;
36753675
ListCell *l;
36763676

3677-
joinCondition = (Node *) list_nth(node->mergeJoinConditions, i);
3677+
joinCondition = (Node *) list_nth(mtstate->mt_mergeJoinConditions, i);
36783678
resultRelInfo = mtstate->resultRelInfo + i;
36793679
i++;
36803680
relationDesc = RelationGetDescr(resultRelInfo->ri_RelationDesc);
@@ -4475,6 +4475,8 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
44754475
List *withCheckOptionLists = NIL;
44764476
List *returningLists = NIL;
44774477
List *updateColnosLists = NIL;
4478+
List *mergeActionLists = NIL;
4479+
List *mergeJoinConditions = NIL;
44784480
ResultRelInfo *resultRelInfo;
44794481
List *arowmarks;
44804482
ListCell *l;
@@ -4518,6 +4520,18 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
45184520

45194521
updateColnosLists = lappend(updateColnosLists, updateColnosList);
45204522
}
4523+
if (node->mergeActionLists)
4524+
{
4525+
List *mergeActionList = list_nth(node->mergeActionLists, i);
4526+
4527+
mergeActionLists = lappend(mergeActionLists, mergeActionList);
4528+
}
4529+
if (node->mergeJoinConditions)
4530+
{
4531+
List *mergeJoinCondition = list_nth(node->mergeJoinConditions, i);
4532+
4533+
mergeJoinConditions = lappend(mergeJoinConditions, mergeJoinCondition);
4534+
}
45214535
}
45224536
i++;
45234537
}
@@ -4544,6 +4558,8 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
45444558
mtstate->mt_merge_updated = 0;
45454559
mtstate->mt_merge_deleted = 0;
45464560
mtstate->mt_updateColnosLists = updateColnosLists;
4561+
mtstate->mt_mergeActionLists = mergeActionLists;
4562+
mtstate->mt_mergeJoinConditions = mergeJoinConditions;
45474563

45484564
/*----------
45494565
* Resolve the target relation. This is the same as:
@@ -4599,8 +4615,8 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
45994615
Index resultRelation = lfirst_int(l);
46004616
List *mergeActions = NIL;
46014617

4602-
if (node->mergeActionLists)
4603-
mergeActions = list_nth(node->mergeActionLists, i);
4618+
if (mergeActionLists)
4619+
mergeActions = list_nth(mergeActionLists, i);
46044620

46054621
if (resultRelInfo != mtstate->rootResultRelInfo)
46064622
{

src/include/nodes/execnodes.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,10 +1448,13 @@ typedef struct ModifyTableState
14481448
double mt_merge_deleted;
14491449

14501450
/*
1451-
* List of valid updateColnosLists. Contains only those belonging to
1452-
* unpruned relations from ModifyTable.updateColnosLists.
1451+
* Lists of valid updateColnosListsm, mergeActionLists, and
1452+
* mergeJoinConditions. These contain only those belonging to unpruned
1453+
* relations from the respective Lists in the ModifyTable.
14531454
*/
14541455
List *mt_updateColnosLists;
1456+
List *mt_mergeActionLists;
1457+
List *mt_mergeJoinConditions;
14551458
} ModifyTableState;
14561459

14571460
/* ----------------

src/test/regress/expected/partition_prune.out

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4513,5 +4513,39 @@ execute update_part_abc_view (2, 'a');
45134513
ERROR: new row violates check option for view "part_abc_view"
45144514
DETAIL: Failing row contains (2, a, t).
45154515
deallocate update_part_abc_view;
4516+
-- Runtime pruning on MERGE using a stable function
4517+
create function stable_one() returns int as $$ begin return 1; end; $$ language plpgsql stable;
4518+
explain (costs off)
4519+
merge into part_abc_view pt
4520+
using (select stable_one() as pid) as q join part_abc_1 pt1 on (q.pid = pt1.a) on pt.a = pt1.a
4521+
when matched then delete returning pt.a;
4522+
QUERY PLAN
4523+
-----------------------------------------------------------------------
4524+
Merge on part_abc
4525+
Merge on part_abc_1
4526+
-> Nested Loop
4527+
-> Append
4528+
Subplans Removed: 1
4529+
-> Seq Scan on part_abc_1
4530+
Filter: ((b <> 'a'::text) AND (a = stable_one()))
4531+
-> Materialize
4532+
-> Seq Scan on part_abc_1 pt1
4533+
Filter: (a = stable_one())
4534+
(10 rows)
4535+
4536+
merge into part_abc_view pt
4537+
using (select stable_one() as pid) as q join part_abc_1 pt1 on (q.pid = pt1.a) on pt.a = pt1.a
4538+
when matched then delete returning pt.a;
4539+
a
4540+
---
4541+
1
4542+
(1 row)
4543+
4544+
table part_abc_view;
4545+
a | b | c
4546+
---+---+---
4547+
2 | c | t
4548+
(1 row)
4549+
45164550
drop view part_abc_view;
45174551
drop table part_abc;

src/test/regress/sql/partition_prune.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,5 +1372,18 @@ execute update_part_abc_view (1, 'd');
13721372
explain (costs off) execute update_part_abc_view (2, 'a');
13731373
execute update_part_abc_view (2, 'a');
13741374
deallocate update_part_abc_view;
1375+
1376+
-- Runtime pruning on MERGE using a stable function
1377+
create function stable_one() returns int as $$ begin return 1; end; $$ language plpgsql stable;
1378+
explain (costs off)
1379+
merge into part_abc_view pt
1380+
using (select stable_one() as pid) as q join part_abc_1 pt1 on (q.pid = pt1.a) on pt.a = pt1.a
1381+
when matched then delete returning pt.a;
1382+
1383+
merge into part_abc_view pt
1384+
using (select stable_one() as pid) as q join part_abc_1 pt1 on (q.pid = pt1.a) on pt.a = pt1.a
1385+
when matched then delete returning pt.a;
1386+
table part_abc_view;
1387+
13751388
drop view part_abc_view;
13761389
drop table part_abc;

0 commit comments

Comments
 (0)