MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:igor Date:July 23 2007 1:26am
Subject:bk commit into 5.0 tree (igor:1.2482) BUG#29611
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of igor. When igor does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2007-07-22 18:26:16-07:00, igor@stripped +3 -0
  Fixed bug #29611.
  If a primary key is defined over column c of enum type then 
  the EXPLAIN command for a look-up query of the form
    SELECT * FROM t WHERE c=0
  said that the query was with an impossible where condition though the
  query correctly returned non-empty result set when the table indeed 
  contained rows with error empty strings for column c. 
  
  This kind of misbehavior was due to a bug in the function 
  Field_enum::store(longlong,bool) that erroneously returned 1 if
  the the value to be stored was equal to 0. 
  Note that the method 
  Field_enum::store(const char *from,uint length,CHARSET_INFO *cs)
  correctly returned 0 if a value of the error empty string 
  was stored. 

  mysql-test/r/type_enum.result@stripped, 2007-07-22 18:26:03-07:00, igor@stripped +24 -0
    Added a test case for bug #29661.

  mysql-test/t/type_enum.test@stripped, 2007-07-22 18:26:03-07:00, igor@stripped +24 -0
    Added a test case for bug #29661.

  sql/field.cc@stripped, 2007-07-22 18:26:03-07:00, igor@stripped +5 -2
    Fixed bug #29611.
    If a primary key was defined over column c of enum type then 
    the EXPLAIN command for a look-up query of the form
      SELECT * FROM t WHERE c=0
    said that the query was with an impossible where condition though the
    query correctly returned non-empty result set when the table indeed 
    contained rows with error empty strings for column c. 
    
    This kind of misbehavior was due to a bug in the function 
    Field_enum::store(longlong,bool) that erroneously returned 1 if
    the the value to be stored was equal to 0. 
    Note that the method 
    Field_enum::store(const char *from,uint length,CHARSET_INFO *cs)
    correctly returned 0 if a value of the error empty string 
    was stored. 

diff -Nrup a/mysql-test/r/type_enum.result b/mysql-test/r/type_enum.result
--- a/mysql-test/r/type_enum.result	2007-07-11 12:02:46 -07:00
+++ b/mysql-test/r/type_enum.result	2007-07-22 18:26:03 -07:00
@@ -1829,3 +1829,27 @@ c1 + 0
 0
 2
 DROP TABLE t1,t2;
+CREATE TABLE t1(a enum('a','b','c','d'));
+INSERT INTO t1 VALUES (4),(1),(0),(3);
+Warnings:
+Warning	1265	Data truncated for column 'a' at row 3
+SELECT a FROM t1;
+a
+d
+a
+
+c
+EXPLAIN SELECT a FROM t1 WHERE a=0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	4	Using where
+SELECT a FROM t1 WHERE a=0;
+a
+
+ALTER TABLE t1 ADD PRIMARY KEY (a);
+EXPLAIN SELECT a FROM t1 WHERE a=0;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	const	PRIMARY	PRIMARY	1	const	1	Using index
+SELECT a FROM t1 WHERE a=0;
+a
+
+DROP TABLE t1;
diff -Nrup a/mysql-test/t/type_enum.test b/mysql-test/t/type_enum.test
--- a/mysql-test/t/type_enum.test	2007-07-11 12:02:43 -07:00
+++ b/mysql-test/t/type_enum.test	2007-07-22 18:26:03 -07:00
@@ -200,3 +200,27 @@ CREATE TABLE t2 SELECT * FROM t1;
 SELECT c1 + 0 FROM t2;
 
 DROP TABLE t1,t2;
+
+#
+# Bug#29661: Lookup by 0 for a primary index over a enum type  
+#
+
+CREATE TABLE t1(a enum('a','b','c','d'));
+INSERT INTO t1 VALUES (4),(1),(0),(3);
+
+SELECT a FROM t1;
+
+EXPLAIN SELECT a FROM t1 WHERE a=0;
+SELECT a FROM t1 WHERE a=0;
+
+ALTER TABLE t1 ADD PRIMARY KEY (a);
+
+EXPLAIN SELECT a FROM t1 WHERE a=0;
+SELECT a FROM t1 WHERE a=0;
+
+DROP TABLE t1;
+
+
+
+
+
diff -Nrup a/sql/field.cc b/sql/field.cc
--- a/sql/field.cc	2007-07-14 11:43:53 -07:00
+++ b/sql/field.cc	2007-07-22 18:26:03 -07:00
@@ -7640,8 +7640,11 @@ int Field_enum::store(longlong nr, bool 
   if ((ulonglong) nr > typelib->count || nr == 0)
   {
     set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
-    nr=0;
-    error=1;
+    if (nr != 0 || table->in_use->count_cuted_fields)
+    {
+      nr= 0;
+      error= 1;
+    }
   }
   store_type((ulonglong) (uint) nr);
   return error;
Thread
bk commit into 5.0 tree (igor:1.2482) BUG#29611igor23 Jul