I'm trying to improve the performance of a query with this table:
CREATE TABLE frag(hash primary key, type, ulen, clen, offset, refs);
SELECT MAX(offset + clen) AS 'EndPos', type AS 'Type' FROM frag GROUP BY type;
My query plan is as such:
sqlite> EXPLAIN QUERY PLAN SELECT MAX(offset + clen) AS 'Offset', type AS 'Type' FROM frag GROUP BY type;
QUERY PLAN
|--SCAN TABLE frag
`--USE TEMP B-TREE FOR GROUP BY
After creating a new index, the query plan changes to this:
CREATE INDEX max_frag ON frag(type, offset+clen DESC);
sqlite> EXPLAIN QUERY PLAN SELECT MAX(offset + clen) AS 'EndPos', type AS 'Type' FROM frag GROUP BY type;
QUERY PLAN
`--SCAN TABLE frag USING INDEX max_frag
My issue is that my query has slowed from from taking 90s to 280s with this new index. My database is 5.6GB large, with 45.5 million rows. Why is a full table scan faster than using this index? .expert is telling me that no new index can improve this