mirror of
https://github.com/postgres/postgres.git
synced 2025-04-22 23:02:54 +03:00
Tweak a couple of planner APIs to save recalculating join relids.
Discussion: https://postgr.es/m/f8128b11-c5bf-3539-48cd-234178b2314d@proxel.se
This commit is contained in:
parent
c792c7db41
commit
ec38dcd363
@ -4023,6 +4023,7 @@ get_restriction_qual_cost(PlannerInfo *root, RelOptInfo *baserel,
|
|||||||
* them to all the join cost estimation functions.
|
* them to all the join cost estimation functions.
|
||||||
*
|
*
|
||||||
* Input parameters:
|
* Input parameters:
|
||||||
|
* joinrel: join relation under consideration
|
||||||
* outerrel: outer relation under consideration
|
* outerrel: outer relation under consideration
|
||||||
* innerrel: inner relation under consideration
|
* innerrel: inner relation under consideration
|
||||||
* jointype: if not JOIN_SEMI or JOIN_ANTI, we assume it's inner_unique
|
* jointype: if not JOIN_SEMI or JOIN_ANTI, we assume it's inner_unique
|
||||||
@ -4033,6 +4034,7 @@ get_restriction_qual_cost(PlannerInfo *root, RelOptInfo *baserel,
|
|||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
compute_semi_anti_join_factors(PlannerInfo *root,
|
compute_semi_anti_join_factors(PlannerInfo *root,
|
||||||
|
RelOptInfo *joinrel,
|
||||||
RelOptInfo *outerrel,
|
RelOptInfo *outerrel,
|
||||||
RelOptInfo *innerrel,
|
RelOptInfo *innerrel,
|
||||||
JoinType jointype,
|
JoinType jointype,
|
||||||
@ -4056,14 +4058,12 @@ compute_semi_anti_join_factors(PlannerInfo *root,
|
|||||||
*/
|
*/
|
||||||
if (IS_OUTER_JOIN(jointype))
|
if (IS_OUTER_JOIN(jointype))
|
||||||
{
|
{
|
||||||
Relids joinrelids = bms_union(outerrel->relids, innerrel->relids);
|
|
||||||
|
|
||||||
joinquals = NIL;
|
joinquals = NIL;
|
||||||
foreach(l, restrictlist)
|
foreach(l, restrictlist)
|
||||||
{
|
{
|
||||||
RestrictInfo *rinfo = lfirst_node(RestrictInfo, l);
|
RestrictInfo *rinfo = lfirst_node(RestrictInfo, l);
|
||||||
|
|
||||||
if (!RINFO_IS_PUSHED_DOWN(rinfo, joinrelids))
|
if (!RINFO_IS_PUSHED_DOWN(rinfo, joinrel->relids))
|
||||||
joinquals = lappend(joinquals, rinfo);
|
joinquals = lappend(joinquals, rinfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,6 +171,7 @@ add_paths_to_joinrel(PlannerInfo *root,
|
|||||||
break;
|
break;
|
||||||
case JOIN_UNIQUE_OUTER:
|
case JOIN_UNIQUE_OUTER:
|
||||||
extra.inner_unique = innerrel_is_unique(root,
|
extra.inner_unique = innerrel_is_unique(root,
|
||||||
|
joinrel->relids,
|
||||||
outerrel->relids,
|
outerrel->relids,
|
||||||
innerrel,
|
innerrel,
|
||||||
JOIN_INNER,
|
JOIN_INNER,
|
||||||
@ -179,6 +180,7 @@ add_paths_to_joinrel(PlannerInfo *root,
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
extra.inner_unique = innerrel_is_unique(root,
|
extra.inner_unique = innerrel_is_unique(root,
|
||||||
|
joinrel->relids,
|
||||||
outerrel->relids,
|
outerrel->relids,
|
||||||
innerrel,
|
innerrel,
|
||||||
jointype,
|
jointype,
|
||||||
@ -207,7 +209,7 @@ add_paths_to_joinrel(PlannerInfo *root,
|
|||||||
* for cost estimation. These will be the same for all paths.
|
* for cost estimation. These will be the same for all paths.
|
||||||
*/
|
*/
|
||||||
if (jointype == JOIN_SEMI || jointype == JOIN_ANTI || extra.inner_unique)
|
if (jointype == JOIN_SEMI || jointype == JOIN_ANTI || extra.inner_unique)
|
||||||
compute_semi_anti_join_factors(root, outerrel, innerrel,
|
compute_semi_anti_join_factors(root, joinrel, outerrel, innerrel,
|
||||||
jointype, sjinfo, restrictlist,
|
jointype, sjinfo, restrictlist,
|
||||||
&extra.semifactors);
|
&extra.semifactors);
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ static bool rel_is_distinct_for(PlannerInfo *root, RelOptInfo *rel,
|
|||||||
List *clause_list);
|
List *clause_list);
|
||||||
static Oid distinct_col_search(int colno, List *colnos, List *opids);
|
static Oid distinct_col_search(int colno, List *colnos, List *opids);
|
||||||
static bool is_innerrel_unique_for(PlannerInfo *root,
|
static bool is_innerrel_unique_for(PlannerInfo *root,
|
||||||
|
Relids joinrelids,
|
||||||
Relids outerrelids,
|
Relids outerrelids,
|
||||||
RelOptInfo *innerrel,
|
RelOptInfo *innerrel,
|
||||||
JoinType jointype,
|
JoinType jointype,
|
||||||
@ -565,7 +566,8 @@ reduce_unique_semijoins(PlannerInfo *root)
|
|||||||
innerrel->joininfo);
|
innerrel->joininfo);
|
||||||
|
|
||||||
/* Test whether the innerrel is unique for those clauses. */
|
/* Test whether the innerrel is unique for those clauses. */
|
||||||
if (!innerrel_is_unique(root, sjinfo->min_lefthand, innerrel,
|
if (!innerrel_is_unique(root,
|
||||||
|
joinrelids, sjinfo->min_lefthand, innerrel,
|
||||||
JOIN_SEMI, restrictlist, true))
|
JOIN_SEMI, restrictlist, true))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -947,7 +949,8 @@ distinct_col_search(int colno, List *colnos, List *opids)
|
|||||||
*
|
*
|
||||||
* We need an actual RelOptInfo for the innerrel, but it's sufficient to
|
* We need an actual RelOptInfo for the innerrel, but it's sufficient to
|
||||||
* identify the outerrel by its Relids. This asymmetry supports use of this
|
* identify the outerrel by its Relids. This asymmetry supports use of this
|
||||||
* function before joinrels have been built.
|
* function before joinrels have been built. (The caller is expected to
|
||||||
|
* also supply the joinrelids, just to save recalculating that.)
|
||||||
*
|
*
|
||||||
* The proof must be made based only on clauses that will be "joinquals"
|
* The proof must be made based only on clauses that will be "joinquals"
|
||||||
* rather than "otherquals" at execution. For an inner join there's no
|
* rather than "otherquals" at execution. For an inner join there's no
|
||||||
@ -966,6 +969,7 @@ distinct_col_search(int colno, List *colnos, List *opids)
|
|||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
innerrel_is_unique(PlannerInfo *root,
|
innerrel_is_unique(PlannerInfo *root,
|
||||||
|
Relids joinrelids,
|
||||||
Relids outerrelids,
|
Relids outerrelids,
|
||||||
RelOptInfo *innerrel,
|
RelOptInfo *innerrel,
|
||||||
JoinType jointype,
|
JoinType jointype,
|
||||||
@ -1014,7 +1018,7 @@ innerrel_is_unique(PlannerInfo *root,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* No cached information, so try to make the proof. */
|
/* No cached information, so try to make the proof. */
|
||||||
if (is_innerrel_unique_for(root, outerrelids, innerrel,
|
if (is_innerrel_unique_for(root, joinrelids, outerrelids, innerrel,
|
||||||
jointype, restrictlist))
|
jointype, restrictlist))
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -1073,12 +1077,12 @@ innerrel_is_unique(PlannerInfo *root,
|
|||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
is_innerrel_unique_for(PlannerInfo *root,
|
is_innerrel_unique_for(PlannerInfo *root,
|
||||||
|
Relids joinrelids,
|
||||||
Relids outerrelids,
|
Relids outerrelids,
|
||||||
RelOptInfo *innerrel,
|
RelOptInfo *innerrel,
|
||||||
JoinType jointype,
|
JoinType jointype,
|
||||||
List *restrictlist)
|
List *restrictlist)
|
||||||
{
|
{
|
||||||
Relids joinrelids = bms_union(outerrelids, innerrel->relids);
|
|
||||||
List *clause_list = NIL;
|
List *clause_list = NIL;
|
||||||
ListCell *lc;
|
ListCell *lc;
|
||||||
|
|
||||||
|
@ -166,6 +166,7 @@ extern void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan);
|
|||||||
extern void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root);
|
extern void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root);
|
||||||
extern void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root);
|
extern void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root);
|
||||||
extern void compute_semi_anti_join_factors(PlannerInfo *root,
|
extern void compute_semi_anti_join_factors(PlannerInfo *root,
|
||||||
|
RelOptInfo *joinrel,
|
||||||
RelOptInfo *outerrel,
|
RelOptInfo *outerrel,
|
||||||
RelOptInfo *innerrel,
|
RelOptInfo *innerrel,
|
||||||
JoinType jointype,
|
JoinType jointype,
|
||||||
|
@ -108,7 +108,7 @@ extern void reduce_unique_semijoins(PlannerInfo *root);
|
|||||||
extern bool query_supports_distinctness(Query *query);
|
extern bool query_supports_distinctness(Query *query);
|
||||||
extern bool query_is_distinct_for(Query *query, List *colnos, List *opids);
|
extern bool query_is_distinct_for(Query *query, List *colnos, List *opids);
|
||||||
extern bool innerrel_is_unique(PlannerInfo *root,
|
extern bool innerrel_is_unique(PlannerInfo *root,
|
||||||
Relids outerrelids, RelOptInfo *innerrel,
|
Relids joinrelids, Relids outerrelids, RelOptInfo *innerrel,
|
||||||
JoinType jointype, List *restrictlist, bool force_cache);
|
JoinType jointype, List *restrictlist, bool force_cache);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user