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/optimizer/path/clausesel.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/optimizer/path/clausesel.c')
-rw-r--r-- | src/backend/optimizer/path/clausesel.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/backend/optimizer/path/clausesel.c b/src/backend/optimizer/path/clausesel.c index e736c6e309e..996c98cc469 100644 --- a/src/backend/optimizer/path/clausesel.c +++ b/src/backend/optimizer/path/clausesel.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/path/clausesel.c,v 1.67 2004/05/30 23:40:28 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/path/clausesel.c,v 1.68 2004/06/11 01:08:49 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -487,16 +487,27 @@ clause_selectivity(Query *root, } } } - else if (IsA(clause, Param)) - { - /* XXX any way to do better? */ - s1 = 1.0; - } else if (IsA(clause, Const)) { /* bool constant is pretty easy... */ s1 = ((bool) ((Const *) clause)->constvalue) ? 1.0 : 0.0; } + else if (IsA(clause, Param)) + { + /* see if we can replace the Param */ + Node *subst = estimate_expression_value(clause); + + if (IsA(subst, Const)) + { + /* bool constant is pretty easy... */ + s1 = ((bool) ((Const *) subst)->constvalue) ? 1.0 : 0.0; + } + else + { + /* XXX any way to do better? */ + s1 = (Selectivity) 0.5; + } + } else if (not_clause(clause)) { /* inverse of the selectivity of the underlying clause */ |