Skip to content

Commit 851b14b

Browse files
committed
Remove rudiments of supporting procnum == 0 from 911e702
Early versions of opclass options patch uses zero support procedure as opclass options procedure. This commit removes rudiments of it, which were committed in 911e702. Also, it implements correct handling of amoptsprocnum == 0.
1 parent 4b42a89 commit 851b14b

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/backend/access/index/indexam.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -773,9 +773,9 @@ index_getprocid(Relation irel,
773773

774774
nproc = irel->rd_indam->amsupport;
775775

776-
Assert(procnum >= 0 && procnum <= (uint16) nproc);
776+
Assert(procnum > 0 && procnum <= (uint16) nproc);
777777

778-
procindex = ((nproc + 1) * (attnum - 1)) + procnum;
778+
procindex = (nproc * (attnum - 1)) + (procnum - 1);
779779

780780
loc = irel->rd_support;
781781

@@ -809,9 +809,9 @@ index_getprocinfo(Relation irel,
809809
nproc = irel->rd_indam->amsupport;
810810
optsproc = irel->rd_indam->amoptsprocnum;
811811

812-
Assert(procnum >= 0 && procnum <= (uint16) nproc);
812+
Assert(procnum > 0 && procnum <= (uint16) nproc);
813813

814-
procindex = ((nproc + 1) * (attnum - 1)) + procnum;
814+
procindex = (nproc * (attnum - 1)) + (procnum - 1);
815815

816816
locinfo = irel->rd_supportinfo;
817817

@@ -937,10 +937,14 @@ index_opclass_options(Relation indrel, AttrNumber attnum, Datum attoptions,
937937
bool validate)
938938
{
939939
int amoptsprocnum = indrel->rd_indam->amoptsprocnum;
940-
Oid procid = index_getprocid(indrel, attnum, amoptsprocnum);
940+
Oid procid = InvalidOid;
941941
FmgrInfo *procinfo;
942942
local_relopts relopts;
943943

944+
/* fetch options support procedure if specified */
945+
if (amoptsprocnum != 0)
946+
procid =index_getprocid(indrel, attnum, amoptsprocnum);
947+
944948
if (!OidIsValid(procid))
945949
{
946950
Oid opclass;

src/backend/utils/cache/relcache.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,7 @@ RelationInitIndexAccessInfo(Relation relation)
14261426
amsupport = relation->rd_indam->amsupport;
14271427
if (amsupport > 0)
14281428
{
1429-
int nsupport = indnatts * (amsupport + 1);
1429+
int nsupport = indnatts * amsupport;
14301430

14311431
relation->rd_support = (RegProcedure *)
14321432
MemoryContextAllocZero(indexcxt, nsupport * sizeof(RegProcedure));
@@ -1541,9 +1541,9 @@ IndexSupportInitialize(oidvector *indclass,
15411541
opFamily[attIndex] = opcentry->opcfamily;
15421542
opcInType[attIndex] = opcentry->opcintype;
15431543
if (maxSupportNumber > 0)
1544-
memcpy(&indexSupport[attIndex * (maxSupportNumber + 1)],
1544+
memcpy(&indexSupport[attIndex * maxSupportNumber],
15451545
opcentry->supportProcs,
1546-
(maxSupportNumber + 1) * sizeof(RegProcedure));
1546+
maxSupportNumber * sizeof(RegProcedure));
15471547
}
15481548
}
15491549

@@ -1695,12 +1695,13 @@ LookupOpclassInfo(Oid operatorClassOid,
16951695
{
16961696
Form_pg_amproc amprocform = (Form_pg_amproc) GETSTRUCT(htup);
16971697

1698-
if (amprocform->amprocnum < 0 ||
1698+
if (amprocform->amprocnum <= 0 ||
16991699
(StrategyNumber) amprocform->amprocnum > numSupport)
17001700
elog(ERROR, "invalid amproc number %d for opclass %u",
17011701
amprocform->amprocnum, operatorClassOid);
17021702

1703-
opcentry->supportProcs[amprocform->amprocnum] = amprocform->amproc;
1703+
opcentry->supportProcs[amprocform->amprocnum - 1] =
1704+
amprocform->amproc;
17041705
}
17051706

17061707
systable_endscan(scan);
@@ -5201,6 +5202,9 @@ RelationGetIndexRawAttOptions(Relation indexrel)
52015202

52025203
for (attnum = 1; attnum <= natts; attnum++)
52035204
{
5205+
if (indexrel->rd_indam->amoptsprocnum == 0)
5206+
continue;
5207+
52045208
if (!OidIsValid(index_getprocid(indexrel, attnum,
52055209
indexrel->rd_indam->amoptsprocnum)))
52065210
continue;
@@ -5661,7 +5665,7 @@ load_relcache_init_file(bool shared)
56615665
}
56625666

56635667
/* set up zeroed fmgr-info vector */
5664-
nsupport = relform->relnatts * (rel->rd_indam->amsupport + 1);
5668+
nsupport = relform->relnatts * rel->rd_indam->amsupport;
56655669
rel->rd_supportinfo = (FmgrInfo *)
56665670
MemoryContextAllocZero(indexcxt, nsupport * sizeof(FmgrInfo));
56675671
}
@@ -5962,7 +5966,7 @@ write_relcache_init_file(bool shared)
59625966

59635967
/* next, write the vector of support procedure OIDs */
59645968
write_item(rel->rd_support,
5965-
relform->relnatts * ((rel->rd_indam->amsupport + 1) * sizeof(RegProcedure)),
5969+
relform->relnatts * (rel->rd_indam->amsupport * sizeof(RegProcedure)),
59665970
fp);
59675971

59685972
/* next, write the vector of collation OIDs */

0 commit comments

Comments
 (0)