PostgreSQL Source Code
git master
|
#include "postgres.h"
#include "catalog/pg_type.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "nodes/multibitmapset.h"
#include "nodes/nodeFuncs.h"
#include "optimizer/clauses.h"
#include "optimizer/optimizer.h"
#include "optimizer/placeholder.h"
#include "optimizer/prep.h"
#include "optimizer/subselect.h"
#include "optimizer/tlist.h"
#include "parser/parse_relation.h"
#include "parser/parsetree.h"
#include "rewrite/rewriteManip.h"
Go to the source code of this file.
Data Structures | |
struct | nullingrel_info |
struct | pullup_replace_vars_context |
struct | reduce_outer_joins_pass1_state |
struct | reduce_outer_joins_pass2_state |
struct | reduce_outer_joins_partial_state |
struct | find_dependent_phvs_context |
struct | substitute_phv_relids_context |
Typedefs | |
typedef struct nullingrel_info | nullingrel_info |
typedef struct pullup_replace_vars_context | pullup_replace_vars_context |
typedef struct reduce_outer_joins_pass1_state | reduce_outer_joins_pass1_state |
typedef struct reduce_outer_joins_pass2_state | reduce_outer_joins_pass2_state |
typedef struct reduce_outer_joins_partial_state | reduce_outer_joins_partial_state |
typedef struct nullingrel_info nullingrel_info |
typedef struct pullup_replace_vars_context pullup_replace_vars_context |
typedef struct reduce_outer_joins_partial_state reduce_outer_joins_partial_state |
typedef struct reduce_outer_joins_pass1_state reduce_outer_joins_pass1_state |
typedef struct reduce_outer_joins_pass2_state reduce_outer_joins_pass2_state |
|
static |
Definition at line 3876 of file prepjointree.c.
References bms_make_singleton(), context, expression_tree_walker, find_dependent_phvs_walker(), query_tree_walker, and root.
Referenced by remove_useless_results_recurse().
|
static |
Definition at line 3898 of file prepjointree.c.
References bms_make_singleton(), bms_next_member(), context, find_dependent_phvs_walker(), get_relids_in_jointree(), range_table_entry_walker, root, and rt_fetch.
Referenced by remove_useless_results_recurse().
|
static |
Definition at line 3841 of file prepjointree.c.
References Assert, bms_equal(), context, expression_tree_walker, IsA, PlaceHolderVar::phlevelsup, and query_tree_walker.
Referenced by find_dependent_phvs(), and find_dependent_phvs_in_jointree().
Definition at line 4152 of file prepjointree.c.
References elog, ERROR, FromExpr::fromlist, IsA, j, lfirst, and nodeTag.
Referenced by get_relids_for_join().
|
static |
Definition at line 4030 of file prepjointree.c.
References Assert, bms_singleton_member(), AppendRelInfo::child_relid, lfirst, AppendRelInfo::parent_relid, root, substitute_phv_relids(), and AppendRelInfo::translated_vars.
Referenced by pull_up_simple_subquery(), and remove_result_refs().
void flatten_simple_union_all | ( | PlannerInfo * | root | ) |
Definition at line 2815 of file prepjointree.c.
References Assert, castNode, copyObject, RangeTblEntry::inh, is_simple_union_all_recurse(), IsA, lappend(), SetOperationStmt::larg, list_length(), list_make1, makeNode, NIL, parse(), pull_up_union_leaf_queries(), root, rt_fetch, RTE_SUBQUERY, RangeTblEntry::rtekind, and RangeTblRef::rtindex.
Referenced by subquery_planner().
|
static |
Definition at line 4201 of file prepjointree.c.
References get_nullingrels_recurse(), list_length(), nullingrel_info::nullingrels, palloc0_array, palloc_object, parse(), and nullingrel_info::rtlength.
Referenced by pull_up_simple_subquery().
|
static |
Definition at line 4221 of file prepjointree.c.
References Assert, bms_add_member(), bms_copy(), elog, ERROR, FromExpr::fromlist, IsA, j, JOIN_ANTI, JOIN_FULL, JOIN_INNER, JOIN_LEFT, JOIN_RIGHT, JOIN_SEMI, lfirst, nodeTag, and nullingrel_info::nullingrels.
Referenced by get_nullingrels().
Definition at line 4135 of file prepjointree.c.
References elog, ERROR, find_jointree_node_for_rel(), get_relids_in_jointree(), and Query::jointree.
Referenced by add_nullingrels_if_needed(), and alias_relid_set().
Definition at line 4074 of file prepjointree.c.
References bms_add_member(), bms_join(), bms_make_singleton(), elog, ERROR, FromExpr::fromlist, IsA, j, JOIN_INNER, lfirst, and nodeTag.
Referenced by find_dependent_phvs_in_jointree(), get_relids_for_join(), is_simple_subquery(), mark_nullable_by_grouping(), preprocess_rowmarks(), pull_up_simple_subquery(), and remove_result_refs().
|
static |
Definition at line 3772 of file prepjointree.c.
References IsA, root, rt_fetch, and RTE_RESULT.
Referenced by remove_useless_results_recurse().
|
static |
Definition at line 2138 of file prepjointree.c.
References Assert, FromExpr::fromlist, IsA, Query::jointree, linitial, list_length(), NIL, and FromExpr::quals.
Referenced by pull_up_simple_subquery(), and pull_up_subqueries_recurse().
|
static |
Definition at line 1654 of file prepjointree.c.
References bms_is_subset(), CMD_SELECT, Query::commandType, contain_volatile_functions(), Query::cteList, Query::distinctClause, elog, ERROR, get_relids_in_jointree(), Query::groupClause, Query::groupingSets, Query::havingQual, IsA, Query::jointree, jointree_contains_lateral_outer_refs(), Query::limitCount, Query::limitOffset, pull_varnos_of_level(), root, Query::setOperations, Query::sortClause, and Query::targetList.
Referenced by pull_up_simple_subquery(), and pull_up_subqueries_recurse().
|
static |
Definition at line 2067 of file prepjointree.c.
References castNode, CMD_SELECT, Query::commandType, Query::cteList, elog, ERROR, is_simple_union_all_recurse(), IsA, Query::limitCount, Query::limitOffset, Query::rowMarks, Query::setOperations, and Query::sortClause.
Referenced by pull_up_subqueries_recurse().
|
static |
Definition at line 2095 of file prepjointree.c.
References SetOperationStmt::all, Assert, check_stack_depth(), elog, ERROR, IsA, SetOperationStmt::larg, nodeTag, SetOperationStmt::op, SetOperationStmt::rarg, rt_fetch, Query::rtable, RangeTblRef::rtindex, SETOP_UNION, RangeTblEntry::subquery, Query::targetList, and tlist_same_datatypes().
Referenced by flatten_simple_union_all(), and is_simple_union_all().
|
static |
Definition at line 1890 of file prepjointree.c.
References Assert, contain_volatile_functions(), expression_returns_set(), linitial, list_length(), root, RTE_VALUES, RangeTblEntry::rtekind, and RangeTblEntry::values_lists.
Referenced by pull_up_subqueries_recurse().
|
static |
Definition at line 2186 of file prepjointree.c.
References bms_is_subset(), elog, ERROR, FromExpr::fromlist, IsA, j, JOIN_INNER, lfirst, nodeTag, pull_varnos_of_level(), FromExpr::quals, and root.
Referenced by is_simple_subquery().
|
static |
Definition at line 1616 of file prepjointree.c.
References lappend(), lfirst, list_length(), makeVarFromTargetEntry(), NIL, AppendRelInfo::num_child_cols, palloc0(), TargetEntry::resno, Query::targetList, and AppendRelInfo::translated_vars.
Referenced by pull_up_union_leaf_queries().
|
static |
Definition at line 2261 of file prepjointree.c.
References generate_unaccent_rules::action, Assert, lfirst, parse(), pullup_replace_vars(), replace_vars_in_jointree(), root, RTE_GROUP, RTE_JOIN, RangeTblEntry::rtekind, AppendRelInfo::translated_vars, and pullup_replace_vars_context::wrap_non_vars.
Referenced by pull_up_constant_function(), pull_up_simple_subquery(), and pull_up_simple_values().
void preprocess_function_rtes | ( | PlannerInfo * | root | ) |
Definition at line 887 of file prepjointree.c.
References eval_const_expressions(), RangeTblEntry::funcordinality, RangeTblEntry::functions, inline_set_returning_function(), lfirst, NIL, root, RTE_FUNCTION, RTE_SUBQUERY, RangeTblEntry::rtekind, and RangeTblEntry::subquery.
Referenced by pull_up_simple_subquery(), and subquery_planner().
|
static |
Definition at line 1949 of file prepjointree.c.
References RangeTblFunction::funcexpr, RangeTblEntry::funcordinality, RangeTblEntry::functions, get_expr_result_type(), IsA, linitial_node, list_length(), list_make1, makeTargetEntry(), NIL, pullup_replace_vars_context::nullinfo, pullup_replace_vars_context::outer_hasSubLinks, palloc0(), parse(), perform_pullup_replace_vars(), pullup_replace_vars_context::relids, pullup_replace_vars_context::root, root, RTE_RESULT, RangeTblEntry::rtekind, pullup_replace_vars_context::rv_cache, pullup_replace_vars_context::target_rte, pullup_replace_vars_context::targetlist, TYPEFUNC_SCALAR, pullup_replace_vars_context::varno, and pullup_replace_vars_context::wrap_non_vars.
Referenced by pull_up_subqueries_recurse().
|
static |
Definition at line 1117 of file prepjointree.c.
References PlannerInfo::all_result_relids, PlannerInfo::append_rel_list, Assert, CombineRangeTables(), copyObject, PlannerInfo::cte_plan_ids, Query::cteList, CurrentMemoryContext, PlannerInfo::ec_merging_done, PlannerInfo::eq_classes, fix_append_rel_relids(), flatten_join_alias_vars(), FromExpr::fromlist, get_nullingrels(), get_relids_in_jointree(), PlannerInfo::glob, PlannerInfo::hasRecursion, IncrementVarSublevelsUp(), PlannerInfo::init_plans, is_safe_append_member(), is_simple_subquery(), IsA, PlannerInfo::join_domains, PlannerInfo::join_info_list, Query::jointree, PlannerInfo::last_rinfo_serial, PlannerInfo::leaf_result_relids, lfirst, linitial, list_concat(), list_length(), makeNode, PlannerInfo::minmax_aggs, PlannerInfo::multiexpr_params, NIL, PlannerInfo::non_recursive_path, pullup_replace_vars_context::nullinfo, OffsetVarNodes(), pullup_replace_vars_context::outer_hasSubLinks, PlannerInfo::outer_params, palloc0(), parse(), PlannerInfo::parse, perform_pullup_replace_vars(), PlannerInfo::placeholder_list, PlannerInfo::placeholdersFrozen, PlannerInfo::plan_params, preprocess_function_rtes(), PlannerInfo::processed_distinctClause, PlannerInfo::processed_groupClause, PlannerInfo::processed_tlist, pull_up_sublinks(), pull_up_subqueries(), PlannerInfo::qual_security_level, FromExpr::quals, PlannerInfo::query_level, pullup_replace_vars_context::relids, replace_empty_jointree(), pullup_replace_vars_context::root, root, PlannerInfo::row_identity_vars, Query::rowMarks, PlannerInfo::rowMarks, Query::rtable, RTE_CTE, RTE_FUNCTION, RTE_GROUP, RTE_JOIN, RTE_NAMEDTUPLESTORE, RTE_RELATION, RTE_RESULT, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, RangeTblEntry::rtekind, pullup_replace_vars_context::rv_cache, RangeTblEntry::subquery, substitute_phv_relids(), RangeTblEntry::tablesample, pullup_replace_vars_context::target_rte, pullup_replace_vars_context::targetlist, Query::targetList, PlannerInfo::update_colnos, pullup_replace_vars_context::varno, pullup_replace_vars_context::wrap_non_vars, and PlannerInfo::wt_param_id.
Referenced by pull_up_subqueries_recurse().
|
static |
Definition at line 1464 of file prepjointree.c.
References Assert, CombineRangeTables(), copyObject, IncrementVarSublevelsUp_rtable(), RangeTblEntry::inh, lfirst, list_length(), pull_up_union_leaf_queries(), root, Query::rtable, RTE_SUBQUERY, RangeTblEntry::rtekind, Query::setOperations, and RangeTblEntry::subquery.
Referenced by pull_up_subqueries_recurse().
|
static |
Definition at line 1794 of file prepjointree.c.
References Assert, contain_vars_of_level(), copyObject, lappend(), lfirst, linitial, list_length(), list_make1, makeAlias(), makeNode, makeTargetEntry(), NIL, pullup_replace_vars_context::nullinfo, pullup_replace_vars_context::outer_hasSubLinks, palloc0(), parse(), perform_pullup_replace_vars(), pullup_replace_vars_context::relids, pullup_replace_vars_context::root, root, RTE_RESULT, RTE_VALUES, RangeTblEntry::rtekind, pullup_replace_vars_context::rv_cache, pullup_replace_vars_context::target_rte, pullup_replace_vars_context::targetlist, RangeTblEntry::values_lists, pullup_replace_vars_context::varno, and pullup_replace_vars_context::wrap_non_vars.
Referenced by pull_up_subqueries_recurse().
void pull_up_sublinks | ( | PlannerInfo * | root | ) |
Definition at line 453 of file prepjointree.c.
References IsA, list_make1, makeFromExpr(), pull_up_sublinks_jointree_recurse(), and root.
Referenced by pull_up_simple_subquery(), and subquery_planner().
|
static |
Definition at line 480 of file prepjointree.c.
References bms_add_member(), bms_join(), bms_make_singleton(), bms_union(), check_stack_depth(), elog, ERROR, FromExpr::fromlist, IsA, j, JOIN_FULL, JOIN_INNER, JOIN_LEFT, JOIN_RIGHT, lappend(), lfirst, makeFromExpr(), NIL, nodeTag, palloc(), pull_up_sublinks_qual_recurse(), FromExpr::quals, and root.
Referenced by pull_up_sublinks(), and pull_up_sublinks_qual_recurse().
|
static |
Definition at line 637 of file prepjointree.c.
References ANY_SUBLINK, generate_unaccent_rules::args, convert_ANY_sublink_to_join(), convert_EXISTS_sublink_to_join(), EXISTS_SUBLINK, get_notclausearg(), is_andclause(), is_notclause(), IsA, j, lappend(), lfirst, linitial, list_length(), make_andclause(), NIL, pull_up_sublinks_jointree_recurse(), root, and SubLink::subLinkType.
Referenced by pull_up_sublinks_jointree_recurse().
void pull_up_subqueries | ( | PlannerInfo * | root | ) |
Definition at line 928 of file prepjointree.c.
References Assert, IsA, pull_up_subqueries_recurse(), and root.
Referenced by pull_up_simple_subquery(), and subquery_planner().
|
static |
Definition at line 972 of file prepjointree.c.
References Assert, CHECK_FOR_INTERRUPTS, check_stack_depth(), elog, ERROR, FromExpr::fromlist, is_safe_append_member(), is_simple_subquery(), is_simple_union_all(), is_simple_values(), IsA, j, JOIN_ANTI, JOIN_FULL, JOIN_INNER, JOIN_LEFT, JOIN_RIGHT, JOIN_SEMI, lfirst, nodeTag, pull_up_constant_function(), pull_up_simple_subquery(), pull_up_simple_union_all(), pull_up_simple_values(), root, rt_fetch, RTE_FUNCTION, RTE_SUBQUERY, RTE_VALUES, RangeTblEntry::rtekind, and RangeTblEntry::subquery.
Referenced by pull_up_subqueries(), and pull_up_union_leaf_queries().
|
static |
Definition at line 1546 of file prepjointree.c.
References AppendRelInfo::child_relid, AppendRelInfo::child_reltype, elog, ERROR, InvalidOid, IsA, lappend(), SetOperationStmt::larg, make_setop_translation_list(), makeNode, nodeTag, AppendRelInfo::parent_relid, AppendRelInfo::parent_reloid, AppendRelInfo::parent_reltype, pull_up_subqueries_recurse(), SetOperationStmt::rarg, root, and RangeTblRef::rtindex.
Referenced by flatten_simple_union_all(), and pull_up_simple_union_all().
|
static |
Definition at line 2475 of file prepjointree.c.
References context, pullup_replace_vars_callback(), and replace_rte_variables().
Referenced by perform_pullup_replace_vars(), and replace_vars_in_jointree().
|
static |
Definition at line 2485 of file prepjointree.c.
References add_nulling_relids(), RowExpr::args, Assert, bms_add_members(), bms_del_members(), bms_intersect(), bms_is_empty, bms_is_member(), bms_is_subset(), bms_make_singleton(), bms_next_member(), bms_overlap(), COERCE_IMPLICIT_CAST, contain_nonstrict_functions(), contain_vars_of_level(), context, copyObject, elog, ERROR, expandRTE(), TargetEntry::expr, get_tle_by_resno(), IncrementVarSublevelsUp(), InvalidAttrNumber, IsA, list_length(), Var::location, RowExpr::location, make_placeholder_expr(), makeNode, NIL, pullup_replace_vars_context::nullinfo, nullingrel_info::nullingrels, PlaceHolderVar::phlevelsup, PlaceHolderVar::phnullingrels, pull_varnos(), pullup_replace_vars_context::relids, replace_rte_variables_mutator(), pullup_replace_vars_context::root, pullup_replace_vars_context::rv_cache, pullup_replace_vars_context::target_rte, pullup_replace_vars_context::targetlist, Var::varattno, Var::varlevelsup, pullup_replace_vars_context::varno, Var::varno, and pullup_replace_vars_context::wrap_non_vars.
Referenced by pullup_replace_vars(), and pullup_replace_vars_subquery().
|
static |
Definition at line 2788 of file prepjointree.c.
References Assert, context, IsA, pullup_replace_vars_callback(), and replace_rte_variables().
Referenced by replace_vars_in_jointree().
void reduce_outer_joins | ( | PlannerInfo * | root | ) |
Definition at line 2934 of file prepjointree.c.
References bms_is_empty, bms_make_singleton(), reduce_outer_joins_pass1_state::contains_outer, elog, ERROR, reduce_outer_joins_partial_state::full_join_rti, reduce_outer_joins_pass2_state::inner_reduced, lfirst, NIL, reduce_outer_joins_pass2_state::partial_reduced, reduce_outer_joins_pass1(), reduce_outer_joins_pass2(), remove_nulling_relids(), root, and reduce_outer_joins_partial_state::unreduced_side.
Referenced by subquery_planner().
|
static |
Definition at line 3007 of file prepjointree.c.
References bms_add_members(), bms_make_singleton(), reduce_outer_joins_pass1_state::contains_outer, elog, ERROR, FromExpr::fromlist, IS_OUTER_JOIN, IsA, j, lappend(), lfirst, NIL, nodeTag, palloc(), reduce_outer_joins_pass1_state::relids, and reduce_outer_joins_pass1_state::sub_states.
Referenced by reduce_outer_joins().
|
static |
Definition at line 3085 of file prepjointree.c.
References Assert, bms_add_member(), bms_add_members(), bms_free(), bms_overlap(), reduce_outer_joins_pass1_state::contains_outer, elog, ERROR, find_forced_null_vars(), find_nonnullable_rels(), find_nonnullable_vars(), forboth, FromExpr::fromlist, reduce_outer_joins_pass2_state::inner_reduced, IsA, j, JOIN_ANTI, JOIN_FULL, JOIN_INNER, JOIN_LEFT, JOIN_RIGHT, JOIN_SEMI, RangeTblEntry::jointype, lfirst, linitial, list_length(), lsecond, mbms_add_members(), mbms_overlap_sets(), NIL, nodeTag, FromExpr::quals, reduce_outer_joins_pass1_state::relids, report_reduced_full_join(), root, rt_fetch, RTE_JOIN, RangeTblEntry::rtekind, and reduce_outer_joins_pass1_state::sub_states.
Referenced by reduce_outer_joins().
|
static |
Definition at line 3802 of file prepjointree.c.
References Assert, bms_is_empty, fix_append_rel_relids(), get_relids_in_jointree(), root, and substitute_phv_relids().
Referenced by remove_useless_results_recurse().
void remove_useless_result_rtes | ( | PlannerInfo * | root | ) |
Definition at line 3428 of file prepjointree.c.
References Assert, bms_is_empty, foreach_delete_current, IsA, lfirst, remove_nulling_relids(), remove_useless_results_recurse(), root, rt_fetch, RTE_RESULT, and PlanRowMark::rti.
Referenced by subquery_planner().
|
static |
Definition at line 3501 of file prepjointree.c.
References Assert, bms_add_member(), bms_next_member(), castNode, elog, ERROR, find_dependent_phvs(), find_dependent_phvs_in_jointree(), foreach_delete_current, FromExpr::fromlist, get_result_relid(), IsA, j, JOIN_ANTI, JOIN_FULL, JOIN_INNER, JOIN_LEFT, JOIN_SEMI, lfirst, linitial, list_concat(), list_length(), list_make1, makeFromExpr(), nodeTag, FromExpr::quals, remove_result_refs(), and root.
Referenced by remove_useless_result_rtes().
void replace_empty_jointree | ( | Query * | parse | ) |
Definition at line 395 of file prepjointree.c.
References lappend(), list_length(), list_make1, makeAlias(), makeNode, NIL, parse(), RTE_RESULT, RangeTblEntry::rtekind, and RangeTblRef::rtindex.
Referenced by convert_EXISTS_sublink_to_join(), pull_up_simple_subquery(), and subquery_planner().
|
static |
Definition at line 2368 of file prepjointree.c.
References Assert, context, elog, ERROR, FromExpr::fromlist, RangeTblEntry::functions, IsA, j, JOIN_FULL, lfirst, nodeTag, pullup_replace_vars(), pullup_replace_vars_subquery(), FromExpr::quals, rt_fetch, RTE_CTE, RTE_FUNCTION, RTE_GROUP, RTE_JOIN, RTE_NAMEDTUPLESTORE, RTE_RELATION, RTE_RESULT, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, RangeTblEntry::rtekind, RangeTblEntry::subquery, RangeTblEntry::tablefunc, RangeTblEntry::tablesample, and RangeTblEntry::values_lists.
Referenced by perform_pullup_replace_vars().
|
static |
Definition at line 3359 of file prepjointree.c.
References reduce_outer_joins_partial_state::full_join_rti, lappend(), palloc(), reduce_outer_joins_pass2_state::partial_reduced, and reduce_outer_joins_partial_state::unreduced_side.
Referenced by reduce_outer_joins_pass2().
Definition at line 4002 of file prepjointree.c.
References context, query_or_expression_tree_walker, and substitute_phv_relids_walker().
Referenced by fix_append_rel_relids(), pull_up_simple_subquery(), and remove_result_refs().
|
static |
Definition at line 3959 of file prepjointree.c.
References Assert, bms_del_member(), bms_is_empty, bms_is_member(), bms_union(), context, expression_tree_walker, IsA, PlaceHolderVar::phlevelsup, and query_tree_walker.
Referenced by substitute_phv_relids().
void transform_MERGE_to_join | ( | Query * | parse | ) |
Definition at line 168 of file prepjointree.c.
References generate_unaccent_rules::action, add_nulling_relids(), NullTest::arg, Assert, bms_make_singleton(), CMD_MERGE, CMD_NOTHING, elog, ERROR, foreach_node, RangeTblEntry::inh, IS_NOT_NULL, IsA, JoinExpr::isNatural, JOIN_FULL, JOIN_INNER, JOIN_LEFT, JOIN_RIGHT, RangeTblEntry::jointype, JoinExpr::jointype, lappend(), JoinExpr::larg, linitial, list_length(), list_make1, NullTest::location, make_and_qual(), makeAlias(), makeFromExpr(), makeNode, makeWholeRowVar(), MERGE_WHEN_MATCHED, MERGE_WHEN_NOT_MATCHED_BY_SOURCE, MERGE_WHEN_NOT_MATCHED_BY_TARGET, NIL, nodeTag, NullTest::nulltesttype, NUM_MERGE_MATCH_KINDS, parse(), JoinExpr::quals, JoinExpr::rarg, rt_fetch, RTE_JOIN, RangeTblEntry::rtekind, RangeTblRef::rtindex, JoinExpr::rtindex, and source.
Referenced by subquery_planner().