PostgreSQL Source Code
git master
|
#include "postgres.h"
#include "access/htup_details.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_type.h"
#include "executor/executor.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "optimizer/clauses.h"
#include "optimizer/cost.h"
#include "optimizer/optimizer.h"
#include "optimizer/paramassign.h"
#include "optimizer/pathnode.h"
#include "optimizer/planmain.h"
#include "optimizer/planner.h"
#include "optimizer/prep.h"
#include "optimizer/subselect.h"
#include "parser/parse_relation.h"
#include "rewrite/rewriteManip.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
Go to the source code of this file.
Data Structures | |
struct | convert_testexpr_context |
struct | process_sublinks_context |
struct | finalize_primnode_context |
struct | inline_cte_walker_context |
Typedefs | |
typedef struct convert_testexpr_context | convert_testexpr_context |
typedef struct process_sublinks_context | process_sublinks_context |
typedef struct finalize_primnode_context | finalize_primnode_context |
typedef struct inline_cte_walker_context | inline_cte_walker_context |
typedef struct convert_testexpr_context convert_testexpr_context |
typedef struct finalize_primnode_context finalize_primnode_context |
typedef struct inline_cte_walker_context inline_cte_walker_context |
typedef struct process_sublinks_context process_sublinks_context |
|
static |
Definition at line 320 of file subselect.c.
References ANY_SUBLINK, arg, ARRAY_SUBLINK, Assert(), bms_add_member(), convert_testexpr(), cost_subplan(), elog(), enable_material, ERROR, ExecMaterializesOutput(), EXISTS_SUBLINK, TargetEntry::expr, EXPR_SUBLINK, exprCollation(), exprType(), exprTypmod(), format_type_be(), generate_new_exec_param(), generate_subquery_params(), get_first_col_type(), get_promoted_array_type(), PlannerInfo::glob, PlannerInfo::init_plans, InvalidOid, IsA, PlannerParamItem::item, lappend(), lappend_int(), lfirst, lfirst_int, linitial, list_copy(), list_length(), list_make1_int, list_nth_cell(), lnext(), makeNode, makeNullConst(), materialize_finished_plan(), PlannerInfo::multiexpr_params, MULTIEXPR_SUBLINK, NIL, nodeTag, OidIsValid, palloc(), PlannerParamItem::paramId, Param::paramid, plan, PlannerGlobal::rewindPlanIDs, ROWCOMPARE_SUBLINK, splan, sprintf, SS_process_sublinks(), subplan_is_hashable(), PlannerGlobal::subplans, and testexpr_is_hashable().
Referenced by make_subplan().
Definition at line 1069 of file subselect.c.
References contain_dml_walker().
Referenced by SS_process_ctes().
Definition at line 1075 of file subselect.c.
References CMD_SELECT, Query::commandType, expression_tree_walker, IsA, NIL, query_tree_walker, and Query::rowMarks.
Referenced by contain_dml().
Definition at line 1096 of file subselect.c.
References Assert(), contain_outer_selfref_walker(), and IsA.
Referenced by SS_process_ctes().
Definition at line 1110 of file subselect.c.
References RangeTblEntry::ctelevelsup, expression_tree_walker, IsA, QTW_EXAMINE_RTES_BEFORE, query_tree_walker, RTE_CTE, RangeTblEntry::rtekind, and RangeTblEntry::self_reference.
Referenced by contain_outer_selfref().
JoinExpr* convert_ANY_sublink_to_join | ( | PlannerInfo * | root, |
SubLink * | sublink, | ||
Relids | available_rels | ||
) |
Definition at line 1267 of file subselect.c.
References addRangeTableEntryForSubquery(), ANY_SUBLINK, Assert(), bms_is_empty, bms_is_subset(), contain_vars_of_level(), contain_volatile_functions(), convert_testexpr(), generate_subquery_vars(), JoinExpr::isNatural, JOIN_SEMI, JoinExpr::jointype, lappend(), JoinExpr::larg, list_length(), make_parsestate(), makeAlias(), makeNode, NIL, parse(), PlannerInfo::parse, pull_varnos(), JoinExpr::quals, JoinExpr::rarg, JoinExpr::rtindex, SubLink::subLinkType, SubLink::subselect, Query::targetList, and SubLink::testexpr.
Referenced by pull_up_sublinks_qual_recurse().
JoinExpr* convert_EXISTS_sublink_to_join | ( | PlannerInfo * | root, |
SubLink * | sublink, | ||
bool | under_not, | ||
Relids | available_rels | ||
) |
Definition at line 1375 of file subselect.c.
References Assert(), bms_add_member(), bms_free(), bms_is_empty, bms_is_subset(), bms_next_member(), CombineRangeTables(), contain_vars_of_level(), contain_volatile_functions(), copyObject, Query::cteList, EXISTS_SUBLINK, FromExpr::fromlist, IncrementVarSublevelsUp(), JoinExpr::isNatural, JOIN_ANTI, JOIN_SEMI, Query::jointree, JoinExpr::jointype, JoinExpr::larg, linitial, list_length(), makeNode, NIL, OffsetVarNodes(), parse(), PlannerInfo::parse, pull_varnos(), JoinExpr::quals, FromExpr::quals, JoinExpr::rarg, replace_empty_jointree(), Query::rtable, JoinExpr::rtindex, simplify_EXISTS_query(), SubLink::subLinkType, and SubLink::subselect.
Referenced by pull_up_sublinks_qual_recurse().
|
static |
Definition at line 1632 of file subselect.c.
References OpExpr::args, Assert(), canonicalize_qual(), contain_aggs_of_level(), contain_subplans(), contain_vars_of_level(), contain_volatile_functions(), eval_const_expressions(), exprCollation(), exprType(), exprTypmod(), forfour, generate_new_exec_param(), get_commutator(), hash_ok_operator(), IncrementVarSublevelsUp(), InvalidOid, IsA, Query::jointree, lappend(), lappend_int(), lappend_oid(), lfirst, lfirst_oid, linitial, lsecond, make_ands_explicit(), make_ands_implicit(), make_opclause(), makeTargetEntry(), NIL, OidIsValid, OpExpr::opno, Param::paramid, PlannerInfo::parse, FromExpr::quals, and Query::targetList.
Referenced by make_subplan().
|
static |
Definition at line 655 of file subselect.c.
References convert_testexpr_mutator(), convert_testexpr_context::root, and convert_testexpr_context::subst_nodes.
Referenced by build_subplan(), and convert_ANY_sublink_to_join().
|
static |
Definition at line 667 of file subselect.c.
References copyObject, elog(), ERROR, expression_tree_mutator, IsA, list_length(), list_nth(), PARAM_SUBLINK, Param::paramid, Param::paramkind, and convert_testexpr_context::subst_nodes.
Referenced by convert_testexpr().
|
static |
Definition at line 2971 of file subselect.c.
References Aggref::aggfilter, Aggref::args, expression_tree_walker, finalize_primnode(), and IsA.
Referenced by finalize_plan().
|
static |
Definition at line 2289 of file subselect.c.
References AGG_HASHED, Agg::aggParams, Agg::aggstrategy, Assert(), bms_add_member(), bms_add_members(), bms_copy(), bms_del_member(), bms_del_members(), bms_difference(), bms_free(), bms_is_subset(), bms_union(), CustomScan::custom_exprs, CustomScan::custom_plans, elog(), ModifyTable::epqParam, ERROR, Plan::extParam, ForeignScan::fdw_exprs, ForeignScan::fdw_recheck_quals, finalize_agg_primnode(), finalize_primnode(), find_base_rel(), RangeTblFunction::funcexpr, FunctionScan::functions, PlannerInfo::glob, lfirst, lfirst_int, list_length(), list_nth(), nodeTag, ModifyTable::onConflictSet, ModifyTable::onConflictWhere, PlannerInfo::outer_params, finalize_primnode_context::paramids, NestLoopParam::paramno, Agg::plan, plan, planner_subplan_get_plan, Plan::qual, ModifyTable::returningLists, finalize_primnode_context::root, SubqueryScan::scan, Scan::scanrelid, SubPlan::setParam, SubqueryScan::subplan, PlannerGlobal::subplans, RelOptInfo::subroot, and Plan::targetlist.
Referenced by SS_finalize_plan().
|
static |
Definition at line 2887 of file subselect.c.
References SubPlan::args, bms_add_member(), bms_copy(), bms_del_member(), bms_join(), expression_tree_walker, find_minmax_agg_replacement_param(), IsA, lfirst_int, PARAM_EXEC, Param::paramid, finalize_primnode_context::paramids, SubPlan::paramIds, SubPlan::parParam, plan, planner_subplan_get_plan, finalize_primnode_context::root, and SubPlan::testexpr.
Referenced by finalize_agg_primnode(), and finalize_plan().
|
static |
Definition at line 593 of file subselect.c.
References TargetEntry::expr, exprCollation(), exprType(), exprTypmod(), generate_new_exec_param(), lappend(), lappend_int(), lfirst, NIL, and Param::paramid.
Referenced by build_subplan().
|
static |
Definition at line 626 of file subselect.c.
References lappend(), lfirst, makeVarFromTargetEntry(), and NIL.
Referenced by convert_ANY_sublink_to_join().
|
static |
Definition at line 118 of file subselect.c.
References TargetEntry::expr, exprCollation(), exprType(), exprTypmod(), InvalidOid, linitial_node, and plan.
Referenced by build_subplan(), SS_make_initplan_from_plan(), and SS_process_ctes().
Definition at line 845 of file subselect.c.
References OpExpr::args, elog(), ERROR, exprType(), func_strict(), GETSTRUCT, HeapTupleIsValid, linitial, list_length(), ObjectIdGetDatum(), op_hashjoinable(), OPEROID, OpExpr::opno, ReleaseSysCache(), and SearchSysCache1().
Referenced by convert_EXISTS_to_ANY(), and test_opexpr_is_hashable().
|
static |
Definition at line 1151 of file subselect.c.
References castNode, inline_cte_walker_context::ctename, CommonTableExpr::ctename, inline_cte_walker_context::ctequery, CommonTableExpr::ctequery, inline_cte_walker(), inline_cte_walker_context::levelsup, and PlannerInfo::parse.
Referenced by SS_process_ctes().
|
static |
Definition at line 1164 of file subselect.c.
References RangeTblEntry::colcollations, RangeTblEntry::coltypes, RangeTblEntry::coltypmods, copyObject, RangeTblEntry::ctelevelsup, inline_cte_walker_context::ctename, RangeTblEntry::ctename, inline_cte_walker_context::ctequery, expression_tree_walker, IncrementVarSublevelsUp(), IsA, inline_cte_walker_context::levelsup, NIL, QTW_EXAMINE_RTES_AFTER, query_tree_walker, RTE_CTE, RTE_SUBQUERY, RangeTblEntry::rtekind, RangeTblEntry::security_barrier, RangeTblEntry::self_reference, and RangeTblEntry::subquery.
Referenced by inline_cte().
|
static |
Definition at line 162 of file subselect.c.
References ALL_SUBLINK, ANY_SUBLINK, Assert(), build_subplan(), castNode, RelOptInfo::cheapest_total_path, convert_EXISTS_to_ANY(), copyObject, create_plan(), EXISTS_SUBLINK, fetch_upper_rel(), get_cheapest_fractional_path(), PlannerInfo::glob, PlannerInfo::hasAlternativeSubPlans, IsA, list_make2, makeNode, NIL, SubPlan::parParam, plan, PlannerInfo::plan_params, simplify_EXISTS_query(), subpath_is_hashable(), AlternativeSubPlan::subplans, subquery_planner(), UPPERREL_FINAL, and SubPlan::useHashTable.
Referenced by process_sublinks_mutator().
|
static |
Definition at line 1926 of file subselect.c.
References generate_unaccent_rules::args, Assert(), expression_tree_mutator, is_andclause(), is_orclause(), IsA, process_sublinks_context::isTopQual, lappend(), lfirst, list_concat(), make_andclause(), make_orclause(), make_subplan(), NIL, process_sublinks_context::root, SubLink::subLinkId, SubLink::subLinkType, SubLink::subselect, and SubLink::testexpr.
Referenced by SS_process_sublinks().
|
static |
Definition at line 1878 of file subselect.c.
References expression_tree_mutator, IsA, replace_outer_agg(), replace_outer_grouping(), replace_outer_placeholdervar(), and replace_outer_var().
Referenced by SS_replace_correlation_vars().
|
static |
Definition at line 1544 of file subselect.c.
References Assert(), CMD_SELECT, Query::commandType, Const::consttype, DatumGetInt64(), Query::distinctClause, eval_const_expressions(), Query::groupClause, Query::groupingSets, Query::havingQual, IsA, Query::limitCount, Query::limitOffset, NIL, Query::rowMarks, Query::setOperations, Query::sortClause, Query::targetList, and Query::windowClause.
Referenced by convert_EXISTS_sublink_to_join(), and make_subplan().
void SS_attach_initplans | ( | PlannerInfo * | root, |
Plan * | plan | ||
) |
Definition at line 2236 of file subselect.c.
References PlannerInfo::init_plans, and plan.
Referenced by create_plan().
void SS_charge_for_initplans | ( | PlannerInfo * | root, |
RelOptInfo * | final_rel | ||
) |
Definition at line 2131 of file subselect.c.
References RelOptInfo::consider_parallel, PlannerInfo::init_plans, lfirst, NIL, Path::parallel_safe, RelOptInfo::partial_pathlist, RelOptInfo::pathlist, SS_compute_initplan_cost(), Path::startup_cost, and Path::total_cost.
Referenced by build_minmax_path(), and subquery_planner().
void SS_compute_initplan_cost | ( | List * | init_plans, |
Cost * | initplan_cost_p, | ||
bool * | unsafe_initplans_p | ||
) |
Definition at line 2195 of file subselect.c.
References lfirst_node, SubPlan::parallel_safe, SubPlan::per_call_cost, and SubPlan::startup_cost.
Referenced by clean_up_removed_plan_level(), materialize_finished_plan(), SS_charge_for_initplans(), and standard_planner().
void SS_finalize_plan | ( | PlannerInfo * | root, |
Plan * | plan | ||
) |
Definition at line 2251 of file subselect.c.
References finalize_plan(), PlannerInfo::outer_params, and plan.
Referenced by standard_planner().
void SS_identify_outer_params | ( | PlannerInfo * | root | ) |
Definition at line 2069 of file subselect.c.
References bms_add_member(), PlannerInfo::glob, PlannerInfo::init_plans, lfirst, lfirst_int, NIL, PlannerInfo::outer_params, PlannerGlobal::paramExecTypes, PlannerParamItem::paramId, PlannerInfo::plan_params, SubPlan::setParam, and PlannerInfo::wt_param_id.
Referenced by build_minmax_path(), and subquery_planner().
void SS_make_initplan_from_plan | ( | PlannerInfo * | root, |
PlannerInfo * | subroot, | ||
Plan * | plan, | ||
Param * | prm | ||
) |
Definition at line 3014 of file subselect.c.
References cost_subplan(), EXPR_SUBLINK, SubPlan::firstColCollation, SubPlan::firstColType, SubPlan::firstColTypmod, get_first_col_type(), PlannerInfo::glob, PlannerInfo::init_plans, lappend(), list_length(), list_make1_int, makeNode, SubPlan::parallel_safe, Param::paramid, plan, SubPlan::plan_id, SubPlan::plan_name, psprintf(), SubPlan::setParam, SubPlan::subLinkType, and PlannerGlobal::subplans.
Referenced by create_minmaxagg_plan().
Param* SS_make_initplan_output_param | ( | PlannerInfo * | root, |
Oid | resulttype, | ||
int32 | resulttypmod, | ||
Oid | resultcollation | ||
) |
Definition at line 2998 of file subselect.c.
References generate_new_exec_param().
Referenced by preprocess_minmax_aggregates().
void SS_process_ctes | ( | PlannerInfo * | root | ) |
Definition at line 893 of file subselect.c.
References Assert(), assign_special_exec_param(), RelOptInfo::cheapest_total_path, CMD_SELECT, contain_dml(), contain_outer_selfref(), contain_volatile_functions(), copyObject, cost_subplan(), create_plan(), PlannerInfo::cte_plan_ids, CTE_SUBLINK, Query::cteList, CommonTableExpr::ctematerialized, CTEMaterializeDefault, CTEMaterializeNever, CommonTableExpr::ctename, CommonTableExpr::ctequery, elog(), ERROR, fetch_upper_rel(), get_first_col_type(), PlannerInfo::glob, PlannerInfo::init_plans, inline_cte(), lappend(), lappend_int(), lfirst, list_length(), list_make1_int, makeNode, NIL, PlannerInfo::parse, plan, PlannerInfo::plan_params, psprintf(), splan, PlannerGlobal::subplans, subquery_planner(), and UPPERREL_FINAL.
Referenced by subquery_planner().
Node* SS_process_sublinks | ( | PlannerInfo * | root, |
Node * | expr, | ||
bool | isQual | ||
) |
Definition at line 1916 of file subselect.c.
References process_sublinks_context::isTopQual, process_sublinks_mutator(), and process_sublinks_context::root.
Referenced by build_subplan(), and preprocess_expression().
Node* SS_replace_correlation_vars | ( | PlannerInfo * | root, |
Node * | expr | ||
) |
Definition at line 1871 of file subselect.c.
References replace_correlation_vars_mutator().
Referenced by preprocess_expression().
Definition at line 749 of file subselect.c.
References get_hash_memory_limit(), MAXALIGN, Path::rows, and SizeofHeapTupleHeader.
Referenced by make_subplan().
Definition at line 725 of file subselect.c.
References get_hash_memory_limit(), MAXALIGN, plan, and SizeofHeapTupleHeader.
Referenced by build_subplan().
Definition at line 805 of file subselect.c.
References OpExpr::args, contain_exec_param(), contain_var_clause(), hash_ok_operator(), linitial, list_length(), and lsecond.
Referenced by testexpr_is_hashable().
Definition at line 774 of file subselect.c.
References generate_unaccent_rules::args, is_andclause(), IsA, lfirst, and test_opexpr_is_hashable().
Referenced by build_subplan().