mirror of
https://github.com/postgres/postgres.git
synced 2025-09-03 15:22:11 +03:00
Revise parameterized-path mechanism to fix assorted issues.
This patch adjusts the treatment of parameterized paths so that all paths with the same parameterization (same set of required outer rels) for the same relation will have the same rowcount estimate. We cache the rowcount estimates to ensure that property, and hopefully save a few cycles too. Doing this makes it practical for add_path_precheck to operate without a rowcount estimate: it need only assume that paths with different parameterizations never dominate each other, which is close enough to true anyway for coarse filtering, because normally a more-parameterized path should yield fewer rows thanks to having more join clauses to apply. In add_path, we do the full nine yards of comparing rowcount estimates along with everything else, so that we can discard parameterized paths that don't actually have an advantage. This fixes some issues I'd found with add_path rejecting parameterized paths on the grounds that they were more expensive than not-parameterized ones, even though they yielded many fewer rows and hence would be cheaper once subsequent joining was considered. To make the same-rowcounts assumption valid, we have to require that any parameterized path enforce *all* join clauses that could be obtained from the particular set of outer rels, even if not all of them are useful for indexing. This is required at both base scans and joins. It's a good thing anyway since the net impact is that join quals are checked at the lowest practical level in the join tree. Hence, discard the original rather ad-hoc mechanism for choosing parameterization joinquals, and build a better one that has a more principled rule for when clauses can be moved. The original rule was actually buggy anyway for lack of knowledge about which relations are part of an outer join's outer side; getting this right requires adding an outer_relids field to RestrictInfo.
This commit is contained in:
@@ -66,17 +66,20 @@ extern int constraint_exclusion;
|
||||
extern double clamp_row_est(double nrows);
|
||||
extern double index_pages_fetched(double tuples_fetched, BlockNumber pages,
|
||||
double index_pages, PlannerInfo *root);
|
||||
extern void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel);
|
||||
extern void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
|
||||
ParamPathInfo *param_info);
|
||||
extern void cost_index(IndexPath *path, PlannerInfo *root,
|
||||
double loop_count);
|
||||
extern void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
|
||||
ParamPathInfo *param_info,
|
||||
Path *bitmapqual, double loop_count);
|
||||
extern void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root);
|
||||
extern void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root);
|
||||
extern void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec);
|
||||
extern void cost_tidscan(Path *path, PlannerInfo *root,
|
||||
RelOptInfo *baserel, List *tidquals);
|
||||
extern void cost_subqueryscan(Path *path, RelOptInfo *baserel);
|
||||
extern void cost_subqueryscan(Path *path, PlannerInfo *root,
|
||||
RelOptInfo *baserel, ParamPathInfo *param_info);
|
||||
extern void cost_functionscan(Path *path, PlannerInfo *root,
|
||||
RelOptInfo *baserel);
|
||||
extern void cost_valuesscan(Path *path, PlannerInfo *root,
|
||||
@@ -149,6 +152,15 @@ extern void compute_semi_anti_join_factors(PlannerInfo *root,
|
||||
List *restrictlist,
|
||||
SemiAntiJoinFactors *semifactors);
|
||||
extern void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel);
|
||||
extern double get_parameterized_baserel_size(PlannerInfo *root,
|
||||
RelOptInfo *rel,
|
||||
List *param_clauses);
|
||||
extern double get_parameterized_joinrel_size(PlannerInfo *root,
|
||||
RelOptInfo *rel,
|
||||
double outer_rows,
|
||||
double inner_rows,
|
||||
SpecialJoinInfo *sjinfo,
|
||||
List *restrict_clauses);
|
||||
extern void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
|
||||
RelOptInfo *outer_rel,
|
||||
RelOptInfo *inner_rel,
|
||||
|
Reference in New Issue
Block a user