提交 225890a8 编写于 作者: P Pengzhou Tang

Add a GUC to limit the number of slices for a query

Executing a query plan containing a large number of slices may slow down
the entire Greenplum cluster: each "n-gang" slice corresponds to a
separate process per segment. An example of such queries is a UNION ALL
atop several complex views. To prevent such a situation, add a GUC
gp_max_slices and refuse to execute plans of which the number of slices
exceed that limit.
Signed-off-by: NJesse Zhang <sbjesse@gmail.com>
上级 b2f507a9
...@@ -1365,6 +1365,14 @@ InitSliceTable(EState *estate, int nMotions, int nSubplans) ...@@ -1365,6 +1365,14 @@ InitSliceTable(EState *estate, int nMotions, int nSubplans)
n; n;
MemoryContext oldcontext; MemoryContext oldcontext;
n = 1 + nMotions + nSubplans;
if (gp_max_slices > 0 && n > gp_max_slices)
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
errmsg("at most %d slices are allowed in a query, current number: %d", gp_max_slices, n),
errhint("rewrite your query or adjust GUC gp_max_slices")));
oldcontext = MemoryContextSwitchTo(estate->es_query_cxt); oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
table = makeNode(SliceTable); table = makeNode(SliceTable);
...@@ -1376,7 +1384,6 @@ InitSliceTable(EState *estate, int nMotions, int nSubplans) ...@@ -1376,7 +1384,6 @@ InitSliceTable(EState *estate, int nMotions, int nSubplans)
/* Each slice table has a unique-id. */ /* Each slice table has a unique-id. */
table->ic_instance_id = ++gp_interconnect_id; table->ic_instance_id = ++gp_interconnect_id;
n = 1 + nMotions + nSubplans;
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
slice = makeNode(Slice); slice = makeNode(Slice);
......
...@@ -579,6 +579,9 @@ bool optimizer_enable_associativity; ...@@ -579,6 +579,9 @@ bool optimizer_enable_associativity;
bool optimizer_analyze_root_partition; bool optimizer_analyze_root_partition;
bool optimizer_analyze_midlevel_partition; bool optimizer_analyze_midlevel_partition;
/* GUCs for slice table*/
int gp_max_slices;
/* System Information */ /* System Information */
static int gp_server_version_num; static int gp_server_version_num;
static char *gp_server_version_string; static char *gp_server_version_string;
...@@ -4720,6 +4723,16 @@ struct config_int ConfigureNamesInt_gp[] = ...@@ -4720,6 +4723,16 @@ struct config_int ConfigureNamesInt_gp[] =
GP_VERSION_NUM, GP_VERSION_NUM, GP_VERSION_NUM, NULL, NULL GP_VERSION_NUM, GP_VERSION_NUM, GP_VERSION_NUM, NULL, NULL
}, },
{
{"gp_max_slices", PGC_USERSET, PRESET_OPTIONS,
gettext_noop("Maximum slices for a single query"),
NULL,
GUC_GPDB_ADDOPT | GUC_NOT_IN_SAMPLE
},
&gp_max_slices,
0, 0, INT_MAX, NULL, NULL
},
/* End-of-list marker */ /* End-of-list marker */
{ {
{NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL {NULL, 0, 0, NULL, NULL}, NULL, 0, 0, 0, NULL, NULL
......
...@@ -500,6 +500,9 @@ extern bool optimizer_analyze_midlevel_partition; ...@@ -500,6 +500,9 @@ extern bool optimizer_analyze_midlevel_partition;
extern bool optimizer_use_gpdb_allocators; extern bool optimizer_use_gpdb_allocators;
/* GUCs for slice table*/
extern int gp_max_slices;
/** /**
* Enable logging of DPE match in optimizer. * Enable logging of DPE match in optimizer.
*/ */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册