From e536c8eca7eb528dfe8cfd5ca96d2772ccca2a86 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 8 Apr 2006 11:42:09 -0700 Subject: [PATCH 1/4] Fixed bug #16069. The function agg_cmp_type in item_cmpfunc.cc neglected the fact that the first argument in a BETWEEN/IN predicate could be a field of a view. As a result in the case when the retrieved table was hidden by a view over it and the arguments in the BETWEEN/IN predicates are of the date/time type the function did not perform conversion of the constant arguments to the same format as the first field argument. If formats of the arguments differed it caused wrong a evaluation of the predicates. mysql-test/r/view.result: Added a test case for bug #16069. mysql-test/t/view.test: Added a test case for bug #16069. --- mysql-test/r/view.result | 21 +++++++++++++++++++++ mysql-test/t/view.test | 20 ++++++++++++++++++++ sql/item_cmpfunc.cc | 4 ++-- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index f0fb35f1a2e..7519b8022f0 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -2579,3 +2579,24 @@ COUNT(*) 2 DROP VIEW v2; DROP TABLE t1, t2; +CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, +td date DEFAULT NULL, KEY idx(td)); +INSERT INTO t1 VALUES +(1, '2005-01-01'), (2, '2005-01-02'), (3, '2005-01-02'), +(4, '2005-01-03'), (5, '2005-01-04'), (6, '2005-01-05'), +(7, '2005-01-05'), (8, '2005-01-05'), (9, '2005-01-06'); +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT * FROM t1 WHERE td BETWEEN '2005.01.02' AND '2005.01.04'; +id td +2 2005-01-02 +3 2005-01-02 +4 2005-01-03 +5 2005-01-04 +SELECT * FROM v1 WHERE td BETWEEN '2005.01.02' AND '2005.01.04'; +id td +2 2005-01-02 +3 2005-01-02 +4 2005-01-03 +5 2005-01-04 +DROP VIEW v1; +DROP TABLE t1; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index afeb0dda729..7ef1f82dbd3 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -2434,3 +2434,23 @@ SELECT COUNT(*) FROM t1 LEFT JOIN v2 ON t1.id=v2.id; DROP VIEW v2; DROP TABLE t1, t2; + +# +# Bug #16069: VIEW does return the same results as underlying SELECT +# with WHERE condition containing BETWEEN over dates + +CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, + td date DEFAULT NULL, KEY idx(td)); + +INSERT INTO t1 VALUES + (1, '2005-01-01'), (2, '2005-01-02'), (3, '2005-01-02'), + (4, '2005-01-03'), (5, '2005-01-04'), (6, '2005-01-05'), + (7, '2005-01-05'), (8, '2005-01-05'), (9, '2005-01-06'); + +CREATE VIEW v1 AS SELECT * FROM t1; + +SELECT * FROM t1 WHERE td BETWEEN '2005.01.02' AND '2005.01.04'; +SELECT * FROM v1 WHERE td BETWEEN '2005.01.02' AND '2005.01.04'; + +DROP VIEW v1; +DROP TABLE t1; diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 24075ac838d..6e1afd4ef09 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -55,8 +55,8 @@ static void agg_cmp_type(THD *thd, Item_result *type, Item **items, uint nitems) bool all_constant= TRUE; /* If the first argument is a FIELD_ITEM, pull out the field. */ - if (items[0]->type() == Item::FIELD_ITEM) - field=((Item_field *)items[0])->field; + if (items[0]->real_item()->type() == Item::FIELD_ITEM) + field=((Item_field *)(items[0]->real_item()))->field; /* But if it can't be compared as a longlong, we don't really care. */ if (field && !field->can_be_compared_as_longlong()) field= NULL; From 5a19f3bc71b9db630fac01561ffc6f37434ac509 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 8 Apr 2006 22:27:43 +0200 Subject: [PATCH 2/4] $MYSQL_TEST was broken with --valgrind. --- mysql-test/mysql-test-run.pl | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 53bf820cce9..20bb6e0117a 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -2316,11 +2316,6 @@ sub run_mysqltest ($) { mtr_init_args(\$args); - if ( defined $opt_valgrind_mysqltest ) - { - valgrind_arguments($args, \$exe); - } - mtr_add_arg($args, "--no-defaults"); mtr_add_arg($args, "--socket=%s", $master->[0]->{'path_mysock'}); mtr_add_arg($args, "--database=test"); @@ -2398,6 +2393,17 @@ sub run_mysqltest ($) { # Add arguments that should not go into the MYSQL_TEST env var # ---------------------------------------------------------------------- + if ( defined $opt_valgrind_mysqltest ) + { + # Prefix the Valgrind options to the argument list. + # We do this here, since we do not want to Valgrind the nested invocations + # of mysqltest; that would mess up the stderr output causing test failure. + my @args_saved = @$args; + mtr_init_args(\$args); + valgrind_arguments($args, \$exe); + mtr_add_arg($args, "%s", $_) for @args_saved; + } + mtr_add_arg($args, "-R"); mtr_add_arg($args, $tinfo->{'result_file'}); From c48ded66d39abe1f62e53a403ca37a601552f58d Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 10 Apr 2006 09:31:46 +0200 Subject: [PATCH 3/4] Fix test case 'cast' on Windows, different floating point output format. --- mysql-test/t/cast.test | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mysql-test/t/cast.test b/mysql-test/t/cast.test index 7e09f44397c..533da542855 100644 --- a/mysql-test/t/cast.test +++ b/mysql-test/t/cast.test @@ -171,6 +171,8 @@ select cast(1.0e+300 as signed int); CREATE TABLE t1 (f1 double); INSERT INTO t1 SET f1 = -1.0e+30 ; INSERT INTO t1 SET f1 = +1.0e+30 ; +# Expected result is +-1e+30, but Windows returns +-1e+030. +--replace_result 1e+030 1e+30 SELECT f1 AS double_val, CAST(f1 AS SIGNED INT) AS cast_val FROM t1; DROP TABLE t1; From 6978949b49a6c9b2746ac8aab1a1362c5db8d576 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 10 Apr 2006 14:14:20 -0700 Subject: [PATCH 4/4] Made the test case for bug #15917 independent on platforms. --- mysql-test/r/having.result | 2 -- mysql-test/t/having.test | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/having.result b/mysql-test/r/having.result index c827e11e50e..fe918e4c3ff 100644 --- a/mysql-test/r/having.result +++ b/mysql-test/r/having.result @@ -360,8 +360,6 @@ s1 count(s1) y 1 drop table t1; DROP SCHEMA IF EXISTS HU; -Warnings: -Note 1008 Can't drop database 'HU'; database doesn't exist CREATE SCHEMA HU ; USE HU ; CREATE TABLE STAFF diff --git a/mysql-test/t/having.test b/mysql-test/t/having.test index 9e5bc4bc136..9b21e544657 100644 --- a/mysql-test/t/having.test +++ b/mysql-test/t/having.test @@ -354,7 +354,9 @@ drop table t1; # when the server is run on Windows or with --lower-case-table-names=1 # +--disable_warnings DROP SCHEMA IF EXISTS HU; +--enable_warnings CREATE SCHEMA HU ; USE HU ;