|
1 | 1 | -- Creating an index on a partitioned table makes the partitions
|
2 | 2 | -- automatically get the index
|
3 | 3 | create table idxpart (a int, b int, c text) partition by range (a);
|
| 4 | +-- relhassubclass of a partitioned index is false before creating any partition. |
| 5 | +-- It will be set after the first partition is created. |
| 6 | +create index idxpart_idx on idxpart (a); |
| 7 | +select relhassubclass from pg_class where relname = 'idxpart_idx'; |
| 8 | + relhassubclass |
| 9 | +---------------- |
| 10 | + f |
| 11 | +(1 row) |
| 12 | + |
| 13 | +drop index idxpart_idx; |
4 | 14 | create table idxpart1 partition of idxpart for values from (0) to (10);
|
5 | 15 | create table idxpart2 partition of idxpart for values from (10) to (100)
|
6 | 16 | partition by range (b);
|
7 | 17 | create table idxpart21 partition of idxpart2 for values from (0) to (100);
|
| 18 | +-- Even with partitions, relhassubclass should not be set if a partitioned |
| 19 | +-- index is created only on the parent. |
| 20 | +create index idxpart_idx on only idxpart(a); |
| 21 | +select relhassubclass from pg_class where relname = 'idxpart_idx'; |
| 22 | + relhassubclass |
| 23 | +---------------- |
| 24 | + f |
| 25 | +(1 row) |
| 26 | + |
| 27 | +drop index idxpart_idx; |
8 | 28 | create index on idxpart (a);
|
9 |
| -select relname, relkind, inhparent::regclass |
| 29 | +select relname, relkind, relhassubclass, inhparent::regclass |
10 | 30 | from pg_class left join pg_index ix on (indexrelid = oid)
|
11 | 31 | left join pg_inherits on (ix.indexrelid = inhrelid)
|
12 | 32 | where relname like 'idxpart%' order by relname;
|
13 |
| - relname | relkind | inhparent |
14 |
| ------------------+---------+---------------- |
15 |
| - idxpart | p | |
16 |
| - idxpart1 | r | |
17 |
| - idxpart1_a_idx | i | idxpart_a_idx |
18 |
| - idxpart2 | p | |
19 |
| - idxpart21 | r | |
20 |
| - idxpart21_a_idx | i | idxpart2_a_idx |
21 |
| - idxpart2_a_idx | I | idxpart_a_idx |
22 |
| - idxpart_a_idx | I | |
| 33 | + relname | relkind | relhassubclass | inhparent |
| 34 | +-----------------+---------+----------------+---------------- |
| 35 | + idxpart | p | t | |
| 36 | + idxpart1 | r | f | |
| 37 | + idxpart1_a_idx | i | f | idxpart_a_idx |
| 38 | + idxpart2 | p | t | |
| 39 | + idxpart21 | r | f | |
| 40 | + idxpart21_a_idx | i | f | idxpart2_a_idx |
| 41 | + idxpart2_a_idx | I | t | idxpart_a_idx |
| 42 | + idxpart_a_idx | I | t | |
23 | 43 | (8 rows)
|
24 | 44 |
|
25 | 45 | drop table idxpart;
|
@@ -110,16 +130,16 @@ Partition of: idxpart FOR VALUES FROM (0, 0) TO (10, 10)
|
110 | 130 | Indexes:
|
111 | 131 | "idxpart1_a_b_idx" btree (a, b)
|
112 | 132 |
|
113 |
| -select relname, relkind, inhparent::regclass |
| 133 | +select relname, relkind, relhassubclass, inhparent::regclass |
114 | 134 | from pg_class left join pg_index ix on (indexrelid = oid)
|
115 | 135 | left join pg_inherits on (ix.indexrelid = inhrelid)
|
116 | 136 | where relname like 'idxpart%' order by relname;
|
117 |
| - relname | relkind | inhparent |
118 |
| -------------------+---------+----------------- |
119 |
| - idxpart | p | |
120 |
| - idxpart1 | r | |
121 |
| - idxpart1_a_b_idx | i | idxpart_a_b_idx |
122 |
| - idxpart_a_b_idx | I | |
| 137 | + relname | relkind | relhassubclass | inhparent |
| 138 | +------------------+---------+----------------+----------------- |
| 139 | + idxpart | p | t | |
| 140 | + idxpart1 | r | f | |
| 141 | + idxpart1_a_b_idx | i | f | idxpart_a_b_idx |
| 142 | + idxpart_a_b_idx | I | t | |
123 | 143 | (4 rows)
|
124 | 144 |
|
125 | 145 | drop table idxpart;
|
|
0 commit comments