Revert commit 66c0185a3 and follow-on patches.
[pgsql.git] / src / include / optimizer / paths.h
blob5f500a1c69fb02ce4af08cdac7502cfe3ae2481a
1 /*-------------------------------------------------------------------------
3 * paths.h
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 *-------------------------------------------------------------------------
14 #ifndef PATHS_H
15 #define PATHS_H
17 #include "nodes/pathnodes.h"
21 * allpaths.c
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,
31 RelOptInfo *rel,
32 Index rti,
33 RangeTblEntry *rte);
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,
38 RelOptInfo *joinrel,
39 RelOptInfo *outerrel,
40 RelOptInfo *innerrel,
41 JoinType jointype,
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,
47 int levels_needed,
48 List *initial_rels);
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,
54 List *initial_rels);
56 extern void generate_gather_paths(PlannerInfo *root, RelOptInfo *rel,
57 bool override_rows);
58 extern void generate_useful_gather_paths(PlannerInfo *root, RelOptInfo *rel,
59 bool override_rows);
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,
63 Path *bitmapqual);
64 extern void generate_partitionwise_join_paths(PlannerInfo *root,
65 RelOptInfo *rel);
68 * indxpath.c
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,
73 List *restrictlist,
74 List *exprlist, List *oprlist);
75 extern bool indexcol_is_bool_constant_for_query(PlannerInfo *root,
76 IndexOptInfo *index,
77 int indexcol);
78 extern bool match_index_to_operand(Node *operand, int indexcol,
79 IndexOptInfo *index);
80 extern void check_index_predicates(PlannerInfo *root, RelOptInfo *rel);
83 * tidpath.c
84 * routines to generate tid paths
86 extern void create_tidscan_paths(PlannerInfo *root, RelOptInfo *rel);
89 * joinpath.c
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,
95 List *restrictlist);
98 * joinrels.c
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);
116 * equivclass.c
117 * routines for managing EquivalenceClasses
119 typedef bool (*ec_matches_callback_type) (PlannerInfo *root,
120 RelOptInfo *rel,
121 EquivalenceClass *ec,
122 EquivalenceMember *em,
123 void *arg);
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,
132 Expr *expr,
133 List *opfamilies,
134 Oid opcintype,
135 Oid collation,
136 Index sortref,
137 Relids rel,
138 bool create_it);
139 extern EquivalenceMember *find_ec_member_matching_expr(EquivalenceClass *ec,
140 Expr *expr,
141 Relids relids);
142 extern EquivalenceMember *find_computable_ec_member(PlannerInfo *root,
143 EquivalenceClass *ec,
144 List *exprs,
145 Relids relids,
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,
152 Relids join_relids,
153 Relids outer_relids,
154 RelOptInfo *inner_rel,
155 SpecialJoinInfo *sjinfo);
156 extern List *generate_join_implied_equalities_for_ecs(PlannerInfo *root,
157 List *eclasses,
158 Relids join_relids,
159 Relids outer_relids,
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,
164 int colno);
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,
172 int nappinfos,
173 AppendRelInfo **appinfos,
174 RelOptInfo *parent_joinrel,
175 RelOptInfo *child_joinrel);
176 extern List *generate_implied_equalities_for_column(PlannerInfo *root,
177 RelOptInfo *rel,
178 ec_matches_callback_type callback,
179 void *callback_arg,
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,
184 RelOptInfo *rel1);
185 extern bool eclass_useful_for_merging(PlannerInfo *root,
186 EquivalenceClass *eclass,
187 RelOptInfo *rel);
188 extern bool is_redundant_derived_clause(RestrictInfo *rinfo, List *clauselist);
189 extern bool is_redundant_with_indexclauses(RestrictInfo *rinfo,
190 List *indexclauses);
193 * pathkeys.c
194 * utilities for matching and building path keys
196 typedef enum
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,
213 List *pathkeys,
214 Relids required_outer,
215 double fraction);
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,
222 Oid opno,
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,
228 RelOptInfo *joinrel,
229 JoinType jointype,
230 List *outer_pathkeys);
231 extern List *make_pathkeys_for_sortclauses(PlannerInfo *root,
232 List *sortclauses,
233 List *tlist);
234 extern List *make_pathkeys_for_sortclauses_extended(PlannerInfo *root,
235 List **sortclauses,
236 List *tlist,
237 bool remove_redundant,
238 bool *sortable);
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,
244 List *pathkeys,
245 List *restrictinfos);
246 extern List *select_outer_pathkeys_for_merge(PlannerInfo *root,
247 List *mergeclauses,
248 RelOptInfo *joinrel);
249 extern List *make_inner_pathkeys_for_merge(PlannerInfo *root,
250 List *mergeclauses,
251 List *outer_pathkeys);
252 extern List *trim_mergeclauses_for_inner_pathkeys(PlannerInfo *root,
253 List *mergeclauses,
254 List *pathkeys);
255 extern List *truncate_useless_pathkeys(PlannerInfo *root,
256 RelOptInfo *rel,
257 List *pathkeys);
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);
266 #endif /* PATHS_H */