Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit17f206f

Browse files
committed
Set pg_class.relhassubclass for partitioned indexes
Like for relations, switching this parameter is optimistic by turning iton each time a partitioned index gains a partition. So seeing thisparameter set to true means that the partitioned index has or has hadpartitions. The flag cannot be reset yet for partitioned indexes, whichis something not obvious anyway as partitioned relations exist to havepartitions.This allows to track more conveniently partition trees for indexes,which will come in use with an upcoming patch helping in listingpartition trees with an SQL-callable function.Author: Amit LangoteReviewed-by: Michael PaquierDiscussion:https://postgr.es/m/80306490-b5fc-ea34-4427-f29c52156052@lab.ntt.co.jp
1 parent31ff51a commit17f206f

File tree

4 files changed

+62
-21
lines changed

4 files changed

+62
-21
lines changed

‎src/backend/catalog/index.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,9 +994,12 @@ index_create(Relation heapRelation,
994994
*/
995995
CacheInvalidateRelcache(heapRelation);
996996

997-
/* update pg_inherits, if needed */
997+
/* update pg_inherits and the parent's relhassubclass, if needed */
998998
if (OidIsValid(parentIndexRelid))
999+
{
9991000
StoreSingleInheritance(indexRelationId,parentIndexRelid,1);
1001+
SetRelationHasSubclass(parentIndexRelid, true);
1002+
}
10001003

10011004
/*
10021005
* Register constraint and dependencies for the index.

‎src/backend/commands/indexcmds.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2608,6 +2608,10 @@ IndexSetParentIndex(Relation partitionIdx, Oid parentOid)
26082608
systable_endscan(scan);
26092609
relation_close(pg_inherits,RowExclusiveLock);
26102610

2611+
/* set relhassubclass if an index partition has been added to the parent */
2612+
if (OidIsValid(parentOid))
2613+
SetRelationHasSubclass(parentOid, true);
2614+
26112615
if (fix_dependencies)
26122616
{
26132617
ObjectAddresspartIdx;

‎src/test/regress/expected/indexing.out

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,45 @@
11
-- Creating an index on a partitioned table makes the partitions
22
-- automatically get the index
33
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;
414
create table idxpart1 partition of idxpart for values from (0) to (10);
515
create table idxpart2 partition of idxpart for values from (10) to (100)
616
partition by range (b);
717
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;
828
create index on idxpart (a);
9-
select relname, relkind, inhparent::regclass
29+
select relname, relkind,relhassubclass,inhparent::regclass
1030
from pg_class left join pg_index ix on (indexrelid = oid)
1131
left join pg_inherits on (ix.indexrelid = inhrelid)
1232
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 |
2343
(8 rows)
2444

2545
drop table idxpart;
@@ -110,16 +130,16 @@ Partition of: idxpart FOR VALUES FROM (0, 0) TO (10, 10)
110130
Indexes:
111131
"idxpart1_a_b_idx" btree (a, b)
112132

113-
select relname, relkind, inhparent::regclass
133+
select relname, relkind,relhassubclass,inhparent::regclass
114134
from pg_class left join pg_index ix on (indexrelid = oid)
115135
left join pg_inherits on (ix.indexrelid = inhrelid)
116136
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 |
123143
(4 rows)
124144

125145
drop table idxpart;

‎src/test/regress/sql/indexing.sql

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
-- Creating an index on a partitioned table makes the partitions
22
-- automatically get the index
33
createtableidxpart (aint, bint, ctext) partition by range (a);
4+
5+
-- relhassubclass of a partitioned index is false before creating any partition.
6+
-- It will be set after the first partition is created.
7+
createindexidxpart_idxon idxpart (a);
8+
select relhassubclassfrom pg_classwhere relname='idxpart_idx';
9+
dropindex idxpart_idx;
10+
411
createtableidxpart1 partition of idxpart forvaluesfrom (0) to (10);
512
createtableidxpart2 partition of idxpart forvaluesfrom (10) to (100)
613
partition by range (b);
714
createtableidxpart21 partition of idxpart2 forvaluesfrom (0) to (100);
15+
16+
-- Even with partitions, relhassubclass should not be set if a partitioned
17+
-- index is created only on the parent.
18+
createindexidxpart_idxon only idxpart(a);
19+
select relhassubclassfrom pg_classwhere relname='idxpart_idx';
20+
dropindex idxpart_idx;
21+
822
createindexon idxpart (a);
9-
select relname, relkind, inhparent::regclass
23+
select relname, relkind,relhassubclass,inhparent::regclass
1024
from pg_classleft join pg_index ixon (indexrelid=oid)
1125
left join pg_inheritson (ix.indexrelid= inhrelid)
1226
where relnamelike'idxpart%'order by relname;
@@ -54,7 +68,7 @@ create table idxpart1 partition of idxpart for values from (0, 0) to (10, 10);
5468
createindexon idxpart1 (a, b);
5569
createindexon idxpart (a, b);
5670
\d idxpart1
57-
select relname, relkind, inhparent::regclass
71+
select relname, relkind,relhassubclass,inhparent::regclass
5872
from pg_classleft join pg_index ixon (indexrelid=oid)
5973
left join pg_inheritson (ix.indexrelid= inhrelid)
6074
where relnamelike'idxpart%'order by relname;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp