Skip to content

Commit 5ea92ba

Browse files
committed
ORCA: Support create plan in singlenode mode
In single node mode, ORCA may produce incorrect results for some insert/update/delete operations, or sublink/subselect operations. I don't have plan to spend a lot of time to support all operators. The current commit supports singlenode-mode in ORCA and disables unsupported operators.
1 parent d5967fd commit 5ea92ba

File tree

16 files changed

+156
-102
lines changed

16 files changed

+156
-102
lines changed

.asf.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ github:
9696
- pax-ic-isolation2-opt-off
9797
- pax-ic-isolation2-opt-on
9898
- ic-expandshrink
99-
- ic-singlenode
99+
- ic-singlenode-opt-off
100100
- ic-resgroup-v2
101101
- ic-contrib
102102
- ic-gpcontrib

.github/workflows/build-cloudberry.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,12 @@ jobs:
269269
{"test":"ic-expandshrink",
270270
"make_configs":["src/test/isolation2:installcheck-expandshrink"]
271271
},
272-
{"test":"ic-singlenode",
272+
{"test":"ic-singlenode-opt-off",
273273
"make_configs":["src/test/isolation:installcheck-singlenode",
274274
"src/test/singlenode_regress:installcheck-singlenode",
275275
"src/test/singlenode_isolation2:installcheck-singlenode"],
276-
"num_primary_mirror_pairs":0
276+
"num_primary_mirror_pairs":0,
277+
"pg_settings":{"optimizer":"off"}
277278
},
278279
{"test":"ic-resgroup-v2",
279280
"make_configs":["src/test/isolation2:installcheck-resgroup-v2"],

src/backend/gpopt/config/CConfigParamMapping.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
extern "C" {
1717
#include "postgres.h"
18-
18+
#include "cdb/cdbvars.h"
1919
#include "utils/guc.h"
2020
}
2121

@@ -379,6 +379,12 @@ CConfigParamMapping::PackConfigParamInBitset(
379379
}
380380
}
381381

382+
if (IS_SINGLENODE()) {
383+
traceflag_bitset->ExchangeSet(EopttraceSingleNodeMode);
384+
} else {
385+
traceflag_bitset->ExchangeClear(EopttraceSingleNodeMode);
386+
}
387+
382388
if (!optimizer_enable_nljoin)
383389
{
384390
CBitSet *nl_join_bitset = CXform::PbsNLJoinXforms(mp);

src/backend/gpopt/translate/CTranslatorQueryToDXL.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ CTranslatorQueryToDXL::CTranslatorQueryToDXL(
210210
}
211211
}
212212

213+
// check if query has insert/update/delete when is_master_only is true.
214+
CheckUnsupportedDDLInSingleMode(m_mp, query);
215+
213216
// check if the query has any unsupported node types
214217
CheckUnsupportedNodeTypes(query);
215218

@@ -280,6 +283,50 @@ CTranslatorQueryToDXL::~CTranslatorQueryToDXL()
280283
}
281284
}
282285

286+
//---------------------------------------------------------------------------
287+
// @function:
288+
// CTranslatorQueryToDXL::CheckUnsupportedNodeTypes
289+
//
290+
// @doc:
291+
// Check for unsupported node types, and throws an exception when found
292+
//
293+
//---------------------------------------------------------------------------
294+
void
295+
CTranslatorQueryToDXL::CheckUnsupportedDDLInSingleMode(CMemoryPool *mp, Query *query)
296+
{
297+
static const SUnsupportedFeature unsupported_features[] = {
298+
{T_SubLink, GPOS_WSZ_LIT("Sublink")},
299+
{T_SubqueryScan, GPOS_WSZ_LIT("Subscan")},
300+
};
301+
302+
List *unsupported_list = NIL;
303+
for (ULONG ul = 0; ul < GPOS_ARRAY_SIZE(unsupported_features); ul++)
304+
{
305+
unsupported_list = gpdb::LAppendInt(unsupported_list,
306+
unsupported_features[ul].node_tag);
307+
}
308+
309+
INT unsupported_node = gpdb::FindNodes((Node *) query, unsupported_list);
310+
gpdb::GPDBFree(unsupported_list);
311+
312+
if (GPOS_FTRACE(EopttraceSingleNodeMode) || GPOS_FTRACE(EopttraceDisableMotions)) {
313+
if (query->commandType == CMD_INSERT || query->commandType == CMD_UPDATE ||
314+
query->commandType == CMD_DELETE) {
315+
GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiQuery2DXLUnsupportedFeature,
316+
GPOS_WSZ_LIT("Single-mode not support insert/update/delete"));
317+
}
318+
319+
if (0 <= unsupported_node) {
320+
CWStringDynamic error_message(mp);
321+
error_message.AppendFormat(GPOS_WSZ_LIT("Single-mode not support %s"),
322+
unsupported_features[unsupported_node].m_feature_name);
323+
324+
GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiQuery2DXLUnsupportedFeature,
325+
error_message.GetBuffer());
326+
}
327+
}
328+
}
329+
283330
//---------------------------------------------------------------------------
284331
// @function:
285332
// CTranslatorQueryToDXL::CheckUnsupportedNodeTypes

src/backend/gpopt/translate/CTranslatorUtils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ CTranslatorUtils::GetTableDescr(CMemoryPool *mp, CMDAccessor *md_accessor,
150150
}
151151
else if (IMDRelation::ErelstorageForeign != rel->RetrieveRelStorageType() &&
152152
!optimizer_enable_master_only_queries &&
153+
!GPOS_FTRACE(EopttraceSingleNodeMode) &&
153154
(IMDRelation::EreldistrMasterOnly == distribution_policy))
154155
{
155156
// fall back to the planner for queries on master-only table if they are disabled with Orca. This is due to

src/backend/gpopt/utils/COptTasks.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -953,10 +953,9 @@ COptTasks::OptimizeTask(void *ptr)
953953
query_to_dxl_translator->GetCTEs();
954954
GPOS_ASSERT(nullptr != query_output_dxlnode_array);
955955

956-
BOOL is_master_only =
957-
!optimizer_enable_motions ||
958-
(!optimizer_enable_motions_masteronly_queries &&
959-
!query_to_dxl_translator->HasDistributedTables());
956+
BOOL is_master_only = GPOS_FTRACE(EopttraceDisableMotions) ||
957+
GPOS_FTRACE(EopttraceSingleNodeMode) ||
958+
!query_to_dxl_translator->HasDistributedTables();
960959
// See NoteDistributionPolicyOpclasses() in src/backend/gpopt/translate/CTranslatorQueryToDXL.cpp
961960
BOOL use_legacy_opfamilies =
962961
(query_to_dxl_translator->GetDistributionHashOpsKind() ==

src/backend/gporca/libnaucrates/include/naucrates/traceflags/traceflags.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ enum EOptTraceFlag
8383
// print debug info of CTE
8484
EopttraceDebugCTE = 101020,
8585

86+
// Is singlenode
87+
EopttraceSingleNodeMode = 101021,
88+
8689
///////////////////////////////////////////////////////
8790
////////////////// transformations flags //////////////
8891
///////////////////////////////////////////////////////

src/backend/optimizer/plan/planner.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ standard_planner(Query *parse, const char *query_string, int cursorOptions,
387387
* PARALLEL RETRIEVE CURSOR is not supported by ORCA yet.
388388
*/
389389
if (optimizer &&
390-
GP_ROLE_DISPATCH == Gp_role &&
390+
IS_QD_OR_SINGLENODE() &&
391391
IS_QUERY_DISPATCHER() &&
392392
(cursorOptions & CURSOR_OPT_SKIP_FOREIGN_PARTITIONS) == 0 &&
393393
(cursorOptions & CURSOR_OPT_PARALLEL_RETRIEVE) == 0)

src/backend/utils/misc/guc_gp.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,6 @@ char *optimizer_search_strategy_path = NULL;
322322
/* GUCs to tell Optimizer to enable a physical operator */
323323
bool optimizer_enable_nljoin;
324324
bool optimizer_enable_indexjoin;
325-
bool optimizer_enable_motions_masteronly_queries;
326325
bool optimizer_enable_motions;
327326
bool optimizer_enable_motion_broadcast;
328327
bool optimizer_enable_motion_gather;
@@ -2175,16 +2174,6 @@ struct config_bool ConfigureNamesBool_gp[] =
21752174
true,
21762175
NULL, NULL, NULL
21772176
},
2178-
{
2179-
{"optimizer_enable_motions_masteronly_queries", PGC_USERSET, DEVELOPER_OPTIONS,
2180-
gettext_noop("Enable plans with Motion operators in the optimizer for queries with no distributed tables."),
2181-
NULL,
2182-
GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
2183-
},
2184-
&optimizer_enable_motions_masteronly_queries,
2185-
false,
2186-
NULL, NULL, NULL
2187-
},
21882177
{
21892178
{"optimizer_enable_motions", PGC_USERSET, DEVELOPER_OPTIONS,
21902179
gettext_noop("Enable plans with Motion operators in the optimizer."),

src/include/gpopt/translate/CTranslatorQueryToDXL.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ class CTranslatorQueryToDXL
147147
// node is found
148148
static void CheckUnsupportedNodeTypes(Query *query);
149149

150+
static void CheckUnsupportedDDLInSingleMode(CMemoryPool *mp, Query *query);
151+
150152
// walker to check if SUBLINK node is present in the security quals
151153
static BOOL CheckSublinkInSecurityQuals(Node *node, void *context);
152154

0 commit comments

Comments
 (0)