IN statement performance in PostgreSQL (and in general)

Posted by Vasil on Stack Overflow See other posts from Stack Overflow or by Vasil
Published on 2010-06-08T23:24:35Z Indexed on 2010/06/09 2:32 UTC
Read the original article Hit count: 285

Filed under:
|
|

I know this has probably been asked before, but I can't find it with SO's search.

Lets say i've TABLE1 and TABLE2, who should I expect the performance of a query such as this:

SELECT * FROM TABLE1 WHERE id IN SUBQUERY_ON_TABLE2;

as the number of rows in TABLE1 and TABLE2 grow and id is a primary key on TABLE1.

Yes, I know using IN is such a n00b mistake, but TABLE2 has a generic relation (django generic relation) to multiple other tables so I can't think of another way to filter the data. At what (aproximate) ammount of rows in TABLE1 and TABLE2 should I expect to notice performance issues because of this? Will performance degrade linearly, exponentially etc. depending on the number of rows?

© Stack Overflow or respective owner

Related posts about sql

Related posts about django