Re: Performance Killer 'IN' ?

From: Kai Hessing <kai(dot)hessing(at)hobsons(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Performance Killer 'IN' ?
Date: 2006-03-31 11:01:00
Message-ID: 494gfdFmqgqrU1@individual.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Joshua D. Drake wrote:
> Kai Hessing wrote:
>> 1.) 21.5 seconds
>> 2.) 363.7 seconds
>>
>> But it is still a significant difference.
>
> Can you provide an explain analyze of each query?

There isn't an explain analyze of the first variant, because there are
just 2000 SQL-Updates. The explain analyze for just one of the commands
(UPDATE xyz SET status=-6 WHERE phon='xyz1' AND status>-1;) is:
------------------
Index Scan using phon_phon_idx on phon (cost=0.00..5193.83 rows=530
width=148) (actual time=0.146..0.146 rows=0 loops=1)

Index Cond: ((phon)::text = 'xyz'::text)

Filter: (status > -1)

Total runtime: 0.387 ms

1 Datensätze (means data sets)

Laufzeit gesamt: 16.682 ms (means running time)
------------------

The second one (UPDATE xyz WHERE id IN (xyz1, xyz2, ....) AND
status>-1;) returns:
------------------
Seq Scan on phon (cost=0.00..1573304.58 rows=105931 width=148) (actual
time=369563.565..369563.565 rows=0 loops=1)

Filter: ((((phon)::text = 'xyz1) OR ((phon)::text = 'xyz2'::text) OR
((phon)::text = 'xyz3'::text) OR ((phon)::text = 'xyz4'::text) OR ...
[all the 2000 entries from the IN clause]

Total runtime: 369566.954 ms

667 Datensätze (means data sets)

Laufzeit gesamt: 370,179.246 ms (means running time)
------------------

Hope, that helps. Have a nice weekend. Being back to work on monday ;)

*greets*
Kai

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrus 2006-03-31 12:03:25 How to use result column names in having cause
Previous Message David Bernal 2006-03-31 10:55:42 pgsql continuing network issues