summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladislav Vaintroub <wlad@mariadb.com>2020-09-28 09:49:46 +0200
committerVladislav Vaintroub <wlad@mariadb.com>2020-09-28 09:49:46 +0200
commita6987d9fb921a6638bb1a2397b89ca606fad6f49 (patch)
treeb48520c88d16dfcd650c45158f042eeb83c5e241
parentd9d9c30b707d7634503c8d3bce7dab7f7ec3fd34 (diff)
downloadmariadb-git-a6987d9fb921a6638bb1a2397b89ca606fad6f49.tar.gz
MDEV-23823 Crash in SELECT NEXT VALUE on locked view
Make open_table() fail if sequence should be opened, but it turns out to be locked view.
-rw-r--r--mysql-test/suite/sql_sequence/next.result9
-rw-r--r--mysql-test/suite/sql_sequence/next.test10
-rw-r--r--sql/sql_base.cc7
3 files changed, 26 insertions, 0 deletions
diff --git a/mysql-test/suite/sql_sequence/next.result b/mysql-test/suite/sql_sequence/next.result
index b1b1bb69306..fe761baa032 100644
--- a/mysql-test/suite/sql_sequence/next.result
+++ b/mysql-test/suite/sql_sequence/next.result
@@ -534,3 +534,12 @@ select next value for s;
next value for s
-999
drop sequence s;
+#
+# MDEV-23823 NEXT VALUE crash on locked view
+#
+CREATE VIEW v AS SELECT 1;
+LOCK TABLE v READ;
+SELECT NEXT VALUE FOR v;
+ERROR 42S02: 'test.v' is not a SEQUENCE
+UNLOCK TABLES;
+DROP VIEW v;
diff --git a/mysql-test/suite/sql_sequence/next.test b/mysql-test/suite/sql_sequence/next.test
index a1f91bd7823..5eac3b668ba 100644
--- a/mysql-test/suite/sql_sequence/next.test
+++ b/mysql-test/suite/sql_sequence/next.test
@@ -280,3 +280,13 @@ select next value for s;
flush tables;
select next value for s;
drop sequence s;
+
+--echo #
+--echo # MDEV-23823 NEXT VALUE crash on locked view
+--echo #
+CREATE VIEW v AS SELECT 1;
+LOCK TABLE v READ;
+--error ER_NOT_SEQUENCE
+SELECT NEXT VALUE FOR v;
+UNLOCK TABLES;
+DROP VIEW v;
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 73ed7a855a2..00e1198df0e 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -1724,7 +1724,14 @@ bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx)
}
if (is_locked_view(thd, table_list))
+ {
+ if (table_list->sequence)
+ {
+ my_error(ER_NOT_SEQUENCE, MYF(0), table_list->db.str, table_list->alias.str);
+ DBUG_RETURN(true);
+ }
DBUG_RETURN(FALSE); // VIEW
+ }
/*
No table in the locked tables list. In case of explicit LOCK TABLES