Skip to content

Commit 92271c7

Browse files
committed
MDEV-8087: Server crashed in Time_and_counter_tracker::incr_loops
Problem: Procedure which uses stack of views first executed without most deep view. It fails but one view cached (as well as whole procedure). Then simultaniusely create the second view we lack and execute the procedure. In the beginning of procedure execution the view is not yet created so procedure used as it was cached (cache was not invalidated). But by the time we are trying to use most deep view it is already created. The problem with the view is that thd->select_number (first view was not parsed) so second view will get the same number. The fix is in keeping the thd->select_number correct even if we use cached views. In the proposed solution (to keep it simple) counter can be bigger then should but it should not create problem because numbers are still unique and situation is very rare.
1 parent e19a6f3 commit 92271c7

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

mysql-test/r/view_debug.result

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
#MDEV-8087:Server crashed in Time_and_counter_tracker::incr_loops
3+
#
4+
CREATE PROCEDURE proc() SELECT * FROM v2;
5+
CREATE ALGORITHM = UNDEFINED VIEW v1 AS SELECT 1;
6+
CREATE ALGORITHM = TEMPTABLE VIEW v2 AS SELECT 3 FROM v1;
7+
DROP VIEW v1;
8+
CALL proc();
9+
ERROR HY000: View 'test.v2' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
10+
SET DEBUG_SYNC= 'after_cached_view_opened SIGNAL oppp WAIT_FOR created';
11+
CALL proc();
12+
SET DEBUG_SYNC= 'now WAIT_FOR oppp';
13+
SET DEBUG_SYNC= 'RESET';
14+
CREATE ALGORITHM = TEMPTABLE VIEW v1 AS SELECT 2;
15+
SET DEBUG_SYNC= 'now SIGNAL created';
16+
SET DEBUG_SYNC= 'RESET';
17+
3
18+
3
19+
SET DEBUG_SYNC= 'RESET';
20+
drop procedure proc;
21+
drop view v1,v2;

mysql-test/t/view_debug.test

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
--source include/have_debug.inc
3+
4+
--echo #
5+
--echo #MDEV-8087:Server crashed in Time_and_counter_tracker::incr_loops
6+
--echo #
7+
8+
CREATE PROCEDURE proc() SELECT * FROM v2;
9+
10+
CREATE ALGORITHM = UNDEFINED VIEW v1 AS SELECT 1;
11+
CREATE ALGORITHM = TEMPTABLE VIEW v2 AS SELECT 3 FROM v1;
12+
DROP VIEW v1;
13+
14+
--connect (con1,localhost,root,,test)
15+
16+
--connect (con2,localhost,root,,test)
17+
18+
--connection con1
19+
--error ER_VIEW_INVALID
20+
CALL proc();
21+
SET DEBUG_SYNC= 'after_cached_view_opened SIGNAL oppp WAIT_FOR created';
22+
send CALL proc();
23+
24+
--connection con2
25+
SET DEBUG_SYNC= 'now WAIT_FOR oppp';
26+
SET DEBUG_SYNC= 'RESET';
27+
CREATE ALGORITHM = TEMPTABLE VIEW v1 AS SELECT 2;
28+
SET DEBUG_SYNC= 'now SIGNAL created';
29+
SET DEBUG_SYNC= 'RESET';
30+
31+
--connection con1
32+
--reap
33+
SET DEBUG_SYNC= 'RESET';
34+
35+
36+
drop procedure proc;
37+
drop view v1,v2;

sql/sql_lex.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,6 +2421,8 @@ struct LEX: public Query_tables_list
24212421
/** SELECT of CREATE VIEW statement */
24222422
LEX_STRING create_view_select;
24232423

2424+
uint number_of_selects; // valid only for view
2425+
24242426
/** Start of 'ON table', in trigger statements. */
24252427
const char* raw_trg_on_table_name_begin;
24262428
/** End of 'ON table', in trigger statements. */

sql/sql_view.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,9 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table,
11701170
*/
11711171
mysql_derived_reinit(thd, NULL, table);
11721172

1173+
thd->select_number+= table->view->number_of_selects;
1174+
1175+
DEBUG_SYNC(thd, "after_cached_view_opened");
11731176
DBUG_RETURN(0);
11741177
}
11751178

@@ -1357,6 +1360,9 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table,
13571360

13581361
parse_status= parse_sql(thd, & parser_state, table->view_creation_ctx);
13591362

1363+
lex->number_of_selects=
1364+
(thd->select_number - view_select->select_number) + 1;
1365+
13601366
/* Restore environment. */
13611367

13621368
if ((old_lex->sql_command == SQLCOM_SHOW_FIELDS) ||

0 commit comments

Comments
 (0)