Skip to content

Commit 8d813f0

Browse files
committed
MDEV-34539 Invalid "use" and "Schema" in slow query log file with multi-line schema
quote a database name in the slow log
1 parent f12634f commit 8d813f0

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

mysql-test/main/log_slow.result

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,30 @@ SET @@global.slow_query_log= @old_slow_query_log;
181181
SET SESSION slow_query_log=default;
182182
drop table tab_MDEV_30820, tab2;
183183
drop function get_zero;
184-
#
185184
# End of 10.4 tests
186185
#
186+
# MDEV-34539 Invalid "use" and "Schema" in slow query log file with multi-line schema
187+
#
188+
set global log_output='file';
189+
set @@log_slow_filter= 'not_using_index';
190+
set slow_query_log=1;
191+
set timestamp=1234567890;
192+
create database `a
193+
b`;
194+
use `a
195+
b`;
196+
select count(*) from mysql.global_priv where length(priv)>2;
197+
count(*)
198+
5
199+
drop database `a
200+
b`;
201+
use test;
202+
set global log_output= @old_log_output;
203+
set slow_query_log=default;
204+
set log_slow_filter=default;
205+
set timestamp=default;
206+
use `a
207+
b`;
208+
SET timestamp=1234567890;
209+
select count(*) from mysql.global_priv where length(priv)>2
210+
# End of 10.5 tests

mysql-test/main/log_slow.test

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,33 @@ drop function get_zero;
186186
--enable_ps2_protocol
187187
--enable_view_protocol
188188

189-
--echo #
190189
--echo # End of 10.4 tests
190+
191191
--echo #
192+
--echo # MDEV-34539 Invalid "use" and "Schema" in slow query log file with multi-line schema
193+
--echo #
194+
set global log_output='file';
195+
set @@log_slow_filter= 'not_using_index';
196+
set slow_query_log=1;
197+
set timestamp=1234567890;
198+
create database `a
199+
b`;
200+
use `a
201+
b`;
202+
--disable_ps_protocol
203+
select count(*) from mysql.global_priv where length(priv)>2;
204+
--enable_ps_protocol
205+
drop database `a
206+
b`;
207+
use test;
208+
set global log_output= @old_log_output;
209+
set slow_query_log=default;
210+
set log_slow_filter=default;
211+
set timestamp=default;
212+
213+
let SEARCH_FILE=`select @@slow_query_log_file`;
214+
let SEARCH_PATTERN=use.*2;
215+
let SEARCH_OUTPUT=matches;
216+
source include/search_pattern_in_file.inc;
217+
218+
--echo # End of 10.5 tests

sql/log.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3324,7 +3324,7 @@ bool MYSQL_QUERY_LOG::write(THD *thd, time_t current_time,
33243324
}
33253325
if (thd->db.str && strcmp(thd->db.str, db))
33263326
{ // Database changed
3327-
if (my_b_printf(&log_file,"use %s;\n",thd->db.str))
3327+
if (my_b_printf(&log_file,"use %`s;\n",thd->db.str))
33283328
goto err;
33293329
strmov(db,thd->db.str);
33303330
}

0 commit comments

Comments
 (0)