The “right” way to design is to use another table, join it, and COUNT . This is consistent with what database normalization teaches.
The problem with normalization is that it cannot scale. There are so many ways to drop a cat, so if you have millions of queries per day, and many of them are related to table X, the database performance goes below ground level, as the server also has to deal with simultaneous records, transactions, etc. d ..
To deal with this problem, the general practice of sharding . Sharding has a side effect that table rows are not stored in the same physical location, and the main consequence of this is that you can no longer JOIN ; how can you JOIN against half the table and get meaningful results? And, obviously, trying JOIN to all sections of the table and merging the results will be worse than the disease.
So, you see that not only the alternative that you are studying is used in practice to achieve high performance, but also the more radical steps that engineers can and do.
Of course, if you have no performance issues, scalding or even de-normalizing just makes life difficult without any tangible benefits.
Jon
source share