The #sqlite3 docs say that indexed by
should not be used for query design -- only to prevent regressions. But what is the alternative? I have a #database where most queries are similar to the following:
select count(distinct tags.file) from tags indexed by tags_tag_nocase join meta on tags.file = meta.file where meta.trash = 0 and (tags.tag = 'foo' or tags.tag like 'foo.%')
Without any indexed by
clause, the best I can get with this query is about 170ms. With the clause shown, it takes about 80ms. I've tried peppering in "likely" and "unlikely", but this is not an improvement
Some key facts about the data:
- about 64K rows in
tags
, and 10K inmeta
- At most 10% of rows in
tags
can be expected to fulfill either of thetags.tag
clauses - 90% of rows in
meta
havemeta.trash=0