SQLite Forum

How to speed up this query?
Login
Dear all and especially Clemens, thanks for your comments.

I have found the problem in an incorrect table declaration of table "meta". I had used (which happens quite frequently to me)

... parameter STRING NOT NULL, value STRING NOT NULL ...

instead of "TEXT" 🙈

So with that having been changed, it works as expected:

QUERY PLAN
|--SCAN TABLE meta AS a
`--CORRELATED SCALAR SUBQUERY 1
   `--SEARCH TABLE meta2 USING COVERING INDEX uidxnc_meta2_parameter_value (parameter=? AND value=?)

It is, however, interesting that both partial queries (i.e. matching only on "parameter" or on "value", but not both) had always (even with the wrong table declaration) used the appropriate indexes:

QUERY PLAN
|--SCAN TABLE meta AS a USING COVERING INDEX metadata_idx_09
`--CORRELATED SCALAR SUBQUERY 1
   `--SEARCH TABLE meta2 USING COVERING INDEX idxnc_meta2_parameter (parameter=?)

QUERY PLAN
|--SCAN TABLE meta AS a
`--CORRELATED SCALAR SUBQUERY 1
   `--SEARCH TABLE meta2 USING COVERING INDEX idxnc_meta2_value (value=?)

So I'm not sure whether the behavior I observed is a bug or a feature. But thanks for helping!