summaryrefslogtreecommitdiff
path: root/src/test/regress/expected/compression.out
blob: 09f198149aa4f8d73f73e9e209f5852eea39d17b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
-- Default set of tests for TOAST compression, independent on compression
-- methods supported by the build.
CREATE SCHEMA pglz;
SET search_path TO pglz, public;
\set HIDE_TOAST_COMPRESSION false
-- ensure we get stable results regardless of installation's default
SET default_toast_compression = 'pglz';
-- test creating table with compression method
CREATE TABLE cmdata(f1 text COMPRESSION pglz);
CREATE INDEX idx ON cmdata(f1);
INSERT INTO cmdata VALUES(repeat('1234567890', 1000));
\d+ cmdata
                                         Table "pglz.cmdata"
 Column | Type | Collation | Nullable | Default | Storage  | Compression | Stats target | Description 
--------+------+-----------+----------+---------+----------+-------------+--------------+-------------
 f1     | text |           |          |         | extended | pglz        |              | 
Indexes:
    "idx" btree (f1)

-- verify stored compression method in the data
SELECT pg_column_compression(f1) FROM cmdata;
 pg_column_compression 
-----------------------
 pglz
(1 row)

-- decompress data slice
SELECT SUBSTR(f1, 200, 5) FROM cmdata;
 substr 
--------
 01234
(1 row)

-- copy with table creation
SELECT * INTO cmmove1 FROM cmdata;
\d+ cmmove1
                                         Table "pglz.cmmove1"
 Column | Type | Collation | Nullable | Default | Storage  | Compression | Stats target | Description 
--------+------+-----------+----------+---------+----------+-------------+--------------+-------------
 f1     | text |           |          |         | extended |             |              | 

SELECT pg_column_compression(f1) FROM cmmove1;
 pg_column_compression 
-----------------------
 pglz
(1 row)

-- try setting compression for incompressible data type
CREATE TABLE cmdata2 (f1 int COMPRESSION pglz);
ERROR:  column data type integer does not support compression
-- test externally stored compressed data
CREATE OR REPLACE FUNCTION large_val() RETURNS TEXT LANGUAGE SQL AS
'select array_agg(fipshash(g::text))::text from generate_series(1, 256) g';
CREATE TABLE cmdata2 (f1 text COMPRESSION pglz);
INSERT INTO cmdata2 SELECT large_val() || repeat('a', 4000);
SELECT pg_column_compression(f1) FROM cmdata2;
 pg_column_compression 
-----------------------
 pglz
(1 row)

SELECT SUBSTR(f1, 200, 5) FROM cmdata2;
 substr 
--------
 79026
(1 row)

DROP TABLE cmdata2;
--test column type update varlena/non-varlena
CREATE TABLE cmdata2 (f1 int);
\d+ cmdata2
                                          Table "pglz.cmdata2"
 Column |  Type   | Collation | Nullable | Default | Storage | Compression | Stats target | Description 
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
 f1     | integer |           |          |         | plain   |             |              | 

ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE varchar;
\d+ cmdata2
                                               Table "pglz.cmdata2"
 Column |       Type        | Collation | Nullable | Default | Storage  | Compression | Stats target | Description 
--------+-------------------+-----------+----------+---------+----------+-------------+--------------+-------------
 f1     | character varying |           |          |         | extended |             |              | 

ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE int USING f1::integer;
\d+ cmdata2
                                          Table "pglz.cmdata2"
 Column |  Type   | Collation | Nullable | Default | Storage | Compression | Stats target | Description 
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
 f1     | integer |           |          |         | plain   |             |              | 

--changing column storage should not impact the compression method
--but the data should not be compressed
ALTER TABLE cmdata2 ALTER COLUMN f1 TYPE varchar;
ALTER TABLE cmdata2 ALTER COLUMN f1 SET COMPRESSION pglz;
\d+ cmdata2
                                               Table "pglz.cmdata2"
 Column |       Type        | Collation | Nullable | Default | Storage  | Compression | Stats target | Description 
--------+-------------------+-----------+----------+---------+----------+-------------+--------------+-------------
 f1     | character varying |           |          |         | extended | pglz        |              | 

ALTER TABLE cmdata2 ALTER COLUMN f1 SET STORAGE plain;
\d+ cmdata2
                                               Table "pglz.cmdata2"
 Column |       Type        | Collation | Nullable | Default | Storage | Compression | Stats target | Description 
--------+-------------------+-----------+----------+---------+---------+-------------+--------------+-------------
 f1     | character varying |           |          |         | plain   | pglz        |              | 

INSERT INTO cmdata2 VALUES (repeat('123456789', 800));
SELECT pg_column_compression(f1) FROM cmdata2;
 pg_column_compression 
-----------------------
 
(1 row)

-- test compression with inheritance
CREATE TABLE cmdata3(f1 text);
CREATE TABLE cminh() INHERITS (cmdata, cmdata3);
NOTICE:  merging multiple inherited definitions of column "f1"
-- test default_toast_compression GUC
-- suppress machine-dependent details
\set VERBOSITY terse
SET default_toast_compression = '';
ERROR:  invalid value for parameter "default_toast_compression": ""
SET default_toast_compression = 'I do not exist compression';
ERROR:  invalid value for parameter "default_toast_compression": "I do not exist compression"
SET default_toast_compression = 'pglz';
\set VERBOSITY default
ALTER TABLE cmdata2 ALTER COLUMN f1 SET COMPRESSION default;
\d+ cmdata2
                                               Table "pglz.cmdata2"
 Column |       Type        | Collation | Nullable | Default | Storage | Compression | Stats target | Description 
--------+-------------------+-----------+----------+---------+---------+-------------+--------------+-------------
 f1     | character varying |           |          |         | plain   |             |              | 

DROP TABLE cmdata2;
-- VACUUM FULL does not recompress
SELECT pg_column_compression(f1) FROM cmdata;
 pg_column_compression 
-----------------------
 pglz
(1 row)

VACUUM FULL cmdata;
SELECT pg_column_compression(f1) FROM cmdata;
 pg_column_compression 
-----------------------
 pglz
(1 row)

-- check data is ok
SELECT length(f1) FROM cmdata;
 length 
--------
  10000
(1 row)

SELECT length(f1) FROM cmmove1;
 length 
--------
  10000
(1 row)

CREATE TABLE badcompresstbl (a text COMPRESSION I_Do_Not_Exist_Compression); -- fails
ERROR:  invalid compression method "i_do_not_exist_compression"
CREATE TABLE badcompresstbl (a text);
ALTER TABLE badcompresstbl ALTER a SET COMPRESSION I_Do_Not_Exist_Compression; -- fails
ERROR:  invalid compression method "i_do_not_exist_compression"
DROP TABLE badcompresstbl;
\set HIDE_TOAST_COMPRESSION true