sqlite3 - Why does SQLite not use an index when using a literal column value in the WHERE clause? -
here's sqlfiddle of example, let me explain:
when have simple table this:
create table forgerock (`id` int, `productname` varchar(7), `description` varchar(55)) ;
and simple index on productname
column this:
create index test_idx on forgerock(productname);
i can select data using productname
in clause , index being used. nice.
when add hard-coded value list of columns i'm selecting, works , index used, too:
select 0 foo, 0 bar, productname, description forgerock (foo = 0 , productname in ('openidm', 'opendj'))
even using hard-coded foo
column in clause still uses index (as should). here's question: why index not being used when add or (foo = 1 , bar in (1))
clause?
select 0 foo, 0 bar, productname, description forgerock (foo = 0 , productname in ('openidm', 'opendj')) or (foo = 1 , bar in (1));
any appreciated. once again, here's sqlfiddle.
the documentation says:
where clause constraints connected or instead of , can handled [...]
given query, fact or-clause optimization described here can used not guarantee used. sqlite uses cost-based query planner estimates cpu , disk i/o costs of various competing query plans , chooses plan thinks fastest. if there many or terms in clause or if of indices on individual or-clause subterms not selective, sqlite might decide faster use different query algorithm, or full-table scan.
Comments
Post a Comment