Re: Have I b0rked something? Slow comparisons on "where x in (...)"

From: Listmail <lists(at)peufeu(dot)com>
To: "Alban Hertroys" <alban(at)magproductions(dot)nl>
Cc: "Stephen Harris" <lists(at)spuddy(dot)org>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Postgres General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Have I b0rked something? Slow comparisons on "where x in (...)"
Date: 2007-05-04 10:20:49
Message-ID: op.trsscziuzcizji@apollo13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I used VALUES as a replacement for the temporary table since for this
application, it is a lot more useful.

The point is :

SELECT * FROM table WHERE value IN ( 1000 integers ) : does 1000
comparisons for each row
SELECT * FROM table WHERE value IN ( VALUES (1000 integerss) ) : builds a
Hash with the 1000 values and uses it to test rows, which is a lot faster
if you have many values to compare with.

The first one is faster if the number of values in the IN() is small. The
second one is faster if the number of values in the IN() is large.

> EXPLAIN ANALYZE SELECT * FROM table JOIN test ON (table.column =
> test.value)

It wouldn't give the same result : both queries above remove duplicates,
this one does not.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Stone 2007-05-04 12:45:39 Re: Feature Request --- was: PostgreSQL Performance Tuning
Previous Message eugene.mindrov 2007-05-04 09:22:28 Re: How to get comments for view columns?