1. What is the cardinality? If this type of index is unique, then the cardinality = number of rows. If this column is sex, and the enumeration type only has male and female, then its cardinality is 2 The higher the Cardinality, the more worthy the column is to be indexed. MySQL execution plan also selects indexes based on Cardinality. The cardinality of each column in the table can be seen in the following way. Take this classic example: 2. When does InnoDB update the cardinality? 3. The base number is estimated The base number is not updated in real time! And it is a value estimated through sampling! As for what the formula for the base is, it may not be important. It is important to know that it is an estimate calculated by randomly sampling data pages. And the number of randomly sampled pages can be set by the parameter innodb_stats_persistent_sample_pages, the default value is 20.
4. Persistent Cardinality You can use the parameter innodb_stats_persistent to control whether the cardinality is persisted. The default setting is off. Of course you can set STATS_PERSISTENT=1 for a single table and its innodb_stats_persistent will be automatically enabled. The advantage of enabling it is that restarting MySQL will not recalculate this value, thus speeding up the restart process. 5. How to actively update the base? Executing the following SQL will trigger InnoDB to update the cardinality (even if you don't realize it will update the cardinality). So try to choose a low business peak period analyze table tableName; If the number of samples is too small, the calculated cardinality will be extremely wrong. That will most likely cause the MySQL optimizer to choose the wrong index. This is where you can increase the value appropriately. But increasing it too much may cause ANALYZE TABLE to run slowly. Conversely, ANALYZE TABLE runs too slowly. You can adjust the value of the parameter innodb_stats_persistent_sample_pages appropriately. However, this may lead to inaccurate cardinality calculation.
refer to: https://dev.mysql.com/doc/refman/5.7/en/innodb-persistent-stats.html https://dev.mysql.com/doc/refman/5.7/en/innodb-analyze-table-complexity.html The above is a brief analysis of the details of MySQL cardinality statistics. For more information about MySQL cardinality statistics, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: Detailed explanation of web page loading progress bar (recommended)
>>: Solution to the problem of insufficient storage resource pool of Docker server
According to the coefficient of pi and the radius...
When using Docker in a production environment, da...
Brief description The editor often encounters som...
Table of contents Prerequisites RN passes value t...
[Abstract] This article quickly builds a complete...
Preface I'm currently working on the data ana...
How to install MySQL 5.7.18 on Linux 1. Download ...
Preface The latest version of MySQL 8.0 is 8.0.4 ...
We can create jsx/tsx files directly The project ...
In the previous article, we talked about MySQL tr...
Portainer is an excellent Docker graphical manage...
In this article, we will analyze the production of...
Table of contents 1. How to switch 2. Dynamically...
Copy code The code is as follows: <!DOCTYPE ht...
Table of contents Preface 1. The significance of ...