List:Commits« Previous MessageNext Message »
From:igor Date:April 11 2006 7:03pm
Subject:bk commit into 5.0 tree (igor:1.2151) BUG#18618
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
  1.2151 06/04/11 10:03:37 igor@stripped +3 -0
  Fixed bug #18618.
  If the second or the third argument of a BETWEEN predicate was
  a constant expression, like '2005.09.01' - INTERVAL 6 MONTH,
  while the other two arguments were fields then the predicate 
  was evaluated incorrectly and the query returned a wrong
  result set.
  The bug was introduced in 5.0.17 when in the fix for 12612.

  sql/item_cmpfunc.cc
    1.199 06/04/11 10:03:30 igor@stripped +2 -10
    Fixed bug #18618.
    If the second or the third argument of a BETWEEN predicate was
    a constant expression, like '2005.09.01' - INTERVAL 6 MONTH,
    while the other two arguments were fields then the predicate 
    was evaluated incorrectly and the query returned a wrong
    result set.
    The bug was introduced in 5.0.17 when in the fix for 12612.

  mysql-test/t/func_time.test
    1.40 06/04/11 10:03:30 igor@stripped +22 -0
    Added a test case for bug #18618.

  mysql-test/r/func_time.result
    1.49 06/04/11 10:03:30 igor@stripped +25 -0
    Added a test case for bug #18618.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	igor
# Host:	rurik.mysql.com
# Root:	/home/igor/dev/mysql-5.0-0

--- 1.198/sql/item_cmpfunc.cc	2006-04-08 11:42:00 -07:00
+++ 1.199/sql/item_cmpfunc.cc	2006-04-11 10:03:30 -07:00
@@ -52,7 +52,6 @@
 {
   uint i;
   Field *field= NULL;
-  bool all_constant= TRUE;
 
   /* If the first argument is a FIELD_ITEM, pull out the field. */
   if (items[0]->real_item()->type() == Item::FIELD_ITEM)
@@ -65,16 +64,9 @@
   for (i= 1; i < nitems; i++)
   {
     type[0]= item_cmp_type(type[0], items[i]->result_type());
-    if (field && !convert_constant_item(thd, field, &items[i]))
-      all_constant= FALSE;
+    if (field && convert_constant_item(thd, field, &items[i]))
+      type[0]= INT_RESULT;
   }
-
-  /*
-    If we had a field that can be compared as a longlong, and all constant
-    items, then the aggregate result will be an INT_RESULT.
-  */
-  if (field && all_constant)
-    type[0]= INT_RESULT;
 }
 
 

--- 1.48/mysql-test/r/func_time.result	2006-04-07 02:15:10 -07:00
+++ 1.49/mysql-test/r/func_time.result	2006-04-11 10:03:30 -07:00
@@ -847,3 +847,28 @@
 select timestampdiff(year,'2004-02-29','2005-02-28');
 timestampdiff(year,'2004-02-29','2005-02-28')
 0
+CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, day date);
+CREATE TABLE t2 (id int NOT NULL PRIMARY KEY, day date);
+INSERT INTO t1 VALUES
+(1, '2005-06-01'), (2, '2005-02-01'), (3, '2005-07-01');
+INSERT INTO t2 VALUES
+(1, '2005-08-01'), (2, '2005-06-15'), (3, '2005-07-15');
+SELECT * FROM t1, t2 
+WHERE t1.day BETWEEN 
+'2005.09.01' - INTERVAL 6 MONTH AND t2.day;
+id	day	id	day
+1	2005-06-01	1	2005-08-01
+3	2005-07-01	1	2005-08-01
+1	2005-06-01	2	2005-06-15
+1	2005-06-01	3	2005-07-15
+3	2005-07-01	3	2005-07-15
+SELECT * FROM t1, t2 
+WHERE CAST(t1.day AS DATE) BETWEEN 
+'2005.09.01' - INTERVAL 6 MONTH AND t2.day;
+id	day	id	day
+1	2005-06-01	1	2005-08-01
+3	2005-07-01	1	2005-08-01
+1	2005-06-01	2	2005-06-15
+1	2005-06-01	3	2005-07-15
+3	2005-07-01	3	2005-07-15
+DROP TABLE t1,t2;

--- 1.39/mysql-test/t/func_time.test	2006-04-07 02:15:10 -07:00
+++ 1.40/mysql-test/t/func_time.test	2006-04-11 10:03:30 -07:00
@@ -446,4 +446,26 @@
 select timestampdiff(year,'2004-02-28','2005-02-28');
 select timestampdiff(year,'2004-02-29','2005-02-28');
 
+#
+# Bug #18618: BETWEEN for dates with the second argument being a constant
+#             expression and the first and the third arguments being fields 
+#
+
+CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, day date);
+CREATE TABLE t2 (id int NOT NULL PRIMARY KEY, day date);
+
+INSERT INTO t1 VALUES
+  (1, '2005-06-01'), (2, '2005-02-01'), (3, '2005-07-01');
+INSERT INTO t2 VALUES
+  (1, '2005-08-01'), (2, '2005-06-15'), (3, '2005-07-15');
+
+SELECT * FROM t1, t2 
+  WHERE t1.day BETWEEN 
+               '2005.09.01' - INTERVAL 6 MONTH AND t2.day;
+SELECT * FROM t1, t2 
+  WHERE CAST(t1.day AS DATE) BETWEEN 
+                             '2005.09.01' - INTERVAL 6 MONTH AND t2.day;
+ 
+DROP TABLE t1,t2;
+
 # End of 5.0 tests
Thread
bk commit into 5.0 tree (igor:1.2151) BUG#18618igor11 Apr