Re: [BUGS] Very slow query in PostgreSQL 9.3.3

From: Sergey Konoplev <gray(dot)ru(at)gmail(dot)com>
To: fburgess(at)radiantblue(dot)com
Cc: pgsql-bugs <pgsql-bugs(at)postgresql(dot)org>, "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: [BUGS] Very slow query in PostgreSQL 9.3.3
Date: 2014-03-13 22:12:25
Message-ID: CAL_0b1sRwnM7ddzP0L-c6AaR3wq+B04mKfiP-KuD-gJg2WbqDA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-general pgsql-performance

On Thu, Mar 13, 2014 at 12:26 PM, <fburgess(at)radiantblue(dot)com> wrote:
> *** Problem Query ***
>
> explain (analyze on, buffers on) Select * from measurement this_
> where this_.logdate between '2007-12-19
> 23:38:41.22'::timestamp and '2007-12-20 08:01:04.22'::timestamp
> and this_.city_id=25183 order by
> this_.logdate asc, this_.peaktemp asc, this_.unitsales asc limit 10000;
>
[...]
> Total runtime: 51717.639 ms <--- *** unacceptable ***

Try to create a multi-column index on the partition by (city_id,
logdate). Then run the original query and the query without peaktemp
and nitsales on the order by. Compare the results, and if the first
one will not be satisfying try to add these two columns to the end of
the column list of your multi-column index on the order as they appear
in your query. It should do the trick. If it wont, please, show the
plans.

--
Kind regards,
Sergey Konoplev
PostgreSQL Consultant and DBA

http://www.linkedin.com/in/grayhemp
+1 (415) 867-9984, +7 (901) 903-0499, +7 (988) 888-1979
gray(dot)ru(at)gmail(dot)com

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message digoal@126.com 2014-03-14 00:07:29 Re: BUG #9552: IndexOnlyScan startup_cost>0, why not equal 0?it's a bug?
Previous Message Pavel Stehule 2014-03-13 19:36:15 Re: [BUGS] Very slow query in PostgreSQL 9.3.3

Browse pgsql-general by date

  From Date Subject
Next Message Ian Lawrence Barwick 2014-03-14 02:19:10 Re: [PERFORM] Very slow query in PostgreSQL 9.3.3
Previous Message Susan Cassidy 2014-03-13 21:46:41 Re: puzzling perl DBI vs psql problem

Browse pgsql-performance by date

  From Date Subject
Next Message Ian Lawrence Barwick 2014-03-14 02:19:10 Re: [PERFORM] Very slow query in PostgreSQL 9.3.3
Previous Message Pavel Stehule 2014-03-13 19:36:15 Re: [BUGS] Very slow query in PostgreSQL 9.3.3