From 168765e5d42be7d3ef750e9e292e14ef94b489e1 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Mon, 26 Jan 2026 09:30:22 +0900 Subject: [PATCH] Add more tests with clause STORAGE on table and TOAST interactions This commit adds more tests to cover STORAGE MAIN and EXTENDED, checking how these use TOAST tables. EXTENDED is already widely tested as the default behavior, but there were no tests where the clause pattern is directly specified. STORAGE MAIN and its interactions with TOAST was not covered at all. This hole in the tests has been noticed for STORAGE MAIN (inline compressible varlenas), where I have managed to break the backend without the tests able to notice the breakage while playing with the varlena structures. Reviewed-by: Nikhil Kumar Veldanda Discussion: https://postgr.es/m/aXMdX1UTHnzYPkHk@paquier.xyz --- src/test/regress/expected/strings.out | 54 +++++++++++++++++++++++++++ src/test/regress/sql/strings.sql | 24 ++++++++++++ 2 files changed, 78 insertions(+) diff --git a/src/test/regress/expected/strings.out b/src/test/regress/expected/strings.out index 5f2b5c39173..f38688b5c37 100644 --- a/src/test/regress/expected/strings.out +++ b/src/test/regress/expected/strings.out @@ -2159,6 +2159,60 @@ SELECT pg_column_compression(f1) AS f1_comp, pg_column_compression(f2) AS f2_com | (1 row) +TRUNCATE toasttest; +-- test with inline compressible varlenas. +SET default_toast_compression = 'pglz'; +ALTER TABLE toasttest ALTER COLUMN f1 SET STORAGE MAIN; +ALTER TABLE toasttest ALTER COLUMN f2 SET STORAGE MAIN; +INSERT INTO toasttest values(repeat('1234', 1024), repeat('5678', 1024)); +-- There should be no values in the toast relation. +SELECT substr(f1, 5, 10) AS f1_data, substr(f2, 5, 10) AS f2_data + FROM toasttest; + f1_data | f2_data +------------+------------ + 1234123412 | 5678567856 +(1 row) + +SELECT pg_column_compression(f1) AS f1_comp, pg_column_compression(f2) AS f2_comp + FROM toasttest; + f1_comp | f2_comp +---------+--------- + pglz | pglz +(1 row) + +SELECT count(*) FROM :reltoastname; + count +------- + 0 +(1 row) + +TRUNCATE toasttest; +-- test with external compressed data (default). +ALTER TABLE toasttest ALTER COLUMN f1 SET STORAGE EXTENDED; +ALTER TABLE toasttest ALTER COLUMN f2 SET STORAGE EXTENDED; +INSERT INTO toasttest values(repeat('1234', 10240), NULL); +-- There should be one value in the toast relation. +SELECT substr(f1, 5, 10) AS f1_data, substr(f2, 5, 10) AS f2_data + FROM toasttest; + f1_data | f2_data +------------+--------- + 1234123412 | +(1 row) + +SELECT pg_column_compression(f1) AS f1_comp, pg_column_compression(f2) AS f2_comp + FROM toasttest; + f1_comp | f2_comp +---------+--------- + pglz | +(1 row) + +SELECT count(*) FROM :reltoastname WHERE chunk_seq = 0; + count +------- + 1 +(1 row) + +RESET default_toast_compression; DROP TABLE toasttest; -- -- test length diff --git a/src/test/regress/sql/strings.sql b/src/test/regress/sql/strings.sql index 37c0893ae83..d8a09737668 100644 --- a/src/test/regress/sql/strings.sql +++ b/src/test/regress/sql/strings.sql @@ -678,6 +678,30 @@ SELECT substr(f1, 5, 10) AS f1_data, substr(f2, 5, 10) AS f2_data FROM toasttest; SELECT pg_column_compression(f1) AS f1_comp, pg_column_compression(f2) AS f2_comp FROM toasttest; +TRUNCATE toasttest; +-- test with inline compressible varlenas. +SET default_toast_compression = 'pglz'; +ALTER TABLE toasttest ALTER COLUMN f1 SET STORAGE MAIN; +ALTER TABLE toasttest ALTER COLUMN f2 SET STORAGE MAIN; +INSERT INTO toasttest values(repeat('1234', 1024), repeat('5678', 1024)); +-- There should be no values in the toast relation. +SELECT substr(f1, 5, 10) AS f1_data, substr(f2, 5, 10) AS f2_data + FROM toasttest; +SELECT pg_column_compression(f1) AS f1_comp, pg_column_compression(f2) AS f2_comp + FROM toasttest; +SELECT count(*) FROM :reltoastname; +TRUNCATE toasttest; +-- test with external compressed data (default). +ALTER TABLE toasttest ALTER COLUMN f1 SET STORAGE EXTENDED; +ALTER TABLE toasttest ALTER COLUMN f2 SET STORAGE EXTENDED; +INSERT INTO toasttest values(repeat('1234', 10240), NULL); +-- There should be one value in the toast relation. +SELECT substr(f1, 5, 10) AS f1_data, substr(f2, 5, 10) AS f2_data + FROM toasttest; +SELECT pg_column_compression(f1) AS f1_comp, pg_column_compression(f2) AS f2_comp + FROM toasttest; +SELECT count(*) FROM :reltoastname WHERE chunk_seq = 0; +RESET default_toast_compression; DROP TABLE toasttest; --