Commit 3a54e593 authored by unknown's avatar unknown
Browse files

Fixed bug #26124: SELECT from a view wrapper over a table

with a column of the DATETIME type could return a wrong 
result set if the WHERE clause included a BETWEEN condition
on the column.
Fixed the method Item_func_between::fix_length_and_dec
where the aggregation type for BETWEEN predicates calculated
incorrectly if the first argument was a view column of the
DATETIME type.


mysql-test/r/view.result:
  Added a test case for bug #26124.
mysql-test/t/view.test:
  Added a test case for bug #26124.
parent 976f0a39
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -3034,4 +3034,22 @@ SHOW CREATE VIEW v1;
View	Create View
v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select _latin1'The\ZEnd' AS `TheEnd`
DROP VIEW v1;
CREATE TABLE t1 (mydate DATETIME);
INSERT INTO t1 VALUES 
('2007-01-01'), ('2007-01-02'), ('2007-01-30'), ('2007-01-31');
CREATE VIEW v1 AS SELECT mydate from t1;
SELECT * FROM t1 WHERE mydate BETWEEN '2007-01-01' AND '2007-01-31';
mydate
2007-01-01 00:00:00
2007-01-02 00:00:00
2007-01-30 00:00:00
2007-01-31 00:00:00
SELECT * FROM v1 WHERE mydate BETWEEN '2007-01-01' AND '2007-01-31';
mydate
2007-01-01 00:00:00
2007-01-02 00:00:00
2007-01-30 00:00:00
2007-01-31 00:00:00
DROP VIEW v1;
DROP TABLE t1;
End of 5.0 tests.
+16 −0
Original line number Diff line number Diff line
@@ -2986,4 +2986,20 @@ SHOW CREATE VIEW v1;

DROP VIEW v1;

#
# Bug #26124: BETWEEN over a view column of the DATETIME type
#

CREATE TABLE t1 (mydate DATETIME);
INSERT INTO t1 VALUES 
  ('2007-01-01'), ('2007-01-02'), ('2007-01-30'), ('2007-01-31');

CREATE VIEW v1 AS SELECT mydate from t1;

SELECT * FROM t1 WHERE mydate BETWEEN '2007-01-01' AND '2007-01-31';
SELECT * FROM v1 WHERE mydate BETWEEN '2007-01-01' AND '2007-01-31';

DROP VIEW v1;
DROP TABLE t1;

--echo End of 5.0 tests.
+2 −2
Original line number Diff line number Diff line
@@ -1185,11 +1185,11 @@ void Item_func_between::fix_length_and_dec()
    They are compared as integers, so for const item this time-consuming
    conversion can be done only once, not for every single comparison
  */
  if (args[0]->type() == FIELD_ITEM &&
  if (args[0]->real_item()->type() == FIELD_ITEM &&
      thd->lex->sql_command != SQLCOM_CREATE_VIEW &&
      thd->lex->sql_command != SQLCOM_SHOW_CREATE)
  {
    Field *field=((Item_field*) args[0])->field;
    Field *field=((Item_field*) (args[0]->real_item()))->field;
    if (field->can_be_compared_as_longlong())
    {
      /*