From f54a8e53c0b3d45a7624c3367545dae906432415 Mon Sep 17 00:00:00 2001 From: Hadi Moshayedi Date: Tue, 2 Jun 2020 09:55:10 -0700 Subject: [PATCH 1/3] Remove unused consts from multi_explain.c --- src/backend/distributed/planner/multi_explain.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/backend/distributed/planner/multi_explain.c b/src/backend/distributed/planner/multi_explain.c index 21a91951f..53a8befe4 100644 --- a/src/backend/distributed/planner/multi_explain.c +++ b/src/backend/distributed/planner/multi_explain.c @@ -57,13 +57,6 @@ #include "utils/snapmgr.h" -/* OR-able flags for ExplainXMLTag() (explain.c) */ -#define X_OPENING 0 -#define X_CLOSING 1 -#define X_CLOSE_IMMEDIATE 2 -#define X_NOWHITESPACE 4 - - /* Config variables that enable printing distributed query plans */ bool ExplainDistributedQueries = true; bool ExplainAllTasks = false; From 02cff1a7c6d430ae58e59d8026fb0b990904463d Mon Sep 17 00:00:00 2001 From: Hadi Moshayedi Date: Tue, 2 Jun 2020 10:05:05 -0700 Subject: [PATCH 2/3] Test that EXPLAIN ANALYZE is not supported for some forms of INSERT/SELECT --- .../distributed/planner/multi_explain.c | 20 ++++++++++--------- .../expected/insert_select_repartition.out | 5 +++++ .../regress/expected/multi_insert_select.out | 8 ++++++++ .../regress/sql/insert_select_repartition.sql | 6 ++++++ src/test/regress/sql/multi_insert_select.sql | 8 ++++++++ 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/backend/distributed/planner/multi_explain.c b/src/backend/distributed/planner/multi_explain.c index 53a8befe4..b5b7a1b5e 100644 --- a/src/backend/distributed/planner/multi_explain.c +++ b/src/backend/distributed/planner/multi_explain.c @@ -141,21 +141,23 @@ CoordinatorInsertSelectExplainScan(CustomScanState *node, List *ancestors, char *queryString = NULL; int cursorOptions = CURSOR_OPT_PARALLEL_OK; - if (es->analyze) - { - /* avoiding double execution here is tricky, error out for now */ - ereport(ERROR, (errmsg("EXPLAIN ANALYZE is currently not supported for INSERT " - "... SELECT commands via the coordinator"))); - } - /* * Make a copy of the query, since pg_plan_query may scribble on it and later * stages of EXPLAIN require it. */ Query *queryCopy = copyObject(query); PlannedStmt *selectPlan = pg_plan_query(queryCopy, cursorOptions, params); - if (IsRedistributablePlan(selectPlan->planTree) && - IsSupportedRedistributionTarget(targetRelationId)) + bool repartition = IsRedistributablePlan(selectPlan->planTree) && + IsSupportedRedistributionTarget(targetRelationId); + + if (es->analyze) + { + ereport(ERROR, (errmsg("EXPLAIN ANALYZE is currently not supported for INSERT " + "... SELECT commands %s", + repartition ? "with repartitioning" : "via coordinator"))); + } + + if (repartition) { ExplainPropertyText("INSERT/SELECT method", "repartition", es); } diff --git a/src/test/regress/expected/insert_select_repartition.out b/src/test/regress/expected/insert_select_repartition.out index 1e3b95a7b..54353c21d 100644 --- a/src/test/regress/expected/insert_select_repartition.out +++ b/src/test/regress/expected/insert_select_repartition.out @@ -573,6 +573,11 @@ EXPLAIN INSERT INTO target_table SELECT a, max(b) FROM source_table GROUP BY a; -> Seq Scan on source_table_4213606 source_table (cost=0.00..32.60 rows=2260 width=8) (10 rows) +-- +-- EXPLAIN ANALYZE is currently not supported +-- +EXPLAIN ANALYZE INSERT INTO target_table SELECT a, max(b) FROM source_table GROUP BY a; +ERROR: EXPLAIN ANALYZE is currently not supported for INSERT ... SELECT commands with repartitioning -- -- Duplicate names in target list -- diff --git a/src/test/regress/expected/multi_insert_select.out b/src/test/regress/expected/multi_insert_select.out index 138a30795..d1e00a728 100644 --- a/src/test/regress/expected/multi_insert_select.out +++ b/src/test/regress/expected/multi_insert_select.out @@ -910,6 +910,14 @@ $Q$); Task Count: 4 (4 rows) +-- EXPLAIN ANALYZE is not supported for INSERT ... SELECT via coordinator +EXPLAIN (costs off, analyze on) + INSERT INTO agg_events (user_id) + SELECT + raw_events_first.user_id + FROM + raw_events_first INNER JOIN raw_events_second ON raw_events_first.value_1 = raw_events_second.value_1; +ERROR: EXPLAIN ANALYZE is currently not supported for INSERT ... SELECT commands via coordinator -- even if there is a filter on the partition key, since the join is not on the partition key we reject -- this query INSERT INTO agg_events (user_id) diff --git a/src/test/regress/sql/insert_select_repartition.sql b/src/test/regress/sql/insert_select_repartition.sql index 8d8b625ea..790bcbd73 100644 --- a/src/test/regress/sql/insert_select_repartition.sql +++ b/src/test/regress/sql/insert_select_repartition.sql @@ -271,6 +271,12 @@ SELECT * FROM target_table ORDER BY a; EXPLAIN INSERT INTO target_table SELECT a, max(b) FROM source_table GROUP BY a; +-- +-- EXPLAIN ANALYZE is currently not supported +-- + +EXPLAIN ANALYZE INSERT INTO target_table SELECT a, max(b) FROM source_table GROUP BY a; + -- -- Duplicate names in target list -- diff --git a/src/test/regress/sql/multi_insert_select.sql b/src/test/regress/sql/multi_insert_select.sql index c71dbbb45..dc8040d8e 100644 --- a/src/test/regress/sql/multi_insert_select.sql +++ b/src/test/regress/sql/multi_insert_select.sql @@ -677,6 +677,14 @@ SET client_min_messages TO WARNING; raw_events_first INNER JOIN raw_events_second ON raw_events_first.value_1 = raw_events_second.value_1; $Q$); +-- EXPLAIN ANALYZE is not supported for INSERT ... SELECT via coordinator +EXPLAIN (costs off, analyze on) + INSERT INTO agg_events (user_id) + SELECT + raw_events_first.user_id + FROM + raw_events_first INNER JOIN raw_events_second ON raw_events_first.value_1 = raw_events_second.value_1; + -- even if there is a filter on the partition key, since the join is not on the partition key we reject -- this query INSERT INTO agg_events (user_id) From 45a41e249f4f44af31cfc945965fbd2261aea167 Mon Sep 17 00:00:00 2001 From: Hadi Moshayedi Date: Tue, 2 Jun 2020 10:07:48 -0700 Subject: [PATCH 3/3] Test EXPLAIN ANALYZE doesn't show repartition join tasks --- src/test/regress/expected/multi_explain.out | 21 +++++++++++++++++++++ src/test/regress/sql/multi_explain.sql | 11 +++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/test/regress/expected/multi_explain.out b/src/test/regress/expected/multi_explain.out index 7ca2f509f..d43441d61 100644 --- a/src/test/regress/expected/multi_explain.out +++ b/src/test/regress/expected/multi_explain.out @@ -289,6 +289,27 @@ Sort (actual rows=50 loops=1) -> HashAggregate (actual rows=50 loops=1) Group Key: l_quantity -> Seq Scan on lineitem_290000 lineitem (actual rows=6000 loops=1) +-- EXPLAIN ANALYZE doesn't show worker tasks for repartition joins yet +SET citus.shard_count TO 3; +CREATE TABLE t1(a int, b int); +CREATE TABLE t2(a int, b int); +SELECT create_distributed_table('t1', 'a'), create_distributed_table('t2', 'a'); +| +BEGIN; +SET LOCAL citus.enable_repartition_joins TO true; +EXPLAIN (COSTS off, ANALYZE on, TIMING off, SUMMARY off) SELECT count(*) FROM t1, t2 WHERE t1.a=t2.b; +Aggregate (actual rows=1 loops=1) + -> Custom Scan (Citus Adaptive) (actual rows=4 loops=1) + Task Count: 4 + Tasks Shown: None, not supported for re-partition queries + -> MapMergeJob + Map Task Count: 3 + Merge Task Count: 4 + -> MapMergeJob + Map Task Count: 3 + Merge Task Count: 4 +END; +DROP TABLE t1, t2; -- Test verbose EXPLAIN (COSTS FALSE, VERBOSE TRUE) SELECT sum(l_quantity) / avg(l_quantity) FROM lineitem; diff --git a/src/test/regress/sql/multi_explain.sql b/src/test/regress/sql/multi_explain.sql index 573e42dbc..84e62b73c 100644 --- a/src/test/regress/sql/multi_explain.sql +++ b/src/test/regress/sql/multi_explain.sql @@ -85,6 +85,17 @@ EXPLAIN (COSTS FALSE, ANALYZE TRUE, TIMING FALSE, SUMMARY FALSE) SELECT l_quantity, count(*) count_quantity FROM lineitem GROUP BY l_quantity ORDER BY count_quantity, l_quantity; +-- EXPLAIN ANALYZE doesn't show worker tasks for repartition joins yet +SET citus.shard_count TO 3; +CREATE TABLE t1(a int, b int); +CREATE TABLE t2(a int, b int); +SELECT create_distributed_table('t1', 'a'), create_distributed_table('t2', 'a'); +BEGIN; +SET LOCAL citus.enable_repartition_joins TO true; +EXPLAIN (COSTS off, ANALYZE on, TIMING off, SUMMARY off) SELECT count(*) FROM t1, t2 WHERE t1.a=t2.b; +END; +DROP TABLE t1, t2; + -- Test verbose EXPLAIN (COSTS FALSE, VERBOSE TRUE) SELECT sum(l_quantity) / avg(l_quantity) FROM lineitem;