Re: [HACKERS] Idea about estimating selectivity for single-column expressions

2009-08-19 Thread Greg Stark
On Wed, Aug 19, 2009 at 3:53 AM, Tom Lanet...@sss.pgh.pa.us wrote: * The expression might throw an error for some inputs, for instance        (1 / field) 0.5 which would fail on zero.  We could recover by wrapping the whole estimation process in a subtransaction, but that seems really

Re: [HACKERS] Idea about estimating selectivity for single-column expressions

2009-08-19 Thread Greg Stark
On Wed, Aug 19, 2009 at 3:16 PM, Greg Starkgsst...@mit.edu wrote: On Wed, Aug 19, 2009 at 3:53 AM, Tom Lanet...@sss.pgh.pa.us wrote: * The expression might throw an error for some inputs, for instance        (1 / field) 0.5 which would fail on zero.  We could recover by wrapping the whole

Re: [HACKERS] Idea about estimating selectivity for single-column expressions

2009-08-19 Thread Tom Lane
Greg Stark gsst...@mit.edu writes: We could add another flag in pg_proc for functions which cannot throw an error. Perhaps all index operator class operators be required to use such functions too? It would be an extremely small set. For starters, anything that returns a pass-by-reference data

Re: [HACKERS] Idea about estimating selectivity for single-column expressions

2009-08-19 Thread Tom Lane
Greg Stark gsst...@mit.edu writes: Another thought. In the above case it would actually be fine to catch the error with PG_TRY() without a subtransaction. As long as no shared database state has been modified when the error is thrown then the subtransaction isn't needed to roll them back. I

Re: [HACKERS] Idea about estimating selectivity for single-column expressions

2009-08-19 Thread Greg Stark
On Wed, Aug 19, 2009 at 7:22 PM, Tom Lanet...@sss.pgh.pa.us wrote: It may be that a subtransaction will actually be acceptable overhead, as long as we don't go overboard and invoke this mechanism for simple WHERE clauses.  Hard to tell without coding it up and testing it though. Are you

Re: [HACKERS] Idea about estimating selectivity for single-column expressions

2009-08-19 Thread Tom Lane
Greg Stark gsst...@mit.edu writes: On Wed, Aug 19, 2009 at 7:22 PM, Tom Lanet...@sss.pgh.pa.us wrote: It may be that a subtransaction will actually be acceptable overhead, as long as we don't go overboard and invoke this mechanism for simple WHERE clauses.  Hard to tell without coding it up

Re: [HACKERS] Idea about estimating selectivity for single-column expressions

2009-08-19 Thread Josh Berkus
Tom, Greg, Robert, Here's my suggestion: 1. First, estimate the cost of the node with a very pessimistic (50%?) selectivity for the calculation. 2. If the cost hits a certain threshold, then run the calculation estimation on the histogram. That way, we avoid the subtransaction and other

Re: [HACKERS] Idea about estimating selectivity for single-column expressions

2009-08-19 Thread Robert Haas
On Wed, Aug 19, 2009 at 3:00 PM, Josh Berkusj...@agliodbs.com wrote: Tom, Greg, Robert, Here's my suggestion: 1. First, estimate the cost of the node with a very pessimistic (50%?) selectivity for the calculation. There is no such thing as a pessimistic selectivity estimation. Right now a

[HACKERS] Idea about estimating selectivity for single-column expressions

2009-08-18 Thread Tom Lane
There were two different complaints today about the planner's inability to make good estimates for WHERE conditions involving bit AND tests, such as (field 8) = 0 (field 8) 0 (field 127) = field I'm not particularly eager to try to put in special-case knowledge for

Re: [HACKERS] Idea about estimating selectivity for single-column expressions

2009-08-18 Thread Robert Haas
On Tue, Aug 18, 2009 at 10:53 PM, Tom Lanet...@sss.pgh.pa.us wrote: There were two different complaints today about the planner's inability to make good estimates for WHERE conditions involving bit AND tests, such as        (field 8) = 0        (field 8) 0        (field 127) = field