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 #148.

Author: Masahiro Ikeda
Backpatch-through: 11
  • Loading branch information
michaelpq committed Aug 29, 2023
1 parent 05300ab commit e309950
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 87 deletions.
48 changes: 24 additions & 24 deletions expected/ut-A.out
Original file line number Diff line number Diff line change
Expand Up @@ -4744,77 +4744,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 Down
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
12 changes: 6 additions & 6 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 Down
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 e309950

Please sign in to comment.