@@ -32,7 +32,10 @@ CREATE TABLE ptif_test1 PARTITION OF ptif_test
32
32
FOR VALUES FROM (0) TO (100) PARTITION BY list (b);
33
33
CREATE TABLE ptif_test11 PARTITION OF ptif_test1 FOR VALUES IN (1);
34
34
CREATE TABLE ptif_test2 PARTITION OF ptif_test
35
- FOR VALUES FROM (100) TO (maxvalue);
35
+ FOR VALUES FROM (100) TO (200);
36
+ -- This partitioned table should remain with no partitions.
37
+ CREATE TABLE ptif_test3 PARTITION OF ptif_test
38
+ FOR VALUES FROM (200) TO (maxvalue) PARTITION BY list (b);
36
39
-- Test index partition tree
37
40
CREATE INDEX ptif_test_index ON ONLY ptif_test (a);
38
41
CREATE INDEX ptif_test0_index ON ONLY ptif_test0 (a);
@@ -45,6 +48,8 @@ CREATE INDEX ptif_test11_index ON ptif_test11 (a);
45
48
ALTER INDEX ptif_test1_index ATTACH PARTITION ptif_test11_index;
46
49
CREATE INDEX ptif_test2_index ON ptif_test2 (a);
47
50
ALTER INDEX ptif_test_index ATTACH PARTITION ptif_test2_index;
51
+ CREATE INDEX ptif_test3_index ON ptif_test3 (a);
52
+ ALTER INDEX ptif_test_index ATTACH PARTITION ptif_test3_index;
48
53
-- List all tables members of the tree
49
54
SELECT relid, parentrelid, level, isleaf
50
55
FROM pg_partition_tree('ptif_test');
@@ -54,9 +59,10 @@ SELECT relid, parentrelid, level, isleaf
54
59
ptif_test0 | ptif_test | 1 | f
55
60
ptif_test1 | ptif_test | 1 | f
56
61
ptif_test2 | ptif_test | 1 | t
62
+ ptif_test3 | ptif_test | 1 | f
57
63
ptif_test01 | ptif_test0 | 2 | t
58
64
ptif_test11 | ptif_test1 | 2 | t
59
- (6 rows)
65
+ (7 rows)
60
66
61
67
-- List tables from an intermediate level
62
68
SELECT relid, parentrelid, level, isleaf
@@ -77,6 +83,15 @@ SELECT relid, parentrelid, level, isleaf
77
83
ptif_test01 | ptif_test0 | 0 | t
78
84
(1 row)
79
85
86
+ -- List from partitioned table with no partitions
87
+ SELECT relid, parentrelid, level, isleaf
88
+ FROM pg_partition_tree('ptif_test3') p
89
+ JOIN pg_class c ON (p.relid = c.oid);
90
+ relid | parentrelid | level | isleaf
91
+ ------------+-------------+-------+--------
92
+ ptif_test3 | ptif_test | 0 | f
93
+ (1 row)
94
+
80
95
-- List all members using pg_partition_root with leaf table reference
81
96
SELECT relid, parentrelid, level, isleaf
82
97
FROM pg_partition_tree(pg_partition_root('ptif_test01')) p
@@ -87,9 +102,10 @@ SELECT relid, parentrelid, level, isleaf
87
102
ptif_test0 | ptif_test | 1 | f
88
103
ptif_test1 | ptif_test | 1 | f
89
104
ptif_test2 | ptif_test | 1 | t
105
+ ptif_test3 | ptif_test | 1 | f
90
106
ptif_test01 | ptif_test0 | 2 | t
91
107
ptif_test11 | ptif_test1 | 2 | t
92
- (6 rows)
108
+ (7 rows)
93
109
94
110
-- List all indexes members of the tree
95
111
SELECT relid, parentrelid, level, isleaf
@@ -100,9 +116,10 @@ SELECT relid, parentrelid, level, isleaf
100
116
ptif_test0_index | ptif_test_index | 1 | f
101
117
ptif_test1_index | ptif_test_index | 1 | f
102
118
ptif_test2_index | ptif_test_index | 1 | t
119
+ ptif_test3_index | ptif_test_index | 1 | f
103
120
ptif_test01_index | ptif_test0_index | 2 | t
104
121
ptif_test11_index | ptif_test1_index | 2 | t
105
- (6 rows)
122
+ (7 rows)
106
123
107
124
-- List indexes from an intermediate level
108
125
SELECT relid, parentrelid, level, isleaf
@@ -123,6 +140,15 @@ SELECT relid, parentrelid, level, isleaf
123
140
ptif_test01_index | ptif_test0_index | 0 | t
124
141
(1 row)
125
142
143
+ -- List from partitioned index with no partitions
144
+ SELECT relid, parentrelid, level, isleaf
145
+ FROM pg_partition_tree('ptif_test3_index') p
146
+ JOIN pg_class c ON (p.relid = c.oid);
147
+ relid | parentrelid | level | isleaf
148
+ ------------------+-----------------+-------+--------
149
+ ptif_test3_index | ptif_test_index | 0 | f
150
+ (1 row)
151
+
126
152
-- List all members using pg_partition_root with leaf index reference
127
153
SELECT relid, parentrelid, level, isleaf
128
154
FROM pg_partition_tree(pg_partition_root('ptif_test01_index')) p
@@ -133,24 +159,24 @@ SELECT relid, parentrelid, level, isleaf
133
159
ptif_test0_index | ptif_test_index | 1 | f
134
160
ptif_test1_index | ptif_test_index | 1 | f
135
161
ptif_test2_index | ptif_test_index | 1 | t
162
+ ptif_test3_index | ptif_test_index | 1 | f
136
163
ptif_test01_index | ptif_test0_index | 2 | t
137
164
ptif_test11_index | ptif_test1_index | 2 | t
138
- (6 rows)
165
+ (7 rows)
139
166
140
167
DROP TABLE ptif_test;
141
- -- Table that is not part of any partition tree is the only member listed.
168
+ -- Table that is not part of any partition tree is not listed.
142
169
CREATE TABLE ptif_normal_table(a int);
143
170
SELECT relid, parentrelid, level, isleaf
144
171
FROM pg_partition_tree('ptif_normal_table');
145
- relid | parentrelid | level | isleaf
146
- -------------------+-------------+-------+--------
147
- ptif_normal_table | | 0 | t
148
- (1 row)
172
+ relid | parentrelid | level | isleaf
173
+ -------+-------------+-------+--------
174
+ (0 rows)
149
175
150
176
SELECT pg_partition_root('ptif_normal_table');
151
177
pg_partition_root
152
178
-------------------
153
- ptif_normal_table
179
+
154
180
(1 row)
155
181
156
182
DROP TABLE ptif_normal_table;
0 commit comments