From 23d9c0fd2b46c85804ab92383d3d0e32079d1aaa Mon Sep 17 00:00:00 2001 From: zhoujiaqi Date: Mon, 30 Dec 2024 11:21:29 +0800 Subject: [PATCH] ORCA dsisable the update and delete on partitioned tables 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. --- src/backend/executor/nodeModifyTable.c | 13 ++----------- .../gpopt/translate/CTranslatorQueryToDXL.cpp | 16 ++++++++++++++++ src/include/nodes/plannodes.h | 1 + 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c index bf61e61057e..2fcab31e275 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -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 @@ -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; } @@ -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 */ @@ -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, diff --git a/src/backend/gpopt/translate/CTranslatorQueryToDXL.cpp b/src/backend/gpopt/translate/CTranslatorQueryToDXL.cpp index 28e3679bcc9..c4dbd9dad70 100644 --- a/src/backend/gpopt/translate/CTranslatorQueryToDXL.cpp +++ b/src/backend/gpopt/translate/CTranslatorQueryToDXL.cpp @@ -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); @@ -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); diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h index e32cc365585..9afa2bec1b2 100644 --- a/src/include/nodes/plannodes.h +++ b/src/include/nodes/plannodes.h @@ -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;