From ffd7f628bd50e241dc26c0e4c8bc42b8c9778ac5 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Tue, 29 Aug 2023 10:46:21 +0900 Subject: [PATCH] Add EXPLAIN (COSTS false) to some tests 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 --- expected/ut-A.out | 62 +++++++++++++++++----------------- expected/ut-T.out | 86 +++++++++++++++++++++++------------------------ sql/ut-A.sql | 14 ++++---- sql/ut-T.sql | 27 +++++++-------- 4 files changed, 94 insertions(+), 95 deletions(-) diff --git a/expected/ut-A.out b/expected/ut-A.out index 461426db..ee9e67fe 100644 --- a/expected/ut-A.out +++ b/expected/ut-A.out @@ -4772,14 +4772,14 @@ 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) @@ -4787,13 +4787,13 @@ 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) @@ -4801,9 +4801,9 @@ 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) @@ -4811,14 +4811,14 @@ error hint: 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) @@ -4826,13 +4826,13 @@ 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) @@ -4840,9 +4840,9 @@ 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) @@ -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) @@ -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) diff --git a/expected/ut-T.out b/expected/ut-T.out index 8b5f5658..d74ba804 100644 --- a/expected/ut-T.out +++ b/expected/ut-T.out @@ -6,47 +6,47 @@ 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) @@ -54,7 +54,7 @@ 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) @@ -62,13 +62,13 @@ 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) @@ -76,13 +76,13 @@ 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) @@ -90,13 +90,13 @@ 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) @@ -104,15 +104,15 @@ 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) @@ -120,9 +120,9 @@ 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) diff --git a/sql/ut-A.sql b/sql/ut-A.sql index 7e30e5e6..7c7d58a2 100644 --- a/sql/ut-A.sql +++ b/sql/ut-A.sql @@ -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; @@ -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]); diff --git a/sql/ut-T.sql b/sql/ut-T.sql index 48a0be3d..aa345ab5 100644 --- a/sql/ut-T.sql +++ b/sql/ut-T.sql @@ -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;