Is performance improvements gained from indexing worth it
Depends on the queries you intend to run.
- If you have something like:
WHERE day = ...
, then you'll need an index whose leading edge contains day
. If properly used, indexes can speed-up querying many orders of magnitude, especially on large data sets.
- OTOH, every additional index costs space/cache and INSERT/UPDATE/DELETE performance.
At the end of the day, I recommend you measure on realistic amounts of data and come to your own conclusions.
BTW, If you are using InnoDB, then your table is clustered (see also: Understanding InnoDB clustered indexes) and the whole table is effectively stored in the primary index. The secondary indexes in clustered tables contain copy of the PK fields, which (I'm assuming) is user_id
in this case. And since we only have two fields in the table, the secondary index on { day
} will cover the user_id
as well, avoiding a double-lookup that could otherwise happen in a clustered table. Effectively, you'll end-up with two separate (but synchronized) B-Trees and an index-only scan no matter which one of them you access (which is good). Of course, you could explicitly make a composite index on {day
, user_id
} instead of just { day
}, for a very similar effect.