Skip to content

Commit 5fad6f3

Browse files
committed
fix tests
1 parent 996414d commit 5fad6f3

File tree

6 files changed

+89
-54
lines changed

6 files changed

+89
-54
lines changed

src/backend/access/compression/cm_pglz.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pglz_cmdecompress(CompressionAmOptions *cmoptions, const struct varlena *value)
148148
if (rawsize < 0)
149149
elog(ERROR, "pglz: compressed data is corrupted");
150150

151-
SET_VARSIZE(result, rawsize);
151+
SET_VARSIZE(result, rawsize + VARHDRSZ);
152152
return result;
153153
}
154154

@@ -170,7 +170,7 @@ pglz_cmdecompress_slice(CompressionAmOptions *cmoptions, const struct varlena *v
170170
if (rawsize < 0)
171171
elog(ERROR, "pglz: compressed data is corrupted");
172172

173-
SET_VARSIZE(result, rawsize);
173+
SET_VARSIZE(result, rawsize + VARHDRSZ);
174174
return result;
175175
}
176176

src/backend/access/compression/cm_zlib.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ zlib_cmcheck(Form_pg_attribute att, List *options)
4444

4545
if (strcmp(def->defname, "level") == 0)
4646
{
47-
if (strcmp(defGetString(def), "best_speed") != 0 &&
48-
strcmp(defGetString(def), "best_compression") != 0 &&
49-
strcmp(defGetString(def), "default") != 0)
47+
int8 level = pg_atoi(defGetString(def), sizeof(int8), 0);
48+
if (level < 0 || level > 9)
5049
ereport(ERROR,
51-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
52-
errmsg("unexpected value for zlib compression level: \"%s\"", defGetString(def))));
50+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
51+
errmsg("unexpected value for zlib compression level: \"%s\"",
52+
defGetString(def)),
53+
errhint("expected value between 0 and 9")
54+
));
5355
}
5456
else if (strcmp(def->defname, "dict") == 0)
5557
{
@@ -98,12 +100,7 @@ zlib_cminitstate(Oid acoid, List *options)
98100
DefElem *def = (DefElem *) lfirst(lc);
99101

100102
if (strcmp(def->defname, "level") == 0)
101-
{
102-
if (strcmp(defGetString(def), "best_speed") == 0)
103-
state->level = Z_BEST_SPEED;
104-
else if (strcmp(defGetString(def), "best_compression") == 0)
105-
state->level = Z_BEST_COMPRESSION;
106-
}
103+
state->level = pg_atoi(defGetString(def), sizeof(int), 0);
107104
else if (strcmp(def->defname, "dict") == 0)
108105
{
109106
char *val,

src/backend/access/index/amapi.c

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "access/htup_details.h"
1818
#include "catalog/pg_am.h"
1919
#include "catalog/pg_opclass.h"
20-
#include "commands/defrem.h"
2120
#include "utils/builtins.h"
2221
#include "utils/syscache.h"
2322

@@ -56,12 +55,52 @@ GetIndexAmRoutine(Oid amhandler)
5655
IndexAmRoutine *
5756
GetIndexAmRoutineByAmId(Oid amoid, bool noerror)
5857
{
58+
HeapTuple tuple;
59+
Form_pg_am amform;
5960
regproc amhandler;
6061

6162
/* Get handler function OID for the access method */
62-
amhandler = get_am_handler_oid(amoid, AMTYPE_INDEX, noerror);
63-
if (noerror && !RegProcedureIsValid(amhandler))
64-
return NULL;
63+
tuple = SearchSysCache1(AMOID, ObjectIdGetDatum(amoid));
64+
if (!HeapTupleIsValid(tuple))
65+
{
66+
if (noerror)
67+
return NULL;
68+
elog(ERROR, "cache lookup failed for access method %u",
69+
amoid);
70+
}
71+
amform = (Form_pg_am) GETSTRUCT(tuple);
72+
73+
/* Check if it's an index access method as opposed to some other AM */
74+
if (amform->amtype != AMTYPE_INDEX)
75+
{
76+
if (noerror)
77+
{
78+
ReleaseSysCache(tuple);
79+
return NULL;
80+
}
81+
ereport(ERROR,
82+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
83+
errmsg("access method \"%s\" is not of type %s",
84+
NameStr(amform->amname), "INDEX")));
85+
}
86+
87+
amhandler = amform->amhandler;
88+
89+
/* Complain if handler OID is invalid */
90+
if (!RegProcedureIsValid(amhandler))
91+
{
92+
if (noerror)
93+
{
94+
ReleaseSysCache(tuple);
95+
return NULL;
96+
}
97+
ereport(ERROR,
98+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
99+
errmsg("index access method \"%s\" does not have a handler",
100+
NameStr(amform->amname))));
101+
}
102+
103+
ReleaseSysCache(tuple);
65104

66105
/* And finally, call the handler function to get the API struct. */
67106
return GetIndexAmRoutine(amhandler);

src/backend/commands/compressioncmds.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
#include "catalog/catalog.h"
2323
#include "catalog/dependency.h"
2424
#include "catalog/indexing.h"
25-
#include "catalog/pg_attr_compression.h"
26-
#include "catalog/pg_am.h"
25+
#include "catalog/pg_attr_compression_d.h"
26+
#include "catalog/pg_am_d.h"
27+
#include "catalog/pg_collation_d.h"
2728
#include "catalog/pg_depend.h"
28-
#include "catalog/pg_proc.h"
29-
#include "catalog/pg_type.h"
29+
#include "catalog/pg_proc_d.h"
30+
#include "catalog/pg_type_d.h"
3031
#include "commands/defrem.h"
3132
#include "parser/parse_func.h"
3233
#include "utils/builtins.h"
@@ -160,7 +161,7 @@ lookup_attribute_compression(Oid attrelid, AttrNumber attnum,
160161

161162
/* check if arrays for WITH options are equal */
162163
equal = DatumGetBool(CallerFInfoFunctionCall2(
163-
array_eq, &arrayeq_info, InvalidOid, acoptions,
164+
array_eq, &arrayeq_info, DEFAULT_COLLATION_OID, acoptions,
164165
values[Anum_pg_attr_compression_acoptions - 1]));
165166

166167
if (equal)

src/test/regress/expected/create_cm.out

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ CREATE ACCESS METHOD pglz1 TYPE COMPRESSION HANDLER pglzhandler;
2020
CREATE ACCESS METHOD pglz2 TYPE COMPRESSION HANDLER pglzhandler;
2121
CREATE TABLE cmaltertest (f1 TEXT COMPRESSION pglz2);
2222
SELECT acname, acattnum, acoptions FROM pg_attr_compression
23-
WHERE acrelid = 'cmaltertest'::regclass;
23+
WHERE acrelid = 'cmaltertest'::REGCLASS;
2424
acname | acattnum | acoptions
2525
--------+----------+-----------
2626
pglz2 | 1 |
2727
(1 row)
2828

2929
ALTER TABLE cmaltertest DROP COLUMN f1;
3030
SELECT acname, acattnum, acoptions FROM pg_attr_compression
31-
WHERE acrelid = 'cmaltertest'::regclass;
31+
WHERE acrelid = 'cmaltertest'::REGCLASS;
3232
acname | acattnum | acoptions
3333
--------+----------+-----------
3434
(0 rows)
@@ -59,7 +59,7 @@ SELECT pg_column_compression('cmaltertest', 'at1');
5959
(1 row)
6060

6161
SELECT acname, acattnum, acoptions FROM pg_attr_compression
62-
WHERE acrelid = 'cmaltertest'::regclass;
62+
WHERE acrelid = 'cmaltertest'::REGCLASS;
6363
acname | acattnum | acoptions
6464
--------+----------+-----------
6565
(0 rows)
@@ -125,15 +125,16 @@ CREATE TABLE cmtest(f1 TEXT);
125125
CREATE VIEW cmtest_deps AS
126126
SELECT classid, objsubid, refclassid, refobjsubid, deptype
127127
FROM pg_depend
128-
WHERE (refclassid = 4001 OR classid = 4001) AND
129-
(objid = 'cmtest'::regclass OR refobjid = 'cmtest'::regclass)
128+
WHERE (refclassid = 'pg_catalog.pg_attr_compression'::REGCLASS OR
129+
classid = 'pg_catalog.pg_attr_compression'::REGCLASS) AND
130+
(objid = 'cmtest'::REGCLASS OR refobjid = 'cmtest'::REGCLASS)
130131
ORDER by objid, refobjid;
131132
INSERT INTO cmtest VALUES(repeat('1234567890',1001));
132133
-- one normal dependency
133134
SELECT * FROM cmtest_deps;
134135
classid | objsubid | refclassid | refobjsubid | deptype
135136
---------+----------+------------+-------------+---------
136-
1259 | 1 | 4001 | 0 | n
137+
1259 | 1 | 4189 | 0 | n
137138
(1 row)
138139

139140
-- check decompression
@@ -177,8 +178,8 @@ SELECT pg_column_compression('cmtest', 'f1');
177178
SELECT * FROM cmtest_deps;
178179
classid | objsubid | refclassid | refobjsubid | deptype
179180
---------+----------+------------+-------------+---------
180-
1259 | 1 | 4001 | 0 | n
181-
4001 | 0 | 1259 | 1 | i
181+
1259 | 1 | 4189 | 0 | n
182+
4189 | 0 | 1259 | 1 | i
182183
(2 rows)
183184

184185
-- rewrite
@@ -196,15 +197,15 @@ SELECT length(f1) FROM cmtest;
196197
SELECT pg_column_compression('cmtest', 'f1');
197198
pg_column_compression
198199
-----------------------
199-
pglz2, pglz1
200+
pglz1, pglz2
200201
(1 row)
201202

202203
-- two internal dependencies
203204
SELECT * FROM cmtest_deps;
204205
classid | objsubid | refclassid | refobjsubid | deptype
205206
---------+----------+------------+-------------+---------
206-
4001 | 0 | 1259 | 1 | i
207-
4001 | 0 | 1259 | 1 | i
207+
4189 | 0 | 1259 | 1 | i
208+
4189 | 0 | 1259 | 1 | i
208209
(2 rows)
209210

210211
-- rewrite
@@ -230,7 +231,7 @@ SELECT pg_column_compression('cmtest', 'f1');
230231
SELECT * FROM cmtest_deps;
231232
classid | objsubid | refclassid | refobjsubid | deptype
232233
---------+----------+------------+-------------+---------
233-
1259 | 1 | 4001 | 0 | n
234+
1259 | 1 | 4189 | 0 | n
234235
(1 row)
235236

236237
-- no rewrites
@@ -243,9 +244,9 @@ INSERT INTO cmtest VALUES(repeat('1234567890',1006));
243244
SELECT * FROM cmtest_deps;
244245
classid | objsubid | refclassid | refobjsubid | deptype
245246
---------+----------+------------+-------------+---------
246-
1259 | 1 | 4001 | 0 | n
247-
4001 | 0 | 1259 | 1 | i
248-
4001 | 0 | 1259 | 1 | i
247+
1259 | 1 | 4189 | 0 | n
248+
4189 | 0 | 1259 | 1 | i
249+
4189 | 0 | 1259 | 1 | i
249250
(3 rows)
250251

251252
-- remove function and related event trigger
@@ -346,7 +347,7 @@ SELECT pg_column_compression('cmaltertest', 'f1');
346347
SELECT pg_column_compression('cmaltertest', 'f2');
347348
pg_column_compression
348349
-----------------------
349-
pglz, pglz2, pglz1
350+
pglz, pglz1, pglz2
350351
(1 row)
351352

352353
-- make pglz2 droppable
@@ -364,7 +365,7 @@ SELECT pg_column_compression('cmaltertest', 'f2');
364365
(1 row)
365366

366367
SELECT acname, acattnum, acoptions FROM pg_attr_compression
367-
WHERE acrelid = 'cmaltertest'::regclass OR acrelid = 'cmtest'::regclass;
368+
WHERE acrelid = 'cmaltertest'::REGCLASS OR acrelid = 'cmtest'::REGCLASS;
368369
acname | acattnum | acoptions
369370
--------+----------+-----------------------
370371
pglz1 | 1 |
@@ -377,14 +378,12 @@ SELECT acname, acattnum, acoptions FROM pg_attr_compression
377378
CREATE TABLE zlibtest(f1 TEXT COMPRESSION zlib WITH (invalid 'param'));
378379
ERROR: unexpected parameter for zlib: "invalid"
379380
CREATE TABLE zlibtest(f1 TEXT COMPRESSION zlib WITH (level 'best'));
380-
ERROR: unexpected value for zlib compression level: "best"
381+
ERROR: invalid input syntax for type integer: "best"
381382
CREATE TABLE zlibtest(f1 TEXT COMPRESSION zlib);
382383
ALTER TABLE zlibtest
383-
ALTER COLUMN f1 SET COMPRESSION zlib WITH (level 'best_compression');
384+
ALTER COLUMN f1 SET COMPRESSION zlib WITH (level '9');
384385
ALTER TABLE zlibtest
385-
ALTER COLUMN f1 SET COMPRESSION zlib WITH (level 'best_speed');
386-
ALTER TABLE zlibtest
387-
ALTER COLUMN f1 SET COMPRESSION zlib WITH (level 'default');
386+
ALTER COLUMN f1 SET COMPRESSION zlib WITH (level '1');
388387
ALTER TABLE zlibtest
389388
ALTER COLUMN f1 SET COMPRESSION zlib WITH (dict 'one');
390389
ERROR: zlib dictionary is too small

src/test/regress/sql/create_cm.sql

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ CREATE ACCESS METHOD pglz1 TYPE COMPRESSION HANDLER pglzhandler;
1414
CREATE ACCESS METHOD pglz2 TYPE COMPRESSION HANDLER pglzhandler;
1515
CREATE TABLE cmaltertest (f1 TEXT COMPRESSION pglz2);
1616
SELECT acname, acattnum, acoptions FROM pg_attr_compression
17-
WHERE acrelid = 'cmaltertest'::regclass;
17+
WHERE acrelid = 'cmaltertest'::REGCLASS;
1818
ALTER TABLE cmaltertest DROP COLUMN f1;
1919
SELECT acname, acattnum, acoptions FROM pg_attr_compression
20-
WHERE acrelid = 'cmaltertest'::regclass;
20+
WHERE acrelid = 'cmaltertest'::REGCLASS;
2121
DROP TABLE cmaltertest;
2222

2323
-- test drop
@@ -31,7 +31,7 @@ ALTER TABLE cmaltertest ALTER COLUMN at1 SET DATA TYPE INT USING at1::INTEGER;
3131
\d+ cmaltertest
3232
SELECT pg_column_compression('cmaltertest', 'at1');
3333
SELECT acname, acattnum, acoptions FROM pg_attr_compression
34-
WHERE acrelid = 'cmaltertest'::regclass;
34+
WHERE acrelid = 'cmaltertest'::REGCLASS;
3535
ALTER TABLE cmaltertest ALTER COLUMN at1 SET DATA TYPE TEXT;
3636
SELECT pg_column_compression('cmaltertest', 'at1');
3737
DROP TABLE cmaltertest;
@@ -61,8 +61,9 @@ CREATE TABLE cmtest(f1 TEXT);
6161
CREATE VIEW cmtest_deps AS
6262
SELECT classid, objsubid, refclassid, refobjsubid, deptype
6363
FROM pg_depend
64-
WHERE (refclassid = 4001 OR classid = 4001) AND
65-
(objid = 'cmtest'::regclass OR refobjid = 'cmtest'::regclass)
64+
WHERE (refclassid = 'pg_catalog.pg_attr_compression'::REGCLASS OR
65+
classid = 'pg_catalog.pg_attr_compression'::REGCLASS) AND
66+
(objid = 'cmtest'::REGCLASS OR refobjid = 'cmtest'::REGCLASS)
6667
ORDER by objid, refobjid;
6768
INSERT INTO cmtest VALUES(repeat('1234567890',1001));
6869

@@ -177,18 +178,16 @@ SELECT pg_column_compression('cmaltertest', 'f1');
177178
SELECT pg_column_compression('cmaltertest', 'f2');
178179

179180
SELECT acname, acattnum, acoptions FROM pg_attr_compression
180-
WHERE acrelid = 'cmaltertest'::regclass OR acrelid = 'cmtest'::regclass;
181+
WHERE acrelid = 'cmaltertest'::REGCLASS OR acrelid = 'cmtest'::REGCLASS;
181182

182183
-- zlib compression
183184
CREATE TABLE zlibtest(f1 TEXT COMPRESSION zlib WITH (invalid 'param'));
184185
CREATE TABLE zlibtest(f1 TEXT COMPRESSION zlib WITH (level 'best'));
185186
CREATE TABLE zlibtest(f1 TEXT COMPRESSION zlib);
186187
ALTER TABLE zlibtest
187-
ALTER COLUMN f1 SET COMPRESSION zlib WITH (level 'best_compression');
188+
ALTER COLUMN f1 SET COMPRESSION zlib WITH (level '9');
188189
ALTER TABLE zlibtest
189-
ALTER COLUMN f1 SET COMPRESSION zlib WITH (level 'best_speed');
190-
ALTER TABLE zlibtest
191-
ALTER COLUMN f1 SET COMPRESSION zlib WITH (level 'default');
190+
ALTER COLUMN f1 SET COMPRESSION zlib WITH (level '1');
192191
ALTER TABLE zlibtest
193192
ALTER COLUMN f1 SET COMPRESSION zlib WITH (dict 'one');
194193
INSERT INTO zlibtest VALUES(repeat('1234567890',1004));

0 commit comments

Comments
 (0)