Skip to content

Commit

Permalink
MDEV-16235 Server crashes in my_utf8_uni or in my_strtod_int
Browse files Browse the repository at this point in the history
           upon SELECT .. LIMIT 0

The code must differentiate between a SELECT with contradictory
WHERE/HAVING and one with LIMIT 0.
Also for the latter printed 'Zero limit' instead of 'Impossible where'
in the EXPLAIN output.
  • Loading branch information
igorbabaev committed May 22, 2018
1 parent 27a7365 commit 6a04c2a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 7 deletions.
16 changes: 16 additions & 0 deletions mysql-test/r/limit.result
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,19 @@ a
16
DROP TABLE t1;
End of 5.1 tests
#
# mdev-16235: SELECT over a table with LIMIT 0
#
EXPLAIN
SELECT * FROM mysql.slow_log WHERE sql_text != 'foo' LIMIT 0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Zero limit
SELECT * FROM mysql.slow_log WHERE sql_text != 'foo' LIMIT 0;
start_time user_host query_time lock_time rows_sent rows_examined db last_insert_id insert_id server_id sql_text
EXPLAIN
SELECT * FROM mysql.help_topic WHERE help_category_id != example LIMIT 0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Zero limit
SELECT * FROM mysql.help_topic WHERE help_category_id != example LIMIT 0;
help_topic_id name help_category_id description example url
End of 5.5 tests
2 changes: 1 addition & 1 deletion mysql-test/r/subselect4.result
Original file line number Diff line number Diff line change
Expand Up @@ -2512,7 +2512,7 @@ SELECT 2 IN (SELECT 2 from DUAL WHERE 1 != 1);
SET optimizer_switch= @@global.optimizer_switch;
set @@tmp_table_size= @@global.tmp_table_size;
#
# mfrv-14515: Wrong results for tableless query with subquery in WHERE
# mdev-14515: Wrong results for tableless query with subquery in WHERE
# and implicit aggregation
#
create table t1 (i1 int, i2 int);
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/r/subselect_mat_cost_bugs.result
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ SELECT * FROM t1
WHERE (f1) IN (SELECT f1 FROM t2)
LIMIT 0;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Zero limit
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where
SELECT * FROM t1
WHERE (f1) IN (SELECT f1 FROM t2)
Expand Down
14 changes: 14 additions & 0 deletions mysql-test/t/limit.test
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,17 @@ SELECT a FROM t1 ORDER BY a LIMIT 2 OFFSET 14;
DROP TABLE t1;

--echo End of 5.1 tests

--echo #
--echo # mdev-16235: SELECT over a table with LIMIT 0
--echo #

EXPLAIN
SELECT * FROM mysql.slow_log WHERE sql_text != 'foo' LIMIT 0;
SELECT * FROM mysql.slow_log WHERE sql_text != 'foo' LIMIT 0;

EXPLAIN
SELECT * FROM mysql.help_topic WHERE help_category_id != example LIMIT 0;
SELECT * FROM mysql.help_topic WHERE help_category_id != example LIMIT 0;

--echo End of 5.5 tests
2 changes: 1 addition & 1 deletion mysql-test/t/subselect4.test
Original file line number Diff line number Diff line change
Expand Up @@ -2047,7 +2047,7 @@ SET optimizer_switch= @@global.optimizer_switch;
set @@tmp_table_size= @@global.tmp_table_size;

--echo #
--echo # mfrv-14515: Wrong results for tableless query with subquery in WHERE
--echo # mdev-14515: Wrong results for tableless query with subquery in WHERE
--echo # and implicit aggregation
--echo #

Expand Down
17 changes: 13 additions & 4 deletions sql/sql_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1136,10 +1136,19 @@ JOIN::optimize()
if (cond_value == Item::COND_FALSE || having_value == Item::COND_FALSE ||
(!unit->select_limit_cnt && !(select_options & OPTION_FOUND_ROWS)))
{ /* Impossible cond */
DBUG_PRINT("info", (having_value == Item::COND_FALSE ?
"Impossible HAVING" : "Impossible WHERE"));
zero_result_cause= having_value == Item::COND_FALSE ?
"Impossible HAVING" : "Impossible WHERE";
if (unit->select_limit_cnt)
{
DBUG_PRINT("info", (having_value == Item::COND_FALSE ?
"Impossible HAVING" : "Impossible WHERE"));
zero_result_cause= having_value == Item::COND_FALSE ?
"Impossible HAVING" : "Impossible WHERE";
}
else
{
DBUG_PRINT("info", ("Zero limit"));
zero_result_cause= "Zero limit";
conds= 0;
}
table_count= top_join_tab_count= 0;
error= 0;
goto setup_subq_exit;
Expand Down

0 comments on commit 6a04c2a

Please sign in to comment.