Commit 851b14b0 authored by Alexander Korotkov's avatar Alexander Korotkov

Remove rudiments of supporting procnum == 0 from 911e7020

Early versions of opclass options patch uses zero support procedure as opclass
options procedure.  This commit removes rudiments of it, which were committed
in 911e7020.  Also, it implements correct handling of amoptsprocnum == 0.
parent 4b42a899
...@@ -773,9 +773,9 @@ index_getprocid(Relation irel, ...@@ -773,9 +773,9 @@ index_getprocid(Relation irel,
nproc = irel->rd_indam->amsupport; nproc = irel->rd_indam->amsupport;
Assert(procnum >= 0 && procnum <= (uint16) nproc); Assert(procnum > 0 && procnum <= (uint16) nproc);
procindex = ((nproc + 1) * (attnum - 1)) + procnum; procindex = (nproc * (attnum - 1)) + (procnum - 1);
loc = irel->rd_support; loc = irel->rd_support;
...@@ -809,9 +809,9 @@ index_getprocinfo(Relation irel, ...@@ -809,9 +809,9 @@ index_getprocinfo(Relation irel,
nproc = irel->rd_indam->amsupport; nproc = irel->rd_indam->amsupport;
optsproc = irel->rd_indam->amoptsprocnum; optsproc = irel->rd_indam->amoptsprocnum;
Assert(procnum >= 0 && procnum <= (uint16) nproc); Assert(procnum > 0 && procnum <= (uint16) nproc);
procindex = ((nproc + 1) * (attnum - 1)) + procnum; procindex = (nproc * (attnum - 1)) + (procnum - 1);
locinfo = irel->rd_supportinfo; locinfo = irel->rd_supportinfo;
...@@ -937,10 +937,14 @@ index_opclass_options(Relation indrel, AttrNumber attnum, Datum attoptions, ...@@ -937,10 +937,14 @@ index_opclass_options(Relation indrel, AttrNumber attnum, Datum attoptions,
bool validate) bool validate)
{ {
int amoptsprocnum = indrel->rd_indam->amoptsprocnum; int amoptsprocnum = indrel->rd_indam->amoptsprocnum;
Oid procid = index_getprocid(indrel, attnum, amoptsprocnum); Oid procid = InvalidOid;
FmgrInfo *procinfo; FmgrInfo *procinfo;
local_relopts relopts; local_relopts relopts;
/* fetch options support procedure if specified */
if (amoptsprocnum != 0)
procid =index_getprocid(indrel, attnum, amoptsprocnum);
if (!OidIsValid(procid)) if (!OidIsValid(procid))
{ {
Oid opclass; Oid opclass;
......
...@@ -1426,7 +1426,7 @@ RelationInitIndexAccessInfo(Relation relation) ...@@ -1426,7 +1426,7 @@ RelationInitIndexAccessInfo(Relation relation)
amsupport = relation->rd_indam->amsupport; amsupport = relation->rd_indam->amsupport;
if (amsupport > 0) if (amsupport > 0)
{ {
int nsupport = indnatts * (amsupport + 1); int nsupport = indnatts * amsupport;
relation->rd_support = (RegProcedure *) relation->rd_support = (RegProcedure *)
MemoryContextAllocZero(indexcxt, nsupport * sizeof(RegProcedure)); MemoryContextAllocZero(indexcxt, nsupport * sizeof(RegProcedure));
...@@ -1541,9 +1541,9 @@ IndexSupportInitialize(oidvector *indclass, ...@@ -1541,9 +1541,9 @@ IndexSupportInitialize(oidvector *indclass,
opFamily[attIndex] = opcentry->opcfamily; opFamily[attIndex] = opcentry->opcfamily;
opcInType[attIndex] = opcentry->opcintype; opcInType[attIndex] = opcentry->opcintype;
if (maxSupportNumber > 0) if (maxSupportNumber > 0)
memcpy(&indexSupport[attIndex * (maxSupportNumber + 1)], memcpy(&indexSupport[attIndex * maxSupportNumber],
opcentry->supportProcs, opcentry->supportProcs,
(maxSupportNumber + 1) * sizeof(RegProcedure)); maxSupportNumber * sizeof(RegProcedure));
} }
} }
...@@ -1695,12 +1695,13 @@ LookupOpclassInfo(Oid operatorClassOid, ...@@ -1695,12 +1695,13 @@ LookupOpclassInfo(Oid operatorClassOid,
{ {
Form_pg_amproc amprocform = (Form_pg_amproc) GETSTRUCT(htup); Form_pg_amproc amprocform = (Form_pg_amproc) GETSTRUCT(htup);
if (amprocform->amprocnum < 0 || if (amprocform->amprocnum <= 0 ||
(StrategyNumber) amprocform->amprocnum > numSupport) (StrategyNumber) amprocform->amprocnum > numSupport)
elog(ERROR, "invalid amproc number %d for opclass %u", elog(ERROR, "invalid amproc number %d for opclass %u",
amprocform->amprocnum, operatorClassOid); amprocform->amprocnum, operatorClassOid);
opcentry->supportProcs[amprocform->amprocnum] = amprocform->amproc; opcentry->supportProcs[amprocform->amprocnum - 1] =
amprocform->amproc;
} }
systable_endscan(scan); systable_endscan(scan);
...@@ -5201,6 +5202,9 @@ RelationGetIndexRawAttOptions(Relation indexrel) ...@@ -5201,6 +5202,9 @@ RelationGetIndexRawAttOptions(Relation indexrel)
for (attnum = 1; attnum <= natts; attnum++) for (attnum = 1; attnum <= natts; attnum++)
{ {
if (indexrel->rd_indam->amoptsprocnum == 0)
continue;
if (!OidIsValid(index_getprocid(indexrel, attnum, if (!OidIsValid(index_getprocid(indexrel, attnum,
indexrel->rd_indam->amoptsprocnum))) indexrel->rd_indam->amoptsprocnum)))
continue; continue;
...@@ -5661,7 +5665,7 @@ load_relcache_init_file(bool shared) ...@@ -5661,7 +5665,7 @@ load_relcache_init_file(bool shared)
} }
/* set up zeroed fmgr-info vector */ /* set up zeroed fmgr-info vector */
nsupport = relform->relnatts * (rel->rd_indam->amsupport + 1); nsupport = relform->relnatts * rel->rd_indam->amsupport;
rel->rd_supportinfo = (FmgrInfo *) rel->rd_supportinfo = (FmgrInfo *)
MemoryContextAllocZero(indexcxt, nsupport * sizeof(FmgrInfo)); MemoryContextAllocZero(indexcxt, nsupport * sizeof(FmgrInfo));
} }
...@@ -5962,7 +5966,7 @@ write_relcache_init_file(bool shared) ...@@ -5962,7 +5966,7 @@ write_relcache_init_file(bool shared)
/* next, write the vector of support procedure OIDs */ /* next, write the vector of support procedure OIDs */
write_item(rel->rd_support, write_item(rel->rd_support,
relform->relnatts * ((rel->rd_indam->amsupport + 1) * sizeof(RegProcedure)), relform->relnatts * (rel->rd_indam->amsupport * sizeof(RegProcedure)),
fp); fp);
/* next, write the vector of collation OIDs */ /* next, write the vector of collation OIDs */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment