Mysql index creation

time, amount, status, user ID.
how can the combination of four fields be more optimized if you want to create a combined index to improve search efficiency?
the specific role is to be used for background management. Given that each is likely to be used frequently, it is not clear who would be more appropriate to start first.
I hope there are bosses to provide advice and reference. Thank you.

Apr.03,2021

The index of

MySQL mainly refers to the BTree index, which needs to follow the leftmost prefix principle. The conventional practice will customize the index according to the select statement. In scenarios like this background management, sql is basically concatenated, and it can be said that there is no fixed index. In this case, you can use the following scheme to optimize:

  1. do not build an index for the time being, open the slow query of MySQL, make a statistical analysis of the slow query in the system, and then optimize the index pertinently
  2. use MySQL master-slave architecture to query the slave database. The system will be slow, but it will not affect the master database
  3. abandon MySQL, to use search engine technology, and lucene-based Solr or es

you don't need a combined index at all.
user ID individual index, time separate index is fine
specific reason, because the index only works when the number you look up is less than 20% of the total function
, that is to say, the number of low uniqueness fields such as state without indexing
amount is indeed high uniqueness, but his update should be quite frequent. If he is indexed, It means that every update has to rebuild the index, so this field is not suitable for indexing

.
Menu