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 319 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(), InvalidOid, IsA, PlannerParamItem::item, lappend(), lappend_int(), lfirst, linitial, list_copy(), list_length(), list_make1_int, list_nth_cell(), makeNode, makeNullConst(), materialize_finished_plan(), MULTIEXPR_SUBLINK, NIL, nodeTag, OidIsValid, PlannerParamItem::paramId, Param::paramid, plan, psprintf(), root, ROWCOMPARE_SUBLINK, splan, SS_process_sublinks(), subplan_is_hashable(), and testexpr_is_hashable().
Referenced by make_subplan().
|
static |
Definition at line 1054 of file subselect.c.
References contain_dml_walker().
Referenced by SS_process_ctes().
|
static |
Definition at line 1060 of file subselect.c.
References CMD_SELECT, Query::commandType, context, expression_tree_walker, IsA, NIL, query_tree_walker, and Query::rowMarks.
Referenced by contain_dml().
|
static |
Definition at line 1081 of file subselect.c.
References Assert, contain_outer_selfref_walker(), and IsA.
Referenced by SS_process_ctes().
Definition at line 1095 of file subselect.c.
References RangeTblEntry::ctelevelsup, expression_tree_walker, IsA, QTW_EXAMINE_RTES_BEFORE, query_tree_walker, RTE_CTE, and RangeTblEntry::rtekind.
Referenced by contain_outer_selfref().
JoinExpr* convert_ANY_sublink_to_join | ( | PlannerInfo * | root, |
SubLink * | sublink, | ||
Relids | available_rels | ||
) |
Definition at line 1251 of file subselect.c.
References addRangeTableEntryForSubquery(), ANY_SUBLINK, Assert, bms_is_empty, bms_is_subset(), 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(), pull_varnos(), pull_varnos_of_level(), JoinExpr::quals, JoinExpr::rarg, root, 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 1368 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(), pull_varnos(), JoinExpr::quals, FromExpr::quals, JoinExpr::rarg, replace_empty_jointree(), root, Query::rtable, JoinExpr::rtindex, simplify_EXISTS_query(), SubLink::subLinkType, and SubLink::subselect.
Referenced by pull_up_sublinks_qual_recurse().
|
static |
Definition at line 1649 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, FromExpr::quals, root, and Query::targetList.
Referenced by make_subplan().
|
static |
Definition at line 642 of file subselect.c.
References context, convert_testexpr_mutator(), and root.
Referenced by build_subplan(), and convert_ANY_sublink_to_join().
|
static |
Definition at line 654 of file subselect.c.
References context, copyObject, elog, ERROR, expression_tree_mutator, IsA, list_length(), list_nth(), PARAM_SUBLINK, Param::paramid, and Param::paramkind.
Referenced by convert_testexpr().
|
static |
Definition at line 2992 of file subselect.c.
References Aggref::aggfilter, Aggref::args, context, expression_tree_walker, finalize_primnode(), and IsA.
Referenced by finalize_plan().
|
static |
Definition at line 2311 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(), context, 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, 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, root, SubqueryScan::scan, Scan::scanrelid, SubPlan::setParam, SubqueryScan::subplan, RelOptInfo::subroot, and Plan::targetlist.
Referenced by SS_finalize_plan().
|
static |
Definition at line 2909 of file subselect.c.
References SubPlan::args, bms_add_member(), bms_copy(), bms_del_member(), bms_join(), context, expression_tree_walker, find_minmax_agg_replacement_param(), IsA, lfirst_int, PARAM_EXEC, Param::paramid, SubPlan::paramIds, SubPlan::parParam, plan, planner_subplan_get_plan, and SubPlan::testexpr.
Referenced by finalize_agg_primnode(), and finalize_plan().
|
static |
Definition at line 580 of file subselect.c.
References TargetEntry::expr, exprCollation(), exprType(), exprTypmod(), generate_new_exec_param(), lappend(), lappend_int(), lfirst, NIL, Param::paramid, and root.
Referenced by build_subplan().
|
static |
Definition at line 613 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().
|
static |
Definition at line 830 of file subselect.c.
References OpExpr::args, elog, ERROR, exprType(), func_strict(), GETSTRUCT, HeapTupleIsValid, linitial, list_length(), ObjectIdGetDatum(), op_hashjoinable(), OpExpr::opno, ReleaseSysCache(), and SearchSysCache1().
Referenced by convert_EXISTS_to_ANY(), and test_opexpr_is_hashable().
|
static |
Definition at line 1135 of file subselect.c.
References castNode, context, CommonTableExpr::ctename, CommonTableExpr::ctequery, inline_cte_walker(), and root.
Referenced by SS_process_ctes().
|
static |
Definition at line 1148 of file subselect.c.
References context, copyObject, RangeTblEntry::ctelevelsup, RangeTblEntry::ctename, expression_tree_walker, IncrementVarSublevelsUp(), IsA, NIL, QTW_EXAMINE_RTES_AFTER, query_tree_walker, RTE_CTE, RTE_SUBQUERY, RangeTblEntry::rtekind, 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(), IsA, list_make2, makeNode, NIL, SubPlan::parParam, plan, root, simplify_EXISTS_query(), subpath_is_hashable(), AlternativeSubPlan::subplans, subquery_planner(), UPPERREL_FINAL, and SubPlan::useHashTable.
Referenced by process_sublinks_mutator().
|
static |
Definition at line 1948 of file subselect.c.
References generate_unaccent_rules::args, Assert, context, 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 1896 of file subselect.c.
References CMD_MERGE, expression_tree_mutator, IsA, replace_outer_agg(), replace_outer_grouping(), replace_outer_merge_support(), replace_outer_placeholdervar(), replace_outer_var(), and root.
Referenced by SS_replace_correlation_vars().
|
static |
Definition at line 1537 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, lfirst_node, Query::limitCount, Query::limitOffset, list_delete_cell(), NIL, root, Query::rowMarks, Query::rtable, RTE_GROUP, RangeTblEntry::rtekind, 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 2258 of file subselect.c.
Referenced by create_plan().
void SS_charge_for_initplans | ( | PlannerInfo * | root, |
RelOptInfo * | final_rel | ||
) |
Definition at line 2153 of file subselect.c.
References RelOptInfo::consider_parallel, lfirst, NIL, Path::parallel_safe, RelOptInfo::partial_pathlist, RelOptInfo::pathlist, root, 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 2217 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 2273 of file subselect.c.
References finalize_plan(), plan, and root.
Referenced by standard_planner().
void SS_identify_outer_params | ( | PlannerInfo * | root | ) |
Definition at line 2091 of file subselect.c.
References bms_add_member(), PlannerInfo::init_plans, lfirst, lfirst_int, NIL, PlannerParamItem::paramId, PlannerInfo::plan_params, root, 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 3034 of file subselect.c.
References cost_subplan(), EXPR_SUBLINK, SubPlan::firstColCollation, SubPlan::firstColType, SubPlan::firstColTypmod, get_first_col_type(), lappend(), list_length(), list_make1_int, makeNode, SubPlan::parallel_safe, Param::paramid, plan, SubPlan::plan_id, SubPlan::plan_name, psprintf(), root, SubPlan::setParam, and SubPlan::subLinkType.
Referenced by create_minmaxagg_plan().
Param* SS_make_initplan_output_param | ( | PlannerInfo * | root, |
Oid | resulttype, | ||
int32 | resulttypmod, | ||
Oid | resultcollation | ||
) |
Definition at line 3018 of file subselect.c.
References generate_new_exec_param(), and root.
Referenced by preprocess_minmax_aggregates().
void SS_process_ctes | ( | PlannerInfo * | root | ) |
Definition at line 878 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(), CTE_SUBLINK, CommonTableExpr::ctematerialized, CTEMaterializeDefault, CTEMaterializeNever, CommonTableExpr::ctename, CommonTableExpr::ctequery, elog, ERROR, fetch_upper_rel(), get_first_col_type(), inline_cte(), lappend(), lappend_int(), lfirst, list_length(), list_make1_int, makeNode, NIL, plan, psprintf(), root, splan, subquery_planner(), and UPPERREL_FINAL.
Referenced by subquery_planner().
Node* SS_process_sublinks | ( | PlannerInfo * | root, |
Node * | expr, | ||
bool | isQual | ||
) |
Definition at line 1938 of file subselect.c.
References context, process_sublinks_mutator(), and root.
Referenced by build_subplan(), and preprocess_expression().
Node* SS_replace_correlation_vars | ( | PlannerInfo * | root, |
Node * | expr | ||
) |
Definition at line 1889 of file subselect.c.
References replace_correlation_vars_mutator(), and root.
Referenced by preprocess_expression().
|
static |
Definition at line 734 of file subselect.c.
References get_hash_memory_limit(), MAXALIGN, Path::rows, and SizeofHeapTupleHeader.
Referenced by make_subplan().
|
static |
Definition at line 710 of file subselect.c.
References get_hash_memory_limit(), MAXALIGN, plan, and SizeofHeapTupleHeader.
Referenced by build_subplan().
Definition at line 790 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 759 of file subselect.c.
References generate_unaccent_rules::args, is_andclause(), IsA, lfirst, and test_opexpr_is_hashable().
Referenced by build_subplan().