1 /*------------------------------------------------------------------------- 2 * 3 * paths.h 4 * prototypes for various files in optimizer/path 5 * 6 * 7 * Portions Copyright (c) 1996-2018, 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 PGDLLIMPORT bool enable_geqo; 24 extern PGDLLIMPORT int geqo_threshold; 25 extern PGDLLIMPORT int min_parallel_table_scan_size; 26 extern PGDLLIMPORT int min_parallel_index_scan_size; 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); 33 extern PGDLLIMPORT set_rel_pathlist_hook_type set_rel_pathlist_hook; 34 35 /* Hook for plugins to get control in add_paths_to_joinrel() */ 36 typedef void (*set_join_pathlist_hook_type) (PlannerInfo *root, 37 RelOptInfo *joinrel, 38 RelOptInfo *outerrel, 39 RelOptInfo *innerrel, 40 JoinType jointype, 41 JoinPathExtraData *extra); 42 extern PGDLLIMPORT set_join_pathlist_hook_type set_join_pathlist_hook; 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); 48 extern PGDLLIMPORT join_search_hook_type join_search_hook; 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 bool override_rows); 58 extern int compute_parallel_worker(RelOptInfo *rel, double heap_pages, 59 double index_pages, int max_workers); 60 extern void create_partial_bitmap_paths(PlannerInfo *root, RelOptInfo *rel, 61 Path *bitmapqual); 62 extern void generate_partitionwise_join_paths(PlannerInfo *root, 63 RelOptInfo *rel); 64 65 #ifdef OPTIMIZER_DEBUG 66 extern void debug_print_rel(PlannerInfo *root, RelOptInfo *rel); 67 #endif 68 69 /* 70 * indxpath.c 71 * routines to generate index paths 72 */ 73 extern void create_index_paths(PlannerInfo *root, RelOptInfo *rel); 74 extern bool relation_has_unique_index_for(PlannerInfo *root, RelOptInfo *rel, 75 List *restrictlist, 76 List *exprlist, List *oprlist); 77 extern bool indexcol_is_bool_constant_for_query(IndexOptInfo *index, 78 int indexcol); 79 extern bool match_index_to_operand(Node *operand, int indexcol, 80 IndexOptInfo *index); 81 extern void expand_indexqual_conditions(IndexOptInfo *index, 82 List *indexclauses, List *indexclausecols, 83 List **indexquals_p, List **indexqualcols_p); 84 extern void check_index_predicates(PlannerInfo *root, RelOptInfo *rel); 85 extern Expr *adjust_rowcompare_for_index(RowCompareExpr *clause, 86 IndexOptInfo *index, 87 int indexcol, 88 List **indexcolnos, 89 bool *var_on_left_p); 90 91 /* 92 * tidpath.h 93 * routines to generate tid paths 94 */ 95 extern void create_tidscan_paths(PlannerInfo *root, RelOptInfo *rel); 96 97 /* 98 * joinpath.c 99 * routines to create join paths 100 */ 101 extern void add_paths_to_joinrel(PlannerInfo *root, RelOptInfo *joinrel, 102 RelOptInfo *outerrel, RelOptInfo *innerrel, 103 JoinType jointype, SpecialJoinInfo *sjinfo, 104 List *restrictlist); 105 106 /* 107 * joinrels.c 108 * routines to determine which relations to join 109 */ 110 extern void join_search_one_level(PlannerInfo *root, int level); 111 extern RelOptInfo *make_join_rel(PlannerInfo *root, 112 RelOptInfo *rel1, RelOptInfo *rel2); 113 extern bool have_join_order_restriction(PlannerInfo *root, 114 RelOptInfo *rel1, RelOptInfo *rel2); 115 extern bool have_dangerous_phv(PlannerInfo *root, 116 Relids outer_relids, Relids inner_params); 117 extern void mark_dummy_rel(RelOptInfo *rel); 118 extern bool have_partkey_equi_join(RelOptInfo *joinrel, 119 RelOptInfo *rel1, RelOptInfo *rel2, 120 JoinType jointype, List *restrictlist); 121 122 /* 123 * equivclass.c 124 * routines for managing EquivalenceClasses 125 */ 126 typedef bool (*ec_matches_callback_type) (PlannerInfo *root, 127 RelOptInfo *rel, 128 EquivalenceClass *ec, 129 EquivalenceMember *em, 130 void *arg); 131 132 extern bool process_equivalence(PlannerInfo *root, 133 RestrictInfo **p_restrictinfo, 134 bool below_outer_join); 135 extern Expr *canonicalize_ec_expression(Expr *expr, 136 Oid req_type, Oid req_collation); 137 extern void reconsider_outer_join_clauses(PlannerInfo *root); 138 extern EquivalenceClass *get_eclass_for_sort_expr(PlannerInfo *root, 139 Expr *expr, 140 Relids nullable_relids, 141 List *opfamilies, 142 Oid opcintype, 143 Oid collation, 144 Index sortref, 145 Relids rel, 146 bool create_it); 147 extern void generate_base_implied_equalities(PlannerInfo *root); 148 extern List *generate_join_implied_equalities(PlannerInfo *root, 149 Relids join_relids, 150 Relids outer_relids, 151 RelOptInfo *inner_rel); 152 extern List *generate_join_implied_equalities_for_ecs(PlannerInfo *root, 153 List *eclasses, 154 Relids join_relids, 155 Relids outer_relids, 156 RelOptInfo *inner_rel); 157 extern bool exprs_known_equal(PlannerInfo *root, Node *item1, Node *item2); 158 extern EquivalenceClass *match_eclasses_to_foreign_key_col(PlannerInfo *root, 159 ForeignKeyOptInfo *fkinfo, 160 int colno); 161 extern void add_child_rel_equivalences(PlannerInfo *root, 162 AppendRelInfo *appinfo, 163 RelOptInfo *parent_rel, 164 RelOptInfo *child_rel); 165 extern List *generate_implied_equalities_for_column(PlannerInfo *root, 166 RelOptInfo *rel, 167 ec_matches_callback_type callback, 168 void *callback_arg, 169 Relids prohibited_rels); 170 extern bool have_relevant_eclass_joinclause(PlannerInfo *root, 171 RelOptInfo *rel1, RelOptInfo *rel2); 172 extern bool has_relevant_eclass_joinclause(PlannerInfo *root, 173 RelOptInfo *rel1); 174 extern bool eclass_useful_for_merging(PlannerInfo *root, 175 EquivalenceClass *eclass, 176 RelOptInfo *rel); 177 extern bool is_redundant_derived_clause(RestrictInfo *rinfo, List *clauselist); 178 179 /* 180 * pathkeys.c 181 * utilities for matching and building path keys 182 */ 183 typedef enum 184 { 185 PATHKEYS_EQUAL, /* pathkeys are identical */ 186 PATHKEYS_BETTER1, /* pathkey 1 is a superset of pathkey 2 */ 187 PATHKEYS_BETTER2, /* vice versa */ 188 PATHKEYS_DIFFERENT /* neither pathkey includes the other */ 189 } PathKeysComparison; 190 191 extern PathKeysComparison compare_pathkeys(List *keys1, List *keys2); 192 extern bool pathkeys_contained_in(List *keys1, List *keys2); 193 extern Path *get_cheapest_path_for_pathkeys(List *paths, List *pathkeys, 194 Relids required_outer, 195 CostSelector cost_criterion, 196 bool require_parallel_safe); 197 extern Path *get_cheapest_fractional_path_for_pathkeys(List *paths, 198 List *pathkeys, 199 Relids required_outer, 200 double fraction); 201 extern Path *get_cheapest_parallel_safe_total_inner(List *paths); 202 extern List *build_index_pathkeys(PlannerInfo *root, IndexOptInfo *index, 203 ScanDirection scandir); 204 extern List *build_expression_pathkey(PlannerInfo *root, Expr *expr, 205 Relids nullable_relids, Oid opno, 206 Relids rel, bool create_it); 207 extern List *convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel, 208 List *subquery_pathkeys, 209 List *subquery_tlist); 210 extern List *build_join_pathkeys(PlannerInfo *root, 211 RelOptInfo *joinrel, 212 JoinType jointype, 213 List *outer_pathkeys); 214 extern List *make_pathkeys_for_sortclauses(PlannerInfo *root, 215 List *sortclauses, 216 List *tlist); 217 extern void initialize_mergeclause_eclasses(PlannerInfo *root, 218 RestrictInfo *restrictinfo); 219 extern void update_mergeclause_eclasses(PlannerInfo *root, 220 RestrictInfo *restrictinfo); 221 extern List *find_mergeclauses_for_outer_pathkeys(PlannerInfo *root, 222 List *pathkeys, 223 List *restrictinfos); 224 extern List *select_outer_pathkeys_for_merge(PlannerInfo *root, 225 List *mergeclauses, 226 RelOptInfo *joinrel); 227 extern List *make_inner_pathkeys_for_merge(PlannerInfo *root, 228 List *mergeclauses, 229 List *outer_pathkeys); 230 extern List *trim_mergeclauses_for_inner_pathkeys(PlannerInfo *root, 231 List *mergeclauses, 232 List *pathkeys); 233 extern List *truncate_useless_pathkeys(PlannerInfo *root, 234 RelOptInfo *rel, 235 List *pathkeys); 236 extern bool has_useful_pathkeys(PlannerInfo *root, RelOptInfo *rel); 237 extern PathKey *make_canonical_pathkey(PlannerInfo *root, 238 EquivalenceClass *eclass, Oid opfamily, 239 int strategy, bool nulls_first); 240 extern void add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel, 241 List *live_childrels); 242 243 #endif /* PATHS_H */ 244