Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: postgresql-cfbot/postgresql
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2a8a006
Choose a base ref
...
head repository: postgresql-cfbot/postgresql
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 81fcf23
Choose a head ref
  • 2 commits
  • 4 files changed
  • 2 contributors

Commits on Feb 15, 2025

  1. Fix an oversight in cbc1279 for MERGE handling

    ExecInitModifyTable() should also trim MERGE-related lists to exclude
    result relations pruned during initial pruning.
    
    Reported-by: Alexander Lakhin <exclusion@gmail.com> (via sqlsmith)
    Discussion: https://postgr.es/m/e72c94d9-e5f9-4753-9bc1-69d72bd54b8a@gmail.com
    amitlan authored and Commitfest Bot committed Feb 15, 2025
    Copy the full SHA
    33ad36e View commit details
  2. [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
    Commitfest Bot committed Feb 15, 2025
    Copy the full SHA
    81fcf23 View commit details
Showing with 72 additions and 6 deletions.
  1. +20 −4 src/backend/executor/nodeModifyTable.c
  2. +5 −2 src/include/nodes/execnodes.h
  3. +34 −0 src/test/regress/expected/partition_prune.out
  4. +13 −0 src/test/regress/sql/partition_prune.sql
24 changes: 20 additions & 4 deletions src/backend/executor/nodeModifyTable.c
Original file line number Diff line number Diff line change
@@ -3667,14 +3667,14 @@ ExecInitMerge(ModifyTableState *mtstate, EState *estate)
* anything here, do so there too.
*/
i = 0;
foreach(lc, node->mergeActionLists)
foreach(lc, mtstate->mt_mergeActionLists)
{
List *mergeActionList = lfirst(lc);
Node *joinCondition;
TupleDesc relationDesc;
ListCell *l;

joinCondition = (Node *) list_nth(node->mergeJoinConditions, i);
joinCondition = (Node *) list_nth(mtstate->mt_mergeJoinConditions, i);
resultRelInfo = mtstate->resultRelInfo + i;
i++;
relationDesc = RelationGetDescr(resultRelInfo->ri_RelationDesc);
@@ -4475,6 +4475,8 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
List *withCheckOptionLists = NIL;
List *returningLists = NIL;
List *updateColnosLists = NIL;
List *mergeActionLists = NIL;
List *mergeJoinConditions = NIL;
ResultRelInfo *resultRelInfo;
List *arowmarks;
ListCell *l;
@@ -4518,6 +4520,18 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)

updateColnosLists = lappend(updateColnosLists, updateColnosList);
}
if (node->mergeActionLists)
{
List *mergeActionList = list_nth(node->mergeActionLists, i);

mergeActionLists = lappend(mergeActionLists, mergeActionList);
}
if (node->mergeJoinConditions)
{
List *mergeJoinCondition = list_nth(node->mergeJoinConditions, i);

mergeJoinConditions = lappend(mergeJoinConditions, mergeJoinCondition);
}
}
i++;
}
@@ -4544,6 +4558,8 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
mtstate->mt_merge_updated = 0;
mtstate->mt_merge_deleted = 0;
mtstate->mt_updateColnosLists = updateColnosLists;
mtstate->mt_mergeActionLists = mergeActionLists;
mtstate->mt_mergeJoinConditions = mergeJoinConditions;

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

if (node->mergeActionLists)
mergeActions = list_nth(node->mergeActionLists, i);
if (mergeActionLists)
mergeActions = list_nth(mergeActionLists, i);

if (resultRelInfo != mtstate->rootResultRelInfo)
{
7 changes: 5 additions & 2 deletions src/include/nodes/execnodes.h
Original file line number Diff line number Diff line change
@@ -1448,10 +1448,13 @@ typedef struct ModifyTableState
double mt_merge_deleted;

/*
* List of valid updateColnosLists. Contains only those belonging to
* unpruned relations from ModifyTable.updateColnosLists.
* Lists of valid updateColnosListsm, mergeActionLists, and
* mergeJoinConditions. These contain only those belonging to unpruned
* relations from the respective Lists in the ModifyTable.
*/
List *mt_updateColnosLists;
List *mt_mergeActionLists;
List *mt_mergeJoinConditions;
} ModifyTableState;

/* ----------------
34 changes: 34 additions & 0 deletions src/test/regress/expected/partition_prune.out
Original file line number Diff line number Diff line change
@@ -4513,5 +4513,39 @@ execute update_part_abc_view (2, 'a');
ERROR: new row violates check option for view "part_abc_view"
DETAIL: Failing row contains (2, a, t).
deallocate update_part_abc_view;
-- Runtime pruning on MERGE using a stable function
create function stable_one() returns int as $$ begin return 1; end; $$ language plpgsql stable;
explain (costs off)
merge into part_abc_view pt
using (select stable_one() as pid) as q join part_abc_1 pt1 on (q.pid = pt1.a) on pt.a = pt1.a
when matched then delete returning pt.a;
QUERY PLAN
-----------------------------------------------------------------------
Merge on part_abc
Merge on part_abc_1
-> Nested Loop
-> Append
Subplans Removed: 1
-> Seq Scan on part_abc_1
Filter: ((b <> 'a'::text) AND (a = stable_one()))
-> Materialize
-> Seq Scan on part_abc_1 pt1
Filter: (a = stable_one())
(10 rows)

merge into part_abc_view pt
using (select stable_one() as pid) as q join part_abc_1 pt1 on (q.pid = pt1.a) on pt.a = pt1.a
when matched then delete returning pt.a;
a
---
1
(1 row)

table part_abc_view;
a | b | c
---+---+---
2 | c | t
(1 row)

drop view part_abc_view;
drop table part_abc;
13 changes: 13 additions & 0 deletions src/test/regress/sql/partition_prune.sql
Original file line number Diff line number Diff line change
@@ -1372,5 +1372,18 @@ execute update_part_abc_view (1, 'd');
explain (costs off) execute update_part_abc_view (2, 'a');
execute update_part_abc_view (2, 'a');
deallocate update_part_abc_view;

-- Runtime pruning on MERGE using a stable function
create function stable_one() returns int as $$ begin return 1; end; $$ language plpgsql stable;
explain (costs off)
merge into part_abc_view pt
using (select stable_one() as pid) as q join part_abc_1 pt1 on (q.pid = pt1.a) on pt.a = pt1.a
when matched then delete returning pt.a;

merge into part_abc_view pt
using (select stable_one() as pid) as q join part_abc_1 pt1 on (q.pid = pt1.a) on pt.a = pt1.a
when matched then delete returning pt.a;
table part_abc_view;

drop view part_abc_view;
drop table part_abc;