Hacker News new | ask | show | jobs
by RedShift1 1889 days ago
Storing both boolean and timestamp with the correct constraints seems like a better solution to me.
1 comments

This is the typical solution for MySQL. There are indexable virtual generated columns but don't seem to have been used/around enough to be battle tested.

Using just the nullable timestamp only lets you index on one of the boolean states: an index on (ts, col2) works for WHERE ts IS NULL ORDER BY col2, but WHERE ts IS NOT NULL ORDER BY col2 doesn't work well (without using generated boolean, etc).