summaryrefslogtreecommitdiffstats
path: root/src/test/regress/expected/partition_info.out
blob: 42b6bc77cad0d2c9e1c557ed902f57550232034b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
--
-- Tests for functions providing information about partitions
--
SELECT * FROM pg_partition_tree(NULL);
 relid | parentrelid | isleaf | level 
-------+-------------+--------+-------
(0 rows)

SELECT * FROM pg_partition_tree(0);
 relid | parentrelid | isleaf | level 
-------+-------------+--------+-------
(0 rows)

SELECT * FROM pg_partition_ancestors(NULL);
 relid 
-------
(0 rows)

SELECT * FROM pg_partition_ancestors(0);
 relid 
-------
(0 rows)

SELECT pg_partition_root(NULL);
 pg_partition_root 
-------------------
 
(1 row)

SELECT pg_partition_root(0);
 pg_partition_root 
-------------------
 
(1 row)

-- Test table partition trees
CREATE TABLE ptif_test (a int, b int) PARTITION BY range (a);
CREATE TABLE ptif_test0 PARTITION OF ptif_test
  FOR VALUES FROM (minvalue) TO (0) PARTITION BY list (b);
CREATE TABLE ptif_test01 PARTITION OF ptif_test0 FOR VALUES IN (1);
CREATE TABLE ptif_test1 PARTITION OF ptif_test
  FOR VALUES FROM (0) TO (100) PARTITION BY list (b);
CREATE TABLE ptif_test11 PARTITION OF ptif_test1 FOR VALUES IN (1);
CREATE TABLE ptif_test2 PARTITION OF ptif_test
  FOR VALUES FROM (100) TO (200);
-- This partitioned table should remain with no partitions.
CREATE TABLE ptif_test3 PARTITION OF ptif_test
  FOR VALUES FROM (200) TO (maxvalue) PARTITION BY list (b);
-- Test pg_partition_root for tables
SELECT pg_partition_root('ptif_test');
 pg_partition_root 
-------------------
 ptif_test
(1 row)

SELECT pg_partition_root('ptif_test0');
 pg_partition_root 
-------------------
 ptif_test
(1 row)

SELECT pg_partition_root('ptif_test01');
 pg_partition_root 
-------------------
 ptif_test
(1 row)

SELECT pg_partition_root('ptif_test3');
 pg_partition_root 
-------------------
 ptif_test
(1 row)

-- Test index partition tree
CREATE INDEX ptif_test_index ON ONLY ptif_test (a);
CREATE INDEX ptif_test0_index ON ONLY ptif_test0 (a);
ALTER INDEX ptif_test_index ATTACH PARTITION ptif_test0_index;
CREATE INDEX ptif_test01_index ON ptif_test01 (a);
ALTER INDEX ptif_test0_index ATTACH PARTITION ptif_test01_index;
CREATE INDEX ptif_test1_index ON ONLY ptif_test1 (a);
ALTER INDEX ptif_test_index ATTACH PARTITION ptif_test1_index;
CREATE INDEX ptif_test11_index ON ptif_test11 (a);
ALTER INDEX ptif_test1_index ATTACH PARTITION ptif_test11_index;
CREATE INDEX ptif_test2_index ON ptif_test2 (a);
ALTER INDEX ptif_test_index ATTACH PARTITION ptif_test2_index;
CREATE INDEX ptif_test3_index ON ptif_test3 (a);
ALTER INDEX ptif_test_index ATTACH PARTITION ptif_test3_index;
-- Test pg_partition_root for indexes
SELECT pg_partition_root('ptif_test_index');
 pg_partition_root 
-------------------
 ptif_test_index
(1 row)

SELECT pg_partition_root('ptif_test0_index');
 pg_partition_root 
-------------------
 ptif_test_index
(1 row)

SELECT pg_partition_root('ptif_test01_index');
 pg_partition_root 
-------------------
 ptif_test_index
(1 row)

SELECT pg_partition_root('ptif_test3_index');
 pg_partition_root 
-------------------
 ptif_test_index
(1 row)

-- List all tables members of the tree
SELECT relid, parentrelid, level, isleaf
  FROM pg_partition_tree('ptif_test');
    relid    | parentrelid | level | isleaf 
-------------+-------------+-------+--------
 ptif_test   |             |     0 | f
 ptif_test0  | ptif_test   |     1 | f
 ptif_test1  | ptif_test   |     1 | f
 ptif_test2  | ptif_test   |     1 | t
 ptif_test3  | ptif_test   |     1 | f
 ptif_test01 | ptif_test0  |     2 | t
 ptif_test11 | ptif_test1  |     2 | t
(7 rows)

-- List tables from an intermediate level
SELECT relid, parentrelid, level, isleaf
  FROM pg_partition_tree('ptif_test0') p
  JOIN pg_class c ON (p.relid = c.oid);
    relid    | parentrelid | level | isleaf 
-------------+-------------+-------+--------
 ptif_test0  | ptif_test   |     0 | f
 ptif_test01 | ptif_test0  |     1 | t
(2 rows)

-- List from leaf table
SELECT relid, parentrelid, level, isleaf
  FROM pg_partition_tree('ptif_test01') p
  JOIN pg_class c ON (p.relid = c.oid);
    relid    | parentrelid | level | isleaf 
-------------+-------------+-------+--------
 ptif_test01 | ptif_test0  |     0 | t
(1 row)

-- List from partitioned table with no partitions
SELECT relid, parentrelid, level, isleaf
  FROM pg_partition_tree('ptif_test3') p
  JOIN pg_class c ON (p.relid = c.oid);
   relid    | parentrelid | level | isleaf 
------------+-------------+-------+--------
 ptif_test3 | ptif_test   |     0 | f
(1 row)

-- List all ancestors of root and leaf tables
SELECT * FROM pg_partition_ancestors('ptif_test01');
    relid    
-------------
 ptif_test01
 ptif_test0
 ptif_test
(3 rows)

SELECT * FROM pg_partition_ancestors('ptif_test');
   relid   
-----------
 ptif_test
(1 row)

-- List all members using pg_partition_root with leaf table reference
SELECT relid, parentrelid, level, isleaf
  FROM pg_partition_tree(pg_partition_root('ptif_test01')) p
  JOIN pg_class c ON (p.relid = c.oid);
    relid    | parentrelid | level | isleaf 
-------------+-------------+-------+--------
 ptif_test   |             |     0 | f
 ptif_test0  | ptif_test   |     1 | f
 ptif_test1  | ptif_test   |     1 | f
 ptif_test2  | ptif_test   |     1 | t
 ptif_test3  | ptif_test   |     1 | f
 ptif_test01 | ptif_test0  |     2 | t
 ptif_test11 | ptif_test1  |     2 | t
(7 rows)

-- List all indexes members of the tree
SELECT relid, parentrelid, level, isleaf
  FROM pg_partition_tree('ptif_test_index');
       relid       |   parentrelid    | level | isleaf 
-------------------+------------------+-------+--------
 ptif_test_index   |                  |     0 | f
 ptif_test0_index  | ptif_test_index  |     1 | f
 ptif_test1_index  | ptif_test_index  |     1 | f
 ptif_test2_index  | ptif_test_index  |     1 | t
 ptif_test3_index  | ptif_test_index  |     1 | f
 ptif_test01_index | ptif_test0_index |     2 | t
 ptif_test11_index | ptif_test1_index |     2 | t
(7 rows)

-- List indexes from an intermediate level
SELECT relid, parentrelid, level, isleaf
  FROM pg_partition_tree('ptif_test0_index') p
  JOIN pg_class c ON (p.relid = c.oid);
       relid       |   parentrelid    | level | isleaf 
-------------------+------------------+-------+--------
 ptif_test0_index  | ptif_test_index  |     0 | f
 ptif_test01_index | ptif_test0_index |     1 | t
(2 rows)

-- List from leaf index
SELECT relid, parentrelid, level, isleaf
  FROM pg_partition_tree('ptif_test01_index') p
  JOIN pg_class c ON (p.relid = c.oid);
       relid       |   parentrelid    | level | isleaf 
-------------------+------------------+-------+--------
 ptif_test01_index | ptif_test0_index |     0 | t
(1 row)

-- List from partitioned index with no partitions
SELECT relid, parentrelid, level, isleaf
  FROM pg_partition_tree('ptif_test3_index') p
  JOIN pg_class c ON (p.relid = c.oid);
      relid       |   parentrelid   | level | isleaf 
------------------+-----------------+-------+--------
 ptif_test3_index | ptif_test_index |     0 | f
(1 row)

-- List all members using pg_partition_root with leaf index reference
SELECT relid, parentrelid, level, isleaf
  FROM pg_partition_tree(pg_partition_root('ptif_test01_index')) p
  JOIN pg_class c ON (p.relid = c.oid);
       relid       |   parentrelid    | level | isleaf 
-------------------+------------------+-------+--------
 ptif_test_index   |                  |     0 | f
 ptif_test0_index  | ptif_test_index  |     1 | f
 ptif_test1_index  | ptif_test_index  |     1 | f
 ptif_test2_index  | ptif_test_index  |     1 | t
 ptif_test3_index  | ptif_test_index  |     1 | f
 ptif_test01_index | ptif_test0_index |     2 | t
 ptif_test11_index | ptif_test1_index |     2 | t
(7 rows)

-- List all ancestors of root and leaf indexes
SELECT * FROM pg_partition_ancestors('ptif_test01_index');
       relid       
-------------------
 ptif_test01_index
 ptif_test0_index
 ptif_test_index
(3 rows)

SELECT * FROM pg_partition_ancestors('ptif_test_index');
      relid      
-----------------
 ptif_test_index
(1 row)

DROP TABLE ptif_test;
-- Table that is not part of any partition tree is not listed.
CREATE TABLE ptif_normal_table(a int);
SELECT relid, parentrelid, level, isleaf
  FROM pg_partition_tree('ptif_normal_table');
 relid | parentrelid | level | isleaf 
-------+-------------+-------+--------
(0 rows)

SELECT * FROM pg_partition_ancestors('ptif_normal_table');
 relid 
-------
(0 rows)

SELECT pg_partition_root('ptif_normal_table');
 pg_partition_root 
-------------------
 
(1 row)

DROP TABLE ptif_normal_table;
-- Various partitioning-related functions return empty/NULL if passed relations
-- of types that cannot be part of a partition tree; for example, views,
-- materialized views, legacy inheritance children or parents, etc.
CREATE VIEW ptif_test_view AS SELECT 1;
CREATE MATERIALIZED VIEW ptif_test_matview AS SELECT 1;
CREATE TABLE ptif_li_parent ();
CREATE TABLE ptif_li_child () INHERITS (ptif_li_parent);
SELECT * FROM pg_partition_tree('ptif_test_view');
 relid | parentrelid | isleaf | level 
-------+-------------+--------+-------
(0 rows)

SELECT * FROM pg_partition_tree('ptif_test_matview');
 relid | parentrelid | isleaf | level 
-------+-------------+--------+-------
(0 rows)

SELECT * FROM pg_partition_tree('ptif_li_parent');
 relid | parentrelid | isleaf | level 
-------+-------------+--------+-------
(0 rows)

SELECT * FROM pg_partition_tree('ptif_li_child');
 relid | parentrelid | isleaf | level 
-------+-------------+--------+-------
(0 rows)

SELECT * FROM pg_partition_ancestors('ptif_test_view');
 relid 
-------
(0 rows)

SELECT * FROM pg_partition_ancestors('ptif_test_matview');
 relid 
-------
(0 rows)

SELECT * FROM pg_partition_ancestors('ptif_li_parent');
 relid 
-------
(0 rows)

SELECT * FROM pg_partition_ancestors('ptif_li_child');
 relid 
-------
(0 rows)

SELECT pg_partition_root('ptif_test_view');
 pg_partition_root 
-------------------
 
(1 row)

SELECT pg_partition_root('ptif_test_matview');
 pg_partition_root 
-------------------
 
(1 row)

SELECT pg_partition_root('ptif_li_parent');
 pg_partition_root 
-------------------
 
(1 row)

SELECT pg_partition_root('ptif_li_child');
 pg_partition_root 
-------------------
 
(1 row)

DROP VIEW ptif_test_view;
DROP MATERIALIZED VIEW ptif_test_matview;
DROP TABLE ptif_li_parent, ptif_li_child;