Skip to content

Commit 39ef2bd

Browse files
bmdoilavamingli
authored andcommitted
Revert "Ban enums as distribution and partition keys"
This reverts commit a863997e6459e907979478f013b588447385ca07. The issues with restoring enums in distribution and partition keys has been resolved in pg_dump by the cherry-pick of 7e7c5b683985c85fb990c4d49ab960cbc83434b4. A gpbackup fix disables gp_enable_segment_copy_checking before loading a table/matview with an enum hash distribution/partition, then reorganizing the table after it's loaded and resetting the GUC. With these two changes it's safe to unban enums as distribution and hash keys.
1 parent 91c28e9 commit 39ef2bd

File tree

15 files changed

+145
-234
lines changed

15 files changed

+145
-234
lines changed
Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
set enable_seqscan=off;
22
CREATE TYPE rainbow AS ENUM ('r','o','y','g','b','i','v');
33
CREATE TABLE test_enum (
4-
h int,
54
i rainbow
65
);
7-
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'h' as the Greenplum Database data distribution key for this table.
8-
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
9-
INSERT INTO test_enum VALUES (1, 'v'),(2, 'y'),(3, 'r'),(4, 'g'),(5, 'o'),(6, 'i'),(7, 'b');
6+
INSERT INTO test_enum VALUES ('v'),('y'),('r'),('g'),('o'),('i'),('b');
107
CREATE INDEX idx_enum ON test_enum USING gin (i);
11-
SELECT i FROM test_enum WHERE i<'g'::rainbow ORDER BY i;
8+
SELECT * FROM test_enum WHERE i<'g'::rainbow ORDER BY i;
129
i
1310
---
1411
r
1512
o
1613
y
1714
(3 rows)
1815

19-
SELECT i FROM test_enum WHERE i<='g'::rainbow ORDER BY i;
16+
SELECT * FROM test_enum WHERE i<='g'::rainbow ORDER BY i;
2017
i
2118
---
2219
r
@@ -25,13 +22,13 @@ SELECT i FROM test_enum WHERE i<='g'::rainbow ORDER BY i;
2522
g
2623
(4 rows)
2724

28-
SELECT i FROM test_enum WHERE i='g'::rainbow ORDER BY i;
25+
SELECT * FROM test_enum WHERE i='g'::rainbow ORDER BY i;
2926
i
3027
---
3128
g
3229
(1 row)
3330

34-
SELECT i FROM test_enum WHERE i>='g'::rainbow ORDER BY i;
31+
SELECT * FROM test_enum WHERE i>='g'::rainbow ORDER BY i;
3532
i
3633
---
3734
g
@@ -40,15 +37,15 @@ SELECT i FROM test_enum WHERE i>='g'::rainbow ORDER BY i;
4037
v
4138
(4 rows)
4239

43-
SELECT i FROM test_enum WHERE i>'g'::rainbow ORDER BY i;
40+
SELECT * FROM test_enum WHERE i>'g'::rainbow ORDER BY i;
4441
i
4542
---
4643
b
4744
i
4845
v
4946
(3 rows)
5047

51-
explain (costs off) SELECT i FROM test_enum WHERE i>='g'::rainbow ORDER BY i;
48+
explain (costs off) SELECT * FROM test_enum WHERE i>='g'::rainbow ORDER BY i;
5249
QUERY PLAN
5350
-----------------------------------------------------
5451
Gather Motion 3:1 (slice1; segments: 3)
@@ -59,17 +56,11 @@ explain (costs off) SELECT i FROM test_enum WHERE i>='g'::rainbow ORDER BY i;
5956
Recheck Cond: (i >= 'g'::rainbow)
6057
-> Bitmap Index Scan on idx_enum
6158
Index Cond: (i >= 'g'::rainbow)
62-
Optimizer: Pivotal Optimizer (GPORCA)
59+
Optimizer: Postgres query optimizer
6360
(9 rows)
6461

6562
-- make sure we handle the non-evenly-numbered oid case for enums
6663
create type e as enum ('0', '2', '3');
6764
alter type e add value '1' after '0';
68-
CREATE TABLE t (
69-
h int,
70-
i e
71-
);
72-
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'h' as the Greenplum Database data distribution key for this table.
73-
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
74-
insert into t select j, (j % 4)::text::e from generate_series(0, 100000) as j;
75-
create index on t using gin (i);
65+
create table t as select (i % 4)::text::e from generate_series(0, 100000) as i;
66+
create index on t using gin (e);

contrib/btree_gin/sql/enum.sql

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
11
set enable_seqscan=off;
2+
23
CREATE TYPE rainbow AS ENUM ('r','o','y','g','b','i','v');
34

45
CREATE TABLE test_enum (
5-
h int,
66
i rainbow
77
);
88

9-
INSERT INTO test_enum VALUES (1, 'v'),(2, 'y'),(3, 'r'),(4, 'g'),(5, 'o'),(6, 'i'),(7, 'b');
9+
INSERT INTO test_enum VALUES ('v'),('y'),('r'),('g'),('o'),('i'),('b');
1010

1111
CREATE INDEX idx_enum ON test_enum USING gin (i);
1212

13-
SELECT i FROM test_enum WHERE i<'g'::rainbow ORDER BY i;
14-
SELECT i FROM test_enum WHERE i<='g'::rainbow ORDER BY i;
15-
SELECT i FROM test_enum WHERE i='g'::rainbow ORDER BY i;
16-
SELECT i FROM test_enum WHERE i>='g'::rainbow ORDER BY i;
17-
SELECT i FROM test_enum WHERE i>'g'::rainbow ORDER BY i;
13+
SELECT * FROM test_enum WHERE i<'g'::rainbow ORDER BY i;
14+
SELECT * FROM test_enum WHERE i<='g'::rainbow ORDER BY i;
15+
SELECT * FROM test_enum WHERE i='g'::rainbow ORDER BY i;
16+
SELECT * FROM test_enum WHERE i>='g'::rainbow ORDER BY i;
17+
SELECT * FROM test_enum WHERE i>'g'::rainbow ORDER BY i;
1818

19-
explain (costs off) SELECT i FROM test_enum WHERE i>='g'::rainbow ORDER BY i;
19+
explain (costs off) SELECT * FROM test_enum WHERE i>='g'::rainbow ORDER BY i;
2020

2121
-- make sure we handle the non-evenly-numbered oid case for enums
2222
create type e as enum ('0', '2', '3');
2323
alter type e add value '1' after '0';
24-
25-
CREATE TABLE t (
26-
h int,
27-
i e
28-
);
29-
insert into t select j, (j % 4)::text::e from generate_series(0, 100000) as j;
30-
create index on t using gin (i);
24+
create table t as select (i % 4)::text::e from generate_series(0, 100000) as i;
25+
create index on t using gin (e);

src/backend/commands/tablecmds.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21176,11 +21176,6 @@ ComputePartitionAttrs(ParseState *pstate, Relation rel, List *partParams, AttrNu
2117621176
}
2117721177
}
2117821178

21179-
if (strategy == PARTITION_STRATEGY_HASH && type_is_enum(atttype))
21180-
ereport(ERROR,
21181-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
21182-
errmsg("cannot use ENUM column \"%s\" in PARTITION BY statement for hash partitions", pelem->name)));
21183-
2118421179
/*
2118521180
* Apply collation override if any
2118621181
*/

src/backend/parser/parse_utilcmd.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3137,13 +3137,6 @@ getPolicyForDistributedBy(DistributedBy *distributedBy, TupleDesc tupdesc)
31373137
if (strcmp(colname, NameStr(attr->attname)) == 0)
31383138
{
31393139
Oid opclass;
3140-
Oid typid;
3141-
3142-
typid = getBaseType(attr->atttypid);
3143-
if (type_is_enum(typid))
3144-
ereport(ERROR,
3145-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3146-
errmsg("cannot use ENUM column \"%s\" in DISTRIBUTED BY statement", colname)));
31473140

31483141
opclass = cdb_get_opclass_for_column_def(dkelem->opclass, attr->atttypid);
31493142

src/test/regress/expected/enum.out

Lines changed: 85 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -198,71 +198,71 @@ ORDER BY enumsortorder;
198198
--
199199
-- Basic table creation, row selection
200200
--
201-
CREATE TABLE enumtest (i int, col rainbow);
202-
INSERT INTO enumtest values (1, 'red'), (2, 'orange'), (3, 'yellow'), (4, 'green');
203-
COPY enumtest (i, col) FROM stdin;
201+
CREATE TABLE enumtest (col rainbow);
202+
INSERT INTO enumtest values ('red'), ('orange'), ('yellow'), ('green');
203+
COPY enumtest FROM stdin;
204204
SELECT * FROM enumtest;
205-
i | col
206-
---+--------
207-
5 | blue
208-
6 | purple
209-
2 | orange
210-
3 | yellow
211-
4 | green
212-
1 | red
205+
col
206+
--------
207+
red
208+
orange
209+
yellow
210+
green
211+
blue
212+
purple
213213
(6 rows)
214214

215215
--
216216
-- Operators, no index
217217
--
218218
SELECT * FROM enumtest WHERE col = 'orange';
219-
i | col
220-
---+--------
221-
2 | orange
219+
col
220+
--------
221+
orange
222222
(1 row)
223223

224224
SELECT * FROM enumtest WHERE col <> 'orange' ORDER BY col;
225-
i | col
226-
---+--------
227-
1 | red
228-
3 | yellow
229-
4 | green
230-
5 | blue
231-
6 | purple
225+
col
226+
--------
227+
red
228+
yellow
229+
green
230+
blue
231+
purple
232232
(5 rows)
233233

234234
SELECT * FROM enumtest WHERE col > 'yellow' ORDER BY col;
235-
i | col
236-
---+--------
237-
4 | green
238-
5 | blue
239-
6 | purple
235+
col
236+
--------
237+
green
238+
blue
239+
purple
240240
(3 rows)
241241

242242
SELECT * FROM enumtest WHERE col >= 'yellow' ORDER BY col;
243-
i | col
244-
---+--------
245-
3 | yellow
246-
4 | green
247-
5 | blue
248-
6 | purple
243+
col
244+
--------
245+
yellow
246+
green
247+
blue
248+
purple
249249
(4 rows)
250250

251251
SELECT * FROM enumtest WHERE col < 'green' ORDER BY col;
252-
i | col
253-
---+--------
254-
1 | red
255-
2 | orange
256-
3 | yellow
252+
col
253+
--------
254+
red
255+
orange
256+
yellow
257257
(3 rows)
258258

259259
SELECT * FROM enumtest WHERE col <= 'green' ORDER BY col;
260-
i | col
261-
---+--------
262-
1 | red
263-
2 | orange
264-
3 | yellow
265-
4 | green
260+
col
261+
--------
262+
red
263+
orange
264+
yellow
265+
green
266266
(4 rows)
267267

268268
--
@@ -311,53 +311,53 @@ SET enable_bitmapscan = off;
311311
--
312312
CREATE INDEX enumtest_btree ON enumtest USING btree (col);
313313
SELECT * FROM enumtest WHERE col = 'orange';
314-
i | col
315-
---+--------
316-
2 | orange
314+
col
315+
--------
316+
orange
317317
(1 row)
318318

319319
SELECT * FROM enumtest WHERE col <> 'orange' ORDER BY col;
320-
i | col
321-
---+--------
322-
1 | red
323-
3 | yellow
324-
4 | green
325-
5 | blue
326-
6 | purple
320+
col
321+
--------
322+
red
323+
yellow
324+
green
325+
blue
326+
purple
327327
(5 rows)
328328

329329
SELECT * FROM enumtest WHERE col > 'yellow' ORDER BY col;
330-
i | col
331-
---+--------
332-
4 | green
333-
5 | blue
334-
6 | purple
330+
col
331+
--------
332+
green
333+
blue
334+
purple
335335
(3 rows)
336336

337337
SELECT * FROM enumtest WHERE col >= 'yellow' ORDER BY col;
338-
i | col
339-
---+--------
340-
3 | yellow
341-
4 | green
342-
5 | blue
343-
6 | purple
338+
col
339+
--------
340+
yellow
341+
green
342+
blue
343+
purple
344344
(4 rows)
345345

346346
SELECT * FROM enumtest WHERE col < 'green' ORDER BY col;
347-
i | col
348-
---+--------
349-
1 | red
350-
2 | orange
351-
3 | yellow
347+
col
348+
--------
349+
red
350+
orange
351+
yellow
352352
(3 rows)
353353

354354
SELECT * FROM enumtest WHERE col <= 'green' ORDER BY col;
355-
i | col
356-
---+--------
357-
1 | red
358-
2 | orange
359-
3 | yellow
360-
4 | green
355+
col
356+
--------
357+
red
358+
orange
359+
yellow
360+
green
361361
(4 rows)
362362

363363
SELECT min(col) FROM enumtest;
@@ -384,9 +384,9 @@ DROP INDEX enumtest_btree;
384384
--
385385
CREATE INDEX enumtest_hash ON enumtest USING hash (col);
386386
SELECT * FROM enumtest WHERE col = 'orange';
387-
i | col
388-
---+--------
389-
2 | orange
387+
col
388+
--------
389+
orange
390390
(1 row)
391391

392392
DROP INDEX enumtest_hash;
@@ -537,11 +537,11 @@ DROP FUNCTION echo_me(rainbow);
537537
--
538538
-- RI triggers on enum types
539539
--
540-
CREATE TABLE enumtest_parent (i int PRIMARY KEY, id rainbow);
541-
CREATE TABLE enumtest_child (i int REFERENCES enumtest_parent, parent rainbow);
542-
INSERT INTO enumtest_parent VALUES (1, 'red');
543-
INSERT INTO enumtest_child VALUES (1, 'red');
544-
INSERT INTO enumtest_child VALUES (2, 'blue'); -- fail
540+
CREATE TABLE enumtest_parent (id rainbow PRIMARY KEY);
541+
CREATE TABLE enumtest_child (parent rainbow REFERENCES enumtest_parent);
542+
INSERT INTO enumtest_parent VALUES ('red');
543+
INSERT INTO enumtest_child VALUES ('red');
544+
INSERT INTO enumtest_child VALUES ('blue'); -- fail
545545
-- start_ignore
546546
-- foreign keys are not checked in GPDB, hence these pass.
547547
-- end_ignore
@@ -550,9 +550,9 @@ DELETE FROM enumtest_parent; -- fail
550550
-- cross-type RI should fail
551551
--
552552
CREATE TYPE bogus AS ENUM('good', 'bad', 'ugly');
553-
CREATE TABLE enumtest_bogus_child(i int, parent bogus REFERENCES enumtest_parent);
553+
CREATE TABLE enumtest_bogus_child(parent bogus REFERENCES enumtest_parent);
554554
ERROR: foreign key constraint "enumtest_bogus_child_parent_fkey" cannot be implemented
555-
DETAIL: Key columns "parent" and "i" are of incompatible types: bogus and integer.
555+
DETAIL: Key columns "parent" and "id" are of incompatible types: bogus and rainbow.
556556
DROP TYPE bogus;
557557
-- check renaming a value
558558
ALTER TYPE rainbow RENAME VALUE 'red' TO 'crimson';

0 commit comments

Comments
 (0)