|
PostgreSQL Source Code git master
|
#include "postgres.h"#include "access/table.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/plancat.h"#include "optimizer/prep.h"#include "optimizer/subselect.h"#include "optimizer/tlist.h"#include "parser/parse_relation.h"#include "parser/parsetree.h"#include "rewrite/rewriteHandler.h"#include "rewrite/rewriteManip.h"#include "utils/rel.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 |
Enumerations | |
| enum | ReplaceWrapOption { REPLACE_WRAP_NONE , REPLACE_WRAP_ALL , REPLACE_WRAP_VARFREE } |
| Enumerator | |
|---|---|
| REPLACE_WRAP_NONE | |
| REPLACE_WRAP_ALL | |
| REPLACE_WRAP_VARFREE | |
Definition at line 62 of file prepjointree.c.
|
static |
Definition at line 486 of file prepjointree.c.
References Assert, build_generation_expression(), ChangeVarNodes(), TupleDescData::constr, fb(), TupleConstr::has_generated_virtual, i, lappend(), list_length(), makeTargetEntry(), makeVar(), TupleDescData::natts, NIL, palloc0(), parse(), pullup_replace_vars(), RelationGetDescr, REPLACE_WRAP_ALL, REPLACE_WRAP_NONE, root, RTE_RELATION, and TupleDescAttr().
Referenced by preprocess_relation_rtes().
|
static |
Definition at line 4107 of file prepjointree.c.
References bms_make_singleton(), expression_tree_walker, find_dependent_phvs_walker(), query_tree_walker, find_dependent_phvs_context::relids, root, and find_dependent_phvs_context::sublevels_up.
Referenced by remove_useless_results_recurse().
|
static |
Definition at line 4129 of file prepjointree.c.
References bms_make_singleton(), bms_next_member(), fb(), find_dependent_phvs_walker(), get_relids_in_jointree(), range_table_entry_walker, find_dependent_phvs_context::relids, root, rt_fetch, and find_dependent_phvs_context::sublevels_up.
Referenced by remove_useless_results_recurse().
|
static |
Definition at line 4072 of file prepjointree.c.
References Assert, bms_equal(), expression_tree_walker, fb(), find_dependent_phvs_walker(), IsA, query_tree_walker, find_dependent_phvs_context::relids, and find_dependent_phvs_context::sublevels_up.
Referenced by find_dependent_phvs(), find_dependent_phvs_in_jointree(), and find_dependent_phvs_walker().
Definition at line 4383 of file prepjointree.c.
References elog, ERROR, fb(), find_jointree_node_for_rel(), FromExpr::fromlist, IsA, j, lfirst, and nodeTag.
Referenced by find_jointree_node_for_rel(), and get_relids_for_join().
|
static |
Definition at line 4261 of file prepjointree.c.
References Assert, bms_singleton_member(), fb(), lfirst, root, and substitute_phv_relids().
Referenced by pull_up_simple_subquery(), and remove_result_refs().
| void flatten_simple_union_all | ( | PlannerInfo * | root | ) |
Definition at line 3047 of file prepjointree.c.
References Assert, castNode, copyObject, fb(), is_simple_union_all_recurse(), IsA, lappend(), list_length(), list_make1, makeNode, NIL, parse(), pull_up_union_leaf_queries(), root, rt_fetch, and RTE_SUBQUERY.
Referenced by subquery_planner().
|
static |
Definition at line 4432 of file prepjointree.c.
References fb(), 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 4452 of file prepjointree.c.
References Assert, bms_add_member(), bms_copy(), elog, ERROR, fb(), FromExpr::fromlist, get_nullingrels_recurse(), IsA, j, JOIN_ANTI, JOIN_FULL, JOIN_INNER, JOIN_LEFT, JOIN_RIGHT, JOIN_SEMI, lfirst, nodeTag, and nullingrel_info::nullingrels.
Referenced by get_nullingrels(), and get_nullingrels_recurse().
Definition at line 4366 of file prepjointree.c.
References elog, ERROR, fb(), 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 4305 of file prepjointree.c.
References bms_add_member(), bms_join(), bms_make_singleton(), elog, ERROR, fb(), FromExpr::fromlist, get_relids_in_jointree(), IsA, j, JOIN_INNER, lfirst, and nodeTag.
Referenced by find_dependent_phvs_in_jointree(), get_relids_for_join(), get_relids_in_jointree(), is_simple_subquery(), mark_nullable_by_grouping(), preprocess_rowmarks(), pull_up_simple_subquery(), and remove_result_refs().
|
static |
Definition at line 4003 of file prepjointree.c.
References IsA, root, rt_fetch, and RTE_RESULT.
Referenced by remove_useless_results_recurse().
Definition at line 2350 of file prepjointree.c.
References Assert, fb(), 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 1871 of file prepjointree.c.
References bms_is_subset(), CMD_SELECT, Query::commandType, contain_volatile_functions(), Query::cteList, Query::distinctClause, elog, ERROR, fb(), 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(), restricted, root, Query::setOperations, Query::sortClause, and Query::targetList.
Referenced by pull_up_simple_subquery(), and pull_up_subqueries_recurse().
Definition at line 2279 of file prepjointree.c.
References castNode, CMD_SELECT, Query::commandType, Query::cteList, elog, ERROR, fb(), 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 2307 of file prepjointree.c.
References SetOperationStmt::all, Assert, check_stack_depth(), elog, ERROR, fb(), is_simple_union_all_recurse(), IsA, SetOperationStmt::larg, nodeTag, SetOperationStmt::op, SetOperationStmt::rarg, rt_fetch, SETOP_UNION, Query::targetList, and tlist_same_datatypes().
Referenced by flatten_simple_union_all(), is_simple_union_all(), and is_simple_union_all_recurse().
|
static |
Definition at line 2108 of file prepjointree.c.
References Assert, contain_volatile_functions(), expression_returns_set(), fb(), linitial, list_length(), root, and RTE_VALUES.
Referenced by pull_up_subqueries_recurse().
|
static |
Definition at line 2398 of file prepjointree.c.
References bms_is_subset(), elog, ERROR, fb(), FromExpr::fromlist, IsA, j, JOIN_INNER, jointree_contains_lateral_outer_refs(), lfirst, nodeTag, pull_varnos_of_level(), FromExpr::quals, restricted, and root.
Referenced by is_simple_subquery(), and jointree_contains_lateral_outer_refs().
|
static |
Definition at line 1833 of file prepjointree.c.
References fb(), lappend(), lfirst, list_length(), makeVarFromTargetEntry(), NIL, palloc0(), and Query::targetList.
Referenced by pull_up_union_leaf_queries().
|
static |
Definition at line 2473 of file prepjointree.c.
References Assert, fb(), lfirst, parse(), pullup_replace_vars(), replace_vars_in_jointree(), REPLACE_WRAP_NONE, root, RTE_GROUP, RTE_JOIN, and AppendRelInfo::translated_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 1095 of file prepjointree.c.
References eval_const_expressions(), fb(), inline_function_in_from(), lfirst, root, RTE_FUNCTION, and RTE_SUBQUERY.
Referenced by pull_up_simple_subquery(), and subquery_planner().
| Query * preprocess_relation_rtes | ( | PlannerInfo * | root | ) |
Definition at line 417 of file prepjointree.c.
References expand_virtual_generated_columns(), fb(), get_relation_notnullatts(), list_length(), NoLock, parse(), RelationData::rd_rel, root, rt_fetch, RTE_RELATION, table_close(), and table_open().
Referenced by convert_EXISTS_sublink_to_join(), pull_up_simple_subquery(), and subquery_planner().
|
static |
Definition at line 2167 of file prepjointree.c.
References fb(), get_expr_result_type(), IsA, linitial_node, list_length(), list_make1, makeTargetEntry(), NIL, palloc0(), parse(), perform_pullup_replace_vars(), REPLACE_WRAP_ALL, REPLACE_WRAP_NONE, root, RTE_RESULT, and TYPEFUNC_SCALAR.
Referenced by pull_up_subqueries_recurse().
|
static |
Definition at line 1331 of file prepjointree.c.
References PlannerInfo::all_result_relids, PlannerInfo::append_rel_list, Assert, PlannerInfo::assumeReplanning, CombineRangeTables(), copyObject, PlannerInfo::cte_plan_ids, Query::cteList, CurrentMemoryContext, PlannerInfo::ec_merging_done, PlannerInfo::eq_classes, fb(), 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, OffsetVarNodes(), PlannerInfo::outer_params, palloc0(), PlannerInfo::parse, parse(), perform_pullup_replace_vars(), PlannerInfo::placeholder_list, PlannerInfo::placeholdersFrozen, PlannerInfo::plan_name, PlannerInfo::plan_params, preprocess_function_rtes(), preprocess_relation_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, replace_empty_jointree(), REPLACE_WRAP_ALL, REPLACE_WRAP_NONE, 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, substitute_phv_relids(), Query::targetList, PlannerInfo::update_colnos, and PlannerInfo::wt_param_id.
Referenced by pull_up_subqueries_recurse().
|
static |
Definition at line 1681 of file prepjointree.c.
References Assert, CombineRangeTables(), copyObject, fb(), IncrementVarSublevelsUp_rtable(), lfirst, list_length(), pull_up_union_leaf_queries(), root, Query::rtable, RTE_SUBQUERY, and Query::setOperations.
Referenced by pull_up_subqueries_recurse().
|
static |
Definition at line 2011 of file prepjointree.c.
References Assert, contain_vars_of_level(), copyObject, fb(), lappend(), lfirst, linitial, list_length(), list_make1, makeAlias(), makeNode, makeTargetEntry(), NIL, palloc0(), parse(), perform_pullup_replace_vars(), REPLACE_WRAP_NONE, root, RTE_RESULT, and RTE_VALUES.
Referenced by pull_up_subqueries_recurse().
| void pull_up_sublinks | ( | PlannerInfo * | root | ) |
Definition at line 647 of file prepjointree.c.
References fb(), IsA, list_make1, makeFromExpr(), pull_up_sublinks_jointree_recurse(), and root.
Referenced by pull_up_simple_subquery(), and subquery_planner().
|
static |
Definition at line 674 of file prepjointree.c.
References bms_add_member(), bms_join(), bms_make_singleton(), bms_union(), check_stack_depth(), elog, ERROR, fb(), FromExpr::fromlist, IsA, j, JOIN_FULL, JOIN_INNER, JOIN_LEFT, JOIN_RIGHT, lappend(), lfirst, makeFromExpr(), NIL, nodeTag, palloc_object, pull_up_sublinks_jointree_recurse(), pull_up_sublinks_qual_recurse(), FromExpr::quals, and root.
Referenced by pull_up_sublinks(), pull_up_sublinks_jointree_recurse(), and pull_up_sublinks_qual_recurse().
|
static |
Definition at line 831 of file prepjointree.c.
References ANY_SUBLINK, convert_ANY_sublink_to_join(), convert_EXISTS_sublink_to_join(), convert_VALUES_to_ANY(), EXISTS_SUBLINK, fb(), get_notclausearg(), is_andclause(), is_notclause(), IsA, j, lappend(), lfirst, linitial, list_length(), make_andclause(), NIL, pull_up_sublinks_jointree_recurse(), pull_up_sublinks_qual_recurse(), and root.
Referenced by pull_up_sublinks_jointree_recurse(), and pull_up_sublinks_qual_recurse().
| void pull_up_subqueries | ( | PlannerInfo * | root | ) |
Definition at line 1142 of file prepjointree.c.
References Assert, fb(), IsA, pull_up_subqueries_recurse(), and root.
Referenced by pull_up_simple_subquery(), and subquery_planner().
|
static |
Definition at line 1186 of file prepjointree.c.
References Assert, CHECK_FOR_INTERRUPTS, check_stack_depth(), elog, ERROR, fb(), 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(), pull_up_subqueries_recurse(), root, rt_fetch, RTE_FUNCTION, RTE_SUBQUERY, and RTE_VALUES.
Referenced by pull_up_subqueries(), pull_up_subqueries_recurse(), and pull_up_union_leaf_queries().
|
static |
Definition at line 1763 of file prepjointree.c.
References elog, ERROR, fb(), InvalidOid, IsA, lappend(), SetOperationStmt::larg, make_setop_translation_list(), makeNode, nodeTag, pull_up_subqueries_recurse(), pull_up_union_leaf_queries(), SetOperationStmt::rarg, and root.
Referenced by flatten_simple_union_all(), pull_up_simple_union_all(), and pull_up_union_leaf_queries().
|
static |
Definition at line 2687 of file prepjointree.c.
References pullup_replace_vars_context::outer_hasSubLinks, pullup_replace_vars_callback(), replace_rte_variables(), and pullup_replace_vars_context::varno.
Referenced by expand_virtual_generated_columns(), perform_pullup_replace_vars(), and replace_vars_in_jointree().
|
static |
Definition at line 2697 of file prepjointree.c.
References add_nulling_relids(), 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(), replace_rte_variables_context::callback_arg, contain_nonstrict_functions(), contain_vars_of_level(), copyObject, fb(), IncrementVarSublevelsUp(), InvalidAttrNumber, IsA, list_length(), make_placeholder_expr(), nullingrel_info::nullingrels, pull_varnos(), REPLACE_WRAP_ALL, REPLACE_WRAP_NONE, ReplaceVarFromTargetList(), REPLACEVARS_REPORT_ERROR, Var::varattno, and Var::varlevelsup.
Referenced by pullup_replace_vars(), and pullup_replace_vars_subquery().
|
static |
Definition at line 3020 of file prepjointree.c.
References Assert, fb(), IsA, pullup_replace_vars_callback(), replace_rte_variables(), and pullup_replace_vars_context::varno.
Referenced by replace_vars_in_jointree().
| void reduce_outer_joins | ( | PlannerInfo * | root | ) |
Definition at line 3166 of file prepjointree.c.
References bms_is_empty, bms_make_singleton(), elog, ERROR, fb(), lfirst, NIL, reduce_outer_joins_pass1(), reduce_outer_joins_pass2(), remove_nulling_relids(), and root.
Referenced by subquery_planner().
|
static |
Definition at line 3239 of file prepjointree.c.
References bms_add_members(), bms_make_singleton(), reduce_outer_joins_pass1_state::contains_outer, elog, ERROR, fb(), FromExpr::fromlist, IS_OUTER_JOIN, IsA, j, lappend(), lfirst, NIL, nodeTag, palloc_object, reduce_outer_joins_pass1(), reduce_outer_joins_pass1_state::relids, and reduce_outer_joins_pass1_state::sub_states.
Referenced by reduce_outer_joins(), and reduce_outer_joins_pass1().
|
static |
Definition at line 3316 of file prepjointree.c.
References Assert, bms_add_member(), bms_add_members(), bms_free(), bms_overlap(), elog, ERROR, fb(), find_forced_null_vars(), find_nonnullable_rels(), find_nonnullable_vars(), forboth, FromExpr::fromlist, IsA, j, JOIN_ANTI, JOIN_FULL, JOIN_INNER, JOIN_LEFT, JOIN_RIGHT, JOIN_SEMI, lfirst, linitial, list_length(), lsecond, mbms_add_members(), mbms_overlap_sets(), NIL, nodeTag, FromExpr::quals, reduce_outer_joins_pass2(), report_reduced_full_join(), root, rt_fetch, and RTE_JOIN.
Referenced by reduce_outer_joins(), and reduce_outer_joins_pass2().
|
static |
Definition at line 4033 of file prepjointree.c.
References Assert, bms_is_empty, fb(), 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 3659 of file prepjointree.c.
References Assert, bms_is_empty, fb(), 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 3732 of file prepjointree.c.
References Assert, bms_add_member(), bms_next_member(), castNode, elog, ERROR, fb(), 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(), remove_useless_results_recurse(), and root.
Referenced by remove_useless_result_rtes(), and remove_useless_results_recurse().
Definition at line 589 of file prepjointree.c.
References fb(), lappend(), list_length(), list_make1, makeAlias(), makeNode, NIL, parse(), and RTE_RESULT.
Referenced by convert_EXISTS_sublink_to_join(), pull_up_simple_subquery(), and subquery_planner().
|
static |
Definition at line 2580 of file prepjointree.c.
References Assert, elog, ERROR, fb(), FromExpr::fromlist, IsA, j, JOIN_FULL, lfirst, nodeTag, PlannerInfo::parse, pullup_replace_vars(), pullup_replace_vars_subquery(), FromExpr::quals, replace_vars_in_jointree(), REPLACE_WRAP_VARFREE, pullup_replace_vars_context::root, rt_fetch, Query::rtable, RTE_CTE, RTE_FUNCTION, RTE_GROUP, RTE_JOIN, RTE_NAMEDTUPLESTORE, RTE_RELATION, RTE_RESULT, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, pullup_replace_vars_context::target_rte, pullup_replace_vars_context::varno, and pullup_replace_vars_context::wrap_option.
Referenced by perform_pullup_replace_vars(), and replace_vars_in_jointree().
|
static |
Definition at line 3590 of file prepjointree.c.
References fb(), lappend(), and palloc_object.
Referenced by reduce_outer_joins_pass2().
Definition at line 4233 of file prepjointree.c.
References query_or_expression_tree_walker, substitute_phv_relids_context::sublevels_up, substitute_phv_relids_context::subrelids, substitute_phv_relids_walker(), and substitute_phv_relids_context::varno.
Referenced by fix_append_rel_relids(), pull_up_simple_subquery(), and remove_result_refs().
|
static |
Definition at line 4190 of file prepjointree.c.
References Assert, bms_del_member(), bms_is_empty, bms_is_member(), bms_union(), expression_tree_walker, fb(), IsA, query_tree_walker, substitute_phv_relids_context::sublevels_up, substitute_phv_relids_context::subrelids, substitute_phv_relids_walker(), and substitute_phv_relids_context::varno.
Referenced by substitute_phv_relids(), and substitute_phv_relids_walker().
Definition at line 187 of file prepjointree.c.
References add_nulling_relids(), Assert, bms_make_singleton(), CMD_MERGE, CMD_NOTHING, elog, ERROR, fb(), foreach_node, IS_NOT_NULL, IsA, JOIN_FULL, JOIN_INNER, JOIN_LEFT, JOIN_RIGHT, lappend(), linitial, list_length(), list_make1, Var::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, NUM_MERGE_MATCH_KINDS, parse(), rt_fetch, RTE_JOIN, and source.
Referenced by subquery_planner().