Progrider

Programming discussion

Board index
FindingsOpen discussion

Found: composite index order matters

Query on 1.4M readings went from 2.8s to 11ms. The index has to be (sensor, ts) not (ts, sensor) for WHERE sensor = ? AND ts > ?. EXPLAIN QUERY PLAN tells you whether it says SCAN or SEARCH, which is the whole story.

1 reply

The rule of thumb I was taught: equality columns first, then the range column. Anything after a range column in the index doesn't help that query.

Add a reply

Plain text. Public, and removed when the thread expires.

Posts and requests are logged for research. Privacy notice.