diff options
Diffstat (limited to 'src/include/optimizer')
27 files changed, 2145 insertions, 0 deletions
diff --git a/src/include/optimizer/appendinfo.h b/src/include/optimizer/appendinfo.h new file mode 100644 index 0000000..39d04d9 --- /dev/null +++ b/src/include/optimizer/appendinfo.h @@ -0,0 +1,50 @@ +/*------------------------------------------------------------------------- + * + * appendinfo.h + * Routines for mapping expressions between append rel parent(s) and + * children + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/appendinfo.h + * + *------------------------------------------------------------------------- + */ +#ifndef APPENDINFO_H +#define APPENDINFO_H + +#include "nodes/pathnodes.h" +#include "utils/relcache.h" + +extern AppendRelInfo *make_append_rel_info(Relation parentrel, + Relation childrel, + Index parentRTindex, Index childRTindex); +extern Node *adjust_appendrel_attrs(PlannerInfo *root, Node *node, + int nappinfos, AppendRelInfo **appinfos); +extern Node *adjust_appendrel_attrs_multilevel(PlannerInfo *root, Node *node, + Relids child_relids, + Relids top_parent_relids); +extern Relids adjust_child_relids(Relids relids, int nappinfos, + AppendRelInfo **appinfos); +extern Relids adjust_child_relids_multilevel(PlannerInfo *root, Relids relids, + Relids child_relids, + Relids top_parent_relids); +extern List *adjust_inherited_attnums(List *attnums, AppendRelInfo *context); +extern List *adjust_inherited_attnums_multilevel(PlannerInfo *root, + List *attnums, + Index child_relid, + Index top_parent_relid); +extern void get_translated_update_targetlist(PlannerInfo *root, Index relid, + List **processed_tlist, + List **update_colnos); +extern AppendRelInfo **find_appinfos_by_relids(PlannerInfo *root, + Relids relids, int *nappinfos); +extern void add_row_identity_var(PlannerInfo *root, Var *rowid_var, + Index rtindex, const char *rowid_name); +extern void add_row_identity_columns(PlannerInfo *root, Index rtindex, + RangeTblEntry *target_rte, + Relation target_relation); +extern void distribute_row_identity_vars(PlannerInfo *root); + +#endif /* APPENDINFO_H */ diff --git a/src/include/optimizer/clauses.h b/src/include/optimizer/clauses.h new file mode 100644 index 0000000..bc3f3e6 --- /dev/null +++ b/src/include/optimizer/clauses.h @@ -0,0 +1,58 @@ +/*------------------------------------------------------------------------- + * + * clauses.h + * prototypes for clauses.c. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/clauses.h + * + *------------------------------------------------------------------------- + */ +#ifndef CLAUSES_H +#define CLAUSES_H + +#include "nodes/pathnodes.h" + +typedef struct +{ + int numWindowFuncs; /* total number of WindowFuncs found */ + Index maxWinRef; /* windowFuncs[] is indexed 0 .. maxWinRef */ + List **windowFuncs; /* lists of WindowFuncs for each winref */ +} WindowFuncLists; + +extern bool contain_agg_clause(Node *clause); + +extern bool contain_window_function(Node *clause); +extern WindowFuncLists *find_window_functions(Node *clause, Index maxWinRef); + +extern double expression_returns_set_rows(PlannerInfo *root, Node *clause); + +extern bool contain_subplans(Node *clause); + +extern char max_parallel_hazard(Query *parse); +extern bool is_parallel_safe(PlannerInfo *root, Node *node); +extern bool contain_nonstrict_functions(Node *clause); +extern bool contain_exec_param(Node *clause, List *param_ids); +extern bool contain_leaked_vars(Node *clause); + +extern Relids find_nonnullable_rels(Node *clause); +extern List *find_nonnullable_vars(Node *clause); +extern List *find_forced_null_vars(Node *clause); +extern Var *find_forced_null_var(Node *clause); + +extern bool is_pseudo_constant_clause(Node *clause); +extern bool is_pseudo_constant_clause_relids(Node *clause, Relids relids); + +extern int NumRelids(PlannerInfo *root, Node *clause); + +extern void CommuteOpExpr(OpExpr *clause); + +extern Query *inline_set_returning_function(PlannerInfo *root, + RangeTblEntry *rte); + +extern Bitmapset *pull_paramids(Expr *expr); + +#endif /* CLAUSES_H */ diff --git a/src/include/optimizer/cost.h b/src/include/optimizer/cost.h new file mode 100644 index 0000000..2113bc8 --- /dev/null +++ b/src/include/optimizer/cost.h @@ -0,0 +1,211 @@ +/*------------------------------------------------------------------------- + * + * cost.h + * prototypes for costsize.c and clausesel.c. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/cost.h + * + *------------------------------------------------------------------------- + */ +#ifndef COST_H +#define COST_H + +#include "nodes/pathnodes.h" +#include "nodes/plannodes.h" + + +/* defaults for costsize.c's Cost parameters */ +/* NB: cost-estimation code should use the variables, not these constants! */ +/* If you change these, update backend/utils/misc/postgresql.conf.sample */ +#define DEFAULT_SEQ_PAGE_COST 1.0 +#define DEFAULT_RANDOM_PAGE_COST 4.0 +#define DEFAULT_CPU_TUPLE_COST 0.01 +#define DEFAULT_CPU_INDEX_TUPLE_COST 0.005 +#define DEFAULT_CPU_OPERATOR_COST 0.0025 +#define DEFAULT_PARALLEL_TUPLE_COST 0.1 +#define DEFAULT_PARALLEL_SETUP_COST 1000.0 + +#define DEFAULT_EFFECTIVE_CACHE_SIZE 524288 /* measured in pages */ + +typedef enum +{ + CONSTRAINT_EXCLUSION_OFF, /* do not use c_e */ + CONSTRAINT_EXCLUSION_ON, /* apply c_e to all rels */ + CONSTRAINT_EXCLUSION_PARTITION /* apply c_e to otherrels only */ +} ConstraintExclusionType; + + +/* + * prototypes for costsize.c + * routines to compute costs and sizes + */ + +/* parameter variables and flags (see also optimizer.h) */ +extern PGDLLIMPORT Cost disable_cost; +extern PGDLLIMPORT int max_parallel_workers_per_gather; +extern PGDLLIMPORT bool enable_seqscan; +extern PGDLLIMPORT bool enable_indexscan; +extern PGDLLIMPORT bool enable_indexonlyscan; +extern PGDLLIMPORT bool enable_bitmapscan; +extern PGDLLIMPORT bool enable_tidscan; +extern PGDLLIMPORT bool enable_sort; +extern PGDLLIMPORT bool enable_incremental_sort; +extern PGDLLIMPORT bool enable_hashagg; +extern PGDLLIMPORT bool enable_nestloop; +extern PGDLLIMPORT bool enable_material; +extern PGDLLIMPORT bool enable_memoize; +extern PGDLLIMPORT bool enable_mergejoin; +extern PGDLLIMPORT bool enable_hashjoin; +extern PGDLLIMPORT bool enable_gathermerge; +extern PGDLLIMPORT bool enable_partitionwise_join; +extern PGDLLIMPORT bool enable_partitionwise_aggregate; +extern PGDLLIMPORT bool enable_parallel_append; +extern PGDLLIMPORT bool enable_parallel_hash; +extern PGDLLIMPORT bool enable_partition_pruning; +extern PGDLLIMPORT bool enable_async_append; +extern PGDLLIMPORT int constraint_exclusion; + +extern double index_pages_fetched(double tuples_fetched, BlockNumber pages, + double index_pages, PlannerInfo *root); +extern void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, + ParamPathInfo *param_info); +extern void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, + ParamPathInfo *param_info); +extern void cost_index(IndexPath *path, PlannerInfo *root, + double loop_count, bool partial_path); +extern void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, + ParamPathInfo *param_info, + Path *bitmapqual, double loop_count); +extern void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root); +extern void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root); +extern void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec); +extern void cost_tidscan(Path *path, PlannerInfo *root, + RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info); +extern void cost_tidrangescan(Path *path, PlannerInfo *root, + RelOptInfo *baserel, List *tidrangequals, + ParamPathInfo *param_info); +extern void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root, + RelOptInfo *baserel, ParamPathInfo *param_info); +extern void cost_functionscan(Path *path, PlannerInfo *root, + RelOptInfo *baserel, ParamPathInfo *param_info); +extern void cost_valuesscan(Path *path, PlannerInfo *root, + RelOptInfo *baserel, ParamPathInfo *param_info); +extern void cost_tablefuncscan(Path *path, PlannerInfo *root, + RelOptInfo *baserel, ParamPathInfo *param_info); +extern void cost_ctescan(Path *path, PlannerInfo *root, + RelOptInfo *baserel, ParamPathInfo *param_info); +extern void cost_namedtuplestorescan(Path *path, PlannerInfo *root, + RelOptInfo *baserel, ParamPathInfo *param_info); +extern void cost_resultscan(Path *path, PlannerInfo *root, + RelOptInfo *baserel, ParamPathInfo *param_info); +extern void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm); +extern void cost_sort(Path *path, PlannerInfo *root, + List *pathkeys, Cost input_cost, double tuples, int width, + Cost comparison_cost, int sort_mem, + double limit_tuples); +extern void cost_incremental_sort(Path *path, + PlannerInfo *root, List *pathkeys, int presorted_keys, + Cost input_startup_cost, Cost input_total_cost, + double input_tuples, int width, Cost comparison_cost, int sort_mem, + double limit_tuples); +extern void cost_append(AppendPath *path); +extern void cost_merge_append(Path *path, PlannerInfo *root, + List *pathkeys, int n_streams, + Cost input_startup_cost, Cost input_total_cost, + double tuples); +extern void cost_material(Path *path, + Cost input_startup_cost, Cost input_total_cost, + double tuples, int width); +extern void cost_agg(Path *path, PlannerInfo *root, + AggStrategy aggstrategy, const AggClauseCosts *aggcosts, + int numGroupCols, double numGroups, + List *quals, + Cost input_startup_cost, Cost input_total_cost, + double input_tuples, double input_width); +extern void cost_windowagg(Path *path, PlannerInfo *root, + List *windowFuncs, int numPartCols, int numOrderCols, + Cost input_startup_cost, Cost input_total_cost, + double input_tuples); +extern void cost_group(Path *path, PlannerInfo *root, + int numGroupCols, double numGroups, + List *quals, + Cost input_startup_cost, Cost input_total_cost, + double input_tuples); +extern void initial_cost_nestloop(PlannerInfo *root, + JoinCostWorkspace *workspace, + JoinType jointype, + Path *outer_path, Path *inner_path, + JoinPathExtraData *extra); +extern void final_cost_nestloop(PlannerInfo *root, NestPath *path, + JoinCostWorkspace *workspace, + JoinPathExtraData *extra); +extern void initial_cost_mergejoin(PlannerInfo *root, + JoinCostWorkspace *workspace, + JoinType jointype, + List *mergeclauses, + Path *outer_path, Path *inner_path, + List *outersortkeys, List *innersortkeys, + JoinPathExtraData *extra); +extern void final_cost_mergejoin(PlannerInfo *root, MergePath *path, + JoinCostWorkspace *workspace, + JoinPathExtraData *extra); +extern void initial_cost_hashjoin(PlannerInfo *root, + JoinCostWorkspace *workspace, + JoinType jointype, + List *hashclauses, + Path *outer_path, Path *inner_path, + JoinPathExtraData *extra, + bool parallel_hash); +extern void final_cost_hashjoin(PlannerInfo *root, HashPath *path, + JoinCostWorkspace *workspace, + JoinPathExtraData *extra); +extern void cost_gather(GatherPath *path, PlannerInfo *root, + RelOptInfo *baserel, ParamPathInfo *param_info, double *rows); +extern void cost_gather_merge(GatherMergePath *path, PlannerInfo *root, + RelOptInfo *rel, ParamPathInfo *param_info, + Cost input_startup_cost, Cost input_total_cost, + double *rows); +extern void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan); +extern void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root); +extern void cost_qual_eval_node(QualCost *cost, Node *qual, PlannerInfo *root); +extern void compute_semi_anti_join_factors(PlannerInfo *root, + RelOptInfo *joinrel, + RelOptInfo *outerrel, + RelOptInfo *innerrel, + JoinType jointype, + SpecialJoinInfo *sjinfo, + List *restrictlist, + SemiAntiJoinFactors *semifactors); +extern void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel); +extern double get_parameterized_baserel_size(PlannerInfo *root, + RelOptInfo *rel, + List *param_clauses); +extern double get_parameterized_joinrel_size(PlannerInfo *root, + RelOptInfo *rel, + Path *outer_path, + Path *inner_path, + SpecialJoinInfo *sjinfo, + List *restrict_clauses); +extern void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, + RelOptInfo *outer_rel, + RelOptInfo *inner_rel, + SpecialJoinInfo *sjinfo, + List *restrictlist); +extern void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel); +extern void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel); +extern void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel); +extern void set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel, + double cte_rows); +extern void set_tablefunc_size_estimates(PlannerInfo *root, RelOptInfo *rel); +extern void set_namedtuplestore_size_estimates(PlannerInfo *root, RelOptInfo *rel); +extern void set_result_size_estimates(PlannerInfo *root, RelOptInfo *rel); +extern void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel); +extern PathTarget *set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target); +extern double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel, + Path *bitmapqual, int loop_count, Cost *cost, double *tuple); + +#endif /* COST_H */ diff --git a/src/include/optimizer/geqo.h b/src/include/optimizer/geqo.h new file mode 100644 index 0000000..24dcdfb --- /dev/null +++ b/src/include/optimizer/geqo.h @@ -0,0 +1,88 @@ +/*------------------------------------------------------------------------- + * + * geqo.h + * prototypes for various files in optimizer/geqo + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo.h + * + *------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +#ifndef GEQO_H +#define GEQO_H + +#include "nodes/pathnodes.h" +#include "optimizer/geqo_gene.h" + + +/* GEQO debug flag */ +/* + #define GEQO_DEBUG + */ + +/* choose one recombination mechanism here */ +/* + #define ERX + #define PMX + #define CX + #define PX + #define OX1 + #define OX2 + */ +#define ERX + + +/* + * Configuration options + * + * If you change these, update backend/utils/misc/postgresql.conf.sample + */ +extern int Geqo_effort; /* 1 .. 10, knob for adjustment of defaults */ + +#define DEFAULT_GEQO_EFFORT 5 +#define MIN_GEQO_EFFORT 1 +#define MAX_GEQO_EFFORT 10 + +extern int Geqo_pool_size; /* 2 .. inf, or 0 to use default */ + +extern int Geqo_generations; /* 1 .. inf, or 0 to use default */ + +extern double Geqo_selection_bias; + +#define DEFAULT_GEQO_SELECTION_BIAS 2.0 +#define MIN_GEQO_SELECTION_BIAS 1.5 +#define MAX_GEQO_SELECTION_BIAS 2.0 + +extern double Geqo_seed; /* 0 .. 1 */ + + +/* + * Private state for a GEQO run --- accessible via root->join_search_private + */ +typedef struct +{ + List *initial_rels; /* the base relations we are joining */ + unsigned short random_state[3]; /* state for pg_erand48() */ +} GeqoPrivateData; + + +/* routines in geqo_main.c */ +extern RelOptInfo *geqo(PlannerInfo *root, + int number_of_rels, List *initial_rels); + +/* routines in geqo_eval.c */ +extern Cost geqo_eval(PlannerInfo *root, Gene *tour, int num_gene); +extern RelOptInfo *gimme_tree(PlannerInfo *root, Gene *tour, int num_gene); + +#endif /* GEQO_H */ diff --git a/src/include/optimizer/geqo_copy.h b/src/include/optimizer/geqo_copy.h new file mode 100644 index 0000000..47c5449 --- /dev/null +++ b/src/include/optimizer/geqo_copy.h @@ -0,0 +1,30 @@ +/*------------------------------------------------------------------------- + * + * geqo_copy.h + * prototypes for copy functions in optimizer/geqo + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_copy.h + * + *------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +#ifndef GEQO_COPY_H +#define GEQO_COPY_H + +#include "optimizer/geqo.h" + + +extern void geqo_copy(PlannerInfo *root, Chromosome *chromo1, Chromosome *chromo2, int string_length); + +#endif /* GEQO_COPY_H */ diff --git a/src/include/optimizer/geqo_gene.h b/src/include/optimizer/geqo_gene.h new file mode 100644 index 0000000..8930054 --- /dev/null +++ b/src/include/optimizer/geqo_gene.h @@ -0,0 +1,45 @@ +/*------------------------------------------------------------------------- + * + * geqo_gene.h + * genome representation in optimizer/geqo + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_gene.h + * + *------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + + +#ifndef GEQO_GENE_H +#define GEQO_GENE_H + +#include "nodes/nodes.h" + +/* we presume that int instead of Relid + is o.k. for Gene; so don't change it! */ +typedef int Gene; + +typedef struct Chromosome +{ + Gene *string; + Cost worth; +} Chromosome; + +typedef struct Pool +{ + Chromosome *data; + int size; + int string_length; +} Pool; + +#endif /* GEQO_GENE_H */ diff --git a/src/include/optimizer/geqo_misc.h b/src/include/optimizer/geqo_misc.h new file mode 100644 index 0000000..458c408 --- /dev/null +++ b/src/include/optimizer/geqo_misc.h @@ -0,0 +1,34 @@ +/*------------------------------------------------------------------------- + * + * geqo_misc.h + * prototypes for printout routines in optimizer/geqo + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_misc.h + * + *------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +#ifndef GEQO_MISC_H +#define GEQO_MISC_H + +#include "optimizer/geqo_recombination.h" + +#ifdef GEQO_DEBUG + +extern void print_pool(FILE *fp, Pool *pool, int start, int stop); +extern void print_gen(FILE *fp, Pool *pool, int generation); +extern void print_edge_table(FILE *fp, Edge *edge_table, int num_gene); +#endif /* GEQO_DEBUG */ + +#endif /* GEQO_MISC_H */ diff --git a/src/include/optimizer/geqo_mutation.h b/src/include/optimizer/geqo_mutation.h new file mode 100644 index 0000000..076e4ab --- /dev/null +++ b/src/include/optimizer/geqo_mutation.h @@ -0,0 +1,30 @@ +/*------------------------------------------------------------------------- + * + * geqo_mutation.h + * prototypes for mutation functions in optimizer/geqo + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_mutation.h + * + *------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +#ifndef GEQO_MUTATION_H +#define GEQO_MUTATION_H + +#include "optimizer/geqo.h" + + +extern void geqo_mutation(PlannerInfo *root, Gene *tour, int num_gene); + +#endif /* GEQO_MUTATION_H */ diff --git a/src/include/optimizer/geqo_pool.h b/src/include/optimizer/geqo_pool.h new file mode 100644 index 0000000..d5c41ac --- /dev/null +++ b/src/include/optimizer/geqo_pool.h @@ -0,0 +1,40 @@ +/*------------------------------------------------------------------------- + * + * geqo_pool.h + * pool representation in optimizer/geqo + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_pool.h + * + *------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + + +#ifndef GEQO_POOL_H +#define GEQO_POOL_H + +#include "optimizer/geqo.h" + + +extern Pool *alloc_pool(PlannerInfo *root, int pool_size, int string_length); +extern void free_pool(PlannerInfo *root, Pool *pool); + +extern void random_init_pool(PlannerInfo *root, Pool *pool); +extern Chromosome *alloc_chromo(PlannerInfo *root, int string_length); +extern void free_chromo(PlannerInfo *root, Chromosome *chromo); + +extern void spread_chromo(PlannerInfo *root, Chromosome *chromo, Pool *pool); + +extern void sort_pool(PlannerInfo *root, Pool *pool); + +#endif /* GEQO_POOL_H */ diff --git a/src/include/optimizer/geqo_random.h b/src/include/optimizer/geqo_random.h new file mode 100644 index 0000000..7f4aad4 --- /dev/null +++ b/src/include/optimizer/geqo_random.h @@ -0,0 +1,41 @@ +/*------------------------------------------------------------------------- + * + * geqo_random.h + * random number generator + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_random.h + * + *------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +/* -- parts of this are adapted from D. Whitley's Genitor algorithm -- */ + +#ifndef GEQO_RANDOM_H +#define GEQO_RANDOM_H + +#include <math.h> + +#include "optimizer/geqo.h" + + +extern void geqo_set_seed(PlannerInfo *root, double seed); + +/* geqo_rand returns a random float value between 0 and 1 inclusive */ +extern double geqo_rand(PlannerInfo *root); + +/* geqo_randint returns integer value between lower and upper inclusive */ +#define geqo_randint(root, upper, lower) \ + ( (int) floor( geqo_rand(root)*(((upper)-(lower))+0.999999) ) + (lower) ) + +#endif /* GEQO_RANDOM_H */ diff --git a/src/include/optimizer/geqo_recombination.h b/src/include/optimizer/geqo_recombination.h new file mode 100644 index 0000000..3001832 --- /dev/null +++ b/src/include/optimizer/geqo_recombination.h @@ -0,0 +1,89 @@ +/*------------------------------------------------------------------------- + * + * geqo_recombination.h + * prototypes for recombination in the genetic query optimizer + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_recombination.h + * + *------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + +/* -- parts of this are adapted from D. Whitley's Genitor algorithm -- */ + +#ifndef GEQO_RECOMBINATION_H +#define GEQO_RECOMBINATION_H + +#include "optimizer/geqo.h" + + +extern void init_tour(PlannerInfo *root, Gene *tour, int num_gene); + + +/* edge recombination crossover [ERX] */ + +typedef struct Edge +{ + Gene edge_list[4]; /* list of edges */ + int total_edges; + int unused_edges; +} Edge; + +extern Edge *alloc_edge_table(PlannerInfo *root, int num_gene); +extern void free_edge_table(PlannerInfo *root, Edge *edge_table); + +extern float gimme_edge_table(PlannerInfo *root, Gene *tour1, Gene *tour2, + int num_gene, Edge *edge_table); + +extern int gimme_tour(PlannerInfo *root, Edge *edge_table, Gene *new_gene, + int num_gene); + + +/* partially matched crossover [PMX] */ + +#define DAD 1 /* indicator for gene from dad */ +#define MOM 0 /* indicator for gene from mom */ + +extern void pmx(PlannerInfo *root, + Gene *tour1, Gene *tour2, + Gene *offspring, int num_gene); + + +typedef struct City +{ + int tour2_position; + int tour1_position; + int used; + int select_list; +} City; + +extern City * alloc_city_table(PlannerInfo *root, int num_gene); +extern void free_city_table(PlannerInfo *root, City * city_table); + +/* cycle crossover [CX] */ +extern int cx(PlannerInfo *root, Gene *tour1, Gene *tour2, + Gene *offspring, int num_gene, City * city_table); + +/* position crossover [PX] */ +extern void px(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, + int num_gene, City * city_table); + +/* order crossover [OX1] according to Davis */ +extern void ox1(PlannerInfo *root, Gene *mom, Gene *dad, Gene *offspring, + int num_gene, City * city_table); + +/* order crossover [OX2] according to Syswerda */ +extern void ox2(PlannerInfo *root, Gene *mom, Gene *dad, Gene *offspring, + int num_gene, City * city_table); + +#endif /* GEQO_RECOMBINATION_H */ diff --git a/src/include/optimizer/geqo_selection.h b/src/include/optimizer/geqo_selection.h new file mode 100644 index 0000000..099c8ce --- /dev/null +++ b/src/include/optimizer/geqo_selection.h @@ -0,0 +1,33 @@ +/*------------------------------------------------------------------------- + * + * geqo_selection.h + * prototypes for selection routines in optimizer/geqo + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/geqo_selection.h + * + *------------------------------------------------------------------------- + */ + +/* contributed by: + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + * Martin Utesch * Institute of Automatic Control * + = = University of Mining and Technology = + * utesch@aut.tu-freiberg.de * Freiberg, Germany * + =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= + */ + + +#ifndef GEQO_SELECTION_H +#define GEQO_SELECTION_H + +#include "optimizer/geqo.h" + + +extern void geqo_selection(PlannerInfo *root, + Chromosome *momma, Chromosome *daddy, + Pool *pool, double bias); + +#endif /* GEQO_SELECTION_H */ diff --git a/src/include/optimizer/inherit.h b/src/include/optimizer/inherit.h new file mode 100644 index 0000000..e9472f2 --- /dev/null +++ b/src/include/optimizer/inherit.h @@ -0,0 +1,27 @@ +/*------------------------------------------------------------------------- + * + * inherit.h + * prototypes for inherit.c. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/inherit.h + * + *------------------------------------------------------------------------- + */ +#ifndef INHERIT_H +#define INHERIT_H + +#include "nodes/pathnodes.h" + + +extern void expand_inherited_rtentry(PlannerInfo *root, RelOptInfo *rel, + RangeTblEntry *rte, Index rti); + +extern bool apply_child_basequals(PlannerInfo *root, RelOptInfo *parentrel, + RelOptInfo *childrel, RangeTblEntry *childRTE, + AppendRelInfo *appinfo); + +#endif /* INHERIT_H */ diff --git a/src/include/optimizer/joininfo.h b/src/include/optimizer/joininfo.h new file mode 100644 index 0000000..739cc52 --- /dev/null +++ b/src/include/optimizer/joininfo.h @@ -0,0 +1,30 @@ +/*------------------------------------------------------------------------- + * + * joininfo.h + * prototypes for joininfo.c. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/joininfo.h + * + *------------------------------------------------------------------------- + */ +#ifndef JOININFO_H +#define JOININFO_H + +#include "nodes/pathnodes.h" + + +extern bool have_relevant_joinclause(PlannerInfo *root, + RelOptInfo *rel1, RelOptInfo *rel2); + +extern void add_join_clause_to_rels(PlannerInfo *root, + RestrictInfo *restrictinfo, + Relids join_relids); +extern void remove_join_clause_from_rels(PlannerInfo *root, + RestrictInfo *restrictinfo, + Relids join_relids); + +#endif /* JOININFO_H */ diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h new file mode 100644 index 0000000..575f245 --- /dev/null +++ b/src/include/optimizer/optimizer.h @@ -0,0 +1,200 @@ +/*------------------------------------------------------------------------- + * + * optimizer.h + * External API for the Postgres planner. + * + * This header is meant to define everything that the core planner + * exposes for use by non-planner modules. + * + * Note that there are files outside src/backend/optimizer/ that are + * considered planner modules, because they're too much in bed with + * planner operations to be treated otherwise. FDW planning code is an + * example. For the most part, however, code outside the core planner + * should not need to include any optimizer/ header except this one. + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/optimizer.h + * + *------------------------------------------------------------------------- + */ +#ifndef OPTIMIZER_H +#define OPTIMIZER_H + +#include "nodes/parsenodes.h" + +/* + * We don't want to include nodes/pathnodes.h here, because non-planner + * code should generally treat PlannerInfo as an opaque typedef. + * But we'd like such code to use that typedef name, so define the + * typedef either here or in pathnodes.h, whichever is read first. + */ +#ifndef HAVE_PLANNERINFO_TYPEDEF +typedef struct PlannerInfo PlannerInfo; +#define HAVE_PLANNERINFO_TYPEDEF 1 +#endif + +/* Likewise for IndexOptInfo and SpecialJoinInfo. */ +#ifndef HAVE_INDEXOPTINFO_TYPEDEF +typedef struct IndexOptInfo IndexOptInfo; +#define HAVE_INDEXOPTINFO_TYPEDEF 1 +#endif +#ifndef HAVE_SPECIALJOININFO_TYPEDEF +typedef struct SpecialJoinInfo SpecialJoinInfo; +#define HAVE_SPECIALJOININFO_TYPEDEF 1 +#endif + +/* It also seems best not to include plannodes.h, params.h, or htup.h here */ +struct PlannedStmt; +struct ParamListInfoData; +struct HeapTupleData; + + +/* in path/clausesel.c: */ + +extern Selectivity clause_selectivity(PlannerInfo *root, + Node *clause, + int varRelid, + JoinType jointype, + SpecialJoinInfo *sjinfo); +extern Selectivity clause_selectivity_ext(PlannerInfo *root, + Node *clause, + int varRelid, + JoinType jointype, + SpecialJoinInfo *sjinfo, + bool use_extended_stats); +extern Selectivity clauselist_selectivity(PlannerInfo *root, + List *clauses, + int varRelid, + JoinType jointype, + SpecialJoinInfo *sjinfo); +extern Selectivity clauselist_selectivity_ext(PlannerInfo *root, + List *clauses, + int varRelid, + JoinType jointype, + SpecialJoinInfo *sjinfo, + bool use_extended_stats); + +/* in path/costsize.c: */ + +/* widely used cost parameters */ +extern PGDLLIMPORT double seq_page_cost; +extern PGDLLIMPORT double random_page_cost; +extern PGDLLIMPORT double cpu_tuple_cost; +extern PGDLLIMPORT double cpu_index_tuple_cost; +extern PGDLLIMPORT double cpu_operator_cost; +extern PGDLLIMPORT double parallel_tuple_cost; +extern PGDLLIMPORT double parallel_setup_cost; +extern PGDLLIMPORT int effective_cache_size; + +extern double clamp_row_est(double nrows); + +/* in path/indxpath.c: */ + +extern bool is_pseudo_constant_for_index(PlannerInfo *root, Node *expr, + IndexOptInfo *index); + +/* in plan/planner.c: */ + +/* possible values for force_parallel_mode */ +typedef enum +{ + FORCE_PARALLEL_OFF, + FORCE_PARALLEL_ON, + FORCE_PARALLEL_REGRESS +} ForceParallelMode; + +/* GUC parameters */ +extern int force_parallel_mode; +extern bool parallel_leader_participation; + +extern struct PlannedStmt *planner(Query *parse, const char *query_string, + int cursorOptions, + struct ParamListInfoData *boundParams); + +extern Expr *expression_planner(Expr *expr); +extern Expr *expression_planner_with_deps(Expr *expr, + List **relationOids, + List **invalItems); + +extern bool plan_cluster_use_sort(Oid tableOid, Oid indexOid); +extern int plan_create_index_workers(Oid tableOid, Oid indexOid); + +/* in plan/setrefs.c: */ + +extern void extract_query_dependencies(Node *query, + List **relationOids, + List **invalItems, + bool *hasRowSecurity); + +/* in prep/prepqual.c: */ + +extern Node *negate_clause(Node *node); +extern Expr *canonicalize_qual(Expr *qual, bool is_check); + +/* in util/clauses.c: */ + +extern bool contain_mutable_functions(Node *clause); +extern bool contain_volatile_functions(Node *clause); +extern bool contain_volatile_functions_not_nextval(Node *clause); + +extern Node *eval_const_expressions(PlannerInfo *root, Node *node); + +extern void convert_saop_to_hashed_saop(Node *node); + +extern Node *estimate_expression_value(PlannerInfo *root, Node *node); + +extern Expr *evaluate_expr(Expr *expr, Oid result_type, int32 result_typmod, + Oid result_collation); + +extern List *expand_function_arguments(List *args, bool include_out_arguments, + Oid result_type, + struct HeapTupleData *func_tuple); + +/* in util/predtest.c: */ + +extern bool predicate_implied_by(List *predicate_list, List *clause_list, + bool weak); +extern bool predicate_refuted_by(List *predicate_list, List *clause_list, + bool weak); + +/* in util/tlist.c: */ + +extern int count_nonjunk_tlist_entries(List *tlist); +extern TargetEntry *get_sortgroupref_tle(Index sortref, + List *targetList); +extern TargetEntry *get_sortgroupclause_tle(SortGroupClause *sgClause, + List *targetList); +extern Node *get_sortgroupclause_expr(SortGroupClause *sgClause, + List *targetList); +extern List *get_sortgrouplist_exprs(List *sgClauses, + List *targetList); +extern SortGroupClause *get_sortgroupref_clause(Index sortref, + List *clauses); +extern SortGroupClause *get_sortgroupref_clause_noerr(Index sortref, + List *clauses); + +/* in util/var.c: */ + +/* Bits that can be OR'd into the flags argument of pull_var_clause() */ +#define PVC_INCLUDE_AGGREGATES 0x0001 /* include Aggrefs in output list */ +#define PVC_RECURSE_AGGREGATES 0x0002 /* recurse into Aggref arguments */ +#define PVC_INCLUDE_WINDOWFUNCS 0x0004 /* include WindowFuncs in output list */ +#define PVC_RECURSE_WINDOWFUNCS 0x0008 /* recurse into WindowFunc arguments */ +#define PVC_INCLUDE_PLACEHOLDERS 0x0010 /* include PlaceHolderVars in + * output list */ +#define PVC_RECURSE_PLACEHOLDERS 0x0020 /* recurse into PlaceHolderVar + * arguments */ + +extern Bitmapset *pull_varnos(PlannerInfo *root, Node *node); +extern Bitmapset *pull_varnos_of_level(PlannerInfo *root, Node *node, int levelsup); +extern void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos); +extern List *pull_vars_of_level(Node *node, int levelsup); +extern bool contain_var_clause(Node *node); +extern bool contain_vars_of_level(Node *node, int levelsup); +extern int locate_var_of_level(Node *node, int levelsup); +extern List *pull_var_clause(Node *node, int flags); +extern Node *flatten_join_alias_vars(Query *query, Node *node); + +#endif /* OPTIMIZER_H */ diff --git a/src/include/optimizer/orclauses.h b/src/include/optimizer/orclauses.h new file mode 100644 index 0000000..526101e --- /dev/null +++ b/src/include/optimizer/orclauses.h @@ -0,0 +1,21 @@ +/*------------------------------------------------------------------------- + * + * orclauses.h + * prototypes for orclauses.c. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/orclauses.h + * + *------------------------------------------------------------------------- + */ +#ifndef ORCLAUSES_H +#define ORCLAUSES_H + +#include "nodes/pathnodes.h" + +extern void extract_restriction_or_clauses(PlannerInfo *root); + +#endif /* ORCLAUSES_H */ diff --git a/src/include/optimizer/paramassign.h b/src/include/optimizer/paramassign.h new file mode 100644 index 0000000..b4fd379 --- /dev/null +++ b/src/include/optimizer/paramassign.h @@ -0,0 +1,34 @@ +/*------------------------------------------------------------------------- + * + * paramassign.h + * Functions for assigning PARAM_EXEC slots during planning. + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/paramassign.h + * + *------------------------------------------------------------------------- + */ +#ifndef PARAMASSIGN_H +#define PARAMASSIGN_H + +#include "nodes/pathnodes.h" + +extern Param *replace_outer_var(PlannerInfo *root, Var *var); +extern Param *replace_outer_placeholdervar(PlannerInfo *root, + PlaceHolderVar *phv); +extern Param *replace_outer_agg(PlannerInfo *root, Aggref *agg); +extern Param *replace_outer_grouping(PlannerInfo *root, GroupingFunc *grp); +extern Param *replace_nestloop_param_var(PlannerInfo *root, Var *var); +extern Param *replace_nestloop_param_placeholdervar(PlannerInfo *root, + PlaceHolderVar *phv); +extern void process_subquery_nestloop_params(PlannerInfo *root, + List *subplan_params); +extern List *identify_current_nestloop_params(PlannerInfo *root, + Relids leftrelids); +extern Param *generate_new_exec_param(PlannerInfo *root, Oid paramtype, + int32 paramtypmod, Oid paramcollation); +extern int assign_special_exec_param(PlannerInfo *root); + +#endif /* PARAMASSIGN_H */ diff --git a/src/include/optimizer/pathnode.h b/src/include/optimizer/pathnode.h new file mode 100644 index 0000000..2922c0c --- /dev/null +++ b/src/include/optimizer/pathnode.h @@ -0,0 +1,336 @@ +/*------------------------------------------------------------------------- + * + * pathnode.h + * prototypes for pathnode.c, relnode.c. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/pathnode.h + * + *------------------------------------------------------------------------- + */ +#ifndef PATHNODE_H +#define PATHNODE_H + +#include "nodes/bitmapset.h" +#include "nodes/pathnodes.h" + + +/* + * prototypes for pathnode.c + */ +extern int compare_path_costs(Path *path1, Path *path2, + CostSelector criterion); +extern int compare_fractional_path_costs(Path *path1, Path *path2, + double fraction); +extern void set_cheapest(RelOptInfo *parent_rel); +extern void add_path(RelOptInfo *parent_rel, Path *new_path); +extern bool add_path_precheck(RelOptInfo *parent_rel, + Cost startup_cost, Cost total_cost, + List *pathkeys, Relids required_outer); +extern void add_partial_path(RelOptInfo *parent_rel, Path *new_path); +extern bool add_partial_path_precheck(RelOptInfo *parent_rel, + Cost total_cost, List *pathkeys); + +extern Path *create_seqscan_path(PlannerInfo *root, RelOptInfo *rel, + Relids required_outer, int parallel_workers); +extern Path *create_samplescan_path(PlannerInfo *root, RelOptInfo *rel, + Relids required_outer); +extern IndexPath *create_index_path(PlannerInfo *root, + IndexOptInfo *index, + List *indexclauses, + List *indexorderbys, + List *indexorderbycols, + List *pathkeys, + ScanDirection indexscandir, + bool indexonly, + Relids required_outer, + double loop_count, + bool partial_path); +extern BitmapHeapPath *create_bitmap_heap_path(PlannerInfo *root, + RelOptInfo *rel, + Path *bitmapqual, + Relids required_outer, + double loop_count, + int parallel_degree); +extern BitmapAndPath *create_bitmap_and_path(PlannerInfo *root, + RelOptInfo *rel, + List *bitmapquals); +extern BitmapOrPath *create_bitmap_or_path(PlannerInfo *root, + RelOptInfo *rel, + List *bitmapquals); +extern TidPath *create_tidscan_path(PlannerInfo *root, RelOptInfo *rel, + List *tidquals, Relids required_outer); +extern TidRangePath *create_tidrangescan_path(PlannerInfo *root, + RelOptInfo *rel, + List *tidrangequals, + Relids required_outer); +extern AppendPath *create_append_path(PlannerInfo *root, RelOptInfo *rel, + List *subpaths, List *partial_subpaths, + List *pathkeys, Relids required_outer, + int parallel_workers, bool parallel_aware, + double rows); +extern MergeAppendPath *create_merge_append_path(PlannerInfo *root, + RelOptInfo *rel, + List *subpaths, + List *pathkeys, + Relids required_outer); +extern GroupResultPath *create_group_result_path(PlannerInfo *root, + RelOptInfo *rel, + PathTarget *target, + List *havingqual); +extern MaterialPath *create_material_path(RelOptInfo *rel, Path *subpath); +extern MemoizePath *create_memoize_path(PlannerInfo *root, + RelOptInfo *rel, + Path *subpath, + List *param_exprs, + List *hash_operators, + bool singlerow, + bool binary_mode, + double calls); +extern UniquePath *create_unique_path(PlannerInfo *root, RelOptInfo *rel, + Path *subpath, SpecialJoinInfo *sjinfo); +extern GatherPath *create_gather_path(PlannerInfo *root, + RelOptInfo *rel, Path *subpath, PathTarget *target, + Relids required_outer, double *rows); +extern GatherMergePath *create_gather_merge_path(PlannerInfo *root, + RelOptInfo *rel, + Path *subpath, + PathTarget *target, + List *pathkeys, + Relids required_outer, + double *rows); +extern SubqueryScanPath *create_subqueryscan_path(PlannerInfo *root, + RelOptInfo *rel, Path *subpath, + List *pathkeys, Relids required_outer); +extern Path *create_functionscan_path(PlannerInfo *root, RelOptInfo *rel, + List *pathkeys, Relids required_outer); +extern Path *create_valuesscan_path(PlannerInfo *root, RelOptInfo *rel, + Relids required_outer); +extern Path *create_tablefuncscan_path(PlannerInfo *root, RelOptInfo *rel, + Relids required_outer); +extern Path *create_ctescan_path(PlannerInfo *root, RelOptInfo *rel, + Relids required_outer); +extern Path *create_namedtuplestorescan_path(PlannerInfo *root, RelOptInfo *rel, + Relids required_outer); +extern Path *create_resultscan_path(PlannerInfo *root, RelOptInfo *rel, + Relids required_outer); +extern Path *create_worktablescan_path(PlannerInfo *root, RelOptInfo *rel, + Relids required_outer); +extern ForeignPath *create_foreignscan_path(PlannerInfo *root, RelOptInfo *rel, + PathTarget *target, + double rows, Cost startup_cost, Cost total_cost, + List *pathkeys, + Relids required_outer, + Path *fdw_outerpath, + List *fdw_private); +extern ForeignPath *create_foreign_join_path(PlannerInfo *root, RelOptInfo *rel, + PathTarget *target, + double rows, Cost startup_cost, Cost total_cost, + List *pathkeys, + Relids required_outer, + Path *fdw_outerpath, + List *fdw_private); +extern ForeignPath *create_foreign_upper_path(PlannerInfo *root, RelOptInfo *rel, + PathTarget *target, + double rows, Cost startup_cost, Cost total_cost, + List *pathkeys, + Path *fdw_outerpath, + List *fdw_private); + +extern Relids calc_nestloop_required_outer(Relids outerrelids, + Relids outer_paramrels, + Relids innerrelids, + Relids inner_paramrels); +extern Relids calc_non_nestloop_required_outer(Path *outer_path, Path *inner_path); + +extern NestPath *create_nestloop_path(PlannerInfo *root, + RelOptInfo *joinrel, + JoinType jointype, + JoinCostWorkspace *workspace, + JoinPathExtraData *extra, + Path *outer_path, + Path *inner_path, + List *restrict_clauses, + List *pathkeys, + Relids required_outer); + +extern MergePath *create_mergejoin_path(PlannerInfo *root, + RelOptInfo *joinrel, + JoinType jointype, + JoinCostWorkspace *workspace, + JoinPathExtraData *extra, + Path *outer_path, + Path *inner_path, + List *restrict_clauses, + List *pathkeys, + Relids required_outer, + List *mergeclauses, + List *outersortkeys, + List *innersortkeys); + +extern HashPath *create_hashjoin_path(PlannerInfo *root, + RelOptInfo *joinrel, + JoinType jointype, + JoinCostWorkspace *workspace, + JoinPathExtraData *extra, + Path *outer_path, + Path *inner_path, + bool parallel_hash, + List *restrict_clauses, + Relids required_outer, + List *hashclauses); + +extern ProjectionPath *create_projection_path(PlannerInfo *root, + RelOptInfo *rel, + Path *subpath, + PathTarget *target); +extern Path *apply_projection_to_path(PlannerInfo *root, + RelOptInfo *rel, + Path *path, + PathTarget *target); +extern ProjectSetPath *create_set_projection_path(PlannerInfo *root, + RelOptInfo *rel, + Path *subpath, + PathTarget *target); +extern SortPath *create_sort_path(PlannerInfo *root, + RelOptInfo *rel, + Path *subpath, + List *pathkeys, + double limit_tuples); +extern IncrementalSortPath *create_incremental_sort_path(PlannerInfo *root, + RelOptInfo *rel, + Path *subpath, + List *pathkeys, + int presorted_keys, + double limit_tuples); +extern GroupPath *create_group_path(PlannerInfo *root, + RelOptInfo *rel, + Path *subpath, + List *groupClause, + List *qual, + double numGroups); +extern UpperUniquePath *create_upper_unique_path(PlannerInfo *root, + RelOptInfo *rel, + Path *subpath, + int numCols, + double numGroups); +extern AggPath *create_agg_path(PlannerInfo *root, + RelOptInfo *rel, + Path *subpath, + PathTarget *target, + AggStrategy aggstrategy, + AggSplit aggsplit, + List *groupClause, + List *qual, + const AggClauseCosts *aggcosts, + double numGroups); +extern GroupingSetsPath *create_groupingsets_path(PlannerInfo *root, + RelOptInfo *rel, + Path *subpath, + List *having_qual, + AggStrategy aggstrategy, + List *rollups, + const AggClauseCosts *agg_costs, + double numGroups); +extern MinMaxAggPath *create_minmaxagg_path(PlannerInfo *root, + RelOptInfo *rel, + PathTarget *target, + List *mmaggregates, + List *quals); +extern WindowAggPath *create_windowagg_path(PlannerInfo *root, + RelOptInfo *rel, + Path *subpath, + PathTarget *target, + List *windowFuncs, + WindowClause *winclause); +extern SetOpPath *create_setop_path(PlannerInfo *root, + RelOptInfo *rel, + Path *subpath, + SetOpCmd cmd, + SetOpStrategy strategy, + List *distinctList, + AttrNumber flagColIdx, + int firstFlag, + double numGroups, + double outputRows); +extern RecursiveUnionPath *create_recursiveunion_path(PlannerInfo *root, + RelOptInfo *rel, + Path *leftpath, + Path *rightpath, + PathTarget *target, + List *distinctList, + int wtParam, + double numGroups); +extern LockRowsPath *create_lockrows_path(PlannerInfo *root, RelOptInfo *rel, + Path *subpath, List *rowMarks, int epqParam); +extern ModifyTablePath *create_modifytable_path(PlannerInfo *root, + RelOptInfo *rel, + Path *subpath, + CmdType operation, bool canSetTag, + Index nominalRelation, Index rootRelation, + bool partColsUpdated, + List *resultRelations, + List *updateColnosLists, + List *withCheckOptionLists, List *returningLists, + List *rowMarks, OnConflictExpr *onconflict, + int epqParam); +extern LimitPath *create_limit_path(PlannerInfo *root, RelOptInfo *rel, + Path *subpath, + Node *limitOffset, Node *limitCount, + LimitOption limitOption, + int64 offset_est, int64 count_est); +extern void adjust_limit_rows_costs(double *rows, + Cost *startup_cost, Cost *total_cost, + int64 offset_est, int64 count_est); + +extern Path *reparameterize_path(PlannerInfo *root, Path *path, + Relids required_outer, + double loop_count); +extern Path *reparameterize_path_by_child(PlannerInfo *root, Path *path, + RelOptInfo *child_rel); + +/* + * prototypes for relnode.c + */ +extern void setup_simple_rel_arrays(PlannerInfo *root); +extern void expand_planner_arrays(PlannerInfo *root, int add_size); +extern RelOptInfo *build_simple_rel(PlannerInfo *root, int relid, + RelOptInfo *parent); +extern RelOptInfo *find_base_rel(PlannerInfo *root, int relid); +extern RelOptInfo *find_join_rel(PlannerInfo *root, Relids relids); +extern RelOptInfo *build_join_rel(PlannerInfo *root, + Relids joinrelids, + RelOptInfo *outer_rel, + RelOptInfo *inner_rel, + SpecialJoinInfo *sjinfo, + List **restrictlist_ptr); +extern Relids min_join_parameterization(PlannerInfo *root, + Relids joinrelids, + RelOptInfo *outer_rel, + RelOptInfo *inner_rel); +extern RelOptInfo *fetch_upper_rel(PlannerInfo *root, UpperRelationKind kind, + Relids relids); +extern Relids find_childrel_parents(PlannerInfo *root, RelOptInfo *rel); +extern ParamPathInfo *get_baserel_parampathinfo(PlannerInfo *root, + RelOptInfo *baserel, + Relids required_outer); +extern ParamPathInfo *get_joinrel_parampathinfo(PlannerInfo *root, + RelOptInfo *joinrel, + Path *outer_path, + Path *inner_path, + SpecialJoinInfo *sjinfo, + Relids required_outer, + List **restrict_clauses); +extern ParamPathInfo *get_appendrel_parampathinfo(RelOptInfo *appendrel, + Relids required_outer); +extern ParamPathInfo *find_param_path_info(RelOptInfo *rel, + Relids required_outer); +extern RelOptInfo *build_child_join_rel(PlannerInfo *root, + RelOptInfo *outer_rel, RelOptInfo *inner_rel, + RelOptInfo *parent_joinrel, List *restrictlist, + SpecialJoinInfo *sjinfo, JoinType jointype); + +#endif /* PATHNODE_H */ diff --git a/src/include/optimizer/paths.h b/src/include/optimizer/paths.h new file mode 100644 index 0000000..f1d1110 --- /dev/null +++ b/src/include/optimizer/paths.h @@ -0,0 +1,258 @@ +/*------------------------------------------------------------------------- + * + * paths.h + * prototypes for various files in optimizer/path + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/paths.h + * + *------------------------------------------------------------------------- + */ +#ifndef PATHS_H +#define PATHS_H + +#include "nodes/pathnodes.h" + + +/* + * allpaths.c + */ +extern PGDLLIMPORT bool enable_geqo; +extern PGDLLIMPORT int geqo_threshold; +extern PGDLLIMPORT int min_parallel_table_scan_size; +extern PGDLLIMPORT int min_parallel_index_scan_size; + +/* Hook for plugins to get control in set_rel_pathlist() */ +typedef void (*set_rel_pathlist_hook_type) (PlannerInfo *root, + RelOptInfo *rel, + Index rti, + RangeTblEntry *rte); +extern PGDLLIMPORT set_rel_pathlist_hook_type set_rel_pathlist_hook; + +/* Hook for plugins to get control in add_paths_to_joinrel() */ +typedef void (*set_join_pathlist_hook_type) (PlannerInfo *root, + RelOptInfo *joinrel, + RelOptInfo *outerrel, + RelOptInfo *innerrel, + JoinType jointype, + JoinPathExtraData *extra); +extern PGDLLIMPORT set_join_pathlist_hook_type set_join_pathlist_hook; + +/* Hook for plugins to replace standard_join_search() */ +typedef RelOptInfo *(*join_search_hook_type) (PlannerInfo *root, + int levels_needed, + List *initial_rels); +extern PGDLLIMPORT join_search_hook_type join_search_hook; + + +extern RelOptInfo *make_one_rel(PlannerInfo *root, List *joinlist); +extern RelOptInfo *standard_join_search(PlannerInfo *root, int levels_needed, + List *initial_rels); + +extern void generate_gather_paths(PlannerInfo *root, RelOptInfo *rel, + bool override_rows); +extern void generate_useful_gather_paths(PlannerInfo *root, RelOptInfo *rel, + bool override_rows); +extern int compute_parallel_worker(RelOptInfo *rel, double heap_pages, + double index_pages, int max_workers); +extern void create_partial_bitmap_paths(PlannerInfo *root, RelOptInfo *rel, + Path *bitmapqual); +extern void generate_partitionwise_join_paths(PlannerInfo *root, + RelOptInfo *rel); + +#ifdef OPTIMIZER_DEBUG +extern void debug_print_rel(PlannerInfo *root, RelOptInfo *rel); +#endif + +/* + * indxpath.c + * routines to generate index paths + */ +extern void create_index_paths(PlannerInfo *root, RelOptInfo *rel); +extern bool relation_has_unique_index_for(PlannerInfo *root, RelOptInfo *rel, + List *restrictlist, + List *exprlist, List *oprlist); +extern bool indexcol_is_bool_constant_for_query(PlannerInfo *root, + IndexOptInfo *index, + int indexcol); +extern bool match_index_to_operand(Node *operand, int indexcol, + IndexOptInfo *index); +extern void check_index_predicates(PlannerInfo *root, RelOptInfo *rel); + +/* + * tidpath.h + * routines to generate tid paths + */ +extern void create_tidscan_paths(PlannerInfo *root, RelOptInfo *rel); + +/* + * joinpath.c + * routines to create join paths + */ +extern void add_paths_to_joinrel(PlannerInfo *root, RelOptInfo *joinrel, + RelOptInfo *outerrel, RelOptInfo *innerrel, + JoinType jointype, SpecialJoinInfo *sjinfo, + List *restrictlist); + +/* + * joinrels.c + * routines to determine which relations to join + */ +extern void join_search_one_level(PlannerInfo *root, int level); +extern RelOptInfo *make_join_rel(PlannerInfo *root, + RelOptInfo *rel1, RelOptInfo *rel2); +extern bool have_join_order_restriction(PlannerInfo *root, + RelOptInfo *rel1, RelOptInfo *rel2); +extern bool have_dangerous_phv(PlannerInfo *root, + Relids outer_relids, Relids inner_params); +extern void mark_dummy_rel(RelOptInfo *rel); + +/* + * equivclass.c + * routines for managing EquivalenceClasses + */ +typedef bool (*ec_matches_callback_type) (PlannerInfo *root, + RelOptInfo *rel, + EquivalenceClass *ec, + EquivalenceMember *em, + void *arg); + +extern bool process_equivalence(PlannerInfo *root, + RestrictInfo **p_restrictinfo, + bool below_outer_join); +extern Expr *canonicalize_ec_expression(Expr *expr, + Oid req_type, Oid req_collation); +extern void reconsider_outer_join_clauses(PlannerInfo *root); +extern 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); +extern EquivalenceMember *find_ec_member_matching_expr(EquivalenceClass *ec, + Expr *expr, + Relids relids); +extern EquivalenceMember *find_computable_ec_member(PlannerInfo *root, + EquivalenceClass *ec, + List *exprs, + Relids relids, + bool require_parallel_safe); +extern Expr *find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel); +extern bool relation_can_be_sorted_early(PlannerInfo *root, RelOptInfo *rel, + EquivalenceClass *ec, + bool require_parallel_safe); +extern void generate_base_implied_equalities(PlannerInfo *root); +extern List *generate_join_implied_equalities(PlannerInfo *root, + Relids join_relids, + Relids outer_relids, + RelOptInfo *inner_rel); +extern List *generate_join_implied_equalities_for_ecs(PlannerInfo *root, + List *eclasses, + Relids join_relids, + Relids outer_relids, + RelOptInfo *inner_rel); +extern bool exprs_known_equal(PlannerInfo *root, Node *item1, Node *item2); +extern EquivalenceClass *match_eclasses_to_foreign_key_col(PlannerInfo *root, + ForeignKeyOptInfo *fkinfo, + int colno); +extern RestrictInfo *find_derived_clause_for_ec_member(EquivalenceClass *ec, + EquivalenceMember *em); +extern void add_child_rel_equivalences(PlannerInfo *root, + AppendRelInfo *appinfo, + RelOptInfo *parent_rel, + RelOptInfo *child_rel); +extern void add_child_join_rel_equivalences(PlannerInfo *root, + int nappinfos, + AppendRelInfo **appinfos, + RelOptInfo *parent_rel, + RelOptInfo *child_rel); +extern List *generate_implied_equalities_for_column(PlannerInfo *root, + RelOptInfo *rel, + ec_matches_callback_type callback, + void *callback_arg, + Relids prohibited_rels); +extern bool have_relevant_eclass_joinclause(PlannerInfo *root, + RelOptInfo *rel1, RelOptInfo *rel2); +extern bool has_relevant_eclass_joinclause(PlannerInfo *root, + RelOptInfo *rel1); +extern bool eclass_useful_for_merging(PlannerInfo *root, + EquivalenceClass *eclass, + RelOptInfo *rel); +extern bool is_redundant_derived_clause(RestrictInfo *rinfo, List *clauselist); +extern bool is_redundant_with_indexclauses(RestrictInfo *rinfo, + List *indexclauses); + +/* + * pathkeys.c + * utilities for matching and building path keys + */ +typedef enum +{ + PATHKEYS_EQUAL, /* pathkeys are identical */ + PATHKEYS_BETTER1, /* pathkey 1 is a superset of pathkey 2 */ + PATHKEYS_BETTER2, /* vice versa */ + PATHKEYS_DIFFERENT /* neither pathkey includes the other */ +} PathKeysComparison; + +extern PathKeysComparison compare_pathkeys(List *keys1, List *keys2); +extern bool pathkeys_contained_in(List *keys1, List *keys2); +extern bool pathkeys_count_contained_in(List *keys1, List *keys2, int *n_common); +extern Path *get_cheapest_path_for_pathkeys(List *paths, List *pathkeys, + Relids required_outer, + CostSelector cost_criterion, + bool require_parallel_safe); +extern Path *get_cheapest_fractional_path_for_pathkeys(List *paths, + List *pathkeys, + Relids required_outer, + double fraction); +extern Path *get_cheapest_parallel_safe_total_inner(List *paths); +extern List *build_index_pathkeys(PlannerInfo *root, IndexOptInfo *index, + ScanDirection scandir); +extern List *build_partition_pathkeys(PlannerInfo *root, RelOptInfo *partrel, + ScanDirection scandir, bool *partialkeys); +extern List *build_expression_pathkey(PlannerInfo *root, Expr *expr, + Relids nullable_relids, Oid opno, + Relids rel, bool create_it); +extern List *convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel, + List *subquery_pathkeys, + List *subquery_tlist); +extern List *build_join_pathkeys(PlannerInfo *root, + RelOptInfo *joinrel, + JoinType jointype, + List *outer_pathkeys); +extern List *make_pathkeys_for_sortclauses(PlannerInfo *root, + List *sortclauses, + List *tlist); +extern void initialize_mergeclause_eclasses(PlannerInfo *root, + RestrictInfo *restrictinfo); +extern void update_mergeclause_eclasses(PlannerInfo *root, + RestrictInfo *restrictinfo); +extern List *find_mergeclauses_for_outer_pathkeys(PlannerInfo *root, + List *pathkeys, + List *restrictinfos); +extern List *select_outer_pathkeys_for_merge(PlannerInfo *root, + List *mergeclauses, + RelOptInfo *joinrel); +extern List *make_inner_pathkeys_for_merge(PlannerInfo *root, + List *mergeclauses, + List *outer_pathkeys); +extern List *trim_mergeclauses_for_inner_pathkeys(PlannerInfo *root, + List *mergeclauses, + List *pathkeys); +extern List *truncate_useless_pathkeys(PlannerInfo *root, + RelOptInfo *rel, + List *pathkeys); +extern bool has_useful_pathkeys(PlannerInfo *root, RelOptInfo *rel); +extern PathKey *make_canonical_pathkey(PlannerInfo *root, + EquivalenceClass *eclass, Oid opfamily, + int strategy, bool nulls_first); +extern void add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel, + List *live_childrels); + +#endif /* PATHS_H */ diff --git a/src/include/optimizer/placeholder.h b/src/include/optimizer/placeholder.h new file mode 100644 index 0000000..69ef5ae --- /dev/null +++ b/src/include/optimizer/placeholder.h @@ -0,0 +1,32 @@ +/*------------------------------------------------------------------------- + * + * placeholder.h + * prototypes for optimizer/util/placeholder.c. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/placeholder.h + * + *------------------------------------------------------------------------- + */ +#ifndef PLACEHOLDER_H +#define PLACEHOLDER_H + +#include "nodes/pathnodes.h" + + +extern PlaceHolderVar *make_placeholder_expr(PlannerInfo *root, Expr *expr, + Relids phrels); +extern PlaceHolderInfo *find_placeholder_info(PlannerInfo *root, + PlaceHolderVar *phv, bool create_new_ph); +extern void find_placeholders_in_jointree(PlannerInfo *root); +extern void update_placeholder_eval_levels(PlannerInfo *root, + SpecialJoinInfo *new_sjinfo); +extern void fix_placeholder_input_needed_levels(PlannerInfo *root); +extern void add_placeholders_to_base_rels(PlannerInfo *root); +extern void add_placeholders_to_joinrel(PlannerInfo *root, RelOptInfo *joinrel, + RelOptInfo *outer_rel, RelOptInfo *inner_rel); + +#endif /* PLACEHOLDER_H */ diff --git a/src/include/optimizer/plancat.h b/src/include/optimizer/plancat.h new file mode 100644 index 0000000..8d1d6c1 --- /dev/null +++ b/src/include/optimizer/plancat.h @@ -0,0 +1,77 @@ +/*------------------------------------------------------------------------- + * + * plancat.h + * prototypes for plancat.c. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/plancat.h + * + *------------------------------------------------------------------------- + */ +#ifndef PLANCAT_H +#define PLANCAT_H + +#include "nodes/pathnodes.h" +#include "utils/relcache.h" + +/* Hook for plugins to get control in get_relation_info() */ +typedef void (*get_relation_info_hook_type) (PlannerInfo *root, + Oid relationObjectId, + bool inhparent, + RelOptInfo *rel); +extern PGDLLIMPORT get_relation_info_hook_type get_relation_info_hook; + + +extern void get_relation_info(PlannerInfo *root, Oid relationObjectId, + bool inhparent, RelOptInfo *rel); + +extern List *infer_arbiter_indexes(PlannerInfo *root); + +extern void estimate_rel_size(Relation rel, int32 *attr_widths, + BlockNumber *pages, double *tuples, double *allvisfrac); + +extern int32 get_rel_data_width(Relation rel, int32 *attr_widths); +extern int32 get_relation_data_width(Oid relid, int32 *attr_widths); + +extern bool relation_excluded_by_constraints(PlannerInfo *root, + RelOptInfo *rel, RangeTblEntry *rte); + +extern List *build_physical_tlist(PlannerInfo *root, RelOptInfo *rel); + +extern bool has_unique_index(RelOptInfo *rel, AttrNumber attno); + +extern Selectivity restriction_selectivity(PlannerInfo *root, + Oid operatorid, + List *args, + Oid inputcollid, + int varRelid); + +extern Selectivity join_selectivity(PlannerInfo *root, + Oid operatorid, + List *args, + Oid inputcollid, + JoinType jointype, + SpecialJoinInfo *sjinfo); + +extern Selectivity function_selectivity(PlannerInfo *root, + Oid funcid, + List *args, + Oid inputcollid, + bool is_join, + int varRelid, + JoinType jointype, + SpecialJoinInfo *sjinfo); + +extern void add_function_cost(PlannerInfo *root, Oid funcid, Node *node, + QualCost *cost); + +extern double get_function_rows(PlannerInfo *root, Oid funcid, Node *node); + +extern bool has_row_triggers(PlannerInfo *root, Index rti, CmdType event); + +extern bool has_stored_generated_columns(PlannerInfo *root, Index rti); + +#endif /* PLANCAT_H */ diff --git a/src/include/optimizer/planmain.h b/src/include/optimizer/planmain.h new file mode 100644 index 0000000..bf1adfc --- /dev/null +++ b/src/include/optimizer/planmain.h @@ -0,0 +1,119 @@ +/*------------------------------------------------------------------------- + * + * planmain.h + * prototypes for various files in optimizer/plan + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/planmain.h + * + *------------------------------------------------------------------------- + */ +#ifndef PLANMAIN_H +#define PLANMAIN_H + +#include "nodes/pathnodes.h" +#include "nodes/plannodes.h" + +/* GUC parameters */ +#define DEFAULT_CURSOR_TUPLE_FRACTION 0.1 +extern double cursor_tuple_fraction; + +/* query_planner callback to compute query_pathkeys */ +typedef void (*query_pathkeys_callback) (PlannerInfo *root, void *extra); + +/* + * prototypes for plan/planmain.c + */ +extern RelOptInfo *query_planner(PlannerInfo *root, + query_pathkeys_callback qp_callback, void *qp_extra); + +/* + * prototypes for plan/planagg.c + */ +extern void preprocess_minmax_aggregates(PlannerInfo *root); + +/* + * prototypes for plan/createplan.c + */ +extern Plan *create_plan(PlannerInfo *root, Path *best_path); +extern ForeignScan *make_foreignscan(List *qptlist, List *qpqual, + Index scanrelid, List *fdw_exprs, List *fdw_private, + List *fdw_scan_tlist, List *fdw_recheck_quals, + Plan *outer_plan); +extern Plan *change_plan_targetlist(Plan *subplan, List *tlist, + bool tlist_parallel_safe); +extern Plan *materialize_finished_plan(Plan *subplan); +extern bool is_projection_capable_path(Path *path); +extern bool is_projection_capable_plan(Plan *plan); + +/* External use of these functions is deprecated: */ +extern Sort *make_sort_from_sortclauses(List *sortcls, Plan *lefttree); +extern Agg *make_agg(List *tlist, List *qual, + AggStrategy aggstrategy, AggSplit aggsplit, + int numGroupCols, AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations, + List *groupingSets, List *chain, double dNumGroups, + Size transitionSpace, Plan *lefttree); +extern Limit *make_limit(Plan *lefttree, Node *limitOffset, Node *limitCount, + LimitOption limitOption, int uniqNumCols, + AttrNumber *uniqColIdx, Oid *uniqOperators, + Oid *uniqCollations); + +/* + * prototypes for plan/initsplan.c + */ +extern int from_collapse_limit; +extern int join_collapse_limit; + +extern void add_base_rels_to_query(PlannerInfo *root, Node *jtnode); +extern void add_other_rels_to_query(PlannerInfo *root); +extern void build_base_rel_tlists(PlannerInfo *root, List *final_tlist); +extern void add_vars_to_targetlist(PlannerInfo *root, List *vars, + Relids where_needed, bool create_new_ph); +extern void find_lateral_references(PlannerInfo *root); +extern void create_lateral_join_info(PlannerInfo *root); +extern List *deconstruct_jointree(PlannerInfo *root); +extern void distribute_restrictinfo_to_rels(PlannerInfo *root, + RestrictInfo *restrictinfo); +extern RestrictInfo *process_implied_equality(PlannerInfo *root, + Oid opno, + Oid collation, + Expr *item1, + Expr *item2, + Relids qualscope, + Relids nullable_relids, + Index security_level, + bool below_outer_join, + bool both_const); +extern RestrictInfo *build_implied_join_equality(PlannerInfo *root, + Oid opno, + Oid collation, + Expr *item1, + Expr *item2, + Relids qualscope, + Relids nullable_relids, + Index security_level); +extern void match_foreign_keys_to_quals(PlannerInfo *root); + +/* + * prototypes for plan/analyzejoins.c + */ +extern List *remove_useless_joins(PlannerInfo *root, List *joinlist); +extern void reduce_unique_semijoins(PlannerInfo *root); +extern bool query_supports_distinctness(Query *query); +extern bool query_is_distinct_for(Query *query, List *colnos, List *opids); +extern bool innerrel_is_unique(PlannerInfo *root, + Relids joinrelids, Relids outerrelids, RelOptInfo *innerrel, + JoinType jointype, List *restrictlist, bool force_cache); + +/* + * prototypes for plan/setrefs.c + */ +extern Plan *set_plan_references(PlannerInfo *root, Plan *plan); +extern void record_plan_function_dependency(PlannerInfo *root, Oid funcid); +extern void record_plan_type_dependency(PlannerInfo *root, Oid typid); +extern bool extract_query_dependencies_walker(Node *node, PlannerInfo *root); + +#endif /* PLANMAIN_H */ diff --git a/src/include/optimizer/planner.h b/src/include/optimizer/planner.h new file mode 100644 index 0000000..9a15de5 --- /dev/null +++ b/src/include/optimizer/planner.h @@ -0,0 +1,61 @@ +/*------------------------------------------------------------------------- + * + * planner.h + * prototypes for planner.c. + * + * Note that the primary entry points for planner.c are declared in + * optimizer/optimizer.h, because they're intended to be called from + * non-planner code. Declarations here are meant for use by other + * planner modules. + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/planner.h + * + *------------------------------------------------------------------------- + */ +#ifndef PLANNER_H +#define PLANNER_H + +#include "nodes/pathnodes.h" +#include "nodes/plannodes.h" + + +/* Hook for plugins to get control in planner() */ +typedef PlannedStmt *(*planner_hook_type) (Query *parse, + const char *query_string, + int cursorOptions, + ParamListInfo boundParams); +extern PGDLLIMPORT planner_hook_type planner_hook; + +/* Hook for plugins to get control when grouping_planner() plans upper rels */ +typedef void (*create_upper_paths_hook_type) (PlannerInfo *root, + UpperRelationKind stage, + RelOptInfo *input_rel, + RelOptInfo *output_rel, + void *extra); +extern PGDLLIMPORT create_upper_paths_hook_type create_upper_paths_hook; + + +extern PlannedStmt *standard_planner(Query *parse, const char *query_string, + int cursorOptions, + ParamListInfo boundParams); + +extern PlannerInfo *subquery_planner(PlannerGlobal *glob, Query *parse, + PlannerInfo *parent_root, + bool hasRecursion, double tuple_fraction); + +extern RowMarkType select_rowmark_type(RangeTblEntry *rte, + LockClauseStrength strength); + +extern bool limit_needed(Query *parse); + +extern void mark_partial_aggref(Aggref *agg, AggSplit aggsplit); + +extern Path *get_cheapest_fractional_path(RelOptInfo *rel, + double tuple_fraction); + +extern Expr *preprocess_phv_expression(PlannerInfo *root, Expr *expr); + +#endif /* PLANNER_H */ diff --git a/src/include/optimizer/prep.h b/src/include/optimizer/prep.h new file mode 100644 index 0000000..bcd2a86 --- /dev/null +++ b/src/include/optimizer/prep.h @@ -0,0 +1,56 @@ +/*------------------------------------------------------------------------- + * + * prep.h + * prototypes for files in optimizer/prep/ + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/prep.h + * + *------------------------------------------------------------------------- + */ +#ifndef PREP_H +#define PREP_H + +#include "nodes/pathnodes.h" +#include "nodes/plannodes.h" + + +/* + * prototypes for prepjointree.c + */ +extern void replace_empty_jointree(Query *parse); +extern void pull_up_sublinks(PlannerInfo *root); +extern void preprocess_function_rtes(PlannerInfo *root); +extern void pull_up_subqueries(PlannerInfo *root); +extern void flatten_simple_union_all(PlannerInfo *root); +extern void reduce_outer_joins(PlannerInfo *root); +extern void remove_useless_result_rtes(PlannerInfo *root); +extern Relids get_relids_in_jointree(Node *jtnode, bool include_joins); +extern Relids get_relids_for_join(Query *query, int joinrelid); + +/* + * prototypes for preptlist.c + */ +extern void preprocess_targetlist(PlannerInfo *root); + +extern List *extract_update_targetlist_colnos(List *tlist); + +extern PlanRowMark *get_plan_rowmark(List *rowmarks, Index rtindex); + +/* + * prototypes for prepagg.c + */ +extern void get_agg_clause_costs(PlannerInfo *root, AggSplit aggsplit, + AggClauseCosts *agg_costs); +extern void preprocess_aggrefs(PlannerInfo *root, Node *clause); + +/* + * prototypes for prepunion.c + */ +extern RelOptInfo *plan_set_operations(PlannerInfo *root); + + +#endif /* PREP_H */ diff --git a/src/include/optimizer/restrictinfo.h b/src/include/optimizer/restrictinfo.h new file mode 100644 index 0000000..0165ffd --- /dev/null +++ b/src/include/optimizer/restrictinfo.h @@ -0,0 +1,49 @@ +/*------------------------------------------------------------------------- + * + * restrictinfo.h + * prototypes for restrictinfo.c. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/restrictinfo.h + * + *------------------------------------------------------------------------- + */ +#ifndef RESTRICTINFO_H +#define RESTRICTINFO_H + +#include "nodes/pathnodes.h" + + +/* Convenience macro for the common case of a valid-everywhere qual */ +#define make_simple_restrictinfo(root, clause) \ + make_restrictinfo(root, clause, true, false, false, 0, NULL, NULL, NULL) + +extern RestrictInfo *make_restrictinfo(PlannerInfo *root, + Expr *clause, + bool is_pushed_down, + bool outerjoin_delayed, + bool pseudoconstant, + Index security_level, + Relids required_relids, + Relids outer_relids, + Relids nullable_relids); +extern RestrictInfo *commute_restrictinfo(RestrictInfo *rinfo, Oid comm_op); +extern bool restriction_is_or_clause(RestrictInfo *restrictinfo); +extern bool restriction_is_securely_promotable(RestrictInfo *restrictinfo, + RelOptInfo *rel); +extern List *get_actual_clauses(List *restrictinfo_list); +extern List *extract_actual_clauses(List *restrictinfo_list, + bool pseudoconstant); +extern void extract_actual_join_clauses(List *restrictinfo_list, + Relids joinrelids, + List **joinquals, + List **otherquals); +extern bool join_clause_is_movable_to(RestrictInfo *rinfo, RelOptInfo *baserel); +extern bool join_clause_is_movable_into(RestrictInfo *rinfo, + Relids currentrelids, + Relids current_and_outer); + +#endif /* RESTRICTINFO_H */ diff --git a/src/include/optimizer/subselect.h b/src/include/optimizer/subselect.h new file mode 100644 index 0000000..059bdf9 --- /dev/null +++ b/src/include/optimizer/subselect.h @@ -0,0 +1,40 @@ +/*------------------------------------------------------------------------- + * + * subselect.h + * Planning routines for subselects. + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/subselect.h + * + *------------------------------------------------------------------------- + */ +#ifndef SUBSELECT_H +#define SUBSELECT_H + +#include "nodes/pathnodes.h" +#include "nodes/plannodes.h" + +extern void SS_process_ctes(PlannerInfo *root); +extern JoinExpr *convert_ANY_sublink_to_join(PlannerInfo *root, + SubLink *sublink, + Relids available_rels); +extern JoinExpr *convert_EXISTS_sublink_to_join(PlannerInfo *root, + SubLink *sublink, + bool under_not, + Relids available_rels); +extern Node *SS_replace_correlation_vars(PlannerInfo *root, Node *expr); +extern Node *SS_process_sublinks(PlannerInfo *root, Node *expr, bool isQual); +extern void SS_identify_outer_params(PlannerInfo *root); +extern void SS_charge_for_initplans(PlannerInfo *root, RelOptInfo *final_rel); +extern void SS_attach_initplans(PlannerInfo *root, Plan *plan); +extern void SS_finalize_plan(PlannerInfo *root, Plan *plan); +extern Param *SS_make_initplan_output_param(PlannerInfo *root, + Oid resulttype, int32 resulttypmod, + Oid resultcollation); +extern void SS_make_initplan_from_plan(PlannerInfo *root, + PlannerInfo *subroot, Plan *plan, + Param *prm); + +#endif /* SUBSELECT_H */ diff --git a/src/include/optimizer/tlist.h b/src/include/optimizer/tlist.h new file mode 100644 index 0000000..d62a096 --- /dev/null +++ b/src/include/optimizer/tlist.h @@ -0,0 +1,56 @@ +/*------------------------------------------------------------------------- + * + * tlist.h + * prototypes for tlist.c. + * + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * src/include/optimizer/tlist.h + * + *------------------------------------------------------------------------- + */ +#ifndef TLIST_H +#define TLIST_H + +#include "nodes/pathnodes.h" + + +extern TargetEntry *tlist_member(Expr *node, List *targetlist); + +extern List *add_to_flat_tlist(List *tlist, List *exprs); + +extern List *get_tlist_exprs(List *tlist, bool includeJunk); + +extern bool tlist_same_exprs(List *tlist1, List *tlist2); + +extern bool tlist_same_datatypes(List *tlist, List *colTypes, bool junkOK); +extern bool tlist_same_collations(List *tlist, List *colCollations, bool junkOK); + +extern void apply_tlist_labeling(List *dest_tlist, List *src_tlist); + +extern Oid *extract_grouping_ops(List *groupClause); +extern Oid *extract_grouping_collations(List *groupClause, List *tlist); +extern AttrNumber *extract_grouping_cols(List *groupClause, List *tlist); +extern bool grouping_is_sortable(List *groupClause); +extern bool grouping_is_hashable(List *groupClause); + +extern PathTarget *make_pathtarget_from_tlist(List *tlist); +extern List *make_tlist_from_pathtarget(PathTarget *target); +extern PathTarget *copy_pathtarget(PathTarget *src); +extern PathTarget *create_empty_pathtarget(void); +extern void add_column_to_pathtarget(PathTarget *target, + Expr *expr, Index sortgroupref); +extern void add_new_column_to_pathtarget(PathTarget *target, Expr *expr); +extern void add_new_columns_to_pathtarget(PathTarget *target, List *exprs); +extern void apply_pathtarget_labeling_to_tlist(List *tlist, PathTarget *target); +extern void split_pathtarget_at_srfs(PlannerInfo *root, + PathTarget *target, PathTarget *input_target, + List **targets, List **targets_contain_srfs); + +/* Convenience macro to get a PathTarget with valid cost/width fields */ +#define create_pathtarget(root, tlist) \ + set_pathtarget_cost_width(root, make_pathtarget_from_tlist(tlist)) + +#endif /* TLIST_H */ |