mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-17 09:44:33 +08:00
Get info from metapage to determine cost
This commit is contained in:
@@ -91,7 +91,7 @@ hnswcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
|
|||||||
MemSet(&costs, 0, sizeof(costs));
|
MemSet(&costs, 0, sizeof(costs));
|
||||||
|
|
||||||
index = index_open(path->indexinfo->indexoid, NoLock);
|
index = index_open(path->indexinfo->indexoid, NoLock);
|
||||||
m = HnswGetM(index);
|
HnswGetMetaPageInfo(index, &m, NULL);
|
||||||
index_close(index, NoLock);
|
index_close(index, NoLock);
|
||||||
|
|
||||||
/* Approximate entry level */
|
/* Approximate entry level */
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ ivfflatcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
|
|||||||
MemSet(&costs, 0, sizeof(costs));
|
MemSet(&costs, 0, sizeof(costs));
|
||||||
|
|
||||||
indexRel = index_open(path->indexinfo->indexoid, NoLock);
|
indexRel = index_open(path->indexinfo->indexoid, NoLock);
|
||||||
lists = IvfflatGetLists(indexRel);
|
IvfflatGetMetaPageInfo(indexRel, &lists, NULL);
|
||||||
index_close(indexRel, NoLock);
|
index_close(indexRel, NoLock);
|
||||||
|
|
||||||
/* Get the ratio of lists that we need to visit */
|
/* Get the ratio of lists that we need to visit */
|
||||||
|
|||||||
@@ -279,6 +279,7 @@ void IvfflatKmeans(Relation index, VectorArray samples, VectorArray centers);
|
|||||||
FmgrInfo *IvfflatOptionalProcInfo(Relation rel, uint16 procnum);
|
FmgrInfo *IvfflatOptionalProcInfo(Relation rel, uint16 procnum);
|
||||||
bool IvfflatNormValue(FmgrInfo *procinfo, Oid collation, Datum *value, Vector * result);
|
bool IvfflatNormValue(FmgrInfo *procinfo, Oid collation, Datum *value, Vector * result);
|
||||||
int IvfflatGetLists(Relation index);
|
int IvfflatGetLists(Relation index);
|
||||||
|
void IvfflatGetMetaPageInfo(Relation index, int *lists, int *dimensions);
|
||||||
void IvfflatUpdateList(Relation index, ListInfo listInfo, BlockNumber insertPage, BlockNumber originalInsertPage, BlockNumber startPage, ForkNumber forkNum);
|
void IvfflatUpdateList(Relation index, ListInfo listInfo, BlockNumber insertPage, BlockNumber originalInsertPage, BlockNumber startPage, ForkNumber forkNum);
|
||||||
void IvfflatCommitBuffer(Buffer buf, GenericXLogState *state);
|
void IvfflatCommitBuffer(Buffer buf, GenericXLogState *state);
|
||||||
void IvfflatAppendPage(Relation index, Buffer *buf, Page *page, GenericXLogState **state, ForkNumber forkNum);
|
void IvfflatAppendPage(Relation index, Buffer *buf, Page *page, GenericXLogState **state, ForkNumber forkNum);
|
||||||
|
|||||||
@@ -182,27 +182,6 @@ GetScanItems(IndexScanDesc scan, Datum value)
|
|||||||
tuplesort_performsort(so->sortstate);
|
tuplesort_performsort(so->sortstate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Get the metapage info
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
IvfflatGetMetaPageInfo(Relation index, int *lists, int *dimensions)
|
|
||||||
{
|
|
||||||
Buffer buf;
|
|
||||||
Page page;
|
|
||||||
IvfflatMetaPage metap;
|
|
||||||
|
|
||||||
buf = ReadBuffer(index, IVFFLAT_METAPAGE_BLKNO);
|
|
||||||
LockBuffer(buf, BUFFER_LOCK_SHARE);
|
|
||||||
page = BufferGetPage(buf);
|
|
||||||
metap = IvfflatPageGetMeta(page);
|
|
||||||
|
|
||||||
*lists = metap->lists;
|
|
||||||
*dimensions = metap->dimensions;
|
|
||||||
|
|
||||||
UnlockReleaseBuffer(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Prepare for an index scan
|
* Prepare for an index scan
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -172,6 +172,29 @@ IvfflatAppendPage(Relation index, Buffer *buf, Page *page, GenericXLogState **st
|
|||||||
*buf = newbuf;
|
*buf = newbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the metapage info
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
IvfflatGetMetaPageInfo(Relation index, int *lists, int *dimensions)
|
||||||
|
{
|
||||||
|
Buffer buf;
|
||||||
|
Page page;
|
||||||
|
IvfflatMetaPage metap;
|
||||||
|
|
||||||
|
buf = ReadBuffer(index, IVFFLAT_METAPAGE_BLKNO);
|
||||||
|
LockBuffer(buf, BUFFER_LOCK_SHARE);
|
||||||
|
page = BufferGetPage(buf);
|
||||||
|
metap = IvfflatPageGetMeta(page);
|
||||||
|
|
||||||
|
*lists = metap->lists;
|
||||||
|
|
||||||
|
if (dimensions != NULL)
|
||||||
|
*dimensions = metap->dimensions;
|
||||||
|
|
||||||
|
UnlockReleaseBuffer(buf);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Update the start or insert page of a list
|
* Update the start or insert page of a list
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user