查询语句: select count(distinct concat('ab',content)) dis ,count(*) all from im_message_201001_12 where owner='huaniaoyuchong83' and time between '2010-01-01 00:00:00' and '2010-02-01 00:00:00' ;
#######测试环境: OS:RHEL 4.7 X86_64 MYSQL 5.0.51a / 5.1.40
请在开始下面测试前,运行: select count(distinct concat('c',content)),count(*) from im_message_201001_11 where owner='huaniaoyuchong83' ; 以让所有结果都在CACHE里;
#######开始第一次测试 show session status like 'Innodb_buffer_pool_read_requests'; +----------------------------------+-----------+ | Variable_name | Value | +----------------------------------+-----------+ | Innodb_buffer_pool_read_requests | 136566076 | +----------------------------------+-----------+ 1 row in set (0.02 sec)
select count(distinct concat('c',content)),count(*) from im_message_201001_11 where owner='huaniaoyuchong83' and time between '2010-01-01 00:00:00' and '2010-02-01 00:00:00' ;
+-------------------------------------+----------+ | count(distinct concat('c',content)) | count(*) | +-------------------------------------+----------+ | 35644 | 44397 | +-------------------------------------+----------+ 1 row in set (1.40 sec)
show session status like 'Innodb_buffer_pool_read_requests'; +----------------------------------+-----------+ | Variable_name | Value | +----------------------------------+-----------+ | Innodb_buffer_pool_read_requests | 136742193 | +----------------------------------+-----------+ 1 row in set (0.02 sec)
select 136742193-136566076 ; +---------------------+ | 136742193-136566076 | +---------------------+ | 176117 | +---------------------+ 1 row in set (0.00 sec)
#######开始第二次测试 show session status like 'Innodb_buffer_pool_read_requests'; +----------------------------------+-----------+ | Variable_name | Value | +----------------------------------+-----------+ | Innodb_buffer_pool_read_requests | 136742194 | +----------------------------------+-----------+ 1 row in set (0.02 sec)
select count(distinct concat('c',content)),count(*) from im_message_201001_11 where owner='huaniaoyuchong83' and time between '2010-01-01 00:00:00' and '2010-01-05 00:00:00' ;
+-------------------------------------+----------+ | count(distinct concat('c',content)) | count(*) | +-------------------------------------+----------+ | 3679 | 4097 | +-------------------------------------+----------+ 1 row in set (0.74 sec)
show session status like 'Innodb_buffer_pool_read_requests'; +----------------------------------+-----------+ | Variable_name | Value | +----------------------------------+-----------+ | Innodb_buffer_pool_read_requests | 136916032 | +----------------------------------+-----------+ 1 row in set (0.01 sec)
select 136916032-136742194; +---------------------+ | 136916032-136742194 | +---------------------+ | 173838 | +---------------------+ 1 row in set (0.00 sec)
#######开始第三次测试
show session status like 'Innodb_buffer_pool_read_requests'; +----------------------------------+-----------+ | Variable_name | Value | +----------------------------------+-----------+ | Innodb_buffer_pool_read_requests | 136916033 | +----------------------------------+-----------+ 1 row in set (0.01 sec)
select count(distinct concat('c',content)),count(*) from im_message_201001_11 where owner='huaniaoyuchong83' and time between '2010-01-01 00:00:00' and '2010-01-01 00:00:00' ;
+-------------------------------------+----------+ | count(distinct concat('c',content)) | count(*) | +-------------------------------------+----------+ | 0 | 0 | +-------------------------------------+----------+ 1 row in set (0.85 sec)
show session status like 'Innodb_buffer_pool_read_requests'; +----------------------------------+-----------+ | Variable_name | Value | +----------------------------------+-----------+ | Innodb_buffer_pool_read_requests | 137086323 | +----------------------------------+-----------+ 1 row in set (0.01 sec)
select 137086323-136916033; +---------------------+ | 137086323-136916033 | +---------------------+ | 170290 | +---------------------+ 1 row in set (0.00 sec)
#######开始第四次测试
show session status like 'Innodb_buffer_pool_read_requests'; +----------------------------------+-----------+ | Variable_name | Value | +----------------------------------+-----------+ | Innodb_buffer_pool_read_requests | 137086324 | +----------------------------------+-----------+ 1 row in set (0.02 sec)
select count(*) from im_message_201001_11 where owner='huaniaoyuchong83' and time between '2010-01-01 00:00:00' and '2010-02-01 00:00:00' ; +----------+ | count(*) | +----------+ | 44397 | +----------+ 1 row in set (0.05 sec)
show session status like 'Innodb_buffer_pool_read_requests'; +----------------------------------+-----------+ | Variable_name | Value | +----------------------------------+-----------+ | Innodb_buffer_pool_read_requests | 137092204 | +----------------------------------+-----------+ 1 row in set (0.01 sec)
select 137092204-137086324 ; +---------------------+ | 137092204-137086324 | +---------------------+ | 5880 | +---------------------+ 1 row in set (0.00 sec)
#######开始第五次测试
show session status like 'Innodb_buffer_pool_read_requests'; +----------------------------------+-----------+ | Variable_name | Value | +----------------------------------+-----------+ | Innodb_buffer_pool_read_requests | 137092205 | +----------------------------------+-----------+ 1 row in set (0.01 sec)
select count(*) from im_message_201001_11 where owner='huaniaoyuchong83' ; +----------+ | count(*) | +----------+ | 44397 | +----------+ 1 row in set (0.04 sec)
show session status like 'Innodb_buffer_pool_read_requests'; +----------------------------------+-----------+ | Variable_name | Value | +----------------------------------+-----------+ | Innodb_buffer_pool_read_requests | 137098085 | +----------------------------------+-----------+ 1 row in set (0.01 sec)
select 137098085-137092205 ; +---------------------+ | 137098085-137092205 | +---------------------+ | 5880 | +---------------------+ 1 row in set (0.00 sec)
#######开始第六次测试
show session status like 'Innodb_buffer_pool_read_requests'; +----------------------------------+-----------+ | Variable_name | Value | +----------------------------------+-----------+ | Innodb_buffer_pool_read_requests | 137098131 | +----------------------------------+-----------+ 1 row in set (0.02 sec)
select count(*) from im_message_201001_11 where owner='huaniaoyuchong83' and time between '2010-01-01 00:00:00' and '2010-01-05 00:00:00' ; +----------+ | count(*) | +----------+ | 4097 | +----------+ 1 row in set (0.05 sec)
show session status like 'Innodb_buffer_pool_read_requests'; +----------------------------------+-----------+ | Variable_name | Value | +----------------------------------+-----------+ | Innodb_buffer_pool_read_requests | 137104011 | +----------------------------------+-----------+ 1 row in set (0.01 sec)
select 137104011-137098131; +---------------------+ | 137104011-137098131 | +---------------------+ | 5880 | +---------------------+ 1 row in set (0.00 sec)