mirror of
https://github.com/postgres/postgres.git
synced 2025-11-06 07:49:08 +03:00
Simplify ParamListInfo data structure to support only numbered parameters,
not named ones, and replace linear searches of the list with array indexing. The named-parameter support has been dead code for many years anyway, and recent profiling suggests that the searching was costing a noticeable amount of performance for complex queries.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.104 2006/03/05 15:58:30 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.105 2006/04/22 01:25:59 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -163,7 +163,7 @@ replace_outer_var(Var *var)
|
||||
|
||||
retval = makeNode(Param);
|
||||
retval->paramkind = PARAM_EXEC;
|
||||
retval->paramid = (AttrNumber) i;
|
||||
retval->paramid = i;
|
||||
retval->paramtype = var->vartype;
|
||||
|
||||
return retval;
|
||||
@@ -201,7 +201,7 @@ replace_outer_agg(Aggref *agg)
|
||||
|
||||
retval = makeNode(Param);
|
||||
retval->paramkind = PARAM_EXEC;
|
||||
retval->paramid = (AttrNumber) i;
|
||||
retval->paramid = i;
|
||||
retval->paramtype = agg->aggtype;
|
||||
|
||||
return retval;
|
||||
@@ -222,7 +222,7 @@ generate_new_param(Oid paramtype, int32 paramtypmod)
|
||||
|
||||
retval = makeNode(Param);
|
||||
retval->paramkind = PARAM_EXEC;
|
||||
retval->paramid = (AttrNumber) list_length(PlannerParamList);
|
||||
retval->paramid = list_length(PlannerParamList);
|
||||
retval->paramtype = paramtype;
|
||||
|
||||
pitem = (PlannerParamItem *) palloc(sizeof(PlannerParamItem));
|
||||
@@ -1211,7 +1211,7 @@ finalize_primnode(Node *node, finalize_primnode_context *context)
|
||||
{
|
||||
if (((Param *) node)->paramkind == PARAM_EXEC)
|
||||
{
|
||||
int paramid = (int) ((Param *) node)->paramid;
|
||||
int paramid = ((Param *) node)->paramid;
|
||||
|
||||
context->paramids = bms_add_member(context->paramids, paramid);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.210 2006/03/14 22:48:19 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.211 2006/04/22 01:25:59 tgl Exp $
|
||||
*
|
||||
* HISTORY
|
||||
* AUTHOR DATE MAJOR EVENT
|
||||
@@ -1500,36 +1500,35 @@ eval_const_expressions_mutator(Node *node,
|
||||
Param *param = (Param *) node;
|
||||
|
||||
/* OK to try to substitute value? */
|
||||
if (context->estimate && param->paramkind != PARAM_EXEC &&
|
||||
if (context->estimate && param->paramkind == PARAM_EXTERN &&
|
||||
PlannerBoundParamList != NULL)
|
||||
{
|
||||
ParamListInfo paramInfo;
|
||||
|
||||
/* Search to see if we've been given a value for this Param */
|
||||
paramInfo = lookupParam(PlannerBoundParamList,
|
||||
param->paramkind,
|
||||
param->paramname,
|
||||
param->paramid,
|
||||
true);
|
||||
if (paramInfo)
|
||||
/* Look to see if we've been given a value for this Param */
|
||||
if (param->paramid > 0 &&
|
||||
param->paramid <= PlannerBoundParamList->numParams)
|
||||
{
|
||||
/*
|
||||
* Found it, so return a Const representing the param value.
|
||||
* Note that we don't copy pass-by-ref datatypes, so the Const
|
||||
* will only be valid as long as the bound parameter list
|
||||
* exists. This is okay for intended uses of
|
||||
* estimate_expression_value().
|
||||
*/
|
||||
int16 typLen;
|
||||
bool typByVal;
|
||||
ParamExternData *prm = &PlannerBoundParamList->params[param->paramid - 1];
|
||||
|
||||
Assert(paramInfo->ptype == param->paramtype);
|
||||
get_typlenbyval(param->paramtype, &typLen, &typByVal);
|
||||
return (Node *) makeConst(param->paramtype,
|
||||
(int) typLen,
|
||||
paramInfo->value,
|
||||
paramInfo->isnull,
|
||||
typByVal);
|
||||
if (OidIsValid(prm->ptype))
|
||||
{
|
||||
/*
|
||||
* Found it, so return a Const representing the param
|
||||
* value. Note that we don't copy pass-by-ref datatypes,
|
||||
* so the Const will only be valid as long as the bound
|
||||
* parameter list exists. This is okay for intended uses
|
||||
* of estimate_expression_value().
|
||||
*/
|
||||
int16 typLen;
|
||||
bool typByVal;
|
||||
|
||||
Assert(prm->ptype == param->paramtype);
|
||||
get_typlenbyval(param->paramtype, &typLen, &typByVal);
|
||||
return (Node *) makeConst(param->paramtype,
|
||||
(int) typLen,
|
||||
prm->value,
|
||||
prm->isnull,
|
||||
typByVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Not replaceable, so just copy the Param (no need to recurse) */
|
||||
@@ -2810,8 +2809,8 @@ substitute_actual_parameters_mutator(Node *node,
|
||||
{
|
||||
Param *param = (Param *) node;
|
||||
|
||||
if (param->paramkind != PARAM_NUM)
|
||||
elog(ERROR, "unexpected paramkind: %d", param->paramkind);
|
||||
if (param->paramkind != PARAM_EXTERN)
|
||||
elog(ERROR, "unexpected paramkind: %d", (int) param->paramkind);
|
||||
if (param->paramid <= 0 || param->paramid > context->nargs)
|
||||
elog(ERROR, "invalid paramid: %d", param->paramid);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user