性能方面
innodb_stats_method
这个参数会影响表的统计信息收集,影响统计信息的value group,
默认值是
nulls_equal
If the
NULL
value group size is much higher than the average non-
NULL
value group size, this method skews the average value group size upward. This makes index appear to the optimizer to be less useful than it really is for joins that look for non-
NULL
values. Consequently, the
nulls_equal
method may cause the optimizer not to use the index for
ref
accesses when it should.
也就是说如何这个字段有很多的null,但是设置的
equal会将它们看成是一个值,这样在ref的时候可能会导致无法使用索引。
https://dev.mysql.com/doc/refman/5.7/en/index-statistics.html
这个是一个null 导致延时的案例,但是这个案例也是比较少见,表上没有主键,master上执行计划采用了基于成本的算法,但是slave上采用的是机遇规则匹配,
- PK
- UK without NULL
- other keys(include UK with NULL)
- table_scan
http://mysql.taobao.org/monthly/2018/01/04/ 从库中的decide_row_lookup_algorithm_and_key()中调用search_key_in_table 所以一般上来说null导致性能问题,就是出现在null值太多,数据发生倾斜,而表发生了关联导致没有走索引。
