mirror of
https://github.com/postgres/postgres.git
synced 2025-08-28 18:48:04 +03:00
Support parallel bitmap heap scans.
The index is scanned by a single process, but then all cooperating processes can iterate jointly over the resulting set of heap blocks. In the future, we might also want to support using a parallel bitmap index scan to set up for a parallel bitmap heap scan, but that's a job for another day. Dilip Kumar, with some corrections and cosmetic changes by me. The larger patch set of which this is a part has been reviewed and tested by (at least) Andres Freund, Amit Khandekar, Tushar Ahuja, Rafia Sabih, Haribabu Kommi, Thomas Munro, and me. Discussion: http://postgr.es/m/CAFiTN-uc4=0WxRGfCzs-xfkMYcSEWUC-Fon6thkJGjkh9i=13A@mail.gmail.com
This commit is contained in:
@@ -2911,6 +2911,30 @@ remove_unused_subquery_outputs(Query *subquery, RelOptInfo *rel)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* create_partial_bitmap_paths
|
||||
* Build partial bitmap heap path for the relation
|
||||
*/
|
||||
void
|
||||
create_partial_bitmap_paths(PlannerInfo *root, RelOptInfo *rel,
|
||||
Path *bitmapqual)
|
||||
{
|
||||
int parallel_workers;
|
||||
double pages_fetched;
|
||||
|
||||
/* Compute heap pages for bitmap heap scan */
|
||||
pages_fetched = compute_bitmap_pages(root, rel, bitmapqual, 1.0,
|
||||
NULL, NULL);
|
||||
|
||||
parallel_workers = compute_parallel_worker(rel, pages_fetched, 0);
|
||||
|
||||
if (parallel_workers <= 0)
|
||||
return;
|
||||
|
||||
add_partial_path(rel, (Path *) create_bitmap_heap_path(root, rel,
|
||||
bitmapqual, rel->lateral_relids, 1.0, parallel_workers));
|
||||
}
|
||||
|
||||
/*
|
||||
* Compute the number of parallel workers that should be used to scan a
|
||||
* relation. We compute the parallel workers based on the size of the heap to
|
||||
|
@@ -860,6 +860,7 @@ cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
|
||||
QualCost qpqual_cost;
|
||||
Cost cpu_per_tuple;
|
||||
Cost cost_per_page;
|
||||
Cost cpu_run_cost;
|
||||
double tuples_fetched;
|
||||
double pages_fetched;
|
||||
double spc_seq_page_cost,
|
||||
@@ -921,8 +922,21 @@ cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
|
||||
|
||||
startup_cost += qpqual_cost.startup;
|
||||
cpu_per_tuple = cpu_tuple_cost + qpqual_cost.per_tuple;
|
||||
cpu_run_cost = cpu_per_tuple * tuples_fetched;
|
||||
|
||||
run_cost += cpu_per_tuple * tuples_fetched;
|
||||
/* Adjust costing for parallelism, if used. */
|
||||
if (path->parallel_workers > 0)
|
||||
{
|
||||
double parallel_divisor = get_parallel_divisor(path);
|
||||
|
||||
/* The CPU cost is divided among all the workers. */
|
||||
cpu_run_cost /= parallel_divisor;
|
||||
|
||||
path->rows = clamp_row_est(path->rows / parallel_divisor);
|
||||
}
|
||||
|
||||
|
||||
run_cost += cpu_run_cost;
|
||||
|
||||
/* tlist eval costs are paid per output row, not per tuple scanned */
|
||||
startup_cost += path->pathtarget->cost.startup;
|
||||
|
@@ -337,8 +337,12 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
|
||||
|
||||
bitmapqual = choose_bitmap_and(root, rel, bitindexpaths);
|
||||
bpath = create_bitmap_heap_path(root, rel, bitmapqual,
|
||||
rel->lateral_relids, 1.0);
|
||||
rel->lateral_relids, 1.0, 0);
|
||||
add_path(rel, (Path *) bpath);
|
||||
|
||||
/* create a partial bitmap heap path */
|
||||
if (rel->consider_parallel && rel->lateral_relids == NULL)
|
||||
create_partial_bitmap_paths(root, rel, bitmapqual);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -410,7 +414,7 @@ create_index_paths(PlannerInfo *root, RelOptInfo *rel)
|
||||
required_outer = get_bitmap_tree_required_outer(bitmapqual);
|
||||
loop_count = get_loop_count(root, rel->relid, required_outer);
|
||||
bpath = create_bitmap_heap_path(root, rel, bitmapqual,
|
||||
required_outer, loop_count);
|
||||
required_outer, loop_count, 0);
|
||||
add_path(rel, (Path *) bpath);
|
||||
}
|
||||
}
|
||||
@@ -1617,6 +1621,11 @@ bitmap_scan_cost_est(PlannerInfo *root, RelOptInfo *rel, Path *ipath)
|
||||
bpath.path.pathkeys = NIL;
|
||||
bpath.bitmapqual = ipath;
|
||||
|
||||
/*
|
||||
* Check the cost of temporary path without considering parallelism.
|
||||
* Parallel bitmap heap path will be considered at later stage.
|
||||
*/
|
||||
bpath.path.parallel_workers = 0;
|
||||
cost_bitmap_heap_scan(&bpath.path, root, rel,
|
||||
bpath.path.param_info,
|
||||
ipath,
|
||||
@@ -1659,6 +1668,12 @@ bitmap_and_cost_est(PlannerInfo *root, RelOptInfo *rel, List *paths)
|
||||
bpath.path.pathkeys = NIL;
|
||||
bpath.bitmapqual = (Path *) &apath;
|
||||
|
||||
/*
|
||||
* Check the cost of temporary path without considering parallelism.
|
||||
* Parallel bitmap heap path will be considered at later stage.
|
||||
*/
|
||||
bpath.path.parallel_workers = 0;
|
||||
|
||||
/* Now we can do cost_bitmap_heap_scan */
|
||||
cost_bitmap_heap_scan(&bpath.path, root, rel,
|
||||
bpath.path.param_info,
|
||||
|
@@ -125,6 +125,7 @@ static BitmapHeapScan *create_bitmap_scan_plan(PlannerInfo *root,
|
||||
List *tlist, List *scan_clauses);
|
||||
static Plan *create_bitmap_subplan(PlannerInfo *root, Path *bitmapqual,
|
||||
List **qual, List **indexqual, List **indexECs);
|
||||
static void bitmap_subplan_mark_shared(Plan *plan);
|
||||
static TidScan *create_tidscan_plan(PlannerInfo *root, TidPath *best_path,
|
||||
List *tlist, List *scan_clauses);
|
||||
static SubqueryScan *create_subqueryscan_plan(PlannerInfo *root,
|
||||
@@ -2590,6 +2591,9 @@ create_bitmap_scan_plan(PlannerInfo *root,
|
||||
&bitmapqualorig, &indexquals,
|
||||
&indexECs);
|
||||
|
||||
if (best_path->path.parallel_aware)
|
||||
bitmap_subplan_mark_shared(bitmapqualplan);
|
||||
|
||||
/*
|
||||
* The qpqual list must contain all restrictions not automatically handled
|
||||
* by the index, other than pseudoconstant clauses which will be handled
|
||||
@@ -4756,6 +4760,24 @@ label_sort_with_costsize(PlannerInfo *root, Sort *plan, double limit_tuples)
|
||||
plan->plan.parallel_aware = false;
|
||||
}
|
||||
|
||||
/*
|
||||
* bitmap_subplan_mark_shared
|
||||
* Set isshared flag in bitmap subplan so that it will be created in
|
||||
* shared memory.
|
||||
*/
|
||||
static void
|
||||
bitmap_subplan_mark_shared(Plan *plan)
|
||||
{
|
||||
if (IsA(plan, BitmapAnd))
|
||||
bitmap_subplan_mark_shared(
|
||||
linitial(((BitmapAnd *) plan)->bitmapplans));
|
||||
else if (IsA(plan, BitmapOr))
|
||||
((BitmapOr *) plan)->isshared = true;
|
||||
else if (IsA(plan, BitmapIndexScan))
|
||||
((BitmapIndexScan *) plan)->isshared = true;
|
||||
else
|
||||
elog(ERROR, "unrecognized node type: %d", nodeTag(plan));
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
|
@@ -1068,7 +1068,8 @@ create_bitmap_heap_path(PlannerInfo *root,
|
||||
RelOptInfo *rel,
|
||||
Path *bitmapqual,
|
||||
Relids required_outer,
|
||||
double loop_count)
|
||||
double loop_count,
|
||||
int parallel_degree)
|
||||
{
|
||||
BitmapHeapPath *pathnode = makeNode(BitmapHeapPath);
|
||||
|
||||
@@ -1077,9 +1078,9 @@ create_bitmap_heap_path(PlannerInfo *root,
|
||||
pathnode->path.pathtarget = rel->reltarget;
|
||||
pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
|
||||
required_outer);
|
||||
pathnode->path.parallel_aware = false;
|
||||
pathnode->path.parallel_aware = parallel_degree > 0 ? true : false;
|
||||
pathnode->path.parallel_safe = rel->consider_parallel;
|
||||
pathnode->path.parallel_workers = 0;
|
||||
pathnode->path.parallel_workers = parallel_degree;
|
||||
pathnode->path.pathkeys = NIL; /* always unordered */
|
||||
|
||||
pathnode->bitmapqual = bitmapqual;
|
||||
@@ -3281,7 +3282,7 @@ reparameterize_path(PlannerInfo *root, Path *path,
|
||||
rel,
|
||||
bpath->bitmapqual,
|
||||
required_outer,
|
||||
loop_count);
|
||||
loop_count, 0);
|
||||
}
|
||||
case T_SubqueryScan:
|
||||
{
|
||||
|
Reference in New Issue
Block a user