|Nov 7, 2012, 07:58 PM||#1|
SQLite speed woes - index not being used
I have an SQLite query that seems to be skipping an index I created on the field Time:
sqlite> explain query plan SELECT UserID, JSON FROM TweetsJSON WHERE TweetID <= 9999999 AND Time >= 1352249596 AND Time <= 1353027196 ORDER BY TweetID DESC LIMIT 100 ;
0|0|0|SEARCH TABLE TweetsJSON USING INTEGER PRIMARY KEY (rowid<?) (~27777 rows)
TweetID is a primary key and an index was created on Time using the syntax CREATE INDEX TimeTweetsJSONIndex ON TweetsJSON (Time). What's wrong here? Why is it skipping that index totally? Search times are reflecting that and they're less than satisfactory.
|Nov 8, 2012, 08:45 AM||#2|
SQLite query optimizer
See section 6 of the SQLite query optimizer docs at http://www.sqlite.org/optoverview.html
It explains that only one index can be used per table, and how the optimizer selects which index to use when there are multiple candidates.
To force the optimizer to use your time index instead of the implicit tweetid index in the table you can add a unary + in front of the tweetid in your where clause. This will prevent the optimizer from using an index for the tweetid and it should then select your time index.
|Thread Tools||Search this Thread|
|thread||Thread Starter||Forum||Replies||Last Post|
|SQL / SQLite browser application?||VideoBeagle||Mac Applications and Mac App Store||2||Mar 20, 2014 04:32 PM|
|missing contacts, but available in backup/sqlite?!||temen||iPhone||0||Sep 2, 2013 04:52 PM|
|Sync sqlite with sql server||RookieAppler||iPhone/iPad Programming||2||Oct 19, 2012 01:09 PM|
|Slow SQLite Query||Starfox||Mac Programming||3||Sep 10, 2012 01:04 PM|
|Sqlite and Core Data||kimbebot||iPhone/iPad Programming||5||Jul 23, 2012 02:44 AM|
All times are GMT -5. The time now is 05:26 AM.