What exactly is read_rnd_buffer_size

Peter Zaitsev  | July 24, 2007 |  Posted In: Insight for DBAs

Looking for documentation for read_rnd_buffer_size you would find descriptions such as “The read_rnd_buffer_size is used after a sort, when reading rows in sorted order. If you use many queries with ORDER BY, upping this can improve performance” which is cool but it does not really tell you how exactly read_rnd_buffer_size works as well as which layer it corresponds to – SQL or storage engine.

Honestly as it had name very similar to read_buffer_size which is currently only used by MyISAM tables I thoughtread_rnd_buffer_size is also MyISAM only. But talking to Monty today I learned it is not the case.

read_rnd_buffer can be used for All storage engines not only by MyISAM. It is used for some sorts to optimally read rows after the sort. Here is how it works:

As sort is performed it can be performed having only row pointers together with key value – which are offsets for MyISAM and primary key values for Innodb or storing full data which is being retrieved (good for small data lengths).

In case sort with row pointer storage is used and the fields which are being length can be converted to fixed size (basically everything but BLOB/TEXT) MySQL can use read_rnd_buffer to optimize data retrieval – As data is sorted by the key value it needs to be accessed in pretty much random row pointer (typically physical) order. MySQL takes bunch of pointers from sort_buffer (just enough so all rows fit in read_rnd_buffer as they are read) and sorts them by row pointer, when performs reading into read_rnd_buffer in the sorted order – it can be pretty much sequential if you’re lucky.

The read_rnd_buffer_size is important (optimization works in following conditions):

  • Row pointers are stored in the sort_buffer, not the whole data selected
  • Blob/Text columns are not selected
  • A lot of rows are retrieved after sort – if you have LIMIT 10 it is unlikely to help as MySQL will stop fetching rows by
    pointers quickly

For me this means since MySQL 4.1 this option is used in narrow range of cases – if you retrieve few fields (less thanmax_length_for_sort_data) data should be stored in sort buffer and sort file so there would be no need for read_rnd_buffer, if the selected columns are long so they are longer than max_length_for_sort_data it would frequently mean there are some TEXT/BLOB columns among them. It would be used however if there is large number of columns or there are long VARCHAR columns used – it takes only couple of UTF8 VARCHAR(255) to create a row which is longer than max_length_for_sort_data in its static presentation.

We should do benchmarks sometime to see how it really impacts performance both for MyISAM and Innodb.

时间: 2024-08-26 05:00:34

What exactly is read_rnd_buffer_size的相关文章

(转)625某电商网站数据库宕机故障解决实录(下)

1.4开始进行故障恢复***** 1.重新初始化建库 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 [[email protected] data]# mkdir mysql [[email protected] data]# chown -R mysql.mysql mysql [ro[email protected] data]# /install/mysql/sc

lnmp脚本

#!/bin/bash#Function: Install LNMP#Author: wang#Date: 20170809 nginx_install(){useradd www -u 509 -s /bin/bash -mmkdir -p /opt/server/nginx/temp #Install the make GCCyum -y install gcc gcc-c++ automake autoconf libtool make #Installing PCRE library (

同一台MySQL服务器启动多个端口

wget  二进制的源码包 解压 cat INSTLL-BINARY 根据说明操作,具体安装步骤请看 http://www.lishiming.net/thread-7-1-1.html 其中1-4步骤是相同的,第5步,也是最重要的一步,要初始化数据库因为是多个端口,所以要根据配置文件来初始化多个数据库比如说有2个端口则要运行两次 ./scripts/mysql_install_db --datadir=/home/mysql1 --user=mysql./scripts/mysql_insta

MySQL内存使用分析

MySQL中内存分为全局内存和线程内存两大部分(其实并不全部,只是影响比较大的 部分) 线程内存公式: per_thread_buffers=(read_buffer_size+read_rnd_buffer_size+sort_buffer_size+thread_stack+join_buffer_size+binlog_cache_size+tmp_table_size)*max_connections 全局内存: global_buffers=innodb_buffer_pool_siz

centos 7.2 Apache+mysql+php step by step备忘

1. 如何允许laravel程序执行sudo shell脚本? chmod u+w /etc/sudoers ; echo "apache ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers 再注释掉Defaults requiretty这行,否则会要求有tty才能运行!(TODO: 写shell实现自动化) chmod u-w /etc/sudoers2. OS: CentOS 7.2 x643. 安装zend server ce: (由于ze

自动安装MySQL脚本

在Linux 上安装MySQL单实例SHELL脚本 在CentOS 6.5环境测试通过 #!/bin/bash user=mysql group=mysql port=3306 basedir=/usr/local/mysql datadir=/data/mysql/mysql_${port}/data sourcefile=$1 mysqlprofile=/etc/my.cnf logfile=/tmp/mysqlinstall.log nowtime=`date '+%Y-%m-%d %H:

阿里云RDS-MYSQL数据库参数设置,K哥

2016.9.2 最近被阿里云的数据库要搞疯掉了 自打阿里云抽风,非要取消myisam引擎,都换成innodb 没事总是主备切换,也没有错误日志 一问客服就是物理机波动,擦,波动是什么???????? 服务器自己跳舞了吗 看了看参数设置,很多都不知道 这两天有时间自己搜索整理了下 发给大家,有需要的看看 我的服务器应用主要是WEB网站服务 有一些不懂的地方或者不对的地方,还请大牛不吝赐教! 回复在评论中就可以了,thank you 我是K哥 auto_increment_offset表示自增长字

mysql的安装和基本配置

一.mysql的安装和基本配置 1 安装cmake #./configure#make &&make install 2 安装mysql# yum install ncurses* bison*   # cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/database/mydata -DSYSCONFDIR=/etc -DTMPDIR=/tmp -DWITH_INNOBASE_STORAGE_ENGINE=1 -

mysql多实例配置

mysql多实例配置  就是在一台服务器上运行多个mysql实例,每个实例需要一个独立的端口,实例的配置可以按实际需求进行设置  1.配置mysql多实例  # vim /etc/my.cnf[mysqld_multi]mysqld = /usr/local/mysql/bin/mysqld_safemysqladmin = /usr/local/mysql/bin/mysqladminuser = mysqllog = /database/log/mysqld-muti.log join_bu