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-2023, 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;
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);
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);
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);
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);
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);
67 extern void debug_print_rel(PlannerInfo *root, RelOptInfo *rel);
68 #endif
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);
80  int indexcol);
81 extern bool match_index_to_operand(Node *operand, int indexcol,
83 extern void check_index_predicates(PlannerInfo *root, RelOptInfo *rel);
85 /*
86  * tidpath.h
87  * routines to generate tid paths
88  */
89 extern void create_tidscan_paths(PlannerInfo *root, RelOptInfo *rel);
91 /*
92  * joinpath.c
93  * routines to create join paths
94  */
95 extern void add_paths_to_joinrel(PlannerInfo *root, RelOptInfo *joinrel,
96  RelOptInfo *outerrel, RelOptInfo *innerrel,
97  JoinType jointype, SpecialJoinInfo *sjinfo,
98  List *restrictlist);
100 /*
101  * joinrels.c
102  * routines to determine which relations to join
103  */
104 extern void join_search_one_level(PlannerInfo *root, int level);
105 extern RelOptInfo *make_join_rel(PlannerInfo *root,
106  RelOptInfo *rel1, RelOptInfo *rel2);
107 extern Relids add_outer_joins_to_relids(PlannerInfo *root, Relids input_relids,
108  SpecialJoinInfo *sjinfo,
109  List **pushed_down_joins);
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 extern void mark_dummy_rel(RelOptInfo *rel);
116 /*
117  * equivclass.c
118  * routines for managing EquivalenceClasses
119  */
121  RelOptInfo *rel,
122  EquivalenceClass *ec,
123  EquivalenceMember *em,
124  void *arg);
126 extern bool process_equivalence(PlannerInfo *root,
127  RestrictInfo **p_restrictinfo,
128  JoinDomain *jdomain);
129 extern Expr *canonicalize_ec_expression(Expr *expr,
130  Oid req_type, Oid req_collation);
131 extern void reconsider_outer_join_clauses(PlannerInfo *root);
133  Expr *expr,
134  List *opfamilies,
135  Oid opcintype,
136  Oid collation,
137  Index sortref,
138  Relids rel,
139  bool create_it);
141  Expr *expr,
142  Relids relids);
144  EquivalenceClass *ec,
145  List *exprs,
146  Relids relids,
147  bool require_parallel_safe);
148 extern bool relation_can_be_sorted_early(PlannerInfo *root, RelOptInfo *rel,
149  EquivalenceClass *ec,
150  bool require_parallel_safe);
153  Relids join_relids,
154  Relids outer_relids,
155  RelOptInfo *inner_rel,
156  SpecialJoinInfo *sjinfo);
158  List *eclasses,
159  Relids join_relids,
160  Relids outer_relids,
161  RelOptInfo *inner_rel);
162 extern bool exprs_known_equal(PlannerInfo *root, Node *item1, Node *item2);
164  ForeignKeyOptInfo *fkinfo,
165  int colno);
167  EquivalenceMember *em);
168 extern void add_child_rel_equivalences(PlannerInfo *root,
169  AppendRelInfo *appinfo,
170  RelOptInfo *parent_rel,
171  RelOptInfo *child_rel);
173  int nappinfos,
174  AppendRelInfo **appinfos,
175  RelOptInfo *parent_joinrel,
176  RelOptInfo *child_joinrel);
178  RelOptInfo *rel,
180  void *callback_arg,
181  Relids prohibited_rels);
183  RelOptInfo *rel1, RelOptInfo *rel2);
185  RelOptInfo *rel1);
186 extern bool eclass_useful_for_merging(PlannerInfo *root,
188  RelOptInfo *rel);
189 extern bool is_redundant_derived_clause(RestrictInfo *rinfo, List *clauselist);
191  List *indexclauses);
193 /*
194  * pathkeys.c
195  * utilities for matching and building path keys
196  */
197 typedef enum
198 {
199  PATHKEYS_EQUAL, /* pathkeys are identical */
200  PATHKEYS_BETTER1, /* pathkey 1 is a superset of pathkey 2 */
201  PATHKEYS_BETTER2, /* vice versa */
202  PATHKEYS_DIFFERENT /* neither pathkey includes the other */
205 extern PathKeysComparison compare_pathkeys(List *keys1, List *keys2);
206 extern bool pathkeys_contained_in(List *keys1, List *keys2);
207 extern bool pathkeys_count_contained_in(List *keys1, List *keys2, int *n_common);
208 extern Path *get_cheapest_path_for_pathkeys(List *paths, List *pathkeys,
209  Relids required_outer,
210  CostSelector cost_criterion,
211  bool require_parallel_safe);
213  List *pathkeys,
214  Relids required_outer,
215  double fraction);
218  ScanDirection scandir);
219 extern List *build_partition_pathkeys(PlannerInfo *root, RelOptInfo *partrel,
220  ScanDirection scandir, bool *partialkeys);
221 extern List *build_expression_pathkey(PlannerInfo *root, Expr *expr,
222  Oid opno,
223  Relids rel, bool create_it);
225  List *subquery_pathkeys,
226  List *subquery_tlist);
227 extern List *build_join_pathkeys(PlannerInfo *root,
228  RelOptInfo *joinrel,
229  JoinType jointype,
230  List *outer_pathkeys);
232  List *sortclauses,
233  List *tlist);
235  List **sortclauses,
236  List *tlist,
237  bool remove_redundant,
238  bool *sortable);
240  RestrictInfo *restrictinfo);
241 extern void update_mergeclause_eclasses(PlannerInfo *root,
242  RestrictInfo *restrictinfo);
244  List *pathkeys,
245  List *restrictinfos);
247  List *mergeclauses,
248  RelOptInfo *joinrel);
250  List *mergeclauses,
251  List *outer_pathkeys);
253  List *mergeclauses,
254  List *pathkeys);
256  RelOptInfo *rel,
257  List *pathkeys);
258 extern bool has_useful_pathkeys(PlannerInfo *root, RelOptInfo *rel);
259 extern List *append_pathkeys(List *target, List *source);
261  EquivalenceClass *eclass, Oid opfamily,
262  int strategy, bool nulls_first);
263 extern void add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
264  List *live_childrels);
266 #endif /* PATHS_H */
Definition: c.h:1321
unsigned char bool
Definition: c.h:440
unsigned int Index
Definition: c.h:598
Definition: nodes.h:299
Definition: pathnodes.h:37
bool exprs_known_equal(PlannerInfo *root, Node *item1, Node *item2)
Definition: equivclass.c:2439
List * build_join_pathkeys(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, List *outer_pathkeys)
Definition: pathkeys.c:1093
List * build_expression_pathkey(PlannerInfo *root, Expr *expr, Oid opno, Relids rel, bool create_it)
Definition: pathkeys.c:799
EquivalenceMember * find_ec_member_matching_expr(EquivalenceClass *ec, Expr *expr, Relids relids)
Definition: equivclass.c:760
void add_child_rel_equivalences(PlannerInfo *root, AppendRelInfo *appinfo, RelOptInfo *parent_rel, RelOptInfo *child_rel)
Definition: equivclass.c:2621
bool is_redundant_with_indexclauses(RestrictInfo *rinfo, List *indexclauses)
Definition: equivclass.c:3221
void generate_base_implied_equalities(PlannerInfo *root)
Definition: equivclass.c:1033
PGDLLIMPORT int geqo_threshold
Definition: allpaths.c:83
void generate_partitionwise_join_paths(PlannerInfo *root, RelOptInfo *rel)
Definition: allpaths.c:4298
RelOptInfo * standard_join_search(PlannerInfo *root, int levels_needed, List *initial_rels)
Definition: allpaths.c:3419
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:2581
List * make_inner_pathkeys_for_merge(PlannerInfo *root, List *mergeclauses, List *outer_pathkeys)
Definition: pathkeys.c:1622
PGDLLIMPORT set_rel_pathlist_hook_type set_rel_pathlist_hook
Definition: allpaths.c:88
Path * get_cheapest_path_for_pathkeys(List *paths, List *pathkeys, Relids required_outer, CostSelector cost_criterion, bool require_parallel_safe)
Definition: pathkeys.c:420
bool pathkeys_count_contained_in(List *keys1, List *keys2, int *n_common)
Definition: pathkeys.c:359
Expr * canonicalize_ec_expression(Expr *expr, Oid req_type, Oid req_collation)
Definition: equivclass.c:472
bool relation_can_be_sorted_early(PlannerInfo *root, RelOptInfo *rel, EquivalenceClass *ec, bool require_parallel_safe)
Definition: equivclass.c:922
List * find_mergeclauses_for_outer_pathkeys(PlannerInfo *root, List *pathkeys, List *restrictinfos)
Definition: pathkeys.c:1311
void add_paths_to_joinrel(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: joinpath.c:123
bool has_useful_pathkeys(PlannerInfo *root, RelOptInfo *rel)
Definition: pathkeys.c:1985
Relids add_outer_joins_to_relids(PlannerInfo *root, Relids input_relids, SpecialJoinInfo *sjinfo, List **pushed_down_joins)
Definition: joinrels.c:802
List * append_pathkeys(List *target, List *source)
Definition: pathkeys.c:105
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:3295
List * truncate_useless_pathkeys(PlannerInfo *root, RelOptInfo *rel, List *pathkeys)
Definition: pathkeys.c:1945
bool process_equivalence(PlannerInfo *root, RestrictInfo **p_restrictinfo, JoinDomain *jdomain)
Definition: equivclass.c:118
RelOptInfo *(* join_search_hook_type)(PlannerInfo *root, int levels_needed, List *initial_rels)
Definition: paths.h:45
int compute_parallel_worker(RelOptInfo *rel, double heap_pages, double index_pages, int max_workers)
Definition: allpaths.c:4210
void generate_gather_paths(PlannerInfo *root, RelOptInfo *rel, bool override_rows)
Definition: allpaths.c:3060
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 * trim_mergeclauses_for_inner_pathkeys(PlannerInfo *root, List *mergeclauses, List *pathkeys)
Definition: pathkeys.c:1725
void(* set_rel_pathlist_hook_type)(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
Definition: paths.h:29
List * select_outer_pathkeys_for_merge(PlannerInfo *root, List *mergeclauses, RelOptInfo *joinrel)
Definition: pathkeys.c:1426
void update_mergeclause_eclasses(PlannerInfo *root, RestrictInfo *restrictinfo)
Definition: pathkeys.c:1277
bool relation_has_unique_index_for(PlannerInfo *root, RelOptInfo *rel, List *restrictlist, List *exprlist, List *oprlist)
Definition: indxpath.c:3491
PGDLLIMPORT int min_parallel_table_scan_size
Definition: allpaths.c:84
List * build_index_pathkeys(PlannerInfo *root, IndexOptInfo *index, ScanDirection scandir)
Definition: pathkeys.c:539
EquivalenceClass * get_eclass_for_sort_expr(PlannerInfo *root, Expr *expr, List *opfamilies, Oid opcintype, Oid collation, Index sortref, Relids rel, bool create_it)
Definition: equivclass.c:587
List * generate_join_implied_equalities(PlannerInfo *root, Relids join_relids, Relids outer_relids, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo)
Definition: equivclass.c:1381
bool have_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
Definition: equivclass.c:3016
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:689
List * generate_implied_equalities_for_column(PlannerInfo *root, RelOptInfo *rel, ec_matches_callback_type callback, void *callback_arg, Relids prohibited_rels)
Definition: equivclass.c:2884
List * make_pathkeys_for_sortclauses_extended(PlannerInfo *root, List **sortclauses, List *tlist, bool remove_redundant, bool *sortable)
Definition: pathkeys.c:1168
PathKey * make_canonical_pathkey(PlannerInfo *root, EquivalenceClass *eclass, Oid opfamily, int strategy, bool nulls_first)
Definition: pathkeys.c:54
void generate_useful_gather_paths(PlannerInfo *root, RelOptInfo *rel, bool override_rows)
Definition: allpaths.c:3198
void mark_dummy_rel(RelOptInfo *rel)
Definition: joinrels.c:1382
bool have_dangerous_phv(PlannerInfo *root, Relids outer_relids, Relids inner_params)
Definition: joinrels.c:1305
Path * get_cheapest_parallel_safe_total_inner(List *paths)
Definition: pathkeys.c:498
void reconsider_outer_join_clauses(PlannerInfo *root)
Definition: equivclass.c:1982
bool have_join_order_restriction(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
Definition: joinrels.c:1072
bool eclass_useful_for_merging(PlannerInfo *root, EquivalenceClass *eclass, RelOptInfo *rel)
Definition: equivclass.c:3136
List * make_pathkeys_for_sortclauses(PlannerInfo *root, List *sortclauses, List *tlist)
Definition: pathkeys.c:1131
PGDLLIMPORT int min_parallel_index_scan_size
Definition: allpaths.c:85
void add_child_join_rel_equivalences(PlannerInfo *root, int nappinfos, AppendRelInfo **appinfos, RelOptInfo *parent_joinrel, RelOptInfo *child_joinrel)
Definition: equivclass.c:2743
List * convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel, List *subquery_pathkeys, List *subquery_tlist)
Definition: pathkeys.c:853
EquivalenceClass * match_eclasses_to_foreign_key_col(PlannerInfo *root, ForeignKeyOptInfo *fkinfo, int colno)
Definition: equivclass.c:2490
void initialize_mergeclause_eclasses(PlannerInfo *root, RestrictInfo *restrictinfo)
Definition: pathkeys.c:1230
bool match_index_to_operand(Node *operand, int indexcol, IndexOptInfo *index)
Definition: indxpath.c:3713
Path * get_cheapest_fractional_path_for_pathkeys(List *paths, List *pathkeys, Relids required_outer, double fraction)
Definition: pathkeys.c:465
bool is_redundant_derived_clause(RestrictInfo *rinfo, List *clauselist)
Definition: equivclass.c:3194
void create_partial_bitmap_paths(PlannerInfo *root, RelOptInfo *rel, Path *bitmapqual)
Definition: allpaths.c:4174
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:340
void create_tidscan_paths(PlannerInfo *root, RelOptInfo *rel)
Definition: tidpath.c:460
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:301
PGDLLIMPORT join_search_hook_type join_search_hook
Definition: allpaths.c:91
void add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel, List *live_childrels)
Definition: allpaths.c:1305
Definition: paths.h:198
Definition: paths.h:201
Definition: paths.h:200
Definition: paths.h:202
Definition: paths.h:199
bool indexcol_is_bool_constant_for_query(PlannerInfo *root, IndexOptInfo *index, int indexcol)
Definition: indxpath.c:3662
EquivalenceMember * find_computable_ec_member(PlannerInfo *root, EquivalenceClass *ec, List *exprs, Relids relids, bool require_parallel_safe)
Definition: equivclass.c:825
RelOptInfo * make_one_rel(PlannerInfo *root, List *joinlist)
Definition: allpaths.c:174
List * build_partition_pathkeys(PlannerInfo *root, RelOptInfo *partrel, ScanDirection scandir, bool *partialkeys)
Definition: pathkeys.c:718
bool has_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1)
Definition: equivclass.c:3092
PGDLLIMPORT bool enable_geqo
Definition: allpaths.c:82
bool(* ec_matches_callback_type)(PlannerInfo *root, RelOptInfo *rel, EquivalenceClass *ec, EquivalenceMember *em, void *arg)
Definition: paths.h:120
PGDLLIMPORT set_join_pathlist_hook_type set_join_pathlist_hook
Definition: joinpath.c:30
void * arg
static rewind_source * source
Definition: pg_rewind.c:87
unsigned int Oid
Definition: postgres_ext.h:31
static struct cvec * eclass(struct vars *v, chr c, int cases)
Definition: regc_locale.c:500
Definition: sdir.h:25
Definition: pg_list.h:54
Definition: nodes.h:129
Definition: type.h:95
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)
Definition: test_ifaddrs.c:46