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 HINT: You need to rebuild PostgreSQL using --with-lz4.
20 INSERT INTO cmdata1 VALUES(repeat('1234567890', 1004));
21 ERROR: relation "cmdata1" does not exist
22 LINE 1: INSERT INTO cmdata1 VALUES(repeat('1234567890', 1004));
25 -- verify stored compression method in the data
26 SELECT pg_column_compression(f1) FROM cmdata;
28 -----------------------
32 SELECT pg_column_compression(f1) FROM cmdata1;
33 ERROR: relation "cmdata1" does not exist
34 LINE 1: SELECT pg_column_compression(f1) FROM cmdata1;
36 -- decompress data slice
37 SELECT SUBSTR(f1, 200, 5) FROM cmdata;
43 SELECT SUBSTR(f1, 2000, 50) FROM cmdata1;
44 ERROR: relation "cmdata1" does not exist
45 LINE 1: SELECT SUBSTR(f1, 2000, 50) FROM cmdata1;
47 -- copy with table creation
48 SELECT * INTO cmmove1 FROM cmdata;
50 Table "public.cmmove1"
51 Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
52 --------+------+-----------+----------+---------+----------+-------------+--------------+-------------
53 f1 | text | | | | extended | | |
55 SELECT pg_column_compression(f1) FROM cmmove1;
57 -----------------------
61 -- copy to existing table
62 CREATE TABLE cmmove3(f1 text COMPRESSION pglz);
63 INSERT INTO cmmove3 SELECT * FROM cmdata;
64 INSERT INTO cmmove3 SELECT * FROM cmdata1;
65 ERROR: relation "cmdata1" does not exist
66 LINE 1: INSERT INTO cmmove3 SELECT * FROM cmdata1;
68 SELECT pg_column_compression(f1) FROM cmmove3;
70 -----------------------
74 -- test LIKE INCLUDING COMPRESSION
75 CREATE TABLE cmdata2 (LIKE cmdata1 INCLUDING COMPRESSION);
76 ERROR: relation "cmdata1" does not exist
77 LINE 1: CREATE TABLE cmdata2 (LIKE cmdata1 INCLUDING COMPRESSION);
81 ERROR: table "cmdata2" does not exist
82 -- try setting compression for incompressible data type
83 CREATE TABLE cmdata2 (f1 int COMPRESSION pglz);
84 ERROR: column data type integer does not support compression
85 -- update using datum from different table
86 CREATE TABLE cmmove2(f1 text COMPRESSION pglz);
87 INSERT INTO cmmove2 VALUES (repeat('1234567890', 1004));
88 SELECT pg_column_compression(f1) FROM cmmove2;
90 -----------------------
94 UPDATE cmmove2 SET f1 = cmdata1.f1 FROM cmdata1;
95 ERROR: relation "cmdata1" does not exist
96 LINE 1: UPDATE cmmove2 SET f1 = cmdata1.f1 FROM cmdata1;
98 SELECT pg_column_compression(f1) FROM cmmove2;
100 -----------------------
104 -- test externally stored compressed data
105 CREATE OR REPLACE FUNCTION large_val() RETURNS TEXT LANGUAGE SQL AS
106 'select array_agg(md5(g::text))::text from generate_series(1, 256) g';
107 CREATE TABLE cmdata2 (f1 text COMPRESSION pglz);
108 INSERT INTO cmdata2 SELECT large_val() || repeat('a', 4000);
109 SELECT pg_column_compression(f1) FROM cmdata2;
110 pg_column_compression
111 -----------------------
115 INSERT INTO cmdata1 SELECT large_val() || repeat('a', 4000);
116 ERROR: relation "cmdata1" does not exist
117 LINE 1: INSERT INTO cmdata1 SELECT large_val() || repeat('a', 4000);
119 SELECT pg_column_compression(f1) FROM cmdata1;
120 ERROR: relation "cmdata1" does not exist
121 LINE 1: SELECT pg_column_compression(f1) FROM cmdata1;
123 SELECT SUBSTR(f1, 200, 5) FROM cmdata1;
124 ERROR: relation "cmdata1" does not exist
125 LINE 1: SELECT SUBSTR(f1, 200, 5) FROM cmdata1;
127 SELECT SUBSTR(f1, 200, 5) FROM cmdata2;
134 --test column type update varlena/non-varlena
135 CREATE TABLE cmdata2 (f1 int);
137 Table "public.cmdata2"
138 Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
139 --------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
140 f1 | integer | | | | plain | | |
142 ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE varchar;
144 Table "public.cmdata2"
145 Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
146 --------+-------------------+-----------+----------+---------+----------+-------------+--------------+-------------
147 f1 | character varying | | | | extended | | |
149 ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE int USING f1::integer;
151 Table "public.cmdata2"
152 Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
153 --------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
154 f1 | integer | | | | plain | | |
156 --changing column storage should not impact the compression method
157 --but the data should not be compressed
158 ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE varchar;
159 ALTER TABLE cmdata2 ALTER COLUMN f1 SET COMPRESSION pglz;
161 Table "public.cmdata2"
162 Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
163 --------+-------------------+-----------+----------+---------+----------+-------------+--------------+-------------
164 f1 | character varying | | | | extended | pglz | |
166 ALTER TABLE cmdata2 ALTER COLUMN f1 SET STORAGE plain;
168 Table "public.cmdata2"
169 Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
170 --------+-------------------+-----------+----------+---------+---------+-------------+--------------+-------------
171 f1 | character varying | | | | plain | pglz | |
173 INSERT INTO cmdata2 VALUES (repeat('123456789', 800));
174 SELECT pg_column_compression(f1) FROM cmdata2;
175 pg_column_compression
176 -----------------------
180 -- test compression with materialized view
181 CREATE MATERIALIZED VIEW compressmv(x) AS SELECT * FROM cmdata1;
182 ERROR: relation "cmdata1" does not exist
183 LINE 1: ...TE MATERIALIZED VIEW compressmv(x) AS SELECT * FROM cmdata1;
186 SELECT pg_column_compression(f1) FROM cmdata1;
187 ERROR: relation "cmdata1" does not exist
188 LINE 1: SELECT pg_column_compression(f1) FROM cmdata1;
190 SELECT pg_column_compression(x) FROM compressmv;
191 ERROR: relation "compressmv" does not exist
192 LINE 1: SELECT pg_column_compression(x) FROM compressmv;
194 -- test compression with partition
195 CREATE TABLE cmpart(f1 text COMPRESSION lz4) PARTITION BY HASH(f1);
196 ERROR: compression method lz4 not supported
197 DETAIL: This functionality requires the server to be built with lz4 support.
198 HINT: You need to rebuild PostgreSQL using --with-lz4.
199 CREATE TABLE cmpart1 PARTITION OF cmpart FOR VALUES WITH (MODULUS 2, REMAINDER 0);
200 ERROR: relation "cmpart" does not exist
201 CREATE TABLE cmpart2(f1 text COMPRESSION pglz);
202 ALTER TABLE cmpart ATTACH PARTITION cmpart2 FOR VALUES WITH (MODULUS 2, REMAINDER 1);
203 ERROR: relation "cmpart" does not exist
204 INSERT INTO cmpart VALUES (repeat('123456789', 1004));
205 ERROR: relation "cmpart" does not exist
206 LINE 1: INSERT INTO cmpart VALUES (repeat('123456789', 1004));
208 INSERT INTO cmpart VALUES (repeat('123456789', 4004));
209 ERROR: relation "cmpart" does not exist
210 LINE 1: INSERT INTO cmpart VALUES (repeat('123456789', 4004));
212 SELECT pg_column_compression(f1) FROM cmpart1;
213 ERROR: relation "cmpart1" does not exist
214 LINE 1: SELECT pg_column_compression(f1) FROM cmpart1;
216 SELECT pg_column_compression(f1) FROM cmpart2;
217 pg_column_compression
218 -----------------------
221 -- test compression with inheritance, error
222 CREATE TABLE cminh() INHERITS(cmdata, cmdata1);
223 ERROR: relation "cmdata1" does not exist
224 CREATE TABLE cminh(f1 TEXT COMPRESSION lz4) INHERITS(cmdata);
225 NOTICE: merging column "f1" with inherited definition
226 ERROR: column "f1" has a compression method conflict
227 DETAIL: pglz versus lz4
228 -- test default_toast_compression GUC
229 SET default_toast_compression = '';
230 ERROR: invalid value for parameter "default_toast_compression": ""
231 HINT: Available values: pglz.
232 SET default_toast_compression = 'I do not exist compression';
233 ERROR: invalid value for parameter "default_toast_compression": "I do not exist compression"
234 HINT: Available values: pglz.
235 SET default_toast_compression = 'lz4';
236 ERROR: invalid value for parameter "default_toast_compression": "lz4"
237 HINT: Available values: pglz.
238 SET default_toast_compression = 'pglz';
239 -- test alter compression method
240 ALTER TABLE cmdata ALTER COLUMN f1 SET COMPRESSION lz4;
241 ERROR: compression method lz4 not supported
242 DETAIL: This functionality requires the server to be built with lz4 support.
243 HINT: You need to rebuild PostgreSQL using --with-lz4.
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 | |
253 SELECT pg_column_compression(f1) FROM cmdata;
254 pg_column_compression
255 -----------------------
260 ALTER TABLE cmdata2 ALTER COLUMN f1 SET COMPRESSION default;
262 Table "public.cmdata2"
263 Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
264 --------+-------------------+-----------+----------+---------+---------+-------------+--------------+-------------
265 f1 | character varying | | | | plain | | |
267 -- test alter compression method for materialized views
268 ALTER MATERIALIZED VIEW compressmv ALTER COLUMN x SET COMPRESSION lz4;
269 ERROR: relation "compressmv" does not exist
271 -- test alter compression method for partitioned tables
272 ALTER TABLE cmpart1 ALTER COLUMN f1 SET COMPRESSION pglz;
273 ERROR: relation "cmpart1" does not exist
274 ALTER TABLE cmpart2 ALTER COLUMN f1 SET COMPRESSION lz4;
275 ERROR: compression method lz4 not supported
276 DETAIL: This functionality requires the server to be built with lz4 support.
277 HINT: You need to rebuild PostgreSQL using --with-lz4.
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 HINT: You need to rebuild PostgreSQL using --with-lz4.
318 CREATE UNIQUE INDEX idx1 ON cmdata2 ((f1 || f2));
319 ERROR: relation "cmdata2" does not exist
320 INSERT INTO cmdata2 VALUES((SELECT array_agg(md5(g::TEXT))::TEXT FROM
321 generate_series(1, 50) g), VERSION());
322 ERROR: relation "cmdata2" does not exist
323 LINE 1: INSERT INTO cmdata2 VALUES((SELECT array_agg(md5(g::TEXT))::...
326 SELECT length(f1) FROM cmdata;
333 SELECT length(f1) FROM cmdata1;
334 ERROR: relation "cmdata1" does not exist
335 LINE 1: SELECT length(f1) FROM cmdata1;
337 SELECT length(f1) FROM cmmove1;
343 SELECT length(f1) FROM cmmove2;
349 SELECT length(f1) FROM cmmove3;
355 CREATE TABLE badcompresstbl (a text COMPRESSION I_Do_Not_Exist_Compression); -- fails
356 ERROR: invalid compression method "i_do_not_exist_compression"
357 CREATE TABLE badcompresstbl (a text);
358 ALTER TABLE badcompresstbl ALTER a SET COMPRESSION I_Do_Not_Exist_Compression; -- fails
359 ERROR: invalid compression method "i_do_not_exist_compression"
360 DROP TABLE badcompresstbl;
361 \set HIDE_TOAST_COMPRESSION true