diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2006-04-22 01:26:01 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2006-04-22 01:26:01 +0000 |
commit | 2206b498d8240447a9353ce4e994ba41a8e307ac (patch) | |
tree | eb60585d0dae556ae45aae35a7d50f83be715ab4 /src/backend/executor/spi.c | |
parent | 0606860a20511c41d5c9074831e6328547722537 (diff) | |
download | postgresql-2206b498d8240447a9353ce4e994ba41a8e307ac.tar.gz postgresql-2206b498d8240447a9353ce4e994ba41a8e307ac.zip |
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.
Diffstat (limited to 'src/backend/executor/spi.c')
-rw-r--r-- | src/backend/executor/spi.c | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c index 3563ba23d3a..333968676d4 100644 --- a/src/backend/executor/spi.c +++ b/src/backend/executor/spi.c @@ -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; |