pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Query performance
2+ messages / 2 participants
[nested] [flat]

* Query performance
@ 2007-08-18 06:40 Stephen Davies <sdc@sdc.com.au>
  2007-08-21 11:39 ` Re: Query performance Jeroen T. Vermeulen <jtv@xs4all.nl>
  0 siblings, 1 reply; 2+ messages in thread

From: Stephen Davies @ 2007-08-18 06:40 UTC (permalink / raw)
  To: pgsql-interfaces

I have a table with some seven million rows.

The query:

select count(rdate),rdate from reading where sensor_id in 
(1137,1138,1139) group by rdate order by rdate desc limit 1;

takes a few seconds but:

select count(rdate),rdate from reading where sensor_id in 
(1137,1138,1139,1140) group by rdate order by rdate desc limit 1;

(anything with four or more values in the "in" list) takes several 
minutes.

Is there any way to make the "larger" queries more efficient?

Both rdate and sensor_id are indexed and the database is vacuumed every 
night.

Explain outputs are:

benparts=# explain select count(rdate),rdate from reading where 
sensor_id in (1137,1138,1139,1140) group by rdate order by rdate desc 
limit 1;
                                            QUERY PLAN
---------------------------------------------------------------------------------------------------
 Limit  (cost=0.00..39890.96 rows=1 width=8)
   ->  GroupAggregate  (cost=0.00..7938300.21 rows=199 width=8)
         ->  Index Scan Backward using date on reading  
(cost=0.00..7937884.59 rows=82625 width=8)
               Filter: (sensor_id = ANY 
('{1137,1138,1139,1140}'::integer[]))
(4 rows)

benparts=# explain select count(rdate),rdate from reading where 
sensor_id in (1137,1138,1139) group by rdate order by rdate desc limit 
1;
                                             QUERY PLAN
-----------------------------------------------------------------------------------------------------
 Limit  (cost=48364.32..48364.32 rows=1 width=8)
   ->  Sort  (cost=48364.32..48364.49 rows=69 width=8)
         Sort Key: rdate
         ->  HashAggregate  (cost=48361.35..48362.21 rows=69 width=8)
               ->  Bitmap Heap Scan on reading  (cost=535.53..48218.10 
rows=28650 width=8)
                     Recheck Cond: (sensor_id = ANY 
('{1137,1138,1139}'::integer[]))
                     ->  Bitmap Index Scan on reading_sensor  
(cost=0.00..528.37 rows=28650 width=0)
                           Index Cond: (sensor_id = ANY 
('{1137,1138,1139}'::integer[]))
(8 rows)

TIA,
Stephen Davies
-- 
========================================================================
This email is for the person(s) identified above, and is confidential to
the sender and the person(s).  No one else is authorised to use or
disseminate this email or its contents.

Stephen Davies Consulting                            Voice: 08-8177 1595
Adelaide, South Australia.                             Fax: 08-8177 0133
Computing & Network solutions.                       Mobile:0403 0405 83



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Query performance
  2007-08-18 06:40 Query performance Stephen Davies <sdc@sdc.com.au>
@ 2007-08-21 11:39 ` Jeroen T. Vermeulen <jtv@xs4all.nl>
  0 siblings, 0 replies; 2+ messages in thread

From: Jeroen T. Vermeulen @ 2007-08-21 11:39 UTC (permalink / raw)
  To: Stephen Davies <sdc@sdc.com.au>; +Cc: pgsql-interfaces

On Sat, August 18, 2007 13:40, Stephen Davies wrote:

> select count(rdate),rdate from reading where sensor_id in
> (1137,1138,1139) group by rdate order by rdate desc limit 1;
>
> takes a few seconds but:

Interesting!  However this is probably not the best list to ask, since
it's about the backend and quite independent of any interface.  You may
have more luck on pgsql-general.


Jeroen





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2007-08-21 11:39 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-08-18 06:40 Query performance Stephen Davies <sdc@sdc.com.au>
2007-08-21 11:39 ` Jeroen T. Vermeulen <jtv@xs4all.nl>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox