![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
The following bug has been logged online: Bug reference: 1753 Logged by: Ernst Bachmann Email address: e.bachmann (AT) xebec (DOT) de PostgreSQL version: 8.0.3 Operating system: Linux Description: Query Optimizer does not work well with libpg / PQexecParams Details: It looks like the query optimizer isn't taking the value of parameters sent with PQexecParams into account, thus generating (in my case, very) unoptimal plans |
#2
| |||
| |||
|
|
Ernst Bachmann wrote: The following bug has been logged online: Bug reference: 1753 Logged by: Ernst Bachmann Email address: e.bachmann (AT) xebec (DOT) de PostgreSQL version: 8.0.3 Operating system: Linux Description: Query Optimizer does not work well with libpg / PQexecParams Details: It looks like the query optimizer isn't taking the value of parameters sent with PQexecParams into account, thus generating (in my case, very) unoptimal plans If PQexecParams uses the unnamed statement (it appears to), this shouldn't happen -- planning of the unnamed statement is delayed until the first set of parameter values is bound. This behaviour started in 8.0. |
#3
| |||
| |||
|
|
The problem is that even with the unnamed statement and deferred planning, the planner still has to treat the parameters as variables, not constants, since nothing in the protocol stops you from running multiple portals from the unnamed statement. This can make a significant difference, especially where function calls are involved and major optimizations can be made on constant values as a result of inlining. |
#4
| ||||
| ||||
|
|
Andrew - Supernews wrote: The problem is that even with the unnamed statement and deferred planning, the planner still has to treat the parameters as variables, not constants, since nothing in the protocol stops you from running multiple portals from the unnamed statement. This can make a significant difference, especially where function calls are involved and major optimizations can be made on constant values as a result of inlining. Sure, expression optimization is less aggressive, but is that on its own really going to produce a 100-fold difference in query execution? |
|
The main problem pre-8.0 (or with named statements) is that index selectivity estimates go out the window with a parameterized query, so a much more general (and slower) plan gets chosen. The 8.0 unnamed-statement behaviour glues the actual parameter values into the selectivity estimates |
|
so in theory you should get the same plan for the unparameterized and parameterized-unnamed-statement cases. |
|
This is why I'd like to see the actual query.. |
#5
| |||
| |||
|
|
Sure, expression optimization is less aggressive, but is that on its own really going to produce a 100-fold difference in query execution? |
#6
| |||
| |||
|
|
Oliver Jowett <oliver (AT) opencloud (DOT) com> writes: Sure, expression optimization is less aggressive, but is that on its own really going to produce a 100-fold difference in query execution? It's certainly possible, depending on query details. |
![]() |
| Thread Tools | |
| Display Modes | |
| |