Commit 6a04c2a1 authored by Igor Babaev's avatar Igor Babaev

MDEV-16235 Server crashes in my_utf8_uni or in my_strtod_int

           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.
parent 27a7365f
......@@ -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
......@@ -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);
......
......@@ -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)
......
......@@ -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
......@@ -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 #
......
......@@ -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;
......
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