Skip to content

Commit f183843

Browse files
committed
MDEV-22706: Assertion `!current' failed in PROFILING::start_new_query
Analysis: ======== When "Profiling" is enabled, server collects the resource usage of each statement that gets executed in current session. Profiling doesn't support nested statements. In order to ensure this behavior when profiling is enabled for a statement, there should not be any other active query which is being profiled. This active query information is stored in 'current' variable. When a nested query arrives it finds 'current' being not NULL and server aborts. When 'init_connect' and 'init_slave' system variables are set they contain a set of statements to be executed. "execute_init_command" is the function call which invokes "dispatch_command" for each statement provided in 'init_connect', 'init_slave' system variables. "execute_init_command" invokes "start_new_query" and it passes the statement list to "dispatch_command". This "dispatch_command" intern invokes "start_new_query" which leads to nesting of queries. Hence '!current' assert is triggered. Fix: === Remove profiling from "execute_init_command" as it will be done within "dispatch_command" execution.
1 parent 9fb8d87 commit f183843

File tree

3 files changed

+58
-8
lines changed

3 files changed

+58
-8
lines changed

mysql-test/r/nested_profiling.result

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
SET @saved_profiling=@@GLOBAL.profiling;
2+
SET @saved_init_connect=@@GLOBAL.init_connect;
3+
SET GLOBAL init_connect="set @a=2;set @b=3";
4+
SET GLOBAL profiling=on;
5+
create user mysqltest1@localhost;
6+
SELECT @a, @b;
7+
@a @b
8+
2 3
9+
SHOW PROFILES;
10+
Query_ID Duration Query
11+
1 # set @a=2;set @b=3
12+
2 # set @b=3
13+
3 # SELECT @a, @b
14+
DROP USER mysqltest1@localhost;
15+
SET GLOBAL profiling=@saved_profiling;
16+
SET GLOBAL init_connect=@saved_init_connect;

mysql-test/t/nested_profiling.test

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# ==== Purpose ====
2+
#
3+
# Test verifies that "init_connect" and "init_slave" system variables work
4+
# fine when "profiling=on".
5+
#
6+
# ==== Implementation ====
7+
#
8+
# Steps:
9+
# 0 - Create regular user without super privilege so that "init_connect"
10+
# variable is effective.
11+
# 1 - Enable profiling.
12+
# 2 - Start a new connection which will try to execute the statements
13+
# specified in "init_connect". No assert should be reported.
14+
# 3 - Execute SHOW PROFILES to verify that statements specified in
15+
# "init_connect" are displayed as part of profiling.
16+
#
17+
# ==== References ====
18+
#
19+
# MDEV-22706: Assertion `!current' failed in PROFILING::start_new_query
20+
#
21+
--source include/not_embedded.inc
22+
--source include/have_profiling.inc
23+
24+
SET @saved_profiling=@@GLOBAL.profiling;
25+
SET @saved_init_connect=@@GLOBAL.init_connect;
26+
SET GLOBAL init_connect="set @a=2;set @b=3";
27+
SET GLOBAL profiling=on;
28+
29+
create user mysqltest1@localhost;
30+
connect (con1,localhost,mysqltest1,,);
31+
connection con1;
32+
SELECT @a, @b;
33+
--replace_column 2 #
34+
SHOW PROFILES;
35+
36+
#========== Clean up ===========
37+
connection default;
38+
disconnect con1;
39+
DROP USER mysqltest1@localhost;
40+
41+
SET GLOBAL profiling=@saved_profiling;
42+
SET GLOBAL init_connect=@saved_init_connect;

sql/sql_parse.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -669,11 +669,6 @@ void execute_init_command(THD *thd, LEX_STRING *init_command,
669669
char *buf= thd->strmake(init_command->str, len);
670670
mysql_rwlock_unlock(var_lock);
671671

672-
#if defined(ENABLED_PROFILING)
673-
thd->profiling.start_new_query();
674-
thd->profiling.set_query_source(buf, len);
675-
#endif
676-
677672
THD_STAGE_INFO(thd, stage_execution_of_init_command);
678673
save_client_capabilities= thd->client_capabilities;
679674
thd->client_capabilities|= CLIENT_MULTI_QUERIES;
@@ -688,9 +683,6 @@ void execute_init_command(THD *thd, LEX_STRING *init_command,
688683
thd->client_capabilities= save_client_capabilities;
689684
thd->net.vio= save_vio;
690685

691-
#if defined(ENABLED_PROFILING)
692-
thd->profiling.finish_current_query();
693-
#endif
694686
}
695687

696688

0 commit comments

Comments
 (0)