PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
paths.h
Go to the documentation of this file.
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 bool enable_geqo;
24 extern int geqo_threshold;
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);
34 
35 /* Hook for plugins to get control in add_paths_to_joinrel() */
37  RelOptInfo *joinrel,
38  RelOptInfo *outerrel,
39  RelOptInfo *innerrel,
40  JoinType jointype,
41  JoinPathExtraData *extra);
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);
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, BlockNumber heap_pages,
58  BlockNumber index_pages);
59 
60 #ifdef OPTIMIZER_DEBUG
61 extern void debug_print_rel(PlannerInfo *root, RelOptInfo *rel);
62 #endif
63 
64 /*
65  * indxpath.c
66  * routines to generate index paths
67  */
68 extern void create_index_paths(PlannerInfo *root, RelOptInfo *rel);
70  List *restrictlist,
71  List *exprlist, List *oprlist);
73  int indexcol);
74 extern bool match_index_to_operand(Node *operand, int indexcol,
77  List *indexclauses, List *indexclausecols,
78  List **indexquals_p, List **indexqualcols_p);
79 extern void check_index_predicates(PlannerInfo *root, RelOptInfo *rel);
82  int indexcol,
83  List **indexcolnos,
84  bool *var_on_left_p);
85 
86 /*
87  * tidpath.h
88  * routines to generate tid paths
89  */
90 extern void create_tidscan_paths(PlannerInfo *root, RelOptInfo *rel);
91 
92 /*
93  * joinpath.c
94  * routines to create join paths
95  */
96 extern void add_paths_to_joinrel(PlannerInfo *root, RelOptInfo *joinrel,
97  RelOptInfo *outerrel, RelOptInfo *innerrel,
98  JoinType jointype, SpecialJoinInfo *sjinfo,
99  List *restrictlist);
100 
101 /*
102  * joinrels.c
103  * routines to determine which relations to join
104  */
105 extern void join_search_one_level(PlannerInfo *root, int level);
106 extern RelOptInfo *make_join_rel(PlannerInfo *root,
107  RelOptInfo *rel1, RelOptInfo *rel2);
108 extern bool have_join_order_restriction(PlannerInfo *root,
109  RelOptInfo *rel1, RelOptInfo *rel2);
110 extern bool have_dangerous_phv(PlannerInfo *root,
111  Relids outer_relids, Relids inner_params);
112 
113 /*
114  * equivclass.c
115  * routines for managing EquivalenceClasses
116  */
118  RelOptInfo *rel,
119  EquivalenceClass *ec,
120  EquivalenceMember *em,
121  void *arg);
122 
123 extern bool process_equivalence(PlannerInfo *root, RestrictInfo *restrictinfo,
124  bool below_outer_join);
125 extern Expr *canonicalize_ec_expression(Expr *expr,
126  Oid req_type, Oid req_collation);
127 extern void reconsider_outer_join_clauses(PlannerInfo *root);
129  Expr *expr,
130  Relids nullable_relids,
131  List *opfamilies,
132  Oid opcintype,
133  Oid collation,
134  Index sortref,
135  Relids rel,
136  bool create_it);
139  Relids join_relids,
140  Relids outer_relids,
141  RelOptInfo *inner_rel);
143  List *eclasses,
144  Relids join_relids,
145  Relids outer_relids,
146  RelOptInfo *inner_rel);
147 extern bool exprs_known_equal(PlannerInfo *root, Node *item1, Node *item2);
149  ForeignKeyOptInfo *fkinfo,
150  int colno);
151 extern void add_child_rel_equivalences(PlannerInfo *root,
152  AppendRelInfo *appinfo,
153  RelOptInfo *parent_rel,
154  RelOptInfo *child_rel);
156  RelOptInfo *rel,
158  void *callback_arg,
159  Relids prohibited_rels);
161  RelOptInfo *rel1, RelOptInfo *rel2);
163  RelOptInfo *rel1);
164 extern bool eclass_useful_for_merging(PlannerInfo *root,
166  RelOptInfo *rel);
167 extern bool is_redundant_derived_clause(RestrictInfo *rinfo, List *clauselist);
168 
169 /*
170  * pathkeys.c
171  * utilities for matching and building path keys
172  */
173 typedef enum
174 {
175  PATHKEYS_EQUAL, /* pathkeys are identical */
176  PATHKEYS_BETTER1, /* pathkey 1 is a superset of pathkey 2 */
177  PATHKEYS_BETTER2, /* vice versa */
178  PATHKEYS_DIFFERENT /* neither pathkey includes the other */
180 
181 extern PathKeysComparison compare_pathkeys(List *keys1, List *keys2);
182 extern bool pathkeys_contained_in(List *keys1, List *keys2);
183 extern Path *get_cheapest_path_for_pathkeys(List *paths, List *pathkeys,
184  Relids required_outer,
185  CostSelector cost_criterion);
187  List *pathkeys,
188  Relids required_outer,
189  double fraction);
191  ScanDirection scandir);
192 extern List *build_expression_pathkey(PlannerInfo *root, Expr *expr,
193  Relids nullable_relids, Oid opno,
194  Relids rel, bool create_it);
196  List *subquery_pathkeys,
197  List *subquery_tlist);
198 extern List *build_join_pathkeys(PlannerInfo *root,
199  RelOptInfo *joinrel,
200  JoinType jointype,
201  List *outer_pathkeys);
203  List *sortclauses,
204  List *tlist);
206  RestrictInfo *restrictinfo);
207 extern void update_mergeclause_eclasses(PlannerInfo *root,
208  RestrictInfo *restrictinfo);
210  List *pathkeys,
211  bool outer_keys,
212  List *restrictinfos);
214  List *mergeclauses,
215  RelOptInfo *joinrel);
217  List *mergeclauses,
218  List *outer_pathkeys);
220  RelOptInfo *rel,
221  List *pathkeys);
222 extern bool has_useful_pathkeys(PlannerInfo *root, RelOptInfo *rel);
224  EquivalenceClass *eclass, Oid opfamily,
225  int strategy, bool nulls_first);
226 
227 #endif /* PATHS_H */
bool is_redundant_derived_clause(RestrictInfo *rinfo, List *clauselist)
Definition: equivclass.c:2448
bool eclass_useful_for_merging(PlannerInfo *root, EquivalenceClass *eclass, RelOptInfo *rel)
Definition: equivclass.c:2393
void generate_gather_paths(PlannerInfo *root, RelOptInfo *rel)
Definition: allpaths.c:2058
void create_tidscan_paths(PlannerInfo *root, RelOptInfo *rel)
Definition: tidpath.c:253
RelOptInfo *(* join_search_hook_type)(PlannerInfo *root, int levels_needed, List *initial_rels)
Definition: paths.h:45
RelOptInfo * make_join_rel(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
Definition: joinrels.c:654
List * truncate_useless_pathkeys(PlannerInfo *root, RelOptInfo *rel, List *pathkeys)
Definition: pathkeys.c:1491
List * generate_join_implied_equalities_for_ecs(PlannerInfo *root, List *eclasses, Relids join_relids, Relids outer_relids, RelOptInfo *inner_rel)
Definition: equivclass.c:1050
void set_dummy_rel_pathlist(RelOptInfo *rel)
Definition: allpaths.c:1616
bool enable_geqo
Definition: allpaths.c:58
List * build_join_pathkeys(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, List *outer_pathkeys)
Definition: pathkeys.c:795
bool have_join_order_restriction(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
Definition: joinrels.c:899
Definition: nodes.h:509
uint32 BlockNumber
Definition: block.h:31
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:278
bool relation_has_unique_index_for(PlannerInfo *root, RelOptInfo *rel, List *restrictlist, List *exprlist, List *oprlist)
Definition: indxpath.c:2941
unsigned int Oid
Definition: postgres_ext.h:31
RelOptInfo * make_one_rel(PlannerInfo *root, List *joinlist)
Definition: allpaths.c:138
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:317
int min_parallel_index_scan_size
Definition: allpaths.c:61
Expr * canonicalize_ec_expression(Expr *expr, Oid req_type, Oid req_collation)
Definition: equivclass.c:456
Expr * adjust_rowcompare_for_index(RowCompareExpr *clause, IndexOptInfo *index, int indexcol, List **indexcolnos, bool *var_on_left_p)
Definition: indxpath.c:3805
void create_index_paths(PlannerInfo *root, RelOptInfo *rel)
Definition: indxpath.c:232
#define PGDLLIMPORT
Definition: c.h:1063
char bool
Definition: c.h:199
static struct cvec * eclass(struct vars *v, chr c, int cases)
Definition: regc_locale.c:508
JoinType
Definition: nodes.h:666
bool(* ec_matches_callback_type)(PlannerInfo *root, RelOptInfo *rel, EquivalenceClass *ec, EquivalenceMember *em, void *arg)
Definition: paths.h:117
Definition: type.h:90
void add_child_rel_equivalences(PlannerInfo *root, AppendRelInfo *appinfo, RelOptInfo *parent_rel, RelOptInfo *child_rel)
Definition: equivclass.c:2068
bool exprs_known_equal(PlannerInfo *root, Node *item1, Node *item2)
Definition: equivclass.c:1943
void(* set_join_pathlist_hook_type)(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, JoinPathExtraData *extra)
Definition: paths.h:36
void initialize_mergeclause_eclasses(PlannerInfo *root, RestrictInfo *restrictinfo)
Definition: pathkeys.c:892
List * generate_implied_equalities_for_column(PlannerInfo *root, RelOptInfo *rel, ec_matches_callback_type callback, void *callback_arg, Relids prohibited_rels)
Definition: equivclass.c:2172
List * build_index_pathkeys(PlannerInfo *root, IndexOptInfo *index, ScanDirection scandir)
Definition: pathkeys.c:433
void generate_base_implied_equalities(PlannerInfo *root)
Definition: equivclass.c:762
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:49
Path * get_cheapest_fractional_path_for_pathkeys(List *paths, List *pathkeys, Relids required_outer, double fraction)
Definition: pathkeys.c:383
PGDLLIMPORT join_search_hook_type join_search_hook
Definition: allpaths.c:67
EquivalenceClass * get_eclass_for_sort_expr(PlannerInfo *root, Expr *expr, Relids nullable_relids, List *opfamilies, Oid opcintype, Oid collation, Index sortref, Relids rel, bool create_it)
Definition: equivclass.c:581
bool match_index_to_operand(Node *operand, int indexcol, IndexOptInfo *index)
Definition: indxpath.c:3161
ScanDirection
Definition: sdir.h:22
PGDLLIMPORT set_join_pathlist_hook_type set_join_pathlist_hook
Definition: joinpath.c:26
void reconsider_outer_join_clauses(PlannerInfo *root)
Definition: equivclass.c:1532
List * build_expression_pathkey(PlannerInfo *root, Expr *expr, Relids nullable_relids, Oid opno, Relids rel, bool create_it)
Definition: pathkeys.c:526
bool process_equivalence(PlannerInfo *root, RestrictInfo *restrictinfo, bool below_outer_join)
Definition: equivclass.c:107
int compute_parallel_worker(RelOptInfo *rel, BlockNumber heap_pages, BlockNumber index_pages)
Definition: allpaths.c:2887
bool has_useful_pathkeys(PlannerInfo *root, RelOptInfo *rel)
Definition: pathkeys.c:1531
bool have_dangerous_phv(PlannerInfo *root, Relids outer_relids, Relids inner_params)
Definition: joinrels.c:1132
void(* set_rel_pathlist_hook_type)(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
Definition: paths.h:29
unsigned int Index
Definition: c.h:362
List * find_mergeclauses_for_pathkeys(PlannerInfo *root, List *pathkeys, bool outer_keys, List *restrictinfos)
Definition: pathkeys.c:976
RelOptInfo * standard_join_search(PlannerInfo *root, int levels_needed, List *initial_rels)
Definition: allpaths.c:2198
List * make_inner_pathkeys_for_merge(PlannerInfo *root, List *mergeclauses, List *outer_pathkeys)
Definition: pathkeys.c:1265
void add_paths_to_joinrel(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: joinpath.c:88
CostSelector
Definition: relation.h:34
bool have_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
Definition: equivclass.c:2300
Path * get_cheapest_path_for_pathkeys(List *paths, List *pathkeys, Relids required_outer, CostSelector cost_criterion)
Definition: pathkeys.c:342
void check_index_predicates(PlannerInfo *root, RelOptInfo *rel)
Definition: indxpath.c:2759
List * convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel, List *subquery_pathkeys, List *subquery_tlist)
Definition: pathkeys.c:580
void join_search_one_level(PlannerInfo *root, int level)
Definition: joinrels.c:51
int geqo_threshold
Definition: allpaths.c:59
PathKeysComparison
Definition: paths.h:173
bool has_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1)
Definition: equivclass.c:2354
EquivalenceClass * match_eclasses_to_foreign_key_col(PlannerInfo *root, ForeignKeyOptInfo *fkinfo, int colno)
Definition: equivclass.c:1990
bool indexcol_is_bool_constant_for_query(IndexOptInfo *index, int indexcol)
Definition: indxpath.c:3112
void * arg
List * select_outer_pathkeys_for_merge(PlannerInfo *root, List *mergeclauses, RelOptInfo *joinrel)
Definition: pathkeys.c:1093
PGDLLIMPORT set_rel_pathlist_hook_type set_rel_pathlist_hook
Definition: allpaths.c:64
void expand_indexqual_conditions(IndexOptInfo *index, List *indexclauses, List *indexclausecols, List **indexquals_p, List **indexqualcols_p)
Definition: indxpath.c:3507
void update_mergeclause_eclasses(PlannerInfo *root, RestrictInfo *restrictinfo)
Definition: pathkeys.c:941
Definition: pg_list.h:45
int min_parallel_table_scan_size
Definition: allpaths.c:60
Definition: relation.h:888
List * make_pathkeys_for_sortclauses(PlannerInfo *root, List *sortclauses, List *tlist)
Definition: pathkeys.c:838
List * generate_join_implied_equalities(PlannerInfo *root, Relids join_relids, Relids outer_relids, RelOptInfo *inner_rel)
Definition: equivclass.c:1033
PathKey * make_canonical_pathkey(PlannerInfo *root, EquivalenceClass *eclass, Oid opfamily, int strategy, bool nulls_first)
Definition: pathkeys.c:51