@@ -12,6 +12,18 @@ SELECT * FROM pg_partition_tree(0);
12
12
| | |
13
13
(1 row)
14
14
15
+ SELECT pg_partition_root(NULL);
16
+ pg_partition_root
17
+ -------------------
18
+
19
+ (1 row)
20
+
21
+ SELECT pg_partition_root(0);
22
+ pg_partition_root
23
+ -------------------
24
+
25
+ (1 row)
26
+
15
27
-- Test table partition trees
16
28
CREATE TABLE ptif_test (a int, b int) PARTITION BY range (a);
17
29
CREATE TABLE ptif_test0 PARTITION OF ptif_test
@@ -66,6 +78,20 @@ SELECT relid, parentrelid, level, isleaf
66
78
ptif_test01 | ptif_test0 | 0 | t
67
79
(1 row)
68
80
81
+ -- List all members using pg_partition_root with leaf table reference
82
+ SELECT relid, parentrelid, level, isleaf
83
+ FROM pg_partition_tree(pg_partition_root('ptif_test01')) p
84
+ JOIN pg_class c ON (p.relid = c.oid);
85
+ relid | parentrelid | level | isleaf
86
+ -------------+-------------+-------+--------
87
+ ptif_test | | 0 | f
88
+ ptif_test0 | ptif_test | 1 | f
89
+ ptif_test1 | ptif_test | 1 | f
90
+ ptif_test2 | ptif_test | 1 | t
91
+ ptif_test01 | ptif_test0 | 2 | t
92
+ ptif_test11 | ptif_test1 | 2 | t
93
+ (6 rows)
94
+
69
95
-- List all indexes members of the tree
70
96
SELECT relid, parentrelid, level, isleaf
71
97
FROM pg_partition_tree('ptif_test_index');
@@ -98,6 +124,20 @@ SELECT relid, parentrelid, level, isleaf
98
124
ptif_test01_index | ptif_test0_index | 0 | t
99
125
(1 row)
100
126
127
+ -- List all members using pg_partition_root with leaf index reference
128
+ SELECT relid, parentrelid, level, isleaf
129
+ FROM pg_partition_tree(pg_partition_root('ptif_test01_index')) p
130
+ JOIN pg_class c ON (p.relid = c.oid);
131
+ relid | parentrelid | level | isleaf
132
+ -------------------+------------------+-------+--------
133
+ ptif_test_index | | 0 | f
134
+ ptif_test0_index | ptif_test_index | 1 | f
135
+ ptif_test1_index | ptif_test_index | 1 | f
136
+ ptif_test2_index | ptif_test_index | 1 | t
137
+ ptif_test01_index | ptif_test0_index | 2 | t
138
+ ptif_test11_index | ptif_test1_index | 2 | t
139
+ (6 rows)
140
+
101
141
DROP TABLE ptif_test;
102
142
-- Table that is not part of any partition tree is the only member listed.
103
143
CREATE TABLE ptif_normal_table(a int);
@@ -108,6 +148,12 @@ SELECT relid, parentrelid, level, isleaf
108
148
ptif_normal_table | | 0 | t
109
149
(1 row)
110
150
151
+ SELECT pg_partition_root('ptif_normal_table');
152
+ pg_partition_root
153
+ -------------------
154
+ ptif_normal_table
155
+ (1 row)
156
+
111
157
DROP TABLE ptif_normal_table;
112
158
-- Various partitioning-related functions return NULL if passed relations
113
159
-- of types that cannot be part of a partition tree; for example, views,
@@ -126,5 +172,17 @@ SELECT * FROM pg_partition_tree('ptif_test_matview');
126
172
| | |
127
173
(1 row)
128
174
175
+ SELECT pg_partition_root('ptif_test_view');
176
+ pg_partition_root
177
+ -------------------
178
+
179
+ (1 row)
180
+
181
+ SELECT pg_partition_root('ptif_test_matview');
182
+ pg_partition_root
183
+ -------------------
184
+
185
+ (1 row)
186
+
129
187
DROP VIEW ptif_test_view;
130
188
DROP MATERIALIZED VIEW ptif_test_matview;
0 commit comments