PostgreSQL Source Code
git master
|
#include "postgres.h"
#include "catalog/pg_class.h"
#include "catalog/pg_type.h"
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "optimizer/clauses.h"
#include "optimizer/cost.h"
#include "optimizer/inherit.h"
#include "optimizer/joininfo.h"
#include "optimizer/optimizer.h"
#include "optimizer/pathnode.h"
#include "optimizer/paths.h"
#include "optimizer/placeholder.h"
#include "optimizer/planmain.h"
#include "optimizer/planner.h"
#include "optimizer/prep.h"
#include "optimizer/restrictinfo.h"
#include "parser/analyze.h"
#include "rewrite/rewriteManip.h"
#include "utils/lsyscache.h"
#include "utils/typcache.h"
Go to the source code of this file.
Data Structures | |
struct | PostponedQual |
Typedefs | |
typedef struct PostponedQual | PostponedQual |
Functions | |
static void | extract_lateral_references (PlannerInfo *root, RelOptInfo *brel, Index rtindex) |
static List * | deconstruct_recurse (PlannerInfo *root, Node *jtnode, bool below_outer_join, Relids *qualscope, Relids *inner_join_rels, List **postponed_qual_list) |
static void | process_security_barrier_quals (PlannerInfo *root, int rti, Relids qualscope, bool below_outer_join) |
static SpecialJoinInfo * | make_outerjoininfo (PlannerInfo *root, Relids left_rels, Relids right_rels, Relids inner_join_rels, JoinType jointype, List *clause) |
static void | compute_semijoin_info (PlannerInfo *root, SpecialJoinInfo *sjinfo, List *clause) |
static void | distribute_qual_to_rels (PlannerInfo *root, Node *clause, bool below_outer_join, JoinType jointype, Index security_level, Relids qualscope, Relids ojscope, Relids outerjoin_nonnullable, List **postponed_qual_list) |
static bool | check_outerjoin_delay (PlannerInfo *root, Relids *relids_p, Relids *nullable_relids_p, bool is_pushed_down) |
static bool | check_equivalence_delay (PlannerInfo *root, RestrictInfo *restrictinfo) |
static bool | check_redundant_nullability_qual (PlannerInfo *root, Node *clause) |
static void | check_mergejoinable (RestrictInfo *restrictinfo) |
static void | check_hashjoinable (RestrictInfo *restrictinfo) |
static void | check_memoizable (RestrictInfo *restrictinfo) |
void | add_base_rels_to_query (PlannerInfo *root, Node *jtnode) |
void | add_other_rels_to_query (PlannerInfo *root) |
void | build_base_rel_tlists (PlannerInfo *root, List *final_tlist) |
void | add_vars_to_targetlist (PlannerInfo *root, List *vars, Relids where_needed, bool create_new_ph) |
void | find_lateral_references (PlannerInfo *root) |
void | create_lateral_join_info (PlannerInfo *root) |
List * | deconstruct_jointree (PlannerInfo *root) |
void | distribute_restrictinfo_to_rels (PlannerInfo *root, RestrictInfo *restrictinfo) |
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) |
RestrictInfo * | build_implied_join_equality (PlannerInfo *root, Oid opno, Oid collation, Expr *item1, Expr *item2, Relids qualscope, Relids nullable_relids, Index security_level) |
void | match_foreign_keys_to_quals (PlannerInfo *root) |
Variables | |
int | from_collapse_limit |
int | join_collapse_limit |
typedef struct PostponedQual PostponedQual |
void add_base_rels_to_query | ( | PlannerInfo * | root, |
Node * | jtnode | ||
) |
Definition at line 106 of file initsplan.c.
References build_simple_rel(), elog, ERROR, FromExpr::fromlist, IsA, j, lfirst, and nodeTag.
Referenced by query_planner().
void add_other_rels_to_query | ( | PlannerInfo * | root | ) |
Definition at line 144 of file initsplan.c.
References expand_inherited_rtentry(), RangeTblEntry::inh, RELOPT_BASEREL, RelOptInfo::reloptkind, PlannerInfo::simple_rel_array, PlannerInfo::simple_rel_array_size, and PlannerInfo::simple_rte_array.
Referenced by query_planner().
void add_vars_to_targetlist | ( | PlannerInfo * | root, |
List * | vars, | ||
Relids | where_needed, | ||
bool | create_new_ph | ||
) |
Definition at line 230 of file initsplan.c.
References Assert(), RelOptInfo::attr_needed, bms_add_members(), bms_is_empty(), bms_is_subset(), copyObject, elog, ERROR, PathTarget::exprs, find_base_rel(), find_placeholder_info(), IsA, lappend(), lfirst, RelOptInfo::min_attr, nodeTag, PlaceHolderInfo::ph_needed, RelOptInfo::relids, RelOptInfo::reltarget, Var::varattno, and Var::varno.
Referenced by build_base_rel_tlists(), distribute_qual_to_rels(), expand_inherited_rtentry(), extract_lateral_references(), fix_placeholder_input_needed_levels(), generate_base_implied_equalities_no_const(), and process_implied_equality().
void build_base_rel_tlists | ( | PlannerInfo * | root, |
List * | final_tlist | ||
) |
Definition at line 183 of file initsplan.c.
References add_vars_to_targetlist(), bms_make_singleton(), Query::havingQual, list_free(), NIL, PlannerInfo::parse, pull_var_clause(), PVC_INCLUDE_PLACEHOLDERS, PVC_RECURSE_AGGREGATES, and PVC_RECURSE_WINDOWFUNCS.
Referenced by query_planner().
RestrictInfo* build_implied_join_equality | ( | PlannerInfo * | root, |
Oid | opno, | ||
Oid | collation, | ||
Expr * | item1, | ||
Expr * | item2, | ||
Relids | qualscope, | ||
Relids | nullable_relids, | ||
Index | security_level | ||
) |
Definition at line 2422 of file initsplan.c.
References check_hashjoinable(), check_memoizable(), check_mergejoinable(), copyObject, InvalidOid, make_opclause(), and make_restrictinfo().
Referenced by create_join_clause(), reconsider_full_join_clause(), and reconsider_outer_join_clause().
|
static |
Definition at line 2104 of file initsplan.c.
References bms_copy(), check_outerjoin_delay(), PlannerInfo::join_info_list, RestrictInfo::left_relids, NIL, and RestrictInfo::right_relids.
Referenced by distribute_qual_to_rels().
|
static |
Definition at line 2690 of file initsplan.c.
References generate_unaccent_rules::args, RestrictInfo::clause, contain_volatile_functions(), exprType(), RestrictInfo::hashjoinoperator, is_opclause(), linitial, list_length(), op_hashjoinable(), and RestrictInfo::pseudoconstant.
Referenced by build_implied_join_equality(), and distribute_restrictinfo_to_rels().
|
static |
Definition at line 2718 of file initsplan.c.
References generate_unaccent_rules::args, RestrictInfo::clause, TypeCacheEntry::eq_opr, exprType(), TypeCacheEntry::hash_proc, is_opclause(), RestrictInfo::left_hasheqoperator, linitial, list_length(), lookup_type_cache(), lsecond, OidIsValid, RestrictInfo::pseudoconstant, RestrictInfo::right_hasheqoperator, TYPECACHE_EQ_OPR, and TYPECACHE_HASH_PROC.
Referenced by build_implied_join_equality(), and distribute_restrictinfo_to_rels().
|
static |
Definition at line 2653 of file initsplan.c.
References generate_unaccent_rules::args, RestrictInfo::clause, contain_volatile_functions(), exprType(), get_mergejoin_opfamilies(), is_opclause(), linitial, list_length(), RestrictInfo::mergeopfamilies, op_mergejoinable(), and RestrictInfo::pseudoconstant.
Referenced by build_implied_join_equality(), distribute_qual_to_rels(), and process_implied_equality().
|
static |
Definition at line 2020 of file initsplan.c.
References bms_add_members(), bms_copy(), bms_free(), bms_int_members(), bms_is_subset(), bms_overlap(), SpecialJoinInfo::delay_upper_joins, JOIN_FULL, PlannerInfo::join_info_list, SpecialJoinInfo::jointype, lfirst, SpecialJoinInfo::min_lefthand, SpecialJoinInfo::min_righthand, and NIL.
Referenced by check_equivalence_delay(), and distribute_qual_to_rels().
|
static |
Definition at line 2139 of file initsplan.c.
References bms_is_member(), find_forced_null_var(), JOIN_ANTI, PlannerInfo::join_info_list, SpecialJoinInfo::jointype, lfirst, SpecialJoinInfo::syn_righthand, and Var::varno.
Referenced by distribute_qual_to_rels().
|
static |
Definition at line 1396 of file initsplan.c.
References OpExpr::args, bms_is_empty(), bms_is_subset(), bms_overlap(), bms_union(), contain_volatile_functions(), copyObject, enable_hashagg, exprType(), get_commutator(), get_mergejoin_opfamilies(), IsA, JOIN_SEMI, SpecialJoinInfo::jointype, lappend(), lappend_oid(), lfirst, linitial, list_length(), lsecond, NIL, OidIsValid, op_hashjoinable(), op_mergejoinable(), OpExpr::opno, pull_varnos(), SpecialJoinInfo::semi_can_btree, SpecialJoinInfo::semi_can_hash, SpecialJoinInfo::semi_operators, SpecialJoinInfo::semi_rhs_exprs, and SpecialJoinInfo::syn_righthand.
Referenced by make_outerjoininfo().
void create_lateral_join_info | ( | PlannerInfo * | root | ) |
Definition at line 450 of file initsplan.c.
References Assert(), bms_add_member(), bms_add_members(), bms_copy(), bms_get_singleton_member(), bms_is_empty(), bms_is_member(), bms_next_member(), RelOptInfo::direct_lateral_relids, find_base_rel(), find_placeholder_info(), PlannerInfo::hasLateralRTEs, IsA, RelOptInfo::lateral_referencers, RelOptInfo::lateral_relids, RelOptInfo::lateral_vars, lfirst, PlaceHolderInfo::ph_eval_at, PlaceHolderInfo::ph_lateral, PlannerInfo::placeholder_list, RelOptInfo::relid, RELOPT_BASEREL, RelOptInfo::reloptkind, PlannerInfo::simple_rel_array, PlannerInfo::simple_rel_array_size, and Var::varno.
Referenced by query_planner().
List* deconstruct_jointree | ( | PlannerInfo * | root | ) |
Definition at line 687 of file initsplan.c.
References Assert(), deconstruct_recurse(), IsA, Query::jointree, NIL, PlannerInfo::nullable_baserels, and PlannerInfo::parse.
Referenced by query_planner().
|
static |
Definition at line 733 of file initsplan.c.
References Assert(), bms_add_members(), bms_is_subset(), bms_make_singleton(), bms_union(), distribute_qual_to_rels(), elog, ERROR, from_collapse_limit, FromExpr::fromlist, IsA, j, JOIN_ANTI, join_collapse_limit, JOIN_FULL, PlannerInfo::join_info_list, JOIN_INNER, JOIN_LEFT, JOIN_SEMI, lappend(), lfirst, linitial, list_concat(), list_length(), list_make1, list_make2, make_outerjoininfo(), SpecialJoinInfo::min_lefthand, SpecialJoinInfo::min_righthand, NIL, nodeTag, PlannerInfo::nullable_baserels, process_security_barrier_quals(), PostponedQual::qual, PlannerInfo::qual_security_level, FromExpr::quals, PostponedQual::relids, remaining, and update_placeholder_eval_levels().
Referenced by deconstruct_jointree().
|
static |
Definition at line 1606 of file initsplan.c.
References add_vars_to_targetlist(), Assert(), bms_copy(), bms_is_empty(), bms_is_subset(), bms_membership(), BMS_MULTIPLE, bms_overlap(), RestrictInfo::can_join, check_equivalence_delay(), check_mergejoinable(), check_outerjoin_delay(), check_redundant_nullability_qual(), contain_volatile_functions(), distribute_restrictinfo_to_rels(), elog, ERROR, PlannerInfo::full_join_clauses, get_relids_in_jointree(), PlannerInfo::hasLateralRTEs, PlannerInfo::hasPseudoConstantQuals, initialize_mergeclause_eclasses(), JOIN_FULL, JOIN_INNER, Query::jointree, lappend(), PlannerInfo::left_join_clauses, RestrictInfo::left_relids, list_free(), make_restrictinfo(), RestrictInfo::mergeopfamilies, palloc(), PlannerInfo::parse, process_equivalence(), pull_var_clause(), pull_varnos(), PVC_INCLUDE_PLACEHOLDERS, PVC_RECURSE_AGGREGATES, PVC_RECURSE_WINDOWFUNCS, PostponedQual::qual, PostponedQual::relids, PlannerInfo::right_join_clauses, and RestrictInfo::right_relids.
Referenced by deconstruct_recurse(), and process_security_barrier_quals().
void distribute_restrictinfo_to_rels | ( | PlannerInfo * | root, |
RestrictInfo * | restrictinfo | ||
) |
Definition at line 2177 of file initsplan.c.
References add_join_clause_to_rels(), RelOptInfo::baserestrict_min_security, RelOptInfo::baserestrictinfo, bms_membership(), BMS_MULTIPLE, BMS_SINGLETON, bms_singleton_member(), check_hashjoinable(), check_memoizable(), elog, ERROR, find_base_rel(), lappend(), Min, RestrictInfo::required_relids, and RestrictInfo::security_level.
Referenced by distribute_qual_to_rels(), generate_base_implied_equalities_broken(), generate_base_implied_equalities_const(), process_implied_equality(), reconsider_outer_join_clauses(), and remove_rel_from_query().
|
static |
Definition at line 352 of file initsplan.c.
References add_vars_to_targetlist(), Assert(), bms_make_singleton(), copyObject, RangeTblEntry::functions, IncrementVarSublevelsUp(), IsA, lappend(), RangeTblEntry::lateral, RelOptInfo::lateral_vars, lfirst, list_free(), NIL, PlaceHolderVar::phexpr, PlaceHolderVar::phlevelsup, preprocess_phv_expression(), pull_vars_of_level(), RTE_FUNCTION, RTE_RELATION, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, RangeTblEntry::rtekind, PlannerInfo::simple_rte_array, RangeTblEntry::subquery, RangeTblEntry::tablefunc, RangeTblEntry::tablesample, RangeTblEntry::values_lists, and Var::varlevelsup.
Referenced by find_lateral_references().
void find_lateral_references | ( | PlannerInfo * | root | ) |
Definition at line 304 of file initsplan.c.
References Assert(), extract_lateral_references(), PlannerInfo::hasLateralRTEs, RelOptInfo::relid, RELOPT_BASEREL, RelOptInfo::reloptkind, PlannerInfo::simple_rel_array, and PlannerInfo::simple_rel_array_size.
Referenced by query_planner().
|
static |
Definition at line 1148 of file initsplan.c.
References Assert(), bms_add_members(), bms_copy(), bms_int_members(), bms_intersect(), bms_is_empty(), bms_is_member(), bms_is_subset(), bms_overlap(), bms_union(), compute_semijoin_info(), SpecialJoinInfo::delay_upper_joins, ereport, errcode(), errmsg(), ERROR, find_nonnullable_rels(), JOIN_ANTI, JOIN_FULL, PlannerInfo::join_info_list, JOIN_INNER, JOIN_RIGHT, JOIN_SEMI, SpecialJoinInfo::jointype, LCS_asString(), lfirst, SpecialJoinInfo::lhs_strict, makeNode, SpecialJoinInfo::min_lefthand, SpecialJoinInfo::min_righthand, PlannerInfo::parse, PlaceHolderInfo::ph_eval_at, PlaceHolderInfo::ph_var, PlaceHolderVar::phrels, PlannerInfo::placeholder_list, pull_varnos(), Query::rowMarks, RowMarkClause::rti, RowMarkClause::strength, SpecialJoinInfo::syn_lefthand, and SpecialJoinInfo::syn_righthand.
Referenced by deconstruct_recurse().
void match_foreign_keys_to_quals | ( | PlannerInfo * | root | ) |
Definition at line 2483 of file initsplan.c.
References OpExpr::args, RestrictInfo::clause, ForeignKeyOptInfo::con_relid, ForeignKeyOptInfo::confkey, ForeignKeyOptInfo::conkey, ForeignKeyOptInfo::conpfeqop, EquivalenceClass::ec_has_const, PlannerInfo::fkey_list, get_commutator(), get_leftop(), get_rightop(), if(), InvalidOid, IsA, RelOptInfo::joininfo, lappend(), lfirst, list_length(), match_eclasses_to_foreign_key_col(), ForeignKeyOptInfo::nconst_ec, NIL, ForeignKeyOptInfo::nkeys, ForeignKeyOptInfo::nmatched_ec, ForeignKeyOptInfo::nmatched_rcols, ForeignKeyOptInfo::nmatched_ri, OidIsValid, OpExpr::opno, RestrictInfo::outerjoin_delayed, ForeignKeyOptInfo::ref_relid, RELOPT_BASEREL, RelOptInfo::reloptkind, ForeignKeyOptInfo::rinfos, PlannerInfo::simple_rel_array, and PlannerInfo::simple_rel_array_size.
Referenced by query_planner().
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 | ||
) |
Definition at line 2272 of file initsplan.c.
References add_vars_to_targetlist(), Assert(), bms_copy(), bms_is_empty(), bms_is_subset(), bms_membership(), BMS_MULTIPLE, check_mergejoinable(), Const::constisnull, Const::consttype, Const::constvalue, contain_volatile_functions(), copyObject, DatumGetBool, distribute_restrictinfo_to_rels(), eval_const_expressions(), get_relids_in_jointree(), PlannerInfo::hasPseudoConstantQuals, InvalidOid, IsA, Query::jointree, list_free(), make_opclause(), make_restrictinfo(), PlannerInfo::parse, pull_var_clause(), pull_varnos(), PVC_INCLUDE_PLACEHOLDERS, PVC_RECURSE_AGGREGATES, and PVC_RECURSE_WINDOWFUNCS.
Referenced by generate_base_implied_equalities_const(), and generate_base_implied_equalities_no_const().
|
static |
Definition at line 1084 of file initsplan.c.
References Assert(), distribute_qual_to_rels(), JOIN_INNER, lfirst, RangeTblEntry::securityQuals, and PlannerInfo::simple_rte_array.
Referenced by deconstruct_recurse().
int from_collapse_limit |
Definition at line 39 of file initsplan.c.
Referenced by deconstruct_recurse().
int join_collapse_limit |
Definition at line 40 of file initsplan.c.
Referenced by deconstruct_recurse().