Re: Have I b0rked something? Slow comparisons on "where x in (...)" - Mailing list pgsql-general

From Listmail
Subject Re: Have I b0rked something? Slow comparisons on "where x in (...)"
Date
Msg-id op.trsscziuzcizji@apollo13
Whole thread Raw
In response to Re: Have I b0rked something? Slow comparisons on "where x in (...)"  (Alban Hertroys <alban@magproductions.nl>)
List 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.

pgsql-general by date:

Previous
From: "Paolo Saudin"
Date:
Subject: R: R: Postgres 8.3-dev
Next
From: Kevin Murphy
Date:
Subject: Permission denied to create database