diff --git a/client/mysql.cc b/client/mysql.cc index 964f55f1e30..3380f5e2b2f 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -236,6 +236,8 @@ static char **defaults_argv; enum enum_info_type { INFO_INFO,INFO_ERROR,INFO_RESULT}; typedef enum enum_info_type INFO_TYPE; +enum ss_comment_type { SSC_NONE= 0, SSC_CONDITIONAL, SSC_HINT }; + static MYSQL mysql; /* The connection */ static my_bool ignore_errors=0,wait_flag=0,quick=0, connected=0,opt_raw_data=0,unbuffered=0,output_tables=0, @@ -1159,7 +1161,8 @@ static void fix_history(String *final_command); static COMMANDS *find_command(char *name); static COMMANDS *find_command(char cmd_name); -static bool add_line(String &, char *, size_t line_length, char *, bool *, bool); +static bool add_line(String &, char *, size_t line_length, char *, + bool *, ss_comment_type *, bool); static void remove_cntrl(String &buffer); static void print_table_data(MYSQL_RES *result); static void print_table_data_html(MYSQL_RES *result); @@ -2212,6 +2215,7 @@ static int read_and_execute(bool interactive) char in_string=0; ulong line_number=0; bool ml_comment= 0; + ss_comment_type ss_comment= SSC_NONE; COMMANDS *com; size_t line_length= 0; status.exit_status=1; @@ -2358,7 +2362,8 @@ static int read_and_execute(bool interactive) #endif continue; } - if (add_line(glob_buffer, line, line_length, &in_string, &ml_comment, + if (add_line(glob_buffer, line, line_length, &in_string, + &ml_comment, &ss_comment, status.line_buff ? status.line_buff->truncated : 0)) break; } @@ -2527,13 +2532,13 @@ static COMMANDS *find_command(char *name) static bool add_line(String &buffer, char *line, size_t line_length, - char *in_string, bool *ml_comment, bool truncated) + char *in_string, bool *ml_comment, + ss_comment_type *ss_comment, bool truncated) { uchar inchar; char buff[80], *pos, *out; COMMANDS *com; bool need_space= 0; - bool ss_comment= 0; DBUG_ENTER("add_line"); if (!line[0] && buffer.is_empty()) @@ -2608,7 +2613,7 @@ static bool add_line(String &buffer, char *line, size_t line_length, DBUG_RETURN(1); // Quit if (com->takes_params) { - if (ss_comment) + if (*ss_comment != SSC_NONE) { /* 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, continue; } } - else if (!*ml_comment && !*in_string && is_prefix(pos, delimiter)) + else if (!*ml_comment && !*in_string && *ss_comment != SSC_HINT && + is_prefix(pos, delimiter)) { // Found a statement. Continue parsing after the delimiter pos+= delimiter_length; @@ -2731,9 +2737,8 @@ static bool add_line(String &buffer, char *line, size_t line_length, break; } else if (!*in_string && inchar == '/' && pos[1] == '*' && - !(pos[2] == '!' || - (pos[2] == 'M' && pos[3] == '!') || - pos[2] == '+')) + pos[2] != '!' && !(pos[2] == 'M' && pos[3] == '!') && + pos[2] != '+' && *ss_comment != SSC_HINT) { if (preserve_comments) { @@ -2749,7 +2754,8 @@ static bool add_line(String &buffer, char *line, size_t line_length, out=line; } } - else if (*ml_comment && !ss_comment && inchar == '*' && *(pos + 1) == '/') + else if (*ml_comment && *ss_comment == SSC_NONE && + inchar == '*' && *(pos + 1) == '/') { if (preserve_comments) { @@ -2770,14 +2776,24 @@ static bool add_line(String &buffer, char *line, size_t line_length, } else { // Add found char to buffer - if (!*in_string && inchar == '/' && pos[1] == '*' && - (pos[2] == '!' || pos[2] == '+')) - ss_comment= 1; - else if (!*in_string && ss_comment && inchar == '*' && *(pos + 1) == '/') - ss_comment= 0; + if (!*in_string && inchar == '/' && pos[1] == '*') + { + if (pos[2] == '!') + *ss_comment= SSC_CONDITIONAL; + else if (pos[2] == '+') + *ss_comment= SSC_HINT; + } + else if (!*in_string && *ss_comment != SSC_NONE && + inchar == '*' && *(pos + 1) == '/') + { + *ss_comment= SSC_NONE; + *out++= *pos++; // copy '*' + *out++= *pos; // copy '/' + continue; + } if (inchar == *in_string) *in_string= 0; - else if (!*ml_comment && !*in_string && + else if (!*ml_comment && !*in_string && *ss_comment != SSC_HINT && (inchar == '\'' || inchar == '"' || inchar == '`')) *in_string= (char) inchar; if (!*ml_comment || preserve_comments) diff --git a/mysql-test/main/mysql_comments.result b/mysql-test/main/mysql_comments.result index 5b2a68974e0..df3dc6e14ed 100644 --- a/mysql-test/main/mysql_comments.result +++ b/mysql-test/main/mysql_comments.result @@ -33,6 +33,14 @@ Trigger sql_mode SQL Original Statement character_set_client collation_connectio 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-- id data trig 12 +id data +trig 12 +id data +trig 12 +id data +trig 12 +id data +trig 12 "Pass 2 : --enable-comments" 1 1 @@ -60,5 +68,13 @@ Trigger sql_mode SQL Original Statement character_set_client collation_connectio 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-- id data trig 12 +id data +trig 12 +id data +trig 12 +id data +trig 12 +id data +trig 12 set global sql_mode=default; End of 5.0 tests diff --git a/mysql-test/main/mysql_comments.sql b/mysql-test/main/mysql_comments.sql index 2497c35e465..c7d20dd8bcb 100644 --- a/mysql-test/main/mysql_comments.sql +++ b/mysql-test/main/mysql_comments.sql @@ -211,6 +211,18 @@ show create trigger t1_bi; insert into t1(id) value ("trig"); select * from t1; +##============================================================================ +## Optimizer hints +##============================================================================ + +select /*+ no_icp(t1)*/* from t1; +select /*+ no_icp(t1) " ;,` */* from t1; +select /*+ "some text" */* from t1; + +select /* no_icp(t1) +no_bka(t1) +*/* from t1; + ##============================================================================ ## Cleanup ##============================================================================ diff --git a/mysql-test/main/opt_hint_timeout.test b/mysql-test/main/opt_hint_timeout.test index 0e9b357be28..08b4c7f0a24 100644 --- a/mysql-test/main/opt_hint_timeout.test +++ b/mysql-test/main/opt_hint_timeout.test @@ -1,6 +1,11 @@ +# Setting statement time-outs is not possible for the embedded server neither +# by SET STATEMENT max_statement_time=X nor by /*+ MAX_EXECUTION_TIME(X)*/ hint. +# That is why this test is disabled for the embedded server --source include/not_embedded.inc ---source include/have_sequence.inc +--disable_view_protocol # Since optimizer hints are not supported inside views + +--source include/have_sequence.inc --echo # --echo # MAX_EXECUTION_TIME hint testing --echo # diff --git a/sql/sql_class.h b/sql/sql_class.h index 915533a83e3..bb529681571 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -6064,7 +6064,9 @@ public: } void set_query_timer_force(ulonglong timeout_val) { +#ifndef EMBEDDED_LIBRARY thr_timer_settime(&query_timer, timeout_val); +#endif } void reset_query_timer() {