I have strange issue with SQLite on iOS 5.
In iOS application I have pretty big table (1 000 000 + records).
I have simple query for fetching about 20 000 records from the table and then I am sorting result via ORDER BY statement. Something like this:
SELECT table2Field,table3Field,table4Field,table5Field,probability,impact
FROM table1
INNER JOIN table2 ON id2=table1_id2
INNER JOIN table3 ON id3=table1_id3
INNER JOIN table4 ON id4=table1_id4
INNER JOIN table5 ON id5=table1_id5
WHERE country_id = 0 AND category_id = 0
ORDER BY table2Field, table3Field, table4Field, ABS(impact) DESC
On the iOS 4 this work around 2-3 seconds. However on the iOS 5 it works more then minute.
I was trying to identify root cause for this issue, but I have no success.
Interesting fact is if I remove ORDER BY statement from the query everything works fine.
Any one have better solution then sorting data manually?
Thanks,
Artem.
It’s likely that the new version of SQLite in iOS 5 has simply chosen a less efficint query plan than the version in iOS 4 did. You can use EXPLAIN QUERY PLAN in each of the versions to see if there are obvious differences. Perhaps the earlier version uses an index that is not used by the later version.
You can also try using ANALYZE to give the query planner better information, and try EXPLAIN QUERY PLAN again.
Sometimes adding/changing an index will help with ORDER BY queries.