From d937987683b6aedd7e8086a7c797ed0800fc1852 Mon Sep 17 00:00:00 2001 From: Alexandre Felipe Date: Wed, 16 Sep 2026 20:18:05 +0100 Subject: [PATCH-v3 3/4] establish expectations wrap up with the regress reference and disable debugging --- src/test/regress/expected/tablespace_xact.out | 482 +++++++++++++++++- src/test/regress/sql/tablespace_xact.sql | 4 +- 2 files changed, 482 insertions(+), 4 deletions(-) diff --git a/src/test/regress/expected/tablespace_xact.out b/src/test/regress/expected/tablespace_xact.out index 85d3d35f332..22338f9ec32 100644 --- a/src/test/regress/expected/tablespace_xact.out +++ b/src/test/regress/expected/tablespace_xact.out @@ -1 +1,481 @@ --- place holder -- \ No newline at end of file +-- +-- Deferred heap copy for ALTER TABLE SET TABLESPACE on indexed tables +-- +SET allow_in_place_tablespaces = true; +SET enable_seqscan = off; +SET enable_bitmapscan = off; +CREATE SCHEMA tablespace_xact; +SET search_path TO tablespace_xact; +CREATE TABLESPACE xact_tblspace LOCATION ''; +CREATE TABLESPACE xact_tblspace2 LOCATION ''; +PREPARE check_tablespace AS + SELECT c.relname, coalesce(s.spcname, '(default)') AS tablespace + FROM pg_class c + LEFT JOIN pg_tablespace s ON s.oid = c.reltablespace + LEFT JOIN pg_namespace n ON n.oid = c.relnamespace + WHERE n.nspname = 'tablespace_xact' + ORDER BY 1; +-- COMMIT +CREATE TABLE defer_t (a int); +EXECUTE check_tablespace; + relname | tablespace +---------+------------ + defer_t | (default) +(1 row) + +CREATE INDEX defer_t_idx ON defer_t (a); +INSERT INTO defer_t VALUES (1); +BEGIN; +INSERT INTO defer_t VALUES (2); +ALTER TABLE defer_t SET TABLESPACE xact_tblspace; +INSERT INTO defer_t VALUES (3); +COMMIT; +EXECUTE check_tablespace; + relname | tablespace +-------------+--------------- + defer_t | xact_tblspace + defer_t_idx | (default) +(2 rows) + +INSERT INTO defer_t VALUES (4), (5); +SELECT ctid, a FROM defer_t ORDER BY a; + ctid | a +-------+--- + (0,1) | 1 + (0,2) | 2 + (0,3) | 3 + (0,4) | 4 + (0,5) | 5 +(5 rows) + +DROP TABLE defer_t; +-- ROLLBACK +CREATE TABLE defer_t (a int); +CREATE INDEX defer_t_idx ON defer_t (a); +INSERT INTO defer_t VALUES (1); +BEGIN; +INSERT INTO defer_t VALUES (2); +ALTER TABLE defer_t SET TABLESPACE xact_tblspace; +INSERT INTO defer_t VALUES (3); +ROLLBACK; +EXECUTE check_tablespace; + relname | tablespace +-------------+------------ + defer_t | (default) + defer_t_idx | (default) +(2 rows) + +INSERT INTO defer_t VALUES (4), (5); +SELECT ctid, a FROM defer_t ORDER BY a; + ctid | a +-------+--- + (0,1) | 1 + (0,4) | 4 + (0,5) | 5 +(3 rows) + +DROP TABLE defer_t; +-- COMMIT ENDING UP IN THE SAME SPACE +CREATE TABLE defer_t (a int); +CREATE INDEX defer_t_idx ON defer_t (a); +INSERT INTO defer_t VALUES (1); +BEGIN; +INSERT INTO defer_t VALUES (2); +ALTER TABLE defer_t SET TABLESPACE xact_tblspace; +INSERT INTO defer_t VALUES (3); +ALTER TABLE defer_t SET TABLESPACE pg_default; +INSERT INTO defer_t VALUES (4); +COMMIT; +EXECUTE check_tablespace; + relname | tablespace +-------------+------------ + defer_t | (default) + defer_t_idx | (default) +(2 rows) + +INSERT INTO defer_t VALUES (5); +SELECT ctid, a FROM defer_t ORDER BY a; + ctid | a +-------+--- + (0,1) | 1 + (0,2) | 2 + (0,3) | 3 + (0,4) | 4 + (0,5) | 5 +(5 rows) + +DROP TABLE defer_t; +-- PREPARE TRANSACTION, COMMIT PREPARED +CREATE TABLE defer_t (a int); +CREATE INDEX defer_t_idx ON defer_t (a); +INSERT INTO defer_t VALUES (1); +BEGIN; +INSERT INTO defer_t VALUES (2); +ALTER TABLE defer_t SET TABLESPACE xact_tblspace; +INSERT INTO defer_t VALUES (3); +PREPARE TRANSACTION 'defer_tblsp_prep_commit'; +COMMIT PREPARED 'defer_tblsp_prep_commit'; +EXECUTE check_tablespace; + relname | tablespace +-------------+--------------- + defer_t | xact_tblspace + defer_t_idx | (default) +(2 rows) + +INSERT INTO defer_t VALUES (4), (5); +SELECT ctid, a FROM defer_t ORDER BY a; + ctid | a +-------+--- + (0,1) | 1 + (0,2) | 2 + (0,3) | 3 + (0,4) | 4 + (0,5) | 5 +(5 rows) + +DROP TABLE defer_t; +-- PREPARE TRANSACTION, ROLLBACK PREPARED +CREATE TABLE defer_t (a int); +CREATE INDEX defer_t_idx ON defer_t (a); +INSERT INTO defer_t VALUES (1); +BEGIN; +INSERT INTO defer_t VALUES (2); +ALTER TABLE defer_t SET TABLESPACE xact_tblspace2; +INSERT INTO defer_t VALUES (3); +PREPARE TRANSACTION 'defer_tblsp_prep_rollback'; +ROLLBACK PREPARED 'defer_tblsp_prep_rollback'; +EXECUTE check_tablespace; + relname | tablespace +-------------+------------ + defer_t | (default) + defer_t_idx | (default) +(2 rows) + +INSERT INTO defer_t VALUES (4), (5); +SELECT ctid, a FROM defer_t ORDER BY a; + ctid | a +-------+--- + (0,1) | 1 + (0,4) | 4 + (0,5) | 5 +(3 rows) + +DROP TABLE defer_t; +-- Subtransaction: move in savepoint, subcommit, then top-level commit +CREATE TABLE defer_t (a int); +CREATE INDEX defer_t_idx ON defer_t (a); +INSERT INTO defer_t VALUES (1); +BEGIN; +INSERT INTO defer_t VALUES (2); +SAVEPOINT sp1; +INSERT INTO defer_t VALUES (3); +ALTER TABLE defer_t SET TABLESPACE xact_tblspace; +INSERT INTO defer_t VALUES (4); +RELEASE SAVEPOINT sp1; +INSERT INTO defer_t VALUES (5); +COMMIT; +EXECUTE check_tablespace; + relname | tablespace +-------------+--------------- + defer_t | xact_tblspace + defer_t_idx | (default) +(2 rows) + +INSERT INTO defer_t VALUES (6), (7); +SELECT ctid, a FROM defer_t ORDER BY a; + ctid | a +-------+--- + (0,1) | 1 + (0,2) | 2 + (0,3) | 3 + (0,4) | 4 + (0,5) | 5 + (0,6) | 6 + (0,7) | 7 +(7 rows) + +DROP TABLE defer_t; +-- Subtransaction: move in savepoint, then rollback to savepoint +CREATE TABLE defer_t (a int); +CREATE INDEX defer_t_idx ON defer_t (a); +INSERT INTO defer_t VALUES (1); +BEGIN; +INSERT INTO defer_t VALUES (2); +SAVEPOINT sp1; +INSERT INTO defer_t VALUES (3); +ALTER TABLE defer_t SET TABLESPACE xact_tblspace; +INSERT INTO defer_t VALUES (4); +ROLLBACK TO SAVEPOINT sp1; +INSERT INTO defer_t VALUES (5); +COMMIT; +EXECUTE check_tablespace; + relname | tablespace +-------------+------------ + defer_t | (default) + defer_t_idx | (default) +(2 rows) + +INSERT INTO defer_t VALUES (6), (7), (8); +SELECT ctid, a FROM defer_t ORDER BY a; + ctid | a +-------+--- + (0,1) | 1 + (0,2) | 2 + (0,5) | 5 + (0,6) | 6 + (0,7) | 7 + (0,8) | 8 +(6 rows) + +DROP TABLE defer_t; +-- Subtransaction: subcommit move, then top-level rollback cancels move +CREATE TABLE defer_t (a int); +CREATE INDEX defer_t_idx ON defer_t (a); +INSERT INTO defer_t VALUES (1); +BEGIN; +INSERT INTO defer_t VALUES (2); +SAVEPOINT sp1; +INSERT INTO defer_t VALUES (3); +ALTER TABLE defer_t SET TABLESPACE xact_tblspace; +INSERT INTO defer_t VALUES (4); +RELEASE SAVEPOINT sp1; +INSERT INTO defer_t VALUES (5); +ROLLBACK; +EXECUTE check_tablespace; + relname | tablespace +-------------+------------ + defer_t | (default) + defer_t_idx | (default) +(2 rows) + +INSERT INTO defer_t VALUES (6), (7), (8); +SELECT ctid, a FROM defer_t ORDER BY a; + ctid | a +-------+--- + (0,1) | 1 + (0,6) | 6 + (0,7) | 7 + (0,8) | 8 +(4 rows) + +DROP TABLE defer_t; +-- Subtransaction: two deferred moves in one transaction +CREATE TABLE defer_t (a int); +CREATE INDEX defer_t_idx ON defer_t (a); +INSERT INTO defer_t VALUES (1); +BEGIN; +INSERT INTO defer_t VALUES (2); +SAVEPOINT sp1; +INSERT INTO defer_t VALUES (3); +ALTER TABLE defer_t SET TABLESPACE xact_tblspace; +INSERT INTO defer_t VALUES (4); +SAVEPOINT sp2; +INSERT INTO defer_t VALUES (5); +ALTER TABLE defer_t SET TABLESPACE xact_tblspace2; +INSERT INTO defer_t VALUES (6); +COMMIT; +EXECUTE check_tablespace; + relname | tablespace +-------------+---------------- + defer_t | xact_tblspace2 + defer_t_idx | (default) +(2 rows) + +INSERT INTO defer_t VALUES (7), (8), (9); +SELECT ctid, a FROM defer_t ORDER BY a; + ctid | a +-------+--- + (0,1) | 1 + (0,2) | 2 + (0,3) | 3 + (0,4) | 4 + (0,5) | 5 + (0,6) | 6 + (0,7) | 7 + (0,8) | 8 + (0,9) | 9 +(9 rows) + +DROP TABLE defer_t; +CREATE TABLE defer_t (a int); +CREATE INDEX defer_t_idx ON defer_t (a); +INSERT INTO defer_t VALUES (1); +BEGIN; +INSERT INTO defer_t VALUES (2); +SAVEPOINT sp1; +INSERT INTO defer_t VALUES (3); +ALTER TABLE defer_t SET TABLESPACE xact_tblspace; +INSERT INTO defer_t VALUES (4); +SAVEPOINT sp2; +INSERT INTO defer_t VALUES (5); +ALTER TABLE defer_t SET TABLESPACE xact_tblspace2; +INSERT INTO defer_t VALUES (6); +ROLLBACK; +EXECUTE check_tablespace; + relname | tablespace +-------------+------------ + defer_t | (default) + defer_t_idx | (default) +(2 rows) + +INSERT INTO defer_t VALUES (7), (8), (9); +SELECT ctid, a FROM defer_t ORDER BY a; + ctid | a +-------+--- + (0,1) | 1 + (0,7) | 7 + (0,8) | 8 + (0,9) | 9 +(4 rows) + +DROP TABLE defer_t; +-- Partitioned table: SET TABLESPACE in a transaction; new partitions use it +CREATE TABLE defer_part (a int) PARTITION BY RANGE (a); +CREATE TABLE defer_part_p0 PARTITION OF defer_part FOR VALUES FROM (0) TO (10); +CREATE INDEX ON defer_part(a); +INSERT INTO defer_part VALUES (1); +EXECUTE check_tablespace; + relname | tablespace +---------------------+------------ + defer_part | (default) + defer_part_a_idx | (default) + defer_part_p0 | (default) + defer_part_p0_a_idx | (default) +(4 rows) + +BEGIN; +ALTER TABLE defer_part SET TABLESPACE xact_tblspace; +-- defer_part tablespace is updated, but partitions are not moved +EXECUTE check_tablespace; + relname | tablespace +---------------------+--------------- + defer_part | xact_tblspace + defer_part_a_idx | (default) + defer_part_p0 | (default) + defer_part_p0_a_idx | (default) +(4 rows) + +-- new partitions created in the new table space +CREATE TABLE defer_part_p1 PARTITION OF defer_part FOR VALUES FROM (10) TO (20); +INSERT INTO defer_part VALUES (15); +ALTER TABLE defer_part SET TABLESPACE xact_tblspace2; +CREATE TABLE defer_part_p2 PARTITION OF defer_part FOR VALUES FROM (20) TO (30); +ALTER TABLE defer_part SET TABLESPACE pg_default; +CREATE TABLE defer_part_p3 PARTITION OF defer_part FOR VALUES FROM (30) TO (40); +EXECUTE check_tablespace; + relname | tablespace +---------------------+---------------- + defer_part | (default) + defer_part_a_idx | (default) + defer_part_p0 | (default) + defer_part_p0_a_idx | (default) + defer_part_p1 | xact_tblspace + defer_part_p1_a_idx | (default) + defer_part_p2 | xact_tblspace2 + defer_part_p2_a_idx | (default) + defer_part_p3 | (default) + defer_part_p3_a_idx | (default) +(10 rows) + +ROLLBACK; -- rollback delete partitions created in the transaction +EXECUTE check_tablespace; + relname | tablespace +---------------------+------------ + defer_part | (default) + defer_part_a_idx | (default) + defer_part_p0 | (default) + defer_part_p0_a_idx | (default) +(4 rows) + +-- Partitioned table: SET TABLESPACE in a transaction; new partitions use it +CREATE TABLE defer_part (a int) PARTITION BY RANGE (a); +ERROR: relation "defer_part" already exists +CREATE TABLE defer_part_p0 PARTITION OF defer_part FOR VALUES FROM (0) TO (10); +ERROR: relation "defer_part_p0" already exists +INSERT INTO defer_part VALUES (1); +EXECUTE check_tablespace; + relname | tablespace +---------------------+------------ + defer_part | (default) + defer_part_a_idx | (default) + defer_part_p0 | (default) + defer_part_p0_a_idx | (default) +(4 rows) + +BEGIN; +ALTER TABLE defer_part SET TABLESPACE xact_tblspace; +-- defer_part tablespace is updated, but partitions are not moved +EXECUTE check_tablespace; + relname | tablespace +---------------------+--------------- + defer_part | xact_tblspace + defer_part_a_idx | (default) + defer_part_p0 | (default) + defer_part_p0_a_idx | (default) +(4 rows) + +-- new partitions created in the new table space +CREATE TABLE defer_part_p1 PARTITION OF defer_part FOR VALUES FROM (10) TO (20); +INSERT INTO defer_part VALUES (15); +ALTER TABLE defer_part SET TABLESPACE xact_tblspace2; +CREATE TABLE defer_part_p2 PARTITION OF defer_part FOR VALUES FROM (20) TO (30); +ALTER TABLE defer_part SET TABLESPACE pg_default; +CREATE TABLE defer_part_p3 PARTITION OF defer_part FOR VALUES FROM (30) TO (40); +EXECUTE check_tablespace; + relname | tablespace +---------------------+---------------- + defer_part | (default) + defer_part_a_idx | (default) + defer_part_p0 | (default) + defer_part_p0_a_idx | (default) + defer_part_p1 | xact_tblspace + defer_part_p1_a_idx | (default) + defer_part_p2 | xact_tblspace2 + defer_part_p2_a_idx | (default) + defer_part_p3 | (default) + defer_part_p3_a_idx | (default) +(10 rows) + +ROLLBACK; -- rollback delete partitions created in the transaction +EXECUTE check_tablespace; + relname | tablespace +---------------------+------------ + defer_part | (default) + defer_part_a_idx | (default) + defer_part_p0 | (default) + defer_part_p0_a_idx | (default) +(4 rows) + +BEGIN; +ALTER TABLE defer_part SET TABLESPACE xact_tblspace; +CREATE TABLE defer_part_p1 PARTITION OF defer_part FOR VALUES FROM (10) TO (20); +INSERT INTO defer_part VALUES (15); +ALTER TABLE defer_part SET TABLESPACE xact_tblspace2; +CREATE TABLE defer_part_p2 PARTITION OF defer_part FOR VALUES FROM (20) TO (30); +ALTER TABLE defer_part SET TABLESPACE pg_default; +CREATE TABLE defer_part_p3 PARTITION OF defer_part FOR VALUES FROM (30) TO (40); +COMMIT; -- commit persists partitions created in the transaction +EXECUTE check_tablespace; + relname | tablespace +---------------------+---------------- + defer_part | (default) + defer_part_a_idx | (default) + defer_part_p0 | (default) + defer_part_p0_a_idx | (default) + defer_part_p1 | xact_tblspace + defer_part_p1_a_idx | (default) + defer_part_p2 | xact_tblspace2 + defer_part_p2_a_idx | (default) + defer_part_p3 | (default) + defer_part_p3_a_idx | (default) +(10 rows) + +DROP TABLE defer_part; +EXECUTE check_tablespace; + relname | tablespace +---------+------------ +(0 rows) + +DROP TABLESPACE xact_tblspace; +DROP TABLESPACE xact_tblspace2; +DROP SCHEMA tablespace_xact CASCADE; diff --git a/src/test/regress/sql/tablespace_xact.sql b/src/test/regress/sql/tablespace_xact.sql index 43fc20c7505..7fe99a5df1c 100644 --- a/src/test/regress/sql/tablespace_xact.sql +++ b/src/test/regress/sql/tablespace_xact.sql @@ -3,7 +3,6 @@ -- Deferred heap copy for ALTER TABLE SET TABLESPACE on indexed tables -- SET allow_in_place_tablespaces = true; -SET client_min_messages = DEBUG1; SET enable_seqscan = off; SET enable_bitmapscan = off; @@ -214,7 +213,6 @@ EXECUTE check_tablespace; -- Partitioned table: SET TABLESPACE in a transaction; new partitions use it CREATE TABLE defer_part (a int) PARTITION BY RANGE (a); CREATE TABLE defer_part_p0 PARTITION OF defer_part FOR VALUES FROM (0) TO (10); -CREATE INDEX ON defer_part(a); INSERT INTO defer_part VALUES (1); EXECUTE check_tablespace; BEGIN; @@ -248,4 +246,4 @@ EXECUTE check_tablespace; DROP TABLESPACE xact_tblspace; DROP TABLESPACE xact_tblspace2; -DROP SCHEMA CASCADE tablespace_xact; \ No newline at end of file +DROP SCHEMA tablespace_xact CASCADE; \ No newline at end of file -- 2.53.0