Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/backend/executor/nodeDML.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,20 @@ ExecInitDML(DML *node, EState *estate, int eflags)
*/
estate->es_result_relation_info = estate->es_result_relations;

/*
* Functions which are settings up the projection of child node
* use plan's targetlist to get types of modifying tuples. So
* set this field here and restore before end of initialization
*/
node->plan.targetlist = node->targetListProj;

CmdType operation = estate->es_plannedstmt->commandType;
ResultRelInfo *resultRelInfo = estate->es_result_relation_info;

ExecInitResultTupleSlot(estate, &dmlstate->ps);

dmlstate->ps.targetlist = (List *)
ExecInitExpr((Expr *) node->plan.targetlist,
ExecInitExpr((Expr *) node->targetListProj,
(PlanState *) dmlstate);

Plan *outerPlan = outerPlan(node);
Expand Down Expand Up @@ -261,6 +268,9 @@ ExecInitDML(DML *node, EState *estate, int eflags)
TupleTableSlot *childResultSlot = outerPlanState(dmlstate)->ps_ResultTupleSlot;
ExecAssignProjectionInfo(&dmlstate->ps, childResultSlot->tts_tupleDescriptor);

/* restore targetlist to emply list as DML node doesn't output */
node->plan.targetlist = NULL;

/*
* Initialize slot to insert/delete using output relation descriptor.
*/
Expand All @@ -271,7 +281,7 @@ ExecInitDML(DML *node, EState *estate, int eflags)
* the junk filter doesn't need to do anything special there about them
*/

dmlstate->junkfilter = ExecInitJunkFilter(node->plan.targetlist,
dmlstate->junkfilter = ExecInitJunkFilter(node->targetListProj,
dmlstate->ps.state->es_result_relation_info->ri_RelationDesc->rd_att->tdhasoid,
dmlstate->cleanedUpSlot);

Expand Down
2 changes: 1 addition & 1 deletion src/backend/gpopt/translate/CTranslatorDXLToPlStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4238,7 +4238,7 @@ CTranslatorDXLToPlStmt::TranslateDXLDml(

GPOS_ASSERT(0 != dml->actionColIdx);

plan->targetlist = dml_target_list;
dml->targetListProj = dml_target_list;

plan->lefttree = child_plan;
plan->nMotionNodes = child_plan->nMotionNodes;
Expand Down
1 change: 1 addition & 0 deletions src/backend/nodes/copyfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,7 @@ _copyDML(const DML *from)
COPY_SCALAR_FIELD(tupleoidColIdx);
COPY_SCALAR_FIELD(tableoidColIdx);
COPY_SCALAR_FIELD(canSetTag);
COPY_NODE_FIELD(targetListProj);

return newnode;
}
Expand Down
1 change: 1 addition & 0 deletions src/backend/nodes/outfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,7 @@ _outDML(StringInfo str, const DML *node)
WRITE_INT_FIELD(tupleoidColIdx);
WRITE_INT_FIELD(tableoidColIdx);
WRITE_BOOL_FIELD(canSetTag);
WRITE_NODE_FIELD(targetListProj);

_outPlanInfo(str, (Plan *) node);
}
Expand Down
1 change: 1 addition & 0 deletions src/backend/nodes/readfast.c
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,7 @@ _readDML(void)
READ_INT_FIELD(tupleoidColIdx);
READ_INT_FIELD(tableoidColIdx);
READ_BOOL_FIELD(canSetTag);
READ_NODE_FIELD(targetListProj);

readPlanInfo((Plan *)local_node);

Expand Down
1 change: 1 addition & 0 deletions src/include/nodes/plannodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,7 @@ typedef struct DML
AttrNumber tupleoidColIdx; /* index of tuple oid column into the target list */
AttrNumber tableoidColIdx; /* index of table oid column into the target list */
bool canSetTag; /* calculate processed tuples */
List *targetListProj; /* projection of target list of child node */
} DML;

/*
Expand Down
12 changes: 4 additions & 8 deletions src/test/regress/expected/partition_pruning_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -3492,15 +3492,14 @@ explain (verbose, costs off) delete from test_1_prt_extra where j = 2;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------
Delete
Output: "outer".ColRef_0009, test_1_prt_extra.ctid
-> Result
Output: test_1_prt_extra.ctid, test_1_prt_extra.gp_segment_id, 0
-> Seq Scan on partition_pruning.test_1_prt_extra
Output: test_1_prt_extra.ctid, test_1_prt_extra.gp_segment_id
Filter: (test_1_prt_extra.j = 2)
Optimizer: Pivotal Optimizer (GPORCA)
Settings: enable_bitmapscan=on, enable_hashjoin=off, enable_indexscan=on, enable_mergejoin=on, enable_seqscan=off
(9 rows)
(8 rows)

delete from test_1_prt_extra where j = 2;
-- Check that deletion performed correctly
Expand Down Expand Up @@ -3558,7 +3557,6 @@ HINT: For non-partitioned tables, run analyze <table_name>(<column_list>). For
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------
Delete
Output: "outer".ColRef_0025, test.ctid, test.tableoid
-> Result
Output: test.ctid, test.tableoid, test.gp_segment_id, 0
-> Hash Anti Join
Expand All @@ -3578,7 +3576,7 @@ HINT: For non-partitioned tables, run analyze <table_name>(<column_list>). For
Output: test_in_predicate.i, test_in_predicate.j
Optimizer: Pivotal Optimizer (GPORCA)
Settings: enable_bitmapscan=on, enable_hashjoin=off, enable_indexscan=on, enable_mergejoin=on, enable_seqscan=off
(21 rows)
(20 rows)

delete from test where not exists(
select 1 from test_in_predicate where test.i = test_in_predicate.i and test.j = test_in_predicate.j
Expand Down Expand Up @@ -3635,7 +3633,6 @@ explain (verbose, costs off) update test_1_prt_extra set k = 10 where j = 2;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------
Update
Output: test_1_prt_extra.i, test_1_prt_extra.j, test_1_prt_extra.k, (DMLAction), test_1_prt_extra.ctid
-> Split
Output: test_1_prt_extra.i, test_1_prt_extra.j, test_1_prt_extra.k, test_1_prt_extra.ctid, test_1_prt_extra.gp_segment_id, DMLAction
-> Result
Expand All @@ -3645,7 +3642,7 @@ explain (verbose, costs off) update test_1_prt_extra set k = 10 where j = 2;
Filter: (test_1_prt_extra.j = 2)
Optimizer: Pivotal Optimizer (GPORCA)
Settings: enable_bitmapscan=on, enable_hashjoin=off, enable_indexscan=on, enable_mergejoin=on, enable_seqscan=off
(11 rows)
(10 rows)

update test_1_prt_extra set k = 10 where j = 2;
-- Check that update performed correctly and tuple moved to correct partition
Expand Down Expand Up @@ -3704,7 +3701,6 @@ HINT: For non-partitioned tables, run analyze <table_name>(<column_list>). For
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------
Update
Output: test.i, test.j, test.k, (DMLAction), test.ctid, test.tableoid
-> Split
Output: test.i, test.j, test.k, test.ctid, test.tableoid, test.gp_segment_id, DMLAction
-> Result
Expand All @@ -3726,7 +3722,7 @@ HINT: For non-partitioned tables, run analyze <table_name>(<column_list>). For
Output: test_in_predicate.i, test_in_predicate.j
Optimizer: Pivotal Optimizer (GPORCA)
Settings: enable_bitmapscan=on, enable_hashjoin=off, enable_indexscan=on, enable_mergejoin=on, enable_seqscan=off
(23 rows)
(22 rows)

update test set k = 10 where not exists(
select 1 from test_in_predicate where test.i = test_in_predicate.i and test.j = test_in_predicate.j
Expand Down
3 changes: 1 addition & 2 deletions src/test/regress/expected/qp_dropped_cols_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -16572,7 +16572,6 @@ EXPLAIN (COSTS OFF, VERBOSE) UPDATE t_part SET c1 = 3;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------
Update
Output: t_part.c1, t_part.c2, t_part.c3, t_part.c4, (DMLAction), t_part.ctid, t_part.tableoid
-> Redistribute Motion 3:3 (slice1; segments: 3)
Output: t_part.c1, t_part.c2, t_part.c3, t_part.c4, t_part.ctid, t_part.tableoid, t_part.gp_segment_id, (DMLAction)
Hash Key: t_part.c1
Expand All @@ -16587,7 +16586,7 @@ EXPLAIN (COSTS OFF, VERBOSE) UPDATE t_part SET c1 = 3;
-> Dynamic Seq Scan on public.t_part (dynamic scan id: 1)
Output: t_part.c1, t_part.c2, t_part.c3, t_part.c4, t_part.ctid, t_part.tableoid, t_part.gp_segment_id
Optimizer: Pivotal Optimizer (GPORCA)
(16 rows)
(15 rows)

UPDATE t_part SET c1 = 3;
SELECT * FROM t_part_1_prt_p2;
Expand Down