Subject Re: [firebird-support] IN predicate 1500 items limit
Author Arno Brinkman
Hi,

<snip>
> this one it's a lot faster, but I found an error when launching
> selects with more than 1499 elements in the IN set. I solved it
> launching consecutive selects with sets of 1499 elements each.
> my_table has a 200 thousand records now, but could have +10 million
> when working at production. Field ID is bigint primary key.
>
> What I want to know is: Is there a better (faster) way to do it? Will
> I get any benefit decreasing the number of elements per select and
> increasing the number of selects? And sorting the ID set before hard
> coding it?

No, making more selects isn't any way faster.

> What's the reason of the 1499 limit?

Internal stack limit, but you can use OR to combine different "IN" predicates.

SELECT
*
FROM
TableX
WHERE
FieldX IN (1, 2, 3, 1499) OR
FieldX IN (1500, 1501, ...)

Note that the parse/prepare-time increase when you add a lot of constants.
Another way is using a "dummy-table" which holds the numbers and JOIN with it.

Regards,
Arno Brinkman
ABVisie

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Firebird open source database (based on IB-OE) with many SQL-99 features :
http://www.firebirdsql.org
http://www.firebirdsql.info
http://www.fingerbird.de/
http://www.comunidade-firebird.org/

Support list for Interbase and Firebird users :
firebird-support@yahoogroups.com

Nederlandse firebird nieuwsgroep :
news://newsgroups.firebirdsql.info