From a18e7577036f3305d671ad29917166aeedf92d8c Mon Sep 17 00:00:00 2001 From: Jason Petersen Date: Thu, 13 Oct 2016 10:49:02 -0600 Subject: [PATCH] Fix issue with EXPLAIN and parallel local queries We need to be sure to pass CURSOR_OPT_PARALLEL in 9.6 for any SELECT query without an INTO clause. --- .../distributed/planner/multi_explain.c | 10 +++++-- src/test/regress/expected/multi_explain.out | 26 ++++++++++++++++++ src/test/regress/expected/multi_explain_0.out | 27 +++++++++++++++++++ src/test/regress/sql/multi_explain.sql | 13 +++++++++ 4 files changed, 74 insertions(+), 2 deletions(-) diff --git a/src/backend/distributed/planner/multi_explain.c b/src/backend/distributed/planner/multi_explain.c index ff92fb32d..22c180071 100644 --- a/src/backend/distributed/planner/multi_explain.c +++ b/src/backend/distributed/planner/multi_explain.c @@ -18,6 +18,7 @@ #include "commands/dbcommands.h" #include "commands/explain.h" #include "commands/tablecmds.h" +#include "optimizer/cost.h" #include "distributed/citus_nodefuncs.h" #include "distributed/multi_client_executor.h" #include "distributed/multi_executor.h" @@ -108,6 +109,11 @@ MultiExplainOneQuery(Query *query, IntoClause *into, ExplainState *es, instr_time planDuration; Query *originalQuery = NULL; RelationRestrictionContext *restrictionContext = NULL; +#if PG_VERSION_NUM >= 90600 + int cursorOptions = into ? 0 : CURSOR_OPT_PARALLEL_OK; +#else + int cursorOptions = 0; +#endif /* if local query, run the standard explain and return */ bool localQuery = !NeedsDistributedPlanning(query); @@ -118,7 +124,7 @@ MultiExplainOneQuery(Query *query, IntoClause *into, ExplainState *es, INSTR_TIME_SET_CURRENT(planStart); /* plan the query */ - plan = pg_plan_query(query, 0, params); + plan = pg_plan_query(query, cursorOptions, params); INSTR_TIME_SET_CURRENT(planDuration); INSTR_TIME_SUBTRACT(planDuration, planStart); @@ -143,7 +149,7 @@ MultiExplainOneQuery(Query *query, IntoClause *into, ExplainState *es, PG_TRY(); { /* call standard planner to modify the query structure before multi planning */ - initialPlan = standard_planner(query, 0, params); + initialPlan = standard_planner(query, cursorOptions, params); commandType = initialPlan->commandType; if (commandType == CMD_INSERT || commandType == CMD_UPDATE || diff --git a/src/test/regress/expected/multi_explain.out b/src/test/regress/expected/multi_explain.out index 7c9ffcb06..ceb608e86 100644 --- a/src/test/regress/expected/multi_explain.out +++ b/src/test/regress/expected/multi_explain.out @@ -645,3 +645,29 @@ EXPLAIN (COSTS FALSE, FORMAT YAML) Parallel Aware: false Relation Name: "pg_merge_job_570036" Alias: "pg_merge_job_570036" +-- test parallel aggregates +SET parallel_setup_cost=0; +SET parallel_tuple_cost=0; +SET min_parallel_relation_size=0; +SET max_parallel_workers_per_gather=4; +-- ensure local plans display correctly +CREATE TABLE lineitem_clone (LIKE lineitem); +EXPLAIN (COSTS FALSE) SELECT avg(l_linenumber) FROM lineitem_clone; +Finalize Aggregate + -> Gather + Workers Planned: 3 + -> Partial Aggregate + -> Parallel Seq Scan on lineitem_clone +-- ensure distributed plans don't break +EXPLAIN (COSTS FALSE) SELECT avg(l_linenumber) FROM lineitem; +Distributed Query into pg_merge_job_570037 + Executor: Task-Tracker + Task Count: 8 + Tasks Shown: One of 8 + -> Task + Node: host=localhost port=57637 dbname=regression + -> Aggregate + -> Seq Scan on lineitem_290001 lineitem +Master Query + -> Aggregate + -> Seq Scan on pg_merge_job_570037 diff --git a/src/test/regress/expected/multi_explain_0.out b/src/test/regress/expected/multi_explain_0.out index d3da016d7..f5745b080 100644 --- a/src/test/regress/expected/multi_explain_0.out +++ b/src/test/regress/expected/multi_explain_0.out @@ -615,3 +615,30 @@ EXPLAIN (COSTS FALSE, FORMAT YAML) Parent Relationship: "Outer" Relation Name: "pg_merge_job_570036" Alias: "pg_merge_job_570036" +-- test parallel aggregates +SET parallel_setup_cost=0; +ERROR: unrecognized configuration parameter "parallel_setup_cost" +SET parallel_tuple_cost=0; +ERROR: unrecognized configuration parameter "parallel_tuple_cost" +SET min_parallel_relation_size=0; +ERROR: unrecognized configuration parameter "min_parallel_relation_size" +SET max_parallel_workers_per_gather=4; +ERROR: unrecognized configuration parameter "max_parallel_workers_per_gather" +-- ensure local plans display correctly +CREATE TABLE lineitem_clone (LIKE lineitem); +EXPLAIN (COSTS FALSE) SELECT avg(l_linenumber) FROM lineitem_clone; +Aggregate + -> Seq Scan on lineitem_clone +-- ensure distributed plans don't break +EXPLAIN (COSTS FALSE) SELECT avg(l_linenumber) FROM lineitem; +Distributed Query into pg_merge_job_570037 + Executor: Task-Tracker + Task Count: 8 + Tasks Shown: One of 8 + -> Task + Node: host=localhost port=57637 dbname=regression + -> Aggregate + -> Seq Scan on lineitem_290001 lineitem +Master Query + -> Aggregate + -> Seq Scan on pg_merge_job_570037 diff --git a/src/test/regress/sql/multi_explain.sql b/src/test/regress/sql/multi_explain.sql index dc062c610..5a911d993 100644 --- a/src/test/regress/sql/multi_explain.sql +++ b/src/test/regress/sql/multi_explain.sql @@ -188,3 +188,16 @@ EXPLAIN (COSTS FALSE, FORMAT YAML) WHERE l_orderkey = o_orderkey AND o_custkey = c_custkey AND l_suppkey = s_suppkey; + +-- test parallel aggregates +SET parallel_setup_cost=0; +SET parallel_tuple_cost=0; +SET min_parallel_relation_size=0; +SET max_parallel_workers_per_gather=4; + +-- ensure local plans display correctly +CREATE TABLE lineitem_clone (LIKE lineitem); +EXPLAIN (COSTS FALSE) SELECT avg(l_linenumber) FROM lineitem_clone; + +-- ensure distributed plans don't break +EXPLAIN (COSTS FALSE) SELECT avg(l_linenumber) FROM lineitem;