From 871ea83951daf153374a094ed00e8964ee6c8172 Mon Sep 17 00:00:00 2001 From: hekewen <821200725@qq.com> Date: Thu, 9 Nov 2023 06:33:05 +0000 Subject: [PATCH 1/2] [Bug] refactor pdml Conflicts: src/backend/px_optimizer/libgpopt/include/gpopt/engine/CHint.h --- src/backend/executor/execUtils_px.c | 2 +- src/backend/px/dispatcher/px_conn.c | 22 +- src/backend/px/dispatcher/px_gang.c | 4 +- src/backend/px/dispatcher/px_gang_async.c | 2 +- src/backend/px/px_util.c | 54 ++--- .../libgpopt/include/gpopt/engine/CHint.h | 67 +----- .../libgpopt/src/operators/CPhysicalDML.cpp | 38 +--- .../src/parser/CParseHandlerHint.cpp | 10 +- .../px_optimizer_util/utils/COptTasks.cpp | 12 +- src/backend/utils/misc/guc_px.c | 22 -- src/include/px/px_conn.h | 4 +- src/include/px/px_util.h | 10 +- src/include/utils/guc.h | 2 - src/include/utils/px_unsync_guc_name.h | 2 - .../polar-px-dev/px_parallel_dml.out | 194 +++++++++--------- .../sql/polar-px-dev/px_parallel_dml.sql | 19 ++ .../sql/polar-px-dev/px_parallel_dml_base.sql | 4 +- 17 files changed, 161 insertions(+), 307 deletions(-) diff --git a/src/backend/executor/execUtils_px.c b/src/backend/executor/execUtils_px.c index 27376339ea9..8e3b1b4afee 100644 --- a/src/backend/executor/execUtils_px.c +++ b/src/backend/executor/execUtils_px.c @@ -221,7 +221,7 @@ FillSliceGangInfo(ExecSlice *slice, int numsegments, DirectDispatchInfo *dd) slice->segments = NIL; for(k = 0;k < numsegments; k++) - slice->segments = lappend_int(slice->segments,RW_SEGMENT); + slice->segments = lappend_int(slice->segments, k); break; case GANGTYPE_PRIMARY_READER: slice->planNumSegments = numsegments; diff --git a/src/backend/px/dispatcher/px_conn.c b/src/backend/px/dispatcher/px_conn.c index 942a18e88d9..e04a0db8ccc 100644 --- a/src/backend/px/dispatcher/px_conn.c +++ b/src/backend/px/dispatcher/px_conn.c @@ -99,10 +99,7 @@ pxconn_createWorkerDescriptor(struct PxNodeInfo *pxinfo, int identifier, pxWorkerDesc->identifier = identifier; pxWorkerDesc->logicalWorkerInfo.total_count = logicalTotalWorkers; /* POLAR px */ - if (MASTER_CONTENT_ID == logicalWorkerIdx && RW_COUNTER_START <= identifier) - pxWorkerDesc->logicalWorkerInfo.idx = (identifier % RW_COUNTER_START) % logicalTotalWorkers; - else - pxWorkerDesc->logicalWorkerInfo.idx = logicalWorkerIdx; + pxWorkerDesc->logicalWorkerInfo.idx = logicalWorkerIdx; /* POLAR end */ MemoryContextSwitchTo(oldContext); @@ -118,10 +115,7 @@ pxconn_termWorkerDescriptor(PxWorkerDescriptor *pxWorkerDesc) px_nodes = pxWorkerDesc->pxNodeInfo->px_nodes; /* put px identifier to free list for reuse */ - if (RW_COUNTER_START > pxWorkerDesc->identifier) - { - px_nodes->freeCounterList = lappend_int(px_nodes->freeCounterList, pxWorkerDesc->identifier); - } + px_nodes->freeCounterList = lappend_int(px_nodes->freeCounterList, pxWorkerDesc->identifier); pxconn_disconnect(pxWorkerDesc); @@ -139,7 +133,8 @@ pxconn_termWorkerDescriptor(PxWorkerDescriptor *pxWorkerDesc) void pxconn_doConnectStart(PxWorkerDescriptor *pxWorkerDesc, const char *pxid, - const char *options) + const char *options, + SegmentType segmentType) { #define MAX_KEYWORDS 10 #define MAX_INT_STRING_LEN 20 @@ -148,6 +143,7 @@ pxconn_doConnectStart(PxWorkerDescriptor *pxWorkerDesc, const char *values[MAX_KEYWORDS]; char portstr[MAX_INT_STRING_LEN]; int nkeywords = 0; + bool should_be_localhost = false; keywords[nkeywords] = "pxid"; values[nkeywords] = pxid; @@ -170,10 +166,10 @@ pxconn_doConnectStart(PxWorkerDescriptor *pxWorkerDesc, * * For other PX connections, we set "hostaddr". "host" is not used. */ - if ((px_role == PX_ROLE_QC && - (pxWorkerDesc->logicalWorkerInfo.idx == MASTER_CONTENT_ID || - pxWorkerDesc->identifier >= RW_COUNTER_START)) || - FAULT_COND(SIMPLE_FAULT_INJECTOR("hostaddr_info") == FaultInjectorTypeEnable)) + /* When EntryDB or pdml, hostaddr should be localhost(127.0.0.1) */ + should_be_localhost = (pxWorkerDesc->logicalWorkerInfo.idx == MASTER_CONTENT_ID) + || (segmentType == SEGMENTTYPE_EXPLICT_WRITER); + if (px_role == PX_ROLE_QC && should_be_localhost) { keywords[nkeywords] = "hostaddr"; values[nkeywords] = "127.0.0.1"; diff --git a/src/backend/px/dispatcher/px_gang.c b/src/backend/px/dispatcher/px_gang.c index fcbbb4dc34f..f1a99e6d8d8 100644 --- a/src/backend/px/dispatcher/px_gang.c +++ b/src/backend/px/dispatcher/px_gang.c @@ -354,7 +354,7 @@ makeOptions(void) Assert(px_role == PX_ROLE_QC); - qdinfo = pxnode_getPxNodeInfo(MASTER_CONTENT_ID); + qdinfo = pxnode_getPxNodeInfo(MASTER_CONTENT_ID, SEGMENTTYPE_ANY); appendStringInfo(&string, " -c polar_px_qc_hostname=%s", qdinfo->config->hostip); appendStringInfo(&string, " -c polar_px_qc_port=%d", qdinfo->config->port); @@ -639,7 +639,7 @@ getPxProcessesForQC(int isPrimary) elog(FATAL, "getPxProcessesForQC: unsupported request for master mirror process"); } - qdinfo = pxnode_getPxNodeInfo(MASTER_CONTENT_ID); + qdinfo = pxnode_getPxNodeInfo(MASTER_CONTENT_ID, SEGMENTTYPE_ANY); Assert(qdinfo->config->node_idx == -1); Assert(qdinfo->config->hostip != NULL); diff --git a/src/backend/px/dispatcher/px_gang_async.c b/src/backend/px/dispatcher/px_gang_async.c index ff593c6ef57..89e380244b4 100644 --- a/src/backend/px/dispatcher/px_gang_async.c +++ b/src/backend/px/dispatcher/px_gang_async.c @@ -138,7 +138,7 @@ pxgang_createGang_async(List *segments, SegmentType segmentType) options = makeOptions(); /* start connection in asynchronous way */ - pxconn_doConnectStart(pxWorkerDesc, pxid, options); + pxconn_doConnectStart(pxWorkerDesc, pxid, options, segmentType); if (pxconn_isBadConnection(pxWorkerDesc)) ereport(ERROR, (errcode(ERRCODE_PX_INTERCONNECTION_ERROR), diff --git a/src/backend/px/px_util.c b/src/backend/px/px_util.c index ce92e68bbaa..a0fd1e96f1b 100644 --- a/src/backend/px/px_util.c +++ b/src/backend/px/px_util.c @@ -72,7 +72,7 @@ static int px_node_configs_generation = POLAR_CLUSTER_INFO_INVALID_GENERATION static MemoryContext px_worker_context = NULL; static PxNodeConfigEntry *px_node_configs = NULL; -static int nextPXIdentifer(PxNodes *px_nodes, bool isRW); +static int nextPXIdentifer(PxNodes *px_nodes); static void GeneratePxNodeConfigs(void); /* NB: all extern function should switch to this context */ @@ -249,7 +249,7 @@ GeneratePxNodeConfigs(void) qc_config->node_idx = -1; qc_config->dop = 1; qc_config->port = PostPortNumber; - qc_config->hostip = "127.0.0.1"; + qc_config->hostip = ""; px_node_configs = configs; px_node_configs_size = idx; @@ -305,7 +305,6 @@ pxnode_getPxNodes() px_nodes->numActivePXs = 0; px_nodes->numIdlePXs = 0; px_nodes->pxCounter = 0; - px_nodes->rwCounter = RW_COUNTER_START; px_nodes->freeCounterList = NIL; px_nodes->pxInfo = @@ -368,10 +367,10 @@ pxnode_allocateIdlePX(int logicalWorkerIdx, int logicalTotalWorkers, SegmentType if (logicalWorkerIdx == -1) { - pxinfo = pxnode_getPxNodeInfo(-1); + pxinfo = pxnode_getPxNodeInfo(-1, segmentType); logicalTotalWorkers = getPxWorkerCount(); } else - pxinfo = pxnode_getPxNodeInfo(logicalWorkerIdx); + pxinfo = pxnode_getPxNodeInfo(logicalWorkerIdx, segmentType); if (pxinfo == NULL) { @@ -414,21 +413,10 @@ pxnode_allocateIdlePX(int logicalWorkerIdx, int logicalTotalWorkers, SegmentType /* POLAR px */ if (!pxWorkerDesc) { - if (RW_SEGMENT == logicalWorkerIdx) - { - /* RW */ - pxWorkerDesc = pxconn_createWorkerDescriptor(pxinfo, - nextPXIdentifer(pxinfo->px_nodes, true), - MASTER_CONTENT_ID, - logicalTotalWorkers); - } - else - { - pxWorkerDesc = pxconn_createWorkerDescriptor(pxinfo, - nextPXIdentifer(pxinfo->px_nodes, false), - logicalWorkerIdx, - logicalTotalWorkers); - } + pxWorkerDesc = pxconn_createWorkerDescriptor(pxinfo, + nextPXIdentifer(pxinfo->px_nodes), + logicalWorkerIdx, + logicalTotalWorkers); } /* POLAR end */ @@ -504,33 +492,25 @@ pxnode_recycleIdlePX(PxWorkerDescriptor *pxWorkerDesc, bool forceDestroy) } static int -nextPXIdentifer(PxNodes *px_nodes, bool isRW) +nextPXIdentifer(PxNodes *px_nodes) { int result; - if (isRW) - { - return px_nodes->rwCounter++; - } - else - { - if (!px_nodes->freeCounterList) - { - result = px_nodes->pxCounter; - px_nodes->pxCounter = (px_nodes->pxCounter + 1) % RW_COUNTER_START; - return result; - } - result = linitial_int(px_nodes->freeCounterList); - px_nodes->freeCounterList = list_delete_first(px_nodes->freeCounterList); + if (!px_nodes->freeCounterList) + { + result = px_nodes->pxCounter++; return result; } + result = linitial_int(px_nodes->freeCounterList); + px_nodes->freeCounterList = list_delete_first(px_nodes->freeCounterList); + return result; } /* * Find PxNodeInfo in the array by segment index. */ PxNodeInfo * -pxnode_getPxNodeInfo(int contentId) +pxnode_getPxNodeInfo(int contentId, SegmentType segmentType) { PxNodeInfo *pxInfo = NULL; PxNodes *px_nodes; @@ -546,7 +526,7 @@ pxnode_getPxNodeInfo(int contentId) * Because the IP and Port of the RW and QC nodes are exactly the same * , qcInfo can be used directly. */ - if (RW_SEGMENT == contentId) + if (SEGMENTTYPE_EXPLICT_WRITER == segmentType) return px_nodes->qcInfo; if (contentId < 0) diff --git a/src/backend/px_optimizer/libgpopt/include/gpopt/engine/CHint.h b/src/backend/px_optimizer/libgpopt/include/gpopt/engine/CHint.h index fba8e60053c..37ce4aa891b 100644 --- a/src/backend/px_optimizer/libgpopt/include/gpopt/engine/CHint.h +++ b/src/backend/px_optimizer/libgpopt/include/gpopt/engine/CHint.h @@ -22,9 +22,6 @@ /* POLAR px */ #define MAX_INSERT_DOP_NUM ULONG(128) -#define MAX_UPDATE_DOP_NUM ULONG(128) -#define MAX_SELECT_DOP_NUM ULONG(128) -#define MAX_DELETE_DOP_NUM ULONG(128) /* POLAR px */ namespace gpopt @@ -59,17 +56,6 @@ class CHint : public CRefCount /* POLAR px */ ULONG m_ulInsertDopNum; - ULONG m_ulUpdateDopNum; - - ULONG m_ulSelectDopNum; - - ULONG m_ulDeleteDopNum; - - BOOL m_fRemoveUpdateRedundantMotion; - - BOOL m_fRemoveDeleteRedundantMotion; - /* POLAR px */ - public: CHint(const CHint &) = delete; @@ -80,12 +66,7 @@ class CHint : public CRefCount ULONG broadcast_threshold, BOOL enforce_constraint_on_dml, ULONG push_group_by_below_setop_threshold, /* POLAR px */ - ULONG insert_dop_num, - ULONG update_dop_num, - ULONG select_dop_num, - ULONG delete_dop_num, - BOOL remove_update_redundant_motion, - BOOL remove_delete_redundant_motion) + ULONG insert_dop_num) : m_ulMinNumOfPartsToRequireSortOnInsert( min_num_of_parts_to_require_sort_on_insert), m_ulJoinArityForAssociativityCommutativity( @@ -97,12 +78,7 @@ class CHint : public CRefCount m_ulPushGroupByBelowSetopThreshold( push_group_by_below_setop_threshold), /* POLAR px */ - m_ulInsertDopNum(insert_dop_num), - m_ulUpdateDopNum(update_dop_num), - m_ulSelectDopNum(select_dop_num), - m_ulDeleteDopNum(delete_dop_num), - m_fRemoveUpdateRedundantMotion(remove_update_redundant_motion), - m_fRemoveDeleteRedundantMotion(remove_delete_redundant_motion) + m_ulInsertDopNum(insert_dop_num) { } @@ -175,37 +151,6 @@ class CHint : public CRefCount return m_ulInsertDopNum; } - ULONG - UlUpdateDopNum() const - { - return m_ulUpdateDopNum; - } - - ULONG - UlSelectDopNum() const - { - return m_ulSelectDopNum; - } - - ULONG - UlDeleteDopNum() const - { - return m_ulDeleteDopNum; - } - - BOOL - FRemoveUpdateRedundantMotion() const - { - return m_fRemoveUpdateRedundantMotion; - } - - BOOL - FRemoveDeleteRedundantMotion() const - { - return m_fRemoveDeleteRedundantMotion; - } - /* POLAR px */ - // generate default hint configurations, which disables sort during insert on // append only row-oriented partitioned tables by default static CHint * @@ -220,13 +165,7 @@ class CHint : public CRefCount true, /* enforce_constraint_on_dml */ PUSH_GROUP_BY_BELOW_SETOP_THRESHOLD, /* push_group_by_below_setop_threshold */ /* POLAR px */ - MAX_INSERT_DOP_NUM, - MAX_UPDATE_DOP_NUM, - MAX_SELECT_DOP_NUM, - MAX_DELETE_DOP_NUM, - true, - true - /* POLAR px */ + MAX_INSERT_DOP_NUM ); } diff --git a/src/backend/px_optimizer/libgpopt/src/operators/CPhysicalDML.cpp b/src/backend/px_optimizer/libgpopt/src/operators/CPhysicalDML.cpp index bf2c69ef513..68d08bc673e 100644 --- a/src/backend/px_optimizer/libgpopt/src/operators/CPhysicalDML.cpp +++ b/src/backend/px_optimizer/libgpopt/src/operators/CPhysicalDML.cpp @@ -284,42 +284,10 @@ CPhysicalDML::PdsRequired(CMemoryPool *mp, else return GPOS_NEW(mp) CDistributionSpecStrictRandom(); } - else if (CLogicalDML::EdmlUpdate == m_edmlop) + // Update and Delete + else if(CLogicalDML::EdmlUpdate == m_edmlop || CLogicalDML::EdmlDelete == m_edmlop) { - bool remove_redundant_motion = optimizer_config->GetHint()->FRemoveUpdateRedundantMotion(); - ULONG update_dop_num = optimizer_config->GetHint()->UlUpdateDopNum(); - ULONG select_dop_num = optimizer_config->GetHint()->UlSelectDopNum(); - if (!remove_redundant_motion) - return GPOS_NEW(mp) CDistributionSpecStrictRandom(); - else - { - if (update_dop_num == select_dop_num) - { - m_pds->AddRef(); - return m_pds; - } - else - return GPOS_NEW(mp) CDistributionSpecStrictRandom(); - } - } - else if (CLogicalDML::EdmlDelete == m_edmlop) - { - /* delete */ - bool remove_redundant_motion = optimizer_config->GetHint()->FRemoveDeleteRedundantMotion(); - ULONG delete_dop_num = optimizer_config->GetHint()->UlDeleteDopNum(); - ULONG select_dop_num = optimizer_config->GetHint()->UlSelectDopNum(); - if (!remove_redundant_motion) - return GPOS_NEW(mp) CDistributionSpecStrictRandom(); - else - { - if (delete_dop_num == select_dop_num) - { - m_pds->AddRef(); - return m_pds; - } - else - return GPOS_NEW(mp) CDistributionSpecStrictRandom(); - } + return GPOS_NEW(mp) CDistributionSpecStrictRandom(); } else { diff --git a/src/backend/px_optimizer/libnaucrates/src/parser/CParseHandlerHint.cpp b/src/backend/px_optimizer/libnaucrates/src/parser/CParseHandlerHint.cpp index 80d696dec0c..1b786234b81 100644 --- a/src/backend/px_optimizer/libnaucrates/src/parser/CParseHandlerHint.cpp +++ b/src/backend/px_optimizer/libnaucrates/src/parser/CParseHandlerHint.cpp @@ -24,9 +24,6 @@ using namespace gpopt; /* POLAR px */ #define DEFAULT_INSERT_DOP_NUM ULONG(1) -#define DEFAULT_UPDATE_DOP_NUM ULONG(1) -#define DEFAULT_SELECT_DOP_NUM ULONG(1) -#define DEFAULT_DELETE_DOP_NUM ULONG(1) /* POLAR px */ XERCES_CPP_NAMESPACE_USE @@ -125,12 +122,7 @@ CParseHandlerHint::StartElement(const XMLCh *const, //element_uri, join_order_dp_threshold, broadcast_threshold, enforce_constraint_on_dml, push_group_by_below_setop_threshold, /* POLAR px */ - DEFAULT_INSERT_DOP_NUM, - DEFAULT_UPDATE_DOP_NUM, - DEFAULT_SELECT_DOP_NUM, - DEFAULT_DELETE_DOP_NUM, - true, - true); + DEFAULT_INSERT_DOP_NUM); } //--------------------------------------------------------------------------- diff --git a/src/backend/px_optimizer_util/utils/COptTasks.cpp b/src/backend/px_optimizer_util/utils/COptTasks.cpp index 0e709065e68..0955c2f9510 100644 --- a/src/backend/px_optimizer_util/utils/COptTasks.cpp +++ b/src/backend/px_optimizer_util/utils/COptTasks.cpp @@ -445,11 +445,6 @@ COptTasks::CreateOptimizerConfig ULONG push_group_by_below_setop_threshold = (ULONG) px_optimizer_push_group_by_below_setop_threshold; /* POLAR px */ ULONG insert_dop_num = (ULONG) local_px_insert_dop_num; - ULONG update_dop_num = (ULONG) px_update_dop_num; - ULONG select_dop_num = (ULONG) getPxWorkerCount(); - ULONG delete_dop_num = (ULONG) px_delete_dop_num; - BOOL remove_update_redundant_motion = px_enable_remove_update_redundant_motion; - BOOL remove_delete_redundant_motion = px_enable_remove_delete_redundant_motion; /* POLAR end */ return GPOS_NEW(mp) COptimizerConfig @@ -469,12 +464,7 @@ COptTasks::CreateOptimizerConfig * enforce them ourselves in the executor */ push_group_by_below_setop_threshold, /* POLAR px */ - insert_dop_num, - update_dop_num, - select_dop_num, - delete_dop_num, - remove_update_redundant_motion, - remove_delete_redundant_motion + insert_dop_num /* POLAR end */ ), GPOS_NEW(mp) CWindowOids(OID(F_WINDOW_ROW_NUMBER), OID(F_WINDOW_RANK)) diff --git a/src/backend/utils/misc/guc_px.c b/src/backend/utils/misc/guc_px.c index 0682c95b003..e77a58e063e 100644 --- a/src/backend/utils/misc/guc_px.c +++ b/src/backend/utils/misc/guc_px.c @@ -109,10 +109,8 @@ bool px_enable_insert_from_tableless; bool px_enable_insert_order_sensitive; bool px_enable_update; int px_update_dop_num; -bool px_enable_remove_update_redundant_motion; bool px_enable_delete; int px_delete_dop_num; -bool px_enable_remove_delete_redundant_motion; bool px_optimizer_remove_superfluous_order; @@ -1946,16 +1944,6 @@ struct config_bool ConfigureNamesBool_px[] = false, NULL, NULL, NULL }, - { - {"polar_px_enable_remove_update_redundant_motion", PGC_USERSET, UNGROUPED, - gettext_noop("This guc remove update redundant motion when update_dop_num == " - "read_dop_num."), - NULL - }, - &px_enable_remove_update_redundant_motion, - false, - NULL, NULL, NULL - }, { {"polar_px_enable_delete", PGC_USERSET, UNGROUPED, gettext_noop("This guc allows parallel delete."), @@ -1965,16 +1953,6 @@ struct config_bool ConfigureNamesBool_px[] = false, NULL, NULL, NULL }, - { - {"polar_px_enable_remove_delete_redundant_motion", PGC_USERSET, UNGROUPED, - gettext_noop("This guc remove delete redundant motion when delete_dop_num == " - "read_dop_num."), - NULL - }, - &px_enable_remove_delete_redundant_motion, - false, - NULL, NULL, NULL - }, { {"polar_px_optimizer_remove_superfluous_order", PGC_USERSET, UNGROUPED, gettext_noop("This guc remove superfluous order"), diff --git a/src/include/px/px_conn.h b/src/include/px/px_conn.h index e119f1d168c..0fc5649ed76 100644 --- a/src/include/px/px_conn.h +++ b/src/include/px/px_conn.h @@ -18,6 +18,7 @@ typedef struct SnapshotData SnapshotData; +typedef enum SegmentType SegmentType; /* -------------------------------------------------------------------------------------------------- * Structure for segment database definition and working values @@ -69,7 +70,8 @@ void pxconn_termWorkerDescriptor(PxWorkerDescriptor *pxWorkerDesc); /* Connect to a PX as a client via libpq. */ void pxconn_doConnectStart(PxWorkerDescriptor *pxWorkerDesc, const char *pxid, - const char *options); + const char *options, + SegmentType segmentType); void pxconn_doConnectComplete(PxWorkerDescriptor *pxWorkerDesc); /* diff --git a/src/include/px/px_util.h b/src/include/px/px_util.h index 634eed5513f..d2d7aa3af9d 100644 --- a/src/include/px/px_util.h +++ b/src/include/px/px_util.h @@ -39,11 +39,6 @@ typedef struct PxNodes PxNodes; */ #define COMPONENT_DBS_MAX_ADDRS (8) -/* POLAR px: For Multi Insert */ -#define RW_SEGMENT (-10002) -#define RW_COUNTER_START (100000) -/* POLAR end */ - typedef struct PxNodeConfigEntry { /* copy of entry in px_node_configuration */ @@ -100,9 +95,6 @@ struct PxNodes int numActivePXs; int numIdlePXs; int pxCounter; - /* POLAR px */ - int rwCounter; - /* POLAR end */ List *freeCounterList; }; @@ -143,7 +135,7 @@ extern void px_cleanup(int code, Datum arg pg_attribute_unused()); */ PxNodes *pxnode_getPxNodes(void); -PxNodeInfo *pxnode_getPxNodeInfo(int contentId); +PxNodeInfo *pxnode_getPxNodeInfo(int contentId, SegmentType segmentType); struct PxWorkerDescriptor *pxnode_allocateIdlePX(int logicalWorkerIdx, int logicalTotalWorkers, SegmentType segmentType); diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h index fa3a9ce04cb..c1ee84b25e4 100644 --- a/src/include/utils/guc.h +++ b/src/include/utils/guc.h @@ -1029,10 +1029,8 @@ extern bool px_enable_insert_order_sensitive; extern bool px_enable_partitionwise_join; extern bool px_enable_update; extern int px_update_dop_num; -extern bool px_enable_remove_update_redundant_motion; extern bool px_enable_delete; extern int px_delete_dop_num; -extern bool px_enable_remove_delete_redundant_motion; extern bool px_optimizer_remove_superfluous_order; extern bool px_allow_strat_seqscan; diff --git a/src/include/utils/px_unsync_guc_name.h b/src/include/utils/px_unsync_guc_name.h index 9b792ff699b..206c4d76106 100644 --- a/src/include/utils/px_unsync_guc_name.h +++ b/src/include/utils/px_unsync_guc_name.h @@ -692,8 +692,6 @@ "polar_px_enable_result_hash_filter", "polar_px_enable_tableless_scan", "polar_px_enable_update", - "polar_px_enable_remove_delete_redundant_motion", - "polar_px_enable_remove_update_redundant_motion", "polar_px_ignore_unusable_nodes", "polar_px_insert_dop_num", "polar_px_optimizer_remove_superfluous_order", diff --git a/src/test/regress/px_expected/polar-px-dev/px_parallel_dml.out b/src/test/regress/px_expected/polar-px-dev/px_parallel_dml.out index 00a4fd879d8..dff1bf25262 100644 --- a/src/test/regress/px_expected/polar-px-dev/px_parallel_dml.out +++ b/src/test/regress/px_expected/polar-px-dev/px_parallel_dml.out @@ -1,22 +1,36 @@ -- config /*--POLAR_ENABLE_PX*/ +set client_min_messages to error; set polar_enable_px = 1; set polar_px_enable_insert_select = 1; set polar_px_optimizer_enable_dml_constraints = 1; set polar_px_enable_insert_order_sensitive = 0; +create function dml_explain_filter(text) returns setof text +language plpgsql as +$$ +declare + ln text; +begin + for ln in execute $1 + loop + -- Replace any actual rows with just 'N' + ln := regexp_replace(ln, 'actual rows=\d+\M', 'actual rows=N', 'g'); + -- In sort output, the above won't match units-suffixed numbers + ln := regexp_replace(ln, '\m\d+kB', 'NkB', 'g'); + return next ln; + end loop; +end; +$$; -- create table \i sql/polar-px-dev/px_parallel_dml_init.sql -- create normal table drop table if exists px_parallel_dml_t1 cascade; -psql:sql/polar-px-dev/px_parallel_dml_init.sql:2: NOTICE: table "px_parallel_dml_t1" does not exist, skipping CREATE TABLE px_parallel_dml_t1 (c1 int, c2 int) ; insert into px_parallel_dml_t1 select generate_series(1,100),generate_series(1,100); drop table if exists px_parallel_dml_t2 cascade; -psql:sql/polar-px-dev/px_parallel_dml_init.sql:6: NOTICE: table "px_parallel_dml_t2" does not exist, skipping CREATE TABLE px_parallel_dml_t2 (c1 int, c2 int) ; insert into px_parallel_dml_t2 select generate_series(1,100),generate_series(1,100); drop table if exists px_parallel_dml_t3 cascade; -psql:sql/polar-px-dev/px_parallel_dml_init.sql:10: NOTICE: table "px_parallel_dml_t3" does not exist, skipping CREATE TABLE px_parallel_dml_t3 (c1 int, c2 int) ; insert into px_parallel_dml_t3 select generate_series(1,1000),generate_series(1,1000); select count(*) from px_parallel_dml_t1; @@ -33,23 +47,18 @@ select count(*) from px_parallel_dml_t2; -- create partition table drop table if exists px_parallel_dml_t0_hash_insert cascade; -psql:sql/polar-px-dev/px_parallel_dml_init.sql:19: NOTICE: table "px_parallel_dml_t0_hash_insert" does not exist, skipping CREATE TABLE px_parallel_dml_t0_hash_insert (id int, value int) PARTITION BY HASH(id); drop table if exists px_parallel_dml_t0_insert cascade; -psql:sql/polar-px-dev/px_parallel_dml_init.sql:21: NOTICE: table "px_parallel_dml_t0_insert" does not exist, skipping CREATE TABLE px_parallel_dml_t0_insert (id int, value int); drop table if exists px_parallel_dml_t0_select_table cascade; -psql:sql/polar-px-dev/px_parallel_dml_init.sql:23: NOTICE: table "px_parallel_dml_t0_select_table" does not exist, skipping CREATE TABLE px_parallel_dml_t0_select_table (id int, value int); insert into px_parallel_dml_t0_select_table select generate_series(1,12000),generate_series(1,12000); drop table if exists px_parallel_dml_t0_select_list_table cascade; -psql:sql/polar-px-dev/px_parallel_dml_init.sql:26: NOTICE: table "px_parallel_dml_t0_select_list_table" does not exist, skipping CREATE TABLE px_parallel_dml_t0_select_list_table (status character varying(30), value int); -- PX Insert... Select from Partition Table ------------------------------------------------------------------------ -- Create partition table drop table if exists px_parallel_dml_t0_hash cascade; -psql:sql/polar-px-dev/px_parallel_dml_init.sql:33: NOTICE: table "px_parallel_dml_t0_hash" does not exist, skipping CREATE TABLE px_parallel_dml_t0_hash (id int, value int) PARTITION BY HASH(id); CREATE TABLE px_parallel_dml_t0_hash_p1 PARTITION OF px_parallel_dml_t0_hash FOR VALUES WITH (modulus 3, remainder 0); CREATE TABLE px_parallel_dml_t0_hash_p2 PARTITION OF px_parallel_dml_t0_hash FOR VALUES WITH (modulus 3, remainder 1); @@ -59,7 +68,6 @@ insert into px_parallel_dml_t0_hash select generate_series(1,30000),generate_ser --range partition --Partition constraint: ((x IS NOT NULL) AND (x >= 10) AND (x < 20)) drop table if exists px_parallel_dml_t1_range cascade; -psql:sql/polar-px-dev/px_parallel_dml_init.sql:43: NOTICE: table "px_parallel_dml_t1_range" does not exist, skipping CREATE TABLE px_parallel_dml_t1_range(id int, value int) PARTITION BY RANGE(id); CREATE TABLE px_parallel_dml_t1_range_p1 PARTITION OF px_parallel_dml_t1_range FOR VALUES FROM (1) TO (10000); CREATE TABLE px_parallel_dml_t1_range_p2 PARTITION OF px_parallel_dml_t1_range FOR VALUES FROM (10000) TO (20000); @@ -67,7 +75,6 @@ CREATE TABLE px_parallel_dml_t1_range_p3 PARTITION OF px_parallel_dml_t1_range D insert into px_parallel_dml_t1_range select generate_series(1,30000, 2); --range partition with INDEX drop table if exists px_parallel_dml_t1_range_index cascade; -psql:sql/polar-px-dev/px_parallel_dml_init.sql:51: NOTICE: table "px_parallel_dml_t1_range_index" does not exist, skipping CREATE TABLE px_parallel_dml_t1_range_index(id int, value int) PARTITION BY RANGE(id); CREATE TABLE px_parallel_dml_t1_range_p1_index PARTITION OF px_parallel_dml_t1_range_index FOR VALUES FROM (1) TO (10000); CREATE TABLE px_parallel_dml_t1_range_p2_index PARTITION OF px_parallel_dml_t1_range_index FOR VALUES FROM (10000) TO (20000); @@ -78,7 +85,6 @@ CREATE INDEX px_parallel_dml_t1_partition_index on px_parallel_dml_t1_range_inde --list --Partition constraint: ((b IS NOT NULL) AND (b = ANY (ARRAY[1, 3]))) drop table if exists px_parallel_dml_t2_list cascade; -psql:sql/polar-px-dev/px_parallel_dml_init.sql:64: NOTICE: table "px_parallel_dml_t2_list" does not exist, skipping create table px_parallel_dml_t2_list(job character varying(30), pvalue int) partition by list (job); CREATE TABLE px_parallel_dml_t2_list_p1 PARTITION OF px_parallel_dml_t2_list FOR VALUES IN ('student'); CREATE TABLE px_parallel_dml_t2_list_p2 PARTITION OF px_parallel_dml_t2_list FOR VALUES IN ('teacher'); @@ -88,20 +94,16 @@ insert into px_parallel_dml_t2_list select 'teacher',generate_series(10000,20000 insert into px_parallel_dml_t2_list select 'other',generate_series(20000,30000); -- Index Test Init drop table if exists px_parallel_dml_t4 cascade; -psql:sql/polar-px-dev/px_parallel_dml_init.sql:74: NOTICE: table "px_parallel_dml_t4" does not exist, skipping CREATE TABLE px_parallel_dml_t4 (c1 int, c2 int) ; insert into px_parallel_dml_t4 select generate_series(1,1000),generate_series(1,1000); CREATE INDEX t_index_plan on px_parallel_dml_t4(c1); -- Constrain Test Init drop table if exists px_parallel_dml_t5 cascade; -psql:sql/polar-px-dev/px_parallel_dml_init.sql:81: NOTICE: table "px_parallel_dml_t5" does not exist, skipping CREATE TABLE px_parallel_dml_t5 (c1 int, c2 int not NULL) ; drop table if exists px_parallel_dml_t6 cascade; -psql:sql/polar-px-dev/px_parallel_dml_init.sql:83: NOTICE: table "px_parallel_dml_t6" does not exist, skipping CREATE TABLE px_parallel_dml_t6 (c1 int, c2 int) ; ---- Insert into table with default num drop table if exists px_parallel_dml_t8 cascade; -psql:sql/polar-px-dev/px_parallel_dml_init.sql:88: NOTICE: table "px_parallel_dml_t8" does not exist, skipping CREATE TABLE px_parallel_dml_t8( c1 int, c2 int DEFAULT 99999, @@ -109,7 +111,6 @@ c3 varchar DEFAULT NULL, c4 timestamp default '2016-06-22 19:10:25-07' ); drop table if exists px_parallel_dml_t9 cascade; -psql:sql/polar-px-dev/px_parallel_dml_init.sql:96: NOTICE: table "px_parallel_dml_t9" does not exist, skipping CREATE TABLE px_parallel_dml_t9 (c1 int, c2 int) ; insert into px_parallel_dml_t9 select generate_series(1,20),generate_series(1,20); /*--EXPLAIN_QUERY_BEGIN*/ @@ -486,29 +487,29 @@ select count(*) from px_parallel_dml_t2; Optimizer: PolarDB PX Optimizer (8 rows) -EXPLAIN (VERBOSE, COSTS OFF) insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t1; - QUERY PLAN --------------------------------------------------------------------------------------- - Insert on public.px_parallel_dml_t1 - -> Result +select dml_explain_filter('EXPLAIN (VERBOSE, COSTS OFF, TIMING OFF, SUMMARY OFF, ANALYZE) insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t1'); + dml_explain_filter +-------------------------------------------------------------------------------------------------------------- + Insert on public.px_parallel_dml_t1 (actual rows=N loops=1) + -> Result (actual rows=N loops=1) Output: px_parallel_dml_t1_1.c2, px_parallel_dml_t1_1.c1 - -> PX Coordinator 6:1 (slice1; segments: 6) + -> PX Coordinator 6:1 (slice1; segments: 6) (actual rows=N loops=1) Output: px_parallel_dml_t1_1.c1, px_parallel_dml_t1_1.c2 - -> Partial Seq Scan on public.px_parallel_dml_t1 px_parallel_dml_t1_1 + -> Partial Seq Scan on public.px_parallel_dml_t1 px_parallel_dml_t1_1 (actual rows=N loops=1) Output: px_parallel_dml_t1_1.c1, px_parallel_dml_t1_1.c2 Optimizer: PolarDB PX Optimizer (8 rows) insert into px_parallel_dml_t2 select c2, c1 from px_parallel_dml_t1; -EXPLAIN (VERBOSE, COSTS OFF) insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t2; - QUERY PLAN --------------------------------------------------------------------------- - Insert on public.px_parallel_dml_t1 - -> Result +select dml_explain_filter('EXPLAIN (VERBOSE, COSTS OFF, TIMING OFF, SUMMARY OFF, ANALYZE) insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t2'); + dml_explain_filter +----------------------------------------------------------------------------------------- + Insert on public.px_parallel_dml_t1 (actual rows=N loops=1) + -> Result (actual rows=N loops=1) Output: px_parallel_dml_t2.c2, px_parallel_dml_t2.c1 - -> PX Coordinator 6:1 (slice1; segments: 6) + -> PX Coordinator 6:1 (slice1; segments: 6) (actual rows=N loops=1) Output: px_parallel_dml_t2.c1, px_parallel_dml_t2.c2 - -> Partial Seq Scan on public.px_parallel_dml_t2 + -> Partial Seq Scan on public.px_parallel_dml_t2 (actual rows=N loops=1) Output: px_parallel_dml_t2.c1, px_parallel_dml_t2.c2 Optimizer: PolarDB PX Optimizer (8 rows) @@ -517,7 +518,7 @@ insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t2; select count(*) from px_parallel_dml_t1; count ------- - 480 + 1280 (1 row) QUERY PLAN @@ -535,7 +536,7 @@ select count(*) from px_parallel_dml_t1; select count(*) from px_parallel_dml_t2; count ------- - 320 + 480 (1 row) QUERY PLAN @@ -555,7 +556,7 @@ insert into px_parallel_dml_t2 select c2, c1 from px_parallel_dml_t1 where c1 = select count(*) from px_parallel_dml_t1; count ------- - 484 + 1286 (1 row) QUERY PLAN @@ -573,7 +574,7 @@ select count(*) from px_parallel_dml_t1; select count(*) from px_parallel_dml_t2; count ------- - 330 + 502 (1 row) QUERY PLAN @@ -1635,7 +1636,7 @@ EXPLAIN (VERBOSE, COSTS OFF) insert into px_parallel_dml_t1 select c1,px_paralle select count(*) from px_parallel_dml_t1; count ------- - 484 + 1286 (1 row) QUERY PLAN @@ -1675,7 +1676,7 @@ insert into px_parallel_dml_t1 select * from px_parallel_dml_t2 group by c1,c2; select count(*) from px_parallel_dml_t1; count ------- - 584 + 1386 (1 row) QUERY PLAN @@ -1941,29 +1942,29 @@ select count(*) from px_parallel_dml_t2; Optimizer: PolarDB PX Optimizer (8 rows) -EXPLAIN (VERBOSE, COSTS OFF) insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t1; - QUERY PLAN --------------------------------------------------------------------------------------- - Insert on public.px_parallel_dml_t1 - -> Result +select dml_explain_filter('EXPLAIN (VERBOSE, COSTS OFF, TIMING OFF, SUMMARY OFF, ANALYZE) insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t1'); + dml_explain_filter +-------------------------------------------------------------------------------------------------------------- + Insert on public.px_parallel_dml_t1 (never executed) + -> Result (actual rows=N loops=1) Output: px_parallel_dml_t1_1.c2, px_parallel_dml_t1_1.c1 - -> PX Hash 6:3 (slice1; segments: 6) + -> PX Hash 6:3 (slice1; segments: 6) (actual rows=N loops=1) Output: px_parallel_dml_t1_1.c2, px_parallel_dml_t1_1.c1, (1) - -> Partial Seq Scan on public.px_parallel_dml_t1 px_parallel_dml_t1_1 + -> Partial Seq Scan on public.px_parallel_dml_t1 px_parallel_dml_t1_1 (actual rows=N loops=1) Output: px_parallel_dml_t1_1.c2, px_parallel_dml_t1_1.c1, 1 Optimizer: PolarDB PX Optimizer (8 rows) insert into px_parallel_dml_t2 select c2, c1 from px_parallel_dml_t1; -EXPLAIN (VERBOSE, COSTS OFF) insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t2; - QUERY PLAN ------------------------------------------------------------------------------ - Insert on public.px_parallel_dml_t1 - -> Result +select dml_explain_filter('EXPLAIN (VERBOSE, COSTS OFF, TIMING OFF, SUMMARY OFF, ANALYZE) insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t2'); + dml_explain_filter +----------------------------------------------------------------------------------------- + Insert on public.px_parallel_dml_t1 (never executed) + -> Result (actual rows=N loops=1) Output: px_parallel_dml_t2.c2, px_parallel_dml_t2.c1 - -> PX Hash 6:3 (slice1; segments: 6) + -> PX Hash 6:3 (slice1; segments: 6) (actual rows=N loops=1) Output: px_parallel_dml_t2.c2, px_parallel_dml_t2.c1, (1) - -> Partial Seq Scan on public.px_parallel_dml_t2 + -> Partial Seq Scan on public.px_parallel_dml_t2 (actual rows=N loops=1) Output: px_parallel_dml_t2.c2, px_parallel_dml_t2.c1, 1 Optimizer: PolarDB PX Optimizer (8 rows) @@ -1972,7 +1973,7 @@ insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t2; select count(*) from px_parallel_dml_t1; count ------- - 480 + 1280 (1 row) QUERY PLAN @@ -1990,7 +1991,7 @@ select count(*) from px_parallel_dml_t1; select count(*) from px_parallel_dml_t2; count ------- - 320 + 480 (1 row) QUERY PLAN @@ -2010,7 +2011,7 @@ insert into px_parallel_dml_t2 select c2, c1 from px_parallel_dml_t1 where c1 = select count(*) from px_parallel_dml_t1; count ------- - 484 + 1286 (1 row) QUERY PLAN @@ -2028,7 +2029,7 @@ select count(*) from px_parallel_dml_t1; select count(*) from px_parallel_dml_t2; count ------- - 330 + 502 (1 row) QUERY PLAN @@ -3110,7 +3111,7 @@ EXPLAIN (VERBOSE, COSTS OFF) insert into px_parallel_dml_t1 select c1,px_paralle select count(*) from px_parallel_dml_t1; count ------- - 484 + 1286 (1 row) QUERY PLAN @@ -3150,7 +3151,7 @@ insert into px_parallel_dml_t1 select * from px_parallel_dml_t2 group by c1,c2; select count(*) from px_parallel_dml_t1; count ------- - 584 + 1386 (1 row) QUERY PLAN @@ -3416,29 +3417,29 @@ select count(*) from px_parallel_dml_t2; Optimizer: PolarDB PX Optimizer (8 rows) -EXPLAIN (VERBOSE, COSTS OFF) insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t1; - QUERY PLAN --------------------------------------------------------------------------------------- - Insert on public.px_parallel_dml_t1 - -> Result +select dml_explain_filter('EXPLAIN (VERBOSE, COSTS OFF, TIMING OFF, SUMMARY OFF, ANALYZE) insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t1'); + dml_explain_filter +-------------------------------------------------------------------------------------------------------------- + Insert on public.px_parallel_dml_t1 (never executed) + -> Result (actual rows=N loops=1) Output: px_parallel_dml_t1_1.c2, px_parallel_dml_t1_1.c1 - -> PX Hash 6:6 (slice1; segments: 6) + -> PX Hash 6:6 (slice1; segments: 6) (actual rows=N loops=1) Output: px_parallel_dml_t1_1.c2, px_parallel_dml_t1_1.c1, (1) - -> Partial Seq Scan on public.px_parallel_dml_t1 px_parallel_dml_t1_1 + -> Partial Seq Scan on public.px_parallel_dml_t1 px_parallel_dml_t1_1 (actual rows=N loops=1) Output: px_parallel_dml_t1_1.c2, px_parallel_dml_t1_1.c1, 1 Optimizer: PolarDB PX Optimizer (8 rows) insert into px_parallel_dml_t2 select c2, c1 from px_parallel_dml_t1; -EXPLAIN (VERBOSE, COSTS OFF) insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t2; - QUERY PLAN ------------------------------------------------------------------------------ - Insert on public.px_parallel_dml_t1 - -> Result +select dml_explain_filter('EXPLAIN (VERBOSE, COSTS OFF, TIMING OFF, SUMMARY OFF, ANALYZE) insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t2'); + dml_explain_filter +----------------------------------------------------------------------------------------- + Insert on public.px_parallel_dml_t1 (never executed) + -> Result (actual rows=N loops=1) Output: px_parallel_dml_t2.c2, px_parallel_dml_t2.c1 - -> PX Hash 6:6 (slice1; segments: 6) + -> PX Hash 6:6 (slice1; segments: 6) (actual rows=N loops=1) Output: px_parallel_dml_t2.c2, px_parallel_dml_t2.c1, (1) - -> Partial Seq Scan on public.px_parallel_dml_t2 + -> Partial Seq Scan on public.px_parallel_dml_t2 (actual rows=N loops=1) Output: px_parallel_dml_t2.c2, px_parallel_dml_t2.c1, 1 Optimizer: PolarDB PX Optimizer (8 rows) @@ -3447,7 +3448,7 @@ insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t2; select count(*) from px_parallel_dml_t1; count ------- - 480 + 1280 (1 row) QUERY PLAN @@ -3465,7 +3466,7 @@ select count(*) from px_parallel_dml_t1; select count(*) from px_parallel_dml_t2; count ------- - 320 + 480 (1 row) QUERY PLAN @@ -3485,7 +3486,7 @@ insert into px_parallel_dml_t2 select c2, c1 from px_parallel_dml_t1 where c1 = select count(*) from px_parallel_dml_t1; count ------- - 484 + 1286 (1 row) QUERY PLAN @@ -3503,7 +3504,7 @@ select count(*) from px_parallel_dml_t1; select count(*) from px_parallel_dml_t2; count ------- - 330 + 502 (1 row) QUERY PLAN @@ -4585,7 +4586,7 @@ EXPLAIN (VERBOSE, COSTS OFF) insert into px_parallel_dml_t1 select c1,px_paralle select count(*) from px_parallel_dml_t1; count ------- - 484 + 1286 (1 row) QUERY PLAN @@ -4625,7 +4626,7 @@ insert into px_parallel_dml_t1 select * from px_parallel_dml_t2 group by c1,c2; select count(*) from px_parallel_dml_t1; count ------- - 584 + 1386 (1 row) QUERY PLAN @@ -4891,29 +4892,29 @@ select count(*) from px_parallel_dml_t2; Optimizer: PolarDB PX Optimizer (8 rows) -EXPLAIN (VERBOSE, COSTS OFF) insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t1; - QUERY PLAN --------------------------------------------------------------------------------------- - Insert on public.px_parallel_dml_t1 - -> Result +select dml_explain_filter('EXPLAIN (VERBOSE, COSTS OFF, TIMING OFF, SUMMARY OFF, ANALYZE) insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t1'); + dml_explain_filter +-------------------------------------------------------------------------------------------------------------- + Insert on public.px_parallel_dml_t1 (never executed) + -> Result (actual rows=N loops=1) Output: px_parallel_dml_t1_1.c2, px_parallel_dml_t1_1.c1 - -> PX Hash 6:10 (slice1; segments: 6) + -> PX Hash 6:10 (slice1; segments: 6) (actual rows=N loops=1) Output: px_parallel_dml_t1_1.c2, px_parallel_dml_t1_1.c1, (1) - -> Partial Seq Scan on public.px_parallel_dml_t1 px_parallel_dml_t1_1 + -> Partial Seq Scan on public.px_parallel_dml_t1 px_parallel_dml_t1_1 (actual rows=N loops=1) Output: px_parallel_dml_t1_1.c2, px_parallel_dml_t1_1.c1, 1 Optimizer: PolarDB PX Optimizer (8 rows) insert into px_parallel_dml_t2 select c2, c1 from px_parallel_dml_t1; -EXPLAIN (VERBOSE, COSTS OFF) insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t2; - QUERY PLAN ------------------------------------------------------------------------------ - Insert on public.px_parallel_dml_t1 - -> Result +select dml_explain_filter('EXPLAIN (VERBOSE, COSTS OFF, TIMING OFF, SUMMARY OFF, ANALYZE) insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t2'); + dml_explain_filter +----------------------------------------------------------------------------------------- + Insert on public.px_parallel_dml_t1 (never executed) + -> Result (actual rows=N loops=1) Output: px_parallel_dml_t2.c2, px_parallel_dml_t2.c1 - -> PX Hash 6:10 (slice1; segments: 6) + -> PX Hash 6:10 (slice1; segments: 6) (actual rows=N loops=1) Output: px_parallel_dml_t2.c2, px_parallel_dml_t2.c1, (1) - -> Partial Seq Scan on public.px_parallel_dml_t2 + -> Partial Seq Scan on public.px_parallel_dml_t2 (actual rows=N loops=1) Output: px_parallel_dml_t2.c2, px_parallel_dml_t2.c1, 1 Optimizer: PolarDB PX Optimizer (8 rows) @@ -4922,7 +4923,7 @@ insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t2; select count(*) from px_parallel_dml_t1; count ------- - 480 + 1280 (1 row) QUERY PLAN @@ -4940,7 +4941,7 @@ select count(*) from px_parallel_dml_t1; select count(*) from px_parallel_dml_t2; count ------- - 320 + 480 (1 row) QUERY PLAN @@ -4960,7 +4961,7 @@ insert into px_parallel_dml_t2 select c2, c1 from px_parallel_dml_t1 where c1 = select count(*) from px_parallel_dml_t1; count ------- - 484 + 1286 (1 row) QUERY PLAN @@ -4978,7 +4979,7 @@ select count(*) from px_parallel_dml_t1; select count(*) from px_parallel_dml_t2; count ------- - 330 + 502 (1 row) QUERY PLAN @@ -6060,7 +6061,7 @@ EXPLAIN (VERBOSE, COSTS OFF) insert into px_parallel_dml_t1 select c1,px_paralle select count(*) from px_parallel_dml_t1; count ------- - 484 + 1286 (1 row) QUERY PLAN @@ -6100,7 +6101,7 @@ insert into px_parallel_dml_t1 select * from px_parallel_dml_t2 group by c1,c2; select count(*) from px_parallel_dml_t1; count ------- - 584 + 1386 (1 row) QUERY PLAN @@ -6200,3 +6201,4 @@ select * from px_parallel_dml_t8 ORDER BY c1 ASC; Optimizer: PolarDB PX Optimizer (9 rows) +reset client_min_messages; diff --git a/src/test/regress/sql/polar-px-dev/px_parallel_dml.sql b/src/test/regress/sql/polar-px-dev/px_parallel_dml.sql index 01d18933366..1e3c6d07d96 100644 --- a/src/test/regress/sql/polar-px-dev/px_parallel_dml.sql +++ b/src/test/regress/sql/polar-px-dev/px_parallel_dml.sql @@ -1,10 +1,27 @@ -- config /*--POLAR_ENABLE_PX*/ +set client_min_messages to error; set polar_enable_px = 1; set polar_px_enable_insert_select = 1; set polar_px_optimizer_enable_dml_constraints = 1; set polar_px_enable_insert_order_sensitive = 0; +create function dml_explain_filter(text) returns setof text +language plpgsql as +$$ +declare + ln text; +begin + for ln in execute $1 + loop + -- Replace any actual rows with just 'N' + ln := regexp_replace(ln, 'actual rows=\d+\M', 'actual rows=N', 'g'); + -- In sort output, the above won't match units-suffixed numbers + ln := regexp_replace(ln, '\m\d+kB', 'NkB', 'g'); + return next ln; + end loop; +end; +$$; -- create table \i sql/polar-px-dev/px_parallel_dml_init.sql @@ -53,3 +70,5 @@ set polar_px_insert_dop_num = 6; set polar_px_insert_dop_num = 10; \i sql/polar-px-dev/px_parallel_dml_init.sql \i sql/polar-px-dev/px_parallel_dml_base.sql + +reset client_min_messages; \ No newline at end of file diff --git a/src/test/regress/sql/polar-px-dev/px_parallel_dml_base.sql b/src/test/regress/sql/polar-px-dev/px_parallel_dml_base.sql index 4cec36956b9..22665f6f152 100644 --- a/src/test/regress/sql/polar-px-dev/px_parallel_dml_base.sql +++ b/src/test/regress/sql/polar-px-dev/px_parallel_dml_base.sql @@ -4,9 +4,9 @@ EXPLAIN (VERBOSE, COSTS OFF) insert into px_parallel_dml_t2 select generate_seri insert into px_parallel_dml_t2 select generate_series(1,60),generate_series(1,60); select count(*) from px_parallel_dml_t1; select count(*) from px_parallel_dml_t2; -EXPLAIN (VERBOSE, COSTS OFF) insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t1; +select dml_explain_filter('EXPLAIN (VERBOSE, COSTS OFF, TIMING OFF, SUMMARY OFF, ANALYZE) insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t1'); insert into px_parallel_dml_t2 select c2, c1 from px_parallel_dml_t1; -EXPLAIN (VERBOSE, COSTS OFF) insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t2; +select dml_explain_filter('EXPLAIN (VERBOSE, COSTS OFF, TIMING OFF, SUMMARY OFF, ANALYZE) insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t2'); insert into px_parallel_dml_t1 select c2, c1 from px_parallel_dml_t2; select count(*) from px_parallel_dml_t1; select count(*) from px_parallel_dml_t2; From ef4db255a56f404f5e45653fb279da3d78f5373f Mon Sep 17 00:00:00 2001 From: ocean-dot-li Date: Thu, 16 Nov 2023 16:40:57 +0800 Subject: [PATCH 2/2] [Bug] fix log buffer inital issue In exec_execute_message(), we should initalize the log buffer at outermost layer. If not, crash may happen when trying to accessing its data member. This patch fixes the issue. --- src/backend/tcop/postgres.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 02a5b3992de..f7f6c98ffff 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -2354,13 +2354,17 @@ exec_execute_message(const char *portal_name, long max_rows) pq_putemptymessage('s'); } + buf.data = NULL; + if (to_log) { /* POLAR: get errmsg params string, we must free it in the last */ // It needs to malloc and free twice, not so efficiency. params_string = polar_get_errmsg_params(portalParams); + /* POLAR: inital buf used by logging info. */ initStringInfo(&buf); + if (polar_enable_log_search_path) appendStringInfo(&buf, "/*polardb %s polardb*/ ", namespace_search_path); @@ -2491,7 +2495,7 @@ exec_execute_message(const char *portal_name, long max_rows) pfree(params_string); /* POLAR end */ - if (buf.data) + if (to_log && buf.data) pfree(buf.data); if (save_log_statement_stats)