Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 33975bb

Browse files
committed
[refer #PGPRO-2887] Add global_temp test
1 parent 4d73a65 commit 33975bb

File tree

5 files changed

+87
-79
lines changed

5 files changed

+87
-79
lines changed

src/backend/parser/parse_utilcmd.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,14 @@ generateSerialExtraStmts(CreateStmtContext *cxt, ColumnDef *column,
435435
seqstmt->for_identity = for_identity;
436436
seqstmt->sequence = makeRangeVar(snamespace, sname, -1);
437437
seqstmt->options = seqoptions;
438-
seqstmt->sequence->relpersistence = cxt->relation->relpersistence;
438+
439+
/*
440+
* Why we should not always use persistence of parent table?
441+
* Although it is prohibited to have unlogged sequences,
442+
* unlogged tables with SERIAL fields are accepted!
443+
*/
444+
if (cxt->relation->relpersistence != RELPERSISTENCE_UNLOGGED)
445+
seqstmt->sequence->relpersistence = cxt->relation->relpersistence;
439446

440447
/*
441448
* If a sequence data type was specified, add it to the options. Prepend

src/test/regress/expected/global_temp.out

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,64 @@
33
-- Test global temp relations
44
--
55
-- Test ON COMMIT DELETE ROWS
6-
CREATE GLOBAL TEMP TABLE temptest(col int) ON COMMIT DELETE ROWS;
6+
CREATE GLOBAL TEMP TABLE global_temptest(col int) ON COMMIT DELETE ROWS;
77
BEGIN;
8-
INSERT INTO temptest VALUES (1);
9-
INSERT INTO temptest VALUES (2);
10-
SELECT * FROM temptest;
8+
INSERT INTO global_temptest VALUES (1);
9+
INSERT INTO global_temptest VALUES (2);
10+
SELECT * FROM global_temptest;
1111
col
1212
-----
1313
1
1414
2
1515
(2 rows)
1616

1717
COMMIT;
18-
SELECT * FROM temptest;
18+
SELECT * FROM global_temptest;
1919
col
2020
-----
2121
(0 rows)
2222

23-
DROP TABLE temptest;
23+
DROP TABLE global_temptest;
2424
BEGIN;
25-
CREATE GLOBAL TEMP TABLE temptest(col) ON COMMIT DELETE ROWS AS SELECT 1;
26-
SELECT * FROM temptest;
25+
CREATE GLOBAL TEMP TABLE global_temptest(col) ON COMMIT DELETE ROWS AS SELECT 1;
26+
SELECT * FROM global_temptest;
2727
col
2828
-----
2929
1
3030
(1 row)
3131

3232
COMMIT;
33-
SELECT * FROM temptest;
33+
SELECT * FROM global_temptest;
3434
col
3535
-----
3636
(0 rows)
3737

38-
DROP TABLE temptest;
38+
DROP TABLE global_temptest;
3939
-- Test foreign keys
4040
BEGIN;
41-
CREATE GLOBAL TEMP TABLE temptest1(col int PRIMARY KEY);
42-
CREATE GLOBAL TEMP TABLE temptest2(col int REFERENCES temptest1)
41+
CREATE GLOBAL TEMP TABLE global_temptest1(col int PRIMARY KEY);
42+
CREATE GLOBAL TEMP TABLE global_temptest2(col int REFERENCES global_temptest1)
4343
ON COMMIT DELETE ROWS;
44-
INSERT INTO temptest1 VALUES (1);
45-
INSERT INTO temptest2 VALUES (1);
44+
INSERT INTO global_temptest1 VALUES (1);
45+
INSERT INTO global_temptest2 VALUES (1);
4646
COMMIT;
47-
SELECT * FROM temptest1;
47+
SELECT * FROM global_temptest1;
4848
col
4949
-----
5050
1
5151
(1 row)
5252

53-
SELECT * FROM temptest2;
53+
SELECT * FROM global_temptest2;
5454
col
5555
-----
5656
(0 rows)
5757

5858
BEGIN;
59-
CREATE GLOBAL TEMP TABLE temptest3(col int PRIMARY KEY) ON COMMIT DELETE ROWS;
60-
CREATE GLOBAL TEMP TABLE temptest4(col int REFERENCES temptest3);
59+
CREATE GLOBAL TEMP TABLE global_temptest3(col int PRIMARY KEY) ON COMMIT DELETE ROWS;
60+
CREATE GLOBAL TEMP TABLE global_temptest4(col int REFERENCES global_temptest3);
6161
COMMIT;
6262
ERROR: unsupported ON COMMIT and foreign key combination
63-
DETAIL: Table "temptest4" references "temptest3", but they do not have the same ON COMMIT setting.
63+
DETAIL: Table "global_temptest4" references "global_temptest3", but they do not have the same ON COMMIT setting.
6464
-- For partitioned temp tables, ON COMMIT actions ignore storage-less
6565
-- partitioned tables.
6666
BEGIN;
@@ -81,55 +81,55 @@ DROP TABLE temp_parted_oncommit;
8181
-- Using ON COMMIT DELETE on a partitioned table does not remove
8282
-- all rows if partitions preserve their data.
8383
BEGIN;
84-
CREATE GLOBAL TEMP TABLE temp_parted_oncommit_test (a int)
84+
CREATE GLOBAL TEMP TABLE global_temp_parted_oncommit_test (a int)
8585
PARTITION BY LIST (a) ON COMMIT DELETE ROWS;
86-
CREATE GLOBAL TEMP TABLE temp_parted_oncommit_test1
87-
PARTITION OF temp_parted_oncommit_test
86+
CREATE GLOBAL TEMP TABLE global_temp_parted_oncommit_test1
87+
PARTITION OF global_temp_parted_oncommit_test
8888
FOR VALUES IN (1) ON COMMIT PRESERVE ROWS;
89-
INSERT INTO temp_parted_oncommit_test VALUES (1);
89+
INSERT INTO global_temp_parted_oncommit_test VALUES (1);
9090
COMMIT;
9191
-- Data from the remaining partition is still here as its rows are
9292
-- preserved.
93-
SELECT * FROM temp_parted_oncommit_test;
93+
SELECT * FROM global_temp_parted_oncommit_test;
9494
a
9595
---
9696
1
9797
(1 row)
9898

9999
-- two relations remain in this case.
100-
SELECT relname FROM pg_class WHERE relname LIKE 'temp_parted_oncommit_test%';
101-
relname
102-
----------------------------
103-
temp_parted_oncommit_test
104-
temp_parted_oncommit_test1
100+
SELECT relname FROM pg_class WHERE relname LIKE 'global_temp_parted_oncommit_test%';
101+
relname
102+
-----------------------------------
103+
global_temp_parted_oncommit_test
104+
global_temp_parted_oncommit_test1
105105
(2 rows)
106106

107-
DROP TABLE temp_parted_oncommit_test;
107+
DROP TABLE global_temp_parted_oncommit_test;
108108
-- Check dependencies between ON COMMIT actions with inheritance trees.
109109
-- Data on the parent is removed, and the child goes away.
110110
BEGIN;
111-
CREATE GLOBAL TEMP TABLE temp_inh_oncommit_test (a int) ON COMMIT DELETE ROWS;
112-
CREATE GLOBAL TEMP TABLE temp_inh_oncommit_test1 ()
113-
INHERITS(temp_inh_oncommit_test) ON COMMIT PRESERVE ROWS;
114-
INSERT INTO temp_inh_oncommit_test1 VALUES (1);
115-
INSERT INTO temp_inh_oncommit_test VALUES (1);
111+
CREATE GLOBAL TEMP TABLE global_temp_inh_oncommit_test (a int) ON COMMIT DELETE ROWS;
112+
CREATE GLOBAL TEMP TABLE global_temp_inh_oncommit_test1 ()
113+
INHERITS(global_temp_inh_oncommit_test) ON COMMIT PRESERVE ROWS;
114+
INSERT INTO global_temp_inh_oncommit_test1 VALUES (1);
115+
INSERT INTO global_temp_inh_oncommit_test VALUES (1);
116116
COMMIT;
117-
SELECT * FROM temp_inh_oncommit_test;
117+
SELECT * FROM global_temp_inh_oncommit_test;
118118
a
119119
---
120120
1
121121
(1 row)
122122

123123
-- two relations remain
124-
SELECT relname FROM pg_class WHERE relname LIKE 'temp_inh_oncommit_test%';
125-
relname
126-
-------------------------
127-
temp_inh_oncommit_test
128-
temp_inh_oncommit_test1
124+
SELECT relname FROM pg_class WHERE relname LIKE 'global_temp_inh_oncommit_test%';
125+
relname
126+
--------------------------------
127+
global_temp_inh_oncommit_test
128+
global_temp_inh_oncommit_test1
129129
(2 rows)
130130

131-
DROP TABLE temp_inh_oncommit_test1;
132-
DROP TABLE temp_inh_oncommit_test;
131+
DROP TABLE global_temp_inh_oncommit_test1;
132+
DROP TABLE global_temp_inh_oncommit_test;
133133
-- Global temp table cannot inherit from temporary relation
134134
BEGIN;
135135
CREATE TEMP TABLE global_temp_table (a int) ON COMMIT DELETE ROWS;

src/test/regress/parallel_schedule

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ test: json jsonb json_encoding jsonpath jsonpath_encoding jsonb_jsonpath
107107
# NB: temp.sql does a reconnect which transiently uses 2 connections,
108108
# so keep this parallel group to at most 19 tests
109109
# ----------
110-
test: plancache limit plpgsql copy2 temp session_table domain rangefuncs prepare conversion truncate alter_table sequence polymorphism rowtypes returning largeobject with xml
110+
test: plancache limit plpgsql copy2 temp global_temp session_table domain rangefuncs prepare conversion truncate alter_table sequence polymorphism rowtypes returning largeobject with xml
111111

112112
# ----------
113113
# Another group of parallel tests

src/test/regress/serial_schedule

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ test: limit
172172
test: plpgsql
173173
test: copy2
174174
test: temp
175+
test: global_temp
175176
test: session_table
176177
test: domain
177178
test: rangefuncs

src/test/regress/sql/global_temp.sql

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,43 @@
55

66
-- Test ON COMMIT DELETE ROWS
77

8-
CREATE GLOBAL TEMP TABLE temptest(col int) ON COMMIT DELETE ROWS;
8+
CREATE GLOBAL TEMP TABLE global_temptest(col int) ON COMMIT DELETE ROWS;
99

1010
BEGIN;
11-
INSERT INTO temptest VALUES (1);
12-
INSERT INTO temptest VALUES (2);
11+
INSERT INTO global_temptest VALUES (1);
12+
INSERT INTO global_temptest VALUES (2);
1313

14-
SELECT * FROM temptest;
14+
SELECT * FROM global_temptest;
1515
COMMIT;
1616

17-
SELECT * FROM temptest;
17+
SELECT * FROM global_temptest;
1818

19-
DROP TABLE temptest;
19+
DROP TABLE global_temptest;
2020

2121
BEGIN;
22-
CREATE GLOBAL TEMP TABLE temptest(col) ON COMMIT DELETE ROWS AS SELECT 1;
22+
CREATE GLOBAL TEMP TABLE global_temptest(col) ON COMMIT DELETE ROWS AS SELECT 1;
2323

24-
SELECT * FROM temptest;
24+
SELECT * FROM global_temptest;
2525
COMMIT;
2626

27-
SELECT * FROM temptest;
27+
SELECT * FROM global_temptest;
2828

29-
DROP TABLE temptest;
29+
DROP TABLE global_temptest;
3030

3131
-- Test foreign keys
3232
BEGIN;
33-
CREATE GLOBAL TEMP TABLE temptest1(col int PRIMARY KEY);
34-
CREATE GLOBAL TEMP TABLE temptest2(col int REFERENCES temptest1)
33+
CREATE GLOBAL TEMP TABLE global_temptest1(col int PRIMARY KEY);
34+
CREATE GLOBAL TEMP TABLE global_temptest2(col int REFERENCES global_temptest1)
3535
ON COMMIT DELETE ROWS;
36-
INSERT INTO temptest1 VALUES (1);
37-
INSERT INTO temptest2 VALUES (1);
36+
INSERT INTO global_temptest1 VALUES (1);
37+
INSERT INTO global_temptest2 VALUES (1);
3838
COMMIT;
39-
SELECT * FROM temptest1;
40-
SELECT * FROM temptest2;
39+
SELECT * FROM global_temptest1;
40+
SELECT * FROM global_temptest2;
4141

4242
BEGIN;
43-
CREATE GLOBAL TEMP TABLE temptest3(col int PRIMARY KEY) ON COMMIT DELETE ROWS;
44-
CREATE GLOBAL TEMP TABLE temptest4(col int REFERENCES temptest3);
43+
CREATE GLOBAL TEMP TABLE global_temptest3(col int PRIMARY KEY) ON COMMIT DELETE ROWS;
44+
CREATE GLOBAL TEMP TABLE global_temptest4(col int REFERENCES global_temptest3);
4545
COMMIT;
4646

4747
-- For partitioned temp tables, ON COMMIT actions ignore storage-less
@@ -61,34 +61,34 @@ DROP TABLE temp_parted_oncommit;
6161
-- Using ON COMMIT DELETE on a partitioned table does not remove
6262
-- all rows if partitions preserve their data.
6363
BEGIN;
64-
CREATE GLOBAL TEMP TABLE temp_parted_oncommit_test (a int)
64+
CREATE GLOBAL TEMP TABLE global_temp_parted_oncommit_test (a int)
6565
PARTITION BY LIST (a) ON COMMIT DELETE ROWS;
66-
CREATE GLOBAL TEMP TABLE temp_parted_oncommit_test1
67-
PARTITION OF temp_parted_oncommit_test
66+
CREATE GLOBAL TEMP TABLE global_temp_parted_oncommit_test1
67+
PARTITION OF global_temp_parted_oncommit_test
6868
FOR VALUES IN (1) ON COMMIT PRESERVE ROWS;
69-
INSERT INTO temp_parted_oncommit_test VALUES (1);
69+
INSERT INTO global_temp_parted_oncommit_test VALUES (1);
7070
COMMIT;
7171
-- Data from the remaining partition is still here as its rows are
7272
-- preserved.
73-
SELECT * FROM temp_parted_oncommit_test;
73+
SELECT * FROM global_temp_parted_oncommit_test;
7474
-- two relations remain in this case.
75-
SELECT relname FROM pg_class WHERE relname LIKE 'temp_parted_oncommit_test%';
76-
DROP TABLE temp_parted_oncommit_test;
75+
SELECT relname FROM pg_class WHERE relname LIKE 'global_temp_parted_oncommit_test%';
76+
DROP TABLE global_temp_parted_oncommit_test;
7777

7878
-- Check dependencies between ON COMMIT actions with inheritance trees.
7979
-- Data on the parent is removed, and the child goes away.
8080
BEGIN;
81-
CREATE GLOBAL TEMP TABLE temp_inh_oncommit_test (a int) ON COMMIT DELETE ROWS;
82-
CREATE GLOBAL TEMP TABLE temp_inh_oncommit_test1 ()
83-
INHERITS(temp_inh_oncommit_test) ON COMMIT PRESERVE ROWS;
84-
INSERT INTO temp_inh_oncommit_test1 VALUES (1);
85-
INSERT INTO temp_inh_oncommit_test VALUES (1);
81+
CREATE GLOBAL TEMP TABLE global_temp_inh_oncommit_test (a int) ON COMMIT DELETE ROWS;
82+
CREATE GLOBAL TEMP TABLE global_temp_inh_oncommit_test1 ()
83+
INHERITS(global_temp_inh_oncommit_test) ON COMMIT PRESERVE ROWS;
84+
INSERT INTO global_temp_inh_oncommit_test1 VALUES (1);
85+
INSERT INTO global_temp_inh_oncommit_test VALUES (1);
8686
COMMIT;
87-
SELECT * FROM temp_inh_oncommit_test;
87+
SELECT * FROM global_temp_inh_oncommit_test;
8888
-- two relations remain
89-
SELECT relname FROM pg_class WHERE relname LIKE 'temp_inh_oncommit_test%';
90-
DROP TABLE temp_inh_oncommit_test1;
91-
DROP TABLE temp_inh_oncommit_test;
89+
SELECT relname FROM pg_class WHERE relname LIKE 'global_temp_inh_oncommit_test%';
90+
DROP TABLE global_temp_inh_oncommit_test1;
91+
DROP TABLE global_temp_inh_oncommit_test;
9292

9393
-- Global temp table cannot inherit from temporary relation
9494
BEGIN;

0 commit comments

Comments
 (0)