I need to get the entries corresponding to the identifiers stored in the list. The query generated at runtime is simple:
SELECT [whatever FROM sometable] WHERE (id = 1) or (id = 5) or (id = 33).
Which is equivalent
SELECT [whatever FROM sometable] WHERE [id] IN (1, 5, 33);
This is good, but what if the list contains hundreds or thousands of identifiers? The statement will be huge, and at some point, the SQL parser may be compressed, or if it is not, the performance is likely to be pretty poor. How can I make it so that it is not so sensitive to the number of records retrieved?
(The reason I can't just iterate over the list and retrieve the records one by one is because I need a database to execute ORDER BY for me. The records should come from a database sorted by a specific field, while the list represents the records selected by the user in the grid that can be sorted in any number of ways.And yes, I could sort the entries in the code after receiving them, but this plan is B, since I do not even need to keep them all in one data structure, only for the right streamlining.)
performance sql sqlite
Marek Jedliลski Jan 27 '12 at 23:34 2012-01-27 23:34
source share