Skip to content

Commit

Permalink
[#20958] test: hide "Memory:" fields in regress tests
Browse files Browse the repository at this point in the history
Summary:
Commit 2dd38ff adds a GUC to hide
non-deterministic fields in EXPLAIN output, but some tests still show
non-deterministic "Memory:" fields.  These fields particularly change in
pg15.  Use the GUC to hide these fields.

Note that there are other "Memory Usage:" fields that seem to not be
affected by the GUC.
Jira: DB-9933

Test Plan:
On Almalinux 8:

    ./yb_build.sh fastdebug --gcc11 \
      --java-test org.yb.pgsql.TestPgRegressDistinctPushdown
    ./yb_build.sh fastdebug --gcc11 \
      --java-test 'org.yb.pgsql.TestPgRegressProc#testPgRegressProc'

Close: #20958
Jenkins: test regex: TestPgRegress(DistinctPushdown|Proc)

Reviewers: kramanathan, patnaik.balivada

Reviewed By: kramanathan

Subscribers: yql

Differential Revision: https://phorge.dev.yugabyte.com/D32204
  • Loading branch information
jaki committed Feb 6, 2024
1 parent 4113566 commit e62fdc8
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,14 @@ INSERT INTO vectors SELECT to_tsvector('simple', 'filler') FROM generate_series(
CREATE INDEX NONCONCURRENTLY igin ON vectors USING ybgin (v);
-- Avoid fetching primary key and fetch secondary key instead since
-- there is already an LSM index on the primary key and LSM supports distinct index scan.
-- XXX: Explain output also shows memory consumed for sort.
-- This can be handled using regex but leave it be for readability.
SET yb_explain_hide_non_deterministic_fields = true;
EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT v FROM vectors;
QUERY PLAN
----------------------------------------------------------
Unique (actual rows=1 loops=1)
-> Sort (actual rows=10 loops=1)
Sort Key: v
Sort Method: quicksort Memory: 25kB
Sort Method: quicksort
-> Seq Scan on vectors (actual rows=10 loops=1)
(5 rows)

Expand Down Expand Up @@ -243,7 +242,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1, r2 FRO
---------------------------------------------------------------------------
Sort (actual rows=6 loops=1)
Sort Key: r2
Sort Method: quicksort Memory: 25kB
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ SELECT DISTINCT t1.r1 FROM t t1 INNER JOIN t t2 USING (r1);
(2 rows)

-- In the Distinct Index Scan of t2, there are 7 rows, not 6, because the tablet split ends up with 1, 1 represented in two tablets.
SET yb_explain_hide_non_deterministic_fields = true;
EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT t1.r1 FROM t t1 INNER JOIN t t2 ON t1.r1 = t2.r2;
QUERY PLAN
------------------------------------------------------------------------------------
Expand All @@ -62,7 +63,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT t1.r1 FROM
Distinct Prefix: 1
-> Sort (actual rows=7 loops=1)
Sort Key: t2.r2
Sort Method: quicksort Memory: 25kB
Sort Method: quicksort
-> Distinct Index Scan using t_pkey on t t2 (actual rows=7 loops=1)
Distinct Prefix: 2
(11 rows)
Expand All @@ -85,7 +86,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT t1.r1 FROM
Distinct Prefix: 1
-> Sort (actual rows=7 loops=1)
Sort Key: t2.r2
Sort Method: quicksort Memory: 25kB
Sort Method: quicksort
-> Distinct Index Scan using t_pkey on t t2 (actual rows=7 loops=1)
Distinct Prefix: 2
(11 rows)
Expand Down Expand Up @@ -518,12 +519,12 @@ INSERT INTO th (SELECT 10, i%3, 2-i%3, i, i/3 FROM GENERATE_SERIES(1, 1000) AS i
Merge Cond: ((t1.h1 = t2.h1) AND (t1.h2 = t2.h2))
-> Sort (actual rows=6 loops=1)
Sort Key: t1.h1, t1.h2
Sort Method: quicksort Memory: 25kB
Sort Method: quicksort
-> Distinct Index Scan using th_pkey on th t1 (actual rows=6 loops=1)
Distinct Prefix: 2
-> Sort (actual rows=6 loops=1)
Sort Key: t2.h1, t2.h2
Sort Method: quicksort Memory: 25kB
Sort Method: quicksort
-> Distinct Index Scan using th_pkey on th t2 (actual rows=6 loops=1)
Distinct Prefix: 2
(12 rows)
Expand Down Expand Up @@ -598,7 +599,7 @@ INSERT INTO th (SELECT 10, i%3, 2-i%3, i, i/3 FROM GENERATE_SERIES(1, 1000) AS i
Distinct Prefix: 2
-> Sort (actual rows=6 loops=1)
Sort Key: th.h1, th.h2
Sort Method: quicksort Memory: 25kB
Sort Method: quicksort
-> Distinct Index Scan using th_pkey on th (actual rows=6 loops=1)
Distinct Prefix: 2
(10 rows)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,13 +562,14 @@ SELECT DISTINCT r1 FROM th;
-- Avoid classifying hash columns as sortable.
-- Guard rails meant to prevent DISTINCT logic from
-- marking hash columns as sortable.
SET yb_explain_hide_non_deterministic_fields = true;
EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT h1 FROM th ORDER BY h1;
QUERY PLAN
-----------------------------------------------------------------------------
Unique (actual rows=2 loops=1)
-> Sort (actual rows=6 loops=1)
Sort Key: h1
Sort Method: quicksort Memory: 25kB
Sort Method: quicksort
-> Distinct Index Scan using th_pkey on th (actual rows=6 loops=1)
Distinct Prefix: 2
(6 rows)
Expand Down Expand Up @@ -602,7 +603,7 @@ EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT r1 FROM th
Unique (actual rows=3 loops=1)
-> Sort (actual rows=3 loops=1)
Sort Key: r1
Sort Method: quicksort Memory: 25kB
Sort Method: quicksort
-> Distinct Index Scan using th_pkey on th (actual rows=3 loops=1)
Distinct Prefix: 3
Remote Filter: (h1 = 1)
Expand Down
7 changes: 4 additions & 3 deletions src/postgres/src/test/regress/expected/yb_hash_code.out
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ DROP TYPE mood;
-- test basic pushdown on a table with one primary hash key column
CREATE TABLE test_table_one_primary (x INT PRIMARY KEY, y INT);
INSERT INTO test_table_one_primary SELECT i,i FROM generate_series(1, 10000) i;
SET yb_explain_hide_non_deterministic_fields = true;
EXPLAIN (COSTS OFF, TIMING OFF, SUMMARY OFF, ANALYZE) SELECT * FROM test_table_one_primary WHERE yb_hash_code(x) = 10427;
QUERY PLAN
------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -229,7 +230,7 @@ EXPLAIN (COSTS OFF, TIMING OFF, SUMMARY OFF, ANALYZE) SELECT x, yb_hash_code(x)
------------------------------------------------------------------------------------------------------
Sort (actual rows=3 loops=1)
Sort Key: x
Sort Method: quicksort Memory: 25kB
Sort Method: quicksort
-> Index Scan using test_table_one_primary_pkey on test_table_one_primary (actual rows=3 loops=1)
Index Cond: ((x = ANY ('{1,2,3,4}'::integer[])) AND (yb_hash_code(x) < 50000))
Rows Removed by Index Recheck: 1
Expand Down Expand Up @@ -584,7 +585,7 @@ EXPLAIN (COSTS OFF, TIMING OFF, SUMMARY OFF, ANALYZE) SELECT * from test_table_m
----------------------------------------------------------------------------------------------------------
Sort (actual rows=8 loops=1)
Sort Key: h1
Sort Method: quicksort Memory: 26kB
Sort Method: quicksort
-> Index Scan using test_table_multi_col_key_pkey on test_table_multi_col_key (actual rows=8 loops=1)
Index Cond: (yb_hash_code(h1, h2, h3) < 60)
(5 rows)
Expand All @@ -608,7 +609,7 @@ EXPLAIN (COSTS OFF, TIMING OFF, SUMMARY OFF, ANALYZE) SELECT * from test_table_m
Limit (actual rows=3 loops=1)
-> Sort (actual rows=3 loops=1)
Sort Key: h1
Sort Method: top-N heapsort Memory: 25kB
Sort Method: top-N heapsort
-> Index Scan using test_table_multi_col_key_pkey on test_table_multi_col_key (actual rows=8 loops=1)
Index Cond: (yb_hash_code(h1, h2, h3) < 60)
(6 rows)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ CREATE INDEX NONCONCURRENTLY igin ON vectors USING ybgin (v);

-- Avoid fetching primary key and fetch secondary key instead since
-- there is already an LSM index on the primary key and LSM supports distinct index scan.
-- XXX: Explain output also shows memory consumed for sort.
-- This can be handled using regex but leave it be for readability.
SET yb_explain_hide_non_deterministic_fields = true;
EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT v FROM vectors;
SELECT DISTINCT v FROM vectors;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ SELECT DISTINCT t1.r1, t2.r1 FROM t t1 CROSS JOIN t t2;
EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT t1.r1 FROM t t1 INNER JOIN t t2 USING (r1);
SELECT DISTINCT t1.r1 FROM t t1 INNER JOIN t t2 USING (r1);
-- In the Distinct Index Scan of t2, there are 7 rows, not 6, because the tablet split ends up with 1, 1 represented in two tablets.
SET yb_explain_hide_non_deterministic_fields = true;
EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT t1.r1 FROM t t1 INNER JOIN t t2 ON t1.r1 = t2.r2;
SELECT DISTINCT t1.r1 FROM t t1 INNER JOIN t t2 ON t1.r1 = t2.r2;
-- LEFT JOIN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ SELECT DISTINCT r1 FROM th;
-- Avoid classifying hash columns as sortable.
-- Guard rails meant to prevent DISTINCT logic from
-- marking hash columns as sortable.
SET yb_explain_hide_non_deterministic_fields = true;
EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF, SUMMARY OFF) SELECT DISTINCT h1 FROM th ORDER BY h1;
SELECT DISTINCT h1 FROM th ORDER BY h1;
-- Once all the hash columns are set, range columns are returned in sorted order as usual.
Expand Down
1 change: 1 addition & 0 deletions src/postgres/src/test/regress/sql/yb_hash_code.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ DROP TYPE mood;
-- test basic pushdown on a table with one primary hash key column
CREATE TABLE test_table_one_primary (x INT PRIMARY KEY, y INT);
INSERT INTO test_table_one_primary SELECT i,i FROM generate_series(1, 10000) i;
SET yb_explain_hide_non_deterministic_fields = true;
EXPLAIN (COSTS OFF, TIMING OFF, SUMMARY OFF, ANALYZE) SELECT * FROM test_table_one_primary WHERE yb_hash_code(x) = 10427;
SELECT * FROM test_table_one_primary WHERE yb_hash_code(x) = 10427;
EXPLAIN (COSTS OFF, TIMING OFF, SUMMARY OFF, ANALYZE) SELECT * FROM test_table_one_primary WHERE yb_hash_code(x) < 512;
Expand Down

0 comments on commit e62fdc8

Please sign in to comment.