A SQL query was made and sorted by the array subscripts obtained. But the predecessor said there will be a lot of visits when this is very memory consumption, online to see a lot of ways to say is to do the cache, there is no other way to deal with it?
Reply to discussion (solution)
Your statement does not consume memory very much. Activenum is the index on it.
Of course, the cache is the best.
Your statement does not consume memory very much. Activenum is the index on it.
Of course, the cache is the best.
If there are hundreds of thousands of of millions of data, will every time someone accesses index to fetch it without consuming resources?
If you add index, what index is good? This field is always changing.
Your statement does not consume memory very much. Activenum is the index on it.
Of course, the cache is the best.
If there are hundreds of thousands of of millions of data, will every time someone accesses index to fetch it without consuming resources?
If you add index, what index is good? This field is always changing.
If the data value is unique, add a unique index otherwise the normal index
If the MySQL table data is more than millions of, then you need to consider the sub-table
1, do not see the array subscript to sort the code
2, the activenum should be indexed (normal index can be)
3. Do you know the difference between accessing the database and accessing the cache?
Would it be appropriate to pass the pressure on the database to the cache?
If there are hundreds of thousands of of millions of data, what is your cache strategy?
1, do not see the array subscript to sort the code
2, the activenum should be indexed (normal index can be)
3. Do you know the difference between accessing the database and accessing the cache?
Would it be appropriate to pass the pressure on the database to the cache?
If there are hundreds of thousands of of millions of data, what is your cache strategy?
Activenum is a digital type, is it valid with index? Always think that the index is used only on the field where the function is, can the sorted field also be indexed?
Sorting can also be used to index, otherwise the amount of data is very large, do not apply the index, your database is not a crash.
1, do not see the array subscript to sort the code
2, the activenum should be indexed (normal index can be)
3. Do you know the difference between accessing the database and accessing the cache?
Would it be appropriate to pass the pressure on the database to the cache?
If there are hundreds of thousands of of millions of data, what is your cache strategy?
Currently activenum This field is not indexed.
EXPLAIN your query instructions.
MySQL will give you helpful advice! Rather than take it for granted.
EXPLAIN your query instructions.
MySQL will give you helpful advice! Rather than take it for granted.
With the command to find out that seems to be unable to use the index, I now think of one way is to create a rank table to put the user's ID, ranking according to the array to drop the mark into the Rank table, and then in the new table with a UID equal to 0 of the field, ranking where I write into the time, each time to take uid= 0 of the time, compared to the current time, if more than 30 minutes, then go back to the active table reading once ranked in the rank table. I wonder if this method works?
Possible_key is an index that can be used, because you do not index the activenum, naturally there is no
So the Extra column has Filesort, indicating that a temporary file is used to sort the activenum.
Possible_key is an index that can be used, because you do not index the activenum, naturally there is no
So the Extra column has Filesort, indicating that a temporary file is used to sort the activenum.
OK, I'll do the drum again, PHP in Linux there is no distinction between thread safety? Per user access once, for example, I wrote a DB call database, is it a reference only once, all users use this one, or everyone is independent?
Everyone is independent.
You can try the singleton mode and try to put the result in a static variable.
If the amount of the query is very large, and the data is not real-time, it can be cached for processing. But if the data is real-time, I think it's the basis to find out where the bottleneck is, the normal index and so on.
Thank you, the temporary table for the cache solution.