Commit 4a5e23e2 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-16152 Expressions with INTERVAL return bad results in some cases

parent 1cb4caa6
...@@ -3484,3 +3484,30 @@ t1 CREATE TABLE `t1` ( ...@@ -3484,3 +3484,30 @@ t1 CREATE TABLE `t1` (
`c5` varchar(100) DEFAULT NULL `c5` varchar(100) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1; DROP TABLE t1;
#
# MDEV-16152 Expressions with INTERVAL return bad results in some cases
#
SELECT TIMESTAMP'2001-01-01 10:20:30' - INTERVAL '10' YEAR AS c1,
-INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c2;
c1 c2
1991-01-01 10:20:30 1991-01-01 10:20:30
SELECT TIMESTAMP'2001-01-01 10:20:30' + INTERVAL '10' YEAR AS c1,
INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c2,
+INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c3;
c1 c2 c3
2011-01-01 10:20:30 2011-01-01 10:20:30 2011-01-01 10:20:30
EXPLAIN EXTENDED SELECT
TIMESTAMP'2001-01-01 10:20:30' - INTERVAL '10' YEAR AS c1,
-INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select TIMESTAMP'2001-01-01 10:20:30' - interval '10' year AS `c1`,TIMESTAMP'2001-01-01 10:20:30' - interval '10' year AS `c2`
EXPLAIN EXTENDED SELECT
TIMESTAMP'2001-01-01 10:20:30' + INTERVAL '10' YEAR AS c1,
INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c2,
+INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select TIMESTAMP'2001-01-01 10:20:30' + interval '10' year AS `c1`,TIMESTAMP'2001-01-01 10:20:30' + interval '10' year AS `c2`,TIMESTAMP'2001-01-01 10:20:30' + interval '10' year AS `c3`
...@@ -2057,3 +2057,23 @@ EXECUTE IMMEDIATE ...@@ -2057,3 +2057,23 @@ EXECUTE IMMEDIATE
USING NULL, '10', 10, 10.0, 10e0, TIME'10:20:30'; USING NULL, '10', 10, 10.0, 10e0, TIME'10:20:30';
SHOW CREATE TABLE t1; SHOW CREATE TABLE t1;
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # MDEV-16152 Expressions with INTERVAL return bad results in some cases
--echo #
SELECT TIMESTAMP'2001-01-01 10:20:30' - INTERVAL '10' YEAR AS c1,
-INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c2;
SELECT TIMESTAMP'2001-01-01 10:20:30' + INTERVAL '10' YEAR AS c1,
INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c2,
+INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c3;
EXPLAIN EXTENDED SELECT
TIMESTAMP'2001-01-01 10:20:30' - INTERVAL '10' YEAR AS c1,
-INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c2;
EXPLAIN EXTENDED SELECT
TIMESTAMP'2001-01-01 10:20:30' + INTERVAL '10' YEAR AS c1,
INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c2,
+INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c3;
SET sql_mode=ORACLE;
#
# Start of 10.3 tests
#
#
# MDEV-16152 Expressions with INTERVAL return bad results in some cases
#
SELECT TIMESTAMP'2001-01-01 10:20:30' - INTERVAL '10' YEAR AS c1,
-INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c2;
c1 c2
1991-01-01 10:20:30 1991-01-01 10:20:30
SELECT TIMESTAMP'2001-01-01 10:20:30' + INTERVAL '10' YEAR AS c1,
INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c2,
+INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c3;
c1 c2 c3
2011-01-01 10:20:30 2011-01-01 10:20:30 2011-01-01 10:20:30
EXPLAIN EXTENDED SELECT
TIMESTAMP'2001-01-01 10:20:30' - INTERVAL '10' YEAR AS c1,
-INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c2;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select TIMESTAMP'2001-01-01 10:20:30' - interval '10' year AS "c1",TIMESTAMP'2001-01-01 10:20:30' - interval '10' year AS "c2"
EXPLAIN EXTENDED SELECT
TIMESTAMP'2001-01-01 10:20:30' + INTERVAL '10' YEAR AS c1,
INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c2,
+INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c3;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select TIMESTAMP'2001-01-01 10:20:30' + interval '10' year AS "c1",TIMESTAMP'2001-01-01 10:20:30' + interval '10' year AS "c2",TIMESTAMP'2001-01-01 10:20:30' + interval '10' year AS "c3"
SET sql_mode=ORACLE;
--echo #
--echo # Start of 10.3 tests
--echo #
--echo #
--echo # MDEV-16152 Expressions with INTERVAL return bad results in some cases
--echo #
SELECT TIMESTAMP'2001-01-01 10:20:30' - INTERVAL '10' YEAR AS c1,
-INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c2;
SELECT TIMESTAMP'2001-01-01 10:20:30' + INTERVAL '10' YEAR AS c1,
INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c2,
+INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c3;
EXPLAIN EXTENDED SELECT
TIMESTAMP'2001-01-01 10:20:30' - INTERVAL '10' YEAR AS c1,
-INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c2;
EXPLAIN EXTENDED SELECT
TIMESTAMP'2001-01-01 10:20:30' + INTERVAL '10' YEAR AS c1,
INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c2,
+INTERVAL '10' YEAR + TIMESTAMP'2001-01-01 10:20:30' AS c3;
...@@ -9776,6 +9776,25 @@ bit_expr: ...@@ -9776,6 +9776,25 @@ bit_expr:
if (unlikely($$ == NULL)) if (unlikely($$ == NULL))
MYSQL_YYABORT; MYSQL_YYABORT;
} }
| INTERVAL_SYM expr interval '+' expr %prec INTERVAL_SYM
/* we cannot put interval before - */
{
$$= new (thd->mem_root) Item_date_add_interval(thd, $5, $2, $3, 0);
if (unlikely($$ == NULL))
MYSQL_YYABORT;
}
| '+' INTERVAL_SYM expr interval '+' expr %prec NEG
{
$$= new (thd->mem_root) Item_date_add_interval(thd, $6, $3, $4, 0);
if (unlikely($$ == NULL))
MYSQL_YYABORT;
}
| '-' INTERVAL_SYM expr interval '+' expr %prec NEG
{
$$= new (thd->mem_root) Item_date_add_interval(thd, $6, $3, $4, 1);
if (unlikely($$ == NULL))
MYSQL_YYABORT;
}
| bit_expr '*' bit_expr %prec '*' | bit_expr '*' bit_expr %prec '*'
{ {
$$= new (thd->mem_root) Item_func_mul(thd, $1, $3); $$= new (thd->mem_root) Item_func_mul(thd, $1, $3);
...@@ -10133,13 +10152,6 @@ simple_expr: ...@@ -10133,13 +10152,6 @@ simple_expr:
if (unlikely($$ == NULL)) if (unlikely($$ == NULL))
MYSQL_YYABORT; MYSQL_YYABORT;
} }
| INTERVAL_SYM expr interval '+' expr %prec INTERVAL_SYM
/* we cannot put interval before - */
{
$$= new (thd->mem_root) Item_date_add_interval(thd, $5, $2, $3, 0);
if (unlikely($$ == NULL))
MYSQL_YYABORT;
}
; ;
function_call_keyword_timestamp: function_call_keyword_timestamp:
......
...@@ -9526,6 +9526,25 @@ bit_expr: ...@@ -9526,6 +9526,25 @@ bit_expr:
if (unlikely($$ == NULL)) if (unlikely($$ == NULL))
MYSQL_YYABORT; MYSQL_YYABORT;
} }
| INTERVAL_SYM expr interval '+' expr %prec INTERVAL_SYM
/* we cannot put interval before - */
{
$$= new (thd->mem_root) Item_date_add_interval(thd, $5, $2, $3, 0);
if (unlikely($$ == NULL))
MYSQL_YYABORT;
}
| '+' INTERVAL_SYM expr interval '+' expr %prec NEG
{
$$= new (thd->mem_root) Item_date_add_interval(thd, $6, $3, $4, 0);
if (unlikely($$ == NULL))
MYSQL_YYABORT;
}
| '-' INTERVAL_SYM expr interval '+' expr %prec NEG
{
$$= new (thd->mem_root) Item_date_add_interval(thd, $6, $3, $4, 1);
if (unlikely($$ == NULL))
MYSQL_YYABORT;
}
| bit_expr '*' bit_expr %prec '*' | bit_expr '*' bit_expr %prec '*'
{ {
$$= new (thd->mem_root) Item_func_mul(thd, $1, $3); $$= new (thd->mem_root) Item_func_mul(thd, $1, $3);
...@@ -9935,13 +9954,6 @@ simple_expr: ...@@ -9935,13 +9954,6 @@ simple_expr:
if (unlikely($$ == NULL)) if (unlikely($$ == NULL))
MYSQL_YYABORT; MYSQL_YYABORT;
} }
| INTERVAL_SYM expr interval '+' expr %prec INTERVAL_SYM
/* we cannot put interval before - */
{
$$= new (thd->mem_root) Item_date_add_interval(thd, $5, $2, $3, 0);
if (unlikely($$ == NULL))
MYSQL_YYABORT;
}
; ;
/* /*
......
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