Commit 625cdb80 authored by unknown's avatar unknown

Fixed bug lp:825051

The cause of the wrong result was that Item_ref_null_helper::get_date()
didn't use a method of the *_result() family, and fetched the data
for the field from the current row instead of result_field. Changed to
use the correct *_result() method, like to all other similar methods
of Item_ref_null_helper.
parent cdde6187
...@@ -5827,5 +5827,31 @@ SELECT (SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0); ...@@ -5827,5 +5827,31 @@ SELECT (SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0);
(SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0) (SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0)
NULL NULL
drop tables t1,t2,t3; drop tables t1,t2,t3;
#
# LP BUG#825051 Wrong result with date/datetime and subquery with GROUP BY and in_to_exists
#
CREATE TABLE t1 (a date, KEY (a)) ;
INSERT INTO t1 VALUES ('2009-01-01'),('2009-02-02');
set @old_optimizer_switch = @@optimizer_switch;
SET @@optimizer_switch='semijoin=off,materialization=off,in_to_exists=on,subquery_cache=off';
EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index NULL a 4 NULL 2 Using where; Using index
2 DEPENDENT SUBQUERY t1 index NULL a 4 NULL 1 Using index
SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
a
2009-01-01
2009-02-02
SET @@optimizer_switch='semijoin=off,materialization=on,in_to_exists=off,subquery_cache=off';
EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index NULL a 4 NULL 2 Using where; Using index
2 SUBQUERY t1 index NULL a 4 NULL 2 Using index
SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
a
2009-01-01
2009-02-02
set @@optimizer_switch=@old_optimizer_switch;
drop table t1;
# return optimizer switch changed in the beginning of this test # return optimizer switch changed in the beginning of this test
set optimizer_switch=@subselect_tmp; set optimizer_switch=@subselect_tmp;
...@@ -5826,6 +5826,32 @@ SELECT (SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0); ...@@ -5826,6 +5826,32 @@ SELECT (SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0);
(SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0) (SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0)
NULL NULL
drop tables t1,t2,t3; drop tables t1,t2,t3;
#
# LP BUG#825051 Wrong result with date/datetime and subquery with GROUP BY and in_to_exists
#
CREATE TABLE t1 (a date, KEY (a)) ;
INSERT INTO t1 VALUES ('2009-01-01'),('2009-02-02');
set @old_optimizer_switch = @@optimizer_switch;
SET @@optimizer_switch='semijoin=off,materialization=off,in_to_exists=on,subquery_cache=off';
EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index NULL a 4 NULL 2 Using where; Using index
2 DEPENDENT SUBQUERY t1 index NULL a 4 NULL 1 Using index
SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
a
2009-01-01
2009-02-02
SET @@optimizer_switch='semijoin=off,materialization=on,in_to_exists=off,subquery_cache=off';
EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index NULL a 4 NULL 2 Using where; Using index
2 SUBQUERY t1 index NULL a 4 NULL 2 Using index
SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
a
2009-01-01
2009-02-02
set @@optimizer_switch=@old_optimizer_switch;
drop table t1;
# return optimizer switch changed in the beginning of this test # return optimizer switch changed in the beginning of this test
set optimizer_switch=@subselect_tmp; set optimizer_switch=@subselect_tmp;
set optimizer_switch=default; set optimizer_switch=default;
......
...@@ -5822,6 +5822,32 @@ SELECT (SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0); ...@@ -5822,6 +5822,32 @@ SELECT (SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0);
(SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0) (SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0)
NULL NULL
drop tables t1,t2,t3; drop tables t1,t2,t3;
#
# LP BUG#825051 Wrong result with date/datetime and subquery with GROUP BY and in_to_exists
#
CREATE TABLE t1 (a date, KEY (a)) ;
INSERT INTO t1 VALUES ('2009-01-01'),('2009-02-02');
set @old_optimizer_switch = @@optimizer_switch;
SET @@optimizer_switch='semijoin=off,materialization=off,in_to_exists=on,subquery_cache=off';
EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index NULL a 4 NULL 2 Using where; Using index
2 DEPENDENT SUBQUERY t1 index NULL a 4 NULL 1 Using index
SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
a
2009-01-01
2009-02-02
SET @@optimizer_switch='semijoin=off,materialization=on,in_to_exists=off,subquery_cache=off';
EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index NULL a 4 NULL 2 Using where; Using index
2 SUBQUERY t1 index NULL a 4 NULL 2 Using index
SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
a
2009-01-01
2009-02-02
set @@optimizer_switch=@old_optimizer_switch;
drop table t1;
# return optimizer switch changed in the beginning of this test # return optimizer switch changed in the beginning of this test
set optimizer_switch=@subselect_tmp; set optimizer_switch=@subselect_tmp;
set @optimizer_switch_for_subselect_test=null; set @optimizer_switch_for_subselect_test=null;
...@@ -5831,6 +5831,32 @@ SELECT (SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0); ...@@ -5831,6 +5831,32 @@ SELECT (SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0);
(SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0) (SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0)
NULL NULL
drop tables t1,t2,t3; drop tables t1,t2,t3;
#
# LP BUG#825051 Wrong result with date/datetime and subquery with GROUP BY and in_to_exists
#
CREATE TABLE t1 (a date, KEY (a)) ;
INSERT INTO t1 VALUES ('2009-01-01'),('2009-02-02');
set @old_optimizer_switch = @@optimizer_switch;
SET @@optimizer_switch='semijoin=off,materialization=off,in_to_exists=on,subquery_cache=off';
EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index NULL a 4 NULL 2 Using where; Using index
2 DEPENDENT SUBQUERY t1 index NULL a 4 NULL 1 Using index
SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
a
2009-01-01
2009-02-02
SET @@optimizer_switch='semijoin=off,materialization=on,in_to_exists=off,subquery_cache=off';
EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index NULL a 4 NULL 2 Using where; Using index
2 SUBQUERY t1 index NULL a 4 NULL 2 Using index
SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
a
2009-01-01
2009-02-02
set @@optimizer_switch=@old_optimizer_switch;
drop table t1;
# return optimizer switch changed in the beginning of this test # return optimizer switch changed in the beginning of this test
set optimizer_switch=@subselect_tmp; set optimizer_switch=@subselect_tmp;
set optimizer_switch=default; set optimizer_switch=default;
......
...@@ -5822,6 +5822,32 @@ SELECT (SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0); ...@@ -5822,6 +5822,32 @@ SELECT (SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0);
(SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0) (SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0)
NULL NULL
drop tables t1,t2,t3; drop tables t1,t2,t3;
#
# LP BUG#825051 Wrong result with date/datetime and subquery with GROUP BY and in_to_exists
#
CREATE TABLE t1 (a date, KEY (a)) ;
INSERT INTO t1 VALUES ('2009-01-01'),('2009-02-02');
set @old_optimizer_switch = @@optimizer_switch;
SET @@optimizer_switch='semijoin=off,materialization=off,in_to_exists=on,subquery_cache=off';
EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index NULL a 4 NULL 2 Using where; Using index
2 DEPENDENT SUBQUERY t1 index NULL a 4 NULL 1 Using index
SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
a
2009-01-01
2009-02-02
SET @@optimizer_switch='semijoin=off,materialization=on,in_to_exists=off,subquery_cache=off';
EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index NULL a 4 NULL 2 Using where; Using index
2 SUBQUERY t1 index NULL a 4 NULL 2 Using index
SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
a
2009-01-01
2009-02-02
set @@optimizer_switch=@old_optimizer_switch;
drop table t1;
# return optimizer switch changed in the beginning of this test # return optimizer switch changed in the beginning of this test
set optimizer_switch=@subselect_tmp; set optimizer_switch=@subselect_tmp;
set @optimizer_switch_for_subselect_test=null; set @optimizer_switch_for_subselect_test=null;
...@@ -4898,5 +4898,21 @@ SELECT (SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0); ...@@ -4898,5 +4898,21 @@ SELECT (SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0);
drop tables t1,t2,t3; drop tables t1,t2,t3;
--echo #
--echo # LP BUG#825051 Wrong result with date/datetime and subquery with GROUP BY and in_to_exists
--echo #
CREATE TABLE t1 (a date, KEY (a)) ;
INSERT INTO t1 VALUES ('2009-01-01'),('2009-02-02');
set @old_optimizer_switch = @@optimizer_switch;
SET @@optimizer_switch='semijoin=off,materialization=off,in_to_exists=on,subquery_cache=off';
EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
SET @@optimizer_switch='semijoin=off,materialization=on,in_to_exists=off,subquery_cache=off';
EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1);
set @@optimizer_switch=@old_optimizer_switch;
drop table t1;
--echo # return optimizer switch changed in the beginning of this test --echo # return optimizer switch changed in the beginning of this test
set optimizer_switch=@subselect_tmp; set optimizer_switch=@subselect_tmp;
...@@ -3864,7 +3864,7 @@ String* Item_ref_null_helper::val_str(String* s) ...@@ -3864,7 +3864,7 @@ String* Item_ref_null_helper::val_str(String* s)
bool Item_ref_null_helper::get_date(MYSQL_TIME *ltime, uint fuzzydate) bool Item_ref_null_helper::get_date(MYSQL_TIME *ltime, uint fuzzydate)
{ {
return (owner->was_null|= null_value= (*ref)->get_date(ltime, fuzzydate)); return (owner->was_null|= null_value= (*ref)->get_date_result(ltime, fuzzydate));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment