diff options
-rw-r--r-- | mysql-test/r/derived.result | 27 | ||||
-rw-r--r-- | mysql-test/r/group_by.result | 5 | ||||
-rw-r--r-- | mysql-test/r/subselect.result | 2 | ||||
-rw-r--r-- | mysql-test/r/subselect_no_mat.result | 2 | ||||
-rw-r--r-- | mysql-test/r/subselect_no_opts.result | 2 | ||||
-rw-r--r-- | mysql-test/r/subselect_no_scache.result | 2 | ||||
-rw-r--r-- | mysql-test/r/subselect_no_semijoin.result | 2 | ||||
-rw-r--r-- | mysql-test/t/derived.test | 34 | ||||
-rw-r--r-- | mysql-test/t/group_by.test | 7 | ||||
-rw-r--r-- | sql/field.cc | 2 | ||||
-rw-r--r-- | sql/item_subselect.cc | 1 | ||||
-rw-r--r-- | sql/sql_derived.cc | 3 | ||||
-rw-r--r-- | sql/sql_prepare.cc | 8 | ||||
-rw-r--r-- | sql/sql_select.cc | 19 | ||||
-rw-r--r-- | sql/sql_select.h | 4 | ||||
-rw-r--r-- | sql/sql_union.cc | 3 | ||||
-rw-r--r-- | storage/maria/ma_checksum.c | 2 | ||||
-rw-r--r-- | storage/maria/ma_key.c | 2 | ||||
-rw-r--r-- | storage/myisam/mi_checksum.c | 3 | ||||
-rw-r--r-- | storage/myisam/mi_key.c | 2 |
20 files changed, 112 insertions, 20 deletions
diff --git a/mysql-test/r/derived.result b/mysql-test/r/derived.result index 685e8ddd6bc..9d31ceab4d1 100644 --- a/mysql-test/r/derived.result +++ b/mysql-test/r/derived.result @@ -438,6 +438,33 @@ CALL p(); id drop procedure p; drop temporary table t1; +# +# MDEV-5143: update of a joined table with a nested subquery with +# a syntax error crashes mysqld with signal 11 +# +create table t1 (id int(11) not null auto_increment, val varchar(100) null,primary key (id)); +create table t2 (id int(11) not null auto_increment, val varchar(100) null,primary key (id)); +insert into t1 (val) values('a'); +insert into t2 (val) values('1'); +update +( +select +val +from +( +select +v.val +from +t2 wrong_table_alias +) t4 +) t3 +inner join t1 on +t1.id=t3.val +set +t1.val=t3.val +; +ERROR 42S22: Unknown column 'v.val' in 'field list' +drop table t1, t2; # End of 5.3 tests # # Bug#58730 Assertion failed: table->key_read == 0 in close_thread_table, diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result index 9f9dcd59d56..9bb22eb8169 100644 --- a/mysql-test/r/group_by.result +++ b/mysql-test/r/group_by.result @@ -2415,6 +2415,11 @@ a 200 set optimizer_switch=@save_optimizer_switch; DROP TABLE t1,t2; +# +# MDEV-5104 crash in Item_field::used_tables with broken order by +# +(select 1 order by x(y)) order by 1; +ERROR 42S22: Unknown column 'y' in 'order clause' # End of 5.3 tests # # Bug#49771: Incorrect MIN (date) when minimum value is 0000-00-00 diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 3b5b838b56a..9e073fe5d06 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -193,7 +193,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 4 SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 NULL UNION RESULT <union1,3> ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 (select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`b` = (select `test`.`t3`.`a` from `test`.`t3` order by 1 desc limit 1))) union (select `test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t4` where (`test`.`t4`.`b` = (select (max(`test`.`t2`.`a`) * 4) from `test`.`t2`)) order by `a`) +Note 1003 (select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`b` = (select `test`.`t3`.`a` from `test`.`t3` order by 1 desc limit 1))) union (select `test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t4` where (`test`.`t4`.`b` = (select (max(`test`.`t2`.`a`) * 4) from `test`.`t2`))) select (select a from t3 where a<t2.a*4 order by 1 desc limit 1), a from t2; (select a from t3 where a<t2.a*4 order by 1 desc limit 1) a 3 1 diff --git a/mysql-test/r/subselect_no_mat.result b/mysql-test/r/subselect_no_mat.result index a14e08b0aac..dc91d0b0587 100644 --- a/mysql-test/r/subselect_no_mat.result +++ b/mysql-test/r/subselect_no_mat.result @@ -200,7 +200,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 4 SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 NULL UNION RESULT <union1,3> ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 (select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`b` = (select `test`.`t3`.`a` from `test`.`t3` order by 1 desc limit 1))) union (select `test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t4` where (`test`.`t4`.`b` = (select (max(`test`.`t2`.`a`) * 4) from `test`.`t2`)) order by `a`) +Note 1003 (select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`b` = (select `test`.`t3`.`a` from `test`.`t3` order by 1 desc limit 1))) union (select `test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t4` where (`test`.`t4`.`b` = (select (max(`test`.`t2`.`a`) * 4) from `test`.`t2`))) select (select a from t3 where a<t2.a*4 order by 1 desc limit 1), a from t2; (select a from t3 where a<t2.a*4 order by 1 desc limit 1) a 3 1 diff --git a/mysql-test/r/subselect_no_opts.result b/mysql-test/r/subselect_no_opts.result index 7c1a7f67670..9937228af54 100644 --- a/mysql-test/r/subselect_no_opts.result +++ b/mysql-test/r/subselect_no_opts.result @@ -196,7 +196,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 4 SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 NULL UNION RESULT <union1,3> ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 (select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`b` = (select `test`.`t3`.`a` from `test`.`t3` order by 1 desc limit 1))) union (select `test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t4` where (`test`.`t4`.`b` = (select (max(`test`.`t2`.`a`) * 4) from `test`.`t2`)) order by `a`) +Note 1003 (select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`b` = (select `test`.`t3`.`a` from `test`.`t3` order by 1 desc limit 1))) union (select `test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t4` where (`test`.`t4`.`b` = (select (max(`test`.`t2`.`a`) * 4) from `test`.`t2`))) select (select a from t3 where a<t2.a*4 order by 1 desc limit 1), a from t2; (select a from t3 where a<t2.a*4 order by 1 desc limit 1) a 3 1 diff --git a/mysql-test/r/subselect_no_scache.result b/mysql-test/r/subselect_no_scache.result index 2b85a66c124..ee10f5e1169 100644 --- a/mysql-test/r/subselect_no_scache.result +++ b/mysql-test/r/subselect_no_scache.result @@ -199,7 +199,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 4 SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 NULL UNION RESULT <union1,3> ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 (select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`b` = (select `test`.`t3`.`a` from `test`.`t3` order by 1 desc limit 1))) union (select `test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t4` where (`test`.`t4`.`b` = (select (max(`test`.`t2`.`a`) * 4) from `test`.`t2`)) order by `a`) +Note 1003 (select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`b` = (select `test`.`t3`.`a` from `test`.`t3` order by 1 desc limit 1))) union (select `test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t4` where (`test`.`t4`.`b` = (select (max(`test`.`t2`.`a`) * 4) from `test`.`t2`))) select (select a from t3 where a<t2.a*4 order by 1 desc limit 1), a from t2; (select a from t3 where a<t2.a*4 order by 1 desc limit 1) a 3 1 diff --git a/mysql-test/r/subselect_no_semijoin.result b/mysql-test/r/subselect_no_semijoin.result index 5a7e303f4b9..73c4de888a0 100644 --- a/mysql-test/r/subselect_no_semijoin.result +++ b/mysql-test/r/subselect_no_semijoin.result @@ -196,7 +196,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 4 SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 NULL UNION RESULT <union1,3> ALL NULL NULL NULL NULL NULL NULL Warnings: -Note 1003 (select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`b` = (select `test`.`t3`.`a` from `test`.`t3` order by 1 desc limit 1))) union (select `test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t4` where (`test`.`t4`.`b` = (select (max(`test`.`t2`.`a`) * 4) from `test`.`t2`)) order by `a`) +Note 1003 (select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`b` = (select `test`.`t3`.`a` from `test`.`t3` order by 1 desc limit 1))) union (select `test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t4` where (`test`.`t4`.`b` = (select (max(`test`.`t2`.`a`) * 4) from `test`.`t2`))) select (select a from t3 where a<t2.a*4 order by 1 desc limit 1), a from t2; (select a from t3 where a<t2.a*4 order by 1 desc limit 1) a 3 1 diff --git a/mysql-test/t/derived.test b/mysql-test/t/derived.test index 008af317aec..a67a0e6c9d0 100644 --- a/mysql-test/t/derived.test +++ b/mysql-test/t/derived.test @@ -350,6 +350,40 @@ drop procedure p; drop temporary table t1; + +--echo # +--echo # MDEV-5143: update of a joined table with a nested subquery with +--echo # a syntax error crashes mysqld with signal 11 +--echo # + +create table t1 (id int(11) not null auto_increment, val varchar(100) null,primary key (id)); +create table t2 (id int(11) not null auto_increment, val varchar(100) null,primary key (id)); + +insert into t1 (val) values('a'); +insert into t2 (val) values('1'); + +--error ER_BAD_FIELD_ERROR +update + ( + select + val + from + ( + select + v.val + from + t2 wrong_table_alias + ) t4 + ) t3 + inner join t1 on + t1.id=t3.val +set + t1.val=t3.val +; + +drop table t1, t2; + + --echo # End of 5.3 tests --echo # diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test index 4b7a475eb28..1ef514d591d 100644 --- a/mysql-test/t/group_by.test +++ b/mysql-test/t/group_by.test @@ -1593,6 +1593,13 @@ set optimizer_switch=@save_optimizer_switch; DROP TABLE t1,t2; +--echo # +--echo # MDEV-5104 crash in Item_field::used_tables with broken order by +--echo # + +--error ER_BAD_FIELD_ERROR +(select 1 order by x(y)) order by 1; + --echo # End of 5.3 tests --echo # diff --git a/sql/field.cc b/sql/field.cc index 8c530c24279..e9cd153ad75 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -7077,7 +7077,7 @@ int Field_blob::store(const char *from,uint length,CHARSET_INFO *cs) if (!String::needs_conversion(length, cs, field_charset, &dummy_offset)) { Field_blob::store_length(length); - bmove(ptr+packlength, &from, sizeof(char*)); + bmove(ptr + packlength, &from, sizeof(char*)); return 0; } if (tmpstr.copy(from, length, cs)) diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index b2545e75bfc..051c5ec874a 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -3018,6 +3018,7 @@ int subselect_single_select_engine::prepare() select_lex->order_list.elements + select_lex->group_list.elements, select_lex->order_list.first, + false, select_lex->group_list.first, select_lex->having, NULL, select_lex, diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index bb55451e9dc..b584ed6de93 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -617,7 +617,8 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived) { sl->context.outer_context= 0; // Prepare underlying views/DT first. - sl->handle_derived(lex, DT_PREPARE); + if ((res= sl->handle_derived(lex, DT_PREPARE))) + goto exit; if (derived->outer_join) { diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 6b4865027c8..a0ec07b9db2 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -2544,7 +2544,13 @@ void reinit_stmt_before_use(THD *thd, LEX *lex) /* Fix ORDER list */ for (order= sl->order_list.first; order; order= order->next) order->item= &order->item_ptr; - sl->handle_derived(lex, DT_REINIT); + { +#ifndef DBUG_OFF + bool res= +#endif + sl->handle_derived(lex, DT_REINIT); + DBUG_ASSERT(res == 0); + } } { SELECT_LEX_UNIT *unit= sl->master_unit(); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 97fdc68ec29..ad73faee553 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -602,8 +602,8 @@ int JOIN::prepare(Item ***rref_pointer_array, TABLE_LIST *tables_init, uint wild_num, COND *conds_init, uint og_num, - ORDER *order_init, ORDER *group_init, - Item *having_init, + ORDER *order_init, bool skip_order_by, + ORDER *group_init, Item *having_init, ORDER *proc_param_init, SELECT_LEX *select_lex_arg, SELECT_LEX_UNIT *unit_arg) { @@ -717,7 +717,16 @@ JOIN::prepare(Item ***rref_pointer_array, DBUG_RETURN(-1); /* purecov: inspected */ ref_pointer_array= *rref_pointer_array; - + + /* Resolve the ORDER BY that was skipped, then remove it. */ + if (skip_order_by && select_lex != select_lex->master_unit()->global_parameters) + { + if (setup_order(thd, (*rref_pointer_array), tables_list, fields_list, + all_fields, select_lex->order_list.first)) + DBUG_RETURN(-1); + select_lex->order_list.empty(); + } + if (having) { nesting_map save_allow_sum_func= thd->lex->allow_sum_func; @@ -3022,7 +3031,7 @@ mysql_select(THD *thd, Item ***rref_pointer_array, else { if ((err= join->prepare(rref_pointer_array, tables, wild_num, - conds, og_num, order, group, having, + conds, og_num, order, false, group, having, proc_param, select_lex, unit))) { goto err; @@ -3046,7 +3055,7 @@ mysql_select(THD *thd, Item ***rref_pointer_array, thd_proc_info(thd, "init"); thd->lex->used_tables=0; if ((err= join->prepare(rref_pointer_array, tables, wild_num, - conds, og_num, order, group, having, proc_param, + conds, og_num, order, false, group, having, proc_param, select_lex, unit))) { goto err; diff --git a/sql/sql_select.h b/sql/sql_select.h index 2415ad1f0b5..0d7ea6d9121 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -1323,8 +1323,8 @@ public: } int prepare(Item ***rref_pointer_array, TABLE_LIST *tables, uint wind_num, - COND *conds, uint og_num, ORDER *order, ORDER *group, - Item *having, ORDER *proc_param, SELECT_LEX *select, + COND *conds, uint og_num, ORDER *order, bool skip_order_by, + ORDER *group, Item *having, ORDER *proc_param, SELECT_LEX *select, SELECT_LEX_UNIT *unit); bool prepare_stage2(); int optimize(); diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 8a5ec26ba80..22b5e5727e8 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -327,6 +327,7 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result, sl->group_list.elements, can_skip_order_by ? NULL : sl->order_list.first, + can_skip_order_by, sl->group_list.first, sl->having, (is_union_select ? NULL : @@ -510,7 +511,7 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result, 0, 0, global_parameters->order_list.elements, // og_num global_parameters->order_list.first, // order - NULL, NULL, NULL, + false, NULL, NULL, NULL, fake_select_lex, this); fake_select_lex->table_list.empty(); } diff --git a/storage/maria/ma_checksum.c b/storage/maria/ma_checksum.c index 61ec638053a..da2d40d3687 100644 --- a/storage/maria/ma_checksum.c +++ b/storage/maria/ma_checksum.c @@ -58,7 +58,7 @@ ha_checksum _ma_checksum(MARIA_HA *info, const uchar *record) length= _ma_calc_blob_length(blob_size_length, pos); if (length) { - memcpy((char*) &pos, pos + blob_size_length, sizeof(char*)); + memcpy(&pos, pos + blob_size_length, sizeof(char*)); crc= my_checksum(crc, pos, length); } continue; diff --git a/storage/maria/ma_key.c b/storage/maria/ma_key.c index f62ffcc49a0..246e5fb6d94 100644 --- a/storage/maria/ma_key.c +++ b/storage/maria/ma_key.c @@ -589,7 +589,7 @@ static int _ma_put_key_in_record(register MARIA_HA *info, uint keynr, if (unpack_blobs) { memcpy(record+keyseg->start+keyseg->bit_start, - (char*) &blob_ptr,sizeof(char*)); + &blob_ptr, sizeof(char*)); memcpy(blob_ptr,key,length); blob_ptr+=length; diff --git a/storage/myisam/mi_checksum.c b/storage/myisam/mi_checksum.c index 4c10b28a653..e0a8672760d 100644 --- a/storage/myisam/mi_checksum.c +++ b/storage/myisam/mi_checksum.c @@ -40,7 +40,8 @@ ha_checksum mi_checksum(MI_INFO *info, const uchar *buf) length=_mi_calc_blob_length(column->length- portable_sizeof_char_ptr, buf); - memcpy(&pos, buf+column->length- portable_sizeof_char_ptr, sizeof(char*)); + memcpy(&pos, buf+column->length - portable_sizeof_char_ptr, + sizeof(char*)); break; } case FIELD_VARCHAR: diff --git a/storage/myisam/mi_key.c b/storage/myisam/mi_key.c index dc078ebd401..9a2526ad2cf 100644 --- a/storage/myisam/mi_key.c +++ b/storage/myisam/mi_key.c @@ -424,7 +424,7 @@ static int _mi_put_key_in_record(register MI_INFO *info, uint keynr, if (unpack_blobs) { memcpy(record+keyseg->start+keyseg->bit_start, - &blob_ptr,sizeof(char*)); + &blob_ptr, sizeof(char *)); memcpy(blob_ptr,key,length); blob_ptr+=length; |