pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephen Davies <scldad@sdc.com.au>
To: Alvaro Herrera <alvherre@commandprompt.com>
Cc: Michael Glaesemann <grzm@seespotcode.net>
Cc: Russell Smith <mr-russ@pws.com.au>
Cc: pgsql-performance@postgresql.org
Subject: Re: Optimising "in" queries
Date: Fri, 24 Aug 2007 09:17:48 +0930
Message-ID: <200708240917.48500.scldad@sdc.com.au> (raw)
In-Reply-To: <20070823194642.GD31461@alvh.no-ip.org>
References: <200708221210.36770.scldad@sdc.com.au>
	<200708230900.13878.scldad@sdc.com.au>
	<20070823194642.GD31461@alvh.no-ip.org>

I thought that I had but I screwed up the addresses.
Here they 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)


benparts=# explain analyze 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=49260.20..49260.20 rows=1 width=8) (actual 
time=3263.219..3263.221 rows=1 loops=1)
   ->  Sort  (cost=49260.20..49260.38 rows=73 width=8) (actual 
time=3263.213..3263.213 rows=1 loops=1)
         Sort Key: rdate
         ->  HashAggregate  (cost=49257.03..49257.94 rows=73 width=8) 
(actual time=3049.667..3093.345 rows=30445 loops=1)
               ->  Bitmap Heap Scan on reading  (cost=541.97..49109.62 
rows=29481 width=8) (actual time=1727.021..2908.563 rows=91334 loops=1)
                     Recheck Cond: (sensor_id = ANY 
('{1137,1138,1139}'::integer[]))
                     ->  Bitmap Index Scan on reading_sensor  
(cost=0.00..534.60 rows=29481 width=0) (actual time=1714.980..1714.980 
rows=91334 loops=1)
                           Index Cond: (sensor_id = ANY 
('{1137,1138,1139}'::integer[]))
 Total runtime: 3264.121 ms
(9 rows)

benparts=# explain analyze 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..41959.54 rows=1 width=8) (actual time=1.284..1.285 
rows=1 loops=1)
   ->  GroupAggregate  (cost=0.00..8182110.32 rows=195 width=8) (actual 
time=1.281..1.281 rows=1 loops=1)
         ->  Index Scan Backward using date on reading  
(cost=0.00..8181711.41 rows=79294 width=8) (actual time=1.254..1.261 
rows=2 loops=1)
               Filter: (sensor_id = ANY 
('{1137,1138,1139,1140}'::integer[]))
 Total runtime: 1.360 ms
(5 rows)

On Friday 24 August 2007 05:16, Alvaro Herrera wrote:
<snip>
> I don't think you showed us the EXPLAIN ANALYZE results that Scott
> requested.

-- 
========================================================================
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



view thread (13+ messages)  latest in thread

Message-ID: <200708240917.48500.scldad@sdc.com.au>
Permalink:  ../200708240917.48500.scldad@sdc.com.au/
Also on:    postgresql.org/message-id/200708240917.48500.scldad@sdc.com.au

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: scldad@sdc.com.au, alvherre@commandprompt.com, grzm@seespotcode.net, mr-russ@pws.com.au
  Subject: Re: Optimising "in" queries
  In-Reply-To: <200708240917.48500.scldad@sdc.com.au>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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