Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit74a3fc3

Browse files
committed
Split regression tests for TOAST compression methods into two files
The regression tests for TOAST compression methods are split into twoindependent files: one specific to LZ4 and interactions between twodifferent TOAST compression methods, now called compression_lz4, and asecond one for the "core" cases where only pglz is required.This saves 300 lines in diffs coming from the alternate output ofcompression.sql, required for builds where lz4 is not available. Thenew test is skipped if the build does not support LZ4 compression,relying on an \if and the values reported in pg_settings for the GUCdefault_toast_compression, "lz4" being available only under USE_LZ4.Another benefit of this split is that this facilitates the addition ofmore compression methods for TOAST, which are under discussion.Note the trick added for the tests of the GUC default_toast_compression,where VERBOSITY = terse is used to avoid the HINT printing the lists ofvalues available in the GUC, which are environment-dependent. Thismakes compression.sql independent of the availability of LZ4.The code coverage of toast_compression.c is slightly improved, increasedfrom 89% to 91%, with one new case covered in lz4_compress_datum() forincompressible data.Author: Nikhil Kumar Veldanda <veldanda.nikhilkumar17@gmail.com>Co-authored-by: Michael Paquier <michael@paquier.xyz>Discussion:https://postgr.es/m/aDlcU-ym9KfMj9sG@paquier.xyz
1 parenta493e74 commit74a3fc3

File tree

7 files changed

+414
-652
lines changed

7 files changed

+414
-652
lines changed

‎src/test/regress/expected/compression.out

Lines changed: 19 additions & 216 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
-- Default set of tests for TOAST compression, independent on compression
2+
-- methods supported by the build.
3+
CREATE SCHEMA pglz;
4+
SET search_path TO pglz, public;
15
\set HIDE_TOAST_COMPRESSION false
26
-- ensure we get stable results regardless of installation's default
37
SET default_toast_compression = 'pglz';
@@ -6,51 +10,31 @@ CREATE TABLE cmdata(f1 text COMPRESSION pglz);
610
CREATE INDEX idx ON cmdata(f1);
711
INSERT INTO cmdata VALUES(repeat('1234567890', 1000));
812
\d+ cmdata
9-
Table "public.cmdata"
13+
Table "pglz.cmdata"
1014
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
1115
--------+------+-----------+----------+---------+----------+-------------+--------------+-------------
1216
f1 | text | | | | extended | pglz | |
1317
Indexes:
1418
"idx" btree (f1)
1519

16-
CREATE TABLE cmdata1(f1 TEXT COMPRESSION lz4);
17-
INSERT INTO cmdata1 VALUES(repeat('1234567890', 1004));
18-
\d+ cmdata1
19-
Table "public.cmdata1"
20-
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
21-
--------+------+-----------+----------+---------+----------+-------------+--------------+-------------
22-
f1 | text | | | | extended | lz4 | |
23-
2420
-- verify stored compression method in the data
2521
SELECT pg_column_compression(f1) FROM cmdata;
2622
pg_column_compression
2723
-----------------------
2824
pglz
2925
(1 row)
3026

31-
SELECT pg_column_compression(f1) FROM cmdata1;
32-
pg_column_compression
33-
-----------------------
34-
lz4
35-
(1 row)
36-
3727
-- decompress data slice
3828
SELECT SUBSTR(f1, 200, 5) FROM cmdata;
3929
substr
4030
--------
4131
01234
4232
(1 row)
4333

44-
SELECT SUBSTR(f1, 2000, 50) FROM cmdata1;
45-
substr
46-
----------------------------------------------------
47-
01234567890123456789012345678901234567890123456789
48-
(1 row)
49-
5034
-- copy with table creation
5135
SELECT * INTO cmmove1 FROM cmdata;
5236
\d+ cmmove1
53-
Table "public.cmmove1"
37+
Table "pglz.cmmove1"
5438
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
5539
--------+------+-----------+----------+---------+----------+-------------+--------------+-------------
5640
f1 | text | | | | extended | | |
@@ -61,45 +45,9 @@ SELECT pg_column_compression(f1) FROM cmmove1;
6145
pglz
6246
(1 row)
6347

64-
-- copy to existing table
65-
CREATE TABLE cmmove3(f1 text COMPRESSION pglz);
66-
INSERT INTO cmmove3 SELECT * FROM cmdata;
67-
INSERT INTO cmmove3 SELECT * FROM cmdata1;
68-
SELECT pg_column_compression(f1) FROM cmmove3;
69-
pg_column_compression
70-
-----------------------
71-
pglz
72-
lz4
73-
(2 rows)
74-
75-
-- test LIKE INCLUDING COMPRESSION
76-
CREATE TABLE cmdata2 (LIKE cmdata1 INCLUDING COMPRESSION);
77-
\d+ cmdata2
78-
Table "public.cmdata2"
79-
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
80-
--------+------+-----------+----------+---------+----------+-------------+--------------+-------------
81-
f1 | text | | | | extended | lz4 | |
82-
83-
DROP TABLE cmdata2;
8448
-- try setting compression for incompressible data type
8549
CREATE TABLE cmdata2 (f1 int COMPRESSION pglz);
8650
ERROR: column data type integer does not support compression
87-
-- update using datum from different table
88-
CREATE TABLE cmmove2(f1 text COMPRESSION pglz);
89-
INSERT INTO cmmove2 VALUES (repeat('1234567890', 1004));
90-
SELECT pg_column_compression(f1) FROM cmmove2;
91-
pg_column_compression
92-
-----------------------
93-
pglz
94-
(1 row)
95-
96-
UPDATE cmmove2 SET f1 = cmdata1.f1 FROM cmdata1;
97-
SELECT pg_column_compression(f1) FROM cmmove2;
98-
pg_column_compression
99-
-----------------------
100-
lz4
101-
(1 row)
102-
10351
-- test externally stored compressed data
10452
CREATE OR REPLACE FUNCTION large_val() RETURNS TEXT LANGUAGE SQL AS
10553
'select array_agg(fipshash(g::text))::text from generate_series(1, 256) g';
@@ -111,21 +59,6 @@ SELECT pg_column_compression(f1) FROM cmdata2;
11159
pglz
11260
(1 row)
11361

114-
INSERT INTO cmdata1 SELECT large_val() || repeat('a', 4000);
115-
SELECT pg_column_compression(f1) FROM cmdata1;
116-
pg_column_compression
117-
-----------------------
118-
lz4
119-
lz4
120-
(2 rows)
121-
122-
SELECT SUBSTR(f1, 200, 5) FROM cmdata1;
123-
substr
124-
--------
125-
01234
126-
79026
127-
(2 rows)
128-
12962
SELECT SUBSTR(f1, 200, 5) FROM cmdata2;
13063
substr
13164
--------
@@ -136,21 +69,21 @@ DROP TABLE cmdata2;
13669
--test column type update varlena/non-varlena
13770
CREATE TABLE cmdata2 (f1 int);
13871
\d+ cmdata2
139-
Table "public.cmdata2"
72+
Table "pglz.cmdata2"
14073
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
14174
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
14275
f1 | integer | | | | plain | | |
14376

14477
ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE varchar;
14578
\d+ cmdata2
146-
Table "public.cmdata2"
79+
Table "pglz.cmdata2"
14780
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
14881
--------+-------------------+-----------+----------+---------+----------+-------------+--------------+-------------
14982
f1 | character varying | | | | extended | | |
15083

15184
ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE int USING f1::integer;
15285
\d+ cmdata2
153-
Table "public.cmdata2"
86+
Table "pglz.cmdata2"
15487
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
15588
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
15689
f1 | integer | | | | plain | | |
@@ -160,14 +93,14 @@ ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE int USING f1::integer;
16093
ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE varchar;
16194
ALTER TABLE cmdata2 ALTER COLUMN f1 SET COMPRESSION pglz;
16295
\d+ cmdata2
163-
Table "public.cmdata2"
96+
Table "pglz.cmdata2"
16497
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
16598
--------+-------------------+-----------+----------+---------+----------+-------------+--------------+-------------
16699
f1 | character varying | | | | extended | pglz | |
167100

168101
ALTER TABLE cmdata2 ALTER COLUMN f1 SET STORAGE plain;
169102
\d+ cmdata2
170-
Table "public.cmdata2"
103+
Table "pglz.cmdata2"
171104
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
172105
--------+-------------------+-----------+----------+---------+---------+-------------+--------------+-------------
173106
f1 | character varying | | | | plain | pglz | |
@@ -179,184 +112,54 @@ SELECT pg_column_compression(f1) FROM cmdata2;
179112

180113
(1 row)
181114

182-
-- test compression with materialized view
183-
CREATE MATERIALIZED VIEW compressmv(x) AS SELECT * FROM cmdata1;
184-
\d+ compressmv
185-
Materialized view "public.compressmv"
186-
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
187-
--------+------+-----------+----------+---------+----------+-------------+--------------+-------------
188-
x | text | | | | extended | | |
189-
View definition:
190-
SELECT f1 AS x
191-
FROM cmdata1;
192-
193-
SELECT pg_column_compression(f1) FROM cmdata1;
194-
pg_column_compression
195-
-----------------------
196-
lz4
197-
lz4
198-
(2 rows)
199-
200-
SELECT pg_column_compression(x) FROM compressmv;
201-
pg_column_compression
202-
-----------------------
203-
lz4
204-
lz4
205-
(2 rows)
206-
207-
-- test compression with partition
208-
CREATE TABLE cmpart(f1 text COMPRESSION lz4) PARTITION BY HASH(f1);
209-
CREATE TABLE cmpart1 PARTITION OF cmpart FOR VALUES WITH (MODULUS 2, REMAINDER 0);
210-
CREATE TABLE cmpart2(f1 text COMPRESSION pglz);
211-
ALTER TABLE cmpart ATTACH PARTITION cmpart2 FOR VALUES WITH (MODULUS 2, REMAINDER 1);
212-
INSERT INTO cmpart VALUES (repeat('123456789', 1004));
213-
INSERT INTO cmpart VALUES (repeat('123456789', 4004));
214-
SELECT pg_column_compression(f1) FROM cmpart1;
215-
pg_column_compression
216-
-----------------------
217-
lz4
218-
(1 row)
219-
220-
SELECT pg_column_compression(f1) FROM cmpart2;
221-
pg_column_compression
222-
-----------------------
223-
pglz
224-
(1 row)
225-
226115
-- test compression with inheritance
227-
CREATE TABLE cminh() INHERITS(cmdata, cmdata1); -- error
228-
NOTICE: merging multiple inherited definitions of column "f1"
229-
ERROR: column "f1" has a compression method conflict
230-
DETAIL: pglz versus lz4
231-
CREATE TABLE cminh(f1 TEXT COMPRESSION lz4) INHERITS(cmdata); -- error
232-
NOTICE: merging column "f1" with inherited definition
233-
ERROR: column "f1" has a compression method conflict
234-
DETAIL: pglz versus lz4
235116
CREATE TABLE cmdata3(f1 text);
236117
CREATE TABLE cminh() INHERITS (cmdata, cmdata3);
237118
NOTICE: merging multiple inherited definitions of column "f1"
238119
-- test default_toast_compression GUC
120+
-- suppress machine-dependent details
121+
\set VERBOSITY terse
239122
SET default_toast_compression = '';
240123
ERROR: invalid value for parameter "default_toast_compression": ""
241-
HINT: Available values: pglz, lz4.
242124
SET default_toast_compression = 'I do not exist compression';
243125
ERROR: invalid value for parameter "default_toast_compression": "I do not exist compression"
244-
HINT: Available values: pglz, lz4.
245-
SET default_toast_compression = 'lz4';
246126
SET default_toast_compression = 'pglz';
247-
-- test alter compression method
248-
ALTER TABLE cmdata ALTER COLUMN f1 SET COMPRESSION lz4;
249-
INSERT INTO cmdata VALUES (repeat('123456789', 4004));
250-
\d+ cmdata
251-
Table "public.cmdata"
252-
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
253-
--------+------+-----------+----------+---------+----------+-------------+--------------+-------------
254-
f1 | text | | | | extended | lz4 | |
255-
Indexes:
256-
"idx" btree (f1)
257-
Child tables: cminh
258-
259-
SELECT pg_column_compression(f1) FROM cmdata;
260-
pg_column_compression
261-
-----------------------
262-
pglz
263-
lz4
264-
(2 rows)
265-
127+
\set VERBOSITY default
266128
ALTER TABLE cmdata2 ALTER COLUMN f1 SET COMPRESSION default;
267129
\d+ cmdata2
268-
Table "public.cmdata2"
130+
Table "pglz.cmdata2"
269131
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
270132
--------+-------------------+-----------+----------+---------+---------+-------------+--------------+-------------
271133
f1 | character varying | | | | plain | | |
272134

273-
-- test alter compression method for materialized views
274-
ALTER MATERIALIZED VIEW compressmv ALTER COLUMN x SET COMPRESSION lz4;
275-
\d+ compressmv
276-
Materialized view "public.compressmv"
277-
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
278-
--------+------+-----------+----------+---------+----------+-------------+--------------+-------------
279-
x | text | | | | extended | lz4 | |
280-
View definition:
281-
SELECT f1 AS x
282-
FROM cmdata1;
283-
284-
-- test alter compression method for partitioned tables
285-
ALTER TABLE cmpart1 ALTER COLUMN f1 SET COMPRESSION pglz;
286-
ALTER TABLE cmpart2 ALTER COLUMN f1 SET COMPRESSION lz4;
287-
-- new data should be compressed with the current compression method
288-
INSERT INTO cmpart VALUES (repeat('123456789', 1004));
289-
INSERT INTO cmpart VALUES (repeat('123456789', 4004));
290-
SELECT pg_column_compression(f1) FROM cmpart1;
291-
pg_column_compression
292-
-----------------------
293-
lz4
294-
pglz
295-
(2 rows)
296-
297-
SELECT pg_column_compression(f1) FROM cmpart2;
298-
pg_column_compression
299-
-----------------------
300-
pglz
301-
lz4
302-
(2 rows)
303-
135+
DROP TABLE cmdata2;
304136
-- VACUUM FULL does not recompress
305137
SELECT pg_column_compression(f1) FROM cmdata;
306138
pg_column_compression
307139
-----------------------
308140
pglz
309-
lz4
310-
(2 rows)
141+
(1 row)
311142

312143
VACUUM FULL cmdata;
313144
SELECT pg_column_compression(f1) FROM cmdata;
314145
pg_column_compression
315146
-----------------------
316147
pglz
317-
lz4
318-
(2 rows)
148+
(1 row)
319149

320-
-- test expression index
321-
DROP TABLE cmdata2;
322-
CREATE TABLE cmdata2 (f1 TEXT COMPRESSION pglz, f2 TEXT COMPRESSION lz4);
323-
CREATE UNIQUE INDEX idx1 ON cmdata2 ((f1 || f2));
324-
INSERT INTO cmdata2 VALUES((SELECT array_agg(fipshash(g::TEXT))::TEXT FROM
325-
generate_series(1, 50) g), VERSION());
326150
-- check data is ok
327151
SELECT length(f1) FROM cmdata;
328152
length
329153
--------
330154
10000
331-
36036
332-
(2 rows)
333-
334-
SELECT length(f1) FROM cmdata1;
335-
length
336-
--------
337-
10040
338-
12449
339-
(2 rows)
155+
(1 row)
340156

341157
SELECT length(f1) FROM cmmove1;
342158
length
343159
--------
344160
10000
345161
(1 row)
346162

347-
SELECT length(f1) FROM cmmove2;
348-
length
349-
--------
350-
10040
351-
(1 row)
352-
353-
SELECT length(f1) FROM cmmove3;
354-
length
355-
--------
356-
10000
357-
10040
358-
(2 rows)
359-
360163
CREATE TABLE badcompresstbl (a text COMPRESSION I_Do_Not_Exist_Compression); -- fails
361164
ERROR: invalid compression method "i_do_not_exist_compression"
362165
CREATE TABLE badcompresstbl (a text);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp