Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3373c71

Browse files
committed
Speed up finding EquivalenceClasses for a given set of rels
Previously in order to determine which ECs a relation had members in, we had to loop over all ECs stored in PlannerInfo's eq_classes and check if ec_relids mentioned the relation. For the most part, this was fine, as generally, unless queries were fairly complex, the overhead of performing the lookup would have not been that significant. However, when queries contained large numbers of joins and ECs, the overhead to find the set of classes matching a given set of relations could become a significant portion of the overall planning effort. Here we allow a much more efficient method to access the ECs which match a given relation or set of relations. A new Bitmapset field in RelOptInfo now exists to store the indexes into PlannerInfo's eq_classes list which each relation is mentioned in. This allows very fast lookups to find all ECs belonging to a single relation. When we need to lookup ECs belonging to a given pair of relations, we can simply bitwise-AND the Bitmapsets from each relation and use the result to perform the lookup. We also take the opportunity to write a new implementation of generate_join_implied_equalities which makes use of the new indexes. generate_join_implied_equalities_for_ecs must remain as is as it can be given a custom list of ECs, which we can't easily determine the indexes of. This was originally intended to fix the performance penalty of looking up foreign keys matching a join condition which was introduced by 100340e. However, we're speeding up much more than just that here. Author: David Rowley, Tom Lane Reviewed-by: Tom Lane, Tomas Vondra Discussion: https://postgr.es/m/6970.1545327857@sss.pgh.pa.us
1 parent 894af78 commit 3373c71

File tree

9 files changed

+306
-82
lines changed

9 files changed

+306
-82
lines changed

src/backend/nodes/outfuncs.c

+2
Original file line numberDiff line numberDiff line change
@@ -2195,6 +2195,7 @@ _outPlannerInfo(StringInfo str, const PlannerInfo *node)
21952195
WRITE_NODE_FIELD(cte_plan_ids);
21962196
WRITE_NODE_FIELD(multiexpr_params);
21972197
WRITE_NODE_FIELD(eq_classes);
2198+
WRITE_BOOL_FIELD(ec_merging_done);
21982199
WRITE_NODE_FIELD(canon_pathkeys);
21992200
WRITE_NODE_FIELD(left_join_clauses);
22002201
WRITE_NODE_FIELD(right_join_clauses);
@@ -2261,6 +2262,7 @@ _outRelOptInfo(StringInfo str, const RelOptInfo *node)
22612262
WRITE_UINT_FIELD(pages);
22622263
WRITE_FLOAT_FIELD(tuples, "%.0f");
22632264
WRITE_FLOAT_FIELD(allvisfrac, "%.6f");
2265+
WRITE_BITMAPSET_FIELD(eclass_indexes);
22642266
WRITE_NODE_FIELD(subroot);
22652267
WRITE_NODE_FIELD(subplan_params);
22662268
WRITE_INT_FIELD(rel_parallel_workers);

0 commit comments

Comments
 (0)