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 31, 2024
1 parent 5ea65f1 commit 25f806d
Show file tree
Hide file tree
Showing 11 changed files with 390 additions and 258 deletions.
13 changes: 2 additions & 11 deletions src/backend/executor/nodeModifyTable.c
Original file line number Diff line number Diff line change
Expand Up @@ -2483,8 +2483,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 @@ -2515,8 +2514,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 @@ -2829,10 +2827,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 @@ -2895,9 +2889,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
48 changes: 24 additions & 24 deletions src/test/isolation2/expected/lockmodes_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -1041,12 +1041,12 @@ BEGIN
DELETE 10
-- on QD, there's a lock on the root and the target partition
1: select * from show_locks_lockmodes;
locktype | mode | granted | relation
----------+-----------------+---------+---------------------------------
relation | AccessShareLock | t | t_lockmods_part_tbl_dml_1_prt_2
relation | AccessShareLock | t | t_lockmods_part_tbl_dml_1_prt_1
relation | AccessShareLock | t | t_lockmods_part_tbl_dml
relation | ExclusiveLock | t | t_lockmods_part_tbl_dml
locktype | mode | granted | relation
----------+-----------------+---------+-------------------------------------
relation | ExclusiveLock | t | t_lockmods_part_tbl_upd_del_1_prt_1
relation | AccessShareLock | t | t_lockmods_part_tbl_upd_del
relation | ExclusiveLock | t | t_lockmods_part_tbl_upd_del
relation | ExclusiveLock | t | t_lockmods_part_tbl_upd_del_1_prt_2
(4 rows)
1: ROLLBACK;
ROLLBACK
Expand Down Expand Up @@ -1080,12 +1080,12 @@ BEGIN
UPDATE 1
-- on QD, there's a lock on the root and the target partition
1: select * from show_locks_lockmodes;
locktype | mode | granted | relation
----------+-----------------+---------+---------------------------------
relation | AccessShareLock | t | t_lockmods_part_tbl_dml_1_prt_2
relation | AccessShareLock | t | t_lockmods_part_tbl_dml_1_prt_1
relation | AccessShareLock | t | t_lockmods_part_tbl_dml
relation | ExclusiveLock | t | t_lockmods_part_tbl_dml
locktype | mode | granted | relation
----------+-----------------+---------+-------------------------------------
relation | ExclusiveLock | t | t_lockmods_part_tbl_upd_del_1_prt_1
relation | AccessShareLock | t | t_lockmods_part_tbl_upd_del
relation | ExclusiveLock | t | t_lockmods_part_tbl_upd_del
relation | ExclusiveLock | t | t_lockmods_part_tbl_upd_del_1_prt_2
(4 rows)
1: ROLLBACK;
ROLLBACK
Expand Down Expand Up @@ -2131,12 +2131,12 @@ BEGIN
DELETE 10
-- on QD, there's a lock on the root and the target partition
1: select * from show_locks_lockmodes;
locktype | mode | granted | relation
----------+------------------+---------+---------------------------------
relation | AccessShareLock | t | t_lockmods_part_tbl_dml_1_prt_2
relation | AccessShareLock | t | t_lockmods_part_tbl_dml_1_prt_1
relation | AccessShareLock | t | t_lockmods_part_tbl_dml
relation | RowExclusiveLock | t | t_lockmods_part_tbl_dml
locktype | mode | granted | relation
----------+------------------+---------+-------------------------------------
relation | RowExclusiveLock | t | t_lockmods_part_tbl_upd_del_1_prt_2
relation | RowExclusiveLock | t | t_lockmods_part_tbl_upd_del_1_prt_1
relation | AccessShareLock | t | t_lockmods_part_tbl_upd_del
relation | RowExclusiveLock | t | t_lockmods_part_tbl_upd_del
(4 rows)
1: ROLLBACK;
ROLLBACK
Expand All @@ -2148,12 +2148,12 @@ BEGIN
UPDATE 1
-- on QD, there's a lock on the root and the target partition
1: select * from show_locks_lockmodes;
locktype | mode | granted | relation
----------+------------------+---------+---------------------------------
relation | AccessShareLock | t | t_lockmods_part_tbl_dml_1_prt_2
relation | AccessShareLock | t | t_lockmods_part_tbl_dml_1_prt_1
relation | AccessShareLock | t | t_lockmods_part_tbl_dml
relation | RowExclusiveLock | t | t_lockmods_part_tbl_dml
locktype | mode | granted | relation
----------+------------------+---------+-------------------------------------
relation | RowExclusiveLock | t | t_lockmods_part_tbl_upd_del_1_prt_2
relation | RowExclusiveLock | t | t_lockmods_part_tbl_upd_del_1_prt_1
relation | AccessShareLock | t | t_lockmods_part_tbl_upd_del
relation | RowExclusiveLock | t | t_lockmods_part_tbl_upd_del
(4 rows)
1: ROLLBACK;
ROLLBACK
Expand Down
Loading

0 comments on commit 25f806d

Please sign in to comment.