[Commits] Rev 3391: Add MRR counters: Handler_mrr_init, Handler_mrr_extra_rowid_sorts, in file:///home/psergey/dev2/5.3-look48/

Sergey Petrunya psergey at askmonty.org
Mon Jan 23 21:35:56 EET 2012


At file:///home/psergey/dev2/5.3-look48/

------------------------------------------------------------
revno: 3391
revision-id: psergey at askmonty.org-20120123193552-oxbf2q6p7k1kqioo
parent: psergey at askmonty.org-20120119221153-vrvfy11wccbr47ql
committer: Sergey Petrunya <psergey at askmonty.org>
branch nick: 5.3-look48
timestamp: Mon 2012-01-23 23:35:52 +0400
message:
  Add MRR counters: Handler_mrr_init, Handler_mrr_extra_rowid_sorts, 
   Handler_mrr_extra_key_sorts.
=== modified file 'mysql-test/r/myisam_mrr.result'
--- a/mysql-test/r/myisam_mrr.result	2011-12-19 21:05:44 +0000
+++ b/mysql-test/r/myisam_mrr.result	2012-01-23 19:35:52 +0000
@@ -557,4 +557,81 @@
 set @@join_cache_level= @tmp_730133_jcl;
 set @@optimizer_switch= @tmp_730133_os;
 drop table t1;
+#
+# Test of MRR handler counters
+#
+flush status;
+show status like 'Handler_mrr%';
+Variable_name	Value
+Handler_mrr_extra_key_sorts	0
+Handler_mrr_extra_rowid_sorts	0
+Handler_mrr_init	0
+create table t0 (a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t1 (a int, b int, filler char(200), key(a));
+insert into t1 
+select A.a+10*B.a+100*C.a+1000*D.a, 123,'filler' from t0 A, t0 B, t0 C, t0 D;
+explain select sum(b) from t1 where a < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	a	a	5	NULL	8	Using index condition; Rowid-ordered scan
+# This should show one MRR scan and no re-fills:
+flush status;
+select sum(b) from t1 where a < 10;
+sum(b)
+1230
+show status like 'handler_mrr%';
+Variable_name	Value
+Handler_mrr_extra_key_sorts	0
+Handler_mrr_extra_rowid_sorts	0
+Handler_mrr_init	1
+set @mrr_buffer_size_save= @@mrr_buffer_size;
+set mrr_buffer_size=128;
+explain select sum(b) from t1 where a < 1600;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	a	a	5	NULL	1380	Using index condition; Rowid-ordered scan
+# This should show one MRR scan and one extra rowid sort:
+flush status;
+select sum(b) from t1 where a < 1600;
+sum(b)
+196800
+show status like 'handler_mrr%';
+Variable_name	Value
+Handler_mrr_extra_key_sorts	0
+Handler_mrr_extra_rowid_sorts	1
+Handler_mrr_init	1
+set @@mrr_buffer_size= @mrr_buffer_size_save;
+#Now, let's check BKA: 
+set @join_cache_level_save= @@join_cache_level;
+set @join_buffer_size_save= @@join_buffer_size;
+set join_cache_level=6;
+explain select sum(t1.b) from t0,t1 where t0.a=t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t0	ALL	NULL	NULL	NULL	NULL	10	Using where
+1	SIMPLE	t1	ref	a	a	5	test.t0.a	1	Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
+flush status;
+select sum(t1.b) from t0,t1 where t0.a=t1.a;
+sum(t1.b)
+1230
+show status like 'handler_mrr%';
+Variable_name	Value
+Handler_mrr_extra_key_sorts	0
+Handler_mrr_extra_rowid_sorts	0
+Handler_mrr_init	1
+set join_buffer_size=10;
+explain select sum(t1.b) from t0,t1 where t0.a=t1.a;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t0	ALL	NULL	NULL	NULL	NULL	10	Using where
+1	SIMPLE	t1	ref	a	a	5	test.t0.a	1	Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
+flush status;
+select sum(t1.b) from t0,t1 where t0.a=t1.a;
+sum(t1.b)
+1230
+show status like 'handler_mrr%';
+Variable_name	Value
+Handler_mrr_extra_key_sorts	1
+Handler_mrr_extra_rowid_sorts	1
+Handler_mrr_init	2
+set join_cache_level= @join_cache_level_save;
+set join_buffer_size= @join_buffer_size_save;
+drop table t0, t1;
 set optimizer_switch= @myisam_mrr_tmp;

=== modified file 'mysql-test/t/myisam_mrr.test'
--- a/mysql-test/t/myisam_mrr.test	2011-10-01 01:55:02 +0000
+++ b/mysql-test/t/myisam_mrr.test	2012-01-23 19:35:52 +0000
@@ -268,5 +268,57 @@
 set @@optimizer_switch= @tmp_730133_os;
 drop table t1;
 
+--echo #
+--echo # Test of MRR handler counters
+--echo #
+flush status;
+show status like 'Handler_mrr%';
+create table t0 (a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t1 (a int, b int, filler char(200), key(a));
+insert into t1 
+select A.a+10*B.a+100*C.a+1000*D.a, 123,'filler' from t0 A, t0 B, t0 C, t0 D;
+
+explain select sum(b) from t1 where a < 10;
+--echo # This should show one MRR scan and no re-fills:
+flush status;
+select sum(b) from t1 where a < 10;
+show status like 'handler_mrr%';
+
+set @mrr_buffer_size_save= @@mrr_buffer_size;
+--disable_warnings
+set mrr_buffer_size=128;
+--enable_warnings
+
+explain select sum(b) from t1 where a < 1600;
+--echo # This should show one MRR scan and one extra rowid sort:
+flush status;
+select sum(b) from t1 where a < 1600;
+show status like 'handler_mrr%';
+set @@mrr_buffer_size= @mrr_buffer_size_save;
+
+--echo #Now, let's check BKA: 
+set @join_cache_level_save= @@join_cache_level;
+set @join_buffer_size_save= @@join_buffer_size;
+set join_cache_level=6;
+
+explain select sum(t1.b) from t0,t1 where t0.a=t1.a;
+flush status;
+select sum(t1.b) from t0,t1 where t0.a=t1.a;
+show status like 'handler_mrr%';
+
+--disable_warnings
+set join_buffer_size=10;
+--enable_warnings
+explain select sum(t1.b) from t0,t1 where t0.a=t1.a;
+flush status;
+select sum(t1.b) from t0,t1 where t0.a=t1.a;
+show status like 'handler_mrr%';
+
+set join_cache_level= @join_cache_level_save;
+set join_buffer_size= @join_buffer_size_save;
+
+drop table t0, t1;
+
 ## This must be last line in the file:
 set optimizer_switch= @myisam_mrr_tmp;

=== modified file 'sql/multi_range_read.cc'
--- a/sql/multi_range_read.cc	2011-10-22 14:19:43 +0000
+++ b/sql/multi_range_read.cc	2012-01-23 19:35:52 +0000
@@ -466,6 +466,10 @@
 
 /**
   Fill the buffer with (lookup_tuple, range_id) pairs and sort
+
+  @return 
+    0                   OK, the buffer is non-empty and sorted
+    HA_ERR_END_OF_FILE  Source exhausted, the buffer is empty.
 */
 
 int Mrr_ordered_index_reader::refill_buffer(bool initial)
@@ -502,6 +506,13 @@
   if (source_exhausted && key_buffer->is_empty())
     DBUG_RETURN(HA_ERR_END_OF_FILE);
 
+  if (!initial)
+  {
+    /* This is a non-initial buffer fill and we've got a non-empty buffer */
+    THD *thd= current_thd;
+    status_var_increment(thd->status_var.ha_mrr_extra_key_sorts);
+  }
+
   key_buffer->sort((key_buffer->type() == Lifo_buffer::FORWARD)? 
                      (qsort2_cmp)Mrr_ordered_index_reader::compare_keys_reverse : 
                      (qsort2_cmp)Mrr_ordered_index_reader::compare_keys, 
@@ -576,6 +587,7 @@
 int Mrr_ordered_rndpos_reader::refill_buffer(bool initial)
 {
   int res;
+  bool first_call= initial;
   DBUG_ENTER("Mrr_ordered_rndpos_reader::refill_buffer");
 
   if (index_reader_exhausted)
@@ -593,6 +605,14 @@
     initial= FALSE;
     index_reader_needs_refill= FALSE;
   }
+
+  if (!first_call && !index_reader_exhausted)
+  {
+    /* Ok, this was a successful buffer refill operation */
+    THD *thd= current_thd;
+    status_var_increment(thd->status_var.ha_mrr_extra_rowid_sorts);
+  }
+
   DBUG_RETURN(res);
 }
 
@@ -825,8 +845,7 @@
     strategy= disk_strategy= &reader_factory.ordered_rndpos_reader;
   }
 
-  if (is_mrr_assoc)
-    status_var_increment(thd->status_var.ha_multi_range_read_init_count);
+  status_var_increment(thd->status_var.ha_multi_range_read_init_count);
 
   full_buf= buf->buffer;
   full_buf_end= buf->buffer_end;

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2012-01-13 12:35:49 +0000
+++ b/sql/mysqld.cc	2012-01-23 19:35:52 +0000
@@ -8303,6 +8303,9 @@
   {"Handler_write",            (char*) offsetof(STATUS_VAR, ha_write_count), SHOW_LONG_STATUS},
   {"Handler_tmp_update",       (char*) offsetof(STATUS_VAR, ha_tmp_update_count), SHOW_LONG_STATUS},
   {"Handler_tmp_write",        (char*) offsetof(STATUS_VAR, ha_tmp_write_count), SHOW_LONG_STATUS},
+  {"Handler_mrr_init",         (char*) offsetof(STATUS_VAR, ha_multi_range_read_init_count),  SHOW_LONG_STATUS},
+  {"Handler_mrr_extra_rowid_sorts", (char*) offsetof(STATUS_VAR, ha_mrr_extra_rowid_sorts), SHOW_LONG_STATUS},
+  {"Handler_mrr_extra_key_sorts",   (char*) offsetof(STATUS_VAR, ha_mrr_extra_key_sorts), SHOW_LONG_STATUS},
   {"Key",                      (char*) &show_default_keycache, SHOW_FUNC},
   {"Last_query_cost",          (char*) offsetof(STATUS_VAR, last_query_cost), SHOW_DOUBLE_STATUS},
   {"Max_used_connections",     (char*) &max_used_connections,  SHOW_LONG},

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2012-01-13 12:35:49 +0000
+++ b/sql/sql_class.h	2012-01-23 19:35:52 +0000
@@ -578,6 +578,8 @@
     BatchedKeyAccess.
   */
   ulong ha_multi_range_read_init_count;
+  ulong ha_mrr_extra_key_sorts;
+  ulong ha_mrr_extra_rowid_sorts;
 
   ulong ha_rollback_count;
   ulong ha_update_count;



More information about the commits mailing list