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