From 2bff1d111fe0c2c860f1e873b270995452464cc5 Mon Sep 17 00:00:00 2001 From: Jinbao Chen Date: Tue, 10 Nov 2026 11:49:50 -0500 Subject: [PATCH 1/2] Optionally share CTE references that have no quals to push down A CTE referenced more than once is inlined by default: each reference is planned as a separate subquery, with its own quals pushed down into it. With gp_cte_sharing, all references share a single computation instead, but then none of their quals can be pushed down. Which is better depends on the query. At TPC-DS scale factor 10, with the Postgres planner, gp_cte_sharing makes q23 1.8x faster, where both references are "x IN (SELECT ... FROM cte)", but q04 5.9x, q11 6.0x and q31 6.2x slower. In q31 each of three references to a CTE filters on a different quarter: inlined, each copy pushes its filter down and the partition selectors skip 420 partition scans; shared, the CTE computes all quarters and years, scanning 6.6 times as many store_sales rows. Over all 99 queries, turning on gp_cte_sharing makes the total 15% slower. Add gp_cte_sharing_auto (off by default; only used when gp_cte_sharing is off). It decides per reference: a reference that has quals that can be pushed down into the CTE is inlined, as without sharing, and the others share a single computation of the CTE. The new cte_ref_has_pushable_quals() makes the same checks as push_down_restrict(), without pushing anything down, as push_down_restrict() removes the quals it pushes from the rel's restrictions. The CTE is shared only if its planned result is partitioned across the segments. That is where sharing pays off, and otherwise a reference executed in the QD and one executed in the segments may need the same Shared Scan, which fails with "cannot share ShareInputScan between QD and primary reader/write gang"; gp_cte_sharing fails like that, for example, in gp_stat_reset_single_table_counters(). To check, the shared plan is made before the decision; plan_shared_cte() is split out of set_cte_pathlist() for that. Like gp_cte_sharing, the option is turned off in subqueries planned at lower levels, to avoid deadlocks between Shared Scans, and doesn't apply to recursive CTEs, CTEs that aren't SELECTs, or CTEs with volatile functions. MATERIALIZED and NOT MATERIALIZED still take precedence. At scale factor 10, 8 of the 99 TPC-DS queries change plan, none gets slower, and the total goes from 302.3 s to 275.4 s; q23 from 45.7 s to 25.3 s, q14 from 26.3 s to 22.5 s, q59 from 4.0 s to 3.0 s. The queries that gp_cte_sharing makes slower don't change. The results are unchanged. This is a heuristic. Where all references filter the CTE, they keep the inlined plans, even if sharing would pay off anyway: gp_cte_sharing makes q74 twice as fast, gp_cte_sharing_auto leaves it as it is. --- src/backend/optimizer/path/allpaths.c | 156 +++++++++++++--- src/backend/optimizer/plan/planmain.c | 1 + src/backend/optimizer/plan/subselect.c | 1 + src/backend/utils/misc/guc_gp.c | 14 ++ src/include/cdb/cdbvars.h | 1 + src/include/nodes/plannerconfig.h | 1 + src/include/utils/unsync_guc_name.h | 1 + src/test/regress/expected/with_clause.out | 174 ++++++++++++++++++ .../expected/with_clause_optimizer.out | 174 ++++++++++++++++++ src/test/regress/sql/with_clause.sql | 53 ++++++ 10 files changed, 548 insertions(+), 28 deletions(-) diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c index 6bb0f9a92a5..5ba49fbed2c 100644 --- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -3369,6 +3369,89 @@ set_tablefunc_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte) root); } +/* + * Would push_down_restrict() push any of the quals of this CTE reference + * into the CTE query? Unlike push_down_restrict(), this doesn't change + * anything. + */ +static bool +cte_ref_has_pushable_quals(RelOptInfo *rel, RangeTblEntry *rte, Query *subquery) +{ + pushdown_safety_info safetyInfo; + bool result = false; + ListCell *l; + + if (rel->baserestrictinfo == NIL) + return false; + + memset(&safetyInfo, 0, sizeof(safetyInfo)); + safetyInfo.unsafeFlags = (unsigned char *) + palloc0((list_length(subquery->targetList) + 1) * sizeof(unsigned char)); + safetyInfo.unsafeLeaky = rte->security_barrier; + + if (subquery_is_pushdown_safe(subquery, subquery, &safetyInfo)) + { + foreach(l, rel->baserestrictinfo) + { + RestrictInfo *rinfo = (RestrictInfo *) lfirst(l); + + if (!rinfo->pseudoconstant && + qual_is_pushdown_safe(subquery, rel->relid, rinfo, &safetyInfo) == PUSHDOWN_SAFE) + { + result = true; + break; + } + } + } + pfree(safetyInfo.unsafeFlags); + + return result; +} + +/* + * Plan CTE 'cte' for sharing among its references, if that hasn't been done + * yet, and return its PlannerInfo. 'subquery' is a copy of the CTE query, which + * subquery_planner() may scribble on. + */ +static PlannerInfo * +plan_shared_cte(PlannerInfo *root, PlannerInfo *cteroot, CtePlanInfo *cteplaninfo, + CommonTableExpr *cte, Query *subquery, double tuple_fraction) +{ + PlannerConfig *config; + PlannerInfo *subroot; + RelOptInfo *sub_final_rel; + + if (cteplaninfo->subroot != NULL) + return cteplaninfo->subroot; + + config = CopyPlannerConfig(root->config); + + /* + * Having multiple SharedScans can lead to deadlocks. For now, disallow + * sharing of ctes at lower levels. + */ + config->gp_cte_sharing = false; + config->gp_cte_sharing_auto = false; + + config->honor_order_by = false; + + subroot = subquery_planner(cteroot->glob, subquery, cteroot, cte->cterecursive, + tuple_fraction, config); + + /* Select best Path and turn it into a Plan */ + sub_final_rel = fetch_upper_rel(subroot, UPPERREL_FINAL, NULL); + + /* + * we cannot use different plans for different instances of this CTE + * reference, so keep only the cheapest + */ + sub_final_rel->pathlist = list_make1(sub_final_rel->cheapest_total_path); + + cteplaninfo->subroot = subroot; + + return subroot; +} + /* * set_cte_pathlist * Build the (single) access path for a non-self-reference CTE RTE @@ -3392,6 +3475,7 @@ set_cte_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte) RelOptInfo *sub_final_rel; Relids required_outer; bool is_shared; + bool shared_by_auto = false; Query *subquery = NULL; bool contain_volatile_function = false; @@ -3487,6 +3571,25 @@ set_cte_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte) /* if plan sharing is enabled and contains volatile functions in the CTE query, also generate a shared scan plan */ is_shared = root->config->gp_cte_sharing && (cte->cterefcount > 1 || contain_volatile_function); + /* + * GPDB: gp_cte_sharing_auto. Sharing a CTE computes it once for all + * references, but then none of the references' quals can be pushed + * down into it. When the references filter the CTE differently, + * e.g. on different years, the shared CTE computes all of them, and + * loses partition pruning too, which can be many times slower than + * computing each filtered copy. So share only the references that + * have no quals that could be pushed down; the others are planned + * as separate subqueries with their quals pushed down, as without + * sharing. + */ + if (!is_shared && root->config->gp_cte_sharing_auto && + cte->cterefcount > 1 && !contain_volatile_function && + !cte->cterecursive && subquery->commandType == CMD_SELECT) + { + is_shared = !cte_ref_has_pushable_quals(rel, rte, subquery); + shared_by_auto = is_shared; + } + } /* @@ -3496,6 +3599,28 @@ set_cte_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte) if (is_shared && contain_outer_selfref(cte->ctequery)) is_shared = false; + /* + * GPDB: gp_cte_sharing_auto. Share the CTE only if its result is spread + * across the segments. That is where sharing pays off, and otherwise a + * reference executed in the QD, e.g. on a CTE without a FROM, and one + * executed in the segments, e.g. joined with gp_dist_random(), would need + * the same Shared Scan in the QD and in a primary gang, which is not + * supported. Plan the shared CTE from a fresh copy, as subquery_planner() + * may scribble on it, and 'subquery' is still needed if we inline it. + */ + if (shared_by_auto) + { + PlannerInfo *shared_root; + Path *shared_path; + + shared_root = plan_shared_cte(root, cteroot, cteplaninfo, cte, + (Query *) copyObject(cte->ctequery), + tuple_fraction); + shared_path = fetch_upper_rel(shared_root, UPPERREL_FINAL, NULL)->cheapest_total_path; + if (!CdbPathLocus_IsPartitioned(shared_path->locus)) + is_shared = false; + } + if (!is_shared) { PlannerConfig *config = CopyPlannerConfig(root->config); @@ -3505,6 +3630,7 @@ set_cte_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte) * disallow sharing of ctes at lower levels. */ config->gp_cte_sharing = false; + config->gp_cte_sharing_auto = false; config->honor_order_by = false; @@ -3554,34 +3680,8 @@ set_cte_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte) * subplan will not be used by InitPlans, so that they can be shared * if this CTE is referenced multiple times (excluding in InitPlans). */ - if (cteplaninfo->subroot == NULL) - { - PlannerConfig *config = CopyPlannerConfig(root->config); - - /* - * Having multiple SharedScans can lead to deadlocks. For now, - * disallow sharing of ctes at lower levels. - */ - config->gp_cte_sharing = false; - - config->honor_order_by = false; - - subroot = subquery_planner(cteroot->glob, subquery, cteroot, cte->cterecursive, - tuple_fraction, config); - - /* Select best Path and turn it into a Plan */ - sub_final_rel = fetch_upper_rel(subroot, UPPERREL_FINAL, NULL); - - /* - * we cannot use different plans for different instances of this CTE - * reference, so keep only the cheapest - */ - sub_final_rel->pathlist = list_make1(sub_final_rel->cheapest_total_path); - - cteplaninfo->subroot = subroot; - } - else - subroot = cteplaninfo->subroot; + subroot = plan_shared_cte(root, cteroot, cteplaninfo, cte, subquery, + tuple_fraction); } rel->subroot = subroot; diff --git a/src/backend/optimizer/plan/planmain.c b/src/backend/optimizer/plan/planmain.c index 728b340fd24..df37cb93148 100644 --- a/src/backend/optimizer/plan/planmain.c +++ b/src/backend/optimizer/plan/planmain.c @@ -354,6 +354,7 @@ PlannerConfig *DefaultPlannerConfig(void) c1->gp_enable_direct_dispatch = gp_enable_direct_dispatch; c1->gp_cte_sharing = gp_cte_sharing; + c1->gp_cte_sharing_auto = gp_cte_sharing_auto; c1->honor_order_by = true; diff --git a/src/backend/optimizer/plan/subselect.c b/src/backend/optimizer/plan/subselect.c index 74d7b811ca2..5d3f3c9fcf2 100644 --- a/src/backend/optimizer/plan/subselect.c +++ b/src/backend/optimizer/plan/subselect.c @@ -389,6 +389,7 @@ make_subplan(PlannerInfo *root, Query *orig_subquery, * See github issue: https://github.com/greenplum-db/gpdb/issues/12701 */ config->gp_cte_sharing = false; + config->gp_cte_sharing_auto = false; } /* * Strictly speaking, the order of rows in a subquery doesn't matter. diff --git a/src/backend/utils/misc/guc_gp.c b/src/backend/utils/misc/guc_gp.c index 11f5588b79c..eca34b56be3 100644 --- a/src/backend/utils/misc/guc_gp.c +++ b/src/backend/utils/misc/guc_gp.c @@ -286,6 +286,7 @@ bool gp_enable_agg_pushdown = false; bool gp_dynamic_partition_pruning = true; bool gp_log_dynamic_partition_pruning = false; bool gp_cte_sharing = false; +bool gp_cte_sharing_auto = false; bool gp_enable_relsize_collection = false; bool gp_recursive_cte = true; bool gp_eager_two_phase_agg = false; @@ -1799,6 +1800,19 @@ struct config_bool ConfigureNamesBool_gp[] = NULL, NULL, NULL }, + { + {"gp_cte_sharing_auto", PGC_USERSET, QUERY_TUNING_METHOD, + gettext_noop("Share CTE references that have no quals to push down."), + gettext_noop("Only used if gp_cte_sharing is off. A CTE referenced more than once is " + "computed once and shared by the references that don't filter it; references " + "with quals that can be pushed down into the CTE get their own filtered copy."), + GUC_NOT_IN_SAMPLE | GUC_EXPLAIN + }, + &gp_cte_sharing_auto, + false, + NULL, NULL, NULL + }, + { {"gp_cte_sharing", PGC_USERSET, QUERY_TUNING_METHOD, gettext_noop("This guc enables sharing of plan fragments for common table expressions."), diff --git a/src/include/cdb/cdbvars.h b/src/include/cdb/cdbvars.h index efd05538a17..59d26e01e00 100644 --- a/src/include/cdb/cdbvars.h +++ b/src/include/cdb/cdbvars.h @@ -655,6 +655,7 @@ extern bool gp_dynamic_partition_pruning; /* Sharing of plan fragments for common table expressions */ extern bool gp_cte_sharing; +extern bool gp_cte_sharing_auto; /* Enable RECURSIVE clauses in common table expressions */ extern bool gp_recursive_cte; diff --git a/src/include/nodes/plannerconfig.h b/src/include/nodes/plannerconfig.h index 923b9f6d4da..f0eb7ef14e7 100644 --- a/src/include/nodes/plannerconfig.h +++ b/src/include/nodes/plannerconfig.h @@ -18,6 +18,7 @@ typedef struct PlannerConfig bool gp_enable_direct_dispatch; bool gp_cte_sharing; /* Indicate whether sharing is to be disabled on any CTEs */ + bool gp_cte_sharing_auto; /* decide per CTE reference whether to share */ bool honor_order_by; diff --git a/src/include/utils/unsync_guc_name.h b/src/include/utils/unsync_guc_name.h index e2fa575da4f..7e34bcc49b5 100644 --- a/src/include/utils/unsync_guc_name.h +++ b/src/include/utils/unsync_guc_name.h @@ -174,6 +174,7 @@ "gp_cost_hashjoin_chainwalk", "gp_create_table_random_default_distribution", "gp_cte_sharing", + "gp_cte_sharing_auto", "gp_dbid", "gp_debug_pgproc", "gp_debug_resqueue_priority", diff --git a/src/test/regress/expected/with_clause.out b/src/test/regress/expected/with_clause.out index d8ba2a29448..02c7be538ee 100644 --- a/src/test/regress/expected/with_clause.out +++ b/src/test/regress/expected/with_clause.out @@ -2405,3 +2405,177 @@ SELECT EXISTS( (1 row) DROP TABLE foo_issue_1204_test; +-- +-- gp_cte_sharing_auto: a CTE referenced more than once is shared by the +-- references that have no quals to push down into it, and inlined, with the +-- quals pushed down, for those that have. +-- +create table cte_auto (a int, b int) distributed by (a); +insert into cte_auto select i, i % 10 from generate_series(1, 1000) i; +analyze cte_auto; +set optimizer = off; +set gp_cte_sharing = off; +set gp_cte_sharing_auto = on; +-- no quals on the references: shared +explain (costs off) +with c as (select b, count(*) n from cte_auto group by b) +select count(*) from cte_auto where b in (select b from c) +union all +select count(*) from cte_auto where a in (select b from c); + QUERY PLAN +------------------------------------------------------------------------------------------------------------ + Append + -> Finalize Aggregate + -> Gather Motion 3:1 (slice1; segments: 3) + -> Partial Aggregate + -> Hash Semi Join + Hash Cond: (cte_auto.b = c.b) + -> Seq Scan on cte_auto + -> Hash + -> Broadcast Motion 3:3 (slice2; segments: 3) + -> Subquery Scan on c + -> Shared Scan (share slice:id 2:0) + -> Finalize HashAggregate + Group Key: cte_auto_1.b + -> Redistribute Motion 3:3 (slice3; segments: 3) + Hash Key: cte_auto_1.b + -> Streaming Partial HashAggregate + Group Key: cte_auto_1.b + -> Seq Scan on cte_auto cte_auto_1 + -> Finalize Aggregate + -> Gather Motion 3:1 (slice4; segments: 3) + -> Partial Aggregate + -> Hash Semi Join + Hash Cond: (cte_auto_2.a = c_1.b) + -> Seq Scan on cte_auto cte_auto_2 + -> Hash + -> Subquery Scan on c_1 + -> Shared Scan (share slice:id 4:0) + Optimizer: Postgres query optimizer +(28 rows) + +with c as (select b, count(*) n from cte_auto group by b) +select count(*) from cte_auto where b in (select b from c) +union all +select count(*) from cte_auto where a in (select b from c); + count +------- + 1000 + 9 +(2 rows) + +-- each reference filters differently: inlined, with the quals pushed down +explain (costs off) +with c as (select b, count(*) n from cte_auto group by b) +select c1.n, c2.n from c c1, c c2 where c1.b = 1 and c2.b = 2; + QUERY PLAN +--------------------------------------------------------------- + Nested Loop + -> Finalize GroupAggregate + -> Gather Motion 3:1 (slice1; segments: 3) + -> Partial GroupAggregate + -> Seq Scan on cte_auto + Filter: (b = 1) + -> Materialize + -> Finalize GroupAggregate + -> Gather Motion 3:1 (slice2; segments: 3) + -> Partial GroupAggregate + -> Seq Scan on cte_auto cte_auto_1 + Filter: (b = 2) + Optimizer: Postgres query optimizer +(13 rows) + +with c as (select b, count(*) n from cte_auto group by b) +select c1.n, c2.n from c c1, c c2 where c1.b = 1 and c2.b = 2; + n | n +-----+----- + 100 | 100 +(1 row) + +-- one reference filters, the other doesn't: the first is inlined, the second +-- reads a shared scan of the CTE that has no other consumer +explain (costs off) +with c as (select b, count(*) n from cte_auto group by b) +select c1.b, c1.n, c2.n from c c1 join c c2 on c1.b = c2.b where c1.n > 99 +order by 1; + QUERY PLAN +------------------------------------------------------------------------------ + Gather Motion 3:1 (slice1; segments: 3) + Merge Key: cte_auto_1.b + -> Sort + Sort Key: cte_auto_1.b + -> Hash Join + Hash Cond: (share0_ref1.b = cte_auto_1.b) + -> Shared Scan (share slice:id 1:0) + -> Finalize HashAggregate + Group Key: cte_auto.b + -> Redistribute Motion 3:3 (slice2; segments: 3) + Hash Key: cte_auto.b + -> Streaming Partial HashAggregate + Group Key: cte_auto.b + -> Seq Scan on cte_auto + -> Hash + -> Finalize HashAggregate + Group Key: cte_auto_1.b + Filter: (count(*) > 99) + -> Redistribute Motion 3:3 (slice3; segments: 3) + Hash Key: cte_auto_1.b + -> Streaming Partial HashAggregate + Group Key: cte_auto_1.b + -> Seq Scan on cte_auto cte_auto_1 + Optimizer: Postgres query optimizer +(24 rows) + +with c as (select b, count(*) n from cte_auto group by b) +select c1.b, c1.n, c2.n from c c1 join c c2 on c1.b = c2.b where c1.n > 99 +order by 1; + b | n | n +---+-----+----- + 0 | 100 | 100 + 1 | 100 | 100 + 2 | 100 | 100 + 3 | 100 | 100 + 4 | 100 | 100 + 5 | 100 | 100 + 6 | 100 | 100 + 7 | 100 | 100 + 8 | 100 | 100 + 9 | 100 | 100 +(10 rows) + +-- a CTE whose result isn't spread across the segments is not shared: here one +-- reference is executed in the QD, because of the volatile function, and the +-- other in the segments, and they couldn't share a Shared Scan +explain (costs off) +with c as (select 1 as x) +select x, random() >= 0 as r from c +union all +select x, random() >= 0 from c, gp_dist_random('gp_id'); + QUERY PLAN +------------------------------------------------ + Append + -> Subquery Scan on c + -> Result + -> Gather Motion 3:1 (slice1; segments: 3) + -> Nested Loop + -> Result + -> Seq Scan on gp_id + Optimizer: Postgres query optimizer +(8 rows) + +with c as (select 1 as x) +select x, random() >= 0 as r from c +union all +select x, random() >= 0 from c, gp_dist_random('gp_id'); + x | r +---+--- + 1 | t + 1 | t + 1 | t + 1 | t +(4 rows) + +reset gp_cte_sharing_auto; +reset gp_cte_sharing; +reset optimizer; +drop table cte_auto; diff --git a/src/test/regress/expected/with_clause_optimizer.out b/src/test/regress/expected/with_clause_optimizer.out index cabbf41e1b2..d7323b9575c 100644 --- a/src/test/regress/expected/with_clause_optimizer.out +++ b/src/test/regress/expected/with_clause_optimizer.out @@ -2414,3 +2414,177 @@ SELECT EXISTS( (1 row) DROP TABLE foo_issue_1204_test; +-- +-- gp_cte_sharing_auto: a CTE referenced more than once is shared by the +-- references that have no quals to push down into it, and inlined, with the +-- quals pushed down, for those that have. +-- +create table cte_auto (a int, b int) distributed by (a); +insert into cte_auto select i, i % 10 from generate_series(1, 1000) i; +analyze cte_auto; +set optimizer = off; +set gp_cte_sharing = off; +set gp_cte_sharing_auto = on; +-- no quals on the references: shared +explain (costs off) +with c as (select b, count(*) n from cte_auto group by b) +select count(*) from cte_auto where b in (select b from c) +union all +select count(*) from cte_auto where a in (select b from c); + QUERY PLAN +------------------------------------------------------------------------------------------------------------ + Append + -> Finalize Aggregate + -> Gather Motion 3:1 (slice1; segments: 3) + -> Partial Aggregate + -> Hash Semi Join + Hash Cond: (cte_auto.b = c.b) + -> Seq Scan on cte_auto + -> Hash + -> Broadcast Motion 3:3 (slice2; segments: 3) + -> Subquery Scan on c + -> Shared Scan (share slice:id 2:0) + -> Finalize HashAggregate + Group Key: cte_auto_1.b + -> Redistribute Motion 3:3 (slice3; segments: 3) + Hash Key: cte_auto_1.b + -> Streaming Partial HashAggregate + Group Key: cte_auto_1.b + -> Seq Scan on cte_auto cte_auto_1 + -> Finalize Aggregate + -> Gather Motion 3:1 (slice4; segments: 3) + -> Partial Aggregate + -> Hash Semi Join + Hash Cond: (cte_auto_2.a = c_1.b) + -> Seq Scan on cte_auto cte_auto_2 + -> Hash + -> Subquery Scan on c_1 + -> Shared Scan (share slice:id 4:0) + Optimizer: Postgres query optimizer +(28 rows) + +with c as (select b, count(*) n from cte_auto group by b) +select count(*) from cte_auto where b in (select b from c) +union all +select count(*) from cte_auto where a in (select b from c); + count +------- + 1000 + 9 +(2 rows) + +-- each reference filters differently: inlined, with the quals pushed down +explain (costs off) +with c as (select b, count(*) n from cte_auto group by b) +select c1.n, c2.n from c c1, c c2 where c1.b = 1 and c2.b = 2; + QUERY PLAN +--------------------------------------------------------------- + Nested Loop + -> Finalize GroupAggregate + -> Gather Motion 3:1 (slice1; segments: 3) + -> Partial GroupAggregate + -> Seq Scan on cte_auto + Filter: (b = 1) + -> Materialize + -> Finalize GroupAggregate + -> Gather Motion 3:1 (slice2; segments: 3) + -> Partial GroupAggregate + -> Seq Scan on cte_auto cte_auto_1 + Filter: (b = 2) + Optimizer: Postgres query optimizer +(13 rows) + +with c as (select b, count(*) n from cte_auto group by b) +select c1.n, c2.n from c c1, c c2 where c1.b = 1 and c2.b = 2; + n | n +-----+----- + 100 | 100 +(1 row) + +-- one reference filters, the other doesn't: the first is inlined, the second +-- reads a shared scan of the CTE that has no other consumer +explain (costs off) +with c as (select b, count(*) n from cte_auto group by b) +select c1.b, c1.n, c2.n from c c1 join c c2 on c1.b = c2.b where c1.n > 99 +order by 1; + QUERY PLAN +------------------------------------------------------------------------------ + Gather Motion 3:1 (slice1; segments: 3) + Merge Key: cte_auto_1.b + -> Sort + Sort Key: cte_auto_1.b + -> Hash Join + Hash Cond: (share0_ref1.b = cte_auto_1.b) + -> Shared Scan (share slice:id 1:0) + -> Finalize HashAggregate + Group Key: cte_auto.b + -> Redistribute Motion 3:3 (slice2; segments: 3) + Hash Key: cte_auto.b + -> Streaming Partial HashAggregate + Group Key: cte_auto.b + -> Seq Scan on cte_auto + -> Hash + -> Finalize HashAggregate + Group Key: cte_auto_1.b + Filter: (count(*) > 99) + -> Redistribute Motion 3:3 (slice3; segments: 3) + Hash Key: cte_auto_1.b + -> Streaming Partial HashAggregate + Group Key: cte_auto_1.b + -> Seq Scan on cte_auto cte_auto_1 + Optimizer: Postgres query optimizer +(24 rows) + +with c as (select b, count(*) n from cte_auto group by b) +select c1.b, c1.n, c2.n from c c1 join c c2 on c1.b = c2.b where c1.n > 99 +order by 1; + b | n | n +---+-----+----- + 0 | 100 | 100 + 1 | 100 | 100 + 2 | 100 | 100 + 3 | 100 | 100 + 4 | 100 | 100 + 5 | 100 | 100 + 6 | 100 | 100 + 7 | 100 | 100 + 8 | 100 | 100 + 9 | 100 | 100 +(10 rows) + +-- a CTE whose result isn't spread across the segments is not shared: here one +-- reference is executed in the QD, because of the volatile function, and the +-- other in the segments, and they couldn't share a Shared Scan +explain (costs off) +with c as (select 1 as x) +select x, random() >= 0 as r from c +union all +select x, random() >= 0 from c, gp_dist_random('gp_id'); + QUERY PLAN +------------------------------------------------ + Append + -> Subquery Scan on c + -> Result + -> Gather Motion 3:1 (slice1; segments: 3) + -> Nested Loop + -> Result + -> Seq Scan on gp_id + Optimizer: Postgres query optimizer +(8 rows) + +with c as (select 1 as x) +select x, random() >= 0 as r from c +union all +select x, random() >= 0 from c, gp_dist_random('gp_id'); + x | r +---+--- + 1 | t + 1 | t + 1 | t + 1 | t +(4 rows) + +reset gp_cte_sharing_auto; +reset gp_cte_sharing; +reset optimizer; +drop table cte_auto; diff --git a/src/test/regress/sql/with_clause.sql b/src/test/regress/sql/with_clause.sql index 149edfe92af..adb32fe62bf 100644 --- a/src/test/regress/sql/with_clause.sql +++ b/src/test/regress/sql/with_clause.sql @@ -491,3 +491,56 @@ SELECT EXISTS( ); DROP TABLE foo_issue_1204_test; + +-- +-- gp_cte_sharing_auto: a CTE referenced more than once is shared by the +-- references that have no quals to push down into it, and inlined, with the +-- quals pushed down, for those that have. +-- +create table cte_auto (a int, b int) distributed by (a); +insert into cte_auto select i, i % 10 from generate_series(1, 1000) i; +analyze cte_auto; +set optimizer = off; +set gp_cte_sharing = off; +set gp_cte_sharing_auto = on; +-- no quals on the references: shared +explain (costs off) +with c as (select b, count(*) n from cte_auto group by b) +select count(*) from cte_auto where b in (select b from c) +union all +select count(*) from cte_auto where a in (select b from c); +with c as (select b, count(*) n from cte_auto group by b) +select count(*) from cte_auto where b in (select b from c) +union all +select count(*) from cte_auto where a in (select b from c); +-- each reference filters differently: inlined, with the quals pushed down +explain (costs off) +with c as (select b, count(*) n from cte_auto group by b) +select c1.n, c2.n from c c1, c c2 where c1.b = 1 and c2.b = 2; +with c as (select b, count(*) n from cte_auto group by b) +select c1.n, c2.n from c c1, c c2 where c1.b = 1 and c2.b = 2; +-- one reference filters, the other doesn't: the first is inlined, the second +-- reads a shared scan of the CTE that has no other consumer +explain (costs off) +with c as (select b, count(*) n from cte_auto group by b) +select c1.b, c1.n, c2.n from c c1 join c c2 on c1.b = c2.b where c1.n > 99 +order by 1; +with c as (select b, count(*) n from cte_auto group by b) +select c1.b, c1.n, c2.n from c c1 join c c2 on c1.b = c2.b where c1.n > 99 +order by 1; +-- a CTE whose result isn't spread across the segments is not shared: here one +-- reference is executed in the QD, because of the volatile function, and the +-- other in the segments, and they couldn't share a Shared Scan +explain (costs off) +with c as (select 1 as x) +select x, random() >= 0 as r from c +union all +select x, random() >= 0 from c, gp_dist_random('gp_id'); +with c as (select 1 as x) +select x, random() >= 0 as r from c +union all +select x, random() >= 0 from c, gp_dist_random('gp_id'); +reset gp_cte_sharing_auto; +reset gp_cte_sharing; +reset optimizer; +drop table cte_auto; From 131b704238e963947a8c8637e3fb9f2baefdca7a Mon Sep 17 00:00:00 2001 From: Jinbao Chen Date: Thu, 19 Nov 2026 18:56:27 -0500 Subject: [PATCH 2/2] Share CTE references without pushable quals by default Drop gp_cte_sharing_auto: when gp_cte_sharing is off, the planner now always decides per reference whether to share a CTE. A reference with quals that can be pushed down into the CTE is still inlined, so the queries that gp_cte_sharing makes slower keep their plans. The per-level switch in PlannerConfig is renamed cte_sharing_auto; it is still turned off in subqueries planned at lower levels. Update the expected plans that now use a Shared Scan, in cte_prune, cte_prune_multi_consumer, dedupset, gporca, shared_scan and table_functions, including queries in the ORCA answer files that fall back to the Postgres planner. Query results are unchanged. --- src/backend/optimizer/path/allpaths.c | 39 +- src/backend/optimizer/plan/planmain.c | 2 +- src/backend/optimizer/plan/subselect.c | 2 +- src/backend/utils/misc/guc_gp.c | 14 - src/include/cdb/cdbvars.h | 1 - src/include/nodes/plannerconfig.h | 3 +- src/include/utils/unsync_guc_name.h | 1 - src/test/regress/expected/cte_prune.out | 1134 +++++++++-------- .../expected/cte_prune_multi_consumer.out | 39 +- src/test/regress/expected/dedupset.out | 216 ++-- src/test/regress/expected/gporca.out | 78 +- src/test/regress/expected/shared_scan.out | 40 +- .../expected/shared_scan_optimizer.out | 25 +- src/test/regress/expected/table_functions.out | 41 +- .../expected/table_functions_optimizer.out | 31 +- src/test/regress/expected/with_clause.out | 4 +- .../expected/with_clause_optimizer.out | 4 +- src/test/regress/sql/with_clause.sql | 4 +- 18 files changed, 847 insertions(+), 831 deletions(-) diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c index 5ba49fbed2c..3ebc781dbaa 100644 --- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -3431,7 +3431,7 @@ plan_shared_cte(PlannerInfo *root, PlannerInfo *cteroot, CtePlanInfo *cteplaninf * sharing of ctes at lower levels. */ config->gp_cte_sharing = false; - config->gp_cte_sharing_auto = false; + config->cte_sharing_auto = false; config->honor_order_by = false; @@ -3572,17 +3572,17 @@ set_cte_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte) is_shared = root->config->gp_cte_sharing && (cte->cterefcount > 1 || contain_volatile_function); /* - * GPDB: gp_cte_sharing_auto. Sharing a CTE computes it once for all - * references, but then none of the references' quals can be pushed - * down into it. When the references filter the CTE differently, - * e.g. on different years, the shared CTE computes all of them, and - * loses partition pruning too, which can be many times slower than - * computing each filtered copy. So share only the references that - * have no quals that could be pushed down; the others are planned - * as separate subqueries with their quals pushed down, as without - * sharing. + * GPDB: when gp_cte_sharing is off, decide per reference. Sharing + * a CTE computes it once for all references, but then none of the + * references' quals can be pushed down into it. When the + * references filter the CTE differently, e.g. on different years, + * the shared CTE computes all of them, and loses partition pruning + * too, which can be many times slower than computing each filtered + * copy. So share only the references that have no quals that could + * be pushed down; the others are planned as separate subqueries + * with their quals pushed down, as without sharing. */ - if (!is_shared && root->config->gp_cte_sharing_auto && + if (!is_shared && root->config->cte_sharing_auto && cte->cterefcount > 1 && !contain_volatile_function && !cte->cterecursive && subquery->commandType == CMD_SELECT) { @@ -3600,13 +3600,14 @@ set_cte_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte) is_shared = false; /* - * GPDB: gp_cte_sharing_auto. Share the CTE only if its result is spread - * across the segments. That is where sharing pays off, and otherwise a - * reference executed in the QD, e.g. on a CTE without a FROM, and one - * executed in the segments, e.g. joined with gp_dist_random(), would need - * the same Shared Scan in the QD and in a primary gang, which is not - * supported. Plan the shared CTE from a fresh copy, as subquery_planner() - * may scribble on it, and 'subquery' is still needed if we inline it. + * GPDB: a CTE that is shared because the reference has no quals to push + * down is shared only if its result is spread across the segments. That + * is where sharing pays off, and otherwise a reference executed in the + * QD, e.g. on a CTE without a FROM, and one executed in the segments, e.g. + * joined with gp_dist_random(), would need the same Shared Scan in the QD + * and in a primary gang, which is not supported. Plan the shared CTE from + * a fresh copy, as subquery_planner() may scribble on it, and 'subquery' + * is still needed if we inline it. */ if (shared_by_auto) { @@ -3630,7 +3631,7 @@ set_cte_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte) * disallow sharing of ctes at lower levels. */ config->gp_cte_sharing = false; - config->gp_cte_sharing_auto = false; + config->cte_sharing_auto = false; config->honor_order_by = false; diff --git a/src/backend/optimizer/plan/planmain.c b/src/backend/optimizer/plan/planmain.c index df37cb93148..f708add1362 100644 --- a/src/backend/optimizer/plan/planmain.c +++ b/src/backend/optimizer/plan/planmain.c @@ -354,7 +354,7 @@ PlannerConfig *DefaultPlannerConfig(void) c1->gp_enable_direct_dispatch = gp_enable_direct_dispatch; c1->gp_cte_sharing = gp_cte_sharing; - c1->gp_cte_sharing_auto = gp_cte_sharing_auto; + c1->cte_sharing_auto = true; c1->honor_order_by = true; diff --git a/src/backend/optimizer/plan/subselect.c b/src/backend/optimizer/plan/subselect.c index 5d3f3c9fcf2..fb1d3c4f637 100644 --- a/src/backend/optimizer/plan/subselect.c +++ b/src/backend/optimizer/plan/subselect.c @@ -389,7 +389,7 @@ make_subplan(PlannerInfo *root, Query *orig_subquery, * See github issue: https://github.com/greenplum-db/gpdb/issues/12701 */ config->gp_cte_sharing = false; - config->gp_cte_sharing_auto = false; + config->cte_sharing_auto = false; } /* * Strictly speaking, the order of rows in a subquery doesn't matter. diff --git a/src/backend/utils/misc/guc_gp.c b/src/backend/utils/misc/guc_gp.c index eca34b56be3..11f5588b79c 100644 --- a/src/backend/utils/misc/guc_gp.c +++ b/src/backend/utils/misc/guc_gp.c @@ -286,7 +286,6 @@ bool gp_enable_agg_pushdown = false; bool gp_dynamic_partition_pruning = true; bool gp_log_dynamic_partition_pruning = false; bool gp_cte_sharing = false; -bool gp_cte_sharing_auto = false; bool gp_enable_relsize_collection = false; bool gp_recursive_cte = true; bool gp_eager_two_phase_agg = false; @@ -1800,19 +1799,6 @@ struct config_bool ConfigureNamesBool_gp[] = NULL, NULL, NULL }, - { - {"gp_cte_sharing_auto", PGC_USERSET, QUERY_TUNING_METHOD, - gettext_noop("Share CTE references that have no quals to push down."), - gettext_noop("Only used if gp_cte_sharing is off. A CTE referenced more than once is " - "computed once and shared by the references that don't filter it; references " - "with quals that can be pushed down into the CTE get their own filtered copy."), - GUC_NOT_IN_SAMPLE | GUC_EXPLAIN - }, - &gp_cte_sharing_auto, - false, - NULL, NULL, NULL - }, - { {"gp_cte_sharing", PGC_USERSET, QUERY_TUNING_METHOD, gettext_noop("This guc enables sharing of plan fragments for common table expressions."), diff --git a/src/include/cdb/cdbvars.h b/src/include/cdb/cdbvars.h index 59d26e01e00..efd05538a17 100644 --- a/src/include/cdb/cdbvars.h +++ b/src/include/cdb/cdbvars.h @@ -655,7 +655,6 @@ extern bool gp_dynamic_partition_pruning; /* Sharing of plan fragments for common table expressions */ extern bool gp_cte_sharing; -extern bool gp_cte_sharing_auto; /* Enable RECURSIVE clauses in common table expressions */ extern bool gp_recursive_cte; diff --git a/src/include/nodes/plannerconfig.h b/src/include/nodes/plannerconfig.h index f0eb7ef14e7..f42a9f6354f 100644 --- a/src/include/nodes/plannerconfig.h +++ b/src/include/nodes/plannerconfig.h @@ -18,7 +18,8 @@ typedef struct PlannerConfig bool gp_enable_direct_dispatch; bool gp_cte_sharing; /* Indicate whether sharing is to be disabled on any CTEs */ - bool gp_cte_sharing_auto; /* decide per CTE reference whether to share */ + bool cte_sharing_auto; /* share CTE references without pushable quals; + * turned off in lower-level subqueries */ bool honor_order_by; diff --git a/src/include/utils/unsync_guc_name.h b/src/include/utils/unsync_guc_name.h index 7e34bcc49b5..e2fa575da4f 100644 --- a/src/include/utils/unsync_guc_name.h +++ b/src/include/utils/unsync_guc_name.h @@ -174,7 +174,6 @@ "gp_cost_hashjoin_chainwalk", "gp_create_table_random_default_distribution", "gp_cte_sharing", - "gp_cte_sharing_auto", "gp_dbid", "gp_debug_pgproc", "gp_debug_resqueue_priority", diff --git a/src/test/regress/expected/cte_prune.out b/src/test/regress/expected/cte_prune.out index e3fed71c3d3..d07ae94679f 100644 --- a/src/test/regress/expected/cte_prune.out +++ b/src/test/regress/expected/cte_prune.out @@ -17,13 +17,15 @@ analyze t2; explain verbose with c1 as (select v1, v2, v3 from t1) select c11.v1 from c1 as c11 left join c1 as c22 on c11.v1=c22.v1 where c11.v1 < 5; QUERY PLAN ------------------------------------------------------------------------------------------ - Gather Motion 3:1 (slice1; segments: 3) (cost=1.06..2.16 rows=3 width=4) + Gather Motion 3:1 (slice1; segments: 3) (cost=1.06..1.34 rows=3 width=4) Output: c11.v1 - -> Hash Right Join (cost=1.06..2.11 rows=1 width=4) + -> Hash Right Join (cost=1.06..1.30 rows=1 width=4) Output: c11.v1 - Hash Cond: (t1.v1 = c11.v1) - -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) - Output: t1.v1, t1.v2, t1.v3 + Hash Cond: (share0_ref1.v1 = c11.v1) + -> Shared Scan (share slice:id 1:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref1.v1, share0_ref1.v2, share0_ref1.v3 + -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) + Output: t1.v1, t1.v2, t1.v3 -> Hash (cost=1.04..1.04 rows=1 width=4) Output: c11.v1 -> Subquery Scan on c11 (cost=0.00..1.04 rows=1 width=4) @@ -31,8 +33,9 @@ explain verbose with c1 as (select v1, v2, v3 from t1) select c11.v1 from c1 as -> Seq Scan on cte_prune.t1 t1_1 (cost=0.00..1.04 rows=1 width=12) Output: t1_1.v1, t1_1.v2, t1_1.v3 Filter: (t1_1.v1 < 5) + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(15 rows) +(18 rows) with c1 as (select v1, v2, v3 from t1) select c11.v1 from c1 as c11 left join c1 as c22 on c11.v1=c22.v1 where c11.v1 < 5; v1 @@ -46,13 +49,15 @@ with c1 as (select v1, v2, v3 from t1) select c11.v1 from c1 as c11 left join c1 explain verbose with c1 as (select v1, v2, v3 from t1) select c11.v2 from c1 as c11 left join c1 as c22 on c11.v1=c22.v1 where c11.v1 < 5; QUERY PLAN ------------------------------------------------------------------------------------------ - Gather Motion 3:1 (slice1; segments: 3) (cost=1.06..2.16 rows=3 width=4) + Gather Motion 3:1 (slice1; segments: 3) (cost=1.06..1.34 rows=3 width=4) Output: c11.v2 - -> Hash Right Join (cost=1.06..2.11 rows=1 width=4) + -> Hash Right Join (cost=1.06..1.30 rows=1 width=4) Output: c11.v2 - Hash Cond: (t1.v1 = c11.v1) - -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) - Output: t1.v1, t1.v2, t1.v3 + Hash Cond: (share0_ref1.v1 = c11.v1) + -> Shared Scan (share slice:id 1:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref1.v1, share0_ref1.v2, share0_ref1.v3 + -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) + Output: t1.v1, t1.v2, t1.v3 -> Hash (cost=1.04..1.04 rows=1 width=8) Output: c11.v2, c11.v1 -> Subquery Scan on c11 (cost=0.00..1.04 rows=1 width=8) @@ -60,8 +65,9 @@ explain verbose with c1 as (select v1, v2, v3 from t1) select c11.v2 from c1 as -> Seq Scan on cte_prune.t1 t1_1 (cost=0.00..1.04 rows=1 width=12) Output: t1_1.v1, t1_1.v2, t1_1.v3 Filter: (t1_1.v1 < 5) + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(15 rows) +(18 rows) with c1 as (select v1, v2, v3 from t1) select c11.v2 from c1 as c11 left join c1 as c22 on c11.v1=c22.v1 where c11.v1 < 5; v2 @@ -75,13 +81,15 @@ with c1 as (select v1, v2, v3 from t1) select c11.v2 from c1 as c11 left join c1 explain verbose with c1 as (select v1, v2, v3 from t1) select c11.v3 from c1 as c11 left join c1 as c22 on c11.v1=c22.v1 where c11.v1 < 5; QUERY PLAN ------------------------------------------------------------------------------------------ - Gather Motion 3:1 (slice1; segments: 3) (cost=1.06..2.16 rows=3 width=4) + Gather Motion 3:1 (slice1; segments: 3) (cost=1.06..1.34 rows=3 width=4) Output: c11.v3 - -> Hash Right Join (cost=1.06..2.11 rows=1 width=4) + -> Hash Right Join (cost=1.06..1.30 rows=1 width=4) Output: c11.v3 - Hash Cond: (t1.v1 = c11.v1) - -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) - Output: t1.v1, t1.v2, t1.v3 + Hash Cond: (share0_ref1.v1 = c11.v1) + -> Shared Scan (share slice:id 1:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref1.v1, share0_ref1.v2, share0_ref1.v3 + -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) + Output: t1.v1, t1.v2, t1.v3 -> Hash (cost=1.04..1.04 rows=1 width=8) Output: c11.v3, c11.v1 -> Subquery Scan on c11 (cost=0.00..1.04 rows=1 width=8) @@ -89,8 +97,9 @@ explain verbose with c1 as (select v1, v2, v3 from t1) select c11.v3 from c1 as -> Seq Scan on cte_prune.t1 t1_1 (cost=0.00..1.04 rows=1 width=12) Output: t1_1.v1, t1_1.v2, t1_1.v3 Filter: (t1_1.v1 < 5) + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(15 rows) +(18 rows) with c1 as (select v1, v2, v3 from t1) select c11.v3 from c1 as c11 left join c1 as c22 on c11.v1=c22.v1 where c11.v1 < 5; v3 @@ -105,13 +114,15 @@ with c1 as (select v1, v2, v3 from t1) select c11.v3 from c1 as c11 left join c1 explain verbose with c1 as (select * from t1) select c11.v1 from c1 as c11 left join c1 as c22 on c11.v1=c22.v1 where c11.v1 < 5; QUERY PLAN ------------------------------------------------------------------------------------------ - Gather Motion 3:1 (slice1; segments: 3) (cost=1.06..2.16 rows=3 width=4) + Gather Motion 3:1 (slice1; segments: 3) (cost=1.06..1.34 rows=3 width=4) Output: c11.v1 - -> Hash Right Join (cost=1.06..2.11 rows=1 width=4) + -> Hash Right Join (cost=1.06..1.30 rows=1 width=4) Output: c11.v1 - Hash Cond: (t1.v1 = c11.v1) - -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) - Output: t1.v1, t1.v2, t1.v3 + Hash Cond: (share0_ref1.v1 = c11.v1) + -> Shared Scan (share slice:id 1:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref1.v1, share0_ref1.v2, share0_ref1.v3 + -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) + Output: t1.v1, t1.v2, t1.v3 -> Hash (cost=1.04..1.04 rows=1 width=4) Output: c11.v1 -> Subquery Scan on c11 (cost=0.00..1.04 rows=1 width=4) @@ -119,8 +130,9 @@ explain verbose with c1 as (select * from t1) select c11.v1 from c1 as c11 left -> Seq Scan on cte_prune.t1 t1_1 (cost=0.00..1.04 rows=1 width=12) Output: t1_1.v1, t1_1.v2, t1_1.v3 Filter: (t1_1.v1 < 5) + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(15 rows) +(18 rows) with c1 as (select * from t1) select c11.v1 from c1 as c11 left join c1 as c22 on c11.v1=c22.v1 where c11.v1 < 5; v1 @@ -133,28 +145,31 @@ with c1 as (select * from t1) select c11.v1 from c1 as c11 left join c1 as c22 o -- no push filter explain verbose with c1 as (select v1, v2, v3 from t1) select c11.v3 from c1 as c11 left join c1 as c22 on c11.v1=c22.v2; - QUERY PLAN ----------------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=1.08..2.35 rows=10 width=4) + QUERY PLAN +----------------------------------------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) (cost=0.33..0.93 rows=10 width=4) Output: c11.v3 - -> Hash Right Join (cost=1.08..2.22 rows=3 width=4) + -> Hash Right Join (cost=0.33..0.80 rows=3 width=4) Output: c11.v3 Hash Cond: (c22.v2 = c11.v1) - -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.00..1.10 rows=3 width=4) + -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.00..0.40 rows=10 width=4) Output: c22.v2 Hash Key: c22.v2 - -> Subquery Scan on c22 (cost=0.00..1.03 rows=3 width=4) + -> Subquery Scan on c22 (cost=0.00..0.20 rows=10 width=4) Output: c22.v2 - -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) - Output: t1.v1, t1.v2, t1.v3 - -> Hash (cost=1.03..1.03 rows=3 width=8) + -> Shared Scan (share slice:id 2:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref2.v1, share0_ref2.v2, share0_ref2.v3 + -> Hash (cost=0.20..0.20 rows=10 width=8) Output: c11.v3, c11.v1 - -> Subquery Scan on c11 (cost=0.00..1.03 rows=3 width=8) + -> Subquery Scan on c11 (cost=0.00..0.20 rows=10 width=8) Output: c11.v3, c11.v1 - -> Seq Scan on cte_prune.t1 t1_1 (cost=0.00..1.03 rows=3 width=12) - Output: t1_1.v1, t1_1.v2, t1_1.v3 + -> Shared Scan (share slice:id 1:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref1.v1, share0_ref1.v2, share0_ref1.v3 + -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) + Output: t1.v1, t1.v2, t1.v3 + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(19 rows) +(22 rows) with c1 as (select v1, v2, v3 from t1) select c11.v3 from c1 as c11 left join c1 as c22 on c11.v1=c22.v2; v3 @@ -172,28 +187,31 @@ with c1 as (select v1, v2, v3 from t1) select c11.v3 from c1 as c11 left join c1 (10 rows) explain verbose with c1 as (select v1, v2, v3 from t1) select c11.v2 from c1 as c11 left join c1 as c22 on c11.v1=c22.v2; - QUERY PLAN ----------------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=1.08..2.35 rows=10 width=4) + QUERY PLAN +----------------------------------------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) (cost=0.33..0.93 rows=10 width=4) Output: c11.v2 - -> Hash Right Join (cost=1.08..2.22 rows=3 width=4) + -> Hash Right Join (cost=0.33..0.80 rows=3 width=4) Output: c11.v2 Hash Cond: (c22.v2 = c11.v1) - -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.00..1.10 rows=3 width=4) + -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.00..0.40 rows=10 width=4) Output: c22.v2 Hash Key: c22.v2 - -> Subquery Scan on c22 (cost=0.00..1.03 rows=3 width=4) + -> Subquery Scan on c22 (cost=0.00..0.20 rows=10 width=4) Output: c22.v2 - -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) - Output: t1.v1, t1.v2, t1.v3 - -> Hash (cost=1.03..1.03 rows=3 width=8) + -> Shared Scan (share slice:id 2:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref2.v1, share0_ref2.v2, share0_ref2.v3 + -> Hash (cost=0.20..0.20 rows=10 width=8) Output: c11.v2, c11.v1 - -> Subquery Scan on c11 (cost=0.00..1.03 rows=3 width=8) + -> Subquery Scan on c11 (cost=0.00..0.20 rows=10 width=8) Output: c11.v2, c11.v1 - -> Seq Scan on cte_prune.t1 t1_1 (cost=0.00..1.03 rows=3 width=12) - Output: t1_1.v1, t1_1.v2, t1_1.v3 + -> Shared Scan (share slice:id 1:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref1.v1, share0_ref1.v2, share0_ref1.v3 + -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) + Output: t1.v1, t1.v2, t1.v3 + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(19 rows) +(22 rows) with c1 as (select v1, v2, v3 from t1) select c11.v2 from c1 as c11 left join c1 as c22 on c11.v1=c22.v2; v2 @@ -212,31 +230,34 @@ with c1 as (select v1, v2, v3 from t1) select c11.v2 from c1 as c11 left join c1 -- distribution col can be pruned which is better than do redistribute in CTE consumer explain verbose with c1 as (select v1, v2, v3 from t1) select c11.v2 from c1 as c11 left join c1 as c22 on c11.v2=c22.v2; - QUERY PLAN ----------------------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=1.14..2.42 rows=10 width=4) + QUERY PLAN +----------------------------------------------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) (cost=0.53..1.13 rows=10 width=4) Output: c11.v2 - -> Hash Left Join (cost=1.14..2.29 rows=3 width=4) + -> Hash Left Join (cost=0.53..1.00 rows=3 width=4) Output: c11.v2 Hash Cond: (c11.v2 = c22.v2) - -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.00..1.10 rows=3 width=4) + -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.00..0.40 rows=10 width=4) Output: c11.v2 Hash Key: c11.v2 - -> Subquery Scan on c11 (cost=0.00..1.03 rows=3 width=4) + -> Subquery Scan on c11 (cost=0.00..0.20 rows=10 width=4) Output: c11.v2 - -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) - Output: t1.v1, t1.v2, t1.v3 - -> Hash (cost=1.10..1.10 rows=3 width=4) + -> Shared Scan (share slice:id 2:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref2.v1, share0_ref2.v2, share0_ref2.v3 + -> Hash (cost=0.40..0.40 rows=10 width=4) Output: c22.v2 - -> Redistribute Motion 3:3 (slice3; segments: 3) (cost=0.00..1.10 rows=3 width=4) + -> Redistribute Motion 3:3 (slice3; segments: 3) (cost=0.00..0.40 rows=10 width=4) Output: c22.v2 Hash Key: c22.v2 - -> Subquery Scan on c22 (cost=0.00..1.03 rows=3 width=4) + -> Subquery Scan on c22 (cost=0.00..0.20 rows=10 width=4) Output: c22.v2 - -> Seq Scan on cte_prune.t1 t1_1 (cost=0.00..1.03 rows=3 width=12) - Output: t1_1.v1, t1_1.v2, t1_1.v3 + -> Shared Scan (share slice:id 3:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref1.v1, share0_ref1.v2, share0_ref1.v3 + -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) + Output: t1.v1, t1.v2, t1.v3 + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(22 rows) +(25 rows) with c1 as (select v1, v2, v3 from t1) select c11.v2 from c1 as c11 left join c1 as c22 on c11.v2=c22.v2; v2 @@ -254,31 +275,34 @@ with c1 as (select v1, v2, v3 from t1) select c11.v2 from c1 as c11 left join c1 (10 rows) explain verbose with c1 as (select v1, v2, v3 from t1) select c11.v3 from c1 as c11 left join c1 as c22 on c11.v3=c22.v3; - QUERY PLAN ----------------------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=1.14..2.42 rows=10 width=4) + QUERY PLAN +----------------------------------------------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) (cost=0.53..1.13 rows=10 width=4) Output: c11.v3 - -> Hash Left Join (cost=1.14..2.29 rows=3 width=4) + -> Hash Left Join (cost=0.53..1.00 rows=3 width=4) Output: c11.v3 Hash Cond: (c11.v3 = c22.v3) - -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.00..1.10 rows=3 width=4) + -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.00..0.40 rows=10 width=4) Output: c11.v3 Hash Key: c11.v3 - -> Subquery Scan on c11 (cost=0.00..1.03 rows=3 width=4) + -> Subquery Scan on c11 (cost=0.00..0.20 rows=10 width=4) Output: c11.v3 - -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) - Output: t1.v1, t1.v2, t1.v3 - -> Hash (cost=1.10..1.10 rows=3 width=4) + -> Shared Scan (share slice:id 2:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref2.v1, share0_ref2.v2, share0_ref2.v3 + -> Hash (cost=0.40..0.40 rows=10 width=4) Output: c22.v3 - -> Redistribute Motion 3:3 (slice3; segments: 3) (cost=0.00..1.10 rows=3 width=4) + -> Redistribute Motion 3:3 (slice3; segments: 3) (cost=0.00..0.40 rows=10 width=4) Output: c22.v3 Hash Key: c22.v3 - -> Subquery Scan on c22 (cost=0.00..1.03 rows=3 width=4) + -> Subquery Scan on c22 (cost=0.00..0.20 rows=10 width=4) Output: c22.v3 - -> Seq Scan on cte_prune.t1 t1_1 (cost=0.00..1.03 rows=3 width=12) - Output: t1_1.v1, t1_1.v2, t1_1.v3 + -> Shared Scan (share slice:id 3:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref1.v1, share0_ref1.v2, share0_ref1.v3 + -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) + Output: t1.v1, t1.v2, t1.v3 + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(22 rows) +(25 rows) with c1 as (select v1, v2, v3 from t1) select c11.v3 from c1 as c11 left join c1 as c22 on c11.v3=c22.v3; v3 @@ -298,26 +322,29 @@ with c1 as (select v1, v2, v3 from t1) select c11.v3 from c1 as c11 left join c1 -- groupby/order by/window function/grouping set should be contains in CTE output -- group by explain verbose with c1 as (select v1, v2, v3 from t1) select sum(c11.v1) from c1 as c11 left join c1 as c22 on c11.v1=c22.v1 group by c11.v1; - QUERY PLAN ------------------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=2.17..2.34 rows=10 width=12) - Output: (sum(t1.v1)), t1.v1 - -> HashAggregate (cost=2.17..2.20 rows=3 width=12) - Output: sum(t1.v1), t1.v1 - Group Key: t1.v1 - -> Hash Left Join (cost=1.08..2.15 rows=3 width=4) - Output: t1.v1 - Hash Cond: (t1.v1 = c22.v1) - -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) - Output: t1.v1, t1.v2, t1.v3 - -> Hash (cost=1.03..1.03 rows=3 width=4) + QUERY PLAN +--------------------------------------------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) (cost=0.61..0.78 rows=10 width=12) + Output: (sum(share0_ref2.v1)), share0_ref2.v1 + -> HashAggregate (cost=0.61..0.65 rows=3 width=12) + Output: sum(share0_ref2.v1), share0_ref2.v1 + Group Key: share0_ref2.v1 + -> Hash Left Join (cost=0.33..0.60 rows=3 width=4) + Output: share0_ref2.v1 + Hash Cond: (share0_ref2.v1 = c22.v1) + -> Shared Scan (share slice:id 1:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref2.v1, share0_ref2.v2, share0_ref2.v3 + -> Hash (cost=0.20..0.20 rows=10 width=4) Output: c22.v1 - -> Subquery Scan on c22 (cost=0.00..1.03 rows=3 width=4) + -> Subquery Scan on c22 (cost=0.00..0.20 rows=10 width=4) Output: c22.v1 - -> Seq Scan on cte_prune.t1 t1_1 (cost=0.00..1.03 rows=3 width=12) - Output: t1_1.v1, t1_1.v2, t1_1.v3 + -> Shared Scan (share slice:id 1:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref1.v1, share0_ref1.v2, share0_ref1.v3 + -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) + Output: t1.v1, t1.v2, t1.v3 + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(17 rows) +(20 rows) with c1 as (select v1, v2, v3 from t1) select sum(c11.v1) from c1 as c11 left join c1 as c22 on c11.v1=c22.v1 group by c11.v1; sum @@ -335,29 +362,32 @@ with c1 as (select v1, v2, v3 from t1) select sum(c11.v1) from c1 as c11 left jo (10 rows) explain verbose with c1 as (select v1, v2, v3 from t1) select sum(c11.v1) from c1 as c11 left join c1 as c22 on c11.v1=c22.v1 group by c11.v2; - QUERY PLAN ------------------------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=2.24..2.40 rows=10 width=12) - Output: (sum(t1.v1)), t1.v2 - -> HashAggregate (cost=2.24..2.27 rows=3 width=12) - Output: sum(t1.v1), t1.v2 - Group Key: t1.v2 - -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=1.08..2.22 rows=3 width=8) - Output: t1.v2, t1.v1 - Hash Key: t1.v2 - -> Hash Left Join (cost=1.08..2.15 rows=3 width=8) - Output: t1.v2, t1.v1 - Hash Cond: (t1.v1 = c22.v1) - -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) - Output: t1.v1, t1.v2, t1.v3 - -> Hash (cost=1.03..1.03 rows=3 width=4) + QUERY PLAN +--------------------------------------------------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) (cost=0.68..0.85 rows=10 width=12) + Output: (sum(share0_ref2.v1)), share0_ref2.v2 + -> HashAggregate (cost=0.68..0.71 rows=3 width=12) + Output: sum(share0_ref2.v1), share0_ref2.v2 + Group Key: share0_ref2.v2 + -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.33..0.66 rows=3 width=8) + Output: share0_ref2.v2, share0_ref2.v1 + Hash Key: share0_ref2.v2 + -> Hash Left Join (cost=0.33..0.60 rows=3 width=8) + Output: share0_ref2.v2, share0_ref2.v1 + Hash Cond: (share0_ref2.v1 = c22.v1) + -> Shared Scan (share slice:id 2:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref2.v1, share0_ref2.v2, share0_ref2.v3 + -> Hash (cost=0.20..0.20 rows=10 width=4) Output: c22.v1 - -> Subquery Scan on c22 (cost=0.00..1.03 rows=3 width=4) + -> Subquery Scan on c22 (cost=0.00..0.20 rows=10 width=4) Output: c22.v1 - -> Seq Scan on cte_prune.t1 t1_1 (cost=0.00..1.03 rows=3 width=12) - Output: t1_1.v1, t1_1.v2, t1_1.v3 + -> Shared Scan (share slice:id 2:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref1.v1, share0_ref1.v2, share0_ref1.v3 + -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) + Output: t1.v1, t1.v2, t1.v3 + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(20 rows) +(23 rows) with c1 as (select v1, v2, v3 from t1) select sum(c11.v1) from c1 as c11 left join c1 as c22 on c11.v1=c22.v1 group by c11.v2; sum @@ -375,29 +405,32 @@ with c1 as (select v1, v2, v3 from t1) select sum(c11.v1) from c1 as c11 left jo (10 rows) explain verbose with c1 as (select v1, v2, v3 from t1) select sum(c11.v3) from c1 as c11 left join c1 as c22 on c11.v1=c22.v1 group by c11.v2; - QUERY PLAN ------------------------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=2.24..2.40 rows=10 width=12) - Output: (sum(t1.v3)), t1.v2 - -> HashAggregate (cost=2.24..2.27 rows=3 width=12) - Output: sum(t1.v3), t1.v2 - Group Key: t1.v2 - -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=1.08..2.22 rows=3 width=8) - Output: t1.v2, t1.v3 - Hash Key: t1.v2 - -> Hash Left Join (cost=1.08..2.15 rows=3 width=8) - Output: t1.v2, t1.v3 - Hash Cond: (t1.v1 = c22.v1) - -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) - Output: t1.v1, t1.v2, t1.v3 - -> Hash (cost=1.03..1.03 rows=3 width=4) + QUERY PLAN +--------------------------------------------------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) (cost=0.68..0.85 rows=10 width=12) + Output: (sum(share0_ref2.v3)), share0_ref2.v2 + -> HashAggregate (cost=0.68..0.71 rows=3 width=12) + Output: sum(share0_ref2.v3), share0_ref2.v2 + Group Key: share0_ref2.v2 + -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.33..0.66 rows=3 width=8) + Output: share0_ref2.v2, share0_ref2.v3 + Hash Key: share0_ref2.v2 + -> Hash Left Join (cost=0.33..0.60 rows=3 width=8) + Output: share0_ref2.v2, share0_ref2.v3 + Hash Cond: (share0_ref2.v1 = c22.v1) + -> Shared Scan (share slice:id 2:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref2.v1, share0_ref2.v2, share0_ref2.v3 + -> Hash (cost=0.20..0.20 rows=10 width=4) Output: c22.v1 - -> Subquery Scan on c22 (cost=0.00..1.03 rows=3 width=4) + -> Subquery Scan on c22 (cost=0.00..0.20 rows=10 width=4) Output: c22.v1 - -> Seq Scan on cte_prune.t1 t1_1 (cost=0.00..1.03 rows=3 width=12) - Output: t1_1.v1, t1_1.v2, t1_1.v3 + -> Shared Scan (share slice:id 2:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref1.v1, share0_ref1.v2, share0_ref1.v3 + -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) + Output: t1.v1, t1.v2, t1.v3 + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(20 rows) +(23 rows) with c1 as (select v1, v2, v3 from t1) select sum(c11.v3) from c1 as c11 left join c1 as c22 on c11.v1=c22.v1 group by c11.v2; sum @@ -416,27 +449,30 @@ with c1 as (select v1, v2, v3 from t1) select sum(c11.v3) from c1 as c11 left jo -- order by explain verbose with c1 as (select v1, v2, v3 from t1) select c11.v1 from c1 as c11 left join c1 as c22 on c11.v1=c22.v1 order by c22.v1; - QUERY PLAN ------------------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=2.18..2.32 rows=10 width=8) - Output: t1.v1, c22.v1 + QUERY PLAN +--------------------------------------------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) (cost=0.62..0.77 rows=10 width=8) + Output: share0_ref2.v1, c22.v1 Merge Key: c22.v1 - -> Sort (cost=2.18..2.19 rows=3 width=8) - Output: t1.v1, c22.v1 + -> Sort (cost=0.62..0.63 rows=3 width=8) + Output: share0_ref2.v1, c22.v1 Sort Key: c22.v1 - -> Hash Left Join (cost=1.08..2.15 rows=3 width=8) - Output: t1.v1, c22.v1 - Hash Cond: (t1.v1 = c22.v1) - -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) - Output: t1.v1, t1.v2, t1.v3 - -> Hash (cost=1.03..1.03 rows=3 width=4) + -> Hash Left Join (cost=0.33..0.60 rows=3 width=8) + Output: share0_ref2.v1, c22.v1 + Hash Cond: (share0_ref2.v1 = c22.v1) + -> Shared Scan (share slice:id 1:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref2.v1, share0_ref2.v2, share0_ref2.v3 + -> Hash (cost=0.20..0.20 rows=10 width=4) Output: c22.v1 - -> Subquery Scan on c22 (cost=0.00..1.03 rows=3 width=4) + -> Subquery Scan on c22 (cost=0.00..0.20 rows=10 width=4) Output: c22.v1 - -> Seq Scan on cte_prune.t1 t1_1 (cost=0.00..1.03 rows=3 width=12) - Output: t1_1.v1, t1_1.v2, t1_1.v3 + -> Shared Scan (share slice:id 1:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref1.v1, share0_ref1.v2, share0_ref1.v3 + -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) + Output: t1.v1, t1.v2, t1.v3 + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(18 rows) +(21 rows) with c1 as (select v1, v2, v3 from t1) select c11.v1 from c1 as c11 left join c1 as c22 on c11.v1=c22.v1 order by c22.v1; v1 @@ -454,27 +490,30 @@ with c1 as (select v1, v2, v3 from t1) select c11.v1 from c1 as c11 left join c1 (10 rows) explain verbose with c1 as (select v1, v2, v3 from t1) select c11.v1 from c1 as c11 left join c1 as c22 on c11.v1=c22.v1 order by c22.v3; - QUERY PLAN ------------------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=2.18..2.32 rows=10 width=8) - Output: t1.v1, c22.v3 + QUERY PLAN +--------------------------------------------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) (cost=0.62..0.77 rows=10 width=8) + Output: share0_ref2.v1, c22.v3 Merge Key: c22.v3 - -> Sort (cost=2.18..2.19 rows=3 width=8) - Output: t1.v1, c22.v3 + -> Sort (cost=0.62..0.63 rows=3 width=8) + Output: share0_ref2.v1, c22.v3 Sort Key: c22.v3 - -> Hash Left Join (cost=1.08..2.15 rows=3 width=8) - Output: t1.v1, c22.v3 - Hash Cond: (t1.v1 = c22.v1) - -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) - Output: t1.v1, t1.v2, t1.v3 - -> Hash (cost=1.03..1.03 rows=3 width=8) + -> Hash Left Join (cost=0.33..0.60 rows=3 width=8) + Output: share0_ref2.v1, c22.v3 + Hash Cond: (share0_ref2.v1 = c22.v1) + -> Shared Scan (share slice:id 1:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref2.v1, share0_ref2.v2, share0_ref2.v3 + -> Hash (cost=0.20..0.20 rows=10 width=8) Output: c22.v3, c22.v1 - -> Subquery Scan on c22 (cost=0.00..1.03 rows=3 width=8) + -> Subquery Scan on c22 (cost=0.00..0.20 rows=10 width=8) Output: c22.v3, c22.v1 - -> Seq Scan on cte_prune.t1 t1_1 (cost=0.00..1.03 rows=3 width=12) - Output: t1_1.v1, t1_1.v2, t1_1.v3 + -> Shared Scan (share slice:id 1:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref1.v1, share0_ref1.v2, share0_ref1.v3 + -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) + Output: t1.v1, t1.v2, t1.v3 + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(18 rows) +(21 rows) with c1 as (select v1, v2, v3 from t1) select c11.v1 from c1 as c11 left join c1 as c22 on c11.v1=c22.v1 order by c22.v3; v1 @@ -493,30 +532,33 @@ with c1 as (select v1, v2, v3 from t1) select c11.v1 from c1 as c11 left join c1 -- window function explain verbose with c1 as (select v1, v2, v3 from t1) select sum(c11.v1) OVER (ORDER BY c11.v2) from c1 as c11 left join c1 as c22 on c11.v1=c22.v1; - QUERY PLAN ------------------------------------------------------------------------------------------------------- - WindowAgg (cost=2.18..2.47 rows=10 width=12) - Output: sum(t1.v1) OVER (?), t1.v2 - Order By: t1.v2 - -> Gather Motion 3:1 (slice1; segments: 3) (cost=2.18..2.32 rows=10 width=8) - Output: t1.v2, t1.v1 - Merge Key: t1.v2 - -> Sort (cost=2.18..2.19 rows=3 width=8) - Output: t1.v2, t1.v1 - Sort Key: t1.v2 - -> Hash Left Join (cost=1.08..2.15 rows=3 width=8) - Output: t1.v2, t1.v1 - Hash Cond: (t1.v1 = c22.v1) - -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) - Output: t1.v1, t1.v2, t1.v3 - -> Hash (cost=1.03..1.03 rows=3 width=4) + QUERY PLAN +--------------------------------------------------------------------------------------------------------- + WindowAgg (cost=0.62..0.92 rows=10 width=12) + Output: sum(share0_ref2.v1) OVER (?), share0_ref2.v2 + Order By: share0_ref2.v2 + -> Gather Motion 3:1 (slice1; segments: 3) (cost=0.62..0.77 rows=10 width=8) + Output: share0_ref2.v2, share0_ref2.v1 + Merge Key: share0_ref2.v2 + -> Sort (cost=0.62..0.63 rows=3 width=8) + Output: share0_ref2.v2, share0_ref2.v1 + Sort Key: share0_ref2.v2 + -> Hash Left Join (cost=0.33..0.60 rows=3 width=8) + Output: share0_ref2.v2, share0_ref2.v1 + Hash Cond: (share0_ref2.v1 = c22.v1) + -> Shared Scan (share slice:id 1:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref2.v1, share0_ref2.v2, share0_ref2.v3 + -> Hash (cost=0.20..0.20 rows=10 width=4) Output: c22.v1 - -> Subquery Scan on c22 (cost=0.00..1.03 rows=3 width=4) + -> Subquery Scan on c22 (cost=0.00..0.20 rows=10 width=4) Output: c22.v1 - -> Seq Scan on cte_prune.t1 t1_1 (cost=0.00..1.03 rows=3 width=12) - Output: t1_1.v1, t1_1.v2, t1_1.v3 + -> Shared Scan (share slice:id 1:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref1.v1, share0_ref1.v2, share0_ref1.v3 + -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) + Output: t1.v1, t1.v2, t1.v3 + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(21 rows) +(24 rows) with c1 as (select v1, v2, v3 from t1) select sum(c11.v1) OVER (ORDER BY c11.v2) from c1 as c11 left join c1 as c22 on c11.v1=c22.v1; sum @@ -534,30 +576,33 @@ with c1 as (select v1, v2, v3 from t1) select sum(c11.v1) OVER (ORDER BY c11.v2) (10 rows) explain verbose with c1 as (select v1, v2, v3 from t1) select sum(c11.v2) OVER (ORDER BY c11.v3) from c1 as c11 left join c1 as c22 on c11.v1=c22.v1; - QUERY PLAN ------------------------------------------------------------------------------------------------------- - WindowAgg (cost=2.18..2.47 rows=10 width=12) - Output: sum(t1.v2) OVER (?), t1.v3 - Order By: t1.v3 - -> Gather Motion 3:1 (slice1; segments: 3) (cost=2.18..2.32 rows=10 width=8) - Output: t1.v3, t1.v2 - Merge Key: t1.v3 - -> Sort (cost=2.18..2.19 rows=3 width=8) - Output: t1.v3, t1.v2 - Sort Key: t1.v3 - -> Hash Left Join (cost=1.08..2.15 rows=3 width=8) - Output: t1.v3, t1.v2 - Hash Cond: (t1.v1 = c22.v1) - -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) - Output: t1.v1, t1.v2, t1.v3 - -> Hash (cost=1.03..1.03 rows=3 width=4) + QUERY PLAN +--------------------------------------------------------------------------------------------------------- + WindowAgg (cost=0.62..0.92 rows=10 width=12) + Output: sum(share0_ref2.v2) OVER (?), share0_ref2.v3 + Order By: share0_ref2.v3 + -> Gather Motion 3:1 (slice1; segments: 3) (cost=0.62..0.77 rows=10 width=8) + Output: share0_ref2.v3, share0_ref2.v2 + Merge Key: share0_ref2.v3 + -> Sort (cost=0.62..0.63 rows=3 width=8) + Output: share0_ref2.v3, share0_ref2.v2 + Sort Key: share0_ref2.v3 + -> Hash Left Join (cost=0.33..0.60 rows=3 width=8) + Output: share0_ref2.v3, share0_ref2.v2 + Hash Cond: (share0_ref2.v1 = c22.v1) + -> Shared Scan (share slice:id 1:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref2.v1, share0_ref2.v2, share0_ref2.v3 + -> Hash (cost=0.20..0.20 rows=10 width=4) Output: c22.v1 - -> Subquery Scan on c22 (cost=0.00..1.03 rows=3 width=4) + -> Subquery Scan on c22 (cost=0.00..0.20 rows=10 width=4) Output: c22.v1 - -> Seq Scan on cte_prune.t1 t1_1 (cost=0.00..1.03 rows=3 width=12) - Output: t1_1.v1, t1_1.v2, t1_1.v3 + -> Shared Scan (share slice:id 1:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref1.v1, share0_ref1.v2, share0_ref1.v3 + -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) + Output: t1.v1, t1.v2, t1.v3 + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(21 rows) +(24 rows) with c1 as (select v1, v2, v3 from t1) select sum(c11.v2) OVER (ORDER BY c11.v3) from c1 as c11 left join c1 as c22 on c11.v1=c22.v1; sum @@ -576,32 +621,35 @@ with c1 as (select v1, v2, v3 from t1) select sum(c11.v2) OVER (ORDER BY c11.v3) -- grouping set explain verbose with c1 as (select v1, v2, v3 from t1) select sum(c11.v2) from c1 as c11 left join c1 as c22 on c11.v1=c22.v1 group by ROLLUP(c11.v1,c11.v2); - QUERY PLAN ------------------------------------------------------------------------------------------------------- - GroupAggregate (cost=2.18..2.61 rows=21 width=16) - Output: sum(t1.v2), t1.v1, t1.v2 - Group Key: t1.v1, t1.v2 - Group Key: t1.v1 + QUERY PLAN +--------------------------------------------------------------------------------------------------------- + GroupAggregate (cost=0.62..1.05 rows=21 width=16) + Output: sum(share0_ref2.v2), share0_ref2.v1, share0_ref2.v2 + Group Key: share0_ref2.v1, share0_ref2.v2 + Group Key: share0_ref2.v1 Group Key: () - -> Gather Motion 3:1 (slice1; segments: 3) (cost=2.18..2.32 rows=10 width=8) - Output: t1.v1, t1.v2 - Merge Key: t1.v1, t1.v2 - -> Sort (cost=2.18..2.19 rows=3 width=8) - Output: t1.v1, t1.v2 - Sort Key: t1.v1, t1.v2 - -> Hash Left Join (cost=1.08..2.15 rows=3 width=8) - Output: t1.v1, t1.v2 - Hash Cond: (t1.v1 = c22.v1) - -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) - Output: t1.v1, t1.v2, t1.v3 - -> Hash (cost=1.03..1.03 rows=3 width=4) + -> Gather Motion 3:1 (slice1; segments: 3) (cost=0.62..0.77 rows=10 width=8) + Output: share0_ref2.v1, share0_ref2.v2 + Merge Key: share0_ref2.v1, share0_ref2.v2 + -> Sort (cost=0.62..0.63 rows=3 width=8) + Output: share0_ref2.v1, share0_ref2.v2 + Sort Key: share0_ref2.v1, share0_ref2.v2 + -> Hash Left Join (cost=0.33..0.60 rows=3 width=8) + Output: share0_ref2.v1, share0_ref2.v2 + Hash Cond: (share0_ref2.v1 = c22.v1) + -> Shared Scan (share slice:id 1:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref2.v1, share0_ref2.v2, share0_ref2.v3 + -> Hash (cost=0.20..0.20 rows=10 width=4) Output: c22.v1 - -> Subquery Scan on c22 (cost=0.00..1.03 rows=3 width=4) + -> Subquery Scan on c22 (cost=0.00..0.20 rows=10 width=4) Output: c22.v1 - -> Seq Scan on cte_prune.t1 t1_1 (cost=0.00..1.03 rows=3 width=12) - Output: t1_1.v1, t1_1.v2, t1_1.v3 + -> Shared Scan (share slice:id 1:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref1.v1, share0_ref1.v2, share0_ref1.v3 + -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) + Output: t1.v1, t1.v2, t1.v3 + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(23 rows) +(26 rows) with c1 as (select v1, v2, v3 from t1) select sum(c11.v2) from c1 as c11 left join c1 as c22 on c11.v1=c22.v1 group by ROLLUP(c11.v1,c11.v2); sum @@ -630,32 +678,35 @@ with c1 as (select v1, v2, v3 from t1) select sum(c11.v2) from c1 as c11 left jo (21 rows) explain verbose with c1 as (select v1, v2, v3 from t1) select sum(c11.v2) from c1 as c11 left join c1 as c22 on c11.v1=c22.v1 group by ROLLUP(c11.v2,c11.v3); - QUERY PLAN ------------------------------------------------------------------------------------------------------- - GroupAggregate (cost=2.18..2.61 rows=21 width=16) - Output: sum(t1.v2), t1.v2, t1.v3 - Group Key: t1.v2, t1.v3 - Group Key: t1.v2 + QUERY PLAN +--------------------------------------------------------------------------------------------------------- + GroupAggregate (cost=0.62..1.05 rows=21 width=16) + Output: sum(share0_ref2.v2), share0_ref2.v2, share0_ref2.v3 + Group Key: share0_ref2.v2, share0_ref2.v3 + Group Key: share0_ref2.v2 Group Key: () - -> Gather Motion 3:1 (slice1; segments: 3) (cost=2.18..2.32 rows=10 width=8) - Output: t1.v2, t1.v3 - Merge Key: t1.v2, t1.v3 - -> Sort (cost=2.18..2.19 rows=3 width=8) - Output: t1.v2, t1.v3 - Sort Key: t1.v2, t1.v3 - -> Hash Left Join (cost=1.08..2.15 rows=3 width=8) - Output: t1.v2, t1.v3 - Hash Cond: (t1.v1 = c22.v1) - -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) - Output: t1.v1, t1.v2, t1.v3 - -> Hash (cost=1.03..1.03 rows=3 width=4) + -> Gather Motion 3:1 (slice1; segments: 3) (cost=0.62..0.77 rows=10 width=8) + Output: share0_ref2.v2, share0_ref2.v3 + Merge Key: share0_ref2.v2, share0_ref2.v3 + -> Sort (cost=0.62..0.63 rows=3 width=8) + Output: share0_ref2.v2, share0_ref2.v3 + Sort Key: share0_ref2.v2, share0_ref2.v3 + -> Hash Left Join (cost=0.33..0.60 rows=3 width=8) + Output: share0_ref2.v2, share0_ref2.v3 + Hash Cond: (share0_ref2.v1 = c22.v1) + -> Shared Scan (share slice:id 1:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref2.v1, share0_ref2.v2, share0_ref2.v3 + -> Hash (cost=0.20..0.20 rows=10 width=4) Output: c22.v1 - -> Subquery Scan on c22 (cost=0.00..1.03 rows=3 width=4) + -> Subquery Scan on c22 (cost=0.00..0.20 rows=10 width=4) Output: c22.v1 - -> Seq Scan on cte_prune.t1 t1_1 (cost=0.00..1.03 rows=3 width=12) - Output: t1_1.v1, t1_1.v2, t1_1.v3 + -> Shared Scan (share slice:id 1:0) (cost=1.03..1.24 rows=3 width=12) + Output: share0_ref1.v1, share0_ref1.v2, share0_ref1.v3 + -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) + Output: t1.v1, t1.v2, t1.v3 + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(23 rows) +(26 rows) with c1 as (select v1, v2, v3 from t1) select sum(c11.v2) OVER (ORDER BY c11.v3) from c1 as c11 left join c1 as c22 on c11.v1=c22.v1; sum @@ -675,37 +726,33 @@ with c1 as (select v1, v2, v3 from t1) select sum(c11.v2) OVER (ORDER BY c11.v3) -- CTE producer should have right output explain verbose with c1 as (select t1.v1 as v1, t2.v1 as t21, t2.v2 as t22, t2.v3 as t23 from t1 join t2 on t1.v1 = t2.v1) select c11.v1 from c1 as c11 left join c1 as c22 on c11.v1=c22.v1; - QUERY PLAN ------------------------------------------------------------------------------------------------------ - Gather Motion 3:1 (slice1; segments: 3) (cost=3.65..5.29 rows=10 width=4) - Output: t1.v1 - -> Hash Left Join (cost=3.65..5.15 rows=3 width=4) - Output: t1.v1 - Hash Cond: (t1.v1 = c22.v1) - -> Hash Join (cost=1.08..2.53 rows=3 width=16) - Output: t1.v1, t2.v1, t2.v2, t2.v3 - Hash Cond: (t2.v1 = t1.v1) - -> Seq Scan on cte_prune.t2 (cost=0.00..1.34 rows=34 width=12) - Output: t2.v1, t2.v2, t2.v3 - -> Hash (cost=1.03..1.03 rows=3 width=4) - Output: t1.v1 - -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=4) - Output: t1.v1 - -> Hash (cost=2.53..2.53 rows=3 width=4) + QUERY PLAN +------------------------------------------------------------------------------------------------------ + Gather Motion 3:1 (slice1; segments: 3) (cost=0.33..0.73 rows=10 width=4) + Output: share0_ref2.v1 + -> Hash Left Join (cost=0.33..0.60 rows=3 width=4) + Output: share0_ref2.v1 + Hash Cond: (share0_ref2.v1 = c22.v1) + -> Shared Scan (share slice:id 1:0) (cost=2.53..2.74 rows=3 width=16) + Output: share0_ref2.v1, share0_ref2.t21, share0_ref2.t22, share0_ref2.t23 + -> Hash (cost=0.20..0.20 rows=10 width=4) Output: c22.v1 - -> Subquery Scan on c22 (cost=1.08..2.53 rows=3 width=4) + -> Subquery Scan on c22 (cost=0.00..0.20 rows=10 width=4) Output: c22.v1 - -> Hash Join (cost=1.08..2.53 rows=3 width=16) - Output: t1_1.v1, t2_1.v1, t2_1.v2, t2_1.v3 - Hash Cond: (t2_1.v1 = t1_1.v1) - -> Seq Scan on cte_prune.t2 t2_1 (cost=0.00..1.34 rows=34 width=12) - Output: t2_1.v1, t2_1.v2, t2_1.v3 - -> Hash (cost=1.03..1.03 rows=3 width=4) - Output: t1_1.v1 - -> Seq Scan on cte_prune.t1 t1_1 (cost=0.00..1.03 rows=3 width=4) - Output: t1_1.v1 + -> Shared Scan (share slice:id 1:0) (cost=2.53..2.74 rows=3 width=16) + Output: share0_ref1.v1, share0_ref1.t21, share0_ref1.t22, share0_ref1.t23 + -> Hash Join (cost=1.08..2.53 rows=3 width=16) + Output: t1.v1, t2.v1, t2.v2, t2.v3 + Hash Cond: (t2.v1 = t1.v1) + -> Seq Scan on cte_prune.t2 (cost=0.00..1.34 rows=34 width=12) + Output: t2.v1, t2.v2, t2.v3 + -> Hash (cost=1.03..1.03 rows=3 width=4) + Output: t1.v1 + -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=4) + Output: t1.v1 + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(28 rows) +(24 rows) with c1 as (select t1.v1 as v1, t2.v1 as t21, t2.v2 as t22, t2.v3 as t23 from t1 join t2 on t1.v1 = t2.v1) select c11.v1 from c1 as c11 left join c1 as c22 on c11.v1=c22.v1; @@ -725,43 +772,40 @@ select c11.v1 from c1 as c11 left join c1 as c22 on c11.v1=c22.v1; explain verbose with c1 as (select sum(v1) as v1, sum(v2) as v2, v3 from t1 group by v3) select c11.v1 from c1 as c11 left join c1 as c22 on c11.v1=c22.v1; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------ - Gather Motion 3:1 (slice1; segments: 3) (cost=2.39..2.67 rows=10 width=8) + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) (cost=0.53..1.13 rows=10 width=8) Output: c11.v1 - -> Hash Left Join (cost=2.39..2.54 rows=3 width=8) + -> Hash Left Join (cost=0.53..1.00 rows=3 width=8) Output: c11.v1 Hash Cond: (c11.v1 = c22.v1) - -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=1.12..1.23 rows=3 width=8) + -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.00..0.40 rows=10 width=8) Output: c11.v1 Hash Key: c11.v1 - -> Subquery Scan on c11 (cost=1.12..1.16 rows=3 width=8) + -> Subquery Scan on c11 (cost=0.00..0.20 rows=10 width=8) Output: c11.v1 - -> HashAggregate (cost=1.12..1.16 rows=3 width=20) - Output: sum(t1.v1), sum(t1.v2), t1.v3 - Group Key: t1.v3 - -> Redistribute Motion 3:3 (slice3; segments: 3) (cost=0.00..1.10 rows=3 width=12) - Output: t1.v3, t1.v1, t1.v2 - Hash Key: t1.v3 - -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) - Output: t1.v3, t1.v1, t1.v2 - -> Hash (cost=1.23..1.23 rows=3 width=8) + -> Shared Scan (share slice:id 2:0) (cost=1.16..1.36 rows=3 width=20) + Output: share0_ref2.v1, share0_ref2.v2, share0_ref2.v3 + -> Hash (cost=0.40..0.40 rows=10 width=8) Output: c22.v1 - -> Redistribute Motion 3:3 (slice4; segments: 3) (cost=1.12..1.23 rows=3 width=8) + -> Redistribute Motion 3:3 (slice3; segments: 3) (cost=0.00..0.40 rows=10 width=8) Output: c22.v1 Hash Key: c22.v1 - -> Subquery Scan on c22 (cost=1.12..1.16 rows=3 width=8) + -> Subquery Scan on c22 (cost=0.00..0.20 rows=10 width=8) Output: c22.v1 - -> HashAggregate (cost=1.12..1.16 rows=3 width=20) - Output: sum(t1_1.v1), sum(t1_1.v2), t1_1.v3 - Group Key: t1_1.v3 - -> Redistribute Motion 3:3 (slice5; segments: 3) (cost=0.00..1.10 rows=3 width=12) - Output: t1_1.v3, t1_1.v1, t1_1.v2 - Hash Key: t1_1.v3 - -> Seq Scan on cte_prune.t1 t1_1 (cost=0.00..1.03 rows=3 width=12) - Output: t1_1.v3, t1_1.v1, t1_1.v2 + -> Shared Scan (share slice:id 3:0) (cost=1.16..1.36 rows=3 width=20) + Output: share0_ref1.v1, share0_ref1.v2, share0_ref1.v3 + -> HashAggregate (cost=1.12..1.16 rows=3 width=20) + Output: sum(t1.v1), sum(t1.v2), t1.v3 + Group Key: t1.v3 + -> Redistribute Motion 3:3 (slice4; segments: 3) (cost=0.00..1.10 rows=3 width=12) + Output: t1.v3, t1.v1, t1.v2 + Hash Key: t1.v3 + -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) + Output: t1.v3, t1.v1, t1.v2 + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(34 rows) +(31 rows) with c1 as (select lt1.v3 as v3, lt1.v1 as lo1, rt1.v1 as ro1 from t1 lt1, t1 rt1 where lt1.v2 = rt1.v2 and lt1.v1 = rt1.v1) select * from t1 where t1.v1 in (select v3 from c1) and t1.v1 in (select v3 from c1 where v3 > 0); @@ -908,49 +952,51 @@ select t1.v1 from t1 where t1.v1 in (select item_sk from frequent_ss_items where and t1.v1 in (select item_sk from frequent_ss_items where item_sk > 0); QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=452.31..452.37 rows=3 width=4) + Gather Motion 3:1 (slice1; segments: 3) (cost=228.56..228.62 rows=3 width=4) Output: t1.v1 - -> HashAggregate (cost=452.31..452.32 rows=1 width=4) + -> HashAggregate (cost=228.56..228.57 rows=1 width=4) Output: t1.v1 Group Key: (RowIdExpr) - -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=451.79..452.31 rows=1 width=4) + -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=228.12..228.56 rows=1 width=4) Output: t1.v1, (RowIdExpr) Hash Key: (RowIdExpr) - -> Hash Join (cost=451.79..452.29 rows=1 width=4) + -> Hash Join (cost=228.12..228.54 rows=1 width=4) Output: t1.v1, (RowIdExpr) Hash Cond: (frequent_ss_items.item_sk = t1.v1) - -> Subquery Scan on frequent_ss_items (cost=223.67..224.14 rows=6 width=4) + -> Subquery Scan on frequent_ss_items (cost=0.00..0.36 rows=18 width=4) Output: frequent_ss_items.item_sk - -> GroupAggregate (cost=223.67..224.14 rows=6 width=48) - Output: (substr((tpcds_item.i_item_desc)::text, 1, 30)), tpcds_item.i_item_sk, tpcds_date_dim.d_date, count(*) - Group Key: (substr((tpcds_item.i_item_desc)::text, 1, 30)), tpcds_item.i_item_sk, tpcds_date_dim.d_date - Filter: (count(*) > 4) - -> Sort (cost=223.67..223.72 rows=18 width=40) - Output: (substr((tpcds_item.i_item_desc)::text, 1, 30)), tpcds_item.i_item_sk, tpcds_date_dim.d_date - Sort Key: (substr((tpcds_item.i_item_desc)::text, 1, 30)), tpcds_item.i_item_sk, tpcds_date_dim.d_date - -> Hash Join (cost=181.20..223.30 rows=18 width=40) - Output: substr((tpcds_item.i_item_desc)::text, 1, 30), tpcds_item.i_item_sk, tpcds_date_dim.d_date - Hash Cond: (tpcds_item.i_item_sk = tpcds_store_sales.ss_item_sk) - -> Seq Scan on cte_prune.tpcds_item (cost=0.00..39.33 rows=533 width=422) - Output: tpcds_item.i_item_sk, tpcds_item.i_item_id, tpcds_item.i_rec_start_date, tpcds_item.i_rec_end_date, tpcds_item.i_item_desc, tpcds_item.i_current_price, tpcds_item.i_wholesale_cost, tpcds_item.i_brand_id, tpcds_item.i_brand, tpcds_item.i_class_id, tpcds_item.i_class, tpcds_item.i_category_id, tpcds_item.i_category, tpcds_item.i_manufact_id, tpcds_item.i_manufact, tpcds_item.i_size, tpcds_item.i_formulation, tpcds_item.i_color, tpcds_item.i_units, tpcds_item.i_container, tpcds_item.i_manager_id, tpcds_item.i_product_name - -> Hash (cost=180.98..180.98 rows=18 width=8) - Output: tpcds_store_sales.ss_item_sk, tpcds_date_dim.d_date - -> Redistribute Motion 3:3 (slice3; segments: 3) (cost=89.63..180.98 rows=18 width=8) + -> Shared Scan (share slice:id 2:0) (cost=224.14..224.34 rows=6 width=48) + Output: share0_ref1.itemdesc, share0_ref1.item_sk, share0_ref1.solddate, share0_ref1.cnt + -> GroupAggregate (cost=223.67..224.14 rows=6 width=48) + Output: (substr((tpcds_item.i_item_desc)::text, 1, 30)), tpcds_item.i_item_sk, tpcds_date_dim.d_date, count(*) + Group Key: (substr((tpcds_item.i_item_desc)::text, 1, 30)), tpcds_item.i_item_sk, tpcds_date_dim.d_date + Filter: (count(*) > 4) + -> Sort (cost=223.67..223.72 rows=18 width=40) + Output: (substr((tpcds_item.i_item_desc)::text, 1, 30)), tpcds_item.i_item_sk, tpcds_date_dim.d_date + Sort Key: (substr((tpcds_item.i_item_desc)::text, 1, 30)), tpcds_item.i_item_sk, tpcds_date_dim.d_date + -> Hash Join (cost=181.20..223.30 rows=18 width=40) + Output: substr((tpcds_item.i_item_desc)::text, 1, 30), tpcds_item.i_item_sk, tpcds_date_dim.d_date + Hash Cond: (tpcds_item.i_item_sk = tpcds_store_sales.ss_item_sk) + -> Seq Scan on cte_prune.tpcds_item (cost=0.00..39.33 rows=533 width=422) + Output: tpcds_item.i_item_sk, tpcds_item.i_item_id, tpcds_item.i_rec_start_date, tpcds_item.i_rec_end_date, tpcds_item.i_item_desc, tpcds_item.i_current_price, tpcds_item.i_wholesale_cost, tpcds_item.i_brand_id, tpcds_item.i_brand, tpcds_item.i_class_id, tpcds_item.i_class, tpcds_item.i_category_id, tpcds_item.i_category, tpcds_item.i_manufact_id, tpcds_item.i_manufact, tpcds_item.i_size, tpcds_item.i_formulation, tpcds_item.i_color, tpcds_item.i_units, tpcds_item.i_container, tpcds_item.i_manager_id, tpcds_item.i_product_name + -> Hash (cost=180.98..180.98 rows=18 width=8) Output: tpcds_store_sales.ss_item_sk, tpcds_date_dim.d_date - Hash Key: tpcds_store_sales.ss_item_sk - -> Hash Join (cost=89.63..180.62 rows=18 width=8) + -> Redistribute Motion 3:3 (slice3; segments: 3) (cost=89.63..180.98 rows=18 width=8) Output: tpcds_store_sales.ss_item_sk, tpcds_date_dim.d_date - Inner Unique: true - Hash Cond: (tpcds_store_sales.ss_sold_date_sk = tpcds_date_dim.d_date_sk) - -> Seq Scan on cte_prune.tpcds_store_sales (cost=0.00..79.00 rows=4500 width=8) - Output: tpcds_store_sales.ss_sold_date_sk, tpcds_store_sales.ss_sold_time_sk, tpcds_store_sales.ss_item_sk, tpcds_store_sales.ss_customer_sk, tpcds_store_sales.ss_cdemo_sk, tpcds_store_sales.ss_hdemo_sk, tpcds_store_sales.ss_addr_sk, tpcds_store_sales.ss_store_sk, tpcds_store_sales.ss_promo_sk, tpcds_store_sales.ss_ticket_number, tpcds_store_sales.ss_quantity, tpcds_store_sales.ss_wholesale_cost, tpcds_store_sales.ss_list_price, tpcds_store_sales.ss_sales_price, tpcds_store_sales.ss_ext_discount_amt, tpcds_store_sales.ss_ext_sales_price, tpcds_store_sales.ss_ext_wholesale_cost, tpcds_store_sales.ss_ext_list_price, tpcds_store_sales.ss_ext_tax, tpcds_store_sales.ss_coupon_amt, tpcds_store_sales.ss_net_paid, tpcds_store_sales.ss_net_paid_inc_tax, tpcds_store_sales.ss_net_profit - -> Hash (cost=89.08..89.08 rows=44 width=8) - Output: tpcds_date_dim.d_date, tpcds_date_dim.d_date_sk - -> Broadcast Motion 3:3 (slice4; segments: 3) (cost=0.00..89.08 rows=44 width=8) + Hash Key: tpcds_store_sales.ss_item_sk + -> Hash Join (cost=89.63..180.62 rows=18 width=8) + Output: tpcds_store_sales.ss_item_sk, tpcds_date_dim.d_date + Inner Unique: true + Hash Cond: (tpcds_store_sales.ss_sold_date_sk = tpcds_date_dim.d_date_sk) + -> Seq Scan on cte_prune.tpcds_store_sales (cost=0.00..79.00 rows=4500 width=8) + Output: tpcds_store_sales.ss_sold_date_sk, tpcds_store_sales.ss_sold_time_sk, tpcds_store_sales.ss_item_sk, tpcds_store_sales.ss_customer_sk, tpcds_store_sales.ss_cdemo_sk, tpcds_store_sales.ss_hdemo_sk, tpcds_store_sales.ss_addr_sk, tpcds_store_sales.ss_store_sk, tpcds_store_sales.ss_promo_sk, tpcds_store_sales.ss_ticket_number, tpcds_store_sales.ss_quantity, tpcds_store_sales.ss_wholesale_cost, tpcds_store_sales.ss_list_price, tpcds_store_sales.ss_sales_price, tpcds_store_sales.ss_ext_discount_amt, tpcds_store_sales.ss_ext_sales_price, tpcds_store_sales.ss_ext_wholesale_cost, tpcds_store_sales.ss_ext_list_price, tpcds_store_sales.ss_ext_tax, tpcds_store_sales.ss_coupon_amt, tpcds_store_sales.ss_net_paid, tpcds_store_sales.ss_net_paid_inc_tax, tpcds_store_sales.ss_net_profit + -> Hash (cost=89.08..89.08 rows=44 width=8) Output: tpcds_date_dim.d_date, tpcds_date_dim.d_date_sk - -> Seq Scan on cte_prune.tpcds_date_dim (cost=0.00..88.50 rows=15 width=8) + -> Broadcast Motion 3:3 (slice4; segments: 3) (cost=0.00..89.08 rows=44 width=8) Output: tpcds_date_dim.d_date, tpcds_date_dim.d_date_sk - Filter: (tpcds_date_dim.d_year = ANY ('{1999,2000,2001,2002}'::integer[])) + -> Seq Scan on cte_prune.tpcds_date_dim (cost=0.00..88.50 rows=15 width=8) + Output: tpcds_date_dim.d_date, tpcds_date_dim.d_date_sk + Filter: (tpcds_date_dim.d_year = ANY ('{1999,2000,2001,2002}'::integer[])) -> Hash (cost=228.10..228.10 rows=1 width=8) Output: t1.v1, frequent_ss_items_1.item_sk, (RowIdExpr) -> Hash Semi Join (cost=227.05..228.10 rows=1 width=8) @@ -995,8 +1041,9 @@ select t1.v1 from t1 where t1.v1 in (select item_sk from frequent_ss_items where -> Seq Scan on cte_prune.tpcds_item tpcds_item_1 (cost=0.00..40.67 rows=178 width=422) Output: tpcds_item_1.i_item_desc, tpcds_item_1.i_item_sk Filter: (tpcds_item_1.i_item_sk > 0) + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(89 rows) +(91 rows) -- sql 95 explain verbose with ws_wh as @@ -1007,35 +1054,37 @@ explain verbose with ws_wh as select * from t1 where t1.v1 in (select ws_order_number from ws_wh where true) and t1.v1 in (select ws_order_number from ws_wh where ws_order_number > 0); QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=2559.45..2559.67 rows=14 width=12) + Gather Motion 3:1 (slice1; segments: 3) (cost=2674.93..2675.15 rows=14 width=12) Output: t1.v1, t1.v2, t1.v3 - -> HashAggregate (cost=2559.45..2559.49 rows=5 width=12) + -> HashAggregate (cost=2674.93..2674.97 rows=5 width=12) Output: t1.v1, t1.v2, t1.v3 Group Key: (RowIdExpr) - -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=468.73..2559.44 rows=5 width=12) + -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=288.82..2674.92 rows=5 width=12) Output: t1.v1, t1.v2, t1.v3, (RowIdExpr) Hash Key: (RowIdExpr) - -> Hash Join (cost=468.73..2559.35 rows=5 width=12) + -> Hash Join (cost=288.82..2674.83 rows=5 width=12) Output: t1.v1, t1.v2, t1.v3, (RowIdExpr) Hash Cond: (ws_wh.ws_order_number = t1.v1) - -> Subquery Scan on ws_wh (cost=179.92..2181.72 rows=35328 width=4) + -> Subquery Scan on ws_wh (cost=0.00..2119.68 rows=105984 width=4) Output: ws_wh.ws_order_number - -> Hash Join (cost=179.92..2181.72 rows=35328 width=12) - Output: ws1.ws_order_number, ws1.ws_warehouse_sk, ws2.ws_warehouse_sk - Hash Cond: (ws1.ws_order_number = ws2.ws_order_number) - Join Filter: (ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - -> Redistribute Motion 3:3 (slice3; segments: 3) (cost=0.00..137.00 rows=3433 width=8) - Output: ws1.ws_order_number, ws1.ws_warehouse_sk - Hash Key: ws1.ws_order_number - -> Seq Scan on cte_prune.tpcds_web_sales ws1 (cost=0.00..68.33 rows=3433 width=8) + -> Shared Scan (share slice:id 2:0) (cost=2181.72..2225.85 rows=35328 width=12) + Output: share0_ref1.ws_order_number, share0_ref1.wh1, share0_ref1.wh2 + -> Hash Join (cost=179.92..2181.72 rows=35328 width=12) + Output: ws1.ws_order_number, ws1.ws_warehouse_sk, ws2.ws_warehouse_sk + Hash Cond: (ws1.ws_order_number = ws2.ws_order_number) + Join Filter: (ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) + -> Redistribute Motion 3:3 (slice3; segments: 3) (cost=0.00..137.00 rows=3433 width=8) Output: ws1.ws_order_number, ws1.ws_warehouse_sk - -> Hash (cost=137.00..137.00 rows=3433 width=8) - Output: ws2.ws_warehouse_sk, ws2.ws_order_number - -> Redistribute Motion 3:3 (slice4; segments: 3) (cost=0.00..137.00 rows=3433 width=8) + Hash Key: ws1.ws_order_number + -> Seq Scan on cte_prune.tpcds_web_sales ws1 (cost=0.00..68.33 rows=3433 width=8) + Output: ws1.ws_order_number, ws1.ws_warehouse_sk + -> Hash (cost=137.00..137.00 rows=3433 width=8) Output: ws2.ws_warehouse_sk, ws2.ws_order_number - Hash Key: ws2.ws_order_number - -> Seq Scan on cte_prune.tpcds_web_sales ws2 (cost=0.00..68.33 rows=3433 width=8) + -> Redistribute Motion 3:3 (slice4; segments: 3) (cost=0.00..137.00 rows=3433 width=8) Output: ws2.ws_warehouse_sk, ws2.ws_order_number + Hash Key: ws2.ws_order_number + -> Seq Scan on cte_prune.tpcds_web_sales ws2 (cost=0.00..68.33 rows=3433 width=8) + Output: ws2.ws_warehouse_sk, ws2.ws_order_number -> Hash (cost=288.76..288.76 rows=5 width=16) Output: t1.v1, t1.v2, t1.v3, ws_wh_1.ws_order_number, (RowIdExpr) -> Redistribute Motion 3:3 (slice5; segments: 3) (cost=288.58..288.76 rows=5 width=16) @@ -1076,8 +1125,9 @@ select * from t1 where t1.v1 in (select ws_order_number from ws_wh where true) a Output: t1.v1, t1.v2, t1.v3, (RowIdExpr) -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) Output: t1.v1, t1.v2, t1.v3, RowIdExpr + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(71 rows) +(73 rows) explain verbose with ws_wh as (select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 @@ -1085,80 +1135,83 @@ explain verbose with ws_wh as where ws1.ws_order_number = ws2.ws_order_number and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) select * from t1 where t1.v1 in (select wh1 from ws_wh where true) and t1.v1 in (select wh1 from ws_wh where ws_order_number > 0); - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - Gather Motion 3:1 (slice1; segments: 3) (cost=2560.02..2560.25 rows=14 width=12) + QUERY PLAN +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) (cost=2675.59..2675.82 rows=14 width=12) Output: t1.v1, t1.v2, t1.v3 - -> HashAggregate (cost=2560.02..2560.07 rows=5 width=12) + -> HashAggregate (cost=2675.59..2675.64 rows=5 width=12) Output: t1.v1, t1.v2, t1.v3 Group Key: (RowIdExpr) - -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=469.15..2560.01 rows=5 width=12) + -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=2502.16..2675.58 rows=5 width=12) Output: t1.v1, t1.v2, t1.v3, (RowIdExpr) Hash Key: (RowIdExpr) - -> Hash Join (cost=469.15..2559.92 rows=5 width=12) + -> Hash Join (cost=2502.16..2675.49 rows=5 width=12) Output: t1.v1, t1.v2, t1.v3, (RowIdExpr) Hash Cond: (ws_wh.wh1 = t1.v1) - -> Subquery Scan on ws_wh (cost=179.92..2181.72 rows=35328 width=4) + -> Subquery Scan on ws_wh (cost=114.11..277.50 rows=3925 width=4) Output: ws_wh.wh1 - -> Hash Join (cost=179.92..2181.72 rows=35328 width=12) + -> Hash Join (cost=114.11..277.50 rows=3925 width=12) Output: ws1.ws_order_number, ws1.ws_warehouse_sk, ws2.ws_warehouse_sk Hash Cond: (ws1.ws_order_number = ws2.ws_order_number) Join Filter: (ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) - -> Redistribute Motion 3:3 (slice3; segments: 3) (cost=0.00..137.00 rows=3433 width=8) + -> Redistribute Motion 3:3 (slice3; segments: 3) (cost=0.00..99.81 rows=1144 width=8) Output: ws1.ws_order_number, ws1.ws_warehouse_sk Hash Key: ws1.ws_order_number - -> Seq Scan on cte_prune.tpcds_web_sales ws1 (cost=0.00..68.33 rows=3433 width=8) + -> Seq Scan on cte_prune.tpcds_web_sales ws1 (cost=0.00..76.92 rows=1144 width=8) Output: ws1.ws_order_number, ws1.ws_warehouse_sk - -> Hash (cost=137.00..137.00 rows=3433 width=8) + Filter: (ws1.ws_order_number > 0) + -> Hash (cost=99.81..99.81 rows=1144 width=8) Output: ws2.ws_warehouse_sk, ws2.ws_order_number - -> Redistribute Motion 3:3 (slice4; segments: 3) (cost=0.00..137.00 rows=3433 width=8) + -> Redistribute Motion 3:3 (slice4; segments: 3) (cost=0.00..99.81 rows=1144 width=8) Output: ws2.ws_warehouse_sk, ws2.ws_order_number Hash Key: ws2.ws_order_number - -> Seq Scan on cte_prune.tpcds_web_sales ws2 (cost=0.00..68.33 rows=3433 width=8) + -> Seq Scan on cte_prune.tpcds_web_sales ws2 (cost=0.00..76.92 rows=1144 width=8) Output: ws2.ws_warehouse_sk, ws2.ws_order_number - -> Hash (cost=289.07..289.07 rows=14 width=16) + Filter: (ws2.ws_order_number > 0) + -> Hash (cost=2387.82..2387.82 rows=18 width=16) Output: t1.v1, t1.v2, t1.v3, ws_wh_1.wh1, (RowIdExpr) - -> Broadcast Motion 3:3 (slice5; segments: 3) (cost=288.80..289.07 rows=14 width=16) + -> Broadcast Motion 3:3 (slice5; segments: 3) (cost=2387.45..2387.82 rows=18 width=16) Output: t1.v1, t1.v2, t1.v3, ws_wh_1.wh1, (RowIdExpr) - -> Result (cost=288.80..288.89 rows=5 width=16) + -> Result (cost=2387.45..2387.57 rows=6 width=16) Output: t1.v1, t1.v2, t1.v3, ws_wh_1.wh1, RowIdExpr - -> HashAggregate (cost=288.80..288.84 rows=5 width=16) + -> HashAggregate (cost=2387.45..2387.51 rows=6 width=16) Output: t1.v1, t1.v2, t1.v3, ws_wh_1.wh1 Group Key: (RowIdExpr) - -> Redistribute Motion 3:3 (slice6; segments: 3) (cost=115.40..288.79 rows=5 width=16) + -> Redistribute Motion 3:3 (slice6; segments: 3) (cost=1.29..2387.44 rows=6 width=16) Output: t1.v1, t1.v2, t1.v3, ws_wh_1.wh1, (RowIdExpr) Hash Key: (RowIdExpr) - -> Hash Join (cost=115.40..288.70 rows=5 width=16) + -> Hash Join (cost=1.29..2387.32 rows=6 width=16) Output: t1.v1, t1.v2, t1.v3, ws_wh_1.wh1, (RowIdExpr) Hash Cond: (ws_wh_1.wh1 = t1.v1) - -> Subquery Scan on ws_wh_1 (cost=114.11..277.50 rows=3925 width=4) + -> Subquery Scan on ws_wh_1 (cost=0.00..2119.68 rows=105984 width=4) Output: ws_wh_1.wh1 - -> Hash Join (cost=114.11..277.50 rows=3925 width=12) - Output: ws1_1.ws_order_number, ws1_1.ws_warehouse_sk, ws2_1.ws_warehouse_sk - Hash Cond: (ws1_1.ws_order_number = ws2_1.ws_order_number) - Join Filter: (ws1_1.ws_warehouse_sk <> ws2_1.ws_warehouse_sk) - -> Redistribute Motion 3:3 (slice7; segments: 3) (cost=0.00..99.81 rows=1144 width=8) - Output: ws1_1.ws_order_number, ws1_1.ws_warehouse_sk - Hash Key: ws1_1.ws_order_number - -> Seq Scan on cte_prune.tpcds_web_sales ws1_1 (cost=0.00..76.92 rows=1144 width=8) + -> Shared Scan (share slice:id 6:0) (cost=2181.72..2225.85 rows=35328 width=12) + Output: share0_ref1.ws_order_number, share0_ref1.wh1, share0_ref1.wh2 + -> Hash Join (cost=179.92..2181.72 rows=35328 width=12) + Output: ws1_1.ws_order_number, ws1_1.ws_warehouse_sk, ws2_1.ws_warehouse_sk + Hash Cond: (ws1_1.ws_order_number = ws2_1.ws_order_number) + Join Filter: (ws1_1.ws_warehouse_sk <> ws2_1.ws_warehouse_sk) + -> Redistribute Motion 3:3 (slice7; segments: 3) (cost=0.00..137.00 rows=3433 width=8) Output: ws1_1.ws_order_number, ws1_1.ws_warehouse_sk - Filter: (ws1_1.ws_order_number > 0) - -> Hash (cost=99.81..99.81 rows=1144 width=8) - Output: ws2_1.ws_warehouse_sk, ws2_1.ws_order_number - -> Redistribute Motion 3:3 (slice8; segments: 3) (cost=0.00..99.81 rows=1144 width=8) + Hash Key: ws1_1.ws_order_number + -> Seq Scan on cte_prune.tpcds_web_sales ws1_1 (cost=0.00..68.33 rows=3433 width=8) + Output: ws1_1.ws_order_number, ws1_1.ws_warehouse_sk + -> Hash (cost=137.00..137.00 rows=3433 width=8) Output: ws2_1.ws_warehouse_sk, ws2_1.ws_order_number - Hash Key: ws2_1.ws_order_number - -> Seq Scan on cte_prune.tpcds_web_sales ws2_1 (cost=0.00..76.92 rows=1144 width=8) + -> Redistribute Motion 3:3 (slice8; segments: 3) (cost=0.00..137.00 rows=3433 width=8) Output: ws2_1.ws_warehouse_sk, ws2_1.ws_order_number - Filter: (ws2_1.ws_order_number > 0) + Hash Key: ws2_1.ws_order_number + -> Seq Scan on cte_prune.tpcds_web_sales ws2_1 (cost=0.00..68.33 rows=3433 width=8) + Output: ws2_1.ws_warehouse_sk, ws2_1.ws_order_number -> Hash (cost=1.17..1.17 rows=10 width=12) Output: t1.v1, t1.v2, t1.v3, (RowIdExpr) -> Broadcast Motion 3:3 (slice9; segments: 3) (cost=0.00..1.17 rows=10 width=12) Output: t1.v1, t1.v2, t1.v3, (RowIdExpr) -> Seq Scan on cte_prune.t1 (cost=0.00..1.03 rows=3 width=12) Output: t1.v1, t1.v2, t1.v3, RowIdExpr + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(72 rows) +(74 rows) -- start_ignore drop table tpcds_store_sales; @@ -1191,88 +1244,81 @@ t WHERE cup.e < 10 GROUP BY cup.c,cup.d, cup.e ,t.d, t.b ORDER BY 1,2,3,4 LIMIT 10; - QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - Limit (cost=20000000030.98..20000000031.12 rows=10 width=56) + QUERY PLAN +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Limit (cost=20000000028.83..20000000028.97 rows=10 width=56) Output: cup.c, cup.d, cup.e, (sum(t.d) OVER (?)), t.d, t.b - -> Gather Motion 3:1 (slice1; segments: 3) (cost=20000000030.98..20000000031.41 rows=30 width=56) + -> Gather Motion 3:1 (slice1; segments: 3) (cost=20000000028.83..20000000029.25 rows=30 width=56) Output: cup.c, cup.d, cup.e, (sum(t.d) OVER (?)), t.d, t.b Merge Key: cup.c, cup.d, cup.e, (sum(t.d) OVER (?)) - -> Limit (cost=20000000030.98..20000000031.01 rows=10 width=56) + -> Limit (cost=20000000028.83..20000000028.85 rows=10 width=56) Output: cup.c, cup.d, cup.e, (sum(t.d) OVER (?)), t.d, t.b - -> Sort (cost=20000000030.98..20000000031.26 rows=111 width=56) + -> Sort (cost=20000000028.83..20000000029.11 rows=111 width=56) Output: cup.c, cup.d, cup.e, (sum(t.d) OVER (?)), t.d, t.b Sort Key: cup.c, cup.d, cup.e, (sum(t.d) OVER (?)) - -> WindowAgg (cost=20000000026.64..20000000028.58 rows=111 width=56) + -> WindowAgg (cost=20000000024.48..20000000026.43 rows=111 width=56) Output: cup.c, cup.d, cup.e, sum(t.d) OVER (?), t.d, t.b Partition By: t.b - -> Sort (cost=20000000026.64..20000000026.91 rows=111 width=48) + -> Sort (cost=20000000024.48..20000000024.76 rows=111 width=48) Output: cup.c, cup.d, cup.e, t.d, t.b Sort Key: t.b - -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=20000000017.86..20000000022.86 rows=111 width=48) + -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=20000000015.71..20000000020.71 rows=111 width=48) Output: cup.c, cup.d, cup.e, t.d, t.b Hash Key: t.b - -> GroupAggregate (cost=20000000017.86..20000000020.64 rows=111 width=48) + -> GroupAggregate (cost=20000000015.71..20000000018.49 rows=111 width=48) Output: cup.c, cup.d, cup.e, t.d, t.b Group Key: cup.c, cup.d, cup.e, t.d, t.b - -> Sort (cost=20000000017.86..20000000018.14 rows=111 width=48) + -> Sort (cost=20000000015.71..20000000015.99 rows=111 width=48) Output: cup.c, cup.d, cup.e, t.d, t.b Sort Key: cup.c, cup.d, cup.e, t.d, t.b - -> Redistribute Motion 3:3 (slice3; segments: 3) (cost=20000000008.36..20000000014.08 rows=111 width=48) + -> Redistribute Motion 3:3 (slice3; segments: 3) (cost=20000000004.11..20000000011.93 rows=111 width=48) Output: cup.c, cup.d, cup.e, t.d, t.b Hash Key: cup.c, cup.d, cup.e, t.d, t.b - -> Nested Loop (cost=20000000008.36..20000000011.86 rows=111 width=48) + -> Nested Loop (cost=20000000004.11..20000000009.71 rows=111 width=48) Output: cup.c, cup.d, cup.e, t.d, t.b - -> Broadcast Motion 3:3 (slice4; segments: 3) (cost=1.08..2.35 rows=10 width=8) + -> Broadcast Motion 3:3 (slice4; segments: 3) (cost=0.00..0.60 rows=30 width=8) Output: t.d, t.b - -> Subquery Scan on t (cost=1.08..2.22 rows=3 width=8) + -> Subquery Scan on t (cost=0.00..0.20 rows=10 width=8) Output: t.d, t.b - -> Hash Join (cost=1.08..2.22 rows=3 width=12) - Output: t3.a, t3.b, t4.d - Hash Cond: (t4.d = t3.a) - -> Redistribute Motion 3:3 (slice5; segments: 3) (cost=0.00..1.10 rows=3 width=4) - Output: t4.d - Hash Key: t4.d - -> Seq Scan on cte_prune.t4 (cost=0.00..1.03 rows=3 width=4) + -> Shared Scan (share slice:id 4:0) (cost=2.22..2.42 rows=3 width=12) + Output: share0_ref1.a, share0_ref1.b, share0_ref1.d + -> Hash Join (cost=1.08..2.22 rows=3 width=12) + Output: t3.a, t3.b, t4.d + Hash Cond: (t4.d = t3.a) + -> Redistribute Motion 3:3 (slice5; segments: 3) (cost=0.00..1.10 rows=3 width=4) Output: t4.d - -> Hash (cost=1.03..1.03 rows=3 width=8) - Output: t3.a, t3.b - -> Seq Scan on cte_prune.t3 (cost=0.00..1.03 rows=3 width=8) + Hash Key: t4.d + -> Seq Scan on cte_prune.t4 (cost=0.00..1.03 rows=3 width=4) + Output: t4.d + -> Hash (cost=1.03..1.03 rows=3 width=8) Output: t3.a, t3.b - -> Materialize (cost=10000000007.29..10000000008.15 rows=11 width=40) + -> Seq Scan on cte_prune.t3 (cost=0.00..1.03 rows=3 width=8) + Output: t3.a, t3.b + -> Materialize (cost=10000000004.11..10000000004.97 rows=11 width=40) Output: cup.c, cup.d, cup.e - -> Subquery Scan on cup (cost=10000000007.29..10000000008.09 rows=11 width=40) + -> Subquery Scan on cup (cost=10000000004.11..10000000004.92 rows=11 width=40) Output: cup.c, cup.d, cup.e Filter: (cup.e < '10'::numeric) - -> WindowAgg (cost=10000000007.29..10000000007.95 rows=33 width=48) - Output: t4_1.c, t4_1.d, avg(t3_1.b) OVER (?), t3_1.b, t3_1.a - Partition By: t3_1.a - Order By: t3_1.b - -> Sort (cost=10000000007.29..10000000007.37 rows=33 width=16) - Output: t3_1.b, t3_1.a, t4_1.c, t4_1.d - Sort Key: t3_1.a, t3_1.b DESC - -> Nested Loop (cost=10000000001.08..10000000006.44 rows=33 width=16) - Output: t3_1.b, t3_1.a, t4_1.c, t4_1.d - -> Hash Join (cost=1.08..2.22 rows=3 width=12) - Output: t3_1.a, t3_1.b, t4_2.d - Hash Cond: (t4_2.d = t3_1.a) - -> Redistribute Motion 3:3 (slice6; segments: 3) (cost=0.00..1.10 rows=3 width=4) - Output: t4_2.d - Hash Key: t4_2.d - -> Seq Scan on cte_prune.t4 t4_2 (cost=0.00..1.03 rows=3 width=4) - Output: t4_2.d - -> Hash (cost=1.03..1.03 rows=3 width=8) - Output: t3_1.a, t3_1.b - -> Seq Scan on cte_prune.t3 t3_1 (cost=0.00..1.03 rows=3 width=8) - Output: t3_1.a, t3_1.b - -> Materialize (cost=0.00..1.22 rows=10 width=8) + -> WindowAgg (cost=10000000004.11..10000000004.78 rows=33 width=48) + Output: t4_1.c, t4_1.d, avg(share0_ref2.b) OVER (?), share0_ref2.b, share0_ref2.a + Partition By: share0_ref2.a + Order By: share0_ref2.b + -> Sort (cost=10000000004.11..10000000004.19 rows=33 width=16) + Output: share0_ref2.b, share0_ref2.a, t4_1.c, t4_1.d + Sort Key: share0_ref2.a, share0_ref2.b DESC + -> Nested Loop (cost=10000000000.00..10000000003.27 rows=33 width=16) + Output: share0_ref2.b, share0_ref2.a, t4_1.c, t4_1.d + -> Broadcast Motion 3:3 (slice6; segments: 3) (cost=0.00..1.17 rows=10 width=8) Output: t4_1.c, t4_1.d - -> Broadcast Motion 3:3 (slice7; segments: 3) (cost=0.00..1.17 rows=10 width=8) + -> Seq Scan on cte_prune.t4 t4_1 (cost=0.00..1.03 rows=3 width=8) Output: t4_1.c, t4_1.d - -> Seq Scan on cte_prune.t4 t4_1 (cost=0.00..1.03 rows=3 width=8) - Output: t4_1.c, t4_1.d + -> Materialize (cost=0.00..0.25 rows=10 width=8) + Output: share0_ref2.a, share0_ref2.b, share0_ref2.d + -> Shared Scan (share slice:id 3:0) (cost=2.22..2.42 rows=3 width=12) + Output: share0_ref2.a, share0_ref2.b, share0_ref2.d + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(80 rows) +(72 rows) WITH t(a,b,d) AS ( @@ -1521,113 +1567,90 @@ where FOO.code = bad_headofstates.code and FOO.capital = city.id) OUTER_FOO group by region ) OUTERMOST_FOO,bad_headofstates,country where country.code = bad_headofstates.code and country.region = OUTERMOST_FOO.region order by OUTERMOST_FOO.region,bad_headofstates.headofstate LIMIT 40; - QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - Limit (cost=3470.04..3470.61 rows=40 width=96) - Output: (avg(country_2.population)), country_2.region, country_1.headofstate - -> Gather Motion 3:1 (slice1; segments: 3) (cost=3470.04..3471.74 rows=120 width=96) - Output: (avg(country_2.population)), country_2.region, country_1.headofstate - Merge Key: country_2.region, country_1.headofstate - -> Limit (cost=3470.04..3470.14 rows=40 width=96) - Output: (avg(country_2.population)), country_2.region, country_1.headofstate - -> Sort (cost=3470.04..3479.16 rows=3648 width=96) - Output: (avg(country_2.population)), country_2.region, country_1.headofstate - Sort Key: country_2.region, country_1.headofstate - -> Hash Join (cost=2912.21..3354.72 rows=3648 width=96) - Output: (avg(country_2.population)), country_2.region, country_1.headofstate + QUERY PLAN +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + Limit (cost=2810.99..2811.56 rows=40 width=96) + Output: (avg(country_1.population)), country_1.region, share0_ref3.headofstate + -> Gather Motion 3:1 (slice1; segments: 3) (cost=2810.99..2812.69 rows=120 width=96) + Output: (avg(country_1.population)), country_1.region, share0_ref3.headofstate + Merge Key: country_1.region, share0_ref3.headofstate + -> Limit (cost=2810.99..2811.09 rows=40 width=96) + Output: (avg(country_1.population)), country_1.region, share0_ref3.headofstate + -> Sort (cost=2810.99..2820.11 rows=3648 width=96) + Output: (avg(country_1.population)), country_1.region, share0_ref3.headofstate + Sort Key: country_1.region, share0_ref3.headofstate + -> Hash Join (cost=2365.51..2695.67 rows=3648 width=96) + Output: (avg(country_1.population)), country_1.region, share0_ref3.headofstate Inner Unique: true - Hash Cond: (country.region = country_2.region) - -> Hash Join (cost=222.07..618.52 rows=3648 width=64) - Output: country_1.headofstate, country.region + Hash Cond: (country.region = country_1.region) + -> Hash Join (cost=112.00..396.10 rows=3648 width=64) + Output: share0_ref3.headofstate, country.region Inner Unique: true - Hash Cond: (country_1.code = country.code) - -> Hash Join (cost=110.07..460.46 rows=3648 width=112) - Output: country_1.code, country_1.name, country_1.headofstate, countrylanguage.language - Inner Unique: true - Hash Cond: (countrylanguage.countrycode = country_1.code) - -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.00..296.67 rows=6567 width=48) - Output: countrylanguage.language, countrylanguage.countrycode - Hash Key: countrylanguage.countrycode - -> Seq Scan on cte_prune.countrylanguage (cost=0.00..165.33 rows=6567 width=48) - Output: countrylanguage.language, countrylanguage.countrycode - Filter: countrylanguage.isofficial - -> Hash (cost=86.00..86.00 rows=1926 width=80) - Output: country_1.code, country_1.name, country_1.headofstate - -> Seq Scan on cte_prune.country country_1 (cost=0.00..86.00 rows=1926 width=80) - Output: country_1.code, country_1.name, country_1.headofstate - Filter: ((country_1.gnp < country_1.gnpold) OR (country_1.gnp < '3000'::numeric)) + Hash Cond: (share0_ref3.code = country.code) + -> Shared Scan (share slice:id 1:0) (cost=460.46..467.31 rows=3648 width=112) + Output: share0_ref3.code, share0_ref3.name, share0_ref3.headofstate, share0_ref3.language -> Hash (cost=68.67..68.67 rows=3467 width=48) Output: country.code, country.region -> Seq Scan on cte_prune.country (cost=0.00..68.67 rows=3467 width=48) Output: country.code, country.region - -> Hash (cost=2677.64..2677.64 rows=1000 width=64) - Output: (avg(country_2.population)), country_2.region - -> Broadcast Motion 3:3 (slice3; segments: 3) (cost=2660.14..2677.64 rows=1000 width=64) - Output: (avg(country_2.population)), country_2.region - -> Finalize HashAggregate (cost=2660.14..2664.31 rows=333 width=64) - Output: avg(country_2.population), country_2.region - Group Key: country_2.region - -> Redistribute Motion 3:3 (slice4; segments: 3) (cost=2625.14..2655.14 rows=1000 width=64) - Output: country_2.region, (PARTIAL avg(country_2.population)) - Hash Key: country_2.region - -> Streaming Partial HashAggregate (cost=2625.14..2635.14 rows=1000 width=64) - Output: country_2.region, PARTIAL avg(country_2.population) - Group Key: country_2.region - -> Hash Join (cost=1662.17..2425.51 rows=39927 width=36) - Output: country_2.region, country_2.population - Hash Cond: (country_3.code = country_2.code) - -> Hash Join (cost=110.07..460.46 rows=3648 width=112) - Output: country_3.code, country_3.name, country_3.headofstate, countrylanguage_1.language - Inner Unique: true - Hash Cond: (countrylanguage_1.countrycode = country_3.code) - -> Redistribute Motion 3:3 (slice5; segments: 3) (cost=0.00..296.67 rows=6567 width=48) - Output: countrylanguage_1.language, countrylanguage_1.countrycode - Hash Key: countrylanguage_1.countrycode - -> Seq Scan on cte_prune.countrylanguage countrylanguage_1 (cost=0.00..165.33 rows=6567 width=48) - Output: countrylanguage_1.language, countrylanguage_1.countrycode - Filter: countrylanguage_1.isofficial - -> Hash (cost=86.00..86.00 rows=1926 width=80) - Output: country_3.code, country_3.name, country_3.headofstate - -> Seq Scan on cte_prune.country country_3 (cost=0.00..86.00 rows=1926 width=80) - Output: country_3.code, country_3.name, country_3.headofstate - Filter: ((country_3.gnp < country_3.gnpold) OR (country_3.gnp < '3000'::numeric)) - -> Hash (cost=1506.49..1506.49 rows=3648 width=68) - Output: country_2.population, country_2.region, country_2.code, country_4.code - -> Hash Join (cost=1063.99..1506.49 rows=3648 width=68) - Output: country_2.population, country_2.region, country_2.code, country_4.code + -> Hash (cost=2241.01..2241.01 rows=1000 width=64) + Output: (avg(country_1.population)), country_1.region + -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=2223.51..2241.01 rows=1000 width=64) + Output: (avg(country_1.population)), country_1.region + -> Finalize HashAggregate (cost=2223.51..2227.68 rows=333 width=64) + Output: avg(country_1.population), country_1.region + Group Key: country_1.region + -> Redistribute Motion 3:3 (slice3; segments: 3) (cost=2188.51..2218.51 rows=1000 width=64) + Output: country_1.region, (PARTIAL avg(country_1.population)) + Hash Key: country_1.region + -> Streaming Partial HashAggregate (cost=2188.51..2198.51 rows=1000 width=64) + Output: country_1.region, PARTIAL avg(country_1.population) + Group Key: country_1.region + -> Hash Join (cost=1329.68..1988.88 rows=39927 width=36) + Output: country_1.region, country_1.population + Hash Cond: (share0_ref2.code = country_1.code) + -> Shared Scan (share slice:id 3:0) (cost=460.46..467.31 rows=3648 width=112) + Output: share0_ref2.code, share0_ref2.name, share0_ref2.headofstate, share0_ref2.language + -> Hash (cost=1284.08..1284.08 rows=3648 width=68) + Output: country_1.population, country_1.region, country_1.code, share0_ref1.code + -> Hash Join (cost=953.92..1284.08 rows=3648 width=68) + Output: country_1.population, country_1.region, country_1.code, share0_ref1.code Inner Unique: true - Hash Cond: (country_2.capital = city.id) - -> Hash Join (cost=222.07..618.52 rows=3648 width=72) - Output: country_2.population, country_2.region, country_2.code, country_2.capital, country_4.code + Hash Cond: (country_1.capital = city.id) + -> Hash Join (cost=112.00..396.10 rows=3648 width=72) + Output: country_1.population, country_1.region, country_1.code, country_1.capital, share0_ref1.code Inner Unique: true - Hash Cond: (country_4.code = country_2.code) - -> Hash Join (cost=110.07..460.46 rows=3648 width=112) - Output: country_4.code, country_4.name, country_4.headofstate, countrylanguage_2.language - Inner Unique: true - Hash Cond: (countrylanguage_2.countrycode = country_4.code) - -> Redistribute Motion 3:3 (slice6; segments: 3) (cost=0.00..296.67 rows=6567 width=48) - Output: countrylanguage_2.language, countrylanguage_2.countrycode - Hash Key: countrylanguage_2.countrycode - -> Seq Scan on cte_prune.countrylanguage countrylanguage_2 (cost=0.00..165.33 rows=6567 width=48) - Output: countrylanguage_2.language, countrylanguage_2.countrycode - Filter: countrylanguage_2.isofficial - -> Hash (cost=86.00..86.00 rows=1926 width=80) - Output: country_4.code, country_4.name, country_4.headofstate - -> Seq Scan on cte_prune.country country_4 (cost=0.00..86.00 rows=1926 width=80) - Output: country_4.code, country_4.name, country_4.headofstate - Filter: ((country_4.gnp < country_4.gnpold) OR (country_4.gnp < '3000'::numeric)) + Hash Cond: (share0_ref1.code = country_1.code) + -> Shared Scan (share slice:id 3:0) (cost=460.46..467.31 rows=3648 width=112) + Output: share0_ref1.code, share0_ref1.name, share0_ref1.headofstate, share0_ref1.language + -> Hash Join (cost=110.07..460.46 rows=3648 width=112) + Output: country_2.code, country_2.name, country_2.headofstate, countrylanguage.language + Inner Unique: true + Hash Cond: (countrylanguage.countrycode = country_2.code) + -> Redistribute Motion 3:3 (slice4; segments: 3) (cost=0.00..296.67 rows=6567 width=48) + Output: countrylanguage.language, countrylanguage.countrycode + Hash Key: countrylanguage.countrycode + -> Seq Scan on cte_prune.countrylanguage (cost=0.00..165.33 rows=6567 width=48) + Output: countrylanguage.language, countrylanguage.countrycode + Filter: countrylanguage.isofficial + -> Hash (cost=86.00..86.00 rows=1926 width=80) + Output: country_2.code, country_2.name, country_2.headofstate + -> Seq Scan on cte_prune.country country_2 (cost=0.00..86.00 rows=1926 width=80) + Output: country_2.code, country_2.name, country_2.headofstate + Filter: ((country_2.gnp < country_2.gnpold) OR (country_2.gnp < '3000'::numeric)) -> Hash (cost=68.67..68.67 rows=3467 width=56) - Output: country_2.population, country_2.region, country_2.code, country_2.capital - -> Seq Scan on cte_prune.country country_2 (cost=0.00..68.67 rows=3467 width=56) - Output: country_2.population, country_2.region, country_2.code, country_2.capital + Output: country_1.population, country_1.region, country_1.code, country_1.capital + -> Seq Scan on cte_prune.country country_1 (cost=0.00..68.67 rows=3467 width=56) + Output: country_1.population, country_1.region, country_1.code, country_1.capital -> Hash (cost=495.67..495.67 rows=27700 width=4) Output: city.id - -> Broadcast Motion 3:3 (slice7; segments: 3) (cost=0.00..495.67 rows=27700 width=4) + -> Broadcast Motion 3:3 (slice5; segments: 3) (cost=0.00..495.67 rows=27700 width=4) Output: city.id -> Seq Scan on cte_prune.city (cost=0.00..126.33 rows=9233 width=4) Output: city.id + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(105 rows) +(81 rows) -- start_ignore drop table city; @@ -1651,29 +1674,31 @@ FROM t6, WHERE t6.a = x.c ORDER BY 1; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=823896670.55..983160271.77 rows=11242136557 width=16) + Gather Motion 3:1 (slice1; segments: 3) (cost=827529160.44..986792761.66 rows=11242136557 width=16) Output: t6.a, t6.b, t5_1.c, t5_1.d Merge Key: t6.a - -> Sort (cost=823896670.55..833265117.68 rows=3747378852 width=16) + -> Sort (cost=827529160.44..836897607.57 rows=3747378852 width=16) Output: t6.a, t6.b, t5_1.c, t5_1.d Sort Key: t6.a - -> Hash Join (cost=4997.05..195981758.94 rows=3747378852 width=16) + -> Hash Join (cost=4484.72..199614248.84 rows=3747378852 width=16) Output: t6.a, t6.b, t5_1.c, t5_1.d Hash Cond: (t5_1.c = t6.a) - -> Hash Join (cost=4317.30..2257696.25 rows=43523564 width=8) + -> Hash Join (cost=3804.97..5890186.14 rows=43523564 width=8) Output: t5_1.c, t5_1.d - Hash Cond: (t5.c = t5_1.c) - -> Hash Join (cost=512.33..4777.51 rows=158519 width=8) - Output: t5.c, t5.d - Hash Cond: (t6_1.a = t5.c) - -> Seq Scan on cte_prune.t6 t6_1 (cost=0.00..464.50 rows=5523 width=8) - Output: t6_1.a, t6_1.b - Filter: ((t6_1.b < 5) AND (t6_1.a < 2)) - -> Hash (cost=392.75..392.75 rows=9567 width=8) + Hash Cond: (share0_ref1.c = t5_1.c) + -> Shared Scan (share slice:id 1:0) (cost=4777.51..4967.03 rows=158519 width=8) + Output: share0_ref1.c, share0_ref1.d + -> Hash Join (cost=512.33..4777.51 rows=158519 width=8) Output: t5.c, t5.d - -> Seq Scan on cte_prune.t5 (cost=0.00..392.75 rows=9567 width=8) + Hash Cond: (t6_1.a = t5.c) + -> Seq Scan on cte_prune.t6 t6_1 (cost=0.00..464.50 rows=5523 width=8) + Output: t6_1.a, t6_1.b + Filter: ((t6_1.b < 5) AND (t6_1.a < 2)) + -> Hash (cost=392.75..392.75 rows=9567 width=8) Output: t5.c, t5.d - Filter: (t5.c < 2) + -> Seq Scan on cte_prune.t5 (cost=0.00..392.75 rows=9567 width=8) + Output: t5.c, t5.d + Filter: (t5.c < 2) -> Hash (cost=2660.95..2660.95 rows=91521 width=8) Output: t5_1.c, t5_1.d -> Hash Join (cost=533.54..2660.95 rows=91521 width=8) @@ -1693,8 +1718,9 @@ WHERE t6.a = x.c ORDER BY 1; Output: t6.a, t6.b -> Seq Scan on cte_prune.t6 (cost=0.00..321.00 rows=28700 width=8) Output: t6.a, t6.b + Settings: optimizer = 'off' Optimizer: Postgres query optimizer -(43 rows) +(46 rows) WITH w AS (SELECT a, b from t6 where b < 5) SELECT * diff --git a/src/test/regress/expected/cte_prune_multi_consumer.out b/src/test/regress/expected/cte_prune_multi_consumer.out index 293ec629470..fe06f7567e5 100644 --- a/src/test/regress/expected/cte_prune_multi_consumer.out +++ b/src/test/regress/expected/cte_prune_multi_consumer.out @@ -143,32 +143,33 @@ from agent x join agent y on x.p_id=y.p_id join agent z on x.p_id=z.p_id order by 1,2,3; - QUERY PLAN ------------------------------------------------------------------------------- + QUERY PLAN +------------------------------------------------------------------------------------ Gather Motion 3:1 (slice1; segments: 3) Merge Key: x.p_id, y.amnt, z.main_risk -> Sort Sort Key: x.p_id, y.amnt, z.main_risk -> Hash Join - Hash Cond: (x.p_id = z.p_id) - -> Hash Join - Hash Cond: (x.p_id = y.p_id) - -> Redistribute Motion 3:3 (slice2; segments: 3) - Hash Key: x.p_id - -> Subquery Scan on x - -> Seq Scan on policy - -> Hash - -> Redistribute Motion 3:3 (slice3; segments: 3) - Hash Key: y.p_id - -> Subquery Scan on y - -> Seq Scan on policy policy_1 + Hash Cond: (z.p_id = x.p_id) + -> Redistribute Motion 3:3 (slice2; segments: 3) + Hash Key: z.p_id + -> Subquery Scan on z + -> Shared Scan (share slice:id 2:0) -> Hash - -> Redistribute Motion 3:3 (slice4; segments: 3) - Hash Key: z.p_id - -> Subquery Scan on z - -> Seq Scan on policy policy_2 + -> Hash Join + Hash Cond: (x.p_id = y.p_id) + -> Redistribute Motion 3:3 (slice3; segments: 3) + Hash Key: x.p_id + -> Subquery Scan on x + -> Shared Scan (share slice:id 3:0) + -> Hash + -> Redistribute Motion 3:3 (slice4; segments: 3) + Hash Key: y.p_id + -> Subquery Scan on y + -> Shared Scan (share slice:id 4:0) + -> Seq Scan on policy Optimizer: Postgres query optimizer -(23 rows) +(24 rows) with agent as (select p_id, amnt, main_risk, premium from policy) select x.p_id, y.amnt, z.main_risk diff --git a/src/test/regress/expected/dedupset.out b/src/test/regress/expected/dedupset.out index bcf9b7f1123..82b9c1bfcfb 100644 --- a/src/test/regress/expected/dedupset.out +++ b/src/test/regress/expected/dedupset.out @@ -225,36 +225,38 @@ select * from pt1 where v1 in (select v3 from pt2 where v3 < 10); explain verbose with cte1 as (select v3 from t2) select count(*) from t1,t2 where t1.v1 in (select v3 from cte1) and t1.v1 in (select v3 from cte1 where v3 < 10); QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------- - Finalize Aggregate (cost=10000000015.48..10000000015.49 rows=1 width=8) + Finalize Aggregate (cost=10000000015.96..10000000015.97 rows=1 width=8) Output: count(*) - -> Gather Motion 3:1 (slice1; segments: 3) (cost=10000000015.43..10000000015.48 rows=3 width=8) + -> Gather Motion 3:1 (slice1; segments: 3) (cost=10000000015.90..10000000015.95 rows=3 width=8) Output: (PARTIAL count(*)) - -> Partial Aggregate (cost=10000000015.43..10000000015.44 rows=1 width=8) + -> Partial Aggregate (cost=10000000015.90..10000000015.91 rows=1 width=8) Output: PARTIAL count(*) - -> Nested Loop (cost=10000000004.85..10000000014.75 rows=270 width=0) - -> Result (cost=4.85..4.86 rows=3 width=0) - -> Unique (cost=4.85..4.86 rows=3 width=0) + -> Nested Loop (cost=10000000005.32..10000000015.23 rows=270 width=0) + -> Result (cost=5.32..5.34 rows=3 width=0) + -> Unique (cost=5.32..5.34 rows=3 width=0) Output: (RowIdExpr) Group Key: (RowIdExpr) - -> Sort (cost=4.85..4.86 rows=3 width=0) + -> Sort (cost=5.32..5.33 rows=3 width=0) Output: (RowIdExpr) Sort Key: (RowIdExpr) - -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=2.96..4.83 rows=3 width=0) + -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=2.93..5.30 rows=3 width=0) Output: (RowIdExpr) Hash Key: (RowIdExpr) - -> Hash Join (cost=2.96..4.78 rows=3 width=0) + -> Hash Join (cost=2.93..5.25 rows=3 width=0) Output: (RowIdExpr) - Hash Cond: (t2_1.v3 = t1.v1) - -> Seq Scan on public.t2 t2_1 (cost=0.00..1.33 rows=33 width=4) - Output: t2_1.v3 - -> Hash (cost=2.93..2.93 rows=3 width=8) + Hash Cond: (share0_ref1.v3 = t1.v1) + -> Shared Scan (share slice:id 2:0) (cost=1.33..1.57 rows=33 width=4) + Output: share0_ref1.v3 + -> Seq Scan on public.t2 t2_1 (cost=0.00..1.33 rows=33 width=4) + Output: t2_1.v3 + -> Hash (cost=2.90..2.90 rows=3 width=8) Output: t1.v1, t2_2.v3, (RowIdExpr) - -> Hash Semi Join (cost=1.48..2.93 rows=3 width=8) + -> Hash Semi Join (cost=1.45..2.90 rows=3 width=8) Output: t1.v1, t2_2.v3, RowIdExpr Hash Cond: (t1.v1 = t2_2.v3) -> Seq Scan on public.t1 (cost=0.00..1.33 rows=33 width=4) Output: t1.v1, t1.v2 - -> Hash (cost=1.44..1.44 rows=3 width=4) + -> Hash (cost=1.42..1.42 rows=3 width=4) Output: t2_2.v3 -> Seq Scan on public.t2 t2_2 (cost=0.00..1.42 rows=3 width=4) Output: t2_2.v3 @@ -264,7 +266,7 @@ explain verbose with cte1 as (select v3 from t2) select count(*) from t1,t2 wher -> Seq Scan on public.t2 (cost=0.00..1.33 rows=33 width=0) Settings: enable_parallel = 'off', optimizer = 'off' Optimizer: Postgres query optimizer -(39 rows) +(41 rows) explain verbose with cte1 as (select v3 from t2) select count(*) from t1,t2 where t1.v1 in (select v3 from cte1 where v3 < 10); QUERY PLAN @@ -309,36 +311,38 @@ set optimizer_cte_inlining_bound to 2; explain verbose with cte1 as (select v3 from t2) select count(*) from t1,t2 where t1.v1 in (select v3 from cte1) and t1.v1 in (select v3 from cte1 where v3 < 10); QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------- - Finalize Aggregate (cost=10000000015.48..10000000015.49 rows=1 width=8) + Finalize Aggregate (cost=10000000015.96..10000000015.97 rows=1 width=8) Output: count(*) - -> Gather Motion 3:1 (slice1; segments: 3) (cost=10000000015.43..10000000015.48 rows=3 width=8) + -> Gather Motion 3:1 (slice1; segments: 3) (cost=10000000015.90..10000000015.95 rows=3 width=8) Output: (PARTIAL count(*)) - -> Partial Aggregate (cost=10000000015.43..10000000015.44 rows=1 width=8) + -> Partial Aggregate (cost=10000000015.90..10000000015.91 rows=1 width=8) Output: PARTIAL count(*) - -> Nested Loop (cost=10000000004.85..10000000014.75 rows=270 width=0) - -> Result (cost=4.85..4.86 rows=3 width=0) - -> Unique (cost=4.85..4.86 rows=3 width=0) + -> Nested Loop (cost=10000000005.32..10000000015.23 rows=270 width=0) + -> Result (cost=5.32..5.34 rows=3 width=0) + -> Unique (cost=5.32..5.34 rows=3 width=0) Output: (RowIdExpr) Group Key: (RowIdExpr) - -> Sort (cost=4.85..4.86 rows=3 width=0) + -> Sort (cost=5.32..5.33 rows=3 width=0) Output: (RowIdExpr) Sort Key: (RowIdExpr) - -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=2.96..4.83 rows=3 width=0) + -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=2.93..5.30 rows=3 width=0) Output: (RowIdExpr) Hash Key: (RowIdExpr) - -> Hash Join (cost=2.96..4.78 rows=3 width=0) + -> Hash Join (cost=2.93..5.25 rows=3 width=0) Output: (RowIdExpr) - Hash Cond: (t2_1.v3 = t1.v1) - -> Seq Scan on public.t2 t2_1 (cost=0.00..1.33 rows=33 width=4) - Output: t2_1.v3 - -> Hash (cost=2.93..2.93 rows=3 width=8) + Hash Cond: (share0_ref1.v3 = t1.v1) + -> Shared Scan (share slice:id 2:0) (cost=1.33..1.57 rows=33 width=4) + Output: share0_ref1.v3 + -> Seq Scan on public.t2 t2_1 (cost=0.00..1.33 rows=33 width=4) + Output: t2_1.v3 + -> Hash (cost=2.90..2.90 rows=3 width=8) Output: t1.v1, t2_2.v3, (RowIdExpr) - -> Hash Semi Join (cost=1.48..2.93 rows=3 width=8) + -> Hash Semi Join (cost=1.45..2.90 rows=3 width=8) Output: t1.v1, t2_2.v3, RowIdExpr Hash Cond: (t1.v1 = t2_2.v3) -> Seq Scan on public.t1 (cost=0.00..1.33 rows=33 width=4) Output: t1.v1, t1.v2 - -> Hash (cost=1.44..1.44 rows=3 width=4) + -> Hash (cost=1.42..1.42 rows=3 width=4) Output: t2_2.v3 -> Seq Scan on public.t2 t2_2 (cost=0.00..1.42 rows=3 width=4) Output: t2_2.v3 @@ -348,7 +352,7 @@ explain verbose with cte1 as (select v3 from t2) select count(*) from t1,t2 wher -> Seq Scan on public.t2 (cost=0.00..1.33 rows=33 width=0) Settings: enable_parallel = 'off', optimizer = 'off', optimizer_cte_inlining_bound = '2' Optimizer: Postgres query optimizer -(39 rows) +(41 rows) with cte1 as (select v3 from t2) select count(*) from t1,t2 where t1.v1 in (select v3 from cte1) and t1.v1 in (select v3 from cte1 where v3 < 10); count @@ -757,34 +761,36 @@ select count(*) from pt1 where v1 in (select v3 from pt2); explain verbose with cte1 as (select v3 from t2) select count(*) from t1,t2 where t1.v1 in (select v3 from cte1) and t1.v1 in (select v3 from cte1); QUERY PLAN --------------------------------------------------------------------------------------------------------------- - Finalize Aggregate (cost=10000000137.03..10000000137.04 rows=1 width=8) + Finalize Aggregate (cost=10000000139.36..10000000139.37 rows=1 width=8) Output: count(*) - -> Gather Motion 3:1 (slice1; segments: 3) (cost=10000000136.97..10000000137.02 rows=3 width=8) + -> Gather Motion 3:1 (slice1; segments: 3) (cost=10000000139.30..10000000139.35 rows=3 width=8) Output: (PARTIAL count(*)) - -> Partial Aggregate (cost=10000000136.97..10000000136.98 rows=1 width=8) + -> Partial Aggregate (cost=10000000139.30..10000000139.31 rows=1 width=8) Output: PARTIAL count(*) - -> Nested Loop (cost=10000000004.17..10000000128.64 rows=3333 width=0) - -> Hash Semi Join (cost=4.17..6.42 rows=33 width=0) - Hash Cond: (t1.v1 = t2_2.v3) - -> Hash Semi Join (cost=2.08..3.87 rows=33 width=8) - Output: t1.v1, t2_1.v3 - Hash Cond: (t1.v1 = t2_1.v3) + -> Nested Loop (cost=10000000006.50..10000000130.97 rows=3333 width=0) + -> Hash Semi Join (cost=6.50..8.75 rows=33 width=0) + Hash Cond: (t1.v1 = share0_ref1.v3) + -> Hash Semi Join (cost=3.25..5.04 rows=33 width=8) + Output: t1.v1, share0_ref2.v3 + Hash Cond: (t1.v1 = share0_ref2.v3) -> Seq Scan on public.t1 (cost=0.00..1.33 rows=33 width=4) Output: t1.v1, t1.v2 - -> Hash (cost=1.67..1.67 rows=33 width=4) - Output: t2_1.v3 + -> Hash (cost=2.00..2.00 rows=100 width=4) + Output: share0_ref2.v3 + -> Shared Scan (share slice:id 1:0) (cost=1.33..1.57 rows=33 width=4) + Output: share0_ref2.v3 + -> Hash (cost=2.00..2.00 rows=100 width=4) + Output: share0_ref1.v3 + -> Shared Scan (share slice:id 1:0) (cost=1.33..1.57 rows=33 width=4) + Output: share0_ref1.v3 -> Seq Scan on public.t2 t2_1 (cost=0.00..1.33 rows=33 width=4) Output: t2_1.v3 - -> Hash (cost=1.67..1.67 rows=33 width=4) - Output: t2_2.v3 - -> Seq Scan on public.t2 t2_2 (cost=0.00..1.33 rows=33 width=4) - Output: t2_2.v3 -> Materialize (cost=0.00..3.17 rows=100 width=0) -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=0.00..2.67 rows=100 width=0) -> Seq Scan on public.t2 (cost=0.00..1.33 rows=33 width=0) Settings: enable_parallel = 'off', optimizer = 'off' Optimizer: Postgres query optimizer -(27 rows) +(29 rows) explain verbose with cte1 as (select v3 from t2) select count(*) from t1,t2 where t1.v1 in (select v3 from cte1); QUERY PLAN @@ -830,34 +836,36 @@ set optimizer_cte_inlining_bound to 2; explain verbose with cte1 as (select v3 from t2) select count(*) from t1,t2 where t1.v1 in (select v3 from cte1) and t1.v1 in (select v3 from cte1); QUERY PLAN --------------------------------------------------------------------------------------------------------------- - Finalize Aggregate (cost=10000000137.03..10000000137.04 rows=1 width=8) + Finalize Aggregate (cost=10000000139.36..10000000139.37 rows=1 width=8) Output: count(*) - -> Gather Motion 3:1 (slice1; segments: 3) (cost=10000000136.97..10000000137.02 rows=3 width=8) + -> Gather Motion 3:1 (slice1; segments: 3) (cost=10000000139.30..10000000139.35 rows=3 width=8) Output: (PARTIAL count(*)) - -> Partial Aggregate (cost=10000000136.97..10000000136.98 rows=1 width=8) + -> Partial Aggregate (cost=10000000139.30..10000000139.31 rows=1 width=8) Output: PARTIAL count(*) - -> Nested Loop (cost=10000000004.17..10000000128.64 rows=3333 width=0) - -> Hash Semi Join (cost=4.17..6.42 rows=33 width=0) - Hash Cond: (t1.v1 = t2_2.v3) - -> Hash Semi Join (cost=2.08..3.87 rows=33 width=8) - Output: t1.v1, t2_1.v3 - Hash Cond: (t1.v1 = t2_1.v3) + -> Nested Loop (cost=10000000006.50..10000000130.97 rows=3333 width=0) + -> Hash Semi Join (cost=6.50..8.75 rows=33 width=0) + Hash Cond: (t1.v1 = share0_ref1.v3) + -> Hash Semi Join (cost=3.25..5.04 rows=33 width=8) + Output: t1.v1, share0_ref2.v3 + Hash Cond: (t1.v1 = share0_ref2.v3) -> Seq Scan on public.t1 (cost=0.00..1.33 rows=33 width=4) Output: t1.v1, t1.v2 - -> Hash (cost=1.67..1.67 rows=33 width=4) - Output: t2_1.v3 + -> Hash (cost=2.00..2.00 rows=100 width=4) + Output: share0_ref2.v3 + -> Shared Scan (share slice:id 1:0) (cost=1.33..1.57 rows=33 width=4) + Output: share0_ref2.v3 + -> Hash (cost=2.00..2.00 rows=100 width=4) + Output: share0_ref1.v3 + -> Shared Scan (share slice:id 1:0) (cost=1.33..1.57 rows=33 width=4) + Output: share0_ref1.v3 -> Seq Scan on public.t2 t2_1 (cost=0.00..1.33 rows=33 width=4) Output: t2_1.v3 - -> Hash (cost=1.67..1.67 rows=33 width=4) - Output: t2_2.v3 - -> Seq Scan on public.t2 t2_2 (cost=0.00..1.33 rows=33 width=4) - Output: t2_2.v3 -> Materialize (cost=0.00..3.17 rows=100 width=0) -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=0.00..2.67 rows=100 width=0) -> Seq Scan on public.t2 (cost=0.00..1.33 rows=33 width=0) Settings: enable_parallel = 'off', optimizer = 'off', optimizer_cte_inlining_bound = '2' Optimizer: Postgres query optimizer -(27 rows) +(29 rows) with cte1 as (select v3 from t2) select count(*) from t1,t2 where t1.v1 in (select v3 from cte1) and t1.v1 in (select v3 from cte1); count @@ -1359,20 +1367,22 @@ select * from pt1 where v1 in (select v3 from pt2,t3 where v4=v6 and v4 < 10); explain verbose with cte1 as (select v3 from t2) select * from t1,t2 where t1.v1 in (select v3 from cte1) and t1.v1 in (select v3 from cte1,t3 where v4=v6); QUERY PLAN ----------------------------------------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=10000000002.08..10000000192.76 rows=5000 width=16) + Gather Motion 3:1 (slice1; segments: 3) (cost=10000000003.25..10000000193.93 rows=5000 width=16) Output: t1.v1, t1.v2, t2.v3, t2.v4 - -> Nested Loop (cost=10000000002.08..10000000126.10 rows=1667 width=16) + -> Nested Loop (cost=10000000003.25..10000000127.26 rows=1667 width=16) Output: t1.v1, t1.v2, t2.v3, t2.v4 Join Filter: (SubPlan 1) - -> Hash Semi Join (cost=2.08..3.87 rows=33 width=8) + -> Hash Semi Join (cost=3.25..5.04 rows=33 width=8) Output: t1.v1, t1.v2 - Hash Cond: (t1.v1 = t2_1.v3) + Hash Cond: (t1.v1 = share0_ref1.v3) -> Seq Scan on public.t1 (cost=0.00..1.33 rows=33 width=8) Output: t1.v1, t1.v2 - -> Hash (cost=1.67..1.67 rows=33 width=4) - Output: t2_1.v3 - -> Seq Scan on public.t2 t2_1 (cost=0.00..1.33 rows=33 width=4) - Output: t2_1.v3 + -> Hash (cost=2.00..2.00 rows=100 width=4) + Output: share0_ref1.v3 + -> Shared Scan (share slice:id 1:0) (cost=1.33..1.57 rows=33 width=4) + Output: share0_ref1.v3 + -> Seq Scan on public.t2 t2_1 (cost=0.00..1.33 rows=33 width=4) + Output: t2_1.v3 -> Materialize (cost=0.00..3.17 rows=100 width=8) Output: t2.v3, t2.v4 -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=0.00..2.67 rows=100 width=8) @@ -1401,25 +1411,27 @@ explain verbose with cte1 as (select v3 from t2) select * from t1,t2 where t1.v1 Output: t3.v6 Settings: enable_parallel = 'off', optimizer = 'off' Optimizer: Postgres query optimizer -(42 rows) +(44 rows) explain verbose with cte1 as (select v3 from t2) select * from t1,t2 where t1.v1 in (select v3 from cte1) and t1.v1 in (select v3 from t3,cte1 where v4=v6); QUERY PLAN ----------------------------------------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=10000000002.08..10000000192.76 rows=5000 width=16) + Gather Motion 3:1 (slice1; segments: 3) (cost=10000000003.25..10000000193.93 rows=5000 width=16) Output: t1.v1, t1.v2, t2.v3, t2.v4 - -> Nested Loop (cost=10000000002.08..10000000126.10 rows=1667 width=16) + -> Nested Loop (cost=10000000003.25..10000000127.26 rows=1667 width=16) Output: t1.v1, t1.v2, t2.v3, t2.v4 Join Filter: (SubPlan 1) - -> Hash Semi Join (cost=2.08..3.87 rows=33 width=8) + -> Hash Semi Join (cost=3.25..5.04 rows=33 width=8) Output: t1.v1, t1.v2 - Hash Cond: (t1.v1 = t2_1.v3) + Hash Cond: (t1.v1 = share0_ref1.v3) -> Seq Scan on public.t1 (cost=0.00..1.33 rows=33 width=8) Output: t1.v1, t1.v2 - -> Hash (cost=1.67..1.67 rows=33 width=4) - Output: t2_1.v3 - -> Seq Scan on public.t2 t2_1 (cost=0.00..1.33 rows=33 width=4) - Output: t2_1.v3 + -> Hash (cost=2.00..2.00 rows=100 width=4) + Output: share0_ref1.v3 + -> Shared Scan (share slice:id 1:0) (cost=1.33..1.57 rows=33 width=4) + Output: share0_ref1.v3 + -> Seq Scan on public.t2 t2_1 (cost=0.00..1.33 rows=33 width=4) + Output: t2_1.v3 -> Materialize (cost=0.00..3.17 rows=100 width=8) Output: t2.v3, t2.v4 -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=0.00..2.67 rows=100 width=8) @@ -1448,7 +1460,7 @@ explain verbose with cte1 as (select v3 from t2) select * from t1,t2 where t1.v1 Output: t3.v6 Settings: enable_parallel = 'off', optimizer = 'off' Optimizer: Postgres query optimizer -(42 rows) +(44 rows) explain verbose with cte1 as (select v3 from t2) select * from t1,t2 where t1.v1 in (select v3 from cte1,t3 where v4=v6 and v4 < 10); QUERY PLAN @@ -1496,20 +1508,22 @@ explain verbose with cte1 as (select v3 from t2) select * from t1,t2 where t1.v1 explain verbose with cte1 as (select v3 from t2) select * from t1,t2 where t1.v1 in (select v3 from cte1) and t1.v1 in (select v3 from cte1,t3 where v4=v6 and v4 < 10); QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=10000000002.08..10000000192.76 rows=5000 width=16) + Gather Motion 3:1 (slice1; segments: 3) (cost=10000000003.25..10000000193.93 rows=5000 width=16) Output: t1.v1, t1.v2, t2.v3, t2.v4 - -> Nested Loop (cost=10000000002.08..10000000126.10 rows=1667 width=16) + -> Nested Loop (cost=10000000003.25..10000000127.26 rows=1667 width=16) Output: t1.v1, t1.v2, t2.v3, t2.v4 Join Filter: (SubPlan 1) - -> Hash Semi Join (cost=2.08..3.87 rows=33 width=8) + -> Hash Semi Join (cost=3.25..5.04 rows=33 width=8) Output: t1.v1, t1.v2 - Hash Cond: (t1.v1 = t2_1.v3) + Hash Cond: (t1.v1 = share0_ref1.v3) -> Seq Scan on public.t1 (cost=0.00..1.33 rows=33 width=8) Output: t1.v1, t1.v2 - -> Hash (cost=1.67..1.67 rows=33 width=4) - Output: t2_1.v3 - -> Seq Scan on public.t2 t2_1 (cost=0.00..1.33 rows=33 width=4) - Output: t2_1.v3 + -> Hash (cost=2.00..2.00 rows=100 width=4) + Output: share0_ref1.v3 + -> Shared Scan (share slice:id 1:0) (cost=1.33..1.57 rows=33 width=4) + Output: share0_ref1.v3 + -> Seq Scan on public.t2 t2_1 (cost=0.00..1.33 rows=33 width=4) + Output: t2_1.v3 -> Materialize (cost=0.00..3.17 rows=100 width=8) Output: t2.v3, t2.v4 -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=0.00..2.67 rows=100 width=8) @@ -1541,7 +1555,7 @@ explain verbose with cte1 as (select v3 from t2) select * from t1,t2 where t1.v1 Output: t3.v6 Settings: enable_parallel = 'off', optimizer = 'off' Optimizer: Postgres query optimizer -(45 rows) +(47 rows) with cte1 as (select v3 from t2) select sum(v1) from t1,t2 where t1.v1 in (select v3 from cte1) and t1.v1 in (select v3 from cte1,t3 where v4=v6 and v4 < 10); sum @@ -1560,20 +1574,22 @@ set optimizer_cte_inlining_bound to 2; explain verbose with cte1 as (select v3 from t2) select * from t1,t2 where t1.v1 in (select v3 from cte1) and t1.v1 in (select v3 from cte1,t3 where v4=v6 and v4 < 10); QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=10000000002.08..10000000192.76 rows=5000 width=16) + Gather Motion 3:1 (slice1; segments: 3) (cost=10000000003.25..10000000193.93 rows=5000 width=16) Output: t1.v1, t1.v2, t2.v3, t2.v4 - -> Nested Loop (cost=10000000002.08..10000000126.10 rows=1667 width=16) + -> Nested Loop (cost=10000000003.25..10000000127.26 rows=1667 width=16) Output: t1.v1, t1.v2, t2.v3, t2.v4 Join Filter: (SubPlan 1) - -> Hash Semi Join (cost=2.08..3.87 rows=33 width=8) + -> Hash Semi Join (cost=3.25..5.04 rows=33 width=8) Output: t1.v1, t1.v2 - Hash Cond: (t1.v1 = t2_1.v3) + Hash Cond: (t1.v1 = share0_ref1.v3) -> Seq Scan on public.t1 (cost=0.00..1.33 rows=33 width=8) Output: t1.v1, t1.v2 - -> Hash (cost=1.67..1.67 rows=33 width=4) - Output: t2_1.v3 - -> Seq Scan on public.t2 t2_1 (cost=0.00..1.33 rows=33 width=4) - Output: t2_1.v3 + -> Hash (cost=2.00..2.00 rows=100 width=4) + Output: share0_ref1.v3 + -> Shared Scan (share slice:id 1:0) (cost=1.33..1.57 rows=33 width=4) + Output: share0_ref1.v3 + -> Seq Scan on public.t2 t2_1 (cost=0.00..1.33 rows=33 width=4) + Output: t2_1.v3 -> Materialize (cost=0.00..3.17 rows=100 width=8) Output: t2.v3, t2.v4 -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=0.00..2.67 rows=100 width=8) @@ -1605,7 +1621,7 @@ explain verbose with cte1 as (select v3 from t2) select * from t1,t2 where t1.v1 Output: t3.v6 Settings: enable_parallel = 'off', optimizer = 'off', optimizer_cte_inlining_bound = '2' Optimizer: Postgres query optimizer -(45 rows) +(47 rows) with cte1 as (select v3 from t2) select sum(v1) from t1,t2 where t1.v1 in (select v3 from cte1) and t1.v1 in (select v3 from cte1,t3 where v4=v6 and v4 < 10); sum diff --git a/src/test/regress/expected/gporca.out b/src/test/regress/expected/gporca.out index a8d2736b323..c4437f944f7 100644 --- a/src/test/regress/expected/gporca.out +++ b/src/test/regress/expected/gporca.out @@ -2395,28 +2395,28 @@ select count(*) from orca.foo x where x.x1 > (select count(*)+1 from orca.bar1 y -- result node with one time filter and filter explain select case when bar1.x2 = bar2.x2 then coalesce((select 1 from orca.foo where bar1.x2 = bar2.x2 and bar1.x2 = random() and foo.x2 = bar2.x2),0) else 1 end as col1, bar1.x1 from orca.bar1 inner join orca.bar2 on (bar1.x2 = bar2.x2) order by bar1.x1; - QUERY PLAN ---------------------------------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice3; segments: 3) (cost=75.54..75.59 rows=20 width=12) + QUERY PLAN +---------------------------------------------------------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) (cost=11.57..11.86 rows=20 width=8) Merge Key: bar1.x1 - -> Sort (cost=75.54..75.59 rows=7 width=12) + -> Sort (cost=11.57..11.59 rows=7 width=8) Sort Key: bar1.x1 - -> Hash Join (cost=3.85..75.11 rows=7 width=12) + -> Hash Join (cost=1.28..11.48 rows=7 width=8) Hash Cond: (bar2.x2 = bar1.x2) - -> Redistribute Motion 3:3 (slice1; segments: 3) (cost=0.00..3.90 rows=10 width=4) + -> Redistribute Motion 3:3 (slice3; segments: 3) (cost=0.00..1.30 rows=10 width=4) Hash Key: bar2.x2 - -> Seq Scan on bar2 (cost=0.00..3.30 rows=10 width=4) - -> Hash (cost=3.60..3.60 rows=7 width=8) - -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.00..3.60 rows=7 width=8) + -> Seq Scan on bar2 (cost=0.00..1.10 rows=10 width=4) + -> Hash (cost=1.20..1.20 rows=7 width=8) + -> Redistribute Motion 3:3 (slice4; segments: 3) (cost=0.00..1.20 rows=7 width=8) Hash Key: bar1.x2 - -> Seq Scan on bar1 (cost=0.00..3.20 rows=7 width=8) + -> Seq Scan on bar1 (cost=0.00..1.07 rows=7 width=8) SubPlan 1 - -> Result (cost=0.00..3.35 rows=10 width=4) + -> Result (cost=0.00..1.32 rows=10 width=4) One-Time Filter: (bar1.x2 = bar2.x2) Filter: ((foo.x2 = bar2.x2) AND ((bar1.x2)::double precision = random())) - -> Materialize (cost=0.00..3.35 rows=10 width=4) - -> Broadcast Motion 3:3 (slice4; segments: 3) (cost=0.00..3.30 rows=4 width=4) - -> Seq Scan on foo (cost=0.00..3.10 rows=4 width=4) + -> Materialize (cost=0.00..1.22 rows=10 width=4) + -> Broadcast Motion 3:3 (slice2; segments: 3) (cost=0.00..1.17 rows=10 width=4) + -> Seq Scan on foo (cost=0.00..1.03 rows=3 width=4) Optimizer: Postgres query optimizer (21 rows) @@ -10350,20 +10350,19 @@ analyze idxscan_inner; set optimizer_enable_hashjoin = off; explain select id, comment from idxscan_outer as o join idxscan_inner as i on o.id = i.productid where ordernum between 10 and 20; - QUERY PLAN + QUERY PLAN ---------------------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice2; segments: 3) (cost=2.12..5.28 rows=4 width=9) - -> Hash Join (cost=2.12..5.28 rows=2 width=9) - Hash Cond: o.id = i.productid - -> Seq Scan on idxscan_outer o (cost=0.00..3.09 rows=3 width=4) - -> Hash (cost=2.09..2.09 rows=1 width=9) - -> Redistribute Motion 3:3 (slice1; segments: 3) (cost=0.00..2.09 rows=1 width=9) + Gather Motion 3:1 (slice1; segments: 3) (cost=1.05..2.14 rows=3 width=9) + -> Hash Join (cost=1.05..2.10 rows=1 width=9) + Hash Cond: (o.id = i.productid) + -> Seq Scan on idxscan_outer o (cost=0.00..1.03 rows=3 width=4) + -> Hash (cost=1.03..1.03 rows=1 width=9) + -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.00..1.03 rows=1 width=9) Hash Key: i.productid - -> Seq Scan on idxscan_inner i (cost=0.00..2.04 rows=1 width=9) - Filter: ordernum >= 10 AND ordernum <= 20 - Settings: optimizer=off - Optimizer status: Postgres query optimizer -(11 rows) + -> Seq Scan on idxscan_inner i (cost=0.00..1.01 rows=1 width=9) + Filter: ((ordernum >= 10) AND (ordernum <= 20)) + Optimizer: Postgres query optimizer +(10 rows) select id, comment from idxscan_outer as o join idxscan_inner as i on o.id = i.productid where ordernum between 10 and 20; @@ -10882,17 +10881,17 @@ FROM (SELECT * FROM tab_3)a; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------- - Finalize Aggregate (cost=4.28..4.29 rows=1 width=8) - -> Gather Motion 3:1 (slice3; segments: 3) (cost=4.25..4.28 rows=1 width=8) - -> Partial Aggregate (cost=4.25..4.26 rows=1 width=8) - -> Append (cost=1.04..4.20 rows=2 width=64) - -> Hash Left Join (cost=1.04..3.14 rows=2 width=6) + Finalize Aggregate (cost=3.19..3.20 rows=1 width=8) + -> Gather Motion 3:1 (slice1; segments: 3) (cost=3.13..3.18 rows=3 width=8) + -> Partial Aggregate (cost=3.13..3.14 rows=1 width=8) + -> Append (cost=1.04..3.12 rows=2 width=64) + -> Hash Left Join (cost=1.04..2.09 rows=1 width=6) Hash Cond: ((tab_1.id)::text = (tab_2.id)::text) - -> Redistribute Motion 3:3 (slice1; segments: 3) (cost=0.00..2.06 rows=1 width=5) + -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.00..1.03 rows=1 width=5) Hash Key: tab_1.id - -> Seq Scan on tab_1 (cost=0.00..2.02 rows=1 width=5) + -> Seq Scan on tab_1 (cost=0.00..1.01 rows=1 width=5) -> Hash (cost=1.03..1.03 rows=1 width=7) - -> Redistribute Motion 3:3 (slice2; segments: 3) (cost=0.00..1.03 rows=1 width=7) + -> Redistribute Motion 3:3 (slice3; segments: 3) (cost=0.00..1.03 rows=1 width=7) Hash Key: tab_2.id -> Seq Scan on tab_2 (cost=0.00..1.01 rows=1 width=7) -> Subquery Scan on "*SELECT* 2" (cost=0.00..1.02 rows=1 width=64) @@ -14865,14 +14864,15 @@ HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sur insert into cte_test select i from generate_series(1,10)i; analyze cte_test; explain (analyze, costs off, summary off, timing off) with cte as (select * from cte_test) select * from cte union all select * from cte; - QUERY PLAN ---------------------------------------------------------------------- + QUERY PLAN +---------------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) (actual rows=20 loops=1) -> Append (actual rows=10 loops=1) - -> Seq Scan on cte_test (actual rows=5 loops=1) - -> Seq Scan on cte_test cte_test_1 (actual rows=5 loops=1) + -> Shared Scan (share slice:id 1:0) (actual rows=5 loops=1) + -> Seq Scan on cte_test (actual rows=5 loops=1) + -> Shared Scan (share slice:id 1:0) (actual rows=5 loops=1) Optimizer: Postgres query optimizer -(5 rows) +(6 rows) -- While retrieving the columns width in partitioned tables, inherited stats i.e. -- stats that cover all the child tables should be used diff --git a/src/test/regress/expected/shared_scan.out b/src/test/regress/expected/shared_scan.out index ba79ef2a223..99bc99cdeda 100644 --- a/src/test/regress/expected/shared_scan.out +++ b/src/test/regress/expected/shared_scan.out @@ -44,22 +44,23 @@ EXPLAIN (COSTS OFF) ------------------------------------------------------------------------ Gather Motion 3:1 (slice1; segments: 3) -> Hash Join - Hash Cond: ((bar.c = jazz.e) AND (foo.b = jazz.f)) + Hash Cond: ((bar.c = jazz.e) AND (share0_ref1.b = jazz.f)) -> Hash Join - Hash Cond: (bar.c = foo.b) + Hash Cond: (bar.c = share0_ref1.b) -> Seq Scan on bar -> Hash -> Redistribute Motion 3:3 (slice2; segments: 3) - Hash Key: foo.b + Hash Key: share0_ref1.b -> Append - -> Seq Scan on foo - -> Seq Scan on foo foo_1 + -> Shared Scan (share slice:id 2:0) + -> Seq Scan on foo + -> Shared Scan (share slice:id 2:0) -> Hash -> Redistribute Motion 3:3 (slice3; segments: 3) Hash Key: jazz.f -> Seq Scan on jazz Optimizer: Postgres query optimizer -(17 rows) +(18 rows) SET statement_timeout = '15s'; :qry ; @@ -202,26 +203,21 @@ where -> Nested Loop -> Broadcast Motion 3:3 (slice2; segments: 3) -> Subquery Scan on tbls - -> HashAggregate - Group Key: pk_list.schema_name, pk_list.table_name - -> Redistribute Motion 3:3 (slice3; segments: 3) - Hash Key: pk_list.schema_name, pk_list.table_name - -> Streaming HashAggregate - Group Key: pk_list.schema_name, pk_list.table_name - -> Seq Scan on pk_list + -> Shared Scan (share slice:id 2:0) -> Materialize -> Seq Scan on calender c -> Hash - -> Broadcast Motion 3:3 (slice4; segments: 3) + -> Broadcast Motion 3:3 (slice3; segments: 3) -> Subquery Scan on stat Filter: (((NOT (hashed SubPlan 1)) AND (NOT (hashed SubPlan 2))) OR (hashed SubPlan 3)) - -> HashAggregate - Group Key: pk_list_1.schema_name, pk_list_1.table_name - -> Redistribute Motion 3:3 (slice5; segments: 3) - Hash Key: pk_list_1.schema_name, pk_list_1.table_name - -> Streaming HashAggregate - Group Key: pk_list_1.schema_name, pk_list_1.table_name - -> Seq Scan on pk_list pk_list_1 + -> Shared Scan (share slice:id 3:0) + -> HashAggregate + Group Key: pk_list.schema_name, pk_list.table_name + -> Redistribute Motion 3:3 (slice4; segments: 3) + Hash Key: pk_list.schema_name, pk_list.table_name + -> Streaming HashAggregate + Group Key: pk_list.schema_name, pk_list.table_name + -> Seq Scan on pk_list SubPlan 1 -> ProjectSet -> Result @@ -232,7 +228,7 @@ where -> ProjectSet -> Result Optimizer: Postgres query optimizer -(37 rows) +(32 rows) -- ORCA should fallback when a CTE over a replicated table is referenced -- from multiple scalar subqueries. diff --git a/src/test/regress/expected/shared_scan_optimizer.out b/src/test/regress/expected/shared_scan_optimizer.out index 18d8219a77e..27b96983b9b 100644 --- a/src/test/regress/expected/shared_scan_optimizer.out +++ b/src/test/regress/expected/shared_scan_optimizer.out @@ -210,26 +210,21 @@ where -> Nested Loop -> Broadcast Motion 3:3 (slice2; segments: 3) -> Subquery Scan on tbls - -> HashAggregate - Group Key: pk_list.schema_name, pk_list.table_name - -> Redistribute Motion 3:3 (slice3; segments: 3) - Hash Key: pk_list.schema_name, pk_list.table_name - -> Streaming HashAggregate - Group Key: pk_list.schema_name, pk_list.table_name - -> Seq Scan on pk_list + -> Shared Scan (share slice:id 2:0) -> Materialize -> Seq Scan on calender c -> Hash - -> Broadcast Motion 3:3 (slice4; segments: 3) + -> Broadcast Motion 3:3 (slice3; segments: 3) -> Subquery Scan on stat Filter: (((NOT (hashed SubPlan 1)) AND (NOT (hashed SubPlan 2))) OR (hashed SubPlan 3)) - -> HashAggregate - Group Key: pk_list_1.schema_name, pk_list_1.table_name - -> Redistribute Motion 3:3 (slice5; segments: 3) - Hash Key: pk_list_1.schema_name, pk_list_1.table_name - -> Streaming HashAggregate - Group Key: pk_list_1.schema_name, pk_list_1.table_name - -> Seq Scan on pk_list pk_list_1 + -> Shared Scan (share slice:id 3:0) + -> HashAggregate + Group Key: pk_list.schema_name, pk_list.table_name + -> Redistribute Motion 3:3 (slice4; segments: 3) + Hash Key: pk_list.schema_name, pk_list.table_name + -> Streaming HashAggregate + Group Key: pk_list.schema_name, pk_list.table_name + -> Seq Scan on pk_list SubPlan 1 -> ProjectSet -> Result diff --git a/src/test/regress/expected/table_functions.out b/src/test/regress/expected/table_functions.out index 834e7c643b1..655470a2015 100644 --- a/src/test/regress/expected/table_functions.out +++ b/src/test/regress/expected/table_functions.out @@ -2034,24 +2034,25 @@ explain WITH cte AS (SELECT * FROM example) SELECT * FROM multiset_5( TABLE ( SE (7 rows) explain WITH cte AS (SELECT * FROM example) SELECT x.* FROM multiset_5( TABLE ( SELECT * FROM cte ) ) x, (SELECT count(*) FROM cte) y order by x.a, x.b; - QUERY PLAN ----------------------------------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=10000000002.39..10000000002.53 rows=10 width=36) + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) (cost=10000000001.26..10000000001.68 rows=30 width=36) Merge Key: a, b - -> Sort (cost=10000000002.39..10000000002.39 rows=3 width=36) + -> Sort (cost=10000000001.26..10000000001.28 rows=10 width=36) Sort Key: a, b - -> Nested Loop (cost=10000000001.08..10000000002.36 rows=3 width=36) - -> Broadcast Motion 1:3 (slice2; segments: 1) (cost=1.08..1.12 rows=1 width=0) - -> Subquery Scan on y (cost=1.08..1.10 rows=1 width=0) - -> Finalize Aggregate (cost=1.08..1.09 rows=1 width=8) - -> Gather Motion 3:1 (slice3; segments: 3) (cost=1.03..1.08 rows=3 width=0) - -> Partial Aggregate (cost=1.03..1.04 rows=1 width=0) - -> Seq Scan on example (cost=0.00..1.03 rows=3 width=16) - -> Materialize (cost=0.00..1.18 rows=10 width=36) - -> Table Function Scan on multiset_5 x (cost=0.00..1.13 rows=10 width=36) - -> Seq Scan on example example_1 (cost=0.00..1.03 rows=3 width=16) + -> Nested Loop (cost=10000000000.25..10000000001.09 rows=10 width=36) + -> Broadcast Motion 1:3 (slice2; segments: 1) (cost=0.25..0.29 rows=1 width=0) + -> Subquery Scan on y (cost=0.25..0.27 rows=1 width=0) + -> Finalize Aggregate (cost=0.25..0.26 rows=1 width=8) + -> Gather Motion 3:1 (slice3; segments: 3) (cost=0.20..0.25 rows=3 width=0) + -> Partial Aggregate (cost=0.20..0.21 rows=1 width=0) + -> Shared Scan (share slice:id 3:0) (cost=1.03..1.24 rows=3 width=16) + -> Materialize (cost=0.00..0.65 rows=30 width=36) + -> Table Function Scan on multiset_5 x (cost=0.00..0.50 rows=30 width=36) + -> Shared Scan (share slice:id 1:0) (cost=1.03..1.24 rows=3 width=16) + -> Seq Scan on example (cost=0.00..1.03 rows=3 width=16) Optimizer: Postgres query optimizer -(15 rows) +(16 rows) explain select * from multiset_2( TABLE( SELECT distinct a.a, b.b from example a, example b where a.a = b.a) ) order by 1,2; QUERY PLAN @@ -2393,11 +2394,11 @@ NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'a' HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew. QUERY PLAN ----------------------------------------------------------------------------------- - Redistribute Motion 1:3 (slice1; segments: 1) (cost=0.00..0.02 rows=8 width=36) - Hash Key: a - -> Table Function Scan on multi_args (cost=0.00..0.02 rows=8 width=36) - -> Result (cost=0.00..0.01 rows=1 width=0) - Settings: gp_segments_for_planner=8 + Redistribute Motion 1:3 (slice1; segments: 1) (cost=0.00..0.04 rows=1 width=36) + Hash Key: multi_args.a + -> Table Function Scan on multi_args (cost=0.00..0.02 rows=1 width=36) + -> Result (cost=0.00..0.01 rows=1 width=36) + Optimizer: Postgres query optimizer (5 rows) CREATE TABLE example_out AS SELECT * FROM multi_args( TABLE(SELECT 1::int, 'hello'::text), 2); diff --git a/src/test/regress/expected/table_functions_optimizer.out b/src/test/regress/expected/table_functions_optimizer.out index a3e855d8988..3edfa621443 100644 --- a/src/test/regress/expected/table_functions_optimizer.out +++ b/src/test/regress/expected/table_functions_optimizer.out @@ -2035,24 +2035,25 @@ explain WITH cte AS (SELECT * FROM example) SELECT * FROM multiset_5( TABLE ( SE (7 rows) explain WITH cte AS (SELECT * FROM example) SELECT x.* FROM multiset_5( TABLE ( SELECT * FROM cte ) ) x, (SELECT count(*) FROM cte) y order by x.a, x.b; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------- - Gather Motion 3:1 (slice1; segments: 3) (cost=10000000004.89..10000000005.12 rows=10 width=36) + QUERY PLAN +--------------------------------------------------------------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) (cost=10000000001.26..10000000001.68 rows=30 width=36) Merge Key: a, b - -> Sort (cost=10000000004.89..10000000004.92 rows=4 width=36) + -> Sort (cost=10000000001.26..10000000001.28 rows=10 width=36) Sort Key: a, b - -> Nested Loop (cost=10000000001.08..10000000002.36 rows=3 width=36) - -> Broadcast Motion 1:3 (slice2; segments: 1) (cost=1.08..1.12 rows=1 width=0) - -> Subquery Scan on y (cost=1.08..1.10 rows=1 width=0) - -> Finalize Aggregate (cost=1.08..1.09 rows=1 width=8) - -> Gather Motion 3:1 (slice3; segments: 3) (cost=1.03..1.08 rows=3 width=0) - -> Partial Aggregate (cost=1.03..1.04 rows=1 width=0) - -> Seq Scan on example (cost=0.00..1.03 rows=3 width=16) - -> Materialize (cost=0.00..1.18 rows=10 width=36) - -> Table Function Scan on multiset_5 x (cost=0.00..1.13 rows=10 width=36) - -> Seq Scan on example example_1 (cost=0.00..1.03 rows=3 width=16) + -> Nested Loop (cost=10000000000.25..10000000001.09 rows=10 width=36) + -> Broadcast Motion 1:3 (slice2; segments: 1) (cost=0.25..0.29 rows=1 width=0) + -> Subquery Scan on y (cost=0.25..0.27 rows=1 width=0) + -> Finalize Aggregate (cost=0.25..0.26 rows=1 width=8) + -> Gather Motion 3:1 (slice3; segments: 3) (cost=0.20..0.25 rows=3 width=0) + -> Partial Aggregate (cost=0.20..0.21 rows=1 width=0) + -> Shared Scan (share slice:id 3:0) (cost=1.03..1.24 rows=3 width=16) + -> Materialize (cost=0.00..0.65 rows=30 width=36) + -> Table Function Scan on multiset_5 x (cost=0.00..0.50 rows=30 width=36) + -> Shared Scan (share slice:id 1:0) (cost=1.03..1.24 rows=3 width=16) + -> Seq Scan on example (cost=0.00..1.03 rows=3 width=16) Optimizer: Postgres query optimizer -(15 rows) +(16 rows) explain select * from multiset_2( TABLE( SELECT distinct a.a, b.b from example a, example b where a.a = b.a) ) order by 1,2; QUERY PLAN diff --git a/src/test/regress/expected/with_clause.out b/src/test/regress/expected/with_clause.out index 02c7be538ee..9a401130a1f 100644 --- a/src/test/regress/expected/with_clause.out +++ b/src/test/regress/expected/with_clause.out @@ -2406,7 +2406,7 @@ SELECT EXISTS( DROP TABLE foo_issue_1204_test; -- --- gp_cte_sharing_auto: a CTE referenced more than once is shared by the +-- With gp_cte_sharing off, a CTE referenced more than once is shared by the -- references that have no quals to push down into it, and inlined, with the -- quals pushed down, for those that have. -- @@ -2415,7 +2415,6 @@ insert into cte_auto select i, i % 10 from generate_series(1, 1000) i; analyze cte_auto; set optimizer = off; set gp_cte_sharing = off; -set gp_cte_sharing_auto = on; -- no quals on the references: shared explain (costs off) with c as (select b, count(*) n from cte_auto group by b) @@ -2575,7 +2574,6 @@ select x, random() >= 0 from c, gp_dist_random('gp_id'); 1 | t (4 rows) -reset gp_cte_sharing_auto; reset gp_cte_sharing; reset optimizer; drop table cte_auto; diff --git a/src/test/regress/expected/with_clause_optimizer.out b/src/test/regress/expected/with_clause_optimizer.out index d7323b9575c..46fb0869cdb 100644 --- a/src/test/regress/expected/with_clause_optimizer.out +++ b/src/test/regress/expected/with_clause_optimizer.out @@ -2415,7 +2415,7 @@ SELECT EXISTS( DROP TABLE foo_issue_1204_test; -- --- gp_cte_sharing_auto: a CTE referenced more than once is shared by the +-- With gp_cte_sharing off, a CTE referenced more than once is shared by the -- references that have no quals to push down into it, and inlined, with the -- quals pushed down, for those that have. -- @@ -2424,7 +2424,6 @@ insert into cte_auto select i, i % 10 from generate_series(1, 1000) i; analyze cte_auto; set optimizer = off; set gp_cte_sharing = off; -set gp_cte_sharing_auto = on; -- no quals on the references: shared explain (costs off) with c as (select b, count(*) n from cte_auto group by b) @@ -2584,7 +2583,6 @@ select x, random() >= 0 from c, gp_dist_random('gp_id'); 1 | t (4 rows) -reset gp_cte_sharing_auto; reset gp_cte_sharing; reset optimizer; drop table cte_auto; diff --git a/src/test/regress/sql/with_clause.sql b/src/test/regress/sql/with_clause.sql index adb32fe62bf..9724fbc3c0c 100644 --- a/src/test/regress/sql/with_clause.sql +++ b/src/test/regress/sql/with_clause.sql @@ -493,7 +493,7 @@ SELECT EXISTS( DROP TABLE foo_issue_1204_test; -- --- gp_cte_sharing_auto: a CTE referenced more than once is shared by the +-- With gp_cte_sharing off, a CTE referenced more than once is shared by the -- references that have no quals to push down into it, and inlined, with the -- quals pushed down, for those that have. -- @@ -502,7 +502,6 @@ insert into cte_auto select i, i % 10 from generate_series(1, 1000) i; analyze cte_auto; set optimizer = off; set gp_cte_sharing = off; -set gp_cte_sharing_auto = on; -- no quals on the references: shared explain (costs off) with c as (select b, count(*) n from cte_auto group by b) @@ -540,7 +539,6 @@ with c as (select 1 as x) select x, random() >= 0 as r from c union all select x, random() >= 0 from c, gp_dist_random('gp_id'); -reset gp_cte_sharing_auto; reset gp_cte_sharing; reset optimizer; drop table cte_auto;