Started support for parallel index scan [skip ci]

This commit is contained in:
Andrew Kane
2025-09-22 11:21:14 -07:00
parent 9e29dff78c
commit f6058beeda
3 changed files with 46 additions and 4 deletions

View File

@@ -143,6 +143,10 @@ ivfflatcostestimate(PlannerInfo *root, IndexPath *path, double loop_count,
*indexSelectivity = costs.indexSelectivity; *indexSelectivity = costs.indexSelectivity;
*indexCorrelation = costs.indexCorrelation; *indexCorrelation = costs.indexCorrelation;
*indexPages = costs.numIndexPages; *indexPages = costs.numIndexPages;
elog(INFO, "ivfflatcostestimate = %f", costs.indexTotalCost);
/* Cost estimates for parallel workers applied outside of amcostestimate */
elog(INFO, "parallel_workers = %d, parallel aware = %d", path->path.parallel_workers, path->path.parallel_aware);
} }
/* /*
@@ -170,6 +174,25 @@ ivfflatvalidate(Oid opclassoid)
return true; return true;
} }
static Size
ivfflatestimateparallelscan()
{
elog(INFO, "ivfflatestimateparallelscan");
return 0;
}
static void
ivfflatinitparallelscan(void *target)
{
elog(INFO, "ivfflatinitparallelscan");
}
static void
ivfflatparallelrescan(IndexScanDesc scan)
{
elog(INFO, "ivfflatparallelrescan");
}
/* /*
* Define index handler * Define index handler
* *
@@ -200,7 +223,7 @@ ivfflathandler(PG_FUNCTION_ARGS)
amroutine->amstorage = false; amroutine->amstorage = false;
amroutine->amclusterable = false; amroutine->amclusterable = false;
amroutine->ampredlocks = false; amroutine->ampredlocks = false;
amroutine->amcanparallel = false; amroutine->amcanparallel = true;
#if PG_VERSION_NUM >= 170000 #if PG_VERSION_NUM >= 170000
amroutine->amcanbuildparallel = true; amroutine->amcanbuildparallel = true;
#endif #endif
@@ -242,9 +265,9 @@ ivfflathandler(PG_FUNCTION_ARGS)
amroutine->amrestrpos = NULL; amroutine->amrestrpos = NULL;
/* Interface functions to support parallel index scans */ /* Interface functions to support parallel index scans */
amroutine->amestimateparallelscan = NULL; amroutine->amestimateparallelscan = ivfflatestimateparallelscan;
amroutine->aminitparallelscan = NULL; amroutine->aminitparallelscan = ivfflatinitparallelscan;
amroutine->amparallelrescan = NULL; amroutine->amparallelrescan = ivfflatparallelrescan;
#if PG_VERSION_NUM >= 180000 #if PG_VERSION_NUM >= 180000
amroutine->amtranslatestrategy = NULL; amroutine->amtranslatestrategy = NULL;

View File

@@ -119,6 +119,9 @@ GetScanItems(IndexScanDesc scan, Datum value)
tuplesort_reset(so->sortstate); tuplesort_reset(so->sortstate);
if (scan->parallel_scan != NULL)
elog(INFO, "parallel scan");
/* Search closest probes lists */ /* Search closest probes lists */
while (so->listIndex < so->maxProbes && (++batchProbes) <= so->probes) while (so->listIndex < so->maxProbes && (++batchProbes) <= so->probes)
{ {

View File

@@ -0,0 +1,16 @@
-- SET force_parallel_mode = on;
SET parallel_setup_cost = 10;
SET parallel_tuple_cost = 0.000001;
SET min_parallel_table_scan_size = 1;
SET min_parallel_index_scan_size = 1;
CREATE TABLE t (id integer, val vector(3));
ALTER TABLE t ALTER COLUMN val SET STORAGE PLAIN;
INSERT INTO t (id, val) SELECT n, ARRAY[random(), random(), random()] FROM generate_series(1,1000000) n;
CREATE INDEX ON t USING ivfflat (val) WITH (lists = 10);
SET ivfflat.probes = 4;
EXPLAIN SELECT * FROM t ORDER BY val <-> '[0.5,0.5,0.5]' LIMIT 5;
SELECT * FROM t ORDER BY val <-> '[0.5,0.5,0.5]' LIMIT 5;
DROP TABLE t;