Skip to content

Commit 0e088b5

Browse files
committed
MDEV-34860 Fix opt_hint_timeout.test for embedded; fix mariadb client
1. Disable opt_hint_timeout.test for embedded server. Make sure the test does not crash even when started for embedded server. Disable view-protocol since hints are not supported inside views. 2. Hints are designed to behave like regular /* ... */ comments: `SELECT /*+ " */ 1;` -- a valid SQL query However, the mysql client program waits for the closing doublequote character. Another problem is observed when there is no space character between closing `*/` of the hint and the following `*`: `SELECT /*+ some_hints(...) */* FROM t1;` In this case the client treats `/*` as a comment section opening and waits for the closing `*/` sequence. This commit fixes all of these issues
1 parent d2918e1 commit 0e088b5

File tree

5 files changed

+68
-17
lines changed

5 files changed

+68
-17
lines changed

client/mysql.cc

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ static char **defaults_argv;
236236
enum enum_info_type { INFO_INFO,INFO_ERROR,INFO_RESULT};
237237
typedef enum enum_info_type INFO_TYPE;
238238

239+
enum ss_comment_type { SSC_NONE= 0, SSC_CONDITIONAL, SSC_HINT };
240+
239241
static MYSQL mysql;/* The connection */
240242
static my_bool ignore_errors=0,wait_flag=0,quick=0,
241243
connected=0,opt_raw_data=0,unbuffered=0,output_tables=0,
@@ -1159,7 +1161,8 @@ static void fix_history(String *final_command);
11591161

11601162
static COMMANDS *find_command(char *name);
11611163
static COMMANDS *find_command(char cmd_name);
1162-
static bool add_line(String &, char *, size_t line_length, char *, bool *, bool);
1164+
static bool add_line(String &, char *, size_t line_length, char *,
1165+
bool *, ss_comment_type *, bool);
11631166
static void remove_cntrl(String &buffer);
11641167
static void print_table_data(MYSQL_RES *result);
11651168
static void print_table_data_html(MYSQL_RES *result);
@@ -2212,6 +2215,7 @@ static int read_and_execute(bool interactive)
22122215
charin_string=0;
22132216
ulong line_number=0;
22142217
bool ml_comment= 0;
2218+
ss_comment_type ss_comment= SSC_NONE;
22152219
COMMANDS *com;
22162220
size_t line_length= 0;
22172221
status.exit_status=1;
@@ -2358,7 +2362,8 @@ static int read_and_execute(bool interactive)
23582362
#endif
23592363
continue;
23602364
}
2361-
if (add_line(glob_buffer, line, line_length, &in_string, &ml_comment,
2365+
if (add_line(glob_buffer, line, line_length, &in_string,
2366+
&ml_comment, &ss_comment,
23622367
status.line_buff ? status.line_buff->truncated : 0))
23632368
break;
23642369
}
@@ -2527,13 +2532,13 @@ static COMMANDS *find_command(char *name)
25272532

25282533

25292534
static bool add_line(String &buffer, char *line, size_t line_length,
2530-
char *in_string, bool *ml_comment, bool truncated)
2535+
char *in_string, bool *ml_comment,
2536+
ss_comment_type *ss_comment, bool truncated)
25312537
{
25322538
uchar inchar;
25332539
char buff[80], *pos, *out;
25342540
COMMANDS *com;
25352541
bool need_space= 0;
2536-
bool ss_comment= 0;
25372542
DBUG_ENTER("add_line");
25382543

25392544
if (!line[0] && buffer.is_empty())
@@ -2608,7 +2613,7 @@ static bool add_line(String &buffer, char *line, size_t line_length,
26082613
DBUG_RETURN(1); // Quit
26092614
if (com->takes_params)
26102615
{
2611-
if (ss_comment)
2616+
if (*ss_comment != SSC_NONE)
26122617
{
26132618
/*
26142619
If a client-side macro appears inside a server-side comment,
@@ -2642,7 +2647,8 @@ static bool add_line(String &buffer, char *line, size_t line_length,
26422647
continue;
26432648
}
26442649
}
2645-
else if (!*ml_comment && !*in_string && is_prefix(pos, delimiter))
2650+
else if (!*ml_comment && !*in_string && *ss_comment != SSC_HINT &&
2651+
is_prefix(pos, delimiter))
26462652
{
26472653
// Found a statement. Continue parsing after the delimiter
26482654
pos+= delimiter_length;
@@ -2731,9 +2737,8 @@ static bool add_line(String &buffer, char *line, size_t line_length,
27312737
break;
27322738
}
27332739
else if (!*in_string && inchar == '/' && pos[1] == '*' &&
2734-
!(pos[2] == '!' ||
2735-
(pos[2] == 'M' && pos[3] == '!') ||
2736-
pos[2] == '+'))
2740+
pos[2] != '!' && !(pos[2] == 'M' && pos[3] == '!') &&
2741+
pos[2] != '+' && *ss_comment != SSC_HINT)
27372742
{
27382743
if (preserve_comments)
27392744
{
@@ -2749,7 +2754,8 @@ static bool add_line(String &buffer, char *line, size_t line_length,
27492754
out=line;
27502755
}
27512756
}
2752-
else if (*ml_comment && !ss_comment && inchar == '*' && *(pos + 1) == '/')
2757+
else if (*ml_comment && *ss_comment == SSC_NONE &&
2758+
inchar == '*' && *(pos + 1) == '/')
27532759
{
27542760
if (preserve_comments)
27552761
{
@@ -2770,14 +2776,24 @@ static bool add_line(String &buffer, char *line, size_t line_length,
27702776
}
27712777
else
27722778
{// Add found char to buffer
2773-
if (!*in_string && inchar == '/' && pos[1] == '*' &&
2774-
(pos[2] == '!' || pos[2] == '+'))
2775-
ss_comment= 1;
2776-
else if (!*in_string && ss_comment && inchar == '*' && *(pos + 1) == '/')
2777-
ss_comment= 0;
2779+
if (!*in_string && inchar == '/' && pos[1] == '*')
2780+
{
2781+
if (pos[2] == '!')
2782+
*ss_comment= SSC_CONDITIONAL;
2783+
else if (pos[2] == '+')
2784+
*ss_comment= SSC_HINT;
2785+
}
2786+
else if (!*in_string && *ss_comment != SSC_NONE &&
2787+
inchar == '*' && *(pos + 1) == '/')
2788+
{
2789+
*ss_comment= SSC_NONE;
2790+
*out++= *pos++; // copy '*'
2791+
*out++= *pos; // copy '/'
2792+
continue;
2793+
}
27782794
if (inchar == *in_string)
27792795
*in_string= 0;
2780-
else if (!*ml_comment && !*in_string &&
2796+
else if (!*ml_comment && !*in_string && *ss_comment != SSC_HINT &&
27812797
(inchar == '\'' || inchar == '"' || inchar == '`'))
27822798
*in_string= (char) inchar;
27832799
if (!*ml_comment || preserve_comments)

mysql-test/main/mysql_comments.result

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ Trigger sql_mode SQL Original Statement character_set_client collation_connectio
3333
t1_bi CREATE DEFINER=`root`@`localhost` trigger t1_bi before insert on t1\nfor each row\nbegin\n\n\n\n \n declare b int;\n declare c float;\n\n \n \n\n \n set NEW.data := 12;\nend latin1 latin1_swedish_ci utf8mb4_uca1400_ai_ci --TIME--
3434
id data
3535
trig 12
36+
id data
37+
trig 12
38+
id data
39+
trig 12
40+
id data
41+
trig 12
42+
id data
43+
trig 12
3644
"Pass 2 : --enable-comments"
3745
1
3846
1
@@ -60,5 +68,13 @@ Trigger sql_mode SQL Original Statement character_set_client collation_connectio
6068
t1_bi CREATE DEFINER=`root`@`localhost` trigger t1_bi before insert on t1\nfor each row\nbegin\n# comment 1a\n-- comment 1b\n/*\n comment 1c\n*/\n -- declare some variables here\n declare b int;\n declare c float;\n\n -- do more stuff here\n -- commented nicely and so on\n\n -- famous last words ...\n set NEW.data := 12;\nend latin1 latin1_swedish_ci utf8mb4_uca1400_ai_ci --TIME--
6169
id data
6270
trig 12
71+
id data
72+
trig 12
73+
id data
74+
trig 12
75+
id data
76+
trig 12
77+
id data
78+
trig 12
6379
set global sql_mode=default;
6480
End of 5.0 tests

mysql-test/main/mysql_comments.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ show create trigger t1_bi;
211211
insert into t1(id) value ("trig");
212212
select * from t1;
213213

214+
##============================================================================
215+
## Optimizer hints
216+
##============================================================================
217+
218+
select /*+ no_icp(t1)*/* from t1;
219+
select /*+ no_icp(t1) " ;,` */* from t1;
220+
select /*+ "some text" */* from t1;
221+
222+
select /* no_icp(t1)
223+
no_bka(t1)
224+
*/* from t1;
225+
214226
##============================================================================
215227
## Cleanup
216228
##============================================================================

mysql-test/main/opt_hint_timeout.test

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
# Setting statement time-outs is not possible for the embedded server neither
2+
# by SET STATEMENT max_statement_time=X nor by /*+ MAX_EXECUTION_TIME(X)*/ hint.
3+
# That is why this test is disabled for the embedded server
14
--source include/not_embedded.inc
2-
--source include/have_sequence.inc
35

6+
--disable_view_protocol # Since optimizer hints are not supported inside views
7+
8+
--source include/have_sequence.inc
49
--echo #
510
--echo # MAX_EXECUTION_TIME hint testing
611
--echo #

sql/sql_class.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6064,7 +6064,9 @@ class THD: public THD_count, /* this must be first */
60646064
}
60656065
void set_query_timer_force(ulonglong timeout_val)
60666066
{
6067+
#ifndef EMBEDDED_LIBRARY
60676068
thr_timer_settime(&query_timer, timeout_val);
6069+
#endif
60686070
}
60696071
void reset_query_timer()
60706072
{

0 commit comments

Comments
 (0)