Re: [PERFORM] hashjoin chosen over 1000x faster plan

2007-10-10 Thread Kevin Grittner
>>> On Wed, Oct 10, 2007 at 3:48 PM, in message <[EMAIL PROTECTED]>, "Kevin Grittner" <[EMAIL PROTECTED]> wrote: > I'm not sure why it looks at the slow option at all; it seems like a > remaining weakness in the OUTER JOIN optimizations. If I change the query to > use an inner join between the

Re: [PERFORM] hashjoin chosen over 1000x faster plan

2007-10-10 Thread Tom Lane
"Kevin Grittner" <[EMAIL PROTECTED]> writes: > I'm not sure why it looks at the slow option at all; it seems like a remain= > ing weakness in the OUTER JOIN optimizations. I think that comes mostly from the fact that you've got non-nullable targetlist entries in the definition of the CaseTypeHistE

Re: [PERFORM] hashjoin chosen over 1000x faster plan

2007-10-10 Thread Kevin Grittner
>>> On Wed, Oct 10, 2007 at 3:48 PM, in message <[EMAIL PROTECTED]>, "Kevin Grittner" <[EMAIL PROTECTED]> wrote: > > This ten times faster That understates it -- I forgot to get things cached, as I had done for all the other tests. When cached, this is sub-millisecond, although not quite the

Re: [PERFORM] hashjoin chosen over 1000x faster plan

2007-10-10 Thread Kevin Grittner
>>> On Wed, Oct 10, 2007 at 3:32 PM, in message <[EMAIL PROTECTED]>, Tom Lane <[EMAIL PROTECTED]> wrote: > > I'd be very hesitant > to make it choose a plan that is fast only if there were exactly zero > such rows and is slow otherwise. I'm not sure why it looks at the slow option at all; it s

Re: [PERFORM] hashjoin chosen over 1000x faster plan

2007-10-10 Thread Tom Lane
"Kevin Grittner" <[EMAIL PROTECTED]> writes: > The point I'm trying to make is that at planning time the > pg_statistic row for this "Charge"."reopHistSeqNo" column showed > stanullfrac as 0.989; it doesn't seem to have taken this into account > when making its guess about how many rows would be jo

Re: [PERFORM] hashjoin chosen over 1000x faster plan

2007-10-10 Thread Kevin Grittner
>>> On Wed, Oct 10, 2007 at 2:52 PM, in message <[EMAIL PROTECTED]>, Simon Riggs <[EMAIL PROTECTED]> wrote: > > The fast plan is an all-or-nothing plan. It is *only* faster when the > number of matched rows is zero. You know it is zero, but currently the > planner doesn't, nor is it able to make

Re: [PERFORM] hashjoin chosen over 1000x faster plan

2007-10-10 Thread Simon Riggs
On Wed, 2007-10-10 at 14:35 -0500, Kevin Grittner wrote: > >>> On Wed, Oct 10, 2007 at 1:54 PM, in message > <[EMAIL PROTECTED]>, Simon Riggs <[EMAIL PROTECTED]> > wrote: > > > > But the planner doesn't work on probability. It works on a best-guess > > selectivity, as known at planning time. >

Re: [PERFORM] hashjoin chosen over 1000x faster plan

2007-10-10 Thread Kevin Grittner
>>> On Wed, Oct 10, 2007 at 1:54 PM, in message <[EMAIL PROTECTED]>, Simon Riggs <[EMAIL PROTECTED]> wrote: > > But the planner doesn't work on probability. It works on a best-guess > selectivity, as known at planning time. The point I'm trying to make is that at planning time the pg_statistic

Re: [PERFORM] hashjoin chosen over 1000x faster plan

2007-10-10 Thread Simon Riggs
On Wed, 2007-10-10 at 14:07 -0400, Tom Lane wrote: > Simon Riggs <[EMAIL PROTECTED]> writes: > > Basically the planner doesn't ever optimise for the possibility of the > > never-executed case because even a single row returned would destroy > > that assumption. > > It's worse than that: the outer

Re: [PERFORM] hashjoin chosen over 1000x faster plan

2007-10-10 Thread Simon Riggs
On Wed, 2007-10-10 at 13:30 -0500, Kevin Grittner wrote: > >>> On Wed, Oct 10, 2007 at 1:07 PM, in message <[EMAIL PROTECTED]>, > Tom Lane <[EMAIL PROTECTED]> wrote: > > Simon Riggs <[EMAIL PROTECTED]> writes: > >> Basically the planner doesn't ever optimise for the possibility of the > >> never-

Re: [PERFORM] hashjoin chosen over 1000x faster plan

2007-10-10 Thread Kevin Grittner
>>> On Wed, Oct 10, 2007 at 1:07 PM, in message <[EMAIL PROTECTED]>, Tom Lane <[EMAIL PROTECTED]> wrote: > Simon Riggs <[EMAIL PROTECTED]> writes: >> Basically the planner doesn't ever optimise for the possibility of the >> never-executed case because even a single row returned would destroy >> t

Re: [PERFORM] hashjoin chosen over 1000x faster plan

2007-10-10 Thread Tom Lane
Simon Riggs <[EMAIL PROTECTED]> writes: > Basically the planner doesn't ever optimise for the possibility of the > never-executed case because even a single row returned would destroy > that assumption. It's worse than that: the outer subplan *does* return some rows. I suppose that all of them ha

Re: [PERFORM] hashjoin chosen over 1000x faster plan

2007-10-10 Thread Simon Riggs
On Wed, 2007-10-10 at 09:15 -0500, Kevin Grittner wrote: > >>> On Wed, Oct 10, 2007 at 1:31 AM, in message > <[EMAIL PROTECTED]>, Simon Riggs <[EMAIL PROTECTED]> > wrote: > > On Tue, 2007-10-09 at 15:09 -0500, Kevin Grittner wrote: > > > >> I have a situation where a query is running much slower

Re: [PERFORM] hashjoin chosen over 1000x faster plan

2007-10-10 Thread Kevin Grittner
>>> On Wed, Oct 10, 2007 at 1:31 AM, in message <[EMAIL PROTECTED]>, Simon Riggs <[EMAIL PROTECTED]> wrote: > On Tue, 2007-10-09 at 15:09 -0500, Kevin Grittner wrote: > >> I have a situation where a query is running much slower than I would >> expect. The ANALYZE showed that it is hashing some

Re: [PERFORM] hashjoin chosen over 1000x faster plan

2007-10-09 Thread Simon Riggs
On Tue, 2007-10-09 at 15:09 -0500, Kevin Grittner wrote: > I have a situation where a query is running much slower than I would > expect. The ANALYZE showed that it is hashing some information which > is rarely needed. When I set enable_hashjoin = off for the > connection the query run in 1/1000