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 1, 2023
1 parent f262185 commit a199223
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 43 deletions.
41 changes: 29 additions & 12 deletions src/backend/executor/nodeDML.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,15 @@ ExecDML(DMLState *node)
return NULL;
}

bool isnull = false;
int action = DatumGetUInt32(slot_getattr(slot, plannode->actionColIdx, &isnull));
Assert(!isnull);

bool isUpdate = false;
if (node->ps.state->es_plannedstmt->commandType == CMD_UPDATE)
{
isUpdate = true;
}

Assert(action == DML_INSERT || action == DML_DELETE);
bool isnull = false;
int action = -1;
bool isUpdate = node->ps.state->es_plannedstmt->commandType == CMD_UPDATE;

// if it's not in place update
if(plannode->actionColIdx){
action = DatumGetUInt32(slot_getattr(slot, plannode->actionColIdx, &isnull));
Assert(!isnull);
}

/*
* Reset per-tuple memory context to free any expression evaluation
Expand Down Expand Up @@ -123,7 +120,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 +148,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
NULL, //epqstate
node->ps.state,
true);
}

return slot;
}
Expand Down
23 changes: 16 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,24 @@ 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 +4200,6 @@ CTranslatorDXLToPlStmt::TranslateDXLDml(
dml->tupleoidColIdx = 0;
}

GPOS_ASSERT(0 != dml->actionColIdx);

plan->targetlist = dml_target_list;

plan->lefttree = child_plan;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3315,9 +3315,10 @@ CExpressionPreprocessor::ConvertSplitUpdateToInPlaceUpdate(CMemoryPool *mp,
{
CColRef *pcrInsert = (*pdrgpcrInsert)[ul];
CColRef *pcrDelete = (*pdrgpcrDelete)[ul];

// Checking if column is either distribution or partition key.
if (pcrInsert != pcrDelete &&
(pcrDelete->IsDistCol() || ppartColRefs->Find(pcrInsert) != NULL))
if ((pcrInsert != pcrDelete &&
pcrDelete->IsDistCol()) || (ppartColRefs->Find(pcrInsert) != NULL))
{
split_update = true;
break;
Expand Down
24 changes: 2 additions & 22 deletions src/backend/gporca/libgpopt/src/xforms/CXformUpdate2DML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,26 +151,6 @@ CXformUpdate2DML::Transform(CXformContext *pxfctxt, CXformResult *pxfres,
pexprAssertConstraints = pexprSplit;
}

// generate oid column and project operator
CExpression *pexprProject = NULL;
if (ptabdesc->IsPartitioned())
{
// generate a partition selector
pexprProject = CXformUtils::PexprLogicalPartitionSelector(
mp, ptabdesc, pdrgpcrInsert, pexprAssertConstraints);
}
else
{
// generate a project operator
IMDId *pmdidTable = ptabdesc->MDId();

OID oidTable = CMDIdGPDB::CastMdid(pmdidTable)->Oid();
CExpression *pexprOid = CUtils::PexprScalarConstOid(mp, oidTable);

pexprProject =
CUtils::PexprAddProjection(mp, pexprAssertConstraints, pexprOid);
}

const ULONG num_cols = pdrgpcrInsert->Size();

CExpression *pexprDML = NULL;
Expand Down Expand Up @@ -199,7 +179,7 @@ CXformUpdate2DML::Transform(CXformContext *pxfctxt, CXformResult *pxfres,
CLogicalDML(mp, CLogicalDML::EdmlUpdate, ptabdesc,
pdrgpcrDelete, pbsModified, pcrAction, pcrCtid,
pcrSegmentId, pcrTupleOid, fSplit),
pexprProject);
pexprAssertConstraints);
}
else
{
Expand All @@ -210,7 +190,7 @@ CXformUpdate2DML::Transform(CXformContext *pxfctxt, CXformResult *pxfres,
CLogicalDML(mp, CLogicalDML::EdmlUpdate, ptabdesc,
pdrgpcrInsert, GPOS_NEW(mp) CBitSet(mp), pcrAction,
pcrCtid, pcrSegmentId, NULL, fSplit),
pexprProject);
pexprAssertConstraints);
}

// TODO: - Oct 30, 2012; detect and handle AFTER triggers on update
Expand Down

0 comments on commit a199223

Please sign in to comment.