Get lists from metapage

This commit is contained in:
Andrew Kane
2023-09-03 10:34:44 -07:00
parent 2179414c05
commit db747e5aa0
2 changed files with 12 additions and 9 deletions

View File

@@ -244,6 +244,7 @@ typedef struct IvfflatScanList
typedef struct IvfflatScanOpaqueData typedef struct IvfflatScanOpaqueData
{ {
int probes; int probes;
int dimensions;
bool first; bool first;
Buffer buf; Buffer buf;

View File

@@ -183,26 +183,24 @@ GetScanItems(IndexScanDesc scan, Datum value)
} }
/* /*
* Get dimensions from metapage * Get the metapage info
*/ */
static int static void
GetDimensions(Relation index) IvfflatGetMetaPageInfo(Relation index, int *lists, int *dimensions)
{ {
Buffer buf; Buffer buf;
Page page; Page page;
IvfflatMetaPage metap; IvfflatMetaPage metap;
int dimensions;
buf = ReadBuffer(index, IVFFLAT_METAPAGE_BLKNO); buf = ReadBuffer(index, IVFFLAT_METAPAGE_BLKNO);
LockBuffer(buf, BUFFER_LOCK_SHARE); LockBuffer(buf, BUFFER_LOCK_SHARE);
page = BufferGetPage(buf); page = BufferGetPage(buf);
metap = IvfflatPageGetMeta(page); metap = IvfflatPageGetMeta(page);
dimensions = metap->dimensions; *lists = metap->dimensions;
*dimensions = metap->dimensions;
UnlockReleaseBuffer(buf); UnlockReleaseBuffer(buf);
return dimensions;
} }
/* /*
@@ -214,6 +212,7 @@ ivfflatbeginscan(Relation index, int nkeys, int norderbys)
IndexScanDesc scan; IndexScanDesc scan;
IvfflatScanOpaque so; IvfflatScanOpaque so;
int lists; int lists;
int dimensions;
AttrNumber attNums[] = {1}; AttrNumber attNums[] = {1};
Oid sortOperators[] = {Float8LessOperator}; Oid sortOperators[] = {Float8LessOperator};
Oid sortCollations[] = {InvalidOid}; Oid sortCollations[] = {InvalidOid};
@@ -221,7 +220,9 @@ ivfflatbeginscan(Relation index, int nkeys, int norderbys)
int probes = ivfflat_probes; int probes = ivfflat_probes;
scan = RelationGetIndexScan(index, nkeys, norderbys); scan = RelationGetIndexScan(index, nkeys, norderbys);
lists = IvfflatGetLists(scan->indexRelation);
/* Get lists and dimensions from metapage */
IvfflatGetMetaPageInfo(index, &lists, &dimensions);
if (probes > lists) if (probes > lists)
probes = lists; probes = lists;
@@ -230,6 +231,7 @@ ivfflatbeginscan(Relation index, int nkeys, int norderbys)
so->buf = InvalidBuffer; so->buf = InvalidBuffer;
so->first = true; so->first = true;
so->probes = probes; so->probes = probes;
so->dimensions = dimensions;
/* Set support functions */ /* Set support functions */
so->procinfo = index_getprocinfo(index, 1, IVFFLAT_DISTANCE_PROC); so->procinfo = index_getprocinfo(index, 1, IVFFLAT_DISTANCE_PROC);
@@ -311,7 +313,7 @@ ivfflatgettuple(IndexScanDesc scan, ScanDirection dir)
elog(ERROR, "cannot scan ivfflat index without order"); elog(ERROR, "cannot scan ivfflat index without order");
if (scan->orderByData->sk_flags & SK_ISNULL) if (scan->orderByData->sk_flags & SK_ISNULL)
value = PointerGetDatum(InitVector(GetDimensions(scan->indexRelation))); value = PointerGetDatum(InitVector(so->dimensions));
else else
{ {
value = scan->orderByData->sk_argument; value = scan->orderByData->sk_argument;