Skip to content

Commit 225ebfe

Browse files
committed
Add regression test for short varlenas saved in TOAST relations
toast_save_datum() has for a very long time some code able to handle short varlenas (values up to 126 bytes reduced to a 1-byte header), converting such varlenas to an external on-disk TOAST pointer with the value saved uncompressed in the secondary TOAST relation. There was zero coverage for this code path. This commit adds a test able to exercise it, relying on two external attributes, one with a low toast_tuple_target, so as it is possible to trigger the threshold for the insertion of short varlenas into the TOAST relation. Author: Nikhil Kumar Veldanda <veldanda.nikhilkumar17@gmail.com> Co-authored-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/aJAl7-NvIk0kZByz@paquier.xyz
1 parent 0b6aea0 commit 225ebfe

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/test/regress/expected/strings.out

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,6 +2090,40 @@ SELECT c FROM toasttest;
20902090
x
20912091
(1 row)
20922092

2093+
DROP TABLE toasttest;
2094+
-- test with short varlenas (up to 126 data bytes reduced to a 1-byte header)
2095+
-- being toasted.
2096+
CREATE TABLE toasttest (f1 text, f2 text);
2097+
ALTER TABLE toasttest SET (toast_tuple_target = 128);
2098+
ALTER TABLE toasttest ALTER COLUMN f1 SET STORAGE EXTERNAL;
2099+
ALTER TABLE toasttest ALTER COLUMN f2 SET STORAGE EXTERNAL;
2100+
-- Here, the first value is a varlena large enough to make it toasted and
2101+
-- stored uncompressed. The second value is a short varlena, toasted
2102+
-- and stored uncompressed.
2103+
INSERT INTO toasttest values(repeat('1234', 1000), repeat('5678', 30));
2104+
SELECT reltoastrelid::regclass AS reltoastname FROM pg_class
2105+
WHERE oid = 'toasttest'::regclass \gset
2106+
-- There should be two values inserted in the toast relation.
2107+
SELECT count(*) FROM :reltoastname WHERE chunk_seq = 0;
2108+
count
2109+
-------
2110+
2
2111+
(1 row)
2112+
2113+
SELECT substr(f1, 5, 10) AS f1_data, substr(f2, 5, 10) AS f2_data
2114+
FROM toasttest;
2115+
f1_data | f2_data
2116+
------------+------------
2117+
1234123412 | 5678567856
2118+
(1 row)
2119+
2120+
SELECT pg_column_compression(f1) AS f1_comp, pg_column_compression(f2) AS f2_comp
2121+
FROM toasttest;
2122+
f1_comp | f2_comp
2123+
---------+---------
2124+
|
2125+
(1 row)
2126+
20932127
DROP TABLE toasttest;
20942128
--
20952129
-- test length

src/test/regress/sql/strings.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,26 @@ SELECT length(c), c::text FROM toasttest;
650650
SELECT c FROM toasttest;
651651
DROP TABLE toasttest;
652652

653+
-- test with short varlenas (up to 126 data bytes reduced to a 1-byte header)
654+
-- being toasted.
655+
CREATE TABLE toasttest (f1 text, f2 text);
656+
ALTER TABLE toasttest SET (toast_tuple_target = 128);
657+
ALTER TABLE toasttest ALTER COLUMN f1 SET STORAGE EXTERNAL;
658+
ALTER TABLE toasttest ALTER COLUMN f2 SET STORAGE EXTERNAL;
659+
-- Here, the first value is a varlena large enough to make it toasted and
660+
-- stored uncompressed. The second value is a short varlena, toasted
661+
-- and stored uncompressed.
662+
INSERT INTO toasttest values(repeat('1234', 1000), repeat('5678', 30));
663+
SELECT reltoastrelid::regclass AS reltoastname FROM pg_class
664+
WHERE oid = 'toasttest'::regclass \gset
665+
-- There should be two values inserted in the toast relation.
666+
SELECT count(*) FROM :reltoastname WHERE chunk_seq = 0;
667+
SELECT substr(f1, 5, 10) AS f1_data, substr(f2, 5, 10) AS f2_data
668+
FROM toasttest;
669+
SELECT pg_column_compression(f1) AS f1_comp, pg_column_compression(f2) AS f2_comp
670+
FROM toasttest;
671+
DROP TABLE toasttest;
672+
653673
--
654674
-- test length
655675
--

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy