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