1/*-------------------------------------------------------------------------
2 *
3 * paths.h
4 * prototypes for various files in optimizer/path
5 *
6 *
7 * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
9 *
10 * src/include/optimizer/paths.h
11 *
12 *-------------------------------------------------------------------------
13 */
14#ifndef PATHS_H
15#define PATHS_H
16
17#include "nodes/pathnodes.h"
18
19
20/*
21 * allpaths.c
22 */
23extern PGDLLIMPORT bool enable_geqo;
24extern PGDLLIMPORT int geqo_threshold;
25extern PGDLLIMPORT int min_parallel_table_scan_size;
26extern PGDLLIMPORT int min_parallel_index_scan_size;
27
28/* Hook for plugins to get control in set_rel_pathlist() */
29typedef void (*set_rel_pathlist_hook_type) (PlannerInfo *root,
30 RelOptInfo *rel,
31 Index rti,
32 RangeTblEntry *rte);
33extern PGDLLIMPORT set_rel_pathlist_hook_type set_rel_pathlist_hook;
34
35/* Hook for plugins to get control in add_paths_to_joinrel() */
36typedef void (*set_join_pathlist_hook_type) (PlannerInfo *root,
37 RelOptInfo *joinrel,
38 RelOptInfo *outerrel,
39 RelOptInfo *innerrel,
40 JoinType jointype,
41 JoinPathExtraData *extra);
42extern PGDLLIMPORT set_join_pathlist_hook_type set_join_pathlist_hook;
43
44/* Hook for plugins to replace standard_join_search() */
45typedef RelOptInfo *(*join_search_hook_type) (PlannerInfo *root,
46 int levels_needed,
47 List *initial_rels);
48extern PGDLLIMPORT join_search_hook_type join_search_hook;
49
50
51extern RelOptInfo *make_one_rel(PlannerInfo *root, List *joinlist);
52extern RelOptInfo *standard_join_search(PlannerInfo *root, int levels_needed,
53 List *initial_rels);
54
55extern void generate_gather_paths(PlannerInfo *root, RelOptInfo *rel,
56 bool override_rows);
57extern int compute_parallel_worker(RelOptInfo *rel, double heap_pages,
58 double index_pages, int max_workers);
59extern void create_partial_bitmap_paths(PlannerInfo *root, RelOptInfo *rel,
60 Path *bitmapqual);
61extern void generate_partitionwise_join_paths(PlannerInfo *root,
62 RelOptInfo *rel);
63
64#ifdef OPTIMIZER_DEBUG
65extern void debug_print_rel(PlannerInfo *root, RelOptInfo *rel);
66#endif
67
68/*
69 * indxpath.c
70 * routines to generate index paths
71 */
72extern void create_index_paths(PlannerInfo *root, RelOptInfo *rel);
73extern bool relation_has_unique_index_for(PlannerInfo *root, RelOptInfo *rel,
74 List *restrictlist,
75 List *exprlist, List *oprlist);
76extern bool indexcol_is_bool_constant_for_query(IndexOptInfo *index,
77 int indexcol);
78extern bool match_index_to_operand(Node *operand, int indexcol,
79 IndexOptInfo *index);
80extern void check_index_predicates(PlannerInfo *root, RelOptInfo *rel);
81
82/*
83 * tidpath.h
84 * routines to generate tid paths
85 */
86extern void create_tidscan_paths(PlannerInfo *root, RelOptInfo *rel);
87
88/*
89 * joinpath.c
90 * routines to create join paths
91 */
92extern void add_paths_to_joinrel(PlannerInfo *root, RelOptInfo *joinrel,
93 RelOptInfo *outerrel, RelOptInfo *innerrel,
94 JoinType jointype, SpecialJoinInfo *sjinfo,
95 List *restrictlist);
96
97/*
98 * joinrels.c
99 * routines to determine which relations to join
100 */
101extern void join_search_one_level(PlannerInfo *root, int level);
102extern RelOptInfo *make_join_rel(PlannerInfo *root,
103 RelOptInfo *rel1, RelOptInfo *rel2);
104extern bool have_join_order_restriction(PlannerInfo *root,
105 RelOptInfo *rel1, RelOptInfo *rel2);
106extern bool have_dangerous_phv(PlannerInfo *root,
107 Relids outer_relids, Relids inner_params);
108extern void mark_dummy_rel(RelOptInfo *rel);
109extern bool have_partkey_equi_join(RelOptInfo *joinrel,
110 RelOptInfo *rel1, RelOptInfo *rel2,
111 JoinType jointype, List *restrictlist);
112
113/*
114 * equivclass.c
115 * routines for managing EquivalenceClasses
116 */
117typedef bool (*ec_matches_callback_type) (PlannerInfo *root,
118 RelOptInfo *rel,
119 EquivalenceClass *ec,
120 EquivalenceMember *em,
121 void *arg);
122
123extern bool process_equivalence(PlannerInfo *root,
124 RestrictInfo **p_restrictinfo,
125 bool below_outer_join);
126extern Expr *canonicalize_ec_expression(Expr *expr,
127 Oid req_type, Oid req_collation);
128extern void reconsider_outer_join_clauses(PlannerInfo *root);
129extern EquivalenceClass *get_eclass_for_sort_expr(PlannerInfo *root,
130 Expr *expr,
131 Relids nullable_relids,
132 List *opfamilies,
133 Oid opcintype,
134 Oid collation,
135 Index sortref,
136 Relids rel,
137 bool create_it);
138extern void generate_base_implied_equalities(PlannerInfo *root);
139extern List *generate_join_implied_equalities(PlannerInfo *root,
140 Relids join_relids,
141 Relids outer_relids,
142 RelOptInfo *inner_rel);
143extern List *generate_join_implied_equalities_for_ecs(PlannerInfo *root,
144 List *eclasses,
145 Relids join_relids,
146 Relids outer_relids,
147 RelOptInfo *inner_rel);
148extern bool exprs_known_equal(PlannerInfo *root, Node *item1, Node *item2);
149extern EquivalenceClass *match_eclasses_to_foreign_key_col(PlannerInfo *root,
150 ForeignKeyOptInfo *fkinfo,
151 int colno);
152extern void add_child_rel_equivalences(PlannerInfo *root,
153 AppendRelInfo *appinfo,
154 RelOptInfo *parent_rel,
155 RelOptInfo *child_rel);
156extern List *generate_implied_equalities_for_column(PlannerInfo *root,
157 RelOptInfo *rel,
158 ec_matches_callback_type callback,
159 void *callback_arg,
160 Relids prohibited_rels);
161extern bool have_relevant_eclass_joinclause(PlannerInfo *root,
162 RelOptInfo *rel1, RelOptInfo *rel2);
163extern bool has_relevant_eclass_joinclause(PlannerInfo *root,
164 RelOptInfo *rel1);
165extern bool eclass_useful_for_merging(PlannerInfo *root,
166 EquivalenceClass *eclass,
167 RelOptInfo *rel);
168extern bool is_redundant_derived_clause(RestrictInfo *rinfo, List *clauselist);
169extern bool is_redundant_with_indexclauses(RestrictInfo *rinfo,
170 List *indexclauses);
171
172/*
173 * pathkeys.c
174 * utilities for matching and building path keys
175 */
176typedef enum
177{
178 PATHKEYS_EQUAL, /* pathkeys are identical */
179 PATHKEYS_BETTER1, /* pathkey 1 is a superset of pathkey 2 */
180 PATHKEYS_BETTER2, /* vice versa */
181 PATHKEYS_DIFFERENT /* neither pathkey includes the other */
182} PathKeysComparison;
183
184extern PathKeysComparison compare_pathkeys(List *keys1, List *keys2);
185extern bool pathkeys_contained_in(List *keys1, List *keys2);
186extern Path *get_cheapest_path_for_pathkeys(List *paths, List *pathkeys,
187 Relids required_outer,
188 CostSelector cost_criterion,
189 bool require_parallel_safe);
190extern Path *get_cheapest_fractional_path_for_pathkeys(List *paths,
191 List *pathkeys,
192 Relids required_outer,
193 double fraction);
194extern Path *get_cheapest_parallel_safe_total_inner(List *paths);
195extern List *build_index_pathkeys(PlannerInfo *root, IndexOptInfo *index,
196 ScanDirection scandir);
197extern List *build_partition_pathkeys(PlannerInfo *root, RelOptInfo *partrel,
198 ScanDirection scandir, bool *partialkeys);
199extern List *build_expression_pathkey(PlannerInfo *root, Expr *expr,
200 Relids nullable_relids, Oid opno,
201 Relids rel, bool create_it);
202extern List *convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel,
203 List *subquery_pathkeys,
204 List *subquery_tlist);
205extern List *build_join_pathkeys(PlannerInfo *root,
206 RelOptInfo *joinrel,
207 JoinType jointype,
208 List *outer_pathkeys);
209extern List *make_pathkeys_for_sortclauses(PlannerInfo *root,
210 List *sortclauses,
211 List *tlist);
212extern void initialize_mergeclause_eclasses(PlannerInfo *root,
213 RestrictInfo *restrictinfo);
214extern void update_mergeclause_eclasses(PlannerInfo *root,
215 RestrictInfo *restrictinfo);
216extern List *find_mergeclauses_for_outer_pathkeys(PlannerInfo *root,
217 List *pathkeys,
218 List *restrictinfos);
219extern List *select_outer_pathkeys_for_merge(PlannerInfo *root,
220 List *mergeclauses,
221 RelOptInfo *joinrel);
222extern List *make_inner_pathkeys_for_merge(PlannerInfo *root,
223 List *mergeclauses,
224 List *outer_pathkeys);
225extern List *trim_mergeclauses_for_inner_pathkeys(PlannerInfo *root,
226 List *mergeclauses,
227 List *pathkeys);
228extern List *truncate_useless_pathkeys(PlannerInfo *root,
229 RelOptInfo *rel,
230 List *pathkeys);
231extern bool has_useful_pathkeys(PlannerInfo *root, RelOptInfo *rel);
232extern PathKey *make_canonical_pathkey(PlannerInfo *root,
233 EquivalenceClass *eclass, Oid opfamily,
234 int strategy, bool nulls_first);
235extern void add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
236 List *live_childrels);
237
238#endif /* PATHS_H */
239