diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-06-11 01:09:22 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-06-11 01:09:22 +0000 |
commit | 7643bed58ecc87eedf7da1ed1938e85ed770d2f8 (patch) | |
tree | 0d97a4c6cb2d02ba9f9d9b5b5d4e1a6d9cbd538e /src/backend/utils/adt/selfuncs.c | |
parent | 5fe8c7d6e50e3a310498f333e4f5130659c931fb (diff) | |
download | postgresql-7643bed58ecc87eedf7da1ed1938e85ed770d2f8.tar.gz postgresql-7643bed58ecc87eedf7da1ed1938e85ed770d2f8.zip |
When using extended-query protocol, postpone planning of unnamed statements
until Bind is received, so that actual parameter values are visible to the
planner. Make use of the parameter values for estimation purposes (but
don't fold them into the actual plan). This buys back most of the
potential loss of plan quality that ensues from using out-of-line
parameters instead of putting literal values right into the query text.
This patch creates a notion of constant-folding expressions 'for
estimation purposes only', in which case we can be more aggressive than
the normal eval_const_expressions() logic can be. Right now the only
difference in behavior is inserting bound values for Params, but it will
be interesting to look at other possibilities. One that we've seen
come up repeatedly is reducing now() and related functions to current
values, so that queries like ... WHERE timestampcol > now() - '1 day'
have some chance of being planned effectively.
Oliver Jowett, with some kibitzing from Tom Lane.
Diffstat (limited to 'src/backend/utils/adt/selfuncs.c')
-rw-r--r-- | src/backend/utils/adt/selfuncs.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index 75eb0d2a529..c7ee847a11a 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.160 2004/05/30 23:40:36 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.161 2004/06/11 01:09:04 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -2823,7 +2823,8 @@ convert_timevalue_to_scalar(Datum value, Oid typid) * * Outputs: (these are valid only if TRUE is returned) * *vardata: gets information about variable (see examine_variable) - * *other: gets other clause argument, stripped of binary relabeling + * *other: gets other clause argument, stripped of binary relabeling, + * and aggressively reduced to a constant * *varonleft: set TRUE if variable is on the left, FALSE if on the right * * Returns TRUE if a variable is identified, otherwise FALSE. @@ -2860,7 +2861,7 @@ get_restriction_variable(Query *root, List *args, int varRelid, if (vardata->rel && rdata.rel == NULL) { *varonleft = true; - *other = rdata.var; + *other = estimate_expression_value(rdata.var); /* Assume we need no ReleaseVariableStats(rdata) here */ return true; } @@ -2868,7 +2869,7 @@ get_restriction_variable(Query *root, List *args, int varRelid, if (vardata->rel == NULL && rdata.rel) { *varonleft = false; - *other = vardata->var; + *other = estimate_expression_value(vardata->var); /* Assume we need no ReleaseVariableStats(*vardata) here */ *vardata = rdata; return true; |