summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/limit_rows_examined.result19
-rw-r--r--mysql-test/t/limit_rows_examined.test17
-rw-r--r--sql/sql_lex.h6
-rw-r--r--sql/sql_select.cc2
-rw-r--r--sql/sql_union.cc2
5 files changed, 44 insertions, 2 deletions
diff --git a/mysql-test/r/limit_rows_examined.result b/mysql-test/r/limit_rows_examined.result
index 8d9ebab7631..e06df8d9cab 100644
--- a/mysql-test/r/limit_rows_examined.result
+++ b/mysql-test/r/limit_rows_examined.result
@@ -876,3 +876,22 @@ Warnings:
Warning 1931 Query execution was interrupted. The query examined at least 3 rows, which exceeds LIMIT ROWS EXAMINED (2). The query result may be incomplete
SET @@sql_mode=@old_mode;
DROP TABLE t1;
+#
+# MDEV-22447: SIGSEGV in Item::val_uint on EXPLAIN
+#
+SET @save_GENERAL_LOG= @@GLOBAL.GENERAL_LOG;
+SET @save_log_output= @@GLOBAL.log_output;
+SET GLOBAL GENERAL_LOG=ON;
+SET GLOBAL log_output="FILE,TABLE";
+CREATE TABLE t(a DATE);
+EXPLAIN SELECT * FROM t LIMIT ROWS EXAMINED 0;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t system NULL NULL NULL NULL 0 const row not found
+SELECT 1;
+1
+Warnings:
+Warning 1931 Query execution was interrupted. The query examined at least 0 rows, which exceeds LIMIT ROWS EXAMINED (18446744073709551615). The query result may be incomplete
+drop table t;
+SET GLOBAL GENERAL_LOG=@save_GENERAL_LOG;
+SET GLOBAL log_output=@save_log_output;
+# End of 10.2 tests
diff --git a/mysql-test/t/limit_rows_examined.test b/mysql-test/t/limit_rows_examined.test
index 4ccf25dc17a..7d4559151f5 100644
--- a/mysql-test/t/limit_rows_examined.test
+++ b/mysql-test/t/limit_rows_examined.test
@@ -594,3 +594,20 @@ INSERT INTO t1 (c) SELECT k FROM t1 LIMIT ROWS EXAMINED 2;
SET @@sql_mode=@old_mode;
DROP TABLE t1;
+
+--echo #
+--echo # MDEV-22447: SIGSEGV in Item::val_uint on EXPLAIN
+--echo #
+
+SET @save_GENERAL_LOG= @@GLOBAL.GENERAL_LOG;
+SET @save_log_output= @@GLOBAL.log_output;
+SET GLOBAL GENERAL_LOG=ON;
+SET GLOBAL log_output="FILE,TABLE";
+CREATE TABLE t(a DATE);
+EXPLAIN SELECT * FROM t LIMIT ROWS EXAMINED 0;
+SELECT 1;
+drop table t;
+SET GLOBAL GENERAL_LOG=@save_GENERAL_LOG;
+SET GLOBAL log_output=@save_log_output;
+
+--echo # End of 10.2 tests
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index bdf52e8ef7b..d9690125b91 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -2932,6 +2932,12 @@ public:
else
limit_rows_examined_cnt= ULONGLONG_MAX;
}
+ inline ulonglong get_limit_rows_examined()
+ {
+ if (limit_rows_examined)
+ return limit_rows_examined->val_uint();
+ return ULONGLONG_MAX;
+ }
SQL_I_List<ORDER> save_group_list;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index ff584e936b7..d1b738e94a0 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -389,7 +389,7 @@ bool handle_select(THD *thd, LEX *lex, select_result *result,
ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT,
ER_THD(thd, ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT),
thd->accessed_rows_and_keys,
- thd->lex->limit_rows_examined->val_uint());
+ thd->lex->get_limit_rows_examined());
thd->abort_on_warning= saved_abort_on_warning;
thd->reset_killed();
}
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 8f7aca2a8ed..da1edc0f058 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -1132,7 +1132,7 @@ bool st_select_lex_unit::exec()
ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT,
ER_THD(thd, ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT),
thd->accessed_rows_and_keys,
- thd->lex->limit_rows_examined->val_uint());
+ thd->lex->get_limit_rows_examined());
thd->reset_killed();
break;
}