SQL NOT IN [list of ids] (performance)

mysql

Solution

Yes, the amount of IDs in the list will impact performance. A network packet is only so big, for example, and the database has to parse all that noise and turn it into a series of:

WHERE foo.ID <> 2
AND foo.ID <> 4
AND foo.ID <> 5
AND ...

You should consider other ways to let your query know about this set.

Problem

I'm just wondering if the amount of id's in a list will influence query performance. query example: ``` SELECT * FROM foos WHERE foos.ID NOT IN (2, 4, 5, 6, 7) ``` Where `(2, 4, 5, 6, 7)` is an indefinitely long list. And how many is too many (in context of order)? UPDATE: The reason why i'm asking it because i have two db. On of it (read-only) is the source of items and another one contain items that is processed by operator. Every time when operator asking for new item from read-only db I want to exclude item that is already processed.

Original source

Related problems