Skip to content

Commit

Permalink
MDEV-22706: Assertion `!current' failed in PROFILING::start_new_query
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sujatha-s committed Jun 25, 2020
1 parent 9fb8d87 commit f183843
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 8 deletions.
16 changes: 16 additions & 0 deletions mysql-test/r/nested_profiling.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SET @saved_profiling=@@GLOBAL.profiling;
SET @saved_init_connect=@@GLOBAL.init_connect;
SET GLOBAL init_connect="set @a=2;set @b=3";
SET GLOBAL profiling=on;
create user mysqltest1@localhost;
SELECT @a, @b;
@a @b
2 3
SHOW PROFILES;
Query_ID Duration Query
1 # set @a=2;set @b=3
2 # set @b=3
3 # SELECT @a, @b
DROP USER mysqltest1@localhost;
SET GLOBAL profiling=@saved_profiling;
SET GLOBAL init_connect=@saved_init_connect;
42 changes: 42 additions & 0 deletions mysql-test/t/nested_profiling.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# ==== Purpose ====
#
# Test verifies that "init_connect" and "init_slave" system variables work
# fine when "profiling=on".
#
# ==== Implementation ====
#
# Steps:
# 0 - Create regular user without super privilege so that "init_connect"
# variable is effective.
# 1 - Enable profiling.
# 2 - Start a new connection which will try to execute the statements
# specified in "init_connect". No assert should be reported.
# 3 - Execute SHOW PROFILES to verify that statements specified in
# "init_connect" are displayed as part of profiling.
#
# ==== References ====
#
# MDEV-22706: Assertion `!current' failed in PROFILING::start_new_query
#
--source include/not_embedded.inc
--source include/have_profiling.inc

SET @saved_profiling=@@GLOBAL.profiling;
SET @saved_init_connect=@@GLOBAL.init_connect;
SET GLOBAL init_connect="set @a=2;set @b=3";
SET GLOBAL profiling=on;

create user mysqltest1@localhost;
connect (con1,localhost,mysqltest1,,);
connection con1;
SELECT @a, @b;
--replace_column 2 #
SHOW PROFILES;

#========== Clean up ===========
connection default;
disconnect con1;
DROP USER mysqltest1@localhost;

SET GLOBAL profiling=@saved_profiling;
SET GLOBAL init_connect=@saved_init_connect;
8 changes: 0 additions & 8 deletions sql/sql_parse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -669,11 +669,6 @@ void execute_init_command(THD *thd, LEX_STRING *init_command,
char *buf= thd->strmake(init_command->str, len);
mysql_rwlock_unlock(var_lock);

#if defined(ENABLED_PROFILING)
thd->profiling.start_new_query();
thd->profiling.set_query_source(buf, len);
#endif

THD_STAGE_INFO(thd, stage_execution_of_init_command);
save_client_capabilities= thd->client_capabilities;
thd->client_capabilities|= CLIENT_MULTI_QUERIES;
Expand All @@ -688,9 +683,6 @@ void execute_init_command(THD *thd, LEX_STRING *init_command,
thd->client_capabilities= save_client_capabilities;
thd->net.vio= save_vio;

#if defined(ENABLED_PROFILING)
thd->profiling.finish_current_query();
#endif
}


Expand Down

0 comments on commit f183843

Please sign in to comment.