List:Commits« Previous MessageNext Message »
From:Martin Hansson Date:February 2 2010 9:09am
Subject:bzr commit into mysql-5.1-bugteam branch (martin.hansson:3342)
Bug#47762
View as plain text  
#At file:///Users/martin/bzr/bug47762/5.1bt/ based on revid:tor.didriksen@stripped

 3342 Martin Hansson	2010-02-02
      Bug#47762: Incorrect result from MIN() when WHERE tests NOT
      NULL column for NULL
      
      The optimization to read MIN() and MAX() values from an
      index does not properly handle comparisons with NULL
      values. Fixed by giving up the particular optimization step
      if there are comparisons with NULL values, as the result is
      NULL anyway.
     @ sql/field.h
        Bug#47762: Only commenting
     @ sql/opt_sum.cc
        Bug#47762: Fix, clarification of comments

    added:
      mysql-test/r/min_null_cond.result
      mysql-test/t/min_null_cond.test
      mysql-test/t/min_null_cond_queries.inc
    modified:
      sql/field.h
      sql/opt_sum.cc
=== added file 'mysql-test/r/min_null_cond.result'
--- a/mysql-test/r/min_null_cond.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/min_null_cond.result	2010-02-02 09:09:00 +0000
@@ -0,0 +1,397 @@
+####################################################
+# These tests test the output of the MIN clause
+# when a WHERE clause tests column for a NULL value
+#
+# More information on this issue can be found at
+# Bug#47762 Incorrect result from MIN() when WHERE 
+#           tests NOT NULL column for NULL
+# http://bugs.mysql.com/bug.php?id=47762
+#
+####################################################
+## Test for NULLs allowed
+CREATE TABLE t1 ( a INT, KEY (a) );
+INSERT INTO t1 VALUES (1), (2), (3);
+# Field to the left
+SELECT      a   FROM t1 WHERE a = NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a = NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a <> NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a <> NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a > NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a > NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a < NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a < NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a <=> NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a <=> NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a BETWEEN NULL AND 10;
+a
+SELECT MIN( a ) FROM t1 WHERE a BETWEEN NULL AND 10;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a BETWEEN NULL AND NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a BETWEEN NULL AND NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a BETWEEN 10 AND NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a BETWEEN 10 AND NULL;
+MIN( a )
+NULL
+SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0);
+MIN( a )
+NULL
+# NULL to the left
+SELECT      a   FROM t1 WHERE NULL = a;
+a
+SELECT MIN( a ) FROM t1 WHERE NULL = a;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE NULL <> a;
+a
+SELECT MIN( a ) FROM t1 WHERE NULL <> a;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE NULL > a;
+a
+SELECT MIN( a ) FROM t1 WHERE NULL > a;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE NULL < a;
+a
+SELECT MIN( a ) FROM t1 WHERE NULL < a;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE NULL <=> a;
+a
+SELECT MIN( a ) FROM t1 WHERE NULL <=> a;
+MIN( a )
+NULL
+SELECT MIN( a ) FROM t1 WHERE (SELECT a FROM t1 WHERE a < 0) = a;
+MIN( a )
+NULL
+INSERT INTO t1 VALUES (NULL), (NULL);
+# Field to the left
+SELECT      a   FROM t1 WHERE a = NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a = NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a <> NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a <> NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a > NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a > NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a < NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a < NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a <=> NULL;
+a
+NULL
+NULL
+SELECT MIN( a ) FROM t1 WHERE a <=> NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a BETWEEN NULL AND 10;
+a
+SELECT MIN( a ) FROM t1 WHERE a BETWEEN NULL AND 10;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a BETWEEN NULL AND NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a BETWEEN NULL AND NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a BETWEEN 10 AND NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a BETWEEN 10 AND NULL;
+MIN( a )
+NULL
+SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0);
+MIN( a )
+NULL
+# NULL to the left
+SELECT      a   FROM t1 WHERE NULL = a;
+a
+SELECT MIN( a ) FROM t1 WHERE NULL = a;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE NULL <> a;
+a
+SELECT MIN( a ) FROM t1 WHERE NULL <> a;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE NULL > a;
+a
+SELECT MIN( a ) FROM t1 WHERE NULL > a;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE NULL < a;
+a
+SELECT MIN( a ) FROM t1 WHERE NULL < a;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE NULL <=> a;
+a
+NULL
+NULL
+SELECT MIN( a ) FROM t1 WHERE NULL <=> a;
+MIN( a )
+NULL
+SELECT MIN( a ) FROM t1 WHERE (SELECT a FROM t1 WHERE a < 0) = a;
+MIN( a )
+NULL
+DROP TABLE t1;
+## Test for NOT NULLs
+CREATE TABLE t1 ( a INT NOT NULL PRIMARY KEY);
+INSERT INTO t1 VALUES (1), (2), (3);
+# Field to the left
+SELECT      a   FROM t1 WHERE a = NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a = NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a <> NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a <> NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a > NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a > NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a < NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a < NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a <=> NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a <=> NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a BETWEEN NULL AND 10;
+a
+SELECT MIN( a ) FROM t1 WHERE a BETWEEN NULL AND 10;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a BETWEEN NULL AND NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a BETWEEN NULL AND NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a BETWEEN 10 AND NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a BETWEEN 10 AND NULL;
+MIN( a )
+NULL
+SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0);
+MIN( a )
+NULL
+# NULL to the left
+SELECT      a   FROM t1 WHERE NULL = a;
+a
+SELECT MIN( a ) FROM t1 WHERE NULL = a;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE NULL <> a;
+a
+SELECT MIN( a ) FROM t1 WHERE NULL <> a;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE NULL > a;
+a
+SELECT MIN( a ) FROM t1 WHERE NULL > a;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE NULL < a;
+a
+SELECT MIN( a ) FROM t1 WHERE NULL < a;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE NULL <=> a;
+a
+SELECT MIN( a ) FROM t1 WHERE NULL <=> a;
+MIN( a )
+NULL
+SELECT MIN( a ) FROM t1 WHERE (SELECT a FROM t1 WHERE a < 0) = a;
+MIN( a )
+NULL
+DROP TABLE t1;
+## Test without index
+CREATE TABLE t1 ( a INT );
+INSERT INTO t1 VALUES (1), (2), (3);
+# Field to the left
+SELECT      a   FROM t1 WHERE a = NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a = NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a <> NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a <> NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a > NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a > NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a < NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a < NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a <=> NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a <=> NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a BETWEEN NULL AND 10;
+a
+SELECT MIN( a ) FROM t1 WHERE a BETWEEN NULL AND 10;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a BETWEEN NULL AND NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a BETWEEN NULL AND NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a BETWEEN 10 AND NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a BETWEEN 10 AND NULL;
+MIN( a )
+NULL
+SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0);
+MIN( a )
+NULL
+# NULL to the left
+SELECT      a   FROM t1 WHERE NULL = a;
+a
+SELECT MIN( a ) FROM t1 WHERE NULL = a;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE NULL <> a;
+a
+SELECT MIN( a ) FROM t1 WHERE NULL <> a;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE NULL > a;
+a
+SELECT MIN( a ) FROM t1 WHERE NULL > a;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE NULL < a;
+a
+SELECT MIN( a ) FROM t1 WHERE NULL < a;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE NULL <=> a;
+a
+SELECT MIN( a ) FROM t1 WHERE NULL <=> a;
+MIN( a )
+NULL
+SELECT MIN( a ) FROM t1 WHERE (SELECT a FROM t1 WHERE a < 0) = a;
+MIN( a )
+NULL
+INSERT INTO t1 VALUES (NULL), (NULL);
+# Field to the left
+SELECT      a   FROM t1 WHERE a = NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a = NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a <> NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a <> NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a > NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a > NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a < NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a < NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a <=> NULL;
+a
+NULL
+NULL
+SELECT MIN( a ) FROM t1 WHERE a <=> NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a BETWEEN NULL AND 10;
+a
+SELECT MIN( a ) FROM t1 WHERE a BETWEEN NULL AND 10;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a BETWEEN NULL AND NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a BETWEEN NULL AND NULL;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE a BETWEEN 10 AND NULL;
+a
+SELECT MIN( a ) FROM t1 WHERE a BETWEEN 10 AND NULL;
+MIN( a )
+NULL
+SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0);
+MIN( a )
+NULL
+# NULL to the left
+SELECT      a   FROM t1 WHERE NULL = a;
+a
+SELECT MIN( a ) FROM t1 WHERE NULL = a;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE NULL <> a;
+a
+SELECT MIN( a ) FROM t1 WHERE NULL <> a;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE NULL > a;
+a
+SELECT MIN( a ) FROM t1 WHERE NULL > a;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE NULL < a;
+a
+SELECT MIN( a ) FROM t1 WHERE NULL < a;
+MIN( a )
+NULL
+SELECT      a   FROM t1 WHERE NULL <=> a;
+a
+NULL
+NULL
+SELECT MIN( a ) FROM t1 WHERE NULL <=> a;
+MIN( a )
+NULL
+SELECT MIN( a ) FROM t1 WHERE (SELECT a FROM t1 WHERE a < 0) = a;
+MIN( a )
+NULL
+DROP TABLE t1;

=== added file 'mysql-test/t/min_null_cond.test'
--- a/mysql-test/t/min_null_cond.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/min_null_cond.test	2010-02-02 09:09:00 +0000
@@ -0,0 +1,32 @@
+--echo ####################################################
+--echo # These tests test the output of the MIN clause
+--echo # when a WHERE clause tests column for a NULL value
+--echo #
+--echo # More information on this issue can be found at
+--echo # Bug#47762 Incorrect result from MIN() when WHERE 
+--echo #           tests NOT NULL column for NULL
+--echo # http://bugs.mysql.com/bug.php?id=47762
+--echo #
+--echo ####################################################
+
+--echo ## Test for NULLs allowed
+CREATE TABLE t1 ( a INT, KEY (a) );
+INSERT INTO t1 VALUES (1), (2), (3);
+--source t/min_null_cond_queries.inc
+INSERT INTO t1 VALUES (NULL), (NULL);
+--source t/min_null_cond_queries.inc
+DROP TABLE t1;
+
+--echo ## Test for NOT NULLs
+CREATE TABLE t1 ( a INT NOT NULL PRIMARY KEY);
+INSERT INTO t1 VALUES (1), (2), (3);
+--source t/min_null_cond_queries.inc
+DROP TABLE t1;
+
+--echo ## Test without index
+CREATE TABLE t1 ( a INT );
+INSERT INTO t1 VALUES (1), (2), (3);
+--source t/min_null_cond_queries.inc
+INSERT INTO t1 VALUES (NULL), (NULL);
+--source t/min_null_cond_queries.inc
+DROP TABLE t1;

=== added file 'mysql-test/t/min_null_cond_queries.inc'
--- a/mysql-test/t/min_null_cond_queries.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/min_null_cond_queries.inc	2010-02-02 09:09:00 +0000
@@ -0,0 +1,46 @@
+--echo # Field to the left
+
+SELECT      a   FROM t1 WHERE a = NULL;
+SELECT MIN( a ) FROM t1 WHERE a = NULL;
+
+SELECT      a   FROM t1 WHERE a <> NULL;
+SELECT MIN( a ) FROM t1 WHERE a <> NULL;
+
+SELECT      a   FROM t1 WHERE a > NULL;
+SELECT MIN( a ) FROM t1 WHERE a > NULL;
+
+SELECT      a   FROM t1 WHERE a < NULL;
+SELECT MIN( a ) FROM t1 WHERE a < NULL;
+
+SELECT      a   FROM t1 WHERE a <=> NULL;
+SELECT MIN( a ) FROM t1 WHERE a <=> NULL;
+
+SELECT      a   FROM t1 WHERE a BETWEEN NULL AND 10;
+SELECT MIN( a ) FROM t1 WHERE a BETWEEN NULL AND 10;
+
+SELECT      a   FROM t1 WHERE a BETWEEN NULL AND NULL;
+SELECT MIN( a ) FROM t1 WHERE a BETWEEN NULL AND NULL;
+
+SELECT      a   FROM t1 WHERE a BETWEEN 10 AND NULL;
+SELECT MIN( a ) FROM t1 WHERE a BETWEEN 10 AND NULL;
+
+SELECT MIN( a ) FROM t1 WHERE a = (SELECT a FROM t1 WHERE a < 0);
+
+--echo # NULL to the left
+
+SELECT      a   FROM t1 WHERE NULL = a;
+SELECT MIN( a ) FROM t1 WHERE NULL = a;
+
+SELECT      a   FROM t1 WHERE NULL <> a;
+SELECT MIN( a ) FROM t1 WHERE NULL <> a;
+
+SELECT      a   FROM t1 WHERE NULL > a;
+SELECT MIN( a ) FROM t1 WHERE NULL > a;
+
+SELECT      a   FROM t1 WHERE NULL < a;
+SELECT MIN( a ) FROM t1 WHERE NULL < a;
+
+SELECT      a   FROM t1 WHERE NULL <=> a;
+SELECT MIN( a ) FROM t1 WHERE NULL <=> a;
+
+SELECT MIN( a ) FROM t1 WHERE (SELECT a FROM t1 WHERE a < 0) = a;

=== modified file 'sql/field.h'
--- a/sql/field.h	2010-01-21 17:20:24 +0000
+++ b/sql/field.h	2010-02-02 09:09:00 +0000
@@ -55,7 +55,11 @@ public:
   static void operator delete(void *ptr_arg, size_t size) { TRASH(ptr_arg, size); }
 
   uchar		*ptr;			// Position to field in record
-  uchar		*null_ptr;		// Byte where null_bit is
+  /**
+     Byte where the NULL bit is stored inside a record. If this Field is a NOT 
+     NULL field, this member is NULL.
+  */
+  uchar		*null_ptr;
   /*
     Note that you can use table->in_use as replacement for current_thd member 
     only inside of val_*() and store() members (e.g. you can't use it in cons)
@@ -261,6 +265,9 @@ public:
   inline void set_notnull(my_ptrdiff_t row_offset= 0)
     { if (null_ptr) null_ptr[row_offset]&= (uchar) ~null_bit; }
   inline bool maybe_null(void) { return null_ptr != 0 || table->maybe_null; }
+  /**
+     Signals that this field is NULLable.
+   */
   inline bool real_maybe_null(void) { return null_ptr != 0; }
 
   enum {

=== modified file 'sql/opt_sum.cc'
--- a/sql/opt_sum.cc	2009-10-14 08:46:50 +0000
+++ b/sql/opt_sum.cc	2010-02-02 09:09:00 +0000
@@ -96,7 +96,7 @@ static ulonglong get_exact_record_count(
   @param conds                 WHERE clause
 
   @note
-    This function is only called for queries with sum functions and no
+    This function is only called for queries with aggregate functions and no
     GROUP BY part. This means that the result set shall contain a single
     row only
 
@@ -484,6 +484,8 @@ int opt_sum_query(TABLE_LIST *tables, Li
 /**
   Test if the predicate compares a field with constants.
 
+  @note NULLs are treated like any other values.
+
   @param func_item        Predicate item
   @param[out] args        Here we store the field followed by constants
   @param[out] inv_order   Is set to 1 if the predicate is of the form
@@ -565,33 +567,40 @@ bool simple_pred(Item_func *func_item, I
 
 
 /**
-  Check whether a condition matches a key to get {MAX|MIN}(field):.
+   Check whether a condition matches a key to get {MAX|MIN}(field):.
 
-     For the index specified by the keyinfo parameter, index that
-     contains field as its component (field_part), the function
-     checks whether the condition cond is a conjunction and all its
-     conjuncts referring to the columns of the same table as column
-     field are one of the following forms:
-     - f_i= const_i or const_i= f_i or f_i is null,
-     where f_i is part of the index
-     - field {<|<=|>=|>|=} const or const {<|<=|>=|>|=} field
-     - field between const1 and const2
-
-  @param[in]     max_fl         Set to 1 if we are optimising MAX()
-  @param[in,out] ref            Reference to the structure we store the key
-    value
-  @param[in]     keyinfo        Reference to the key info
-  @param[in]     field_part     Pointer to the key part for the field
-  @param[in]     cond           WHERE condition
-  @param[in,out] key_part_used  Map of matchings parts
-  @param[in,out] range_fl       Says whether including key will be used
-  @param[out]    prefix_len     Length of common key part for the range
-    where MAX/MIN is searched for
+   For the index specified by the keyinfo parameter and an index that
+   contains the field as its component (field_part), the function
+   checks whether 
+
+   - the condition cond is a conjunction, 
+   - all of its conjuncts refer to columns of the same table, and
+   - each conjunct is on one of the following forms:
+     - f_i = const_i or const_i = f_i or f_i IS NULL,
+       where f_i is part of the index
+     - field {<|<=|>=|>|=} const
+     - const {<|<=|>=|>|=} field
+     - field BETWEEN const_1 AND const_2
+
+   @note NULL handling: If the comparison is between a field and NULL, the
+   return value is always false, even for NULL-safe comparisons.
+
+   @param[in]     max_fl         Set to true if we are optimizing MAX(),
+                                 false means we are optimizing %MIN()
+   @param[in, out] ref           Reference to the structure where the function 
+                                 stores the key value
+   @param[in]     keyinfo        Reference to the key info
+   @param[in]     field_part     Pointer to the key part for the field
+   @param[in]     cond           WHERE condition
+   @param[in,out] key_part_used  Map of matchings parts
+   @param[in,out] range_fl       Says whether including key will be used
+   @param[out]    prefix_len     Length of common key part for the range
+                                 where MAX/MIN is searched for
 
   @retval
-    0        Index can't be used.
+    false    Index can't be used.
   @retval
-    1        We can use index to get MIN/MAX value
+    true     We can use index to get MIN/MAX value
 */
 
 static bool matching_cond(bool max_fl, TABLE_REF *ref, KEY *keyinfo, 
@@ -630,8 +639,8 @@ static bool matching_cond(bool max_fl, T
   bool eq_type= 0;                            // =, <=> or IS NULL
   bool noeq_type= 0;                          // < or >  
   bool less_fl= 0;                            // < or <= 
-  bool is_null= 0;
-  bool between= 0;
+  bool is_null= 0;                            // IS NULL
+  bool between= 0;                            // BETWEEN ... AND ... 
 
   switch (((Item_func*) cond)->functype()) {
   case Item_func::ISNULL_FUNC:
@@ -722,9 +731,11 @@ static bool matching_cond(bool max_fl, T
       *key_ptr= (uchar) 1;
     }
     else
-    {
-      store_val_in_field(part->field, args[between && max_fl ? 2 : 1],
-                         CHECK_FIELD_IGNORE);
+    { 
+      Item *value= args[between && max_fl ? 2 : 1];      
+      if (value->is_null())
+        return FALSE;
+      store_val_in_field(part->field, value, CHECK_FIELD_IGNORE);
       if (part->null_bit) 
         *key_ptr++= (uchar) test(part->field->is_null());
       part->field->get_key_image(key_ptr, part->length, Field::itRAW);


Attachment: [text/bzr-bundle] bzr/martin.hansson@sun.com-20100202090900-ux0pbjfk0geogzxi.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (martin.hansson:3342)Bug#47762Martin Hansson2 Feb
  • Re: bzr commit into mysql-5.1-bugteam branch (martin.hansson:3342)Bug#47762Jørgen Løland5 Feb
  • Re: bzr commit into mysql-5.1-bugteam branch (martin.hansson:3342)Bug#47762Evgeny Potemkin9 Feb
    • Re: bzr commit into mysql-5.1-bugteam branch (martin.hansson:3342)Bug#47762Martin Hansson9 Feb