pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Guerin <guerin@rentec.com>
To: Stephan Szabo <sszabo@megazone.bigpanda.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Simple queries take forever to run
Date: Thu, 28 Aug 2003 13:42:35 -0400
Message-ID: <3F4E3F0B.9000802@rentec.com> (raw)
In-Reply-To: <20030828081914.A6403-100000@megazone.bigpanda.com>
References: <20030828081914.A6403-100000@megazone.bigpanda.com>

Stephan Szabo wrote:

>On Thu, 28 Aug 2003, Michael Guerin wrote:
>
>  
>
>>Stephan Szabo wrote:
>>
>>    
>>
>>>On Wed, 27 Aug 2003, Michael Guerin wrote:
>>>
>>>
>>>
>>>      
>>>
>>>>I'm running into some performance problems trying to execute simple
>>>>queries.
>>>>
>>>>postgresql version 7.3.3
>>>>.conf params changed from defaults.
>>>>shared_buffers = 64000
>>>>sort_mem = 64000
>>>>fsync = false
>>>>effective_cache_size = 400000
>>>>
>>>>ex. query: select * from x where id in (select id from y);
>>>>
>>>>There's an index on each table for id.  SQL Server takes <1s to return,
>>>>postgresql doesn't return at all, neither does explain analyze.
>>>>
>>>>
>>>>        
>>>>
>>>IN(subquery) is known to run poorly in 7.3.x and earlier.  7.4 is
>>>generally much better (for reasonably sized subqueries) but in earlier
>>>versions you'll probably want to convert into an EXISTS or join form.
>>>
>>>
>>>
>>>
>>>      
>>>
>>Something else seems to be going on, even switching to an exists clause
>>gives much better but poor performance.
>>count(*) where exists clause: Postgresql 19s, SQL Server <1s
>>count(*) where not exists:  23.3s SQL Server 1.5s
>>    
>>
>
>What does explain analyze show for the two queries?
>
>
>  
>
explain analyze  select count(*) from tbltimeseries where exists(select 
uniqid  from tblobjectname where timeseriesid = uniqid);
Aggregate  (cost=5681552.18..5681552.18 rows=1 width=0) (actual 
time=22756.64..22756.64 rows=1 loops=1)
   ->  Seq Scan on tbltimeseries  (cost=0.00..5680051.34 rows=600336 
width=0) (actual time=22.06..21686.78 rows=1200113 loops=1)
         Filter: (NOT (subplan))
         SubPlan
           ->  Index Scan using idx_objectname on tblobjectname  
(cost=0.00..4.70 rows=1 width=4) (actual time=0.01..0.01 rows=0 
loops=1200673)
                 Index Cond: ($0 = uniqid)
 Total runtime: 22756.83 msec
(7 rows)

fiasco=# explain analyze  select count(*) from tbltimeseries where 
exists(select uniqid  from tblobjectname where timeseriesid = uniqid);
                                                                   QUERY 
PLAN
------------------------------------------------------------------------------------------------------------------------------------------------
explain analyze  select count(*) from tbltimeseries where exists(select 
uniqid  from tblobjectname where timeseriesid = uniqid);
 Aggregate  (cost=5681552.18..5681552.18 rows=1 width=0) (actual 
time=19558.77..19558.77 rows=1 loops=1)
   ->  Seq Scan on tbltimeseries  (cost=0.00..5680051.34 rows=600336 
width=0) (actual time=0.21..19557.73 rows=560 loops=1)
         Filter: (subplan)
         SubPlan
           ->  Index Scan using idx_objectname on tblobjectname  
(cost=0.00..4.70 rows=1 width=4) (actual time=0.01..0.01 rows=0 
loops=1200673)
                 Index Cond: ($0 = uniqid)
 Total runtime: 19559.04 msec
(7 rows)







view thread (11+ messages)  latest in thread

Message-ID: <3F4E3F0B.9000802@rentec.com>
Permalink:  ../3F4E3F0B.9000802@rentec.com/
Also on:    postgresql.org/message-id/3F4E3F0B.9000802@rentec.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: guerin@rentec.com, sszabo@megazone.bigpanda.com
  Subject: Re: Simple queries take forever to run
  In-Reply-To: <3F4E3F0B.9000802@rentec.com>
  References: <20030828081914.A6403-100000@megazone.bigpanda.com> <3F4E3F0B.9000802@rentec.com>

* 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