sqlite not using index with like query

前端 未结 4 1904
别那么骄傲
别那么骄傲 2021-02-19 10:27

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

4条回答
  •  攒了一身酷
    2021-02-19 10:59

    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 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

    So the answer is to update SQLite.

提交回复
热议问题