Skip to content

Commit dab1236

Browse files
committed
MDEV-6956:SET STATEMENT default_master_connection = ... has no effect
the problem was in assigning default value during parsing.
1 parent e91bc2e commit dab1236

File tree

9 files changed

+124
-11
lines changed

9 files changed

+124
-11
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# ==== Usage ====
2+
#
3+
# --let $status_items= Column_Name[, Column_Name[, ...]]
4+
# --source include/show_all_slaves_status.inc
5+
#
6+
# Parameters:
7+
# $status_items
8+
# Set to the name of the column in the output of SHOW SLAVE STATUS
9+
# that you want to display. Example:
10+
#
11+
# --let $status_items= Master_SSL_Allowed
12+
#
13+
# You can show multiple columns by setting $status_items to a
14+
# comma-separated list. Example:
15+
#
16+
# --let $status_items= Master_Log_File, Relay_Master_Log_File
17+
#
18+
# $slave_field_result_replace
19+
# If set, one or more regex patterns for replacing variable
20+
# text in the error message. Syntax as --replace-regex
21+
#
22+
# $slave_sql_mode
23+
# If set, change the slave sql mode during this macro, reverting
24+
# to the previous on exit. Default sql_mode is NO_BACKSLASH_ESCAPES
25+
# to allow replace '\' by '/' making paths OS independent. Example:
26+
#
27+
# --let $slave_sql_mode= NO_BACKSLASH_ESCAPES
28+
#
29+
30+
31+
--let $_show_slave_status_items=$status_items
32+
if (!$status_items)
33+
{
34+
--die Bug in test case: The mysqltest variable $status_items is not set.
35+
}
36+
37+
38+
--let $_slave_sql_mode= NO_BACKSLASH_ESCAPES
39+
if ($slave_sql_mode)
40+
{
41+
--let $_slave_sql_mode= $slave_sql_mode
42+
}
43+
--let $_previous_slave_sql_mode = `SELECT @@sql_mode`
44+
--disable_query_log
45+
eval SET sql_mode= '$_slave_sql_mode';
46+
--enable_query_log
47+
48+
49+
while ($_show_slave_status_items)
50+
{
51+
--let $_show_slave_status_name= `SELECT SUBSTRING_INDEX('$_show_slave_status_items', ',', 1)`
52+
--let $_show_slave_status_items= `SELECT LTRIM(SUBSTRING('$_show_slave_status_items', LENGTH('$_show_slave_status_name') + 2))`
53+
54+
--replace_regex /\.[\\\/]master/master/
55+
--let $_show_slave_status_value= query_get_value(SHOW ALL SLAVES STATUS, $_show_slave_status_name, 1)
56+
--let $_slave_field_result_replace= /[\\\\]/\// $slave_field_result_replace
57+
--replace_regex $_slave_field_result_replace
58+
--let $_show_slave_status_value= `SELECT REPLACE("$_show_slave_status_value", '$MYSQL_TEST_DIR', 'MYSQL_TEST_DIR')`
59+
--echo $_show_slave_status_name = '$_show_slave_status_value'
60+
}
61+
62+
63+
--disable_query_log
64+
eval SET sql_mode= '$_previous_slave_sql_mode';
65+
--enable_query_log

mysql-test/r/set_statement_notembedded.result

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,3 @@ Max_statement_time_exceeded 1
1616
SELECT @@MAX_STATEMENT_TIME;
1717
@@MAX_STATEMENT_TIME
1818
0.000000
19-
set statement default_master_connection=default for select 1;
20-
ERROR 42000: The system variable default_master_connection cannot be set in SET STATEMENT.
21-
set statement default_master_connection=default for select 1;
22-
ERROR 42000: The system variable default_master_connection cannot be set in SET STATEMENT.

mysql-test/suite/rpl/r/rpl_set_statement.test

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
include/master-slave.inc
2+
[connection master]
3+
include/stop_slave.inc
4+
RESET SLAVE ALL;
5+
# Does not work for CHANGE MASTER:
6+
SET STATEMENT default_master_connection = 'm1' FOR
7+
CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_MYPORT, MASTER_USER='root';
8+
#
9+
# The first field, Connection_name, should say 'm1'...
10+
#
11+
Connection_name = 'm1'
12+
RESET SLAVE ALL;
13+
CHANGE MASTER 'm1' TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_MYPORT, MASTER_USER='root';
14+
SET STATEMENT default_master_connection = 'm1' FOR START SLAVE;
15+
set default_master_connection = 'm1';
16+
stop slave;
17+
include/wait_for_slave_to_stop.inc
18+
reset slave all;
19+
set default_master_connection = '';
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--source include/master-slave.inc
2+
3+
--connection slave
4+
5+
--source include/stop_slave.inc
6+
RESET SLAVE ALL;
7+
8+
--echo # Does not work for CHANGE MASTER:
9+
--replace_result $MASTER_MYPORT MASTER_MYPORT
10+
eval SET STATEMENT default_master_connection = 'm1' FOR
11+
CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root';
12+
13+
14+
--echo #
15+
--echo # The first field, Connection_name, should say 'm1'...
16+
--echo #
17+
--let $status_items= Connection_name
18+
--source include/show_all_slaves_status.inc
19+
#query_vertical SHOW ALL SLAVES STATUS;
20+
21+
22+
RESET SLAVE ALL;
23+
24+
--replace_result $MASTER_MYPORT MASTER_MYPORT
25+
eval CHANGE MASTER 'm1' TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root';
26+
SET STATEMENT default_master_connection = 'm1' FOR START SLAVE;
27+
28+
set default_master_connection = 'm1';
29+
stop slave;
30+
--source include/wait_for_slave_to_stop.inc
31+
reset slave all;
32+
set default_master_connection = '';
33+
--disconnect slave
34+
--connection default

mysql-test/t/set_statement_notembedded.test

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,4 @@ SET STATEMENT MAX_STATEMENT_TIME=2 FOR SELECT SLEEP(3);
1010
SHOW STATUS LIKE "max_statement_time_exceeded";
1111
SELECT @@MAX_STATEMENT_TIME;
1212

13-
--error ER_SET_STATEMENT_NOT_SUPPORTED
14-
set statement default_master_connection=default for select 1;
15-
--error ER_SET_STATEMENT_NOT_SUPPORTED
16-
set statement default_master_connection=default for select 1;
1713

sql/sql_parse.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,6 +2730,9 @@ mysql_execute_command(THD *thd)
27302730
}
27312731
}
27322732

2733+
if (thd->lex->mi.connection_name.str == NULL)
2734+
thd->lex->mi.connection_name= thd->variables.default_master_connection;
2735+
27332736
/*
27342737
Force statement logging for DDL commands to allow us to update
27352738
privilege, system or statistic tables directly without the updates

sql/sql_yacc.yy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,7 +2443,7 @@ optional_connection_name:
24432443
/* empty */
24442444
{
24452445
LEX *lex= thd->lex;
2446-
lex->mi.connection_name= thd->variables.default_master_connection;
2446+
lex->mi.connection_name= null_lex_str;
24472447
}
24482448
| connection_name;
24492449
;
@@ -12674,7 +12674,7 @@ show_param:
1267412674
| SLAVE STATUS_SYM
1267512675
{
1267612676
LEX *lex= thd->lex;
12677-
lex->mi.connection_name= thd->variables.default_master_connection;
12677+
lex->mi.connection_name= null_lex_str;
1267812678
lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
1267912679
lex->verbose= 0;
1268012680
}

sql/sys_vars.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ static bool check_master_connection(sys_var *self, THD *thd, set_var *var)
993993
static Sys_var_session_lexstring Sys_default_master_connection(
994994
"default_master_connection",
995995
"Master connection to use for all slave variables and slave commands",
996-
NO_SET_STMT SESSION_ONLY(default_master_connection),
996+
SESSION_ONLY(default_master_connection),
997997
NO_CMD_LINE, IN_SYSTEM_CHARSET,
998998
DEFAULT(""), MAX_CONNECTION_NAME, ON_CHECK(check_master_connection));
999999
#endif

0 commit comments

Comments
 (0)