mercredi 22 avril 2015

Comparison operators behave differently after indexing

With this schema:

CREATE TABLE temperatures(
 sometext TEXT,
 lowtemp INT,
 hightemp INT,
 moretext TEXT);

When I do search

select * from temperatures where lowtemp < 20 and hightemp > 20;

I get the correct result which is always one record (due to the specifics of the data).

Now, when I index the table:

CREATE INDEX ltemps ON temperatures(lowtemp);
CREATE INDEX htemps ON temperatures(hightemp);

The exact same query above stops providing expected results -- now I get many records, including ones where the lowtemp and hightemp obviously don't meet the comparison test.

I'm running this on the same sqlite3 database, same table. The only difference is adding the above 2 index statements after table creation.

Can someone explain how indexing influences this behavior?

Aucun commentaire:

Enregistrer un commentaire