summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2018-05-22 12:09:05 -0700
committerIgor Babaev <igor@askmonty.org>2018-05-22 12:09:05 -0700
commit6a04c2a1aa60e67c07d4e6ada63f65cc3b26a5a9 (patch)
treec602e72328a69ad6a77856040a237fd1ec6e3853
parent27a7365f42ce0184a004e09b3bb1cadb868c8f64 (diff)
downloadmariadb-git-6a04c2a1aa60e67c07d4e6ada63f65cc3b26a5a9.tar.gz
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.
-rw-r--r--mysql-test/r/limit.result16
-rw-r--r--mysql-test/r/subselect4.result2
-rw-r--r--mysql-test/r/subselect_mat_cost_bugs.result2
-rw-r--r--mysql-test/t/limit.test14
-rw-r--r--mysql-test/t/subselect4.test2
-rw-r--r--sql/sql_select.cc17
6 files changed, 46 insertions, 7 deletions
diff --git a/mysql-test/r/limit.result b/mysql-test/r/limit.result
index 176a93c7a46..deb4ca2ab95 100644
--- a/mysql-test/r/limit.result
+++ b/mysql-test/r/limit.result
@@ -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
diff --git a/mysql-test/r/subselect4.result b/mysql-test/r/subselect4.result
index 6accc23d18a..8973330c7da 100644
--- a/mysql-test/r/subselect4.result
+++ b/mysql-test/r/subselect4.result
@@ -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);
diff --git a/mysql-test/r/subselect_mat_cost_bugs.result b/mysql-test/r/subselect_mat_cost_bugs.result
index df6b543bab8..d33f1488e4d 100644
--- a/mysql-test/r/subselect_mat_cost_bugs.result
+++ b/mysql-test/r/subselect_mat_cost_bugs.result
@@ -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)
diff --git a/mysql-test/t/limit.test b/mysql-test/t/limit.test
index 4dbe13096d4..668d3b74518 100644
--- a/mysql-test/t/limit.test
+++ b/mysql-test/t/limit.test
@@ -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
diff --git a/mysql-test/t/subselect4.test b/mysql-test/t/subselect4.test
index 2b53b55b735..2727fd9daed 100644
--- a/mysql-test/t/subselect4.test
+++ b/mysql-test/t/subselect4.test
@@ -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 #
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 1e9f1c0848b..d6d269a700f 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -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;