gpt4 book ai didi

mysql - order by 子句中的可为空索引列是否会影响 MySQL 查询性能?

转载 作者:行者123 更新时间:2023-11-29 17:11:38 25 4
gpt4 key购买 nike

我有一个包含超过一百万行的表和一个执行良好的选择查询,直到我必须进行架构更改以使 order by 子句中使用的列接受空值。该列始终已建立索引。唯一的变化是它现在允许空值。

进行更改后,查询性能显着下降,导致相同流量的 CPU 峰值达到 30 倍。

order by 子句中只有一个列。类似于 order by id desc ,其中 id 是无符号 bigint,并且已建立索引,默认为 NULL

删除该列上的索引可以解决问题,但我无法理解其根本原因。我

知道会发生什么吗?

最佳答案

Does having a nullable indexed column in the order by clause affect MySQL query performance?

是的,确实如此。

Declare columns to be NOT NULL if possible. It makes SQL operations faster, by enabling better use of indexes and eliminating overhead for testing whether each value is NULL. You also save some storage space, one bit per column. If you really need NULL values in your tables, use them. Just avoid the default setting that allows NULL values in every column

来源https://dev.mysql.com/doc/refman/5.5/en/data-size.html

关于mysql - order by 子句中的可为空索引列是否会影响 MySQL 查询性能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51865533/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com