Skip to content

Commit

Permalink
ORCA dsisable the update and delete on partitioned tables
Browse files Browse the repository at this point in the history
After CBDB merged with PG14, we need to provide additional
support for the case where the update/delete is a dynamic (any)
scan operator. This is because in `ExecModifyTable`, PG14 has
an assumption: the current `resultRelInfo` will not be a root
partition table.

The current commit disables the update/delete generated by ORCA
on the partition table, and this behavior will be supported in
subsequent changes.
  • Loading branch information
jiaqizho committed Dec 30, 2024
1 parent d5246de commit 23d9c0f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/backend/executor/nodeModifyTable.c
Original file line number Diff line number Diff line change
Expand Up @@ -2490,8 +2490,7 @@ ExecPrepareTupleRouting(ModifyTableState *mtstate,
* valid target for INSERTs. This is required since a partitioned table
* UPDATE to another partition becomes a DELETE+INSERT.
*/
if (partRelInfo)
partrel = ExecFindPartition(mtstate, targetRelInfo, proute, slot, estate);
partrel = ExecFindPartition(mtstate, targetRelInfo, proute, slot, estate);

/*
* If we're capturing transition tuples, we might need to convert from the
Expand Down Expand Up @@ -2522,8 +2521,7 @@ ExecPrepareTupleRouting(ModifyTableState *mtstate,
slot = execute_attr_map_slot(map->attrMap, slot, new_slot);
}

if (partRelInfo)
*partRelInfo = partrel;
*partRelInfo = partrel;
return slot;
}

Expand Down Expand Up @@ -2836,10 +2834,6 @@ ExecModifyTable(PlanState *pstate)
estate, node->canSetTag, false /* splitUpdate */);
break;
case CMD_UPDATE:
/* Prepare for tuple routing if needed. */
if (castNode(ModifyTable, node->ps.plan)->forceTupleRouting)
slot = ExecPrepareTupleRouting(node, estate, proute,
resultRelInfo, slot, NULL);
if (!AttributeNumberIsValid(action_attno))
{
/* normal non-split UPDATE */
Expand Down Expand Up @@ -2902,9 +2896,6 @@ ExecModifyTable(PlanState *pstate)
ereport(ERROR, (errmsg("unknown action = %d", action)));
break;
case CMD_DELETE:
if (castNode(ModifyTable, node->ps.plan)->forceTupleRouting)
planSlot = ExecPrepareTupleRouting(node, estate, proute,
resultRelInfo, slot, NULL);
slot = ExecDelete(node, resultRelInfo, tupleid, oldtuple,
planSlot, &node->mt_epqstate, estate,
segid,
Expand Down
16 changes: 16 additions & 0 deletions src/backend/gpopt/translate/CTranslatorQueryToDXL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,14 @@ CTranslatorQueryToDXL::TranslateDeleteQueryToDXL()
&m_context->m_has_distributed_tables);
const IMDRelation *md_rel = m_md_accessor->RetrieveRel(table_descr->MDId());

// CBDB_MERGE_FIXME: Support DML operations on partitioned tables
if (md_rel->IsPartitioned())
{
// GPDB_12_MERGE_FIXME: Support DML operations on partitioned tables
GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiQuery2DXLUnsupportedFeature,
GPOS_WSZ_LIT("DML(delete) on partitioned tables"));
}

// make note of the operator classes used in the distribution key
NoteDistributionPolicyOpclasses(rte);

Expand Down Expand Up @@ -1255,6 +1263,14 @@ CTranslatorQueryToDXL::TranslateUpdateQueryToDXL()
GPOS_WSZ_LIT("UPDATE with constraints"));
}

// CBDB_MERGE_FIXME: Support DML operations on partitioned tables
if (md_rel->IsPartitioned())
{
// GPDB_12_MERGE_FIXME: Support DML operations on partitioned tables
GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiQuery2DXLUnsupportedFeature,
GPOS_WSZ_LIT("DML(update) on partitioned tables"));
}

// make note of the operator classes used in the distribution key
NoteDistributionPolicyOpclasses(rte);

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 @@ -424,6 +424,7 @@ typedef struct ModifyTable
Node *onConflictWhere; /* WHERE for ON CONFLICT UPDATE */
Index exclRelRTI; /* RTI of the EXCLUDED pseudo relation */
List *exclRelTlist; /* tlist of the EXCLUDED pseudo relation */
/* CBDB_CHERRYPICK_FIXME: need enable it */
bool forceTupleRouting; /* dynamic scans require tuple routing */
} ModifyTable;

Expand Down

0 comments on commit 23d9c0f

Please sign in to comment.