sqlite not using index with like query

前端 未结 4 1872
别那么骄傲
别那么骄傲 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 11:05

    I also have the same issue with org.xerial/sqlite-jdbc "3.25.2". A simple TEXT based index is not getting used with LIKE operator. But, if I put =, the index gets used. My table schema :

     create table if not exists test (ID INTEGER PRIMARY KEY, VALUE TEXT NOT NULL)
     create index test_idx on test(value)
     insert into test (ID,  VALUE) values (1, 'gold bangles')
     insert into test (ID,  VALUE) values (2, 'gold bandana')
     insert into test (ID,  VALUE) values (2, 'gold bracelet')
    
     explain query plan select * from test where value='gold bandana'
    
     Output:
     0|0|0|SEARCH TABLE test USING COVERING INDEX test_idx(VALUE=?)
    
     explain query plan select * from test where value like 'gold%'
    
     Output:
     0|0|0|SCAN TABLE test
    

提交回复
热议问题