PostgreSQL Source Code git master
|
#include "postgres.h"
#include "catalog/pg_class.h"
#include "nodes/nodeFuncs.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/restrictinfo.h"
#include "rewrite/rewriteManip.h"
#include "utils/lsyscache.h"
Go to the source code of this file.
Data Structures | |
struct | SelfJoinCandidate |
Variables | |
bool | enable_self_join_elimination |
|
static |
Definition at line 1638 of file analyzejoins.c.
References Assert(), bms_equal(), bms_is_member(), distribute_restrictinfo_to_rels(), foreach_node, restrict_infos_logically_equal(), and root.
Referenced by remove_self_join_rel().
Definition at line 1248 of file analyzejoins.c.
References forboth, InvalidOid, lfirst_int, and lfirst_oid.
Referenced by query_is_distinct_for().
bool innerrel_is_unique | ( | PlannerInfo * | root, |
Relids | joinrelids, | ||
Relids | outerrelids, | ||
RelOptInfo * | innerrel, | ||
JoinType | jointype, | ||
List * | restrictlist, | ||
bool | force_cache | ||
) |
Definition at line 1288 of file analyzejoins.c.
References innerrel_is_unique_ext(), and root.
Referenced by add_paths_to_joinrel(), and reduce_unique_semijoins().
bool innerrel_is_unique_ext | ( | PlannerInfo * | root, |
Relids | joinrelids, | ||
Relids | outerrelids, | ||
RelOptInfo * | innerrel, | ||
JoinType | jointype, | ||
List * | restrictlist, | ||
bool | force_cache, | ||
List ** | extra_clauses | ||
) |
Definition at line 1310 of file analyzejoins.c.
References bms_copy(), bms_equal(), bms_is_subset(), UniqueRelInfo::extra_clauses, is_innerrel_unique_for(), lappend(), lfirst, makeNode, MemoryContextSwitchTo(), NIL, RelOptInfo::non_unique_for_rels, UniqueRelInfo::outerrelids, rel_supports_distinctness(), root, UniqueRelInfo::self_join, and RelOptInfo::unique_for_rels.
Referenced by innerrel_is_unique(), and remove_self_joins_one_group().
|
static |
Definition at line 1440 of file analyzejoins.c.
References clause_sides_match_join(), IS_OUTER_JOIN, lappend(), lfirst, NIL, rel_is_distinct_for(), RelOptInfo::relids, RINFO_IS_PUSHED_DOWN, and root.
Referenced by innerrel_is_unique_ext().
|
static |
Definition at line 153 of file analyzejoins.c.
References Assert(), bms_add_member(), bms_copy(), bms_get_singleton_member(), bms_is_member(), bms_is_subset(), bms_overlap(), bms_union(), clause_sides_match_join(), find_base_rel(), RestrictInfo::is_clone, JOIN_LEFT, RelOptInfo::joininfo, SpecialJoinInfo::jointype, lappend(), lfirst, RelOptInfo::max_attr, RelOptInfo::min_attr, SpecialJoinInfo::min_lefthand, SpecialJoinInfo::min_righthand, NIL, SpecialJoinInfo::ojrelid, PlaceHolderInfo::ph_eval_at, PlaceHolderInfo::ph_lateral, PlaceHolderInfo::ph_needed, PlaceHolderInfo::ph_var, pull_varnos(), rel_is_distinct_for(), rel_supports_distinctness(), RelOptInfo::relids, RINFO_IS_PUSHED_DOWN, and root.
Referenced by remove_useless_joins().
|
static |
Definition at line 1931 of file analyzejoins.c.
References Assert(), RelOptInfo::baserestrictinfo, bms_is_empty, ChangeVarNodes(), copyObject, equal(), foreach_node, get_leftop(), get_rightop(), is_opclause(), NIL, and RelOptInfo::relid.
Referenced by remove_self_joins_one_group().
Definition at line 1099 of file analyzejoins.c.
References SetOperationStmt::all, Assert(), castNode, distinct_col_search(), Query::distinctClause, SortGroupClause::eqop, equality_ops_are_compatible(), get_sortgroupclause_tle(), Query::groupClause, GROUPING_SET_EMPTY, Query::groupingSets, Query::havingQual, lfirst, linitial, list_head(), list_length(), lnext(), OidIsValid, SetOperationStmt::op, TargetEntry::resno, SETOP_NONE, Query::setOperations, and Query::targetList.
Referenced by create_unique_path(), and rel_is_distinct_for().
bool query_supports_distinctness | ( | Query * | query | ) |
Definition at line 1061 of file analyzejoins.c.
References Query::distinctClause, Query::groupClause, Query::groupingSets, Query::havingQual, NIL, and Query::setOperations.
Referenced by create_unique_path(), and rel_supports_distinctness().
void reduce_unique_semijoins | ( | PlannerInfo * | root | ) |
Definition at line 826 of file analyzejoins.c.
References Assert(), bms_get_singleton_member(), bms_union(), find_base_rel(), foreach_delete_current, generate_join_implied_equalities(), innerrel_is_unique(), JOIN_SEMI, RelOptInfo::joininfo, SpecialJoinInfo::jointype, lfirst, list_concat(), SpecialJoinInfo::min_lefthand, SpecialJoinInfo::min_righthand, SpecialJoinInfo::ojrelid, rel_supports_distinctness(), and root.
Referenced by query_planner().
|
static |
Definition at line 962 of file analyzejoins.c.
References castNode, RestrictInfo::clause, get_leftop(), get_rightop(), IsA, lappend_int(), lappend_oid(), lfirst_node, NIL, query_is_distinct_for(), relation_has_unique_index_ext(), RelOptInfo::relid, RELOPT_BASEREL, RelOptInfo::reloptkind, root, RTE_RELATION, RTE_SUBQUERY, RelOptInfo::rtekind, Var::varattno, Var::varlevelsup, and Var::varno.
Referenced by is_innerrel_unique_for(), and join_is_removable().
|
static |
Definition at line 902 of file analyzejoins.c.
References RelOptInfo::indexlist, lfirst, NIL, query_supports_distinctness(), RelOptInfo::relid, RELOPT_BASEREL, RelOptInfo::reloptkind, root, RTE_RELATION, RTE_SUBQUERY, and RelOptInfo::rtekind.
Referenced by innerrel_is_unique_ext(), join_is_removable(), and reduce_unique_semijoins().
|
static |
Definition at line 528 of file analyzejoins.c.
References Assert(), bms_add_member(), bms_add_members(), bms_is_member(), bms_union(), RestrictInfo::clause, SpecialJoinInfo::commute_above_r, SpecialJoinInfo::commute_below_l, distribute_restrictinfo_to_rels(), find_base_rel(), RelOptInfo::joininfo, lfirst, list_copy(), SpecialJoinInfo::min_lefthand, SpecialJoinInfo::min_righthand, SpecialJoinInfo::ojrelid, pfree(), pull_varnos(), rebuild_eclass_attr_needed(), rebuild_joinclause_attr_needed(), rebuild_lateral_attr_needed(), rebuild_placeholder_attr_needed(), remove_join_clause_from_rels(), remove_rel_from_query(), remove_rel_from_restrictinfo(), RestrictInfo::required_relids, RINFO_IS_PUSHED_DOWN, and root.
Referenced by remove_useless_joins().
|
static |
Definition at line 702 of file analyzejoins.c.
References adjust_relid_set(), Assert(), bms_is_empty, bms_is_member(), ChangeVarNodes(), EquivalenceClass::ec_childmembers, ec_clear_derived_clauses(), EquivalenceClass::ec_members, EquivalenceClass::ec_relids, EquivalenceClass::ec_sources, EquivalenceMember::em_is_const, EquivalenceMember::em_relids, foreach_delete_current, lfirst, SpecialJoinInfo::ojrelid, and remove_rel_from_restrictinfo().
Referenced by remove_rel_from_query().
Definition at line 772 of file analyzejoins.c.
References elog, ERROR, IsA, lappend(), lfirst, NIL, nodeTag, and remove_rel_from_joinlist().
Referenced by remove_rel_from_joinlist(), remove_useless_joins(), and remove_useless_self_joins().
|
static |
Definition at line 323 of file analyzejoins.c.
References adjust_relid_set(), Assert(), bms_copy(), bms_del_member(), bms_difference(), bms_is_empty, bms_is_member(), bms_is_subset(), bms_make_singleton(), ChangeVarNodes(), SpecialJoinInfo::commute_above_l, SpecialJoinInfo::commute_above_r, SpecialJoinInfo::commute_below_l, SpecialJoinInfo::commute_below_r, EquivalenceClass::ec_relids, foreach_delete_current, RelOptInfo::lateral_vars, lfirst, RelOptInfo::max_attr, RelOptInfo::min_attr, SpecialJoinInfo::min_lefthand, SpecialJoinInfo::min_righthand, SpecialJoinInfo::ojrelid, PlaceHolderInfo::ph_eval_at, PlaceHolderInfo::ph_lateral, PlaceHolderInfo::ph_needed, PlaceHolderInfo::ph_var, PlaceHolderInfo::phid, PlaceHolderVar::phnullingrels, RelOptInfo::relid, remove_rel_from_eclass(), root, SpecialJoinInfo::semi_rhs_exprs, SpecialJoinInfo::syn_lefthand, and SpecialJoinInfo::syn_righthand.
Referenced by remove_leftjoinrel_from_query(), and remove_self_join_rel().
|
static |
Definition at line 641 of file analyzejoins.c.
References Assert(), bms_copy(), bms_del_member(), castNode, is_andclause(), is_orclause(), lfirst, lfirst_node, remove_rel_from_restrictinfo(), RestrictInfo::required_relids, and restriction_is_or_clause().
Referenced by remove_leftjoinrel_from_query(), remove_rel_from_eclass(), and remove_rel_from_restrictinfo().
|
static |
Definition at line 1694 of file analyzejoins.c.
References add_non_redundant_clauses(), adjust_relid_set(), Assert(), RelOptInfo::baserestrictinfo, bms_add_member(), bms_add_members(), bms_membership(), BMS_MULTIPLE, bms_next_member(), ChangeVarNodes(), ChangeVarNodesExtended(), RelOptInfo::eclass_indexes, PathTarget::exprs, foreach_node, i, RelOptInfo::joininfo, lappend(), lfirst, list_concat(), list_copy(), list_delete_ptr(), list_free(), list_member(), list_nth(), PlanRowMark::markType, RelOptInfo::min_attr, NIL, pfree(), PlanRowMark::prti, rebuild_eclass_attr_needed(), rebuild_joinclause_attr_needed(), rebuild_lateral_attr_needed(), rebuild_placeholder_attr_needed(), RelOptInfo::relid, RelOptInfo::reltarget, remove_join_clause_from_rels(), remove_rel_from_query(), root, PlanRowMark::rti, and update_eclasses().
Referenced by remove_self_joins_one_group().
|
static |
Definition at line 1996 of file analyzejoins.c.
References Assert(), RelOptInfo::baserestrictinfo, bms_add_member(), bms_is_member(), bms_next_member(), generate_join_implied_equalities(), innerrel_is_unique_ext(), JOIN_INNER, lfirst, list_concat(), list_length(), PlanRowMark::markType, match_unique_clauses(), NIL, RelOptInfo::relid, RelOptInfo::relids, remove_self_join_rel(), root, PlanRowMark::rti, split_selfjoin_quals(), SpecialJoinInfo::syn_lefthand, and SpecialJoinInfo::syn_righthand.
Referenced by remove_self_joins_recurse().
|
static |
Definition at line 2163 of file analyzejoins.c.
References Assert(), bms_add_member(), bms_add_members(), bms_del_member(), bms_del_members(), bms_free(), bms_is_empty, bms_is_member(), bms_membership(), BMS_MULTIPLE, bms_next_member(), bms_num_members(), bms_overlap(), elog, ERROR, i, IsA, j, lfirst, nodeTag, palloc(), qsort, SelfJoinCandidate::relid, SelfJoinCandidate::reloid, remove_self_joins_one_group(), remove_self_joins_recurse(), root, RTE_RELATION, RangeTblEntry::rtekind, self_join_candidates_cmp(), and RangeTblEntry::tablesample.
Referenced by remove_self_joins_recurse(), and remove_useless_self_joins().
List * remove_useless_joins | ( | PlannerInfo * | root, |
List * | joinlist | ||
) |
Definition at line 88 of file analyzejoins.c.
References bms_singleton_member(), elog, ERROR, join_is_removable(), lfirst, list_delete_cell(), SpecialJoinInfo::min_righthand, remove_leftjoinrel_from_query(), remove_rel_from_joinlist(), and root.
Referenced by query_planner().
List * remove_useless_self_joins | ( | PlannerInfo * | root, |
List * | joinlist | ||
) |
Definition at line 2344 of file analyzejoins.c.
References bms_next_member(), elog, enable_self_join_elimination, ERROR, IsA, linitial, list_length(), NIL, remove_rel_from_joinlist(), remove_self_joins_recurse(), root, and unlikely.
Referenced by query_planner().
|
static |
Definition at line 1612 of file analyzejoins.c.
Referenced by add_non_redundant_clauses().
|
static |
Definition at line 2297 of file analyzejoins.c.
References a, b, and SelfJoinCandidate::reloid.
Referenced by remove_self_joins_recurse().
|
static |
Definition at line 1868 of file analyzejoins.c.
References arg, OpExpr::args, bms_membership(), bms_num_members(), BMS_SINGLETON, bms_singleton_member(), ChangeVarNodes(), copyObject, equal(), foreach_node, get_leftop(), get_rightop(), if(), IsA, lappend(), list_length(), and NIL.
Referenced by remove_self_joins_one_group().
|
static |
Definition at line 1514 of file analyzejoins.c.
References adjust_relid_set(), Assert(), bms_is_member(), ChangeVarNodes(), EquivalenceClass::ec_childmembers, ec_clear_derived_clauses(), EquivalenceClass::ec_members, EquivalenceClass::ec_relids, EquivalenceClass::ec_sources, equal(), foreach_node, lappend(), list_free(), and NIL.
Referenced by remove_self_join_rel().
bool enable_self_join_elimination |
Definition at line 53 of file analyzejoins.c.
Referenced by remove_useless_self_joins().