|
| 1 | +-- |
| 2 | +-- Verify that index scans encountering dead rows produced by an |
| 3 | +-- aborted subtransaction of the current transaction can utilize the |
| 4 | +-- kill_prio_tuple optimization |
| 5 | +-- |
| 6 | +-- NB: The table size is currently *not* expected to stay the same, we |
| 7 | +-- don't have logic to trigger opportunistic pruning in cases like |
| 8 | +-- this. |
| 9 | +BEGIN; |
| 10 | +SET LOCAL enable_seqscan = false; |
| 11 | +SET LOCAL enable_indexonlyscan = false; |
| 12 | +SET LOCAL enable_bitmapscan = false; |
| 13 | +-- Can't easily use a unique index, since dead tuples can be found |
| 14 | +-- independent of the kill_prior_tuples optimization. |
| 15 | +CREATE TABLE clean_aborted_self(key int, data text); |
| 16 | +CREATE INDEX clean_aborted_self_key ON clean_aborted_self(key); |
| 17 | +INSERT INTO clean_aborted_self (key, data) VALUES (-1, 'just to allocate metapage'); |
| 18 | +-- save index size from before the changes, for comparison |
| 19 | +SELECT pg_relation_size('clean_aborted_self_key') AS clean_aborted_self_key_before \gset |
| 20 | +DO $$ |
| 21 | +BEGIN |
| 22 | + -- iterate often enough to see index growth even on larger-than-default page sizes |
| 23 | + FOR i IN 1..100 LOOP |
| 24 | + BEGIN |
| 25 | + -- perform index scan over all the inserted keys to get them to be seen as dead |
| 26 | + IF EXISTS(SELECT * FROM clean_aborted_self WHERE key > 0 AND key < 100) THEN |
| 27 | + RAISE data_corrupted USING MESSAGE = 'these rows should not exist'; |
| 28 | + END IF; |
| 29 | + INSERT INTO clean_aborted_self SELECT g.i, 'rolling back in a sec' FROM generate_series(1, 100) g(i); |
| 30 | + -- just some error that's not normally thrown |
| 31 | + RAISE reading_sql_data_not_permitted USING MESSAGE = 'round and round again'; |
| 32 | + EXCEPTION WHEN reading_sql_data_not_permitted THEN END; |
| 33 | + END LOOP; |
| 34 | +END;$$; |
| 35 | +-- show sizes only if they differ |
| 36 | +SELECT :clean_aborted_self_key_before AS size_before, pg_relation_size('clean_aborted_self_key') size_after |
| 37 | +WHERE :clean_aborted_self_key_before != pg_relation_size('clean_aborted_self_key'); |
| 38 | + size_before | size_after |
| 39 | +-------------+------------ |
| 40 | +(0 rows) |
| 41 | + |
| 42 | +ROLLBACK; |
0 commit comments