mysql> select @@tidb_partition_prune_mode;
+-----------------------------+
| @@tidb_partition_prune_mode |
+-----------------------------+
| dynamic |
+-----------------------------+
1 row in set (0.00 sec)
mysql> CREATE TABLE t (a int) PARTITION BY RANGE( a ) (
-> PARTITION p0 VALUES LESS THAN (10),
-> PARTITION p1 VALUES LESS THAN (MAXVALUE)
-> );
Query OK, 0 rows affected (0.04 sec)
mysql> insert into t values (1), (100);
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> insert into t select a + 1 from t where a > 10;
Query OK, 1 row affected, 1 warning (0.00 sec)
Records: 1 Duplicates: 0 Warnings: 1
-- repeat insert ... select ... to make the row count of p1 exceed 1000
-- wait 1 min to dump stats delta
mysql> show stats_meta;
+---------+------------+----------------+---------------------+--------------+-----------+
| Db_name | Table_name | Partition_name | Update_time | Modify_count | Row_count |
+---------+------------+----------------+---------------------+--------------+-----------+
| test | t | global | 2022-11-09 11:08:01 | 8193 | 8193 |
| test | t | p0 | 2022-11-09 11:07:01 | 1 | 1 |
| test | t | p1 | 2022-11-09 11:08:01 | 8192 | 8192 |
+---------+------------+----------------+---------------------+--------------+-----------+
3 rows in set (0.00 sec)
Notice that we don't trigger auto analyze when row count is less then 1000. So p0 would not be auto analyzed and
When auto analyze table t partition p1 is triggered, we see the following logs:
Since p0 doesn't have statistics, merging partition statistics to global statistics fails.
For a partition table, if the row count of some paritition is less than 1000, the partition would not be auto analyzed. When some other partitions are auto analyzed, global statistics cannot be merged successfully due to missing partition statistics. Besides, the fail reason of global statistics is added into warnings and we cannot see the warnings of auto analyze. In other word, we cannot see any error in logs when the case happens.
There are several things we need to do:
When statistics of some partition have problems(for example, some partition has no statistics) and cannot participate in the procedure of merging partition statistics to global statistics, currently we just give up the procedure and global statistics cannot be updated. A more reasonable behavior is to exclude the partition whose statistics have problems and merge statistics of other partitions to global statistics.
Add more logs about merging partition statistics to global statistics.
Enhance auto analyze mechanism. Maybe we should trigger auto analyze for the tables whose row count is less than 1000.
Enhancement
Notice that we don't trigger auto analyze when row count is less then 1000. So
p0
would not be auto analyzed and Whenauto analyze table t partition p1
is triggered, we see the following logs:PS: the last two logs are added by me for debugging
Since
p0
doesn't have statistics, merging partition statistics to global statistics fails.For a partition table, if the row count of some paritition is less than 1000, the partition would not be auto analyzed. When some other partitions are auto analyzed, global statistics cannot be merged successfully due to missing partition statistics. Besides, the fail reason of global statistics is added into warnings and we cannot see the warnings of auto analyze. In other word, we cannot see any error in logs when the case happens.
There are several things we need to do: