Skip to content

Commit

Permalink
Add EXPLAIN (COSTS false) to some tests
Browse files Browse the repository at this point in the history
The commit adds the EXPLAIN OPTION '(COSTS false)' to improve the test
stability, as these can get influences by upstream if the costing model
changes for a reason or another like the recent upstrean change
82a4edabd272.

This change does not influence the coverage of the test as the plans are
the same, just the output produced.

Per pull request yugabyte#148.

Author: Masahiro Ikeda
Backpatch-through: 11
  • Loading branch information
michaelpq committed Aug 29, 2023
1 parent 33adb40 commit ffd7f62
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 95 deletions.
62 changes: 31 additions & 31 deletions expected/ut-A.out
Original file line number Diff line number Diff line change
Expand Up @@ -4772,77 +4772,77 @@ CREATE INDEX ON s1.tpc(a);
PREPARE p1 AS SELECT * FROM s1.tpc WHERE a < 999;
/*+ IndexScan(tpc) */PREPARE p2 AS SELECT * FROM s1.tpc WHERE a < 999;
/*+ SeqScan(tpc) */PREPARE p3(int) AS SELECT * FROM s1.tpc WHERE a = $1;
EXPLAIN EXECUTE p1;
QUERY PLAN
------------------------------------------------------
Seq Scan on tpc (cost=0.00..17.50 rows=333 width=4)
EXPLAIN (COSTS false) EXECUTE p1;
QUERY PLAN
---------------------
Seq Scan on tpc
Filter: (a < 999)
(2 rows)

EXPLAIN EXECUTE p2;
EXPLAIN (COSTS false) EXECUTE p2;
LOG: pg_hint_plan:
used hint:
IndexScan(tpc)
not used hint:
duplication hint:
error hint:

QUERY PLAN
------------------------------------------------------------------------
Index Scan using tpc_a_idx on tpc (cost=0.28..34.10 rows=333 width=4)
QUERY PLAN
-----------------------------------
Index Scan using tpc_a_idx on tpc
Index Cond: (a < 999)
(2 rows)

EXPLAIN EXECUTE p3(500);
EXPLAIN (COSTS false) EXECUTE p3(500);
LOG: pg_hint_plan:
used hint:
SeqScan(tpc)
not used hint:
duplication hint:
error hint:

QUERY PLAN
----------------------------------------------------
Seq Scan on tpc (cost=0.00..17.50 rows=5 width=4)
QUERY PLAN
---------------------
Seq Scan on tpc
Filter: (a = 500)
(2 rows)

-- The DROP invalidates the plan caches
DROP TABLE s1.tpc;
CREATE TABLE s1.tpc AS SELECT a FROM generate_series(0, 999) a;
CREATE INDEX ON s1.tpc(a);
EXPLAIN EXECUTE p1;
QUERY PLAN
------------------------------------------------------
Seq Scan on tpc (cost=0.00..17.50 rows=333 width=4)
EXPLAIN (COSTS false) EXECUTE p1;
QUERY PLAN
---------------------
Seq Scan on tpc
Filter: (a < 999)
(2 rows)

EXPLAIN EXECUTE p2;
EXPLAIN (COSTS false) EXECUTE p2;
LOG: pg_hint_plan:
used hint:
IndexScan(tpc)
not used hint:
duplication hint:
error hint:

QUERY PLAN
------------------------------------------------------------------------
Index Scan using tpc_a_idx on tpc (cost=0.28..34.10 rows=333 width=4)
QUERY PLAN
-----------------------------------
Index Scan using tpc_a_idx on tpc
Index Cond: (a < 999)
(2 rows)

EXPLAIN EXECUTE p3(500);
EXPLAIN (COSTS false) EXECUTE p3(500);
LOG: pg_hint_plan:
used hint:
SeqScan(tpc)
not used hint:
duplication hint:
error hint:

QUERY PLAN
----------------------------------------------------
Seq Scan on tpc (cost=0.00..17.50 rows=5 width=4)
QUERY PLAN
---------------------
Seq Scan on tpc
Filter: (a = 500)
(2 rows)

Expand All @@ -4856,7 +4856,7 @@ PREPARE test_query(numeric[]) AS
(SELECT 1 AS x)
SELECT t1.* FROM test t1, test t2
WHERE t1.x = ANY($1) AND t1.x = t2.x;
EXPLAIN EXECUTE test_query(array[1,2,3]);
EXPLAIN (COSTS false) EXECUTE test_query(array[1,2,3]);
LOG: pg_hint_plan:
used hint:
MergeJoin(t1 t2)
Expand All @@ -4866,16 +4866,16 @@ error hint:

QUERY PLAN
-------------------------------------------------------------------
Merge Join (cost=0.08..0.10 rows=1 width=4)
Merge Join
Merge Cond: (t1.x = t2.x)
CTE test
-> Result (cost=0.00..0.01 rows=1 width=4)
-> Sort (cost=0.04..0.04 rows=1 width=4)
-> Result
-> Sort
Sort Key: t1.x
-> CTE Scan on test t1 (cost=0.00..0.03 rows=1 width=4)
-> CTE Scan on test t1
Filter: ((x)::numeric = ANY ('{1,2,3}'::numeric[]))
-> Sort (cost=0.03..0.04 rows=1 width=4)
-> Sort
Sort Key: t2.x
-> CTE Scan on test t2 (cost=0.00..0.02 rows=1 width=4)
-> CTE Scan on test t2
(11 rows)

86 changes: 43 additions & 43 deletions expected/ut-T.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,123 +6,123 @@ SET pg_hint_plan.debug_print TO on;
SET client_min_messages TO LOG;
SET search_path TO public;
-- test for get_query_string
INSERT INTO hint_plan.hints VALUES(DEFAULT,'EXPLAIN SELECT * FROM t1 WHERE id = ?;', '', 'SeqScan(t1)');
INSERT INTO hint_plan.hints VALUES(DEFAULT,'EXPLAIN (COSTS false) SELECT * FROM t1 WHERE id = ?;', '', 'SeqScan(t1)');
INSERT INTO hint_plan.hints VALUES(DEFAULT,'PREPARE p1 AS SELECT * FROM t1 WHERE id = ?;', '', 'SeqScan(t1)');
INSERT INTO hint_plan.hints VALUES(DEFAULT,'EXPLAIN DECLARE c1 CURSOR FOR SELECT * FROM t1 WHERE id = ?;', '', 'SeqScan(t1)');
INSERT INTO hint_plan.hints VALUES(DEFAULT,'EXPLAIN CREATE TABLE ct1 AS SELECT * FROM t1 WHERE id = ?;', '', 'SeqScan(t1)');
INSERT INTO hint_plan.hints VALUES(DEFAULT,'EXPLAIN (COSTS false) DECLARE c1 CURSOR FOR SELECT * FROM t1 WHERE id = ?;', '', 'SeqScan(t1)');
INSERT INTO hint_plan.hints VALUES(DEFAULT,'EXPLAIN (COSTS false) CREATE TABLE ct1 AS SELECT * FROM t1 WHERE id = ?;', '', 'SeqScan(t1)');
PREPARE p1 AS SELECT * FROM t1 WHERE id = 100;
-- These queries uses IndexScan without hints
SET pg_hint_plan.enable_hint_table to off;
EXPLAIN SELECT * FROM t1 WHERE id = 100;
QUERY PLAN
------------------------------------------------------------------
Index Scan using t1_pkey on t1 (cost=0.29..8.30 rows=1 width=8)
EXPLAIN (COSTS false) SELECT * FROM t1 WHERE id = 100;
QUERY PLAN
--------------------------------
Index Scan using t1_pkey on t1
Index Cond: (id = 100)
(2 rows)

EXPLAIN DECLARE c1 CURSOR FOR SELECT * FROM t1 WHERE id = 100;
QUERY PLAN
------------------------------------------------------------------
Index Scan using t1_pkey on t1 (cost=0.29..8.30 rows=1 width=8)
EXPLAIN (COSTS false) DECLARE c1 CURSOR FOR SELECT * FROM t1 WHERE id = 100;
QUERY PLAN
--------------------------------
Index Scan using t1_pkey on t1
Index Cond: (id = 100)
(2 rows)

EXPLAIN CREATE TABLE ct1 AS SELECT * FROM t1 WHERE id = 100;
QUERY PLAN
------------------------------------------------------------------
Index Scan using t1_pkey on t1 (cost=0.29..8.30 rows=1 width=8)
EXPLAIN (COSTS false) CREATE TABLE ct1 AS SELECT * FROM t1 WHERE id = 100;
QUERY PLAN
--------------------------------
Index Scan using t1_pkey on t1
Index Cond: (id = 100)
(2 rows)

EXPLAIN EXECUTE p1;
QUERY PLAN
------------------------------------------------------------------
Index Scan using t1_pkey on t1 (cost=0.29..8.30 rows=1 width=8)
EXPLAIN (COSTS false) EXECUTE p1;
QUERY PLAN
--------------------------------
Index Scan using t1_pkey on t1
Index Cond: (id = 100)
(2 rows)

DEALLOCATE p1;
PREPARE p1 AS SELECT * FROM t1 WHERE id = 100;
EXPLAIN CREATE TABLE ct1 AS EXECUTE p1;
QUERY PLAN
------------------------------------------------------------------
Index Scan using t1_pkey on t1 (cost=0.29..8.30 rows=1 width=8)
EXPLAIN (COSTS false) CREATE TABLE ct1 AS EXECUTE p1;
QUERY PLAN
--------------------------------
Index Scan using t1_pkey on t1
Index Cond: (id = 100)
(2 rows)

DEALLOCATE p1;
PREPARE p1 AS SELECT * FROM t1 WHERE id = 100;
-- Forced to use SeqScan by table hints
SET pg_hint_plan.enable_hint_table to on;
EXPLAIN SELECT * FROM t1 WHERE id = 100;
EXPLAIN (COSTS false) SELECT * FROM t1 WHERE id = 100;
LOG: pg_hint_plan:
used hint:
SeqScan(t1)
not used hint:
duplication hint:
error hint:

QUERY PLAN
----------------------------------------------------
Seq Scan on t1 (cost=0.00..170.00 rows=1 width=8)
QUERY PLAN
----------------------
Seq Scan on t1
Filter: (id = 100)
(2 rows)

EXPLAIN DECLARE c1 CURSOR FOR SELECT * FROM t1 WHERE id = 100;
EXPLAIN (COSTS false) DECLARE c1 CURSOR FOR SELECT * FROM t1 WHERE id = 100;
LOG: pg_hint_plan:
used hint:
SeqScan(t1)
not used hint:
duplication hint:
error hint:

QUERY PLAN
----------------------------------------------------
Seq Scan on t1 (cost=0.00..170.00 rows=1 width=8)
QUERY PLAN
----------------------
Seq Scan on t1
Filter: (id = 100)
(2 rows)

EXPLAIN CREATE TABLE ct1 AS SELECT * FROM t1 WHERE id = 100;
EXPLAIN (COSTS false) CREATE TABLE ct1 AS SELECT * FROM t1 WHERE id = 100;
LOG: pg_hint_plan:
used hint:
SeqScan(t1)
not used hint:
duplication hint:
error hint:

QUERY PLAN
----------------------------------------------------
Seq Scan on t1 (cost=0.00..170.00 rows=1 width=8)
QUERY PLAN
----------------------
Seq Scan on t1
Filter: (id = 100)
(2 rows)

EXPLAIN EXECUTE p1;
EXPLAIN (COSTS false) EXECUTE p1;
LOG: pg_hint_plan:
used hint:
SeqScan(t1)
not used hint:
duplication hint:
error hint:

QUERY PLAN
----------------------------------------------------
Seq Scan on t1 (cost=0.00..170.00 rows=1 width=8)
QUERY PLAN
----------------------
Seq Scan on t1
Filter: (id = 100)
(2 rows)

DEALLOCATE p1;
PREPARE p1 AS SELECT * FROM t1 WHERE id = 100;
EXPLAIN CREATE TABLE ct1 AS EXECUTE p1;
EXPLAIN (COSTS false) CREATE TABLE ct1 AS EXECUTE p1;
LOG: pg_hint_plan:
used hint:
SeqScan(t1)
not used hint:
duplication hint:
error hint:

QUERY PLAN
----------------------------------------------------
Seq Scan on t1 (cost=0.00..170.00 rows=1 width=8)
QUERY PLAN
----------------------
Seq Scan on t1
Filter: (id = 100)
(2 rows)

Expand Down
14 changes: 7 additions & 7 deletions sql/ut-A.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1241,16 +1241,16 @@ CREATE INDEX ON s1.tpc(a);
PREPARE p1 AS SELECT * FROM s1.tpc WHERE a < 999;
/*+ IndexScan(tpc) */PREPARE p2 AS SELECT * FROM s1.tpc WHERE a < 999;
/*+ SeqScan(tpc) */PREPARE p3(int) AS SELECT * FROM s1.tpc WHERE a = $1;
EXPLAIN EXECUTE p1;
EXPLAIN EXECUTE p2;
EXPLAIN EXECUTE p3(500);
EXPLAIN (COSTS false) EXECUTE p1;
EXPLAIN (COSTS false) EXECUTE p2;
EXPLAIN (COSTS false) EXECUTE p3(500);
-- The DROP invalidates the plan caches
DROP TABLE s1.tpc;
CREATE TABLE s1.tpc AS SELECT a FROM generate_series(0, 999) a;
CREATE INDEX ON s1.tpc(a);
EXPLAIN EXECUTE p1;
EXPLAIN EXECUTE p2;
EXPLAIN EXECUTE p3(500);
EXPLAIN (COSTS false) EXECUTE p1;
EXPLAIN (COSTS false) EXECUTE p2;
EXPLAIN (COSTS false) EXECUTE p3(500);
DEALLOCATE p1;
DEALLOCATE p2;
DEALLOCATE p3;
Expand All @@ -1262,4 +1262,4 @@ PREPARE test_query(numeric[]) AS
(SELECT 1 AS x)
SELECT t1.* FROM test t1, test t2
WHERE t1.x = ANY($1) AND t1.x = t2.x;
EXPLAIN EXECUTE test_query(array[1,2,3]);
EXPLAIN (COSTS false) EXECUTE test_query(array[1,2,3]);
27 changes: 13 additions & 14 deletions sql/ut-T.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,35 @@ SET client_min_messages TO LOG;
SET search_path TO public;

-- test for get_query_string
INSERT INTO hint_plan.hints VALUES(DEFAULT,'EXPLAIN SELECT * FROM t1 WHERE id = ?;', '', 'SeqScan(t1)');
INSERT INTO hint_plan.hints VALUES(DEFAULT,'EXPLAIN (COSTS false) SELECT * FROM t1 WHERE id = ?;', '', 'SeqScan(t1)');
INSERT INTO hint_plan.hints VALUES(DEFAULT,'PREPARE p1 AS SELECT * FROM t1 WHERE id = ?;', '', 'SeqScan(t1)');
INSERT INTO hint_plan.hints VALUES(DEFAULT,'EXPLAIN DECLARE c1 CURSOR FOR SELECT * FROM t1 WHERE id = ?;', '', 'SeqScan(t1)');
INSERT INTO hint_plan.hints VALUES(DEFAULT,'EXPLAIN CREATE TABLE ct1 AS SELECT * FROM t1 WHERE id = ?;', '', 'SeqScan(t1)');
INSERT INTO hint_plan.hints VALUES(DEFAULT,'EXPLAIN (COSTS false) DECLARE c1 CURSOR FOR SELECT * FROM t1 WHERE id = ?;', '', 'SeqScan(t1)');
INSERT INTO hint_plan.hints VALUES(DEFAULT,'EXPLAIN (COSTS false) CREATE TABLE ct1 AS SELECT * FROM t1 WHERE id = ?;', '', 'SeqScan(t1)');

PREPARE p1 AS SELECT * FROM t1 WHERE id = 100;

-- These queries uses IndexScan without hints
SET pg_hint_plan.enable_hint_table to off;
EXPLAIN SELECT * FROM t1 WHERE id = 100;
EXPLAIN DECLARE c1 CURSOR FOR SELECT * FROM t1 WHERE id = 100;
EXPLAIN CREATE TABLE ct1 AS SELECT * FROM t1 WHERE id = 100;

EXPLAIN EXECUTE p1;
EXPLAIN (COSTS false) SELECT * FROM t1 WHERE id = 100;
EXPLAIN (COSTS false) DECLARE c1 CURSOR FOR SELECT * FROM t1 WHERE id = 100;
EXPLAIN (COSTS false) CREATE TABLE ct1 AS SELECT * FROM t1 WHERE id = 100;
EXPLAIN (COSTS false) EXECUTE p1;
DEALLOCATE p1;
PREPARE p1 AS SELECT * FROM t1 WHERE id = 100;
EXPLAIN CREATE TABLE ct1 AS EXECUTE p1;
EXPLAIN (COSTS false) CREATE TABLE ct1 AS EXECUTE p1;

DEALLOCATE p1;
PREPARE p1 AS SELECT * FROM t1 WHERE id = 100;

-- Forced to use SeqScan by table hints
SET pg_hint_plan.enable_hint_table to on;
EXPLAIN SELECT * FROM t1 WHERE id = 100;
EXPLAIN DECLARE c1 CURSOR FOR SELECT * FROM t1 WHERE id = 100;
EXPLAIN CREATE TABLE ct1 AS SELECT * FROM t1 WHERE id = 100;
EXPLAIN EXECUTE p1;
EXPLAIN (COSTS false) SELECT * FROM t1 WHERE id = 100;
EXPLAIN (COSTS false) DECLARE c1 CURSOR FOR SELECT * FROM t1 WHERE id = 100;
EXPLAIN (COSTS false) CREATE TABLE ct1 AS SELECT * FROM t1 WHERE id = 100;
EXPLAIN (COSTS false) EXECUTE p1;
DEALLOCATE p1;
PREPARE p1 AS SELECT * FROM t1 WHERE id = 100;
EXPLAIN CREATE TABLE ct1 AS EXECUTE p1;
EXPLAIN (COSTS false) CREATE TABLE ct1 AS EXECUTE p1;

DEALLOCATE p1;

Expand Down

0 comments on commit ffd7f62

Please sign in to comment.