mirror of
https://github.com/postgres/postgres.git
synced 2025-10-15 05:46:52 +03:00
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
This commit is contained in:
@@ -2090,6 +2090,40 @@ SELECT c FROM toasttest;
|
||||
x
|
||||
(1 row)
|
||||
|
||||
DROP TABLE toasttest;
|
||||
-- test with short varlenas (up to 126 data bytes reduced to a 1-byte header)
|
||||
-- being toasted.
|
||||
CREATE TABLE toasttest (f1 text, f2 text);
|
||||
ALTER TABLE toasttest SET (toast_tuple_target = 128);
|
||||
ALTER TABLE toasttest ALTER COLUMN f1 SET STORAGE EXTERNAL;
|
||||
ALTER TABLE toasttest ALTER COLUMN f2 SET STORAGE EXTERNAL;
|
||||
-- Here, the first value is a varlena large enough to make it toasted and
|
||||
-- stored uncompressed. The second value is a short varlena, toasted
|
||||
-- and stored uncompressed.
|
||||
INSERT INTO toasttest values(repeat('1234', 1000), repeat('5678', 30));
|
||||
SELECT reltoastrelid::regclass AS reltoastname FROM pg_class
|
||||
WHERE oid = 'toasttest'::regclass \gset
|
||||
-- There should be two values inserted in the toast relation.
|
||||
SELECT count(*) FROM :reltoastname WHERE chunk_seq = 0;
|
||||
count
|
||||
-------
|
||||
2
|
||||
(1 row)
|
||||
|
||||
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
|
||||
---------+---------
|
||||
|
|
||||
(1 row)
|
||||
|
||||
DROP TABLE toasttest;
|
||||
--
|
||||
-- test length
|
||||
|
@@ -650,6 +650,26 @@ SELECT length(c), c::text FROM toasttest;
|
||||
SELECT c FROM toasttest;
|
||||
DROP TABLE toasttest;
|
||||
|
||||
-- test with short varlenas (up to 126 data bytes reduced to a 1-byte header)
|
||||
-- being toasted.
|
||||
CREATE TABLE toasttest (f1 text, f2 text);
|
||||
ALTER TABLE toasttest SET (toast_tuple_target = 128);
|
||||
ALTER TABLE toasttest ALTER COLUMN f1 SET STORAGE EXTERNAL;
|
||||
ALTER TABLE toasttest ALTER COLUMN f2 SET STORAGE EXTERNAL;
|
||||
-- Here, the first value is a varlena large enough to make it toasted and
|
||||
-- stored uncompressed. The second value is a short varlena, toasted
|
||||
-- and stored uncompressed.
|
||||
INSERT INTO toasttest values(repeat('1234', 1000), repeat('5678', 30));
|
||||
SELECT reltoastrelid::regclass AS reltoastname FROM pg_class
|
||||
WHERE oid = 'toasttest'::regclass \gset
|
||||
-- There should be two values inserted in the toast relation.
|
||||
SELECT count(*) FROM :reltoastname WHERE chunk_seq = 0;
|
||||
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;
|
||||
DROP TABLE toasttest;
|
||||
|
||||
--
|
||||
-- test length
|
||||
--
|
||||
|
Reference in New Issue
Block a user