]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Add more tests with clause STORAGE on table and TOAST interactions
authorMichael Paquier <michael@paquier.xyz>
Mon, 26 Jan 2026 00:30:22 +0000 (09:30 +0900)
committerMichael Paquier <michael@paquier.xyz>
Mon, 26 Jan 2026 00:30:22 +0000 (09:30 +0900)
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 <veldanda.nikhilkumar17@gmail.com>
Discussion: https://postgr.es/m/aXMdX1UTHnzYPkHk@paquier.xyz

src/test/regress/expected/strings.out
src/test/regress/sql/strings.sql

index 5f2b5c39173997ba3980d91afbbdb0037c6d3202..f38688b5c37eb6efdcd24d9256e151a7cf1d4a18 100644 (file)
@@ -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
index 37c0893ae83868b1a23d6cde6dc89fe47e748081..d8a09737668b967971b59cee26a53103fc958648 100644 (file)
@@ -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;
 
 --