PostgreSQL Source Code  git master
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-2020, 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  */
23 extern PGDLLIMPORT bool enable_geqo;
24 extern PGDLLIMPORT 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 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  bool override_rows);
58  bool override_rows);
59 extern int compute_parallel_worker(RelOptInfo *rel, double heap_pages,
60  double index_pages, int max_workers);
61 extern void create_partial_bitmap_paths(PlannerInfo *root, RelOptInfo *rel,
62  Path *bitmapqual);
64  RelOptInfo *rel);
65 
66 #ifdef OPTIMIZER_DEBUG
67 extern void debug_print_rel(PlannerInfo *root, RelOptInfo *rel);
68 #endif
69 
70 /*
71  * indxpath.c
72  * routines to generate index paths
73  */
74 extern void create_index_paths(PlannerInfo *root, RelOptInfo *rel);
76  List *restrictlist,
77  List *exprlist, List *oprlist);
79  int indexcol);
80 extern bool match_index_to_operand(Node *operand, int indexcol,
82 extern void check_index_predicates(PlannerInfo *root, RelOptInfo *rel);
83 
84 /*
85  * tidpath.h
86  * routines to generate tid paths
87  */
88 extern void create_tidscan_paths(PlannerInfo *root, RelOptInfo *rel);
89 
90 /*
91  * joinpath.c
92  * routines to create join paths
93  */
94 extern void add_paths_to_joinrel(PlannerInfo *root, RelOptInfo *joinrel,
95  RelOptInfo *outerrel, RelOptInfo *innerrel,
96  JoinType jointype, SpecialJoinInfo *sjinfo,
97  List *restrictlist);
98 
99 /*
100  * joinrels.c
101  * routines to determine which relations to join
102  */
103 extern void join_search_one_level(PlannerInfo *root, int level);
104 extern RelOptInfo *make_join_rel(PlannerInfo *root,
105  RelOptInfo *rel1, RelOptInfo *rel2);
106 extern bool have_join_order_restriction(PlannerInfo *root,
107  RelOptInfo *rel1, RelOptInfo *rel2);
108 extern bool have_dangerous_phv(PlannerInfo *root,
109  Relids outer_relids, Relids inner_params);
110 extern void mark_dummy_rel(RelOptInfo *rel);
111 
112 /*
113  * equivclass.c
114  * routines for managing EquivalenceClasses
115  */
117  RelOptInfo *rel,
118  EquivalenceClass *ec,
119  EquivalenceMember *em,
120  void *arg);
121 
122 extern bool process_equivalence(PlannerInfo *root,
123  RestrictInfo **p_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);
140  Relids join_relids,
141  Relids outer_relids,
142  RelOptInfo *inner_rel);
144  List *eclasses,
145  Relids join_relids,
146  Relids outer_relids,
147  RelOptInfo *inner_rel);
148 extern bool exprs_known_equal(PlannerInfo *root, Node *item1, Node *item2);
150  ForeignKeyOptInfo *fkinfo,
151  int colno);
152 extern void add_child_rel_equivalences(PlannerInfo *root,
153  AppendRelInfo *appinfo,
154  RelOptInfo *parent_rel,
155  RelOptInfo *child_rel);
157  int nappinfos,
158  AppendRelInfo **appinfos,
159  RelOptInfo *parent_rel,
160  RelOptInfo *child_rel);
162  RelOptInfo *rel,
164  void *callback_arg,
165  Relids prohibited_rels);
167  RelOptInfo *rel1, RelOptInfo *rel2);
169  RelOptInfo *rel1);
170 extern bool eclass_useful_for_merging(PlannerInfo *root,
172  RelOptInfo *rel);
173 extern bool is_redundant_derived_clause(RestrictInfo *rinfo, List *clauselist);
175  List *indexclauses);
176 
177 /*
178  * pathkeys.c
179  * utilities for matching and building path keys
180  */
181 typedef enum
182 {
183  PATHKEYS_EQUAL, /* pathkeys are identical */
184  PATHKEYS_BETTER1, /* pathkey 1 is a superset of pathkey 2 */
185  PATHKEYS_BETTER2, /* vice versa */
186  PATHKEYS_DIFFERENT /* neither pathkey includes the other */
188 
189 extern PathKeysComparison compare_pathkeys(List *keys1, List *keys2);
190 extern bool pathkeys_contained_in(List *keys1, List *keys2);
191 extern bool pathkeys_count_contained_in(List *keys1, List *keys2, int *n_common);
192 extern Path *get_cheapest_path_for_pathkeys(List *paths, List *pathkeys,
193  Relids required_outer,
194  CostSelector cost_criterion,
195  bool require_parallel_safe);
197  List *pathkeys,
198  Relids required_outer,
199  double fraction);
202  ScanDirection scandir);
203 extern List *build_partition_pathkeys(PlannerInfo *root, RelOptInfo *partrel,
204  ScanDirection scandir, bool *partialkeys);
205 extern List *build_expression_pathkey(PlannerInfo *root, Expr *expr,
206  Relids nullable_relids, Oid opno,
207  Relids rel, bool create_it);
209  List *subquery_pathkeys,
210  List *subquery_tlist);
211 extern List *build_join_pathkeys(PlannerInfo *root,
212  RelOptInfo *joinrel,
213  JoinType jointype,
214  List *outer_pathkeys);
216  List *sortclauses,
217  List *tlist);
219  RestrictInfo *restrictinfo);
220 extern void update_mergeclause_eclasses(PlannerInfo *root,
221  RestrictInfo *restrictinfo);
223  List *pathkeys,
224  List *restrictinfos);
226  List *mergeclauses,
227  RelOptInfo *joinrel);
229  List *mergeclauses,
230  List *outer_pathkeys);
232  List *mergeclauses,
233  List *pathkeys);
235  RelOptInfo *rel,
236  List *pathkeys);
237 extern bool has_useful_pathkeys(PlannerInfo *root, RelOptInfo *rel);
239  EquivalenceClass *eclass, Oid opfamily,
240  int strategy, bool nulls_first);
241 extern void add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
242  List *live_childrels);
243 
244 #endif /* PATHS_H */
bool is_redundant_derived_clause(RestrictInfo *rinfo, List *clauselist)
Definition: equivclass.c:2824
bool eclass_useful_for_merging(PlannerInfo *root, EquivalenceClass *eclass, RelOptInfo *rel)
Definition: equivclass.c:2766
List * build_partition_pathkeys(PlannerInfo *root, RelOptInfo *partrel, ScanDirection scandir, bool *partialkeys)
Definition: pathkeys.c:699
PGDLLIMPORT int geqo_threshold
Definition: allpaths.c:63
bool is_redundant_with_indexclauses(RestrictInfo *rinfo, List *indexclauses)
Definition: equivclass.c:2851
void create_tidscan_paths(PlannerInfo *root, RelOptInfo *rel)
Definition: tidpath.c:385
bool process_equivalence(PlannerInfo *root, RestrictInfo **p_restrictinfo, bool below_outer_join)
Definition: equivclass.c:118
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:686
List * truncate_useless_pathkeys(PlannerInfo *root, RelOptInfo *rel, List *pathkeys)
Definition: pathkeys.c:1870
List * generate_join_implied_equalities_for_ecs(PlannerInfo *root, List *eclasses, Relids join_relids, Relids outer_relids, RelOptInfo *inner_rel)
Definition: equivclass.c:1232
Path * get_cheapest_path_for_pathkeys(List *paths, List *pathkeys, Relids required_outer, CostSelector cost_criterion, bool require_parallel_safe)
Definition: pathkeys.c:404
List * build_join_pathkeys(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, List *outer_pathkeys)
Definition: pathkeys.c:1082
bool have_join_order_restriction(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
Definition: joinrels.c:951
Definition: nodes.h:529
List * trim_mergeclauses_for_inner_pathkeys(PlannerInfo *root, List *mergeclauses, List *pathkeys)
Definition: pathkeys.c:1650
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:285
bool relation_has_unique_index_for(PlannerInfo *root, RelOptInfo *rel, List *restrictlist, List *exprlist, List *oprlist)
Definition: indxpath.c:3499
unsigned int Oid
Definition: postgres_ext.h:31
RelOptInfo * make_one_rel(PlannerInfo *root, List *joinlist)
Definition: allpaths.c:152
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:324
Expr * canonicalize_ec_expression(Expr *expr, Oid req_type, Oid req_collation)
Definition: equivclass.c:499
int compute_parallel_worker(RelOptInfo *rel, double heap_pages, double index_pages, int max_workers)
Definition: allpaths.c:3808
void create_index_paths(PlannerInfo *root, RelOptInfo *rel)
Definition: indxpath.c:231
#define PGDLLIMPORT
Definition: c.h:1286
static struct cvec * eclass(struct vars *v, chr c, int cases)
Definition: regc_locale.c:508
JoinType
Definition: nodes.h:696
Definition: type.h:89
void add_child_rel_equivalences(PlannerInfo *root, AppendRelInfo *appinfo, RelOptInfo *parent_rel, RelOptInfo *child_rel)
Definition: equivclass.c:2256
bool exprs_known_equal(PlannerInfo *root, Node *item1, Node *item2)
Definition: equivclass.c:2113
void initialize_mergeclause_eclasses(PlannerInfo *root, RestrictInfo *restrictinfo)
Definition: pathkeys.c:1179
List * generate_implied_equalities_for_column(PlannerInfo *root, RelOptInfo *rel, ec_matches_callback_type callback, void *callback_arg, Relids prohibited_rels)
Definition: equivclass.c:2525
List * build_index_pathkeys(PlannerInfo *root, IndexOptInfo *index, ScanDirection scandir)
Definition: pathkeys.c:523
void generate_base_implied_equalities(PlannerInfo *root)
Definition: equivclass.c:855
void generate_partitionwise_join_paths(PlannerInfo *root, RelOptInfo *rel)
Definition: allpaths.c:3896
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48
Path * get_cheapest_fractional_path_for_pathkeys(List *paths, List *pathkeys, Relids required_outer, double fraction)
Definition: pathkeys.c:449
PGDLLIMPORT join_search_hook_type join_search_hook
Definition: allpaths.c:71
List * find_mergeclauses_for_outer_pathkeys(PlannerInfo *root, List *pathkeys, List *restrictinfos)
Definition: pathkeys.c:1262
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:625
bool match_index_to_operand(Node *operand, int indexcol, IndexOptInfo *index)
Definition: indxpath.c:3719
ScanDirection
Definition: sdir.h:22
PGDLLIMPORT int min_parallel_table_scan_size
Definition: allpaths.c:64
PGDLLIMPORT set_join_pathlist_hook_type set_join_pathlist_hook
Definition: joinpath.c:27
PGDLLIMPORT int min_parallel_index_scan_size
Definition: allpaths.c:65
void reconsider_outer_join_clauses(PlannerInfo *root)
Definition: equivclass.c:1716
void add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel, List *live_childrels)
Definition: allpaths.c:1297
List * build_expression_pathkey(PlannerInfo *root, Expr *expr, Relids nullable_relids, Oid opno, Relids rel, bool create_it)
Definition: pathkeys.c:782
bool has_useful_pathkeys(PlannerInfo *root, RelOptInfo *rel)
Definition: pathkeys.c:1910
bool have_dangerous_phv(PlannerInfo *root, Relids outer_relids, Relids inner_params)
Definition: joinrels.c:1184
PGDLLIMPORT bool enable_geqo
Definition: allpaths.c:62
unsigned int Index
Definition: c.h:482
Expr * find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel)
Definition: equivclass.c:782
void generate_gather_paths(PlannerInfo *root, RelOptInfo *rel, bool override_rows)
Definition: allpaths.c:2685
void create_partial_bitmap_paths(PlannerInfo *root, RelOptInfo *rel, Path *bitmapqual)
Definition: allpaths.c:3772
CostSelector
Definition: pathnodes.h:34
RelOptInfo * standard_join_search(PlannerInfo *root, int levels_needed, List *initial_rels)
Definition: allpaths.c:3062
bool(* ec_matches_callback_type)(PlannerInfo *root, RelOptInfo *rel, EquivalenceClass *ec, EquivalenceMember *em, void *arg)
Definition: paths.h:116
void(* set_rel_pathlist_hook_type)(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
Definition: paths.h:29
bool pathkeys_count_contained_in(List *keys1, List *keys2, int *n_common)
Definition: pathkeys.c:343
List * make_inner_pathkeys_for_merge(PlannerInfo *root, List *mergeclauses, List *outer_pathkeys)
Definition: pathkeys.c:1547
void add_paths_to_joinrel(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: joinpath.c:117
bool have_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
Definition: equivclass.c:2655
Path * get_cheapest_parallel_safe_total_inner(List *paths)
Definition: pathkeys.c:482
void(* set_join_pathlist_hook_type)(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, JoinPathExtraData *extra)
Definition: paths.h:36
void check_index_predicates(PlannerInfo *root, RelOptInfo *rel)
Definition: indxpath.c:3308
List * convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel, List *subquery_pathkeys, List *subquery_tlist)
Definition: pathkeys.c:838
void join_search_one_level(PlannerInfo *root, int level)
Definition: joinrels.c:71
PathKeysComparison
Definition: paths.h:181
bool has_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1)
Definition: equivclass.c:2722
EquivalenceClass * match_eclasses_to_foreign_key_col(PlannerInfo *root, ForeignKeyOptInfo *fkinfo, int colno)
Definition: equivclass.c:2160
bool indexcol_is_bool_constant_for_query(IndexOptInfo *index, int indexcol)
Definition: indxpath.c:3670
void * arg
void add_child_join_rel_equivalences(PlannerInfo *root, int nappinfos, AppendRelInfo **appinfos, RelOptInfo *parent_rel, RelOptInfo *child_rel)
Definition: equivclass.c:2384
void mark_dummy_rel(RelOptInfo *rel)
Definition: joinrels.c:1261
List * select_outer_pathkeys_for_merge(PlannerInfo *root, List *mergeclauses, RelOptInfo *joinrel)
Definition: pathkeys.c:1375
void generate_useful_gather_paths(PlannerInfo *root, RelOptInfo *rel, bool override_rows)
Definition: allpaths.c:2816
PGDLLIMPORT set_rel_pathlist_hook_type set_rel_pathlist_hook
Definition: allpaths.c:68
void update_mergeclause_eclasses(PlannerInfo *root, RestrictInfo *restrictinfo)
Definition: pathkeys.c:1228
Definition: pg_list.h:50
List * make_pathkeys_for_sortclauses(PlannerInfo *root, List *sortclauses, List *tlist)
Definition: pathkeys.c:1125
unsigned char bool
Definition: c.h:324
List * generate_join_implied_equalities(PlannerInfo *root, Relids join_relids, Relids outer_relids, RelOptInfo *inner_rel)
Definition: equivclass.c:1154
PathKey * make_canonical_pathkey(PlannerInfo *root, EquivalenceClass *eclass, Oid opfamily, int strategy, bool nulls_first)
Definition: pathkeys.c:54