PostgreSQL Source Code  git master
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-2022, 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
17 #include "nodes/pathnodes.h"
20 /*
21  * allpaths.c
22  */
23 extern PGDLLIMPORT bool enable_geqo;
24 extern PGDLLIMPORT int geqo_threshold;
29 /* Hook for plugins to get control in set_rel_pathlist() */
30 typedef void (*set_rel_pathlist_hook_type) (PlannerInfo *root,
31  RelOptInfo *rel,
32  Index rti,
33  RangeTblEntry *rte);
36 /* Hook for plugins to get control in add_paths_to_joinrel() */
38  RelOptInfo *joinrel,
39  RelOptInfo *outerrel,
40  RelOptInfo *innerrel,
41  JoinType jointype,
42  JoinPathExtraData *extra);
45 /* Hook for plugins to replace standard_join_search() */
46 typedef RelOptInfo *(*join_search_hook_type) (PlannerInfo *root,
47  int levels_needed,
48  List *initial_rels);
52 extern RelOptInfo *make_one_rel(PlannerInfo *root, List *joinlist);
53 extern RelOptInfo *standard_join_search(PlannerInfo *root, int levels_needed,
54  List *initial_rels);
56 extern void generate_gather_paths(PlannerInfo *root, RelOptInfo *rel,
57  bool override_rows);
59  bool override_rows);
60 extern int compute_parallel_worker(RelOptInfo *rel, double heap_pages,
61  double index_pages, int max_workers);
62 extern void create_partial_bitmap_paths(PlannerInfo *root, RelOptInfo *rel,
63  Path *bitmapqual);
65  RelOptInfo *rel);
68 extern void debug_print_rel(PlannerInfo *root, RelOptInfo *rel);
69 #endif
71 /*
72  * indxpath.c
73  * routines to generate index paths
74  */
75 extern void create_index_paths(PlannerInfo *root, RelOptInfo *rel);
77  List *restrictlist,
78  List *exprlist, List *oprlist);
81  int indexcol);
82 extern bool match_index_to_operand(Node *operand, int indexcol,
84 extern void check_index_predicates(PlannerInfo *root, RelOptInfo *rel);
86 /*
87  * tidpath.h
88  * routines to generate tid paths
89  */
90 extern void create_tidscan_paths(PlannerInfo *root, RelOptInfo *rel);
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);
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 extern void mark_dummy_rel(RelOptInfo *rel);
114 /*
115  * equivclass.c
116  * routines for managing EquivalenceClasses
117  */
119  RelOptInfo *rel,
120  EquivalenceClass *ec,
121  EquivalenceMember *em,
122  void *arg);
124 extern bool process_equivalence(PlannerInfo *root,
125  RestrictInfo **p_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);
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);
140  Expr *expr,
141  Relids relids);
143  EquivalenceClass *ec,
144  List *exprs,
145  Relids relids,
146  bool require_parallel_safe);
147 extern bool relation_can_be_sorted_early(PlannerInfo *root, RelOptInfo *rel,
148  EquivalenceClass *ec,
149  bool require_parallel_safe);
152  Relids join_relids,
153  Relids outer_relids,
154  RelOptInfo *inner_rel);
156  List *eclasses,
157  Relids join_relids,
158  Relids outer_relids,
159  RelOptInfo *inner_rel);
160 extern bool exprs_known_equal(PlannerInfo *root, Node *item1, Node *item2);
162  ForeignKeyOptInfo *fkinfo,
163  int colno);
165  EquivalenceMember *em);
166 extern void add_child_rel_equivalences(PlannerInfo *root,
167  AppendRelInfo *appinfo,
168  RelOptInfo *parent_rel,
169  RelOptInfo *child_rel);
171  int nappinfos,
172  AppendRelInfo **appinfos,
173  RelOptInfo *parent_rel,
174  RelOptInfo *child_rel);
176  RelOptInfo *rel,
178  void *callback_arg,
179  Relids prohibited_rels);
181  RelOptInfo *rel1, RelOptInfo *rel2);
183  RelOptInfo *rel1);
184 extern bool eclass_useful_for_merging(PlannerInfo *root,
186  RelOptInfo *rel);
187 extern bool is_redundant_derived_clause(RestrictInfo *rinfo, List *clauselist);
189  List *indexclauses);
191 /*
192  * pathkeys.c
193  * utilities for matching and building path keys
194  */
195 typedef enum
196 {
197  PATHKEYS_EQUAL, /* pathkeys are identical */
198  PATHKEYS_BETTER1, /* pathkey 1 is a superset of pathkey 2 */
199  PATHKEYS_BETTER2, /* vice versa */
200  PATHKEYS_DIFFERENT /* neither pathkey includes the other */
203 extern PathKeysComparison compare_pathkeys(List *keys1, List *keys2);
204 extern bool pathkeys_contained_in(List *keys1, List *keys2);
205 extern bool pathkeys_count_contained_in(List *keys1, List *keys2, int *n_common);
206 extern int group_keys_reorder_by_pathkeys(List *pathkeys,
207  List **group_pathkeys,
208  List **group_clauses);
209 extern List *get_useful_group_keys_orderings(PlannerInfo *root, double nrows,
210  List *path_pathkeys,
211  List *pathkeys, List *clauses);
212 extern Path *get_cheapest_path_for_pathkeys(List *paths, List *pathkeys,
213  Relids required_outer,
214  CostSelector cost_criterion,
215  bool require_parallel_safe);
217  List *pathkeys,
218  Relids required_outer,
219  double fraction);
222  ScanDirection scandir);
223 extern List *build_partition_pathkeys(PlannerInfo *root, RelOptInfo *partrel,
224  ScanDirection scandir, bool *partialkeys);
225 extern List *build_expression_pathkey(PlannerInfo *root, Expr *expr,
226  Relids nullable_relids, Oid opno,
227  Relids rel, bool create_it);
229  List *subquery_pathkeys,
230  List *subquery_tlist);
231 extern List *build_join_pathkeys(PlannerInfo *root,
232  RelOptInfo *joinrel,
233  JoinType jointype,
234  List *outer_pathkeys);
236  List *sortclauses,
237  List *tlist);
239  RestrictInfo *restrictinfo);
240 extern void update_mergeclause_eclasses(PlannerInfo *root,
241  RestrictInfo *restrictinfo);
243  List *pathkeys,
244  List *restrictinfos);
246  List *mergeclauses,
247  RelOptInfo *joinrel);
249  List *mergeclauses,
250  List *outer_pathkeys);
252  List *mergeclauses,
253  List *pathkeys);
255  RelOptInfo *rel,
256  List *pathkeys);
257 extern bool has_useful_pathkeys(PlannerInfo *root, RelOptInfo *rel);
259  EquivalenceClass *eclass, Oid opfamily,
260  int strategy, bool nulls_first);
261 extern void add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
262  List *live_childrels);
264 #endif /* PATHS_H */
Definition: c.h:1331
unsigned char bool
Definition: c.h:391
unsigned int Index
Definition: c.h:549
Definition: nodes.h:744
Definition: pathnodes.h:35
bool exprs_known_equal(PlannerInfo *root, Node *item1, Node *item2)
Definition: equivclass.c:2368
List * build_join_pathkeys(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, List *outer_pathkeys)
Definition: pathkeys.c:1605
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:621
EquivalenceMember * find_ec_member_matching_expr(EquivalenceClass *ec, Expr *expr, Relids relids)
Definition: equivclass.c:797
void add_child_rel_equivalences(PlannerInfo *root, AppendRelInfo *appinfo, RelOptInfo *parent_rel, RelOptInfo *child_rel)
Definition: equivclass.c:2550
bool is_redundant_with_indexclauses(RestrictInfo *rinfo, List *indexclauses)
Definition: equivclass.c:3158
void generate_base_implied_equalities(PlannerInfo *root)
Definition: equivclass.c:1070
PGDLLIMPORT int geqo_threshold
Definition: allpaths.c:64
void generate_partitionwise_join_paths(PlannerInfo *root, RelOptInfo *rel)
Definition: allpaths.c:4182
RelOptInfo * standard_join_search(PlannerInfo *root, int levels_needed, List *initial_rels)
Definition: allpaths.c:3330
void join_search_one_level(PlannerInfo *root, int level)
Definition: joinrels.c:71
RestrictInfo * find_derived_clause_for_ec_member(EquivalenceClass *ec, EquivalenceMember *em)
Definition: equivclass.c:2510
List * make_inner_pathkeys_for_merge(PlannerInfo *root, List *mergeclauses, List *outer_pathkeys)
Definition: pathkeys.c:2070
PGDLLIMPORT set_rel_pathlist_hook_type set_rel_pathlist_hook
Definition: allpaths.c:69
Path * get_cheapest_path_for_pathkeys(List *paths, List *pathkeys, Relids required_outer, CostSelector cost_criterion, bool require_parallel_safe)
Definition: pathkeys.c:927
bool pathkeys_count_contained_in(List *keys1, List *keys2, int *n_common)
Definition: pathkeys.c:866
Expr * canonicalize_ec_expression(Expr *expr, Oid req_type, Oid req_collation)
Definition: equivclass.c:500
bool relation_can_be_sorted_early(PlannerInfo *root, RelOptInfo *rel, EquivalenceClass *ec, bool require_parallel_safe)
Definition: equivclass.c:959
List * find_mergeclauses_for_outer_pathkeys(PlannerInfo *root, List *pathkeys, List *restrictinfos)
Definition: pathkeys.c:1785
void add_paths_to_joinrel(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: joinpath.c:123
List * get_useful_group_keys_orderings(PlannerInfo *root, double nrows, List *path_pathkeys, List *pathkeys, List *clauses)
Definition: pathkeys.c:745
PGDLLIMPORT bool enable_group_by_reordering
Definition: pathkeys.c:35
bool has_useful_pathkeys(PlannerInfo *root, RelOptInfo *rel)
Definition: pathkeys.c:2484
void(* set_join_pathlist_hook_type)(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, JoinPathExtraData *extra)
Definition: paths.h:37
void check_index_predicates(PlannerInfo *root, RelOptInfo *rel)
Definition: indxpath.c:3307
List * truncate_useless_pathkeys(PlannerInfo *root, RelOptInfo *rel, List *pathkeys)
Definition: pathkeys.c:2441
void add_child_join_rel_equivalences(PlannerInfo *root, int nappinfos, AppendRelInfo **appinfos, RelOptInfo *parent_rel, RelOptInfo *child_rel)
Definition: equivclass.c:2678
RelOptInfo *(* join_search_hook_type)(PlannerInfo *root, int levels_needed, List *initial_rels)
Definition: paths.h:46
int compute_parallel_worker(RelOptInfo *rel, double heap_pages, double index_pages, int max_workers)
Definition: allpaths.c:4094
void generate_gather_paths(PlannerInfo *root, RelOptInfo *rel, bool override_rows)
Definition: allpaths.c:2953
List * generate_join_implied_equalities_for_ecs(PlannerInfo *root, List *eclasses, Relids join_relids, Relids outer_relids, RelOptInfo *inner_rel)
Definition: equivclass.c:1481
List * build_expression_pathkey(PlannerInfo *root, Expr *expr, Relids nullable_relids, Oid opno, Relids rel, bool create_it)
Definition: pathkeys.c:1305
List * trim_mergeclauses_for_inner_pathkeys(PlannerInfo *root, List *mergeclauses, List *pathkeys)
Definition: pathkeys.c:2173
void(* set_rel_pathlist_hook_type)(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
Definition: paths.h:30
List * select_outer_pathkeys_for_merge(PlannerInfo *root, List *mergeclauses, RelOptInfo *joinrel)
Definition: pathkeys.c:1898
void update_mergeclause_eclasses(PlannerInfo *root, RestrictInfo *restrictinfo)
Definition: pathkeys.c:1751
bool relation_has_unique_index_for(PlannerInfo *root, RelOptInfo *rel, List *restrictlist, List *exprlist, List *oprlist)
Definition: indxpath.c:3498
PGDLLIMPORT int min_parallel_table_scan_size
Definition: allpaths.c:65
List * build_index_pathkeys(PlannerInfo *root, IndexOptInfo *index, ScanDirection scandir)
Definition: pathkeys.c:1046
bool have_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
Definition: equivclass.c:2962
void create_index_paths(PlannerInfo *root, RelOptInfo *rel)
Definition: indxpath.c:235
RelOptInfo * make_join_rel(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
Definition: joinrels.c:686
List * generate_implied_equalities_for_column(PlannerInfo *root, RelOptInfo *rel, ec_matches_callback_type callback, void *callback_arg, Relids prohibited_rels)
Definition: equivclass.c:2832
PathKey * make_canonical_pathkey(PlannerInfo *root, EquivalenceClass *eclass, Oid opfamily, int strategy, bool nulls_first)
Definition: pathkeys.c:59
void generate_useful_gather_paths(PlannerInfo *root, RelOptInfo *rel, bool override_rows)
Definition: allpaths.c:3091
int group_keys_reorder_by_pathkeys(List *pathkeys, List **group_pathkeys, List **group_clauses)
Definition: pathkeys.c:352
void mark_dummy_rel(RelOptInfo *rel)
Definition: joinrels.c:1261
bool have_dangerous_phv(PlannerInfo *root, Relids outer_relids, Relids inner_params)
Definition: joinrels.c:1184
Path * get_cheapest_parallel_safe_total_inner(List *paths)
Definition: pathkeys.c:1005
void reconsider_outer_join_clauses(PlannerInfo *root)
Definition: equivclass.c:1966
bool have_join_order_restriction(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
Definition: joinrels.c:951
bool eclass_useful_for_merging(PlannerInfo *root, EquivalenceClass *eclass, RelOptInfo *rel)
Definition: equivclass.c:3073
List * make_pathkeys_for_sortclauses(PlannerInfo *root, List *sortclauses, List *tlist)
Definition: pathkeys.c:1648
List * generate_join_implied_equalities(PlannerInfo *root, Relids join_relids, Relids outer_relids, RelOptInfo *inner_rel)
Definition: equivclass.c:1403
PGDLLIMPORT int min_parallel_index_scan_size
Definition: allpaths.c:66
List * convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel, List *subquery_pathkeys, List *subquery_tlist)
Definition: pathkeys.c:1361
EquivalenceClass * match_eclasses_to_foreign_key_col(PlannerInfo *root, ForeignKeyOptInfo *fkinfo, int colno)
Definition: equivclass.c:2419
void initialize_mergeclause_eclasses(PlannerInfo *root, RestrictInfo *restrictinfo)
Definition: pathkeys.c:1702
bool match_index_to_operand(Node *operand, int indexcol, IndexOptInfo *index)
Definition: indxpath.c:3720
Path * get_cheapest_fractional_path_for_pathkeys(List *paths, List *pathkeys, Relids required_outer, double fraction)
Definition: pathkeys.c:972
bool is_redundant_derived_clause(RestrictInfo *rinfo, List *clauselist)
Definition: equivclass.c:3131
bool process_equivalence(PlannerInfo *root, RestrictInfo **p_restrictinfo, bool below_outer_join)
Definition: equivclass.c:119
void create_partial_bitmap_paths(PlannerInfo *root, RelOptInfo *rel, Path *bitmapqual)
Definition: allpaths.c:4058
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:329
void create_tidscan_paths(PlannerInfo *root, RelOptInfo *rel)
Definition: tidpath.c:459
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:290
PGDLLIMPORT join_search_hook_type join_search_hook
Definition: allpaths.c:72
void add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel, List *live_childrels)
Definition: allpaths.c:1286
Definition: paths.h:196
Definition: paths.h:199
Definition: paths.h:198
Definition: paths.h:200
Definition: paths.h:197
bool indexcol_is_bool_constant_for_query(PlannerInfo *root, IndexOptInfo *index, int indexcol)
Definition: indxpath.c:3669
EquivalenceMember * find_computable_ec_member(PlannerInfo *root, EquivalenceClass *ec, List *exprs, Relids relids, bool require_parallel_safe)
Definition: equivclass.c:862
RelOptInfo * make_one_rel(PlannerInfo *root, List *joinlist)
Definition: allpaths.c:154
List * build_partition_pathkeys(PlannerInfo *root, RelOptInfo *partrel, ScanDirection scandir, bool *partialkeys)
Definition: pathkeys.c:1222
bool has_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1)
Definition: equivclass.c:3029
PGDLLIMPORT bool enable_geqo
Definition: allpaths.c:63
bool(* ec_matches_callback_type)(PlannerInfo *root, RelOptInfo *rel, EquivalenceClass *ec, EquivalenceMember *em, void *arg)
Definition: paths.h:118
PGDLLIMPORT set_join_pathlist_hook_type set_join_pathlist_hook
Definition: joinpath.c:30
void * arg
unsigned int Oid
Definition: postgres_ext.h:31
static struct cvec * eclass(struct vars *v, chr c, int cases)
Definition: regc_locale.c:504
Definition: sdir.h:23
Definition: pg_list.h:51
Definition: nodes.h:574
Definition: type.h:90
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:48