我从示例配置文件中读取了以下内容:
# Sort buffer is used to perform sorts for some ORDER BY and GROUP BY
# queries. If sorted data does not fit into the sort buffer, a disk
# based merge sort is used instead - See the "Sort_merge_passes"
# status variable. Allocated per thread if sort is needed.
我有几个使用filesort的查询.如何确定查询在没有访问磁盘的情况下平稳运行所需的缓冲区大小?
解决方法:
只有一个状态变量关注sort_buffer_size.这就是你在问题中回复的信息:Sort_merge_passes.MySQL文档说:
Sort_merge_passes : The number of merge passes that the sort algorithm has had to do. If this value is large, you should consider increasing the value of the 07002 system variable.
关于sort_buffer_size,请记住一件事
If you see many Sort_merge_passes per second in SHOW GLOBAL STATUS output, you can consider increasing the sort_buffer_size value to speed up ORDER BY or GROUP BY operations that cannot be improved with query optimization or improved indexing
虽然提高sort_buffer_size可以帮助查询使用GROUP BY和ORDER BY的查询,但最好还是改进可以改进的查询并添加可供查询优化器使用的索引.
问题仍然存在:你如何检查Sort_merge_passes ???
使用此代码检查过去5分钟内发生的Sort_merge_passes数量.它还计算每小时的Sort_merge_passes.
SET @SleepTime = 300;
SELECT variable_value INTO @SMP1
FROM information_schema.global_status WHERE variable_name = 'Sort_merge_passes';
SELECT SLEEP(@SleepTime) INTO @x;
SELECT variable_value INTO @SMP2
FROM information_schema.global_status WHERE variable_name = 'Sort_merge_passes';
SET @SMP = @SMP2 - @SMP1;
SET @SMP_RATE = @SMP * 3600 / @SleepTime;
SELECT @SMP,@SMP_RATE;
如果你发现Sort_merge_passes和速率太高,那么随意增加sort_buffer_size.假设你想提高到4M.你会运行这个:
mysql> SET GLOBAL sort_buffer_size = 1024 * 1024 * 4;
然后你会把它添加到my.cnf
[mysqld]
sort_buffer_size = 4M
您将定期运行代码以检查Sort_merge_passes峰值的其他时间.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。