Ive been trying to get sqlite to use an index with a like to no avail. Ive tried collate nocase and still no luck. Anyone have any ideas on how to get sqlite to do a like hittin
In SQLite 3.6.23.1, the index on test
is used:
> explain query plan select * from test where name like 'test%';
TABLE test WITH INDEX idx_test_name
> explain query plan select * from test2 where name like 'test%';
TABLE test2
> explain query plan select * from test3 where name like 'test%';
TABLE test3
With a development version of SQLite 3.7.15, both test
's and test3
's indexes are used (the index on test2
is used for scanning, not searching):
> explain query plan select * from test where name like 'test%';
SEARCH TABLE test USING COVERING INDEX idx_test_name (name>? AND name) (~31250 rows)
> explain query plan select * from test2 where name like 'test%';
SCAN TABLE test2 USING COVERING INDEX idx_test2_name (~500000 rows)
> explain query plan select * from test3 where name like 'test%';
SEARCH TABLE test3 USING COVERING INDEX idx_test3_name (name>? AND name) (~31250 rows)
So the answer is to update SQLite.