Re: [GENERAL] Problem with planner

2011-08-10 Thread Cédric Villemain
2011/8/9 hubert depesz lubaczewski : > On Tue, Aug 09, 2011 at 04:08:39PM -0400, Tom Lane wrote: >> I suppose what's going on here is that the "state" and "ending_tsz" >> columns are highly correlated, such that there are lots of 'active' >> items but hardly any of them ended more than a day ago?  

Re: [GENERAL] Problem with planner

2011-08-10 Thread hubert depesz lubaczewski
On Tue, Aug 09, 2011 at 05:18:38PM -0400, Tom Lane wrote: > hubert depesz lubaczewski writes: > > I solved the problem by adding "enable_bitmapscan = false" (and keeping > > the query in original format, with subselect) which caused the plan to > > be ok. > > I doubt that solution is any more rob

Re: [GENERAL] Problem with planner

2011-08-09 Thread Tom Lane
hubert depesz lubaczewski writes: > I solved the problem by adding "enable_bitmapscan = false" (and keeping > the query in original format, with subselect) which caused the plan to > be ok. I doubt that solution is any more robust than what you had before --- in particular, it's likely to fall ba

Re: [GENERAL] Problem with planner

2011-08-09 Thread hubert depesz lubaczewski
On Tue, Aug 09, 2011 at 04:08:39PM -0400, Tom Lane wrote: > I suppose what's going on here is that the "state" and "ending_tsz" > columns are highly correlated, such that there are lots of 'active' > items but hardly any of them ended more than a day ago? If so, yes, that's correct. > you're goi

Re: [GENERAL] Problem with planner

2011-08-09 Thread Tom Lane
hubert depesz lubaczewski writes: > version with disabled bitmapscans: > $ explain analyze select count(*) from objects where state='active' and > ending_tsz <= now() - '1 day'::interval; > QUERY PLAN > -

Re: [GENERAL] Problem with planner

2011-08-09 Thread hubert depesz lubaczewski
On Tue, Aug 09, 2011 at 12:11:48PM -0400, Tom Lane wrote: > There's absolutely no hope of getting the planner to make intelligent > plan choices when its estimates are that far off (3344138 rows estimated > versus none actual). It's just luck if you get the "right" plan despite > that. > Now part

Re: [GENERAL] Problem with planner

2011-08-09 Thread hubert depesz lubaczewski
On Tue, Aug 09, 2011 at 12:11:48PM -0400, Tom Lane wrote: > Now part of the reason why the estimate is so bad is the sub-select, > which completely defeats selectivity estimation for the ending_tsz > condition. Could we see EXPLAIN ANALYZE for the query without a > sub-select, both with and withou

Re: [GENERAL] Problem with planner

2011-08-09 Thread Tom Lane
hubert depesz lubaczewski writes: > as for good plan. sure. If i'll disable bitmap scans, I get: > $ explain analyze select count(*) from objects where state='active' and > ending_tsz <= (select now() - '1 day'::interval ); >

Re: [GENERAL] Problem with planner

2011-08-09 Thread hubert depesz lubaczewski
On Tue, Aug 09, 2011 at 05:11:09PM +0200, Cédric Villemain wrote: > The plan turn bad without any new ANALYZE, right ? Right. > does the table increase more quickly now than before ? is it now way > larger than before ? > Also, do you have an explain with the 'good' plan ? changes in the object

Re: [GENERAL] Problem with planner

2011-08-09 Thread Cédric Villemain
2011/8/8 hubert depesz lubaczewski : > Hi, > we have 8.3.11 installation on client site, with table, which looks like > this: > > $ \d objects >                                              Table "public.objects" >         Column          |           Type           |                           > Mo

Re: [GENERAL] Problem with planner

2011-08-09 Thread hubert depesz lubaczewski
On Mon, Aug 08, 2011 at 10:01:58PM +0200, pasman pasmański wrote: > Try to change index: objects_endings_tsz_active(state,endings_tsz) > where state='active'. adding new indexes on this machine is quite complicated, as it's heavily used production system. And the current index should be chosen by

Re: [GENERAL] Problem with planner

2011-08-08 Thread pasman pasmański
Try to change index: objects_endings_tsz_active(state,endings_tsz) where state='active'. 2011/8/8, hubert depesz lubaczewski : > Hi, > we have 8.3.11 installation on client site, with table, which looks like > this: > > $ \d objects > Table "public.obj

Re: [GENERAL] Problem with planner

2011-08-08 Thread hubert depesz lubaczewski
On Mon, Aug 08, 2011 at 12:51:40PM -0400, Tom Lane wrote: > hubert depesz lubaczewski writes: > > and we have a query: > > select count(*) from objects where state='active'::text and ending_tsz <= ( > > select now() - '1 day'::interval ); > > Try getting rid of the sub-select. There might have

Re: [GENERAL] Problem with planner

2011-08-08 Thread Tom Lane
hubert depesz lubaczewski writes: > and we have a query: > select count(*) from objects where state='active'::text and ending_tsz <= ( > select now() - '1 day'::interval ); Try getting rid of the sub-select. There might have been a reason to do it like that ten years ago, but these days it's a

Re: [GENERAL] Problem with planner choosing nested loop

2008-04-03 Thread Craig Ringer
Alban Hertroys wrote: > > On Apr 2, 2008, at 9:02 PM, Alex Solovey wrote: >> The reduced database example has the same problem in EXPLAIN ANALYZE >> as production one, here: >> >> Seq Scan on bar (cost=0.00..393.07 rows=1 width=4) (actual >> time=0.098..3.561 rows=24 loops=1) > > Hang on...

Re: [GENERAL] Problem with planner choosing nested loop

2008-04-02 Thread Alban Hertroys
On Apr 2, 2008, at 9:02 PM, Alex Solovey wrote: The reduced database example has the same problem in EXPLAIN ANALYZE as production one, here: Seq Scan on bar (cost=0.00..393.07 rows=1 width=4) (actual time=0.098..3.561 rows=24 loops=1) Hang on... You prefer sequential scans because i

Re: [GENERAL] Problem with planner choosing nested loop

2008-04-02 Thread Scott Marlowe
On Wed, Apr 2, 2008 at 1:06 PM, Harald Fuchs <[EMAIL PROTECTED]> wrote: > In article <[EMAIL PROTECTED]>, > > "Rodrigo E. De León Plicet" <[EMAIL PROTECTED]> writes: > > > On Wed, Apr 2, 2008 at 12:36 PM, Alex Solovey <[EMAIL PROTECTED]> wrote: > >> ... I have no idea how it could be fixed. > >

Re: [GENERAL] Problem with planner choosing nested loop

2008-04-02 Thread Harald Fuchs
In article <[EMAIL PROTECTED]>, "Rodrigo E. De León Plicet" <[EMAIL PROTECTED]> writes: > On Wed, Apr 2, 2008 at 12:36 PM, Alex Solovey <[EMAIL PROTECTED]> wrote: >> ... I have no idea how it could be fixed. > - CREATE INDEX xifoo ON foo(bar_id); > - ANALYZE; > - Retry. A compound index CREATE

Re: [GENERAL] Problem with planner choosing nested loop

2008-04-02 Thread Rodrigo E. De León Plicet
On Wed, Apr 2, 2008 at 1:20 PM, Alex Solovey <[EMAIL PROTECTED]> wrote: > In this simple (which means "reduced") test database, yes. But the actual > table "foo" in production database: > > 1. partitioned, with 50+ partitions > 2. heavily updated (and indexes make it slow) > 3. has more fields

Re: [GENERAL] Problem with planner choosing nested loop

2008-04-02 Thread Alex Solovey
The reduced database example has the same problem in EXPLAIN ANALYZE as production one, here: Seq Scan on bar (cost=0.00..393.07 rows=1 width=4) (actual time=0.098..3.561 rows=24 loops=1) That's why I posted the smallest dataset I could reproduce the problem with. Rodrigo E. De León Pli

Re: [GENERAL] Problem with planner choosing nested loop

2008-04-02 Thread Scott Marlowe
On Wed, Apr 2, 2008 at 12:12 PM, Rodrigo E. De León Plicet <[EMAIL PROTECTED]> wrote: > Also important, consider creating additional indexes based on your > access patterns. Good point. Note that you can create indexes and then track their usefulness with the pg_stat_user_indexes view, which I f

Re: [GENERAL] Problem with planner choosing nested loop

2008-04-02 Thread Alex Solovey
> - CREATE INDEX xifoo ON foo(bar_id); In this simple (which means "reduced") test database, yes. But the actual table "foo" in production database: 1. partitioned, with 50+ partitions 2. heavily updated (and indexes make it slow) 3. has more fields like bar_id We had indexes on several fiel

Re: [GENERAL] Problem with planner choosing nested loop

2008-04-02 Thread Rodrigo E. De León Plicet
Also important, consider creating additional indexes based on your access patterns. -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general

Re: [GENERAL] Problem with planner choosing nested loop

2008-04-02 Thread Rodrigo E. De León Plicet
On Wed, Apr 2, 2008 at 12:36 PM, Alex Solovey <[EMAIL PROTECTED]> wrote: > ... I have no idea how it could be fixed. - CREATE INDEX xifoo ON foo(bar_id); - ANALYZE; - Retry. -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.po