1 /*-------------------------------------------------------------------------
4 * prototypes for various files in optimizer/path
7 * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/optimizer/paths.h
12 *-------------------------------------------------------------------------
17 #include "nodes/pathnodes.h"
23 extern PGDLLIMPORT
bool enable_geqo
;
24 extern PGDLLIMPORT
int geqo_threshold
;
25 extern PGDLLIMPORT
int min_parallel_table_scan_size
;
26 extern PGDLLIMPORT
int min_parallel_index_scan_size
;
27 extern PGDLLIMPORT
bool enable_group_by_reordering
;
29 /* Hook for plugins to get control in set_rel_pathlist() */
30 typedef void (*set_rel_pathlist_hook_type
) (PlannerInfo
*root
,
34 extern PGDLLIMPORT set_rel_pathlist_hook_type set_rel_pathlist_hook
;
36 /* Hook for plugins to get control in add_paths_to_joinrel() */
37 typedef void (*set_join_pathlist_hook_type
) (PlannerInfo
*root
,
42 JoinPathExtraData
*extra
);
43 extern PGDLLIMPORT set_join_pathlist_hook_type set_join_pathlist_hook
;
45 /* Hook for plugins to replace standard_join_search() */
46 typedef RelOptInfo
*(*join_search_hook_type
) (PlannerInfo
*root
,
49 extern PGDLLIMPORT join_search_hook_type join_search_hook
;
52 extern RelOptInfo
*make_one_rel(PlannerInfo
*root
, List
*joinlist
);
53 extern RelOptInfo
*standard_join_search(PlannerInfo
*root
, int levels_needed
,
56 extern void generate_gather_paths(PlannerInfo
*root
, RelOptInfo
*rel
,
58 extern void generate_useful_gather_paths(PlannerInfo
*root
, RelOptInfo
*rel
,
60 extern int compute_parallel_worker(RelOptInfo
*rel
, double heap_pages
,
61 double index_pages
, int max_workers
);
62 extern void create_partial_bitmap_paths(PlannerInfo
*root
, RelOptInfo
*rel
,
64 extern void generate_partitionwise_join_paths(PlannerInfo
*root
,
69 * routines to generate index paths
71 extern void create_index_paths(PlannerInfo
*root
, RelOptInfo
*rel
);
72 extern bool relation_has_unique_index_for(PlannerInfo
*root
, RelOptInfo
*rel
,
74 List
*exprlist
, List
*oprlist
);
75 extern bool indexcol_is_bool_constant_for_query(PlannerInfo
*root
,
78 extern bool match_index_to_operand(Node
*operand
, int indexcol
,
80 extern void check_index_predicates(PlannerInfo
*root
, RelOptInfo
*rel
);
84 * routines to generate tid paths
86 extern void create_tidscan_paths(PlannerInfo
*root
, RelOptInfo
*rel
);
90 * routines to create join paths
92 extern void add_paths_to_joinrel(PlannerInfo
*root
, RelOptInfo
*joinrel
,
93 RelOptInfo
*outerrel
, RelOptInfo
*innerrel
,
94 JoinType jointype
, SpecialJoinInfo
*sjinfo
,
99 * routines to determine which relations to join
101 extern void join_search_one_level(PlannerInfo
*root
, int level
);
102 extern RelOptInfo
*make_join_rel(PlannerInfo
*root
,
103 RelOptInfo
*rel1
, RelOptInfo
*rel2
);
104 extern Relids
add_outer_joins_to_relids(PlannerInfo
*root
, Relids input_relids
,
105 SpecialJoinInfo
*sjinfo
,
106 List
**pushed_down_joins
);
107 extern bool have_join_order_restriction(PlannerInfo
*root
,
108 RelOptInfo
*rel1
, RelOptInfo
*rel2
);
109 extern bool have_dangerous_phv(PlannerInfo
*root
,
110 Relids outer_relids
, Relids inner_params
);
111 extern void mark_dummy_rel(RelOptInfo
*rel
);
112 extern void init_dummy_sjinfo(SpecialJoinInfo
*sjinfo
, Relids left_relids
,
113 Relids right_relids
);
117 * routines for managing EquivalenceClasses
119 typedef bool (*ec_matches_callback_type
) (PlannerInfo
*root
,
121 EquivalenceClass
*ec
,
122 EquivalenceMember
*em
,
125 extern bool process_equivalence(PlannerInfo
*root
,
126 RestrictInfo
**p_restrictinfo
,
127 JoinDomain
*jdomain
);
128 extern Expr
*canonicalize_ec_expression(Expr
*expr
,
129 Oid req_type
, Oid req_collation
);
130 extern void reconsider_outer_join_clauses(PlannerInfo
*root
);
131 extern EquivalenceClass
*get_eclass_for_sort_expr(PlannerInfo
*root
,
139 extern EquivalenceMember
*find_ec_member_matching_expr(EquivalenceClass
*ec
,
142 extern EquivalenceMember
*find_computable_ec_member(PlannerInfo
*root
,
143 EquivalenceClass
*ec
,
146 bool require_parallel_safe
);
147 extern bool relation_can_be_sorted_early(PlannerInfo
*root
, RelOptInfo
*rel
,
148 EquivalenceClass
*ec
,
149 bool require_parallel_safe
);
150 extern void generate_base_implied_equalities(PlannerInfo
*root
);
151 extern List
*generate_join_implied_equalities(PlannerInfo
*root
,
154 RelOptInfo
*inner_rel
,
155 SpecialJoinInfo
*sjinfo
);
156 extern List
*generate_join_implied_equalities_for_ecs(PlannerInfo
*root
,
160 RelOptInfo
*inner_rel
);
161 extern bool exprs_known_equal(PlannerInfo
*root
, Node
*item1
, Node
*item2
);
162 extern EquivalenceClass
*match_eclasses_to_foreign_key_col(PlannerInfo
*root
,
163 ForeignKeyOptInfo
*fkinfo
,
165 extern RestrictInfo
*find_derived_clause_for_ec_member(EquivalenceClass
*ec
,
166 EquivalenceMember
*em
);
167 extern void add_child_rel_equivalences(PlannerInfo
*root
,
168 AppendRelInfo
*appinfo
,
169 RelOptInfo
*parent_rel
,
170 RelOptInfo
*child_rel
);
171 extern void add_child_join_rel_equivalences(PlannerInfo
*root
,
173 AppendRelInfo
**appinfos
,
174 RelOptInfo
*parent_joinrel
,
175 RelOptInfo
*child_joinrel
);
176 extern List
*generate_implied_equalities_for_column(PlannerInfo
*root
,
178 ec_matches_callback_type callback
,
180 Relids prohibited_rels
);
181 extern bool have_relevant_eclass_joinclause(PlannerInfo
*root
,
182 RelOptInfo
*rel1
, RelOptInfo
*rel2
);
183 extern bool has_relevant_eclass_joinclause(PlannerInfo
*root
,
185 extern bool eclass_useful_for_merging(PlannerInfo
*root
,
186 EquivalenceClass
*eclass
,
188 extern bool is_redundant_derived_clause(RestrictInfo
*rinfo
, List
*clauselist
);
189 extern bool is_redundant_with_indexclauses(RestrictInfo
*rinfo
,
194 * utilities for matching and building path keys
198 PATHKEYS_EQUAL
, /* pathkeys are identical */
199 PATHKEYS_BETTER1
, /* pathkey 1 is a superset of pathkey 2 */
200 PATHKEYS_BETTER2
, /* vice versa */
201 PATHKEYS_DIFFERENT
, /* neither pathkey includes the other */
202 } PathKeysComparison
;
204 extern PathKeysComparison
compare_pathkeys(List
*keys1
, List
*keys2
);
205 extern bool pathkeys_contained_in(List
*keys1
, List
*keys2
);
206 extern bool pathkeys_count_contained_in(List
*keys1
, List
*keys2
, int *n_common
);
207 extern List
*get_useful_group_keys_orderings(PlannerInfo
*root
, Path
*path
);
208 extern Path
*get_cheapest_path_for_pathkeys(List
*paths
, List
*pathkeys
,
209 Relids required_outer
,
210 CostSelector cost_criterion
,
211 bool require_parallel_safe
);
212 extern Path
*get_cheapest_fractional_path_for_pathkeys(List
*paths
,
214 Relids required_outer
,
216 extern Path
*get_cheapest_parallel_safe_total_inner(List
*paths
);
217 extern List
*build_index_pathkeys(PlannerInfo
*root
, IndexOptInfo
*index
,
218 ScanDirection scandir
);
219 extern List
*build_partition_pathkeys(PlannerInfo
*root
, RelOptInfo
*partrel
,
220 ScanDirection scandir
, bool *partialkeys
);
221 extern List
*build_expression_pathkey(PlannerInfo
*root
, Expr
*expr
,
223 Relids rel
, bool create_it
);
224 extern List
*convert_subquery_pathkeys(PlannerInfo
*root
, RelOptInfo
*rel
,
225 List
*subquery_pathkeys
,
226 List
*subquery_tlist
);
227 extern List
*build_join_pathkeys(PlannerInfo
*root
,
230 List
*outer_pathkeys
);
231 extern List
*make_pathkeys_for_sortclauses(PlannerInfo
*root
,
234 extern List
*make_pathkeys_for_sortclauses_extended(PlannerInfo
*root
,
237 bool remove_redundant
,
239 extern void initialize_mergeclause_eclasses(PlannerInfo
*root
,
240 RestrictInfo
*restrictinfo
);
241 extern void update_mergeclause_eclasses(PlannerInfo
*root
,
242 RestrictInfo
*restrictinfo
);
243 extern List
*find_mergeclauses_for_outer_pathkeys(PlannerInfo
*root
,
245 List
*restrictinfos
);
246 extern List
*select_outer_pathkeys_for_merge(PlannerInfo
*root
,
248 RelOptInfo
*joinrel
);
249 extern List
*make_inner_pathkeys_for_merge(PlannerInfo
*root
,
251 List
*outer_pathkeys
);
252 extern List
*trim_mergeclauses_for_inner_pathkeys(PlannerInfo
*root
,
255 extern List
*truncate_useless_pathkeys(PlannerInfo
*root
,
258 extern bool has_useful_pathkeys(PlannerInfo
*root
, RelOptInfo
*rel
);
259 extern List
*append_pathkeys(List
*target
, List
*source
);
260 extern PathKey
*make_canonical_pathkey(PlannerInfo
*root
,
261 EquivalenceClass
*eclass
, Oid opfamily
,
262 int strategy
, bool nulls_first
);
263 extern void add_paths_to_append_rel(PlannerInfo
*root
, RelOptInfo
*rel
,
264 List
*live_childrels
);