[Commits] Rev 3574: Fixed bug mdev-3851. in file:///home/igor/maria/maria-5.5/

Igor Babaev igor at askmonty.org
Sun Nov 11 21:47:44 EET 2012


At file:///home/igor/maria/maria-5.5/

------------------------------------------------------------
revno: 3574
revision-id: igor at askmonty.org-20121111194744-5pspezgkyp7u4k2k
parent: sergii at pisem.net-20121106170926-w64cf6i419skvhlg
committer: Igor Babaev <igor at askmonty.org>
branch nick: maria-5.5
timestamp: Sun 2012-11-11 11:47:44 -0800
message:
  Fixed bug mdev-3851.
  Any ref access to a table by a key fully extended by the components
  of the primary key should be actually an eq_ref access.
-------------- next part --------------
=== modified file 'include/my_base.h'
--- a/include/my_base.h	2012-05-21 18:54:41 +0000
+++ b/include/my_base.h	2012-11-11 19:47:44 +0000
@@ -282,6 +282,9 @@
 #define HA_USES_BLOCK_SIZE	 ((uint) 32768)
 #define HA_SORT_ALLOWS_SAME      512    /* Intern bit when sorting records */
 
+/* This flag can be used only in KEY::ext_key_flags */
+#define HA_EXT_NOSAME            131072
+
 	/* These flags can be added to key-seg-flag */
 
 #define HA_SPACE_PACK		 1	/* Pack space in key-seg */

=== modified file 'mysql-test/r/innodb_ext_key.result'
--- a/mysql-test/r/innodb_ext_key.result	2012-03-28 18:25:31 +0000
+++ b/mysql-test/r/innodb_ext_key.result	2012-11-11 19:47:44 +0000
@@ -613,6 +613,26 @@
 Handler_read_rnd	0
 Handler_read_rnd_deleted	0
 Handler_read_rnd_next	0
+#
+# Bug mdev-3851: ref access used instead of expected eq_ref access
+#                when extended_keys=on
+#
+create table t0 (a int);
+insert into t0 values (1), (2), (3), (4), (5);
+create index i_p_size on part(p_size);
+set optimizer_switch='extended_keys=on';
+explain
+select * from t0, part ignore index (primary)
+where p_partkey=t0.a and p_size=1;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t0	ALL	NULL	NULL	NULL	NULL	5	Using where
+1	SIMPLE	part	eq_ref	i_p_size	i_p_size	9	const,dbt3_s001.t0.a	1	
+select * from t0,  part ignore index (primary)
+where p_partkey=t0.a and p_size=1;
+a	p_partkey	p_name	p_mfgr	p_brand	p_type	p_size	p_container	p_retailprice	p_comment
+2	2	blush rosy metallic lemon navajo	Manufacturer#1	Brand#13	LARGE BRUSHED BRASS	1	LG CASE	902	final platelets hang f
+drop table t0;
+drop index i_p_size on part;
 DROP DATABASE dbt3_s001;
 use test;
 #

=== modified file 'mysql-test/t/innodb_ext_key.test'
--- a/mysql-test/t/innodb_ext_key.test	2012-03-03 21:22:49 +0000
+++ b/mysql-test/t/innodb_ext_key.test	2012-11-11 19:47:44 +0000
@@ -287,6 +287,27 @@
         and o_orderkey=l_orderkey and p_partkey=l_partkey;
 show status like 'handler_read%';
 
+--echo #
+--echo # Bug mdev-3851: ref access used instead of expected eq_ref access
+--echo #                when extended_keys=on
+--echo #
+
+create table t0 (a int);
+insert into t0 values (1), (2), (3), (4), (5);
+create index i_p_size on part(p_size);
+
+set optimizer_switch='extended_keys=on';
+
+explain
+select * from t0, part ignore index (primary)
+  where p_partkey=t0.a and p_size=1;
+
+select * from t0,  part ignore index (primary)
+  where p_partkey=t0.a and p_size=1;
+
+drop table t0;
+drop index i_p_size on part; 
+
 DROP DATABASE dbt3_s001;
 
 use test;

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2012-11-04 15:09:46 +0000
+++ b/sql/sql_select.cc	2012-11-11 19:47:44 +0000
@@ -5378,7 +5378,8 @@
             !ref_or_null_part)
         {                                         /* use eq key */
           max_key_part= (uint) ~0;
-          if ((key_flags & (HA_NOSAME | HA_NULL_PART_KEY)) == HA_NOSAME)
+          if ((key_flags & (HA_NOSAME | HA_NULL_PART_KEY)) == HA_NOSAME ||
+	      test(key_flags & HA_EXT_NOSAME))
           {
             tmp = prev_record_reads(join->positions, idx, found_ref);
             records=1.0;
@@ -7966,18 +7967,23 @@
   *ref_key=0;				// end_marker
   if (j->type == JT_FT)
     DBUG_RETURN(0);
+  ulong key_flags= j->table->actual_key_flags(keyinfo);
   if (j->type == JT_CONST)
     j->table->const_table= 1;
-  else if (((j->table->actual_key_flags(keyinfo) &
-            (HA_NOSAME | HA_NULL_PART_KEY))
-           != HA_NOSAME) ||
+  else if (((key_flags & (HA_NOSAME | HA_NULL_PART_KEY))!= HA_NOSAME) ||
 	   keyparts != j->table->actual_n_key_parts(keyinfo) ||
            null_ref_key)
   {
-    /* Must read with repeat */
-    j->type= null_ref_key ? JT_REF_OR_NULL : JT_REF;
-    j->ref.null_ref_key= null_ref_key;
-    j->ref.null_ref_part= null_ref_part;
+    if (test(key_flags & HA_EXT_NOSAME) && keyparts == keyinfo->ext_key_parts &&
+        !null_ref_key)
+      j->type= JT_EQ_REF;
+    else
+    {
+      /* Must read with repeat */
+      j->type= null_ref_key ? JT_REF_OR_NULL : JT_REF;
+      j->ref.null_ref_key= null_ref_key;
+      j->ref.null_ref_part= null_ref_part;
+    }
   }
   else if (keyuse_uses_no_tables)
   {

=== modified file 'sql/table.cc'
--- a/sql/table.cc	2012-10-18 21:33:06 +0000
+++ b/sql/table.cc	2012-11-11 19:47:44 +0000
@@ -981,7 +981,6 @@
     keyinfo->ext_key_part_map= 0;
     if (share->use_ext_keys && i)
     {
-      keyinfo->ext_key_flags= keyinfo->flags | HA_NOSAME;
       keyinfo->ext_key_part_map= 0;
       for (j= 0; 
            j < first_key_parts && keyinfo->ext_key_parts < MAX_REF_PARTS;
@@ -1002,7 +1001,9 @@
           keyinfo->ext_key_parts++;
           keyinfo->ext_key_part_map|= 1 << j;
         }
-      } 
+      }
+      if (j == first_key_parts)
+        keyinfo->ext_key_flags= keyinfo->flags | HA_NOSAME | HA_EXT_NOSAME;
     }
     share->ext_key_parts+= keyinfo->ext_key_parts;  
   }



More information about the commits mailing list