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/nodes | |
| parent | 0606860a20511c41d5c9074831e6328547722537 (diff) | |
| download | postgresql-2206b498d8240447a9353ce4e994ba41a8e307ac.tar.gz | |
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/nodes')
| -rw-r--r-- | src/backend/nodes/copyfuncs.c | 3 | ||||
| -rw-r--r-- | src/backend/nodes/equalfuncs.c | 18 | ||||
| -rw-r--r-- | src/backend/nodes/outfuncs.c | 5 | ||||
| -rw-r--r-- | src/backend/nodes/params.c | 112 | ||||
| -rw-r--r-- | src/backend/nodes/readfuncs.c | 5 |
5 files changed, 32 insertions, 111 deletions
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index cd8ebe1f5d..b060d38b5e 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -15,7 +15,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.333 2006/04/15 17:45:34 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.334 2006/04/22 01:25:58 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -729,7 +729,6 @@ _copyParam(Param *from) COPY_SCALAR_FIELD(paramkind); COPY_SCALAR_FIELD(paramid); - COPY_STRING_FIELD(paramname); COPY_SCALAR_FIELD(paramtype); return newnode; diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index 9aa0b399b7..94799d0c85 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -18,7 +18,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.269 2006/04/15 17:45:34 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.270 2006/04/22 01:25:59 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -147,23 +147,9 @@ static bool _equalParam(Param *a, Param *b) { COMPARE_SCALAR_FIELD(paramkind); + COMPARE_SCALAR_FIELD(paramid); COMPARE_SCALAR_FIELD(paramtype); - switch (a->paramkind) - { - case PARAM_NAMED: - COMPARE_STRING_FIELD(paramname); - break; - case PARAM_NUM: - case PARAM_EXEC: - case PARAM_SUBLINK: - COMPARE_SCALAR_FIELD(paramid); - break; - default: - elog(ERROR, "unrecognized paramkind: %d", - a->paramkind); - } - return true; } diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index 58e800bab2..314d68d2ef 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.272 2006/03/23 00:19:29 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.273 2006/04/22 01:25:59 tgl Exp $ * * NOTES * Every node type that can appear in stored rules' parsetrees *must* @@ -624,9 +624,8 @@ _outParam(StringInfo str, Param *node) { WRITE_NODE_TYPE("PARAM"); - WRITE_INT_FIELD(paramkind); + WRITE_ENUM_FIELD(paramkind, ParamKind); WRITE_INT_FIELD(paramid); - WRITE_STRING_FIELD(paramname); WRITE_OID_FIELD(paramtype); } diff --git a/src/backend/nodes/params.c b/src/backend/nodes/params.c index 618a1c1e81..1d4e1d48e8 100644 --- a/src/backend/nodes/params.c +++ b/src/backend/nodes/params.c @@ -1,13 +1,14 @@ /*------------------------------------------------------------------------- * * params.c - * Support functions for plan parameter lists. + * Support for finding the values associated with Param nodes. + * * * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/nodes/params.c,v 1.5 2006/03/05 15:58:28 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/nodes/params.c,v 1.6 2006/04/22 01:25:59 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -20,7 +21,7 @@ /* - * Copy a ParamList. + * Copy a ParamListInfo structure. * * The result is allocated in CurrentMemoryContext. */ @@ -28,97 +29,34 @@ ParamListInfo copyParamList(ParamListInfo from) { ParamListInfo retval; - int i, - size; + Size size; + int i; - if (from == NULL) + if (from == NULL || from->numParams <= 0) return NULL; - size = 0; - while (from[size].kind != PARAM_INVALID) - size++; + /* sizeof(ParamListInfoData) includes the first array element */ + size = sizeof(ParamListInfoData) + + (from->numParams - 1) * sizeof(ParamExternData); - retval = (ParamListInfo) palloc0((size + 1) * sizeof(ParamListInfoData)); + retval = (ParamListInfo) palloc(size); + memcpy(retval, from, size); - for (i = 0; i < size; i++) + /* + * Flat-copy is not good enough for pass-by-ref data values, so make + * a pass over the array to copy those. + */ + for (i = 0; i < retval->numParams; i++) { - /* copy metadata */ - retval[i].kind = from[i].kind; - if (from[i].kind == PARAM_NAMED) - retval[i].name = pstrdup(from[i].name); - retval[i].id = from[i].id; - retval[i].ptype = from[i].ptype; - - /* copy value */ - retval[i].isnull = from[i].isnull; - if (from[i].isnull) - { - retval[i].value = from[i].value; /* nulls just copy */ - } - else - { - int16 typLen; - bool typByVal; - - get_typlenbyval(from[i].ptype, &typLen, &typByVal); - retval[i].value = datumCopy(from[i].value, typByVal, typLen); - } + ParamExternData *prm = &retval->params[i]; + int16 typLen; + bool typByVal; + + if (prm->isnull || !OidIsValid(prm->ptype)) + continue; + get_typlenbyval(prm->ptype, &typLen, &typByVal); + prm->value = datumCopy(prm->value, typByVal, typLen); } - retval[size].kind = PARAM_INVALID; - return retval; } - -/* - * Search a ParamList for a given parameter. - * - * On success, returns a pointer to the parameter's entry. - * On failure, returns NULL if noError is true, else ereports the error. - */ -ParamListInfo -lookupParam(ParamListInfo paramList, int thisParamKind, - const char *thisParamName, AttrNumber thisParamId, - bool noError) -{ - if (paramList != NULL) - { - while (paramList->kind != PARAM_INVALID) - { - if (thisParamKind == paramList->kind) - { - switch (thisParamKind) - { - case PARAM_NAMED: - if (strcmp(paramList->name, thisParamName) == 0) - return paramList; - break; - case PARAM_NUM: - if (paramList->id == thisParamId) - return paramList; - break; - default: - elog(ERROR, "unrecognized paramkind: %d", - thisParamKind); - } - } - paramList++; - } - } - - if (!noError) - { - if (thisParamKind == PARAM_NAMED) - ereport(ERROR, - (errcode(ERRCODE_UNDEFINED_OBJECT), - errmsg("no value found for parameter \"%s\"", - thisParamName))); - else - ereport(ERROR, - (errcode(ERRCODE_UNDEFINED_OBJECT), - errmsg("no value found for parameter %d", - thisParamId))); - } - - return NULL; -} diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c index 4e762d3a2e..9fdf02fd56 100644 --- a/src/backend/nodes/readfuncs.c +++ b/src/backend/nodes/readfuncs.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.187 2006/03/16 00:31:55 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.188 2006/04/22 01:25:59 tgl Exp $ * * NOTES * Path and Plan nodes do not have any readfuncs support, because we @@ -318,9 +318,8 @@ _readParam(void) { READ_LOCALS(Param); - READ_INT_FIELD(paramkind); + READ_ENUM_FIELD(paramkind, ParamKind); READ_INT_FIELD(paramid); - READ_STRING_FIELD(paramname); READ_OID_FIELD(paramtype); READ_DONE(); |
