From ad947563ac9e42090cbcaef00ce0d22708d19f12 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 6 Jun 2013 23:33:40 +0300 Subject: [PATCH 1/2] MDEV-4593: p_s: crash in simplify_joins with delete using subselect from view mysql_derived_merge_for_insert() should not be called for views or derived tables which are not put (directly or via other views) in main SELECT_LEX "join list". --- mysql-test/r/view.result | 12 ++++++++++++ mysql-test/t/view.test | 14 ++++++++++++++ sql/sql_derived.cc | 11 ++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index ee6c235d09e..0f666f0e708 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -4651,6 +4651,18 @@ a 1 drop view v1; drop table t1,t2; +# +# MDEV-4593: p_s: crash in simplify_joins with delete using subselect +# from view +# +create table `t1`(`a` int); +create table `t2`(`a` int); +create or replace view `v1` as select `a` from `t1`; +prepare s from "delete from `t2` order by (select 1 from `v1`)"; +execute s; +deallocate prepare s; +drop view v1; +drop tables t1,t2; # ----------------------------------------------------------------- # -- End of 5.3 tests. # ----------------------------------------------------------------- diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 2a230e65493..f3f8dbfe77f 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -4596,6 +4596,20 @@ WHERE a = alias.a ); drop view v1; drop table t1,t2; +--echo # +--echo # MDEV-4593: p_s: crash in simplify_joins with delete using subselect +--echo # from view +--echo # + +create table `t1`(`a` int); +create table `t2`(`a` int); +create or replace view `v1` as select `a` from `t1`; +prepare s from "delete from `t2` order by (select 1 from `v1`)"; +execute s; +deallocate prepare s; +drop view v1; +drop tables t1,t2; + --echo # ----------------------------------------------------------------- --echo # -- End of 5.3 tests. --echo # ----------------------------------------------------------------- diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 99d20090623..afc2dea359a 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -83,7 +83,16 @@ mysql_handle_derived(LEX *lex, uint phases) sl && !res; sl= sl->next_select_in_list()) { - for (TABLE_LIST *cursor= sl->get_table_list(); + TABLE_LIST *cursor= sl->get_table_list(); + /* + DT_MERGE_FOR_INSERT is not needed for views/derived tables inside + subqueries. Views and derived tables of subqueries should be + processed normally. + */ + if (phases == DT_MERGE_FOR_INSERT && + cursor && cursor->top_table()->select_lex != &lex->select_lex) + continue; + for (; cursor && !res; cursor= cursor->next_local) { From fee78df3130f68c68df7c136593cf92bcb0dd208 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Mon, 17 Jun 2013 17:04:51 +0400 Subject: [PATCH 2/2] MDEV-4651 Crash in my_decimal2decimal in a ORDER BY query modified: mysql-test/r/ps_2myisam.result mysql-test/r/ps_3innodb.result mysql-test/r/ps_4heap.result mysql-test/r/ps_5merge.result mysql-test/r/type_datetime_hires.result mysql-test/suite/maria/r/ps_maria.result mysql-test/t/type_datetime_hires.test sql/item_timefunc.h --- mysql-test/r/ps_2myisam.result | 4 ++-- mysql-test/r/ps_3innodb.result | 4 ++-- mysql-test/r/ps_4heap.result | 4 ++-- mysql-test/r/ps_5merge.result | 8 ++++---- mysql-test/r/type_datetime_hires.result | 12 ++++++++++++ mysql-test/suite/maria/r/ps_maria.result | 4 ++-- mysql-test/t/type_datetime_hires.test | 9 +++++++++ sql/item_timefunc.h | 1 + 8 files changed, 34 insertions(+), 12 deletions(-) diff --git a/mysql-test/r/ps_2myisam.result b/mysql-test/r/ps_2myisam.result index 2a9d08a70f4..cce5d6e9e2f 100644 --- a/mysql-test/r/ps_2myisam.result +++ b/mysql-test/r/ps_2myisam.result @@ -1793,7 +1793,7 @@ t5 CREATE TABLE `t5` ( `param08` longtext, `const09` datetime DEFAULT NULL, `param09` longblob, - `const10` decimal(22,6) NOT NULL DEFAULT '0.000000', + `const10` decimal(22,6) DEFAULT NULL, `param10` decimal(65,30) DEFAULT NULL, `const11` int(4) DEFAULT NULL, `param11` bigint(20) DEFAULT NULL, @@ -1823,7 +1823,7 @@ def test t5 t5 const08 const08 253 19 19 N 1 0 8 def test t5 t5 param08 param08 252 4294967295 19 Y 16 0 8 def test t5 t5 const09 const09 12 19 19 Y 128 0 63 def test t5 t5 param09 param09 252 4294967295 19 Y 144 0 63 -def test t5 t5 const10 const10 246 24 16 N 1 6 63 +def test t5 t5 const10 const10 246 24 16 Y 0 6 63 def test t5 t5 param10 param10 246 67 40 Y 0 30 63 def test t5 t5 const11 const11 3 4 4 Y 32768 0 63 def test t5 t5 param11 param11 8 20 4 Y 32768 0 63 diff --git a/mysql-test/r/ps_3innodb.result b/mysql-test/r/ps_3innodb.result index 6b7434390af..328df9e5978 100644 --- a/mysql-test/r/ps_3innodb.result +++ b/mysql-test/r/ps_3innodb.result @@ -1776,7 +1776,7 @@ t5 CREATE TABLE `t5` ( `param08` longtext, `const09` datetime DEFAULT NULL, `param09` longblob, - `const10` decimal(22,6) NOT NULL DEFAULT '0.000000', + `const10` decimal(22,6) DEFAULT NULL, `param10` decimal(65,30) DEFAULT NULL, `const11` int(4) DEFAULT NULL, `param11` bigint(20) DEFAULT NULL, @@ -1806,7 +1806,7 @@ def test t5 t5 const08 const08 253 19 19 N 1 0 8 def test t5 t5 param08 param08 252 4294967295 19 Y 16 0 8 def test t5 t5 const09 const09 12 19 19 Y 128 0 63 def test t5 t5 param09 param09 252 4294967295 19 Y 144 0 63 -def test t5 t5 const10 const10 246 24 16 N 1 6 63 +def test t5 t5 const10 const10 246 24 16 Y 0 6 63 def test t5 t5 param10 param10 246 67 40 Y 0 30 63 def test t5 t5 const11 const11 3 4 4 Y 32768 0 63 def test t5 t5 param11 param11 8 20 4 Y 32768 0 63 diff --git a/mysql-test/r/ps_4heap.result b/mysql-test/r/ps_4heap.result index 58acc19124a..cc4330c57e4 100644 --- a/mysql-test/r/ps_4heap.result +++ b/mysql-test/r/ps_4heap.result @@ -1777,7 +1777,7 @@ t5 CREATE TABLE `t5` ( `param08` longtext, `const09` datetime DEFAULT NULL, `param09` longblob, - `const10` decimal(22,6) NOT NULL DEFAULT '0.000000', + `const10` decimal(22,6) DEFAULT NULL, `param10` decimal(65,30) DEFAULT NULL, `const11` int(4) DEFAULT NULL, `param11` bigint(20) DEFAULT NULL, @@ -1807,7 +1807,7 @@ def test t5 t5 const08 const08 253 19 19 N 1 0 8 def test t5 t5 param08 param08 252 4294967295 19 Y 16 0 8 def test t5 t5 const09 const09 12 19 19 Y 128 0 63 def test t5 t5 param09 param09 252 4294967295 19 Y 144 0 63 -def test t5 t5 const10 const10 246 24 16 N 1 6 63 +def test t5 t5 const10 const10 246 24 16 Y 0 6 63 def test t5 t5 param10 param10 246 67 40 Y 0 30 63 def test t5 t5 const11 const11 3 4 4 Y 32768 0 63 def test t5 t5 param11 param11 8 20 4 Y 32768 0 63 diff --git a/mysql-test/r/ps_5merge.result b/mysql-test/r/ps_5merge.result index 654e641deeb..fe1665fc24e 100644 --- a/mysql-test/r/ps_5merge.result +++ b/mysql-test/r/ps_5merge.result @@ -1713,7 +1713,7 @@ t5 CREATE TABLE `t5` ( `param08` longtext, `const09` datetime DEFAULT NULL, `param09` longblob, - `const10` decimal(22,6) NOT NULL DEFAULT '0.000000', + `const10` decimal(22,6) DEFAULT NULL, `param10` decimal(65,30) DEFAULT NULL, `const11` int(4) DEFAULT NULL, `param11` bigint(20) DEFAULT NULL, @@ -1743,7 +1743,7 @@ def test t5 t5 const08 const08 253 19 19 N 1 0 8 def test t5 t5 param08 param08 252 4294967295 19 Y 16 0 8 def test t5 t5 const09 const09 12 19 19 Y 128 0 63 def test t5 t5 param09 param09 252 4294967295 19 Y 144 0 63 -def test t5 t5 const10 const10 246 24 16 N 1 6 63 +def test t5 t5 const10 const10 246 24 16 Y 0 6 63 def test t5 t5 param10 param10 246 67 40 Y 0 30 63 def test t5 t5 const11 const11 3 4 4 Y 32768 0 63 def test t5 t5 param11 param11 8 20 4 Y 32768 0 63 @@ -5067,7 +5067,7 @@ t5 CREATE TABLE `t5` ( `param08` longtext, `const09` datetime DEFAULT NULL, `param09` longblob, - `const10` decimal(22,6) NOT NULL DEFAULT '0.000000', + `const10` decimal(22,6) DEFAULT NULL, `param10` decimal(65,30) DEFAULT NULL, `const11` int(4) DEFAULT NULL, `param11` bigint(20) DEFAULT NULL, @@ -5097,7 +5097,7 @@ def test t5 t5 const08 const08 253 19 19 N 1 0 8 def test t5 t5 param08 param08 252 4294967295 19 Y 16 0 8 def test t5 t5 const09 const09 12 19 19 Y 128 0 63 def test t5 t5 param09 param09 252 4294967295 19 Y 144 0 63 -def test t5 t5 const10 const10 246 24 16 N 1 6 63 +def test t5 t5 const10 const10 246 24 16 Y 0 6 63 def test t5 t5 param10 param10 246 67 40 Y 0 30 63 def test t5 t5 const11 const11 3 4 4 Y 32768 0 63 def test t5 t5 param11 param11 8 20 4 Y 32768 0 63 diff --git a/mysql-test/r/type_datetime_hires.result b/mysql-test/r/type_datetime_hires.result index 583030bf0da..5da6d31acc6 100644 --- a/mysql-test/r/type_datetime_hires.result +++ b/mysql-test/r/type_datetime_hires.result @@ -338,3 +338,15 @@ select * from t1; a b 2010-01-02 03:04:05.000000 2010-01-02 03:04:05 drop table t1; +# +# MDEV-4651 Crash in my_decimal2decimal in a ORDER BY query +# +SET @@time_zone='+00:00'; +CREATE TABLE t1 (a DATETIME(4) NOT NULL); +INSERT INTO t1 VALUES ('2001-01-01 00:00:00'),('2000-00-00 00:00:00'); +SELECT UNIX_TIMESTAMP(a) FROM t1 ORDER BY 1; +UNIX_TIMESTAMP(a) +NULL +978307200.0000 +DROP TABLE t1; +SET @@time_zone=DEFAULT; diff --git a/mysql-test/suite/maria/r/ps_maria.result b/mysql-test/suite/maria/r/ps_maria.result index 8ac0fee6f50..3546e78512c 100644 --- a/mysql-test/suite/maria/r/ps_maria.result +++ b/mysql-test/suite/maria/r/ps_maria.result @@ -1793,7 +1793,7 @@ t5 CREATE TABLE `t5` ( `param08` longtext, `const09` datetime DEFAULT NULL, `param09` longblob, - `const10` decimal(22,6) NOT NULL DEFAULT '0.000000', + `const10` decimal(22,6) DEFAULT NULL, `param10` decimal(65,30) DEFAULT NULL, `const11` int(4) DEFAULT NULL, `param11` bigint(20) DEFAULT NULL, @@ -1823,7 +1823,7 @@ def test t5 t5 const08 const08 253 19 19 N 1 0 8 def test t5 t5 param08 param08 252 4294967295 19 Y 16 0 8 def test t5 t5 const09 const09 12 19 19 Y 128 0 63 def test t5 t5 param09 param09 252 4294967295 19 Y 144 0 63 -def test t5 t5 const10 const10 246 24 16 N 1 6 63 +def test t5 t5 const10 const10 246 24 16 Y 0 6 63 def test t5 t5 param10 param10 246 67 40 Y 0 30 63 def test t5 t5 const11 const11 3 4 4 Y 32768 0 63 def test t5 t5 param11 param11 8 20 4 Y 32768 0 63 diff --git a/mysql-test/t/type_datetime_hires.test b/mysql-test/t/type_datetime_hires.test index 74f686d4157..a62c227f563 100644 --- a/mysql-test/t/type_datetime_hires.test +++ b/mysql-test/t/type_datetime_hires.test @@ -69,3 +69,12 @@ alter table t1 modify b datetime, modify a datetime(6); select * from t1; drop table t1; +--echo # +--echo # MDEV-4651 Crash in my_decimal2decimal in a ORDER BY query +--echo # +SET @@time_zone='+00:00'; +CREATE TABLE t1 (a DATETIME(4) NOT NULL); +INSERT INTO t1 VALUES ('2001-01-01 00:00:00'),('2000-00-00 00:00:00'); +SELECT UNIX_TIMESTAMP(a) FROM t1 ORDER BY 1; +DROP TABLE t1; +SET @@time_zone=DEFAULT; diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index 25a160d91f6..b17e1c794ee 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -370,6 +370,7 @@ public: decimals= args[0]->decimals; set_if_smaller(decimals, TIME_SECOND_PART_DIGITS); max_length=17 + (decimals ? decimals + 1 : 0); + set_persist_maybe_null(1); } void find_num_type() { hybrid_type= decimals ? DECIMAL_RESULT : INT_RESULT; } double real_op() { DBUG_ASSERT(0); return 0; }