Some tests for TOAST, STORAGE MAIN/EXTENDED
Hi all,
While playing with the TOAST code this week, I have managed to break
the handling of inline compressible entries, and noticed that the main
regression test suite did not complain following that.
Breaking that stuff is my issue, but I would like to add some
regression tests to cover all that, giving the attached. This also
includes tests with EXTENDED in the same area, while on it, with
checks for the TOAST table itself.
Thoughts or comments?
--
Michael
Attachments:
0001-More-tests-for-TOAST-and-STORAGE.patchtext/x-diff; charset=us-asciiDownload
From b00fa7379eece6e3da2d46c0fd19aa80531cd7a9 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@paquier.xyz>
Date: Fri, 23 Jan 2026 15:32:50 +0900
Subject: [PATCH] More tests for TOAST and STORAGE
---
src/test/regress/expected/strings.out | 52 +++++++++++++++++++++++++++
src/test/regress/sql/strings.sql | 22 ++++++++++++
2 files changed, 74 insertions(+)
diff --git a/src/test/regress/expected/strings.out b/src/test/regress/expected/strings.out
index 5f2b5c391739..db03fd00d071 100644
--- a/src/test/regress/expected/strings.out
+++ b/src/test/regress/expected/strings.out
@@ -2159,6 +2159,58 @@ SELECT pg_column_compression(f1) AS f1_comp, pg_column_compression(f2) AS f2_com
|
(1 row)
+TRUNCATE toasttest;
+-- test with inline compressible varlenas.
+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;
+ count
+-------
+ 1
+(1 row)
+
DROP TABLE toasttest;
--
-- test length
diff --git a/src/test/regress/sql/strings.sql b/src/test/regress/sql/strings.sql
index 37c0893ae838..592599722b8b 100644
--- a/src/test/regress/sql/strings.sql
+++ b/src/test/regress/sql/strings.sql
@@ -678,6 +678,28 @@ 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.
+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;
DROP TABLE toasttest;
--
--
2.51.0
Hi Michael,
On Thu, Jan 22, 2026 at 11:04 PM Michael Paquier <michael@paquier.xyz> wrote:
Thoughts or comments?
Two nits on the new toasttest block:
The `SELECT count(*) FROM :reltoastname` assertion is a bit brittle
for `STORAGE EXTENDED`: depending on the toast compression method /
effectiveness, the value may end up as >1 chunk, which would flip the
expected count(*) = 1. Prefer SELECT count(DISTINCT chunk_id) FROM
:reltoastname (or WHERE chunk_seq = 0) and adjust expected.
pg_column_compression() expects pglz, but default_toast_compression
isn’t pinned here. Suggest SET default_toast_compression = 'pglz';
near this block; otherwise this can fail on builds with a different
default.
--
Nikhil Veldanda
On Fri, Jan 23, 2026 at 12:25:33AM -0800, Nikhil Kumar Veldanda wrote:
The `SELECT count(*) FROM :reltoastname` assertion is a bit brittle
for `STORAGE EXTENDED`: depending on the toast compression method /
effectiveness, the value may end up as >1 chunk, which would flip the
expected count(*) = 1. Prefer SELECT count(DISTINCT chunk_id) FROM
:reltoastname (or WHERE chunk_seq = 0) and adjust expected.
Yeah, this suggestion sounds sensible and that would still notice what
I was able to break.
pg_column_compression() expects pglz, but default_toast_compression
isn’t pinned here. Suggest SET default_toast_compression = 'pglz';
near this block; otherwise this can fail on builds with a different
default.
Agreed, let's do that as well.
--
Michael