From e75e20d3866e4c2421850a5fbc2a6bcd653aa506 Mon Sep 17 00:00:00 2001 From: Bvsk Patnaik Date: Mon, 11 Mar 2024 11:42:59 -0700 Subject: [PATCH] [#20831] YSQL: Show distinct prefix keys explicitly in the explain output Summary: ### Objective Before this change, the explain output looks as follows ``` yugabyte=# explain select distinct col_int_key from mm; QUERY PLAN --------------------------------------------------------------------------------------------------- Unique (cost=0.00..12.00 rows=93 width=4) -> Distinct Index Only Scan using idx_mm_col_int_key on mm (cost=0.00..12.00 rows=93 width=4) Distinct Prefix: 1 (3 rows) ``` We displayed the length of the distinct prefix because that is the sole parameter necessary for the HybridScan on the DocDB side. However, users may find it more useful if we instead displayed the keys corresponding to the index columns instead. The new output looks ``` yugabyte=# explain select distinct k1 from t; QUERY PLAN ---------------------------------------------------------------------------------- Unique (cost=0.00..22.80 rows=200 width=4) -> Distinct Index Scan using t_pkey on t (cost=0.00..22.80 rows=200 width=4) Distinct Prefix Keys: k1 (3 rows) ``` ### Solution Pick the prefix length number of leading columns from the list of index targets and print them in explain. Also, change the regression test output to reflect the change. Jira: DB-9820 Test Plan: Jenkins ./yb_build.sh --java-test TestPgRegressDistinctPushdown Reviewers: tnayak Reviewed By: tnayak Subscribers: yql Differential Revision: https://phorge.dev.yugabyte.com/D33042 --- src/postgres/src/backend/commands/explain.c | 58 ++++++++-- .../test/regress/expected/yb_aggregates.out | 2 +- .../expected/yb_bitmap_scans_distinct.out | 4 +- .../expected/yb_distinct_pushdown_base.out | 26 ++--- .../expected/yb_distinct_pushdown_join.out | 106 +++++++++--------- .../expected/yb_distinct_pushdown_pred.out | 72 ++++++------ .../expected/yb_feature_colocation.out | 4 +- 7 files changed, 158 insertions(+), 114 deletions(-) diff --git a/src/postgres/src/backend/commands/explain.c b/src/postgres/src/backend/commands/explain.c index d36703a07829..2f71e08713ec 100644 --- a/src/postgres/src/backend/commands/explain.c +++ b/src/postgres/src/backend/commands/explain.c @@ -144,7 +144,8 @@ static void YbAggregateExplainableRPCRequestStat(ExplainState *es, const YbInstrumentation *instr); static void YbExplainDistinctPrefixLen( - int yb_distinct_prefixlen, ExplainState *es); + PlanState *planstate, List *indextlist, int yb_distinct_prefixlen, + ExplainState *es, List *ancestors); static void show_ybtidbitmap_info(YbBitmapTableScanState *planstate, ExplainState *es); @@ -2413,7 +2414,8 @@ ExplainNode(PlanState *planstate, List *ancestors, * that's currently the order of operations in DocDB. */ YbExplainDistinctPrefixLen( - ((IndexScan *) plan)->yb_distinct_prefixlen, es); + planstate, ((IndexScan *) plan)->indextlist, + ((IndexScan *) plan)->yb_distinct_prefixlen, es, ancestors); show_scan_qual(((IndexScan *) plan)->yb_idx_pushdown.quals, "Storage Index Filter", planstate, ancestors, es); show_scan_qual(((IndexScan *) plan)->yb_rel_pushdown.quals, @@ -2451,7 +2453,8 @@ ExplainNode(PlanState *planstate, List *ancestors, * that's currently the order of operations in DocDB. */ YbExplainDistinctPrefixLen( - ((IndexOnlyScan *) plan)->yb_distinct_prefixlen, es); + planstate, ((IndexOnlyScan *) plan)->indextlist, + ((IndexOnlyScan *) plan)->yb_distinct_prefixlen, es, ancestors); /* * Storage filter is applied first, so it is output first. */ @@ -5059,15 +5062,56 @@ YbAggregateExplainableRPCRequestStat(ExplainState *es, * -------------- * Distinct Index Scan * ... - * Distinct Prefix: + * Distinct Keys: * ... * * Adds Distinct Prefix to explain info */ static void -YbExplainDistinctPrefixLen(int yb_distinct_prefixlen, ExplainState *es) +YbExplainDistinctPrefixLen(PlanState *planstate, List *indextlist, + int yb_distinct_prefixlen, ExplainState *es, + List *ancestors) { if (yb_distinct_prefixlen > 0) - ExplainPropertyInteger( - "Distinct Prefix", NULL, yb_distinct_prefixlen, es); + { + /* Print distinct prefix keys. */ + List *context; + List *result = NIL; + StringInfoData distinct_prefix_key_buf; + bool useprefix; + int keyno; + ListCell *tlelc; + + initStringInfo(&distinct_prefix_key_buf); + + /* Set up deparsing context */ + context = set_deparse_context_planstate(es->deparse_cxt, + (Node *) planstate, + ancestors); + useprefix = (list_length(es->rtable) > 1 || es->verbose); + + keyno = 0; + foreach(tlelc, indextlist) + { + TargetEntry *indextle; + char *exprstr; + + if (keyno >= yb_distinct_prefixlen) + break; + + indextle = (TargetEntry *) lfirst(tlelc); + + /* Deparse the expression, showing any top-level cast */ + exprstr = deparse_expression((Node *) indextle->expr, context, + useprefix, true); + resetStringInfo(&distinct_prefix_key_buf); + appendStringInfoString(&distinct_prefix_key_buf, exprstr); + /* Emit one property-list item per key */ + result = lappend(result, pstrdup(distinct_prefix_key_buf.data)); + + keyno++; + } + + ExplainPropertyList("Distinct Keys", result, es); + } } diff --git a/src/postgres/src/test/regress/expected/yb_aggregates.out b/src/postgres/src/test/regress/expected/yb_aggregates.out index 92bf4cefec3c..75ae0134ccb3 100644 --- a/src/postgres/src/test/regress/expected/yb_aggregates.out +++ b/src/postgres/src/test/regress/expected/yb_aggregates.out @@ -715,7 +715,7 @@ EXPLAIN (COSTS OFF) SELECT DISTINCT int_8 FROM ybaggtest; HashAggregate Group Key: int_8 -> Distinct Index Only Scan using ybaggtestindex on ybaggtest - Distinct Prefix: 2 + Distinct Keys: int_8, int_2 (4 rows) EXPLAIN (COSTS OFF) SELECT COUNT(distinct int_4), SUM(int_4) FROM ybaggtest; diff --git a/src/postgres/src/test/regress/expected/yb_bitmap_scans_distinct.out b/src/postgres/src/test/regress/expected/yb_bitmap_scans_distinct.out index 27a48706f15a..f9172df858a2 100644 --- a/src/postgres/src/test/regress/expected/yb_bitmap_scans_distinct.out +++ b/src/postgres/src/test/regress/expected/yb_bitmap_scans_distinct.out @@ -15,7 +15,7 @@ SELECT DISTINCT r1 FROM test_distinct WHERE r1 < 2 ORDER BY r1; Unique (actual rows=1 loops=1) -> Distinct Index Scan using test_distinct_pkey on test_distinct (actual rows=2 loops=1) Index Cond: (r1 < 2) - Distinct Prefix: 1 + Distinct Keys: r1 Storage Table Read Requests: 2 Storage Table Rows Scanned: 2 (6 rows) @@ -32,7 +32,7 @@ SELECT DISTINCT r1, r2 FROM test_distinct WHERE r1 < 2 OR r2 < 3 ORDER BY r1, r2 --------------------------------------------------------------------------------------------- Unique (actual rows=6 loops=1) -> Distinct Index Scan using test_distinct_pkey on test_distinct (actual rows=7 loops=1) - Distinct Prefix: 2 + Distinct Keys: r1, r2 Storage Filter: ((r1 < 2) OR (r2 < 3)) (4 rows) diff --git a/src/postgres/src/test/regress/expected/yb_distinct_pushdown_base.out b/src/postgres/src/test/regress/expected/yb_distinct_pushdown_base.out index 9029984190f9..da1391a8121e 100644 --- a/src/postgres/src/test/regress/expected/yb_distinct_pushdown_base.out +++ b/src/postgres/src/test/regress/expected/yb_distinct_pushdown_base.out @@ -31,7 +31,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1 FROM t; --------------------------------------------------------------------- Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: r1 (3 rows) SELECT DISTINCT r1 FROM t; @@ -47,7 +47,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1, r2 FRO --------------------------------------------------------------------- Unique (actual rows=6 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=7 loops=1) - Distinct Prefix: 2 + Distinct Keys: r1, r2 (3 rows) SELECT DISTINCT r1, r2 FROM t; @@ -71,7 +71,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r2 FROM t; HashAggregate (actual rows=3 loops=1) Group Key: r2 -> Distinct Index Scan using t_pkey on t (actual rows=7 loops=1) - Distinct Prefix: 2 + Distinct Keys: r1, r2 (4 rows) SELECT DISTINCT r2 FROM t; @@ -90,7 +90,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1 FROM t Limit (actual rows=2 loops=1) -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: r1 (4 rows) SELECT DISTINCT r1 FROM t LIMIT 2; @@ -109,7 +109,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1 FROM tr ----------------------------------------------------------------------- Unique (actual rows=1 loops=1) -> Distinct Index Scan using tr_pkey on tr (actual rows=1 loops=1) - Distinct Prefix: 1 + Distinct Keys: r1 (3 rows) SELECT DISTINCT r1 FROM tr; @@ -127,7 +127,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1 FROM ts ----------------------------------------------------------------------- Unique (actual rows=1 loops=1) -> Distinct Index Scan using ts_pkey on ts (actual rows=1 loops=1) - Distinct Prefix: 1 + Distinct Keys: r1 (3 rows) SELECT DISTINCT r1 FROM ts; @@ -170,7 +170,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1 FROM t --------------------------------------------------------------------- Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: r1 (3 rows) SELECT DISTINCT r1 FROM t ORDER BY r1; @@ -185,7 +185,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1 FROM t ------------------------------------------------------------------------------ Unique (actual rows=2 loops=1) -> Distinct Index Scan Backward using t_pkey on t (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: r1 (3 rows) SELECT DISTINCT r1 FROM t ORDER BY r1 DESC; @@ -201,7 +201,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1, r2 FRO --------------------------------------------------------------------- Unique (actual rows=6 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=7 loops=1) - Distinct Prefix: 2 + Distinct Keys: r1, r2 (3 rows) SELECT DISTINCT r1, r2 FROM t ORDER BY r1, r2; @@ -220,7 +220,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1, r2 FRO ------------------------------------------------------------------------------ Unique (actual rows=6 loops=1) -> Distinct Index Scan Backward using t_pkey on t (actual rows=7 loops=1) - Distinct Prefix: 2 + Distinct Keys: r1, r2 (3 rows) SELECT DISTINCT r1, r2 FROM t ORDER BY r1 DESC, r2 DESC; @@ -245,7 +245,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1, r2 FRO Sort Method: quicksort -> Unique (actual rows=6 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=7 loops=1) - Distinct Prefix: 2 + Distinct Keys: r1, r2 (6 rows) SELECT DISTINCT r1, r2 FROM t ORDER BY r2; @@ -271,7 +271,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1, r2 FRO ----------------------------------------------------------------------- Unique (actual rows=3 loops=1) -> Distinct Index Scan using tm_pkey on tm (actual rows=3 loops=1) - Distinct Prefix: 2 + Distinct Keys: r1, r2 (3 rows) SELECT DISTINCT r1, r2 FROM tm; @@ -288,7 +288,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1, r2 FRO -------------------------------------------------------------------------------- Unique (actual rows=3 loops=1) -> Distinct Index Scan Backward using tm_pkey on tm (actual rows=3 loops=1) - Distinct Prefix: 2 + Distinct Keys: r1, r2 (3 rows) SELECT DISTINCT r1, r2 FROM tm ORDER BY r1, r2 DESC; diff --git a/src/postgres/src/test/regress/expected/yb_distinct_pushdown_join.out b/src/postgres/src/test/regress/expected/yb_distinct_pushdown_join.out index 7942d9731ad8..7699bf32e7ef 100644 --- a/src/postgres/src/test/regress/expected/yb_distinct_pushdown_join.out +++ b/src/postgres/src/test/regress/expected/yb_distinct_pushdown_join.out @@ -13,11 +13,11 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT t1.r1, t2. Nested Loop (actual rows=4 loops=1) -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t1 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t1.r1 -> Materialize (actual rows=2 loops=2) -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t2 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t2.r1 (8 rows) SELECT DISTINCT t1.r1, t2.r1 FROM t t1 CROSS JOIN t t2; @@ -37,11 +37,11 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT t1.r1 FROM Merge Cond: (t1.r1 = t2.r1) -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t1 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t1.r1 -> Materialize (actual rows=2 loops=1) -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t2 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t2.r1 (9 rows) SELECT DISTINCT t1.r1 FROM t t1 INNER JOIN t t2 USING (r1); @@ -61,12 +61,12 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT t1.r1 FROM Merge Cond: (t1.r1 = t2.r2) -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t1 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t1.r1 -> Sort (actual rows=7 loops=1) Sort Key: t2.r2 Sort Method: quicksort -> Distinct Index Scan using t_pkey on t t2 (actual rows=7 loops=1) - Distinct Prefix: 2 + Distinct Keys: t2.r1, t2.r2 (11 rows) SELECT DISTINCT t1.r1 FROM t t1 INNER JOIN t t2 ON t1.r1 = t2.r2; @@ -84,12 +84,12 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT t1.r1 FROM Merge Cond: (t1.r1 = t2.r2) -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t1 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t1.r1 -> Sort (actual rows=7 loops=1) Sort Key: t2.r2 Sort Method: quicksort -> Distinct Index Scan using t_pkey on t t2 (actual rows=7 loops=1) - Distinct Prefix: 2 + Distinct Keys: t2.r1, t2.r2 (11 rows) SELECT DISTINCT t1.r1 FROM t t1 LEFT JOIN t t2 ON t1.r1 = t2.r2; @@ -109,11 +109,11 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT t1.r1 FROM Hash Cond: (t1.r1 = t2.r2) -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t1 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t1.r1 -> Hash (actual rows=7 loops=1) Buckets: 1024 (originally 1024) Original Batches: 1 -> Distinct Index Scan using t_pkey on t t2 (actual rows=7 loops=1) - Distinct Prefix: 2 + Distinct Keys: t2.r1, t2.r2 (11 rows) SELECT DISTINCT t1.r1 FROM t t1 RIGHT JOIN t t2 ON t1.r1 = t2.r2; @@ -133,11 +133,11 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT t1.r1, t2. Hash Cond: (t1.r1 = t2.r2) -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t1 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t1.r1 -> Hash (actual rows=7 loops=1) Buckets: 1024 (originally 1024) Original Batches: 1 -> Distinct Index Scan using t_pkey on t t2 (actual rows=7 loops=1) - Distinct Prefix: 2 + Distinct Keys: t2.r1, t2.r2 (11 rows) SELECT DISTINCT t1.r1, t2.r2 FROM t t1 FULL JOIN t t2 ON t1.r1 = t2.r2; @@ -160,10 +160,10 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT t1.r1 FROM Rows Removed by Join Filter: 12 -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t1 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t1.r1 -> Materialize (actual rows=7 loops=2) -> Distinct Index Scan using t_pkey on t t2 (actual rows=7 loops=1) - Distinct Prefix: 2 + Distinct Keys: t2.r1, t2.r2 (10 rows) SELECT DISTINCT t1.r1 FROM t t1 JOIN t t2 ON t1.r1 < t2.r2; @@ -180,10 +180,10 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT t2.r1 FROM Join Filter: (t1.r1 < t2.r2) Rows Removed by Join Filter: 17 -> Distinct Index Scan using t_pkey on t t2 (actual rows=7 loops=1) - Distinct Prefix: 2 + Distinct Keys: t2.r1, t2.r2 -> Materialize (actual rows=3 loops=7) -> Distinct Index Scan using t_pkey on t t1 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t1.r1 (9 rows) SELECT DISTINCT t2.r1 FROM t t1 JOIN t t2 ON t1.r1 < t2.r2; @@ -203,12 +203,12 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1 FROM t Hash Cond: (t.r2 = t_1.r1) -> Unique (actual rows=6 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=7 loops=1) - Distinct Prefix: 2 + Distinct Keys: t.r1, t.r2 -> Hash (actual rows=2 loops=1) Buckets: 1024 (originally 1024) Original Batches: 1 -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t_1 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t_1.r1 (12 rows) SELECT DISTINCT r1 FROM t WHERE r2 IN (SELECT r1 FROM t); @@ -258,11 +258,11 @@ EXPLAIN (COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT t1.r1 * RANDOM() FR Merge Cond: (t1.r1 = t2.r1) -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t1 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t1.r1 -> Materialize (actual rows=2 loops=1) -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t2 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t2.r1 (9 rows) /*+MergeJoin(t1 t2)*/ SELECT DISTINCT r1 FROM t t1 JOIN t t2 USING (r1); @@ -279,12 +279,12 @@ EXPLAIN (COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT t1.r1 * RANDOM() FR Hash Cond: (t1.r1 = t2.r1) -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t1 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t1.r1 -> Hash (actual rows=2 loops=1) Buckets: 1024 (originally 1024) Original Batches: 1 -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t2 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t2.r1 (10 rows) /*+HashJoin(t1 t2)*/ SELECT DISTINCT r1 FROM t t1 JOIN t t2 USING (r1); @@ -302,11 +302,11 @@ EXPLAIN (COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT t1.r1 * RANDOM() FR Rows Removed by Join Filter: 2 -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t1 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t1.r1 -> Materialize (actual rows=2 loops=2) -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t2 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t2.r1 (10 rows) /*+Nestloop(t1 t2)*/ SELECT DISTINCT r1 FROM t t1 JOIN t t2 USING (r1); @@ -331,7 +331,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT t1.r1 FROM -> Hash (actual rows=7 loops=1) Buckets: 1024 (originally 1024) Original Batches: 1 -> Distinct Index Scan using t_pkey on t t2 (actual rows=7 loops=1) - Distinct Prefix: 2 + Distinct Keys: t2.r1, t2.r2 (10 rows) SELECT DISTINCT t1.r1 FROM t t1 JOIN t t2 ON t1.r1 = t2.r2 WHERE t1.r1 + RANDOM() < 5; @@ -348,13 +348,13 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT t1.r1 FROM Merge Cond: (t2.r1 = t1.r1) -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t2 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t2.r1 -> Materialize (actual rows=1000 loops=1) -> Merge Join (actual rows=1000 loops=1) Merge Cond: (t1.r1 = t3.r1) -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t1 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t1.r1 -> Materialize (actual rows=1000 loops=1) -> Index Scan using t_pkey on t t3 (actual rows=1000 loops=1) Storage Filter: (((r1)::double precision + random()) < '5'::double precision) @@ -376,11 +376,11 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT t1.r1, t2. Merge Cond: (t1.r1 = t2.r1) -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t1 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t1.r1 -> Materialize (actual rows=2 loops=1) -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t2 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t2.r1 (9 rows) SELECT DISTINCT t1.r1, t2.r1 FROM t t1 JOIN t t2 USING (r1); @@ -398,11 +398,11 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT t2.r1, t1. Merge Cond: (t1.r1 = t2.r1) -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t1 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t1.r1 -> Materialize (actual rows=2 loops=1) -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t2 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t2.r1 (9 rows) SELECT DISTINCT t2.r1, t1.r1 FROM t t1 JOIN t t2 USING (r1); @@ -420,11 +420,11 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT t1.r1, t2. Merge Cond: (t2.r1 = t1.r1) -> Unique (actual rows=6 loops=1) -> Distinct Index Scan using t_pkey on t t2 (actual rows=7 loops=1) - Distinct Prefix: 2 + Distinct Keys: t2.r1, t2.r2 -> Materialize (actual rows=4 loops=1) -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t1 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t1.r1 (9 rows) SELECT DISTINCT t1.r1, t2.r1, t2.r2 FROM t t1 JOIN t t2 USING (r1); @@ -446,11 +446,11 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT t2.r2, t1. Merge Cond: (t1.r1 = t2.r1) -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t t1 (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: t1.r1 -> Materialize (actual rows=6 loops=1) -> Unique (actual rows=6 loops=1) -> Distinct Index Scan using t_pkey on t t2 (actual rows=7 loops=1) - Distinct Prefix: 2 + Distinct Keys: t2.r1, t2.r2 (9 rows) SELECT DISTINCT t2.r2, t1.r1, t2.r1 FROM t t1 JOIN t t2 USING (r1); @@ -473,12 +473,12 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT t1.r2 FROM -> Unique (actual rows=1 loops=1) -> Distinct Index Scan using t_pkey on t t1 (actual rows=2 loops=1) Index Cond: (r2 = 2) - Distinct Prefix: 1 + Distinct Keys: t1.r1 -> Materialize (actual rows=1 loops=1) -> Unique (actual rows=1 loops=1) -> Distinct Index Scan using t_pkey on t t2 (actual rows=2 loops=1) Index Cond: (r2 = 2) - Distinct Prefix: 1 + Distinct Keys: t2.r1 (10 rows) SELECT DISTINCT t1.r2 FROM t t1 JOIN t t2 USING (r2) WHERE t2.r2 = 2; @@ -499,7 +499,7 @@ SELECT DISTINCT t1.r2 FROM t t1 JOIN t t2 USING (r2) WHERE t2.r2 = 2; -> Unique (actual rows=1 loops=1) -> Distinct Index Scan using t_pkey on t t2 (actual rows=2 loops=1) Index Cond: (r1 = 1) - Distinct Prefix: 1 + Distinct Keys: t2.r1 (9 rows) /*+ Seqscan(t1) */ SELECT DISTINCT t1.r1 FROM t t1 JOIN t t2 USING (r1) WHERE t2.r1 = 1; @@ -522,12 +522,12 @@ INSERT INTO th (SELECT 10, i%3, 2-i%3, i, i/3 FROM GENERATE_SERIES(1, 1000) AS i Sort Key: t1.h1, t1.h2 Sort Method: quicksort -> Distinct Index Scan using th_pkey on th t1 (actual rows=6 loops=1) - Distinct Prefix: 2 + Distinct Keys: t1.h1, t1.h2 -> Sort (actual rows=6 loops=1) Sort Key: t2.h1, t2.h2 Sort Method: quicksort -> Distinct Index Scan using th_pkey on th t2 (actual rows=6 loops=1) - Distinct Prefix: 2 + Distinct Keys: t2.h1, t2.h2 (12 rows) /*+ MergeJoin(t1 t2) */ SELECT DISTINCT h1, h2 FROM th t1 JOIN th t2 USING (h1, h2); @@ -547,11 +547,11 @@ INSERT INTO th (SELECT 10, i%3, 2-i%3, i, i/3 FROM GENERATE_SERIES(1, 1000) AS i Hash Join (actual rows=6 loops=1) Hash Cond: ((t1.h1 = t2.h1) AND (t1.h2 = t2.h2)) -> Distinct Index Scan using th_pkey on th t1 (actual rows=6 loops=1) - Distinct Prefix: 2 + Distinct Keys: t1.h1, t1.h2 -> Hash (actual rows=6 loops=1) Buckets: 1024 (originally 1024) Original Batches: 1 -> Distinct Index Scan using th_pkey on th t2 (actual rows=6 loops=1) - Distinct Prefix: 2 + Distinct Keys: t2.h1, t2.h2 (8 rows) /*+ HashJoin(t1 t2) */ SELECT DISTINCT h1, h2 FROM th t1 JOIN th t2 USING (h1, h2); @@ -572,10 +572,10 @@ INSERT INTO th (SELECT 10, i%3, 2-i%3, i, i/3 FROM GENERATE_SERIES(1, 1000) AS i Join Filter: ((t1.h1 = t2.h1) AND (t1.h2 = t2.h2)) Rows Removed by Join Filter: 30 -> Distinct Index Scan using th_pkey on th t1 (actual rows=6 loops=1) - Distinct Prefix: 2 + Distinct Keys: t1.h1, t1.h2 -> Materialize (actual rows=6 loops=6) -> Distinct Index Scan using th_pkey on th t2 (actual rows=6 loops=1) - Distinct Prefix: 2 + Distinct Keys: t2.h1, t2.h2 (8 rows) /*+ Nestloop(t1 t2) */ SELECT DISTINCT h1, h2 FROM th t1 JOIN th t2 USING (h1, h2); @@ -597,12 +597,12 @@ INSERT INTO th (SELECT 10, i%3, 2-i%3, i, i/3 FROM GENERATE_SERIES(1, 1000) AS i Merge Cond: ((t.r1 = th.h1) AND (t.r2 = th.h2)) -> Unique (actual rows=6 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=7 loops=1) - Distinct Prefix: 2 + Distinct Keys: t.r1, t.r2 -> Sort (actual rows=6 loops=1) Sort Key: th.h1, th.h2 Sort Method: quicksort -> Distinct Index Scan using th_pkey on th (actual rows=6 loops=1) - Distinct Prefix: 2 + Distinct Keys: th.h1, th.h2 (10 rows) /*+ MergeJoin(th t) */ SELECT DISTINCT th.h1, th.h2 FROM th JOIN t ON th.h1 = t.r1 AND th.h2 = t.r2; @@ -623,11 +623,11 @@ INSERT INTO th (SELECT 10, i%3, 2-i%3, i, i/3 FROM GENERATE_SERIES(1, 1000) AS i Hash Cond: ((t.r1 = th.h1) AND (t.r2 = th.h2)) -> Unique (actual rows=6 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=7 loops=1) - Distinct Prefix: 2 + Distinct Keys: t.r1, t.r2 -> Hash (actual rows=6 loops=1) Buckets: 1024 (originally 1024) Original Batches: 1 -> Distinct Index Scan using th_pkey on th (actual rows=6 loops=1) - Distinct Prefix: 2 + Distinct Keys: th.h1, th.h2 (9 rows) /*+ HashJoin(th t) */ SELECT DISTINCT th.h1, th.h2 FROM th JOIN t ON th.h1 = t.r1 AND th.h2 = t.r2; @@ -649,10 +649,10 @@ INSERT INTO th (SELECT 10, i%3, 2-i%3, i, i/3 FROM GENERATE_SERIES(1, 1000) AS i Rows Removed by Join Filter: 30 -> Unique (actual rows=6 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=7 loops=1) - Distinct Prefix: 2 + Distinct Keys: t.r1, t.r2 -> Materialize (actual rows=6 loops=6) -> Distinct Index Scan using th_pkey on th (actual rows=6 loops=1) - Distinct Prefix: 2 + Distinct Keys: th.h1, th.h2 (9 rows) /*+ Nestloop(th t) */ SELECT DISTINCT th.h1, th.h2 FROM th JOIN t ON th.h1 = t.r1 AND th.h2 = t.r2; @@ -675,12 +675,12 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT v FROM t t Hash Join (actual rows=334 loops=1) Hash Cond: (t1.v = t2.v) -> Distinct Index Only Scan using irv on t t1 (actual rows=334 loops=1) - Distinct Prefix: 1 + Distinct Keys: t1.v Heap Fetches: 0 -> Hash (actual rows=334 loops=1) Buckets: 1024 (originally 1024) Original Batches: 1 -> Distinct Index Only Scan using irv on t t2 (actual rows=334 loops=1) - Distinct Prefix: 1 + Distinct Keys: t2.v Heap Fetches: 0 (10 rows) @@ -708,7 +708,7 @@ SELECT DISTINCT t2.pk FROM t1 JOIN t2 ON t1.col_int_key = t2.col_int WHERE t2.pk -> Unique (actual rows=2 loops=1) -> Distinct Index Scan using t1_pkey on t1 (actual rows=2 loops=1) Index Cond: (col_int_key = ANY (ARRAY[t2.col_int, $1, $2, ..., $1023])) - Distinct Prefix: 1 + Distinct Keys: t1.col_int_key (10 rows) /*+ Set(enable_mergejoin off) Set(enable_hashjoin off) Set(enable_material off) */ diff --git a/src/postgres/src/test/regress/expected/yb_distinct_pushdown_pred.out b/src/postgres/src/test/regress/expected/yb_distinct_pushdown_pred.out index 048ac9e6bbd6..9a5b8fa82747 100644 --- a/src/postgres/src/test/regress/expected/yb_distinct_pushdown_pred.out +++ b/src/postgres/src/test/regress/expected/yb_distinct_pushdown_pred.out @@ -54,7 +54,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r2 FROM t --------------------------------------------------------------------- Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=3 loops=1) - Distinct Prefix: 2 + Distinct Keys: r1, r2 Storage Filter: (r1 = r2) (4 rows) @@ -70,7 +70,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1, r2 FRO --------------------------------------------------------------------- Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=3 loops=1) - Distinct Prefix: 2 + Distinct Keys: r1, r2 Storage Filter: (r1 = r2) (4 rows) @@ -88,7 +88,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r3 FROM t Unique (actual rows=1 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=3 loops=1) Index Cond: (r3 = 1) - Distinct Prefix: 1 + Distinct Keys: r1 (4 rows) SELECT DISTINCT r3 FROM t WHERE r3 = 1; @@ -104,7 +104,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r3 FROM t Unique (actual rows=0 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=0 loops=1) Index Cond: (r3 = 5) - Distinct Prefix: 1 + Distinct Keys: r1 (4 rows) SELECT DISTINCT r3 FROM t WHERE r3 = 5; @@ -120,7 +120,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r2, r3 FRO Group Key: r2, r3 -> Distinct Index Scan using t_pkey on t (actual rows=3 loops=1) Index Cond: (r3 = 1) - Distinct Prefix: 2 + Distinct Keys: r1, r2 (5 rows) SELECT DISTINCT r2, r3 FROM t WHERE r3 = 1; @@ -136,7 +136,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r2, r3 FRO Group Key: r2, r3 -> Distinct Index Scan using t_pkey on t (actual rows=0 loops=1) Index Cond: (r3 = 5) - Distinct Prefix: 2 + Distinct Keys: r1, r2 (5 rows) SELECT DISTINCT r2, r3 FROM t WHERE r3 = 5; @@ -152,7 +152,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r2, r3 FRO Unique (actual rows=1 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=3 loops=1) Index Cond: ((r2 = 1) AND (r3 = 1)) - Distinct Prefix: 1 + Distinct Keys: r1 (4 rows) SELECT DISTINCT r2, r3 FROM t WHERE r2 = r3 AND r3 = 1; @@ -201,7 +201,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1 FROM t --------------------------------------------------------------------- Unique (actual rows=1 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=2 loops=1) - Distinct Prefix: 1 + Distinct Keys: r1 Storage Filter: ((r1 * r1) = 1) (4 rows) @@ -216,7 +216,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1 FROM t --------------------------------------------------------------------- Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=3 loops=1) - Distinct Prefix: 2 + Distinct Keys: r1, r2 Storage Filter: ((r2 * r2) = 1) (4 rows) @@ -234,7 +234,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1 * r2 AS HashAggregate (actual rows=4 loops=1) Group Key: (r1 * r2) -> Distinct Index Scan using t_pkey on t (actual rows=7 loops=1) - Distinct Prefix: 2 + Distinct Keys: r1, r2 (4 rows) SELECT DISTINCT r1 * r2 AS r FROM t; @@ -253,7 +253,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT 0 * r1 AS HashAggregate (actual rows=1 loops=1) Group Key: (0 * r1) -> Distinct Index Scan using t_pkey on t (actual rows=3 loops=1) - Distinct Prefix: 1 + Distinct Keys: r1 (4 rows) SELECT DISTINCT 0 * r1 AS r FROM t; @@ -289,7 +289,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1 FROM t Unique (actual rows=1 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=1 loops=1) Index Cond: (r1 > 1) - Distinct Prefix: 1 + Distinct Keys: r1 (4 rows) SELECT DISTINCT r1 FROM t WHERE r1 > 1; @@ -306,7 +306,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1 FROM t Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=2 loops=1) Index Cond: (r2 > 1) - Distinct Prefix: 1 + Distinct Keys: r1 (4 rows) SELECT DISTINCT r1 FROM t WHERE r2 > 1; @@ -325,7 +325,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r2 FROM t Group Key: r2 -> Distinct Index Scan using t_pkey on t (actual rows=7 loops=1) Index Cond: (r2 < 5) - Distinct Prefix: 2 + Distinct Keys: r1, r2 (5 rows) SELECT DISTINCT r2 FROM t WHERE r2 < 5; @@ -343,7 +343,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1 FROM t Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=3 loops=1) Index Cond: (r1 = ANY ('{1,2}'::integer[])) - Distinct Prefix: 1 + Distinct Keys: r1 (4 rows) SELECT DISTINCT r1 FROM t WHERE r1 IN (1, 2); @@ -360,7 +360,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1 FROM t Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=3 loops=1) Index Cond: (r1 = ANY ('{1,2}'::integer[])) - Distinct Prefix: 1 + Distinct Keys: r1 (4 rows) SELECT DISTINCT r1 FROM t WHERE r1 IN (3, 5); @@ -375,7 +375,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1 FROM t Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=3 loops=1) Index Cond: (r2 = ANY ('{1,2}'::integer[])) - Distinct Prefix: 1 + Distinct Keys: r1 (4 rows) SELECT DISTINCT r1 FROM t WHERE r2 IN (1, 2); @@ -392,7 +392,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1, r2 FRO Unique (actual rows=2 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=2 loops=1) Index Cond: ((r1 = ANY ('{1,2}'::integer[])) AND (r2 = 2)) - Distinct Prefix: 1 + Distinct Keys: r1 (4 rows) SELECT DISTINCT r1, r2 FROM t WHERE r1 IN (1, 2) AND r2 = 2; @@ -410,7 +410,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1, r2 FRO Unique (actual rows=4 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=5 loops=1) Index Cond: (r2 = ANY ('{1,2}'::integer[])) - Distinct Prefix: 2 + Distinct Keys: r1, r2 (4 rows) SELECT DISTINCT r1, r2 FROM t WHERE r2 IN (1, 2) ORDER BY r1, r2; @@ -429,7 +429,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1 FROM t Unique (actual rows=1 loops=1) -> Distinct Index Scan using t_pkey on t (actual rows=2 loops=1) Index Cond: (r1 = 1) - Distinct Prefix: 1 + Distinct Keys: r1 (4 rows) SELECT DISTINCT r1 FROM t WHERE r1 = 1; @@ -471,7 +471,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT h1, h2 FRO QUERY PLAN ----------------------------------------------------------------- Distinct Index Scan using th_pkey on th (actual rows=6 loops=1) - Distinct Prefix: 2 + Distinct Keys: h1, h2 (2 rows) SELECT DISTINCT h1, h2 FROM th; @@ -492,7 +492,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT h1 FROM th HashAggregate (actual rows=2 loops=1) Group Key: h1 -> Distinct Index Scan using th_pkey on th (actual rows=6 loops=1) - Distinct Prefix: 2 + Distinct Keys: h1, h2 (4 rows) SELECT DISTINCT h1 FROM th; @@ -509,7 +509,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT h2 FROM th HashAggregate (actual rows=3 loops=1) Group Key: h2 -> Distinct Index Scan using th_pkey on th (actual rows=6 loops=1) - Distinct Prefix: 2 + Distinct Keys: h1, h2 (4 rows) SELECT DISTINCT h2 FROM th; @@ -526,7 +526,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT h1, h2, r1 QUERY PLAN ----------------------------------------------------------------- Distinct Index Scan using th_pkey on th (actual rows=6 loops=1) - Distinct Prefix: 3 + Distinct Keys: h1, h2, r1 (2 rows) SELECT DISTINCT h1, h2, r1 FROM th; @@ -548,7 +548,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1 FROM th HashAggregate (actual rows=3 loops=1) Group Key: r1 -> Distinct Index Scan using th_pkey on th (actual rows=6 loops=1) - Distinct Prefix: 3 + Distinct Keys: h1, h2, r1 (4 rows) SELECT DISTINCT r1 FROM th; @@ -571,7 +571,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT h1 FROM th Sort Key: h1 Sort Method: quicksort -> Distinct Index Scan using th_pkey on th (actual rows=6 loops=1) - Distinct Prefix: 2 + Distinct Keys: h1, h2 (6 rows) SELECT DISTINCT h1 FROM th ORDER BY h1; @@ -587,7 +587,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1 FROM th ----------------------------------------------------------------- Distinct Index Scan using th_pkey on th (actual rows=1 loops=1) Index Cond: ((h1 = 1) AND (h2 = 1)) - Distinct Prefix: 3 + Distinct Keys: h1, h2, r1 (3 rows) SELECT DISTINCT r1 FROM th WHERE h1 = 1 AND h2 = 1 ORDER BY r1; @@ -605,7 +605,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1 FROM th Sort Key: r1 Sort Method: quicksort -> Distinct Index Scan using th_pkey on th (actual rows=3 loops=1) - Distinct Prefix: 3 + Distinct Keys: h1, h2, r1 Storage Filter: (h1 = 1) (7 rows) @@ -623,7 +623,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT h1, h2 FRO ----------------------------------------------------------------- Distinct Index Scan using th_pkey on th (actual rows=1 loops=1) Index Cond: ((h1 = 1) AND (h2 = 1)) - Distinct Prefix: 2 + Distinct Keys: h1, h2 (3 rows) SELECT DISTINCT h1, h2 FROM th WHERE h1 = 1 AND h2 = 1; @@ -637,7 +637,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT h1, h2 FRO QUERY PLAN ----------------------------------------------------------------- Distinct Index Scan using th_pkey on th (actual rows=2 loops=1) - Distinct Prefix: 3 + Distinct Keys: h1, h2, r1 Storage Filter: (r1 = 1) (3 rows) @@ -653,7 +653,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1 FROM th ----------------------------------------------------------------------- Unique (actual rows=1 loops=1) -> Distinct Index Scan using th_pkey on th (actual rows=2 loops=1) - Distinct Prefix: 3 + Distinct Keys: h1, h2, r1 Storage Filter: (r1 = 1) (4 rows) @@ -680,7 +680,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT v FROM t; ------------------------------------------------------------------------- Unique (actual rows=335 loops=1) -> Distinct Index Only Scan using irv on t (actual rows=335 loops=1) - Distinct Prefix: 1 + Distinct Keys: v Heap Fetches: 0 (4 rows) @@ -706,7 +706,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT v FROM t O ---------------------------------------------------------------------------------- Unique (actual rows=335 loops=1) -> Distinct Index Only Scan Backward using irv on t (actual rows=335 loops=1) - Distinct Prefix: 1 + Distinct Keys: v Heap Fetches: 0 (4 rows) @@ -757,7 +757,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT v FROM t; ------------------------------------------------------------------------- Unique (actual rows=335 loops=1) -> Distinct Index Only Scan using irv on t (actual rows=335 loops=1) - Distinct Prefix: 1 + Distinct Keys: v Heap Fetches: 0 (4 rows) @@ -790,7 +790,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT v FROM th; HashAggregate (actual rows=334 loops=1) Group Key: v -> Distinct Index Only Scan using ihv on th (actual rows=668 loops=1) - Distinct Prefix: 2 + Distinct Keys: v, h1 Heap Fetches: 0 (5 rows) @@ -884,7 +884,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT a FROM sam Unique (actual rows=1 loops=1) -> Distinct Index Scan using sample_pkey on sample (actual rows=1 loops=1) Index Cond: (a > 0) - Distinct Prefix: 1 + Distinct Keys: a (4 rows) SELECT DISTINCT a FROM sample WHERE a > 0; diff --git a/src/postgres/src/test/regress/expected/yb_feature_colocation.out b/src/postgres/src/test/regress/expected/yb_feature_colocation.out index e1197fc8eb7b..bc49e90c0e0b 100644 --- a/src/postgres/src/test/regress/expected/yb_feature_colocation.out +++ b/src/postgres/src/test/regress/expected/yb_feature_colocation.out @@ -842,7 +842,7 @@ EXPLAIN (COSTS OFF) SELECT DISTINCT r1 FROM tbl_colo WHERE r3 <= 1; Unique -> Distinct Index Only Scan using tbl_colo_r1_r3_r5_idx on tbl_colo Index Cond: (r3 <= 1) - Distinct Prefix: 1 + Distinct Keys: r1 (4 rows) SELECT DISTINCT r1 FROM tbl_colo WHERE r3 <= 1; @@ -859,7 +859,7 @@ SELECT DISTINCT r1 FROM tbl_colo WHERE r3 <= 1; Unique -> Distinct Index Only Scan using tbl_colo_r1_r3_r5_idx on tbl_colo Index Cond: (r3 <= 1) - Distinct Prefix: 1 + Distinct Keys: r1 (4 rows) /*+Set(enable_hashagg false)*/ SELECT DISTINCT r1 FROM tbl_colo WHERE r3 <= 1;