Re-adjust drop-index-concurrently-1 isolation test

It seems that drop-index-concurrently-1 has started to forget what it was
originally meant to be testing.  d2d8a229b, which added incremental sorts
changed the expected plan to be an Index Scan plan instead of a Seq Scan
plan.  This occurred as the primary key index of the table in question
provided presorted input and, because that index happened to be the
cheapest input path due to enable_seqscan being disabled, the incremental
sort changes just added a Sort on top of that.  It seems based on the name
of the PREPAREd statement that the intention here is that the query
produces a seqscan plan.

The reason this test has become broken seems to be due to how the test was
originally coded.  The test was trying to force a seqscan plan by
performing some casting to make it so the test_dc index couldn't be used
to perform the required filtering.  Trying to coax the planner into using
a plan which has costed in a disable_cost seems like it's always going to
be flakey as small changes in costs are drowned out by the large
disable_cost combined with add_path's STD_FUZZ_FACTOR.  Here we get rid of
the casts that we're using to try to trick the planner into a seqscan and
instead toggle enable_seqscan as and when required to get the desired
plan.

Additionally, rename a few things in the test and add some additional
wording to the comments to try and make it more clear in the future what
we expect this test to be doing.

Discussion: https://postgr.es/m/CAApHDvrbDhObhLV+=U_K_-t+2Av2av1aL9d+2j_3AO-XndaviA@mail.gmail.com
Backpatch-through: 13, where d2d8a229b changed the expected test output
This commit is contained in:
David Rowley 2022-12-16 11:39:40 +13:00
parent ac99802080
commit 8b6b043cee
3 changed files with 44 additions and 40 deletions

View File

@ -1,17 +1,17 @@
Parsed test spec with 3 sessions Parsed test spec with 3 sessions
starting permutation: noseq chkiso prepi preps begin explaini explains select2 drop insert2 end2 selecti selects end starting permutation: chkiso prepi preps begin disableseq explaini enableseq explains select2 drop insert2 end2 selecti selects end
step noseq: SET enable_seqscan = false;
step chkiso: SELECT (setting in ('read committed','read uncommitted')) AS is_read_committed FROM pg_settings WHERE name = 'default_transaction_isolation'; step chkiso: SELECT (setting in ('read committed','read uncommitted')) AS is_read_committed FROM pg_settings WHERE name = 'default_transaction_isolation';
is_read_committed is_read_committed
----------------- -----------------
t t
(1 row) (1 row)
step prepi: PREPARE getrow_idx AS SELECT * FROM test_dc WHERE data=34 ORDER BY id,data; step prepi: PREPARE getrow_idxscan AS SELECT * FROM test_dc WHERE data = 34 ORDER BY id,data;
step preps: PREPARE getrow_seq AS SELECT * FROM test_dc WHERE data::text=34::text ORDER BY id,data; step preps: PREPARE getrow_seqscan AS SELECT * FROM test_dc WHERE data = 34 ORDER BY id,data;
step begin: BEGIN; step begin: BEGIN;
step explaini: EXPLAIN (COSTS OFF) EXECUTE getrow_idx; step disableseq: SET enable_seqscan = false;
step explaini: EXPLAIN (COSTS OFF) EXECUTE getrow_idxscan;
QUERY PLAN QUERY PLAN
---------------------------------------------- ----------------------------------------------
Sort Sort
@ -20,16 +20,17 @@ Sort
Index Cond: (data = 34) Index Cond: (data = 34)
(4 rows) (4 rows)
step explains: EXPLAIN (COSTS OFF) EXECUTE getrow_seq; step enableseq: SET enable_seqscan = true;
QUERY PLAN step explains: EXPLAIN (COSTS OFF) EXECUTE getrow_seqscan;
---------------------------------------------- QUERY PLAN
Sort ---------------------------
Sort Key: id, data Sort
-> Index Scan using test_dc_pkey on test_dc Sort Key: id
Filter: ((data)::text = '34'::text) -> Seq Scan on test_dc
Filter: (data = 34)
(4 rows) (4 rows)
step select2: SELECT * FROM test_dc WHERE data=34 ORDER BY id,data; step select2: SELECT * FROM test_dc WHERE data = 34 ORDER BY id,data;
id|data id|data
--+---- --+----
34| 34 34| 34
@ -38,14 +39,14 @@ id|data
step drop: DROP INDEX CONCURRENTLY test_dc_data; <waiting ...> step drop: DROP INDEX CONCURRENTLY test_dc_data; <waiting ...>
step insert2: INSERT INTO test_dc(data) SELECT * FROM generate_series(1, 100); step insert2: INSERT INTO test_dc(data) SELECT * FROM generate_series(1, 100);
step end2: COMMIT; step end2: COMMIT;
step selecti: EXECUTE getrow_idx; step selecti: EXECUTE getrow_idxscan;
id|data id|data
---+---- ---+----
34| 34 34| 34
134| 34 134| 34
(2 rows) (2 rows)
step selects: EXECUTE getrow_seq; step selects: EXECUTE getrow_seqscan;
id|data id|data
---+---- ---+----
34| 34 34| 34

View File

@ -1,17 +1,17 @@
Parsed test spec with 3 sessions Parsed test spec with 3 sessions
starting permutation: noseq chkiso prepi preps begin explaini explains select2 drop insert2 end2 selecti selects end starting permutation: chkiso prepi preps begin disableseq explaini enableseq explains select2 drop insert2 end2 selecti selects end
step noseq: SET enable_seqscan = false;
step chkiso: SELECT (setting in ('read committed','read uncommitted')) AS is_read_committed FROM pg_settings WHERE name = 'default_transaction_isolation'; step chkiso: SELECT (setting in ('read committed','read uncommitted')) AS is_read_committed FROM pg_settings WHERE name = 'default_transaction_isolation';
is_read_committed is_read_committed
----------------- -----------------
f f
(1 row) (1 row)
step prepi: PREPARE getrow_idx AS SELECT * FROM test_dc WHERE data=34 ORDER BY id,data; step prepi: PREPARE getrow_idxscan AS SELECT * FROM test_dc WHERE data = 34 ORDER BY id,data;
step preps: PREPARE getrow_seq AS SELECT * FROM test_dc WHERE data::text=34::text ORDER BY id,data; step preps: PREPARE getrow_seqscan AS SELECT * FROM test_dc WHERE data = 34 ORDER BY id,data;
step begin: BEGIN; step begin: BEGIN;
step explaini: EXPLAIN (COSTS OFF) EXECUTE getrow_idx; step disableseq: SET enable_seqscan = false;
step explaini: EXPLAIN (COSTS OFF) EXECUTE getrow_idxscan;
QUERY PLAN QUERY PLAN
---------------------------------------------- ----------------------------------------------
Sort Sort
@ -20,16 +20,17 @@ Sort
Index Cond: (data = 34) Index Cond: (data = 34)
(4 rows) (4 rows)
step explains: EXPLAIN (COSTS OFF) EXECUTE getrow_seq; step enableseq: SET enable_seqscan = true;
QUERY PLAN step explains: EXPLAIN (COSTS OFF) EXECUTE getrow_seqscan;
---------------------------------------------- QUERY PLAN
Sort ---------------------------
Sort Key: id, data Sort
-> Index Scan using test_dc_pkey on test_dc Sort Key: id
Filter: ((data)::text = '34'::text) -> Seq Scan on test_dc
Filter: (data = 34)
(4 rows) (4 rows)
step select2: SELECT * FROM test_dc WHERE data=34 ORDER BY id,data; step select2: SELECT * FROM test_dc WHERE data = 34 ORDER BY id,data;
id|data id|data
--+---- --+----
34| 34 34| 34
@ -38,13 +39,13 @@ id|data
step drop: DROP INDEX CONCURRENTLY test_dc_data; <waiting ...> step drop: DROP INDEX CONCURRENTLY test_dc_data; <waiting ...>
step insert2: INSERT INTO test_dc(data) SELECT * FROM generate_series(1, 100); step insert2: INSERT INTO test_dc(data) SELECT * FROM generate_series(1, 100);
step end2: COMMIT; step end2: COMMIT;
step selecti: EXECUTE getrow_idx; step selecti: EXECUTE getrow_idxscan;
id|data id|data
--+---- --+----
34| 34 34| 34
(1 row) (1 row)
step selects: EXECUTE getrow_seq; step selects: EXECUTE getrow_seqscan;
id|data id|data
--+---- --+----
34| 34 34| 34

View File

@ -3,7 +3,8 @@
# This test shows that the concurrent write behaviour works correctly # This test shows that the concurrent write behaviour works correctly
# with the expected output being 2 rows at the READ COMMITTED and READ # with the expected output being 2 rows at the READ COMMITTED and READ
# UNCOMMITTED transaction isolation levels, and 1 row at the other # UNCOMMITTED transaction isolation levels, and 1 row at the other
# transaction isolation levels. # transaction isolation levels. We ensure this is the case by checking
# the returned rows in an index scan plan and a seq scan plan.
# #
setup setup
{ {
@ -18,24 +19,25 @@ teardown
} }
session s1 session s1
step noseq { SET enable_seqscan = false; }
step chkiso { SELECT (setting in ('read committed','read uncommitted')) AS is_read_committed FROM pg_settings WHERE name = 'default_transaction_isolation'; } step chkiso { SELECT (setting in ('read committed','read uncommitted')) AS is_read_committed FROM pg_settings WHERE name = 'default_transaction_isolation'; }
step prepi { PREPARE getrow_idx AS SELECT * FROM test_dc WHERE data=34 ORDER BY id,data; } step prepi { PREPARE getrow_idxscan AS SELECT * FROM test_dc WHERE data = 34 ORDER BY id,data; }
step preps { PREPARE getrow_seq AS SELECT * FROM test_dc WHERE data::text=34::text ORDER BY id,data; } step preps { PREPARE getrow_seqscan AS SELECT * FROM test_dc WHERE data = 34 ORDER BY id,data; }
step begin { BEGIN; } step begin { BEGIN; }
step explaini { EXPLAIN (COSTS OFF) EXECUTE getrow_idx; } step disableseq { SET enable_seqscan = false; }
step explains { EXPLAIN (COSTS OFF) EXECUTE getrow_seq; } step explaini { EXPLAIN (COSTS OFF) EXECUTE getrow_idxscan; }
step selecti { EXECUTE getrow_idx; } step enableseq { SET enable_seqscan = true; }
step selects { EXECUTE getrow_seq; } step explains { EXPLAIN (COSTS OFF) EXECUTE getrow_seqscan; }
step selecti { EXECUTE getrow_idxscan; }
step selects { EXECUTE getrow_seqscan; }
step end { COMMIT; } step end { COMMIT; }
session s2 session s2
setup { BEGIN; } setup { BEGIN; }
step select2 { SELECT * FROM test_dc WHERE data=34 ORDER BY id,data; } step select2 { SELECT * FROM test_dc WHERE data = 34 ORDER BY id,data; }
step insert2 { INSERT INTO test_dc(data) SELECT * FROM generate_series(1, 100); } step insert2 { INSERT INTO test_dc(data) SELECT * FROM generate_series(1, 100); }
step end2 { COMMIT; } step end2 { COMMIT; }
session s3 session s3
step drop { DROP INDEX CONCURRENTLY test_dc_data; } step drop { DROP INDEX CONCURRENTLY test_dc_data; }
permutation noseq chkiso prepi preps begin explaini explains select2 drop insert2 end2 selecti selects end permutation chkiso prepi preps begin disableseq explaini enableseq explains select2 drop insert2 end2 selecti selects end