Well, that’s why the decisions related to this issue are actually a bit nuanced. I went ahead and decided to answer, but also wanted to consider some of the nuances / details that are not yet considered.
Firstly, I would strongly advise you not to use auto_increment for the primary key, if not for some other reason, which is very easy for these auto increment identifiers to be discarded (for example, rollback transactions will prevent them from MySQL AUTO_INCREMENT not ROLLBACK . This will be deleted as mentioned by @Sebas).
Secondly, you should consider your storage engine. If you use MyISAM, you can get COUNT (*) tables very quickly (since MyISAM always knows how many rows are in each table). If you use INNODB, it is not. Depending on what you need this table for, you may leave with MyISAM. This is not the default mechanism, but, of course, you may encounter a requirement for which MyISAM will be the best choice.
The third thing you should ask yourself is: "Why?" Why do you need to store data this way? What does this actually give you? Do you really need this information in SQL? In the same SQL table table?
And if “Why” has an answer that justifies its use, then the last thing I ask is “how?” In particular, how are you going to do parallel inserts? How are you going to deal with deletion or kickbacks?
Given what you have, you actually need a table counting table ... but even so, there are some nuances (deletes, rollbacks, concurrency), as well as some decisions that need to be made (which storage engine you are using, can you avoid using MyISAM, which will be faster for counting stars?).
Moreover, I would ask why I need this in the first place. Maybe you really ... but it's a terribly strange claim.
IN LIGHT FROM YOUR IMAGE:
EDIT: the reason for this is to sort the table by this particular area; and this field will be controlled by the user on the client side using jQuery sorting
Essentially, you are requesting metadata about your tables. And I would recommend storing this metadata in a separate table or in a separate service in general (Elastic Search, Redis, etc.). You need to periodically update this separate table (or storage of key values). If you do this in SQL, you can use a trigger. Or you used something like Elastic Search, you can embed your data in SQL and ES at the same time. In any case, you have some difficult problems that you need to deal with (for example, possible consistency, concurrency, all nice things that can have unpleasant consequences when using triggers in MySQL).
If it were me, I would point out two things. Firstly, even Google does not always update COUNT(*) . "Showing lines 1-10 of approximately XYZ." They do this partly because they have more data that I believe you are doing, and partly because it is actually impractical (and very quickly becoming impracticable and not permissible) to calculate the exact COUNT(*) table and constant updates all the time.
So, either I completely changed my requirement, or used statistics that I can get quickly (if you use MyISAM for storage, continue to use count( * ) ... it will be very fast), or I would consider supporting the index of counting stars of my tables, which is periodically updated through some process (cron job, trigger, whatever) every couple of hours or every day or something like that.
In gratitude for this question ... there will never be a single canonical answer to this question. There are trade-offs that need to be made no matter how you decide to manage it. They can be a compromise in terms of consistency, latency, scalability, exact and approximate solutions, loss of INNODB in exchange for MyISAM ... but there will be compromises. And ultimately, the decision comes down to the fact that you are ready to trade in order to get your demand.
If it were me, I would probably have knocked down my claim. And if I did, I would most likely index it in Elastic Search and make sure it is updated every couple of hours or so. Is that what you should do? It depends. This is definitely not the “right answer”, as it is one answer (out of many) that will work if I can live with the fact that my COUNT(*) bit outdated.
Should you use Elastic Search for this? It depends. But you will have to deal with the tradeoffs that you ever go. It does not depend. And you will need to decide that you are ready to give up in order to get what you want. If this is not critical, bend the requirement.