1 \set HIDE_TOAST_COMPRESSION false
2 -- ensure we get stable results regardless of installation's default
3 SET default_toast_compression = 'pglz';
4 -- test creating table with compression method
5 CREATE TABLE cmdata(f1 text COMPRESSION pglz);
6 CREATE INDEX idx ON cmdata(f1);
7 INSERT INTO cmdata VALUES(repeat('1234567890', 1000));
10 Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
11 --------+------+-----------+----------+---------+----------+-------------+--------------+-------------
12 f1 | text | | | | extended | pglz | |
16 CREATE TABLE cmdata1(f1 TEXT COMPRESSION lz4);
17 ERROR: compression method lz4 not supported
18 DETAIL: This functionality requires the server to be built with lz4 support.
19 INSERT INTO cmdata1 VALUES(repeat('1234567890', 1004));
20 ERROR: relation "cmdata1" does not exist
21 LINE 1: INSERT INTO cmdata1 VALUES(repeat('1234567890', 1004));
24 -- verify stored compression method in the data
25 SELECT pg_column_compression(f1) FROM cmdata;
27 -----------------------
31 SELECT pg_column_compression(f1) FROM cmdata1;
32 ERROR: relation "cmdata1" does not exist
33 LINE 1: SELECT pg_column_compression(f1) FROM cmdata1;
35 -- decompress data slice
36 SELECT SUBSTR(f1, 200, 5) FROM cmdata;
42 SELECT SUBSTR(f1, 2000, 50) FROM cmdata1;
43 ERROR: relation "cmdata1" does not exist
44 LINE 1: SELECT SUBSTR(f1, 2000, 50) FROM cmdata1;
46 -- copy with table creation
47 SELECT * INTO cmmove1 FROM cmdata;
49 Table "public.cmmove1"
50 Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
51 --------+------+-----------+----------+---------+----------+-------------+--------------+-------------
52 f1 | text | | | | extended | | |
54 SELECT pg_column_compression(f1) FROM cmmove1;
56 -----------------------
60 -- copy to existing table
61 CREATE TABLE cmmove3(f1 text COMPRESSION pglz);
62 INSERT INTO cmmove3 SELECT * FROM cmdata;
63 INSERT INTO cmmove3 SELECT * FROM cmdata1;
64 ERROR: relation "cmdata1" does not exist
65 LINE 1: INSERT INTO cmmove3 SELECT * FROM cmdata1;
67 SELECT pg_column_compression(f1) FROM cmmove3;
69 -----------------------
73 -- test LIKE INCLUDING COMPRESSION
74 CREATE TABLE cmdata2 (LIKE cmdata1 INCLUDING COMPRESSION);
75 ERROR: relation "cmdata1" does not exist
76 LINE 1: CREATE TABLE cmdata2 (LIKE cmdata1 INCLUDING COMPRESSION);
80 ERROR: table "cmdata2" does not exist
81 -- try setting compression for incompressible data type
82 CREATE TABLE cmdata2 (f1 int COMPRESSION pglz);
83 ERROR: column data type integer does not support compression
84 -- update using datum from different table
85 CREATE TABLE cmmove2(f1 text COMPRESSION pglz);
86 INSERT INTO cmmove2 VALUES (repeat('1234567890', 1004));
87 SELECT pg_column_compression(f1) FROM cmmove2;
89 -----------------------
93 UPDATE cmmove2 SET f1 = cmdata1.f1 FROM cmdata1;
94 ERROR: relation "cmdata1" does not exist
95 LINE 1: UPDATE cmmove2 SET f1 = cmdata1.f1 FROM cmdata1;
97 SELECT pg_column_compression(f1) FROM cmmove2;
99 -----------------------
103 -- test externally stored compressed data
104 CREATE OR REPLACE FUNCTION large_val() RETURNS TEXT LANGUAGE SQL AS
105 'select array_agg(fipshash(g::text))::text from generate_series(1, 256) g';
106 CREATE TABLE cmdata2 (f1 text COMPRESSION pglz);
107 INSERT INTO cmdata2 SELECT large_val() || repeat('a', 4000);
108 SELECT pg_column_compression(f1) FROM cmdata2;
109 pg_column_compression
110 -----------------------
114 INSERT INTO cmdata1 SELECT large_val() || repeat('a', 4000);
115 ERROR: relation "cmdata1" does not exist
116 LINE 1: INSERT INTO cmdata1 SELECT large_val() || repeat('a', 4000);
118 SELECT pg_column_compression(f1) FROM cmdata1;
119 ERROR: relation "cmdata1" does not exist
120 LINE 1: SELECT pg_column_compression(f1) FROM cmdata1;
122 SELECT SUBSTR(f1, 200, 5) FROM cmdata1;
123 ERROR: relation "cmdata1" does not exist
124 LINE 1: SELECT SUBSTR(f1, 200, 5) FROM cmdata1;
126 SELECT SUBSTR(f1, 200, 5) FROM cmdata2;
133 --test column type update varlena/non-varlena
134 CREATE TABLE cmdata2 (f1 int);
136 Table "public.cmdata2"
137 Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
138 --------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
139 f1 | integer | | | | plain | | |
141 ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE varchar;
143 Table "public.cmdata2"
144 Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
145 --------+-------------------+-----------+----------+---------+----------+-------------+--------------+-------------
146 f1 | character varying | | | | extended | | |
148 ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE int USING f1::integer;
150 Table "public.cmdata2"
151 Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
152 --------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
153 f1 | integer | | | | plain | | |
155 --changing column storage should not impact the compression method
156 --but the data should not be compressed
157 ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE varchar;
158 ALTER TABLE cmdata2 ALTER COLUMN f1 SET COMPRESSION pglz;
160 Table "public.cmdata2"
161 Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
162 --------+-------------------+-----------+----------+---------+----------+-------------+--------------+-------------
163 f1 | character varying | | | | extended | pglz | |
165 ALTER TABLE cmdata2 ALTER COLUMN f1 SET STORAGE plain;
167 Table "public.cmdata2"
168 Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
169 --------+-------------------+-----------+----------+---------+---------+-------------+--------------+-------------
170 f1 | character varying | | | | plain | pglz | |
172 INSERT INTO cmdata2 VALUES (repeat('123456789', 800));
173 SELECT pg_column_compression(f1) FROM cmdata2;
174 pg_column_compression
175 -----------------------
179 -- test compression with materialized view
180 CREATE MATERIALIZED VIEW compressmv(x) AS SELECT * FROM cmdata1;
181 ERROR: relation "cmdata1" does not exist
182 LINE 1: ...TE MATERIALIZED VIEW compressmv(x) AS SELECT * FROM cmdata1;
185 SELECT pg_column_compression(f1) FROM cmdata1;
186 ERROR: relation "cmdata1" does not exist
187 LINE 1: SELECT pg_column_compression(f1) FROM cmdata1;
189 SELECT pg_column_compression(x) FROM compressmv;
190 ERROR: relation "compressmv" does not exist
191 LINE 1: SELECT pg_column_compression(x) FROM compressmv;
193 -- test compression with partition
194 CREATE TABLE cmpart(f1 text COMPRESSION lz4) PARTITION BY HASH(f1);
195 ERROR: compression method lz4 not supported
196 DETAIL: This functionality requires the server to be built with lz4 support.
197 CREATE TABLE cmpart1 PARTITION OF cmpart FOR VALUES WITH (MODULUS 2, REMAINDER 0);
198 ERROR: relation "cmpart" does not exist
199 CREATE TABLE cmpart2(f1 text COMPRESSION pglz);
200 ALTER TABLE cmpart ATTACH PARTITION cmpart2 FOR VALUES WITH (MODULUS 2, REMAINDER 1);
201 ERROR: relation "cmpart" does not exist
202 INSERT INTO cmpart VALUES (repeat('123456789', 1004));
203 ERROR: relation "cmpart" does not exist
204 LINE 1: INSERT INTO cmpart VALUES (repeat('123456789', 1004));
206 INSERT INTO cmpart VALUES (repeat('123456789', 4004));
207 ERROR: relation "cmpart" does not exist
208 LINE 1: INSERT INTO cmpart VALUES (repeat('123456789', 4004));
210 SELECT pg_column_compression(f1) FROM cmpart1;
211 ERROR: relation "cmpart1" does not exist
212 LINE 1: SELECT pg_column_compression(f1) FROM cmpart1;
214 SELECT pg_column_compression(f1) FROM cmpart2;
215 pg_column_compression
216 -----------------------
219 -- test compression with inheritance
220 CREATE TABLE cminh() INHERITS(cmdata, cmdata1); -- error
221 ERROR: relation "cmdata1" does not exist
222 CREATE TABLE cminh(f1 TEXT COMPRESSION lz4) INHERITS(cmdata); -- error
223 NOTICE: merging column "f1" with inherited definition
224 ERROR: column "f1" has a compression method conflict
225 DETAIL: pglz versus lz4
226 CREATE TABLE cmdata3(f1 text);
227 CREATE TABLE cminh() INHERITS (cmdata, cmdata3);
228 NOTICE: merging multiple inherited definitions of column "f1"
229 -- test default_toast_compression GUC
230 SET default_toast_compression = '';
231 ERROR: invalid value for parameter "default_toast_compression": ""
232 HINT: Available values: pglz.
233 SET default_toast_compression = 'I do not exist compression';
234 ERROR: invalid value for parameter "default_toast_compression": "I do not exist compression"
235 HINT: Available values: pglz.
236 SET default_toast_compression = 'lz4';
237 ERROR: invalid value for parameter "default_toast_compression": "lz4"
238 HINT: Available values: pglz.
239 SET default_toast_compression = 'pglz';
240 -- test alter compression method
241 ALTER TABLE cmdata ALTER COLUMN f1 SET COMPRESSION lz4;
242 ERROR: compression method lz4 not supported
243 DETAIL: This functionality requires the server to be built with lz4 support.
244 INSERT INTO cmdata VALUES (repeat('123456789', 4004));
246 Table "public.cmdata"
247 Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
248 --------+------+-----------+----------+---------+----------+-------------+--------------+-------------
249 f1 | text | | | | extended | pglz | |
254 SELECT pg_column_compression(f1) FROM cmdata;
255 pg_column_compression
256 -----------------------
261 ALTER TABLE cmdata2 ALTER COLUMN f1 SET COMPRESSION default;
263 Table "public.cmdata2"
264 Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
265 --------+-------------------+-----------+----------+---------+---------+-------------+--------------+-------------
266 f1 | character varying | | | | plain | | |
268 -- test alter compression method for materialized views
269 ALTER MATERIALIZED VIEW compressmv ALTER COLUMN x SET COMPRESSION lz4;
270 ERROR: relation "compressmv" does not exist
272 -- test alter compression method for partitioned tables
273 ALTER TABLE cmpart1 ALTER COLUMN f1 SET COMPRESSION pglz;
274 ERROR: relation "cmpart1" does not exist
275 ALTER TABLE cmpart2 ALTER COLUMN f1 SET COMPRESSION lz4;
276 ERROR: compression method lz4 not supported
277 DETAIL: This functionality requires the server to be built with lz4 support.
278 -- new data should be compressed with the current compression method
279 INSERT INTO cmpart VALUES (repeat('123456789', 1004));
280 ERROR: relation "cmpart" does not exist
281 LINE 1: INSERT INTO cmpart VALUES (repeat('123456789', 1004));
283 INSERT INTO cmpart VALUES (repeat('123456789', 4004));
284 ERROR: relation "cmpart" does not exist
285 LINE 1: INSERT INTO cmpart VALUES (repeat('123456789', 4004));
287 SELECT pg_column_compression(f1) FROM cmpart1;
288 ERROR: relation "cmpart1" does not exist
289 LINE 1: SELECT pg_column_compression(f1) FROM cmpart1;
291 SELECT pg_column_compression(f1) FROM cmpart2;
292 pg_column_compression
293 -----------------------
296 -- VACUUM FULL does not recompress
297 SELECT pg_column_compression(f1) FROM cmdata;
298 pg_column_compression
299 -----------------------
305 SELECT pg_column_compression(f1) FROM cmdata;
306 pg_column_compression
307 -----------------------
312 -- test expression index
314 CREATE TABLE cmdata2 (f1 TEXT COMPRESSION pglz, f2 TEXT COMPRESSION lz4);
315 ERROR: compression method lz4 not supported
316 DETAIL: This functionality requires the server to be built with lz4 support.
317 CREATE UNIQUE INDEX idx1 ON cmdata2 ((f1 || f2));
318 ERROR: relation "cmdata2" does not exist
319 INSERT INTO cmdata2 VALUES((SELECT array_agg(fipshash(g::TEXT))::TEXT FROM
320 generate_series(1, 50) g), VERSION());
321 ERROR: relation "cmdata2" does not exist
322 LINE 1: INSERT INTO cmdata2 VALUES((SELECT array_agg(fipshash(g::TEX...
325 SELECT length(f1) FROM cmdata;
332 SELECT length(f1) FROM cmdata1;
333 ERROR: relation "cmdata1" does not exist
334 LINE 1: SELECT length(f1) FROM cmdata1;
336 SELECT length(f1) FROM cmmove1;
342 SELECT length(f1) FROM cmmove2;
348 SELECT length(f1) FROM cmmove3;
354 CREATE TABLE badcompresstbl (a text COMPRESSION I_Do_Not_Exist_Compression); -- fails
355 ERROR: invalid compression method "i_do_not_exist_compression"
356 CREATE TABLE badcompresstbl (a text);
357 ALTER TABLE badcompresstbl ALTER a SET COMPRESSION I_Do_Not_Exist_Compression; -- fails
358 ERROR: invalid compression method "i_do_not_exist_compression"
359 DROP TABLE badcompresstbl;
360 \set HIDE_TOAST_COMPRESSION true