我一直试图让sqlite使用索引,似乎无济于事.香港专业教育学院尝试整理nocase仍然没有运气.任何人都有任何关于如何让sqlite像命中索引一样的想法.提前致谢
DROP TABLE IF EXISTS "test"; DROP TABLE IF EXISTS "test2"; DROP TABLE IF EXISTS "test3"; create table test(name TEXT COLLATE NOCASE); create table test2(name TEXT); create table test3(name TEXT); create index idx_test_name on test(name); create index idx_test2_name on test2(name); create index idx_test3_name on test3(name COLLATE NOCASE); insert into test(name) values('dan'); insert into test2(name) values('dan'); insert into test3(name) values('dan'); --explain query plan select * from test where name like 'test%' -- explain query plan select * from test2 where name like 'test%' -- explain query plan select * from test3 where name like 'test%'
在sqlite 3.6.23.1中,使用了测试索引:
原文链接:https://www.f2er.com/sqlite/197683.html> 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
使用sqlite 3.7.15的开发版本,使用test和test3的索引(test2上的索引用于扫描,而不是搜索):
> 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)
所以答案是更新sqlite.