During the interview, you will be asked a variety of strange questions. You may be able to give the most perfect solution from the actual point of view when thinking about the solution.
The following is a database-related interview question:
Statistics on the total number of CSDN Forum posts are required to be updated in real time!
In the case of MyISAM storage engine, select count (*) Query can be solved! Note: The MyISAM storage engine is basically unavailable on the Internet.
What about the Innodb Storage engine? What about tens of millions of posts? What about higher traffic volumes?
Some friends may want to add a statistical table. Each time a new post is generated, the statistical value in the statistical table is increased by 1,
This buddy's method can certainly solve the query problem, but during the peak hours, there may be dozens or even hundreds of new posts per second?
It's another nightmare, isn't it ......
In fact, is this a reasonable requirement for us to change our mindset? The resource input-output ratio caused by obvious demand is quite low.
How many people are concerned about the total number of posts updated in real time? Who cares about the inaccuracy of this data in a short period of time?
In fact, the problem of removing real-time updates is well solved. It is okay to create a statistical table and perform statistics once every time, isn't it?
This not only solves the efficiency problem of statistic value query, but also ensures that the efficiency of new posts is not affected.
Although there are not many such problems, there are actually many similar functions. For example, when we display them on pages after some expressions reach an order of magnitude
You do not need to accurately display the total number of items in the list and the total number of pages divided. Instead, you only need an approximate estimate or the statistical value before a time period.
This can also be used to save the COUNT operation of real-time big data.
Conclusion: From the Perspective of interview questions, we can often think about problems from another angle and think more about divergent thinking.
From the perspective of demand, not blindly real-time and accurate is a good and valuable solution.
Starting from the problem, we need to know the root cause of the problem.