I have a field, post_status, in my backend database, that I use to categorize posts. Each category is a numeric code so SQL can filter it relatively quickly. I have statuses for active posts, dead posts, ignored links, links needing review, etc.
It's a way for me to sort through my scraper's results quickly.
What would you suggest as a non-optimized alternative? That might make your point about premature optimization clearer.
After all, hardware is cheap, but developer time isn't.
For a more concrete example, I might have chosen the value `'pending'` (or similar) instead of `5`. Active listings might have status `'active'`. Expired ones might have status `'expired'`, etc.
I use the following scheme:
1 - exhausted
0 - alive
-1 - blocked (by my rules)
-2 - redirected
-3 - errorOn my own little SaaS project, the difference between querying an integer and a varchar like “active” is imperceptible, and that’s in a table with 7,000,000 rows.
It would take the author 19 years to run into the scale that I’m running at, where this optimisation is meaningless. And that’s assuming they don’t periodically clean their database of stale data, which they should.
So this looks like a premature optimisation to me, which is why it stood out as odd to me in the article.
You can map meaning onto the column in your code, as most languages have enums that are free in terms of performance. It does not make sense to burden the storage layer with this, as it lacks this feature.
Was just looking at how to do this with an enum today! Read my mind. :)
> if you have a sufficiently large database
Roughly 360,000 rows per year is not sufficiently large. It's tiny.