PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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-2024, 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;
28 
29 /* Hook for plugins to get control in set_rel_pathlist() */
31  RelOptInfo *rel,
32  Index rti,
33  RangeTblEntry *rte);
35 
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);
44 
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);
50 
51 
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);
55 
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);
63  Path *bitmapqual);
65  RelOptInfo *rel);
66 
67 /*
68  * indxpath.c
69  * routines to generate index paths
70  */
71 extern void create_index_paths(PlannerInfo *root, RelOptInfo *rel);
73  List *restrictlist,
74  List *exprlist, List *oprlist);
77  int indexcol);
78 extern bool match_index_to_operand(Node *operand, int indexcol,
81 
82 /*
83  * tidpath.c
84  * routines to generate tid paths
85  */
87 
88 /*
89  * joinpath.c
90  * routines to create join paths
91  */
92 extern void add_paths_to_joinrel(PlannerInfo *root, RelOptInfo *joinrel,
93  RelOptInfo *outerrel, RelOptInfo *innerrel,
94  JoinType jointype, SpecialJoinInfo *sjinfo,
95  List *restrictlist);
96 
97 /*
98  * joinrels.c
99  * routines to determine which relations to join
100  */
101 extern void join_search_one_level(PlannerInfo *root, int level);
103  RelOptInfo *rel1, RelOptInfo *rel2);
105  SpecialJoinInfo *sjinfo,
106  List **pushed_down_joins);
108  RelOptInfo *rel1, RelOptInfo *rel2);
109 extern bool have_dangerous_phv(PlannerInfo *root,
110  Relids outer_relids, Relids inner_params);
111 extern void mark_dummy_rel(RelOptInfo *rel);
112 extern void init_dummy_sjinfo(SpecialJoinInfo *sjinfo, Relids left_relids,
113  Relids right_relids);
114 
115 /*
116  * equivclass.c
117  * routines for managing EquivalenceClasses
118  */
120  RelOptInfo *rel,
121  EquivalenceClass *ec,
122  EquivalenceMember *em,
123  void *arg);
124 
126  RestrictInfo **p_restrictinfo,
127  JoinDomain *jdomain);
128 extern Expr *canonicalize_ec_expression(Expr *expr,
129  Oid req_type, Oid req_collation);
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);
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,
163  Oid opfamily);
165  ForeignKeyOptInfo *fkinfo,
166  int colno);
168  EquivalenceMember *em);
170  AppendRelInfo *appinfo,
171  RelOptInfo *parent_rel,
172  RelOptInfo *child_rel);
174  int nappinfos,
175  AppendRelInfo **appinfos,
176  RelOptInfo *parent_joinrel,
177  RelOptInfo *child_joinrel);
179  RelOptInfo *child_rel,
180  List *child_tlist,
181  List *setop_pathkeys);
183  RelOptInfo *rel,
185  void *callback_arg,
186  Relids prohibited_rels);
188  RelOptInfo *rel1, RelOptInfo *rel2);
190  RelOptInfo *rel1);
193  RelOptInfo *rel);
194 extern bool is_redundant_derived_clause(RestrictInfo *rinfo, List *clauselist);
196  List *indexclauses);
197 
198 /*
199  * pathkeys.c
200  * utilities for matching and building path keys
201  */
202 typedef enum
203 {
204  PATHKEYS_EQUAL, /* pathkeys are identical */
205  PATHKEYS_BETTER1, /* pathkey 1 is a superset of pathkey 2 */
206  PATHKEYS_BETTER2, /* vice versa */
207  PATHKEYS_DIFFERENT, /* neither pathkey includes the other */
209 
210 extern PathKeysComparison compare_pathkeys(List *keys1, List *keys2);
211 extern bool pathkeys_contained_in(List *keys1, List *keys2);
212 extern bool pathkeys_count_contained_in(List *keys1, List *keys2, int *n_common);
214 extern Path *get_cheapest_path_for_pathkeys(List *paths, List *pathkeys,
215  Relids required_outer,
216  CostSelector cost_criterion,
217  bool require_parallel_safe);
219  List *pathkeys,
220  Relids required_outer,
221  double fraction);
224  ScanDirection scandir);
226  ScanDirection scandir, bool *partialkeys);
228  Oid opno,
229  Relids rel, bool create_it);
231  List *subquery_pathkeys,
232  List *subquery_tlist);
234  RelOptInfo *joinrel,
235  JoinType jointype,
236  List *outer_pathkeys);
238  List *sortclauses,
239  List *tlist);
241  List **sortclauses,
242  List *tlist,
243  bool remove_redundant,
244  bool remove_group_rtindex,
245  bool *sortable,
246  bool set_ec_sortref);
248  RestrictInfo *restrictinfo);
250  RestrictInfo *restrictinfo);
252  List *pathkeys,
253  List *restrictinfos);
255  List *mergeclauses,
256  RelOptInfo *joinrel);
258  List *mergeclauses,
259  List *outer_pathkeys);
261  List *mergeclauses,
262  List *pathkeys);
264  RelOptInfo *rel,
265  List *pathkeys);
266 extern bool has_useful_pathkeys(PlannerInfo *root, RelOptInfo *rel);
267 extern List *append_pathkeys(List *target, List *source);
269  EquivalenceClass *eclass, Oid opfamily,
270  int strategy, bool nulls_first);
272  List *live_childrels);
273 
274 #endif /* PATHS_H */
#define PGDLLIMPORT
Definition: c.h:1321
unsigned char bool
Definition: c.h:471
unsigned int Index
Definition: c.h:619
JoinType
Definition: nodes.h:288
CostSelector
Definition: pathnodes.h:37
List * build_join_pathkeys(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, List *outer_pathkeys)
Definition: pathkeys.c:1294
void rebuild_eclass_attr_needed(PlannerInfo *root)
Definition: equivclass.c:2431
List * get_useful_group_keys_orderings(PlannerInfo *root, Path *path)
Definition: pathkeys.c:467
List * build_expression_pathkey(PlannerInfo *root, Expr *expr, Oid opno, Relids rel, bool create_it)
Definition: pathkeys.c:1000
EquivalenceMember * find_ec_member_matching_expr(EquivalenceClass *ec, Expr *expr, Relids relids)
Definition: equivclass.c:763
void add_child_rel_equivalences(PlannerInfo *root, AppendRelInfo *appinfo, RelOptInfo *parent_rel, RelOptInfo *child_rel)
Definition: equivclass.c:2690
bool is_redundant_with_indexclauses(RestrictInfo *rinfo, List *indexclauses)
Definition: equivclass.c:3351
void generate_base_implied_equalities(PlannerInfo *root)
Definition: equivclass.c:1032
bool exprs_known_equal(PlannerInfo *root, Node *item1, Node *item2, Oid opfamily)
Definition: equivclass.c:2498
PGDLLIMPORT int geqo_threshold
Definition: allpaths.c:80
void generate_partitionwise_join_paths(PlannerInfo *root, RelOptInfo *rel)
Definition: allpaths.c:4302
RelOptInfo * standard_join_search(PlannerInfo *root, int levels_needed, List *initial_rels)
Definition: allpaths.c:3422
void join_search_one_level(PlannerInfo *root, int level)
Definition: joinrels.c:72
RestrictInfo * find_derived_clause_for_ec_member(EquivalenceClass *ec, EquivalenceMember *em)
Definition: equivclass.c:2650
List * make_inner_pathkeys_for_merge(PlannerInfo *root, List *mergeclauses, List *outer_pathkeys)
Definition: pathkeys.c:1854
PGDLLIMPORT set_rel_pathlist_hook_type set_rel_pathlist_hook
Definition: allpaths.c:85
Path * get_cheapest_path_for_pathkeys(List *paths, List *pathkeys, Relids required_outer, CostSelector cost_criterion, bool require_parallel_safe)
Definition: pathkeys.c:620
bool pathkeys_count_contained_in(List *keys1, List *keys2, int *n_common)
Definition: pathkeys.c:558
List * make_pathkeys_for_sortclauses_extended(PlannerInfo *root, List **sortclauses, List *tlist, bool remove_redundant, bool remove_group_rtindex, bool *sortable, bool set_ec_sortref)
Definition: pathkeys.c:1380
Expr * canonicalize_ec_expression(Expr *expr, Oid req_type, Oid req_collation)
Definition: equivclass.c:471
bool relation_can_be_sorted_early(PlannerInfo *root, RelOptInfo *rel, EquivalenceClass *ec, bool require_parallel_safe)
Definition: equivclass.c:921
List * find_mergeclauses_for_outer_pathkeys(PlannerInfo *root, List *pathkeys, List *restrictinfos)
Definition: pathkeys.c:1543
void add_paths_to_joinrel(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, JoinType jointype, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: joinpath.c:124
PGDLLIMPORT bool enable_group_by_reordering
Definition: pathkeys.c:32
bool has_useful_pathkeys(PlannerInfo *root, RelOptInfo *rel)
Definition: pathkeys.c:2277
Relids add_outer_joins_to_relids(PlannerInfo *root, Relids input_relids, SpecialJoinInfo *sjinfo, List **pushed_down_joins)
Definition: joinrels.c:801
List * append_pathkeys(List *target, List *source)
Definition: pathkeys.c:107
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:3946
List * truncate_useless_pathkeys(PlannerInfo *root, RelOptInfo *rel, List *pathkeys)
Definition: pathkeys.c:2231
bool process_equivalence(PlannerInfo *root, RestrictInfo **p_restrictinfo, JoinDomain *jdomain)
Definition: equivclass.c:117
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:4214
void generate_gather_paths(PlannerInfo *root, RelOptInfo *rel, bool override_rows)
Definition: allpaths.c:3064
List * generate_join_implied_equalities_for_ecs(PlannerInfo *root, List *eclasses, Relids join_relids, Relids outer_relids, RelOptInfo *inner_rel)
Definition: equivclass.c:1485
List * trim_mergeclauses_for_inner_pathkeys(PlannerInfo *root, List *mergeclauses, List *pathkeys)
Definition: pathkeys.c:1957
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:1658
void update_mergeclause_eclasses(PlannerInfo *root, RestrictInfo *restrictinfo)
Definition: pathkeys.c:1509
bool relation_has_unique_index_for(PlannerInfo *root, RelOptInfo *rel, List *restrictlist, List *exprlist, List *oprlist)
Definition: indxpath.c:4142
PGDLLIMPORT int min_parallel_table_scan_size
Definition: allpaths.c:81
List * build_index_pathkeys(PlannerInfo *root, IndexOptInfo *index, ScanDirection scandir)
Definition: pathkeys.c:740
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:586
List * generate_join_implied_equalities(PlannerInfo *root, Relids join_relids, Relids outer_relids, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo)
Definition: equivclass.c:1385
bool have_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
Definition: equivclass.c:3146
void create_index_paths(PlannerInfo *root, RelOptInfo *rel)
Definition: indxpath.c:241
RelOptInfo * make_join_rel(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
Definition: joinrels.c:704
List * generate_implied_equalities_for_column(PlannerInfo *root, RelOptInfo *rel, ec_matches_callback_type callback, void *callback_arg, Relids prohibited_rels)
Definition: equivclass.c:3014
PathKey * make_canonical_pathkey(PlannerInfo *root, EquivalenceClass *eclass, Oid opfamily, int strategy, bool nulls_first)
Definition: pathkeys.c:56
void generate_useful_gather_paths(PlannerInfo *root, RelOptInfo *rel, bool override_rows)
Definition: allpaths.c:3201
void mark_dummy_rel(RelOptInfo *rel)
Definition: joinrels.c:1384
bool have_dangerous_phv(PlannerInfo *root, Relids outer_relids, Relids inner_params)
Definition: joinrels.c:1307
void add_setop_child_rel_equivalences(PlannerInfo *root, RelOptInfo *child_rel, List *child_tlist, List *setop_pathkeys)
Definition: equivclass.c:2942
Path * get_cheapest_parallel_safe_total_inner(List *paths)
Definition: pathkeys.c:699
void reconsider_outer_join_clauses(PlannerInfo *root)
Definition: equivclass.c:2001
bool have_join_order_restriction(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
Definition: joinrels.c:1074
bool eclass_useful_for_merging(PlannerInfo *root, EquivalenceClass *eclass, RelOptInfo *rel)
Definition: equivclass.c:3266
List * make_pathkeys_for_sortclauses(PlannerInfo *root, List *sortclauses, List *tlist)
Definition: pathkeys.c:1335
PGDLLIMPORT int min_parallel_index_scan_size
Definition: allpaths.c:82
void add_child_join_rel_equivalences(PlannerInfo *root, int nappinfos, AppendRelInfo **appinfos, RelOptInfo *parent_joinrel, RelOptInfo *child_joinrel)
Definition: equivclass.c:2812
List * convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel, List *subquery_pathkeys, List *subquery_tlist)
Definition: pathkeys.c:1054
EquivalenceClass * match_eclasses_to_foreign_key_col(PlannerInfo *root, ForeignKeyOptInfo *fkinfo, int colno)
Definition: equivclass.c:2559
void initialize_mergeclause_eclasses(PlannerInfo *root, RestrictInfo *restrictinfo)
Definition: pathkeys.c:1462
bool create_tidscan_paths(PlannerInfo *root, RelOptInfo *rel)
Definition: tidpath.c:498
bool match_index_to_operand(Node *operand, int indexcol, IndexOptInfo *index)
Definition: indxpath.c:4367
void init_dummy_sjinfo(SpecialJoinInfo *sjinfo, Relids left_relids, Relids right_relids)
Definition: joinrels.c:669
Path * get_cheapest_fractional_path_for_pathkeys(List *paths, List *pathkeys, Relids required_outer, double fraction)
Definition: pathkeys.c:666
bool is_redundant_derived_clause(RestrictInfo *rinfo, List *clauselist)
Definition: equivclass.c:3324
void create_partial_bitmap_paths(PlannerInfo *root, RelOptInfo *rel, Path *bitmapqual)
Definition: allpaths.c:4178
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:343
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:304
PGDLLIMPORT join_search_hook_type join_search_hook
Definition: allpaths.c:88
void add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel, List *live_childrels)
Definition: allpaths.c:1314
PathKeysComparison
Definition: paths.h:203
@ PATHKEYS_BETTER2
Definition: paths.h:206
@ PATHKEYS_BETTER1
Definition: paths.h:205
@ PATHKEYS_DIFFERENT
Definition: paths.h:207
@ PATHKEYS_EQUAL
Definition: paths.h:204
bool indexcol_is_bool_constant_for_query(PlannerInfo *root, IndexOptInfo *index, int indexcol)
Definition: indxpath.c:4316
EquivalenceMember * find_computable_ec_member(PlannerInfo *root, EquivalenceClass *ec, List *exprs, Relids relids, bool require_parallel_safe)
Definition: equivclass.c:837
RelOptInfo * make_one_rel(PlannerInfo *root, List *joinlist)
Definition: allpaths.c:171
List * build_partition_pathkeys(PlannerInfo *root, RelOptInfo *partrel, ScanDirection scandir, bool *partialkeys)
Definition: pathkeys.c:919
bool has_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1)
Definition: equivclass.c:3222
PGDLLIMPORT bool enable_geqo
Definition: allpaths.c:79
bool(* ec_matches_callback_type)(PlannerInfo *root, RelOptInfo *rel, EquivalenceClass *ec, EquivalenceMember *em, void *arg)
Definition: paths.h:119
PGDLLIMPORT set_join_pathlist_hook_type set_join_pathlist_hook
Definition: joinpath.c:33
void * arg
static rewind_source * source
Definition: pg_rewind.c:89
unsigned int Oid
Definition: postgres_ext.h:31
tree ctl root
Definition: radixtree.h:1886
static struct cvec * eclass(struct vars *v, chr c, int cases)
Definition: regc_locale.c:500
ScanDirection
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