mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +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:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.189 2006/03/10 01:51:23 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.190 2006/04/22 01:25:58 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -605,13 +605,12 @@ ExecEvalParam(ExprState *exprstate, ExprContext *econtext,
|
||||
bool *isNull, ExprDoneCond *isDone)
|
||||
{
|
||||
Param *expression = (Param *) exprstate->expr;
|
||||
int thisParamKind = expression->paramkind;
|
||||
AttrNumber thisParamId = expression->paramid;
|
||||
int thisParamId = expression->paramid;
|
||||
|
||||
if (isDone)
|
||||
*isDone = ExprSingleResult;
|
||||
|
||||
if (thisParamKind == PARAM_EXEC)
|
||||
if (expression->paramkind == PARAM_EXEC)
|
||||
{
|
||||
/*
|
||||
* PARAM_EXEC params (internal executor parameters) are stored in the
|
||||
@ -633,18 +632,27 @@ ExecEvalParam(ExprState *exprstate, ExprContext *econtext,
|
||||
else
|
||||
{
|
||||
/*
|
||||
* All other parameter types must be sought in ecxt_param_list_info.
|
||||
* PARAM_EXTERN parameters must be sought in ecxt_param_list_info.
|
||||
*/
|
||||
ParamListInfo paramInfo;
|
||||
ParamListInfo paramInfo = econtext->ecxt_param_list_info;
|
||||
|
||||
paramInfo = lookupParam(econtext->ecxt_param_list_info,
|
||||
thisParamKind,
|
||||
expression->paramname,
|
||||
thisParamId,
|
||||
false);
|
||||
Assert(paramInfo->ptype == expression->paramtype);
|
||||
*isNull = paramInfo->isnull;
|
||||
return paramInfo->value;
|
||||
Assert(expression->paramkind == PARAM_EXTERN);
|
||||
if (paramInfo &&
|
||||
thisParamId > 0 && thisParamId <= paramInfo->numParams)
|
||||
{
|
||||
ParamExternData *prm = ¶mInfo->params[thisParamId - 1];
|
||||
|
||||
if (OidIsValid(prm->ptype))
|
||||
{
|
||||
Assert(prm->ptype == expression->paramtype);
|
||||
*isNull = prm->isnull;
|
||||
return prm->value;
|
||||
}
|
||||
}
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("no value found for parameter %d", thisParamId)));
|
||||
return (Datum) 0; /* keep compiler quiet */
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/executor/functions.c,v 1.101 2006/03/05 15:58:26 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/executor/functions.c,v 1.102 2006/04/22 01:25:58 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -431,17 +431,19 @@ postquel_sub_params(SQLFunctionCachePtr fcache,
|
||||
{
|
||||
int i;
|
||||
|
||||
paramLI = (ParamListInfo) palloc0((nargs + 1) * sizeof(ParamListInfoData));
|
||||
/* sizeof(ParamListInfoData) includes the first array element */
|
||||
paramLI = (ParamListInfo) palloc(sizeof(ParamListInfoData) +
|
||||
(nargs - 1) * sizeof(ParamExternData));
|
||||
paramLI->numParams = nargs;
|
||||
|
||||
for (i = 0; i < nargs; i++)
|
||||
{
|
||||
paramLI[i].kind = PARAM_NUM;
|
||||
paramLI[i].id = i + 1;
|
||||
paramLI[i].ptype = fcache->argtypes[i];
|
||||
paramLI[i].value = fcinfo->arg[i];
|
||||
paramLI[i].isnull = fcinfo->argnull[i];
|
||||
ParamExternData *prm = ¶mLI->params[i];
|
||||
|
||||
prm->value = fcinfo->arg[i];
|
||||
prm->isnull = fcinfo->argnull[i];
|
||||
prm->ptype = fcache->argtypes[i];
|
||||
}
|
||||
paramLI[nargs].kind = PARAM_INVALID;
|
||||
}
|
||||
else
|
||||
paramLI = NULL;
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.150 2006/04/04 19:35:34 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.151 2006/04/22 01:25:58 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -885,19 +885,21 @@ SPI_cursor_open(const char *name, void *plan,
|
||||
/* If the plan has parameters, set them up */
|
||||
if (spiplan->nargs > 0)
|
||||
{
|
||||
paramLI = (ParamListInfo) palloc0((spiplan->nargs + 1) *
|
||||
sizeof(ParamListInfoData));
|
||||
/* sizeof(ParamListInfoData) includes the first array element */
|
||||
paramLI = (ParamListInfo) palloc(sizeof(ParamListInfoData) +
|
||||
(spiplan->nargs - 1) * sizeof(ParamExternData));
|
||||
paramLI->numParams = spiplan->nargs;
|
||||
|
||||
for (k = 0; k < spiplan->nargs; k++)
|
||||
{
|
||||
paramLI[k].kind = PARAM_NUM;
|
||||
paramLI[k].id = k + 1;
|
||||
paramLI[k].ptype = spiplan->argtypes[k];
|
||||
paramLI[k].isnull = (Nulls && Nulls[k] == 'n');
|
||||
if (paramLI[k].isnull)
|
||||
ParamExternData *prm = ¶mLI->params[k];
|
||||
|
||||
prm->ptype = spiplan->argtypes[k];
|
||||
prm->isnull = (Nulls && Nulls[k] == 'n');
|
||||
if (prm->isnull)
|
||||
{
|
||||
/* nulls just copy */
|
||||
paramLI[k].value = Values[k];
|
||||
prm->value = Values[k];
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -905,13 +907,11 @@ SPI_cursor_open(const char *name, void *plan,
|
||||
int16 paramTypLen;
|
||||
bool paramTypByVal;
|
||||
|
||||
get_typlenbyval(spiplan->argtypes[k],
|
||||
¶mTypLen, ¶mTypByVal);
|
||||
paramLI[k].value = datumCopy(Values[k],
|
||||
paramTypByVal, paramTypLen);
|
||||
get_typlenbyval(prm->ptype, ¶mTypLen, ¶mTypByVal);
|
||||
prm->value = datumCopy(Values[k],
|
||||
paramTypByVal, paramTypLen);
|
||||
}
|
||||
}
|
||||
paramLI[k].kind = PARAM_INVALID;
|
||||
}
|
||||
else
|
||||
paramLI = NULL;
|
||||
@ -1334,18 +1334,19 @@ _SPI_execute_plan(_SPI_plan *plan, Datum *Values, const char *Nulls,
|
||||
{
|
||||
int k;
|
||||
|
||||
paramLI = (ParamListInfo)
|
||||
palloc0((nargs + 1) * sizeof(ParamListInfoData));
|
||||
/* sizeof(ParamListInfoData) includes the first array element */
|
||||
paramLI = (ParamListInfo) palloc(sizeof(ParamListInfoData) +
|
||||
(nargs - 1) * sizeof(ParamExternData));
|
||||
paramLI->numParams = nargs;
|
||||
|
||||
for (k = 0; k < nargs; k++)
|
||||
{
|
||||
paramLI[k].kind = PARAM_NUM;
|
||||
paramLI[k].id = k + 1;
|
||||
paramLI[k].ptype = plan->argtypes[k];
|
||||
paramLI[k].isnull = (Nulls && Nulls[k] == 'n');
|
||||
paramLI[k].value = Values[k];
|
||||
ParamExternData *prm = ¶mLI->params[k];
|
||||
|
||||
prm->value = Values[k];
|
||||
prm->isnull = (Nulls && Nulls[k] == 'n');
|
||||
prm->ptype = plan->argtypes[k];
|
||||
}
|
||||
paramLI[k].kind = PARAM_INVALID;
|
||||
}
|
||||
else
|
||||
paramLI = NULL;
|
||||
|
Reference in New Issue
Block a user