Skip to content

Commit b0e3f48

Browse files
committed
MDEV-8756 MariaDB 10.0.21 crashes during PREPARE
Non-select-like queries has no correct JOIN structure connected to top-most SELECT_LEX (and should not).
1 parent ac67f9a commit b0e3f48

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

mysql-test/r/ps.result

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4052,3 +4052,24 @@ SELECT 1 FROM t1 GROUP BY 0 OR 18446744073709551615+1;
40524052
ERROR 22003: BIGINT UNSIGNED value is out of range in '(18446744073709551615 + 1)'
40534053
drop table t1;
40544054
# End of 5.3 tests
4055+
#
4056+
# MDEV-8756: MariaDB 10.0.21 crashes during PREPARE
4057+
#
4058+
CREATE TABLE t1 ( id INT(10), value INT(10) );
4059+
CREATE TABLE t2 ( id INT(10) );
4060+
SET @save_sql_mode= @@sql_mode;
4061+
SET SESSION sql_mode = 'ONLY_FULL_GROUP_BY';
4062+
PREPARE stmt FROM 'UPDATE t1 t1 SET value = (SELECT 1 FROM t2 WHERE id = t1.id)';
4063+
execute stmt;
4064+
insert into t1 values (1,10),(2,10),(3,10);
4065+
insert into t2 values (1),(2);
4066+
execute stmt;
4067+
select * from t1;
4068+
id value
4069+
1 1
4070+
2 1
4071+
3 NULL
4072+
deallocate prepare stmt;
4073+
SET SESSION sql_mode = @save_sql_mode;
4074+
DROP TABLE t1,t2;
4075+
# End of 10.0 tests

mysql-test/t/ps.test

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3633,3 +3633,25 @@ SELECT 1 FROM t1 GROUP BY 0 OR 18446744073709551615+1;
36333633
drop table t1;
36343634

36353635
--echo # End of 5.3 tests
3636+
3637+
--echo #
3638+
--echo # MDEV-8756: MariaDB 10.0.21 crashes during PREPARE
3639+
--echo #
3640+
3641+
CREATE TABLE t1 ( id INT(10), value INT(10) );
3642+
CREATE TABLE t2 ( id INT(10) );
3643+
SET @save_sql_mode= @@sql_mode;
3644+
SET SESSION sql_mode = 'ONLY_FULL_GROUP_BY';
3645+
3646+
PREPARE stmt FROM 'UPDATE t1 t1 SET value = (SELECT 1 FROM t2 WHERE id = t1.id)';
3647+
execute stmt;
3648+
insert into t1 values (1,10),(2,10),(3,10);
3649+
insert into t2 values (1),(2);
3650+
execute stmt;
3651+
select * from t1;
3652+
deallocate prepare stmt;
3653+
SET SESSION sql_mode = @save_sql_mode;
3654+
DROP TABLE t1,t2;
3655+
3656+
3657+
--echo # End of 10.0 tests

sql/item.cc

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4834,8 +4834,24 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
48344834
As this is an outer field it should be added to the list of
48354835
non aggregated fields of the outer select.
48364836
*/
4837-
marker= select->cur_pos_in_select_list;
4838-
select->join->non_agg_fields.push_back(this);
4837+
if (select->join)
4838+
{
4839+
marker= select->cur_pos_in_select_list;
4840+
select->join->non_agg_fields.push_back(this);
4841+
}
4842+
else
4843+
{
4844+
/*
4845+
join is absent if it is upper SELECT_LEX of non-select
4846+
command
4847+
*/
4848+
DBUG_ASSERT(select->master_unit()->outer_select() == NULL &&
4849+
(thd->lex->sql_command != SQLCOM_SELECT &&
4850+
thd->lex->sql_command != SQLCOM_UPDATE_MULTI &&
4851+
thd->lex->sql_command != SQLCOM_DELETE_MULTI &&
4852+
thd->lex->sql_command != SQLCOM_INSERT_SELECT &&
4853+
thd->lex->sql_command != SQLCOM_REPLACE_SELECT));
4854+
}
48394855
}
48404856
if (*from_field != view_ref_found)
48414857
{

0 commit comments

Comments
 (0)