Skip to content

Commit

Permalink
6X specific changes
Browse files Browse the repository at this point in the history
  • Loading branch information
KnightMurloc committed Sep 5, 2023
1 parent f262185 commit 92a9469
Show file tree
Hide file tree
Showing 16 changed files with 451 additions and 338 deletions.
42 changes: 32 additions & 10 deletions src/backend/executor/nodeDML.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,19 @@ ExecDML(DMLState *node)
{
return NULL;
}
EvalPlanQualSetSlot(&node->mt_epqstate, slot);

bool isnull = false;
int action = DatumGetUInt32(slot_getattr(slot, plannode->actionColIdx, &isnull));
Assert(!isnull);
int action = -1;
bool isUpdate = node->ps.state->es_plannedstmt->commandType == CMD_UPDATE;

bool isUpdate = false;
if (node->ps.state->es_plannedstmt->commandType == CMD_UPDATE)
// if it's not in place update
if(plannode->actionColIdx)
{
isUpdate = true;
action = DatumGetUInt32(slot_getattr(slot, plannode->actionColIdx, &isnull));
Assert(!isnull);
}

Assert(action == DML_INSERT || action == DML_DELETE);


/*
* Reset per-tuple memory context to free any expression evaluation
* storage allocated in the previous tuple cycle.
Expand Down Expand Up @@ -123,7 +122,7 @@ ExecDML(DMLState *node)
isUpdate,
InvalidOid);
}
else /* DML_DELETE */
else if(DML_DELETE == action)
{
int32 segid = GpIdentity.segindex;
Datum ctid = slot_getattr(slot, plannode->ctidColIdx, &isnull);
Expand Down Expand Up @@ -151,6 +150,26 @@ ExecDML(DMLState *node)
PLANGEN_OPTIMIZER /* Plan origin */,
isUpdate);
}
else /* in place update */
{
int32 segid = GpIdentity.segindex;

Datum ctid = slot_getattr(slot, plannode->ctidColIdx, &isnull);

ItemPointer tupleid = (ItemPointer) DatumGetPointer(ctid);
ItemPointerData tuple_ctid = *tupleid;
tupleid = &tuple_ctid;

ExecUpdate(
tupleid,
segid,
NULL, //oldtuple
node->cleanedUpSlot,
NULL, //planSlot
&node->mt_epqstate,
node->ps.state,
true);
}

return slot;
}
Expand Down Expand Up @@ -186,6 +205,8 @@ ExecInitDML(DML *node, EState *estate, int eflags)
Plan *outerPlan = outerPlan(node);
outerPlanState(dmlstate) = ExecInitNode(outerPlan, estate, eflags);

EvalPlanQualInit(&dmlstate->mt_epqstate, estate, outerPlan, NIL, 0);

/*
* ORCA Plan does not seem to set junk attribute for "gp_segment_id", else we
* could call the simple code below.
Expand Down Expand Up @@ -229,7 +250,7 @@ ExecInitDML(DML *node, EState *estate, int eflags)
dmlstate->junkfilter = ExecInitJunkFilter(node->plan.targetlist,
dmlstate->ps.state->es_result_relation_info->ri_RelationDesc->rd_att->tdhasoid,
dmlstate->cleanedUpSlot);

estate->es_result_relation_info->ri_junkFilter = dmlstate->junkfilter;
/*
* We don't maintain typmod in the targetlist, so we should fixup the
* junkfilter to use the same tuple descriptor as the result relation.
Expand Down Expand Up @@ -279,6 +300,7 @@ ExecEndDML(DMLState *node)
ExecFreeExprContext(&node->ps);
ExecClearTuple(node->ps.ps_ResultTupleSlot);
ExecClearTuple(node->cleanedUpSlot);
EvalPlanQualEnd(&node->mt_epqstate);
ExecEndNode(outerPlanState(node));
EndPlanStateGpmonPkt(&node->ps);
}
Expand Down
1 change: 0 additions & 1 deletion src/backend/gpopt/gpopt.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
override CPPFLAGS := -std=c++98 $(CPPFLAGS)
override CPPFLAGS := -I$(top_builddir)/src/backend/gporca/libgpos/include $(CPPFLAGS)
override CPPFLAGS := -I$(top_builddir)/src/backend/gporca/libgpopt/include $(CPPFLAGS)
override CPPFLAGS := -I$(top_builddir)/src/backend/gporca/libnaucrates/include $(CPPFLAGS)
Expand Down
25 changes: 18 additions & 7 deletions src/backend/gpopt/translate/CTranslatorDXLToPlStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4084,6 +4084,7 @@ CTranslatorDXLToPlStmt::TranslateDXLDml(
DML *dml = MakeNode(DML);
Plan *plan = &(dml->plan);
AclMode acl_mode = ACL_NO_RIGHTS;
BOOL isSplit = phy_dml_dxlop->FSplit();

switch (phy_dml_dxlop->GetDmlOpType())
{
Expand Down Expand Up @@ -4170,14 +4171,26 @@ CTranslatorDXLToPlStmt::TranslateDXLDml(
dml_target_list = target_list_with_dropped_cols;
}

// Extract column numbers of the action and ctid columns from the
// target list.
dml->actionColIdx = AddTargetEntryForColId(&dml_target_list, &child_context,
phy_dml_dxlop->ActionColId(),
true /*is_resjunk*/);

dml->ctidColIdx = AddTargetEntryForColId(&dml_target_list, &child_context,
phy_dml_dxlop->GetCtIdColId(),
true /*is_resjunk*/);

// Doesn't needed for in place update
if (isSplit || CMD_UPDATE != m_cmd_type)
{
// Extract column numbers of the action and ctid columns from the
// target list.
dml->actionColIdx = AddTargetEntryForColId(
&dml_target_list, &child_context, phy_dml_dxlop->ActionColId(),
true /*is_resjunk*/);
GPOS_ASSERT(0 != dml->actionColIdx);
}
else
{
dml->actionColIdx = 0;
}

if (phy_dml_dxlop->IsOidsPreserved())
{
dml->tupleoidColIdx = AddTargetEntryForColId(
Expand All @@ -4189,8 +4202,6 @@ CTranslatorDXLToPlStmt::TranslateDXLDml(
dml->tupleoidColIdx = 0;
}

GPOS_ASSERT(0 != dml->actionColIdx);

plan->targetlist = dml_target_list;

plan->lefttree = child_plan;
Expand Down
81 changes: 56 additions & 25 deletions src/backend/gporca/data/dxl/minidump/SelfUpdate.mdp
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,17 @@ update t1 set b = c;
</dxl:LogicalUpdate>
</dxl:Query>
<dxl:Plan Id="0" SpaceSize="1">
<dxl:DMLUpdate Columns="0,2,2" ActionCol="10" CtidCol="3" SegmentIdCol="9" IsSplitUpdate="false" PreserveOids="false">
<dxl:DMLUpdate Columns="0,1,2" ActionCol="10" CtidCol="3" SegmentIdCol="9" IsSplitUpdate="true">
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="431.023462" Rows="1.000000" Width="1"/>
<dxl:Cost StartupCost="0" TotalCost="431.067764" Rows="1.000000" Width="1"/>
</dxl:Properties>
<dxl:DirectDispatchInfo/>
<dxl:ProjList>
<dxl:ProjElem ColId="0" Alias="a">
<dxl:Ident ColId="0" ColName="a" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
<dxl:ProjElem ColId="2" Alias="c">
<dxl:Ident ColId="2" ColName="c" TypeMdid="0.23.1.0"/>
<dxl:ProjElem ColId="1" Alias="b">
<dxl:Ident ColId="1" ColName="b" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
<dxl:ProjElem ColId="2" Alias="c">
<dxl:Ident ColId="2" ColName="c" TypeMdid="0.23.1.0"/>
Expand All @@ -248,14 +248,14 @@ update t1 set b = c;
</dxl:TableDescriptor>
<dxl:Assert ErrorCode="23502">
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="431.000025" Rows="1.000000" Width="18"/>
<dxl:Cost StartupCost="0" TotalCost="431.000056" Rows="2.000000" Width="26"/>
</dxl:Properties>
<dxl:ProjList>
<dxl:ProjElem ColId="0" Alias="a">
<dxl:Ident ColId="0" ColName="a" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
<dxl:ProjElem ColId="2" Alias="c">
<dxl:Ident ColId="2" ColName="c" TypeMdid="0.23.1.0"/>
<dxl:ProjElem ColId="1" Alias="b">
<dxl:Ident ColId="1" ColName="b" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
<dxl:ProjElem ColId="2" Alias="c">
<dxl:Ident ColId="2" ColName="c" TypeMdid="0.23.1.0"/>
Expand All @@ -266,6 +266,9 @@ update t1 set b = c;
<dxl:ProjElem ColId="9" Alias="gp_segment_id">
<dxl:Ident ColId="9" ColName="gp_segment_id" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
<dxl:ProjElem ColId="10" Alias="ColRef_0010">
<dxl:Ident ColId="10" ColName="ColRef_0010" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
</dxl:ProjList>
<dxl:AssertConstraintList>
<dxl:AssertConstraint ErrorMessage="Not null constraint for column b of table t1 was violated">
Expand All @@ -276,14 +279,17 @@ update t1 set b = c;
</dxl:Not>
</dxl:AssertConstraint>
</dxl:AssertConstraintList>
<dxl:TableScan>
<dxl:Split DeleteColumns="0,1,2" InsertColumns="0,2,2" ActionCol="10" CtidCol="3" SegmentIdCol="9" PreserveOids="false">
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="431.000008" Rows="1.000000" Width="18"/>
<dxl:Cost StartupCost="0" TotalCost="431.000039" Rows="2.000000" Width="26"/>
</dxl:Properties>
<dxl:ProjList>
<dxl:ProjElem ColId="0" Alias="a">
<dxl:Ident ColId="0" ColName="a" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
<dxl:ProjElem ColId="1" Alias="b">
<dxl:Ident ColId="1" ColName="b" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
<dxl:ProjElem ColId="2" Alias="c">
<dxl:Ident ColId="2" ColName="c" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
Expand All @@ -293,23 +299,48 @@ update t1 set b = c;
<dxl:ProjElem ColId="9" Alias="gp_segment_id">
<dxl:Ident ColId="9" ColName="gp_segment_id" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
<dxl:ProjElem ColId="10" Alias="ColRef_0010">
<dxl:DMLAction/>
</dxl:ProjElem>
</dxl:ProjList>
<dxl:Filter/>
<dxl:TableDescriptor Mdid="6.47297780.1.1" TableName="t1">
<dxl:Columns>
<dxl:Column ColId="0" Attno="1" ColName="a" TypeMdid="0.23.1.0"/>
<dxl:Column ColId="1" Attno="2" ColName="b" TypeMdid="0.23.1.0"/>
<dxl:Column ColId="2" Attno="3" ColName="c" TypeMdid="0.23.1.0"/>
<dxl:Column ColId="3" Attno="-1" ColName="ctid" TypeMdid="0.27.1.0"/>
<dxl:Column ColId="4" Attno="-3" ColName="xmin" TypeMdid="0.28.1.0"/>
<dxl:Column ColId="5" Attno="-4" ColName="cmin" TypeMdid="0.29.1.0"/>
<dxl:Column ColId="6" Attno="-5" ColName="xmax" TypeMdid="0.28.1.0"/>
<dxl:Column ColId="7" Attno="-6" ColName="cmax" TypeMdid="0.29.1.0"/>
<dxl:Column ColId="8" Attno="-7" ColName="tableoid" TypeMdid="0.26.1.0"/>
<dxl:Column ColId="9" Attno="-8" ColName="gp_segment_id" TypeMdid="0.23.1.0"/>
</dxl:Columns>
</dxl:TableDescriptor>
</dxl:TableScan>
<dxl:TableScan>
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="431.000008" Rows="1.000000" Width="22"/>
</dxl:Properties>
<dxl:ProjList>
<dxl:ProjElem ColId="0" Alias="a">
<dxl:Ident ColId="0" ColName="a" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
<dxl:ProjElem ColId="1" Alias="b">
<dxl:Ident ColId="1" ColName="b" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
<dxl:ProjElem ColId="2" Alias="c">
<dxl:Ident ColId="2" ColName="c" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
<dxl:ProjElem ColId="3" Alias="ctid">
<dxl:Ident ColId="3" ColName="ctid" TypeMdid="0.27.1.0"/>
</dxl:ProjElem>
<dxl:ProjElem ColId="9" Alias="gp_segment_id">
<dxl:Ident ColId="9" ColName="gp_segment_id" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
</dxl:ProjList>
<dxl:Filter/>
<dxl:TableDescriptor Mdid="6.47297780.1.1" TableName="t1">
<dxl:Columns>
<dxl:Column ColId="0" Attno="1" ColName="a" TypeMdid="0.23.1.0"/>
<dxl:Column ColId="1" Attno="2" ColName="b" TypeMdid="0.23.1.0"/>
<dxl:Column ColId="2" Attno="3" ColName="c" TypeMdid="0.23.1.0"/>
<dxl:Column ColId="3" Attno="-1" ColName="ctid" TypeMdid="0.27.1.0"/>
<dxl:Column ColId="4" Attno="-3" ColName="xmin" TypeMdid="0.28.1.0"/>
<dxl:Column ColId="5" Attno="-4" ColName="cmin" TypeMdid="0.29.1.0"/>
<dxl:Column ColId="6" Attno="-5" ColName="xmax" TypeMdid="0.28.1.0"/>
<dxl:Column ColId="7" Attno="-6" ColName="cmax" TypeMdid="0.29.1.0"/>
<dxl:Column ColId="8" Attno="-7" ColName="tableoid" TypeMdid="0.26.1.0"/>
<dxl:Column ColId="9" Attno="-8" ColName="gp_segment_id" TypeMdid="0.23.1.0"/>
</dxl:Columns>
</dxl:TableDescriptor>
</dxl:TableScan>
</dxl:Split>
</dxl:Assert>
</dxl:DMLUpdate>
</dxl:Plan>
Expand Down
Loading

0 comments on commit 92a9469

Please sign in to comment.