SQLite Forum

Usage of suboptimum index
Login
That's not what the stat1 data you showed us means.

The stat1 data for Index2 is "80965 80965 80965 1 1".  The first number is
the number of entries in that index.  The second number is the number of
rows that you would expect to select using an equality constraint on just
the first term.  The third number is the number of rows you would expect to
select using equality constraints on the first two terms.  The fourth number
is the number of rows you would expect to select using equality constraints
on the first three terms.

The fourth number is 1, so we expect that the equality constraints on the
first three terms of the index will narrow down the search to just 1 row.

Since you have equality constraints on the all four columns of both Index1
and Index2, SQLite expects that a single binary search against either of these
indexes to narrow down to just one row.

I don't know why that isn't work for you.

Perhaps we could analyze the situation better if you supplied us with the
complete schema for your database together with all of the stat1 data.
Basically, we'd like to see the output of this command:

~~~~~
  .fullschema
~~~~~

It would also be helpful to see the
complete output from the following four commands:

~~~~~
  EXPLAIN QUERY PLAN
  SELECT
     Relations.IDSecondDatum,Games.Result
  FROM
     Games,Relations,Classifications
   WHERE
     (Games.BlackID=?1)AND
     (Relations.TypeFirstDatum==2)AND
     (Relations.IDFirstDatum=Games.ID)AND
     (Relations.TypeSecondDatum=3)AND
     (Relations.IDSecondDatum=Classifications.ID)AND
     (Classifications.System=?4)AND
     (Classifications.GameType=?5);

  EXPLAIN QUERY PLAN
  SELECT
     Relations.IDSecondDatum,Games.Result
  FROM
     Games,Relations INDEXED BY Relations_Index1,Classifications
   WHERE
     (Games.BlackID=?1)AND
     (Relations.TypeFirstDatum==2)AND
     (Relations.IDFirstDatum=Games.ID)AND
     (Relations.TypeSecondDatum=3)AND
     (Relations.IDSecondDatum=Classifications.ID)AND
     (Classifications.System=?4)AND
     (Classifications.GameType=?5);

  SELECT sqlite_source_id();

  PRAGMA compile_options;
~~~~~