Details
-
Bug
-
Status: Closed (View Workflow)
-
Blocker
-
Resolution: Fixed
-
10.5.11, 10.3(EOL), 10.4(EOL), 10.5, 10.6
-
Docker: mariadb:10.5.11
AWS RDS: mariadb 10.5.8
Client: ConnectorJ 2.6.0
Description
Steps to reproduce:
1. Create a function, which selects data from any table. It is not enough to just return some constant value.
2. Create a view, which uses the function created in step 1.
3. Create a procedure, which runs for-loop. This for loop must query view created on step 2. However, it should not use any columns returned from the query, but a constant, eg. 1, for each row.
4. Call procedure twice from the same connection. First run success normally. The second one crashes the server without any explanation.
Minimal Reproducible Example is on attachment server_crash.sql.
All these details seem to be required to cause the server to crash. Interestingly enough, dropping some of them causes a different issue. If I select any value on cursor definition or skip the view and call the function directly, the first run results an error Table 'test_table' doesn't exist. Example of this is on file table_does_not_exist.sql.
This fixes suite without view, but test suite with a view crashes by other cause (maybe other bug or this patch should be impruved):
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 57ab31d9edf..7f9e15d8dc9 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -4584,6 +4584,7 @@ sp_instr_cursor_copy_struct::exec_core(THD *thd, uint *nextp)
if (!row->arguments())
{
sp_cursor tmp(thd, &m_lex_keeper, true);
+ TABLE_LIST **query_tables_last_save= m_lex_keeper.get_query_tables_last();
// Open the cursor without copying data
if (!(ret= tmp.open(thd)))
{
@@ -4605,6 +4606,7 @@ sp_instr_cursor_copy_struct::exec_core(THD *thd, uint *nextp)
thd->restore_active_arena(thd->spcont->callers_arena, ¤t_arena);
tmp.close(thd);
}
+ m_lex_keeper.set_query_tables_last(query_tables_last_save);
}
*nextp= m_ip + 1;
DBUG_RETURN(ret);
diff --git a/sql/sp_head.h b/sql/sp_head.h
index e1cfbb484ad..1fa9232b0d9 100644
--- a/sql/sp_head.h
+++ b/sql/sp_head.h
@@ -1214,6 +1214,17 @@ class sp_lex_keeper
m_lex->safe_to_cache_query= 0;
}
+ TABLE_LIST **get_query_tables_last()
+ {
+ return m_lex->query_tables_last;
+ }
+
+ void set_query_tables_last(TABLE_LIST ** t)
+ {
+ m_lex->query_tables_last= t;
+ }
+
+
private:
LEX *m_lex;