From 91faec36f9e2591e09a602d6064e9a67dae69ded Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 31 Oct 2005 12:25:08 +0100 Subject: [PATCH 01/68] WL#2930 Adding view and cursor 'protocols' to mysqltest - Cleanup of mysqltest.c before extending it client/mysqltest.c: Cleanup functions run_query_* before adding new functionality. Break out common functions used in both run_query_stmt and run_query_normal Move functionality for all run_query_* calls into run_query Since the normal way of handling an unepected error is to call die(which will never return), remove all return values from functions that does not return. Add comments. Remove unused vars. Cleanup... Removed oboslete syntax @, "require" or "result" should be used. mysql-test/include/master-slave.inc: remove obsolete syntax @, use "require" command mysql-test/include/ps_query.inc: Remove this comment, mysqltest will now produce output. Old mysqltest didn't return any output since command starting with @ was treated as a require. Uggh. mysql-test/r/mysqltest.result: Update test result mysql-test/r/ps_2myisam.result: Update test result mysql-test/r/ps_3innodb.result: Update test result mysql-test/r/ps_4heap.result: Update test result mysql-test/r/ps_5merge.result: Update test result mysql-test/r/ps_6bdb.result: Update test result mysql-test/r/ps_7ndb.result: Update test result mysql-test/t/alias.test: Remove --disable/enable_ps_protocol, only used to mask bugs in mysqltest mysql-test/t/group_by.test: Remove --disable/enable_ps_protocol, only used to mask bugs in mysqltest mysql-test/t/mysqltest.test: Add test for "Missing delimiter until eof" mysql-test/t/union.test: Remove --disable/enable_ps_protocol, "select found_rows" works with ps_protocol now! --- client/mysqltest.c | 1531 +++++++++++++-------------- mysql-test/include/master-slave.inc | 6 +- mysql-test/include/ps_query.inc | 1 - mysql-test/r/mysqltest.result | 3 + mysql-test/r/ps_2myisam.result | 2 + mysql-test/r/ps_3innodb.result | 2 + mysql-test/r/ps_4heap.result | 2 + mysql-test/r/ps_5merge.result | 4 + mysql-test/r/ps_6bdb.result | 2 + mysql-test/r/ps_7ndb.result | 2 + mysql-test/t/alias.test | 2 - mysql-test/t/group_by.test | 4 - mysql-test/t/mysqltest.test | 9 + mysql-test/t/union.test | 21 - 14 files changed, 761 insertions(+), 830 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 6653d24e575..308bf6f9b79 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -248,8 +248,6 @@ typedef struct int read_lines,current_line; } PARSER; -MYSQL_RES *last_result=0; - PARSER parser; MASTER_POS master_pos; /* if set, all results are concated and compared against this file */ @@ -437,7 +435,7 @@ static VAR* var_init(VAR* v, const char *name, int name_len, const char *val, static void var_free(void* v); int dyn_string_cmp(DYNAMIC_STRING* ds, const char *fname); -void reject_dump(const char *record_file, char *buf, int size); +void dump_result_to_reject_file(const char *record_file, char *buf, int size); int close_connection(struct st_query*); static void set_charset(struct st_query*); @@ -464,9 +462,8 @@ void free_replace(); static int insert_pointer_name(reg1 POINTER_ARRAY *pa,my_string name); void free_pointer_array(POINTER_ARRAY *pa); static int initialize_replace_buffer(void); -static void free_replace_buffer(void); static void do_eval(DYNAMIC_STRING *query_eval, const char *query); -void str_to_file(const char *fname, char *str, int size); +static void str_to_file(const char *fname, char *str, int size); int do_server_op(struct st_query *q,const char *op); struct st_replace *glob_replace; @@ -491,10 +488,10 @@ my_bool mysql_rpl_probe(MYSQL *mysql __attribute__((unused))) { return 1; } static void replace_dynstr_append_mem(DYNAMIC_STRING *ds, const char *val, int len); static void replace_dynstr_append(DYNAMIC_STRING *ds, const char *val); -static int handle_error(const char *query, struct st_query *q, - unsigned int err_errno, const char *err_error, - const char *err_sqlstate, DYNAMIC_STRING *ds); -static int handle_no_error(struct st_query *q); +static void handle_error(const char *query, struct st_query *q, + unsigned int err_errno, const char *err_error, + const char *err_sqlstate, DYNAMIC_STRING *ds); +static void handle_no_error(struct st_query *q); static void do_eval(DYNAMIC_STRING* query_eval, const char *query) { @@ -541,8 +538,6 @@ static void do_eval(DYNAMIC_STRING* query_eval, const char *query) static void close_cons() { DBUG_ENTER("close_cons"); - if (last_result) - mysql_free_result(last_result); for (--next_con; next_con >= cons; --next_con) { mysql_close(&next_con->mysql); @@ -734,7 +729,21 @@ err: DBUG_RETURN(res); } -static int check_result(DYNAMIC_STRING* ds, const char *fname, +/* + Check the content of ds against content of file fname + + SYNOPSIS + check_result + ds - content to be checked + fname - name of file to check against + require_option - if set and check fails, the test will be aborted with the special + exit code "not supported test" + + RETURN VALUES + error - the function will not return + +*/ +static void check_result(DYNAMIC_STRING* ds, const char *fname, my_bool require_option) { int res= dyn_string_cmp(ds, fname); @@ -746,17 +755,18 @@ static int check_result(DYNAMIC_STRING* ds, const char *fname, case RESULT_OK: break; /* ok */ case RESULT_LENGTH_MISMATCH: - verbose_msg("Result length mismatch"); + dump_result_to_reject_file(fname, ds->str, ds->length); + die("Result length mismatch"); break; case RESULT_CONTENT_MISMATCH: - verbose_msg("Result content mismatch"); + dump_result_to_reject_file(fname, ds->str, ds->length); + die("Result content mismatch"); break; default: /* impossible */ die("Unknown error code from dyn_string_cmp()"); } - if (res != RESULT_OK) - reject_dump(fname, ds->str, ds->length); - DBUG_RETURN(res); + + DBUG_VOID_RETURN; } @@ -1043,7 +1053,6 @@ static void do_exec(struct st_query *query) { int error; DYNAMIC_STRING *ds= NULL; - DYNAMIC_STRING ds_tmp; char buf[1024]; FILE *res_file; char *cmd= query->first_argument; @@ -1070,14 +1079,7 @@ static void do_exec(struct st_query *query) } else { - if (query->record_file[0]) - { - init_dynamic_string(&ds_tmp, "", 16384, 65536); - ds= &ds_tmp; - } - else - ds= &ds_res; - + ds= &ds_res; while (fgets(buf, sizeof(buf), res_file)) replace_dynstr_append(ds, buf); } @@ -1118,25 +1120,7 @@ static void do_exec(struct st_query *query) cmd, query->expected_errno[0].code.errnum); } - if (!disable_result_log) - { - if (glob_replace) - free_replace(); - - if (record) - { - if (!query->record_file[0] && !result_file) - die("Missing result file"); - if (!result_file) - str_to_file(query->record_file, ds->str, ds->length); - } - else if (query->record_file[0]) - { - error= check_result(ds, query->record_file, query->require_file); - } - if (ds == &ds_tmp) - dynstr_free(&ds_tmp); - } + free_replace(); } @@ -1354,25 +1338,16 @@ int do_echo(struct st_query *q) { char *p= q->first_argument; DYNAMIC_STRING *ds; - DYNAMIC_STRING ds_tmp; VAR v; var_init(&v,0,0,0,0); - if (q->record_file[0]) - { - init_dynamic_string(&ds_tmp, "", 256, 512); - ds= &ds_tmp; - } - else - ds= &ds_res; + ds= &ds_res; eval_expr(&v, p, 0); /* NULL terminated */ if (v.str_val_len) dynstr_append_mem(ds, v.str_val, v.str_val_len); dynstr_append_mem(ds, "\n", 1); var_free(&v); - if (ds == &ds_tmp) - dynstr_free(&ds_tmp); q->last_argument= q->end; return 0; } @@ -1401,7 +1376,7 @@ wait_for_position: die("failed in %s: %d: %s", query_buf, mysql_errno(mysql), mysql_error(mysql)); - if (!(last_result= res= mysql_store_result(mysql))) + if (!(res= mysql_store_result(mysql))) die("mysql_store_result() returned NULL for '%s'", query_buf); if (!(row= mysql_fetch_row(res))) die("empty result in %s", query_buf); @@ -1418,7 +1393,6 @@ wait_for_position: goto wait_for_position; } mysql_free_result(res); - last_result=0; if (rpl_parse) mysql_enable_rpl_parse(mysql); @@ -1457,13 +1431,13 @@ int do_save_master_pos() die("failed in show master status: %d: %s", mysql_errno(mysql), mysql_error(mysql)); - if (!(last_result =res = mysql_store_result(mysql))) + if (!(res = mysql_store_result(mysql))) die("mysql_store_result() retuned NULL for '%s'", query); if (!(row = mysql_fetch_row(res))) die("empty result in show master status"); strnmov(master_pos.file, row[0], sizeof(master_pos.file)-1); master_pos.pos = strtoul(row[1], (char**) 0, 10); - mysql_free_result(res); last_result=0; + mysql_free_result(res); if (rpl_parse) mysql_enable_rpl_parse(mysql); @@ -1832,7 +1806,7 @@ void free_replace() { my_free((char*) glob_replace,MYF(0)); glob_replace=0; - free_replace_buffer(); + my_free(out_buff,MYF(MY_WME)); } DBUG_VOID_RETURN; } @@ -2029,21 +2003,11 @@ int connect_n_handle_errors(struct st_query *q, MYSQL* con, const char* host, const char* db, int port, const char* sock, int* create_conn) { - DYNAMIC_STRING ds_tmp, *ds; + DYNAMIC_STRING *ds; my_bool reconnect= 1; int error= 0; - /* - Altough we ignore --require or --result before connect() command we still - need to handle record_file because of "@result_file sql-command" syntax. - */ - if (q->record_file[0]) - { - init_dynamic_string(&ds_tmp, "", 16384, 65536); - ds= &ds_tmp; - } - else - ds= &ds_res; + ds= &ds_res; if (!disable_query_log) { @@ -2076,13 +2040,15 @@ int connect_n_handle_errors(struct st_query *q, MYSQL* con, const char* host, if (!mysql_real_connect(con, host, user, pass, db, port, sock ? sock: 0, CLIENT_MULTI_STATEMENTS)) { - error= handle_error("connect", q, mysql_errno(con), mysql_error(con), - mysql_sqlstate(con), ds); + handle_error("connect", q, mysql_errno(con), mysql_error(con), + mysql_sqlstate(con), ds); *create_conn= 0; goto err; } - else if (handle_no_error(q)) + else { + handle_no_error(q); + /* Fail if there was no error but we expected it. We also don't want to have connection in this case. @@ -2099,20 +2065,8 @@ int connect_n_handle_errors(struct st_query *q, MYSQL* con, const char* host, */ mysql_options(con, MYSQL_OPT_RECONNECT, (char *)&reconnect); - if (record) - { - if (!q->record_file[0] && !result_file) - die("Missing result file"); - if (!result_file) - str_to_file(q->record_file, ds->str, ds->length); - } - else if (q->record_file[0]) - error|= check_result(ds, q->record_file, q->require_file); - err: free_replace(); - if (ds == &ds_tmp) - dynstr_free(&ds_tmp); return error; } @@ -2470,7 +2424,7 @@ int read_line(char *buf, int size) state= R_Q; } else - state= R_NORMAL; +state= R_NORMAL; break; case R_Q: @@ -2559,7 +2513,7 @@ static char read_query_buf[MAX_QUERY]; int read_query(struct st_query** q_ptr) { - char *p= read_query_buf, *p1; + char *p= read_query_buf; struct st_query* q; DBUG_ENTER("read_query"); @@ -2578,10 +2532,13 @@ int read_query(struct st_query** q_ptr) q->type= Q_UNKNOWN; q->query_buf= q->query= 0; + read_query_buf[0]= 0; if (read_line(read_query_buf, sizeof(read_query_buf))) { + check_eol_junk(read_query_buf); DBUG_RETURN(1); } + DBUG_PRINT("info", ("query: %s", read_query_buf)); if (*p == '#') { @@ -2606,15 +2563,6 @@ int read_query(struct st_query** q_ptr) { while (*p && my_isspace(charset_info, *p)) p++ ; - if (*p == '@') - { - p++; - p1 = q->record_file; - while (!my_isspace(charset_info, *p) && - p1 < q->record_file + sizeof(q->record_file) - 1) - *p1++ = *p++; - *p1 = 0; - } } end: @@ -2862,7 +2810,17 @@ char* safe_str_append(char *buf, const char *str, int size) return buf; } -void str_to_file(const char *fname, char *str, int size) + +/* + Write the content of str into file + + SYNOPSIS + str_to_file + fname - name of file to truncate/create and write to + str - content to write to file + size - size of content witten to file +*/ +static void str_to_file(const char *fname, char *str, int size) { int fd; char buff[FN_REFLEN]; @@ -2881,7 +2839,7 @@ void str_to_file(const char *fname, char *str, int size) my_close(fd, MYF(0)); } -void reject_dump(const char *record_file, char *buf, int size) +void dump_result_to_reject_file(const char *record_file, char *buf, int size) { char reject_file[FN_REFLEN]; str_to_file(fn_format(reject_file, record_file,"",".reject",2), buf, size); @@ -2921,7 +2879,7 @@ static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res) MYSQL_ROW row; uint num_fields= mysql_num_fields(res); MYSQL_FIELD *fields= !display_result_vertically ? 0 : mysql_fetch_fields(res); - unsigned long *lengths; + ulong *lengths; while ((row = mysql_fetch_row(res))) { uint i; @@ -2963,667 +2921,118 @@ static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res) /* -* flags control the phased/stages of query execution to be performed -* if QUERY_SEND bit is on, the query will be sent. If QUERY_REAP is on -* the result will be read - for regular query, both bits must be on + Append all results from ps execution to the dynamic string separated + with '\t'. Values may be converted with 'replace_column' */ -static int run_query_normal(MYSQL *mysql, struct st_query *q, int flags); -static int run_query_stmt (MYSQL *mysql, struct st_query *q, int flags); -static void run_query_stmt_handle_warnings(MYSQL *mysql, DYNAMIC_STRING *ds); -static void run_query_display_metadata(MYSQL_FIELD *field, uint num_fields, - DYNAMIC_STRING *ds); - -static int run_query(MYSQL *mysql, struct st_query *q, int flags) +static void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT* stmt, + MYSQL_FIELD* field, uint num_fields) { - - /* - Try to find out if we can run this statement using the prepared - statement protocol. - - We don't have a mysql_stmt_send_execute() so we only handle - complete SEND+REAP. - - If it is a '?' in the query it may be a SQL level prepared - statement already and we can't do it twice - */ - - if (ps_protocol_enabled && disable_info && - (flags & QUERY_SEND) && (flags & QUERY_REAP) && ps_match_re(q->query)) - return run_query_stmt(mysql, q, flags); - return run_query_normal(mysql, q, flags); -} - - -static int run_query_normal(MYSQL* mysql, struct st_query* q, int flags) -{ - MYSQL_RES* res= 0; - uint i; - int error= 0, err= 0, counter= 0; - DYNAMIC_STRING *ds; - DYNAMIC_STRING ds_tmp; - DYNAMIC_STRING eval_query; - char* query; - int query_len, got_error_on_send= 0; - DBUG_ENTER("run_query_normal"); - DBUG_PRINT("enter",("flags: %d", flags)); - - if (q->type != Q_EVAL) - { - query = q->query; - query_len = strlen(query); - } - else - { - init_dynamic_string(&eval_query, "", 16384, 65536); - do_eval(&eval_query, q->query); - query = eval_query.str; - query_len = eval_query.length; - } - DBUG_PRINT("enter", ("query: '%-.60s'", query)); - - if (q->record_file[0]) - { - init_dynamic_string(&ds_tmp, "", 16384, 65536); - ds = &ds_tmp; - } - else - ds= &ds_res; - - if (flags & QUERY_SEND) - { - got_error_on_send= mysql_send_query(mysql, query, query_len); - if (got_error_on_send && q->expected_errno[0].type == ERR_EMPTY) - die("unable to send query '%s' (mysql_errno=%d , errno=%d)", - query, mysql_errno(mysql), errno); - } - - do - { - if ((flags & QUERY_SEND) && !disable_query_log && !counter) - { - replace_dynstr_append_mem(ds,query, query_len); - dynstr_append_mem(ds, delimiter, delimiter_length); - dynstr_append_mem(ds, "\n", 1); - } - if (!(flags & QUERY_REAP)) - DBUG_RETURN(0); - - if (got_error_on_send || - (!counter && (*mysql->methods->read_query_result)(mysql)) || - (!(last_result= res= mysql_store_result(mysql)) && - mysql_field_count(mysql))) - { - if (handle_error(query, q, mysql_errno(mysql), mysql_error(mysql), - mysql_sqlstate(mysql), ds)) - error= 1; - goto end; - } - - if (!disable_result_log) - { - ulong affected_rows; /* Ok to be undef if 'disable_info' is set */ - LINT_INIT(affected_rows); - - if (res) - { - MYSQL_FIELD *field= mysql_fetch_fields(res); - uint num_fields= mysql_num_fields(res); - - if (display_metadata) - run_query_display_metadata(field, num_fields, ds); - - if (!display_result_vertically) - { - for (i = 0; i < num_fields; i++) - { - if (i) - dynstr_append_mem(ds, "\t", 1); - replace_dynstr_append(ds, field[i].name); - } - dynstr_append_mem(ds, "\n", 1); - } - append_result(ds, res); - } - - /* - Need to call mysql_affected_rows() before the new - query to find the warnings - */ - if (!disable_info) - affected_rows= (ulong)mysql_affected_rows(mysql); - - /* - Add all warnings to the result. We can't do this if we are in - the middle of processing results from multi-statement, because - this will break protocol. - */ - if (!disable_warnings && !mysql_more_results(mysql) && - mysql_warning_count(mysql)) - { - MYSQL_RES *warn_res=0; - uint count= mysql_warning_count(mysql); - if (!mysql_real_query(mysql, "SHOW WARNINGS", 13)) - warn_res= mysql_store_result(mysql); - if (!warn_res) - die("Warning count is %u but didn't get any warnings", count); - else - { - dynstr_append_mem(ds, "Warnings:\n", 10); - append_result(ds, warn_res); - mysql_free_result(warn_res); - } - } - if (!disable_info) - { - char buf[40]; - sprintf(buf,"affected rows: %lu\n", affected_rows); - dynstr_append(ds, buf); - if (mysql_info(mysql)) - { - dynstr_append(ds, "info: "); - dynstr_append(ds, mysql_info(mysql)); - dynstr_append_mem(ds, "\n", 1); - } - } - } - - if (record) - { - if (!q->record_file[0] && !result_file) - die("Missing result file"); - if (!result_file) - str_to_file(q->record_file, ds->str, ds->length); - } - else if (q->record_file[0]) - { - error= check_result(ds, q->record_file, q->require_file); - } - if (res) - mysql_free_result(res); - last_result= 0; - counter++; - } while (!(err= mysql_next_result(mysql))); - if (err > 0) - { - /* We got an error from mysql_next_result, maybe expected */ - if (handle_error(query, q, mysql_errno(mysql), mysql_error(mysql), - mysql_sqlstate(mysql), ds)) - error= 1; - goto end; - } - - /* If we come here the query is both executed and read successfully */ - if (handle_no_error(q)) - { - error= 1; - goto end; - } - -end: - free_replace(); - last_result=0; - if (ds == &ds_tmp) - dynstr_free(&ds_tmp); - if (q->type == Q_EVAL) - dynstr_free(&eval_query); - - /* - We save the return code (mysql_errno(mysql)) from the last call sent - to the server into the mysqltest builtin variable $mysql_errno. This - variable then can be used from the test case itself. - */ - var_set_errno(mysql_errno(mysql)); - DBUG_RETURN(error); -} - - -/* - Handle errors which occurred after execution - - SYNOPSIS - handle_error() - query - query string - q - query context - err_errno - error number - err_error - error message - err_sqlstate - sql state - ds - dynamic string which is used for output buffer - - NOTE - If there is an unexpected error this function will abort mysqltest - immediately. - - RETURN VALUE - 0 - OK - 1 - Some other error was expected. -*/ - -static int handle_error(const char *query, struct st_query *q, - unsigned int err_errno, const char *err_error, - const char* err_sqlstate, DYNAMIC_STRING *ds) -{ - uint i; - - DBUG_ENTER("handle_error"); - - if (q->require_file) - abort_not_supported_test(); - - if (q->abort_on_error) - die("query '%s' failed: %d: %s", query, err_errno, err_error); - - for (i= 0 ; (uint) i < q->expected_errors ; i++) - { - if (((q->expected_errno[i].type == ERR_ERRNO) && - (q->expected_errno[i].code.errnum == err_errno)) || - ((q->expected_errno[i].type == ERR_SQLSTATE) && - (strcmp(q->expected_errno[i].code.sqlstate, err_sqlstate) == 0))) - { - if (q->expected_errors == 1) - { - /* Only log error if there is one possible error */ - dynstr_append_mem(ds, "ERROR ", 6); - replace_dynstr_append(ds, err_sqlstate); - dynstr_append_mem(ds, ": ", 2); - replace_dynstr_append(ds, err_error); - dynstr_append_mem(ds,"\n",1); - } - /* Don't log error if we may not get an error */ - else if (q->expected_errno[0].type == ERR_SQLSTATE || - (q->expected_errno[0].type == ERR_ERRNO && - q->expected_errno[0].code.errnum != 0)) - dynstr_append(ds,"Got one of the listed errors\n"); - /* OK */ - DBUG_RETURN(0); - } - } - - DBUG_PRINT("info",("i: %d expected_errors: %d", i, q->expected_errors)); - - dynstr_append_mem(ds, "ERROR ",6); - replace_dynstr_append(ds, err_sqlstate); - dynstr_append_mem(ds, ": ", 2); - replace_dynstr_append(ds, err_error); - dynstr_append_mem(ds, "\n", 1); - - if (i) - { - if (q->expected_errno[0].type == ERR_ERRNO) - die("query '%s' failed with wrong errno %d instead of %d...", - q->query, err_errno, q->expected_errno[0].code.errnum); - else - die("query '%s' failed with wrong sqlstate %s instead of %s...", - q->query, err_sqlstate, q->expected_errno[0].code.sqlstate); - DBUG_RETURN(1); - } - - /* - If we do not abort on error, failure to run the query does not fail the - whole test case. - */ - verbose_msg("query '%s' failed: %d: %s", q->query, err_errno, - err_error); - DBUG_RETURN(0); -} - - -/* - Handle absence of errors after execution - - SYNOPSIS - handle_no_error() - q - context of query - - RETURN VALUE - 0 - OK - 1 - Some error was expected from this query. -*/ - -static int handle_no_error(struct st_query *q) -{ - DBUG_ENTER("handle_no_error"); - - if (q->expected_errno[0].type == ERR_ERRNO && - q->expected_errno[0].code.errnum != 0) - { - /* Error code we wanted was != 0, i.e. not an expected success */ - die("query '%s' succeeded - should have failed with errno %d...", - q->query, q->expected_errno[0].code.errnum); - DBUG_RETURN(1); - } - else if (q->expected_errno[0].type == ERR_SQLSTATE && - strcmp(q->expected_errno[0].code.sqlstate,"00000") != 0) - { - /* SQLSTATE we wanted was != "00000", i.e. not an expected success */ - die("query '%s' succeeded - should have failed with sqlstate %s...", - q->query, q->expected_errno[0].code.sqlstate); - DBUG_RETURN(1); - } - - DBUG_RETURN(0); -} - -/****************************************************************************\ - * If --ps-protocol run ordinary statements using prepared statemnt C API -\****************************************************************************/ - -/* - We don't have a mysql_stmt_send_execute() so we only handle - complete SEND+REAP -*/ - -static int run_query_stmt(MYSQL *mysql, struct st_query *q, int flags) -{ - int error= 0; /* Function return code if "goto end;" */ - int err; /* Temporary storage of return code from calls */ - int query_len; + MYSQL_BIND *bind; + my_bool *is_null; + ulong *length; ulonglong num_rows; - char *query; - MYSQL_RES *res= NULL; /* Note that here 'res' is meta data result set */ - DYNAMIC_STRING *ds; - DYNAMIC_STRING ds_tmp; - DYNAMIC_STRING eval_query; - MYSQL_STMT *stmt; - DBUG_ENTER("run_query_stmt"); - /* - We must allocate a new stmt for each query in this program becasue this - may be a new connection. - */ - if (!(stmt= mysql_stmt_init(mysql))) - die("unable init stmt structure"); - - if (q->type != Q_EVAL) - { - query= q->query; - query_len= strlen(query); - } - else - { - init_dynamic_string(&eval_query, "", 16384, 65536); - do_eval(&eval_query, q->query); - query= eval_query.str; - query_len= eval_query.length; - } - DBUG_PRINT("query", ("'%-.60s'", query)); - - if (q->record_file[0]) - { - init_dynamic_string(&ds_tmp, "", 16384, 65536); - ds= &ds_tmp; - } - else - ds= &ds_res; - - /* Store the query into the output buffer if not disabled */ - if (!disable_query_log) - { - replace_dynstr_append_mem(ds,query, query_len); - dynstr_append_mem(ds, delimiter, delimiter_length); - dynstr_append_mem(ds, "\n", 1); - } - - /* - We use the prepared statement interface but there is actually no - '?' in the query. If unpreparable we fall back to use normal - C API. - */ - if ((err= mysql_stmt_prepare(stmt, query, query_len)) == CR_NO_PREPARE_STMT) - return run_query_normal(mysql, q, flags); - - if (err != 0) + /* FIXME we don't handle vertical display ..... */ + uint col_idx, row_idx; + + /* Allocate array with bind structs, lengths and NULL flags */ + bind= (MYSQL_BIND*) my_malloc(num_fields * sizeof(MYSQL_BIND), + MYF(MY_WME | MY_FAE | MY_ZEROFILL)); + length= (ulong*) my_malloc(num_fields * sizeof(ulong), + MYF(MY_WME | MY_FAE)); + is_null= (my_bool*) my_malloc(num_fields * sizeof(my_bool), + MYF(MY_WME | MY_FAE)); + + for (col_idx= 0; col_idx < num_fields; col_idx++) { + /* Allocate data for output */ /* - Preparing is part of normal execution and some errors may be expected + FIXME it may be a bug that for non string/blob types + 'max_length' is 0, should try out 'length' in that case */ - if (handle_error(query, q, mysql_stmt_errno(stmt), - mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt), ds)) - error= 1; - goto end; + uint max_length= max(field[col_idx].max_length + 1, 1024); + char *str_data= (char *) my_malloc(max_length, MYF(MY_WME | MY_FAE)); + + bind[col_idx].buffer_type= MYSQL_TYPE_STRING; + bind[col_idx].buffer= (char *)str_data; + bind[col_idx].buffer_length= max_length; + bind[col_idx].is_null= &is_null[col_idx]; + bind[col_idx].length= &length[col_idx]; } - - /* We may have got warnings already, collect them if any */ - if (!disable_ps_warnings) - run_query_stmt_handle_warnings(mysql, ds); - - /* - No need to call mysql_stmt_bind_param() because we have no - parameter markers. - - To optimize performance we use a global 'stmt' that is initiated - once. A new prepare will implicitely close the old one. When we - terminate we will lose the connection, this also closes the last - prepared statement. - */ - - if (mysql_stmt_execute(stmt) != 0) /* 0 == Success */ - { - /* We got an error, maybe expected */ - if (handle_error(query, q, mysql_stmt_errno(stmt), - mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt), ds)) - error= 1; - goto end; - } - - /* - We instruct that we want to update the "max_length" field in - mysql_stmt_store_result(), this is our only way to know how much - buffer to allocate for result data - */ - { - my_bool one= 1; - if ((err= mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, - (void*) &one)) != 0) - die("unable to set stmt attribute " - "'STMT_ATTR_UPDATE_MAX_LENGTH' err: %d", err); - } - - /* - If we got here the statement succeeded and was expected to do so, - get data. Note that this can still give errors found during execution! - */ - if ((err= mysql_stmt_store_result(stmt)) != 0) - { - /* We got an error, maybe expected */ - if(handle_error(query, q, mysql_stmt_errno(stmt), - mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt), ds)) - error = 1; - goto end; - } - - /* If we got here the statement was both executed and read succeesfully */ - if (handle_no_error(q)) - { - error= 1; - goto end; - } - + + /* Fill in the data into the structures created above */ + if (mysql_stmt_bind_result(stmt, bind)) + die("mysql_stmt_bind_result failed: %d: %s", + mysql_stmt_errno(stmt), mysql_stmt_error(stmt)); + + /* Read result from each row */ num_rows= mysql_stmt_num_rows(stmt); - - /* - Not all statements creates a result set. If there is one we can - now create another normal result set that contains the meta - data. This set can be handled almost like any other non prepared - statement result set. - */ - if (!disable_result_log && ((res= mysql_stmt_result_metadata(stmt)) != NULL)) + for (row_idx= 0; row_idx < num_rows; row_idx++) { - /* Take the column count from meta info */ - MYSQL_FIELD *field= mysql_fetch_fields(res); - uint num_fields= mysql_num_fields(res); - - if (display_metadata) - run_query_display_metadata(field, num_fields, ds); - + if (mysql_stmt_fetch(stmt)) + die("mysql_stmt_fetch failed: %d %s", + mysql_stmt_errno(stmt), mysql_stmt_error(stmt)); + + /* Read result from each column */ + for (col_idx= 0; col_idx < num_fields; col_idx++) + { + /* FIXME is string terminated? */ + const char *val= (const char *)bind[col_idx].buffer; + ulonglong len= *bind[col_idx].length; + if (col_idx < max_replace_column && replace_column[col_idx]) + { + val= replace_column[col_idx]; + len= strlen(val); + } + if (*bind[col_idx].is_null) + { + val= "NULL"; + len= 4; + } + if (!display_result_vertically) + { + if (col_idx) /* No tab before first col */ + dynstr_append_mem(ds, "\t", 1); + replace_dynstr_append_mem(ds, val, (int)len); + } + else + { + dynstr_append(ds, field[col_idx].name); + dynstr_append_mem(ds, "\t", 1); + replace_dynstr_append_mem(ds, val, (int)len); + dynstr_append_mem(ds, "\n", 1); + } + } if (!display_result_vertically) - { - /* Display the table heading with the names tab separated */ - uint col_idx; - for (col_idx= 0; col_idx < num_fields; col_idx++) - { - if (col_idx) - dynstr_append_mem(ds, "\t", 1); - replace_dynstr_append(ds, field[col_idx].name); - } dynstr_append_mem(ds, "\n", 1); - } - - /* Now we are to put the real result into the output buffer */ - /* FIXME when it works, create function append_stmt_result() */ - { - MYSQL_BIND *bind; - my_bool *is_null; - unsigned long *length; - /* FIXME we don't handle vertical display ..... */ - uint col_idx, row_idx; - - /* Allocate array with bind structs, lengths and NULL flags */ - bind= (MYSQL_BIND*) my_malloc(num_fields * sizeof(MYSQL_BIND), - MYF(MY_WME | MY_FAE | MY_ZEROFILL)); - length= (unsigned long*) my_malloc(num_fields * sizeof(unsigned long), - MYF(MY_WME | MY_FAE)); - is_null= (my_bool*) my_malloc(num_fields * sizeof(my_bool), - MYF(MY_WME | MY_FAE)); - - for (col_idx= 0; col_idx < num_fields; col_idx++) - { - /* Allocate data for output */ - /* - FIXME it may be a bug that for non string/blob types - 'max_length' is 0, should try out 'length' in that case - */ - uint max_length= max(field[col_idx].max_length + 1, 1024); - char *str_data= (char *) my_malloc(max_length, MYF(MY_WME | MY_FAE)); - - bind[col_idx].buffer_type= MYSQL_TYPE_STRING; - bind[col_idx].buffer= (char *)str_data; - bind[col_idx].buffer_length= max_length; - bind[col_idx].is_null= &is_null[col_idx]; - bind[col_idx].length= &length[col_idx]; - } - - /* Fill in the data into the structures created above */ - if ((err= mysql_stmt_bind_result(stmt, bind)) != 0) - die("unable to bind result to statement '%s': " - "%s (mysql_stmt_errno=%d returned=%d)", - query, - mysql_stmt_error(stmt), mysql_stmt_errno(stmt), err); - - /* Read result from each row */ - for (row_idx= 0; row_idx < num_rows; row_idx++) - { - if ((err= mysql_stmt_fetch(stmt)) != 0) - die("unable to fetch all rows from statement '%s': " - "%s (mysql_stmt_errno=%d returned=%d)", - query, - mysql_stmt_error(stmt), mysql_stmt_errno(stmt), err); - - /* Read result from each column */ - for (col_idx= 0; col_idx < num_fields; col_idx++) - { - /* FIXME is string terminated? */ - const char *val= (const char *)bind[col_idx].buffer; - ulonglong len= *bind[col_idx].length; - if (col_idx < max_replace_column && replace_column[col_idx]) - { - val= replace_column[col_idx]; - len= strlen(val); - } - if (*bind[col_idx].is_null) - { - val= "NULL"; - len= 4; - } - if (!display_result_vertically) - { - if (col_idx) /* No tab before first col */ - dynstr_append_mem(ds, "\t", 1); - replace_dynstr_append_mem(ds, val, (int)len); - } - else - { - dynstr_append(ds, field[col_idx].name); - dynstr_append_mem(ds, "\t", 1); - replace_dynstr_append_mem(ds, val, (int)len); - dynstr_append_mem(ds, "\n", 1); - } - } - if (!display_result_vertically) - dynstr_append_mem(ds, "\n", 1); - } - - if ((err= mysql_stmt_fetch(stmt)) != MYSQL_NO_DATA) - die("fetch didn't end with MYSQL_NO_DATA from statement " - "'%s': %s (mysql_stmt_errno=%d returned=%d)", - query, - mysql_stmt_error(stmt), mysql_stmt_errno(stmt), err); - - free_replace_column(); - - for (col_idx= 0; col_idx < num_fields; col_idx++) - { - /* Free data for output */ - my_free((gptr)bind[col_idx].buffer, MYF(MY_WME | MY_FAE)); - } - /* Free array with bind structs, lengths and NULL flags */ - my_free((gptr)bind , MYF(MY_WME | MY_FAE)); - my_free((gptr)length , MYF(MY_WME | MY_FAE)); - my_free((gptr)is_null , MYF(MY_WME | MY_FAE)); - } - - /* Add all warnings to the result */ - run_query_stmt_handle_warnings(mysql, ds); - - if (!disable_info) - { - char buf[40]; - sprintf(buf,"affected rows: %lu\n",(ulong) mysql_affected_rows(mysql)); - dynstr_append(ds, buf); - if (mysql_info(mysql)) - { - dynstr_append(ds, "info: "); - dynstr_append(ds, mysql_info(mysql)); - dynstr_append_mem(ds, "\n", 1); - } - } } - run_query_stmt_handle_warnings(mysql, ds); - - if (record) + + if (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) + die("fetch didn't end with MYSQL_NO_DATA from statement: %d %s", + mysql_stmt_error(stmt), mysql_stmt_errno(stmt)); + + free_replace_column(); + + for (col_idx= 0; col_idx < num_fields; col_idx++) { - if (!q->record_file[0] && !result_file) - die("Missing result file"); - if (!result_file) - str_to_file(q->record_file, ds->str, ds->length); + /* Free data for output */ + my_free((gptr)bind[col_idx].buffer, MYF(MY_WME | MY_FAE)); } - else if (q->record_file[0]) - { - error= check_result(ds, q->record_file, q->require_file); - } - if (res) - mysql_free_result(res); /* Free normal result set with meta data */ - last_result= 0; /* FIXME have no idea what this is about... */ - -end: - free_replace(); - last_result=0; - if (ds == &ds_tmp) - dynstr_free(&ds_tmp); - if (q->type == Q_EVAL) - dynstr_free(&eval_query); - var_set_errno(mysql_stmt_errno(stmt)); - mysql_stmt_close(stmt); - DBUG_RETURN(error); + /* Free array with bind structs, lengths and NULL flags */ + my_free((gptr)bind , MYF(MY_WME | MY_FAE)); + my_free((gptr)length , MYF(MY_WME | MY_FAE)); + my_free((gptr)is_null , MYF(MY_WME | MY_FAE)); } -/****************************************************************************\ - * Broken out sub functions to run_query_stmt() -\****************************************************************************/ +/* + Append metadata for fields to output +*/ -static void run_query_display_metadata(MYSQL_FIELD *field, uint num_fields, - DYNAMIC_STRING *ds) +static void append_metadata(DYNAMIC_STRING *ds, + MYSQL_FIELD *field, + uint num_fields) { MYSQL_FIELD *field_end; dynstr_append(ds,"Catalog\tDatabase\tTable\tTable_alias\tColumn\t" @@ -3676,39 +3085,564 @@ static void run_query_display_metadata(MYSQL_FIELD *field, uint num_fields, } } +/* + Append affected row count and other info to output +*/ -static void run_query_stmt_handle_warnings(MYSQL *mysql, DYNAMIC_STRING *ds) +static void append_info(DYNAMIC_STRING* ds, ulong affected_rows, + const char* info) +{ + char buf[40]; + sprintf(buf,"affected rows: %lu\n", affected_rows); + dynstr_append(ds, buf); + if (info) + { + dynstr_append(ds, "info: "); + dynstr_append(ds, info); + dynstr_append_mem(ds, "\n", 1); + } +} + + +/* + Display the table headings with the names tab separated +*/ +static void append_table_headings(DYNAMIC_STRING* ds, + MYSQL_FIELD* field, + uint num_fields) +{ + uint col_idx; + for (col_idx= 0; col_idx < num_fields; col_idx++) + { + if (col_idx) + dynstr_append_mem(ds, "\t", 1); + replace_dynstr_append(ds, field[col_idx].name); + } + dynstr_append_mem(ds, "\n", 1); +} + +/* + Fetch warnings from server and append to output +*/ + +static void append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql) { uint count; - DBUG_ENTER("run_query_stmt_handle_warnings"); + DBUG_ENTER("append_warnings"); - if (!disable_warnings && (count= mysql_warning_count(mysql))) + if (!(count= mysql_warning_count(mysql))) + DBUG_VOID_RETURN; + + /* + If one day we will support execution of multi-statements + through PS API we should not issue SHOW WARNINGS until + we have not read all results... + */ + DBUG_ASSERT(!mysql_more_results(mysql)); + + if (mysql_real_query(mysql, "SHOW WARNINGS", 13)) + die("Error running query \"SHOW WARNINGS\": %s", mysql_error(mysql)); + + MYSQL_RES *warn_res= mysql_store_result(mysql); + if (!warn_res) + die("Warning count is %u but didn't get any warnings", + count); + + + dynstr_append_mem(ds, "Warnings:\n", 10); + append_result(ds, warn_res); + mysql_free_result(warn_res); + + DBUG_VOID_RETURN; +} + + +/* + Run query using MySQL C API + + SYNPOSIS + run_query_normal + mysql - mysql handle + command - currrent command pointer + query - query string to execute + query_len - length query string to execute + ds - output buffer wherte to store result form query + + RETURN VALUE + error - function will not return +*/ + +static void run_query_normal(MYSQL *mysql, struct st_query *command, + int flags, char *query, int query_len, + DYNAMIC_STRING *ds) +{ + MYSQL_RES *res= 0; + int err= 0, counter= 0; + DBUG_ENTER("run_query_normal"); + DBUG_PRINT("enter",("flags: %d", flags)); + DBUG_PRINT("enter", ("query: '%-.60s'", query)); + + if (flags & QUERY_SEND) { - /* - If one day we will support execution of multi-statements - through PS API we should not issue SHOW WARNINGS until - we have not read all results... - */ - DBUG_ASSERT(!mysql_more_results(mysql)); - - if (mysql_real_query(mysql, "SHOW WARNINGS", 13) == 0) + /* + Send the query, using the undocumented function mysql_send_query + */ + if (mysql_send_query(mysql, query, query_len)) { - MYSQL_RES *warn_res= mysql_store_result(mysql); - if (!warn_res) - die("Warning count is %u but didn't get any warnings", - count); - else - { - dynstr_append_mem(ds, "Warnings:\n", 10); - append_result(ds, warn_res); - mysql_free_result(warn_res); - } + handle_error(query, command, mysql_errno(mysql), mysql_error(mysql), + mysql_sqlstate(mysql), ds); + goto end; } } + + if (!(flags & QUERY_REAP)) + DBUG_VOID_RETURN; + + do + { + /* + When on first result set, call mysql_read_query_result to retrrieve + answer to the query sent earlier + */ + if ((counter==0) && mysql_read_query_result(mysql)) + { + handle_error(query, command, mysql_errno(mysql), mysql_error(mysql), + mysql_sqlstate(mysql), ds); + goto end; + + } + + /* + Store the result. If res is NULL, use mysql_field_count to + determine if that was expected + */ + if (!(res= mysql_store_result(mysql)) && mysql_field_count(mysql)) + { + handle_error(query, command, mysql_errno(mysql), mysql_error(mysql), + mysql_sqlstate(mysql), ds); + goto end; + } + + if (!disable_result_log) + { + ulong affected_rows; /* Ok to be undef if 'disable_info' is set */ + LINT_INIT(affected_rows); + + if (res) + { + MYSQL_FIELD *fields= mysql_fetch_fields(res); + uint num_fields= mysql_num_fields(res); + + if (display_metadata) + append_metadata(ds, fields, num_fields); + + if (!display_result_vertically) + append_table_headings(ds, fields, num_fields); + + append_result(ds, res); + } + + /* + Need to call mysql_affected_rows() before the "new" + query to find the warnings + */ + if (!disable_info) + affected_rows= (ulong)mysql_affected_rows(mysql); + + /* + Add all warnings to the result. We can't do this if we are in + the middle of processing results from multi-statement, because + this will break protocol. + */ + if (!disable_warnings && !mysql_more_results(mysql)) + append_warnings(ds, mysql); + + if (!disable_info) + append_info(ds, affected_rows, mysql_info(mysql)); + } + + if (res) + mysql_free_result(res); + counter++; + } while (!(err= mysql_next_result(mysql))); + if (err > 0) + { + /* We got an error from mysql_next_result, maybe expected */ + handle_error(query, command, mysql_errno(mysql), mysql_error(mysql), + mysql_sqlstate(mysql), ds); + goto end; + } + DBUG_ASSERT(err == -1); /* Successful and there are no more results */ + + /* If we come here the query is both executed and read successfully */ + handle_no_error(command); + +end: + free_replace(); + + /* + We save the return code (mysql_errno(mysql)) from the last call sent + to the server into the mysqltest builtin variable $mysql_errno. This + variable then can be used from the test case itself. + */ + var_set_errno(mysql_errno(mysql)); DBUG_VOID_RETURN; } +/* + Handle errors which occurred during execution + + SYNOPSIS + handle_error() + query - query string + q - query context + err_errno - error number + err_error - error message + err_sqlstate - sql state + ds - dynamic string which is used for output buffer + + NOTE + If there is an unexpected error this function will abort mysqltest + immediately. + + RETURN VALUE + error - function will not return +*/ + +static void handle_error(const char *query, struct st_query *q, + unsigned int err_errno, const char *err_error, + const char *err_sqlstate, DYNAMIC_STRING *ds) +{ + uint i; + + DBUG_ENTER("handle_error"); + + if (q->require_file) + abort_not_supported_test(); + + if (q->abort_on_error) + die("query '%s' failed: %d: %s", query, err_errno, err_error); + + for (i= 0 ; (uint) i < q->expected_errors ; i++) + { + if (((q->expected_errno[i].type == ERR_ERRNO) && + (q->expected_errno[i].code.errnum == err_errno)) || + ((q->expected_errno[i].type == ERR_SQLSTATE) && + (strcmp(q->expected_errno[i].code.sqlstate, err_sqlstate) == 0))) + { + if (q->expected_errors == 1) + { + /* Only log error if there is one possible error */ + dynstr_append_mem(ds, "ERROR ", 6); + replace_dynstr_append(ds, err_sqlstate); + dynstr_append_mem(ds, ": ", 2); + replace_dynstr_append(ds, err_error); + dynstr_append_mem(ds,"\n",1); + } + /* Don't log error if we may not get an error */ + else if (q->expected_errno[0].type == ERR_SQLSTATE || + (q->expected_errno[0].type == ERR_ERRNO && + q->expected_errno[0].code.errnum != 0)) + dynstr_append(ds,"Got one of the listed errors\n"); + /* OK */ + DBUG_VOID_RETURN; + } + } + + DBUG_PRINT("info",("i: %d expected_errors: %d", i, q->expected_errors)); + + dynstr_append_mem(ds, "ERROR ",6); + replace_dynstr_append(ds, err_sqlstate); + dynstr_append_mem(ds, ": ", 2); + replace_dynstr_append(ds, err_error); + dynstr_append_mem(ds, "\n", 1); + + if (i) + { + if (q->expected_errno[0].type == ERR_ERRNO) + die("query '%s' failed with wrong errno %d instead of %d...", + q->query, err_errno, q->expected_errno[0].code.errnum); + else + die("query '%s' failed with wrong sqlstate %s instead of %s...", + q->query, err_sqlstate, q->expected_errno[0].code.sqlstate); + } + + /* + If we do not abort on error, failure to run the query does not fail the + whole test case. + */ + verbose_msg("query '%s' failed: %d: %s", q->query, err_errno, + err_error); + DBUG_VOID_RETURN; +} + + +/* + Handle absence of errors after execution + + SYNOPSIS + handle_no_error() + q - context of query + + RETURN VALUE + error - function will not return +*/ + +static void handle_no_error(struct st_query *q) +{ + DBUG_ENTER("handle_no_error"); + + if (q->expected_errno[0].type == ERR_ERRNO && + q->expected_errno[0].code.errnum != 0) + { + /* Error code we wanted was != 0, i.e. not an expected success */ + die("query '%s' succeeded - should have failed with errno %d...", + q->query, q->expected_errno[0].code.errnum); + } + else if (q->expected_errno[0].type == ERR_SQLSTATE && + strcmp(q->expected_errno[0].code.sqlstate,"00000") != 0) + { + /* SQLSTATE we wanted was != "00000", i.e. not an expected success */ + die("query '%s' succeeded - should have failed with sqlstate %s...", + q->query, q->expected_errno[0].code.sqlstate); + } + + DBUG_VOID_RETURN; +} + + +/* + Run query using prepared statement C API + + SYNPOSIS + run_query_stmt + mysql - mysql handle + command - currrent command pointer + query - query string to execute + query_len - length query string to execute + ds - output buffer wherte to store result form query + + RETURN VALUE + error - function will not return +*/ + +static void run_query_stmt(MYSQL *mysql, struct st_query *command, + char *query, int query_len, DYNAMIC_STRING *ds) +{ + MYSQL_RES *res= NULL; /* Note that here 'res' is meta data result set */ + MYSQL_STMT *stmt; + DBUG_ENTER("run_query_stmt"); + DBUG_PRINT("query", ("'%-.60s'", query)); + + /* + We must allocate a new stmt for each query in this program because this + may be a new connection. + + Well, it could be stored togeter with mysql pointer in cur_con struct + */ + if (!(stmt= mysql_stmt_init(mysql))) + die("unable to init stmt structure"); + + /* + Prepare the query + */ + if (mysql_stmt_prepare(stmt, query, query_len)) + { + handle_error(query, command, mysql_stmt_errno(stmt), + mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt), ds); + goto end; + } + + /* + No need to call mysql_stmt_bind_param() because we have no + parameter markers. + */ + + /* + Execute the query + */ + if (mysql_stmt_execute(stmt)) + { + handle_error(query, command, mysql_stmt_errno(stmt), + mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt), ds); + goto end; + } + + /* + We instruct that we want to update the "max_length" field in + mysql_stmt_store_result(), this is our only way to know how much + buffer to allocate for result data + */ + { + my_bool one= 1; + if (mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (void*) &one)) + die("mysql_stmt_attr_set failed': %d %s", + mysql_stmt_errno(stmt), mysql_stmt_error(stmt)); + } + + /* + If we got here the statement succeeded and was expected to do so, + get data. Note that this can still give errors found during execution! + */ + if (mysql_stmt_store_result(stmt)) + { + handle_error(query, command, mysql_stmt_errno(stmt), + mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt), ds); + goto end; + } + + /* If we got here the statement was both executed and read succeesfully */ + handle_no_error(command); + + /* + Not all statements creates a result set. If there is one we can + now create another normal result set that contains the meta + data. This set can be handled almost like any other non prepared + statement result set. + */ + if (!disable_result_log) + { + if ((res= mysql_stmt_result_metadata(stmt)) != NULL) + { + /* Take the column count from meta info */ + MYSQL_FIELD *fields= mysql_fetch_fields(res); + uint num_fields= mysql_num_fields(res); + + if (display_metadata) + append_metadata(ds, fields, num_fields); + + if (!display_result_vertically) + append_table_headings(ds, fields, num_fields); + + append_stmt_result(ds, stmt, fields, num_fields); + + mysql_free_result(res); /* Free normal result set with meta data */ + + } + + if (!disable_warnings) + append_warnings(ds, mysql); + + if (!disable_info) + append_info(ds, (ulong)mysql_affected_rows(mysql), mysql_info(mysql)); + } + +end: + free_replace(); + /* + We save the return code (mysql_stmt_errno(stmt)) from the last call sent + to the server into the mysqltest builtin variable $mysql_errno. This + variable then can be used from the test case itself. + */ + var_set_errno(mysql_stmt_errno(stmt)); + mysql_stmt_close(stmt); + DBUG_VOID_RETURN; +} + + +/* + + Run query + + flags control the phased/stages of query execution to be performed + if QUERY_SEND bit is on, the query will be sent. If QUERY_REAP is on + the result will be read - for regular query, both bits must be on + + SYNPOSIS + run_query + mysql - mysql handle + command - currrent command pointer + +*/ + +static void run_query(MYSQL *mysql, struct st_query *command, int flags) +{ + DYNAMIC_STRING *ds; + DYNAMIC_STRING ds_tmp; + DYNAMIC_STRING eval_query; + char *query; + int query_len; + + /* + Evaluate query if this is an eval command + */ + if (command->type == Q_EVAL) + { + init_dynamic_string(&eval_query, "", 16384, 65536); + do_eval(&eval_query, command->query); + query = eval_query.str; + query_len = eval_query.length; + } + else + { + query = command->query; + query_len = strlen(query); + } + + /* + When command->record_file is set the output of _this_ query + should be compared with an already existing file + Create a temporary dynamic string to contain the output from + this query. + */ + if (command->record_file[0]) + { + init_dynamic_string(&ds_tmp, "", 16384, 65536); + ds= &ds_tmp; + } + else + ds= &ds_res; + + /* Store the query into the output buffer */ + if (!disable_query_log && (flags & QUERY_SEND)) + { + replace_dynstr_append_mem(ds,query, query_len); + dynstr_append_mem(ds, delimiter, delimiter_length); + dynstr_append_mem(ds, "\n", 1); + } + + /* + Find out how to run this query + + We don't have a mysql_stmt_send_execute() so it must be a + complete SEND+REAP to use prepared statement + + If it is a '?' in the query it may be a SQL level prepared + statement already and we can't do it twice + */ + if (ps_protocol_enabled && + (flags & QUERY_SEND) && (flags & QUERY_REAP) && + ps_match_re(query)) + run_query_stmt(mysql, command, query, query_len, ds); + else + run_query_normal(mysql, command, flags, query, query_len, ds); + + if (record) + { + /* Recording in progress */ + if (!command->record_file[0]) + die("Missing result file"); + + /* Dump the output from _this_ query to the specified record_file */ + str_to_file(command->record_file, ds->str, ds->length); + } + else if (command->record_file[0]) + { + /* + The output from _this_ query should be checked against an already + existing file which has been specified using --require or --result + */ + check_result(ds, command->record_file, command->require_file); + } + + if (ds == &ds_tmp) + dynstr_free(&ds_tmp); + if (command->type == Q_EVAL) + dynstr_free(&eval_query); +} + + /****************************************************************************\ * Functions to match SQL statements that can be prepared \****************************************************************************/ @@ -3911,7 +3845,6 @@ static void init_var_hash(MYSQL *mysql) int main(int argc, char **argv) { - int error = 0; struct st_query *q; my_bool require_file=0, q_send_flag=0, abort_flag= 0, query_executed= 0; @@ -4005,7 +3938,7 @@ int main(int argc, char **argv) processed = 1; switch (q->type) { case Q_CONNECT: - error|= do_connect(q); + do_connect(q); break; case Q_CONNECTION: select_connection(q); break; case Q_DISCONNECT: @@ -4039,7 +3972,7 @@ int main(int argc, char **argv) #endif case Q_INC: do_modify_var(q, "inc", DO_INC); break; case Q_DEC: do_modify_var(q, "dec", DO_DEC); break; - case Q_ECHO: do_echo(q); break; + case Q_ECHO: do_echo(q); query_executed= 1; break; case Q_SYSTEM: do_system(q); break; case Q_DELIMITER: strmake(delimiter, q->first_argument, sizeof(delimiter) - 1); @@ -4066,15 +3999,6 @@ int main(int argc, char **argv) case Q_QUERY_HORIZONTAL: { my_bool old_display_result_vertically= display_result_vertically; - if (!q->query[q->first_word_len]) - { - /* This happens when we use 'query_..' on it's own line */ - q_send_flag=1; - DBUG_PRINT("info", - ("query: '%s' first_word_len: %d send_flag=1", - q->query, q->first_word_len)); - break; - } /* fix up query pointer if this is * first iteration for this line */ if (q->query == q->query_buf) q->query += q->first_word_len + 1; @@ -4085,7 +4009,7 @@ int main(int argc, char **argv) q->require_file=require_file; save_file[0]=0; } - error|= run_query(&cur_con->mysql, q, QUERY_REAP|QUERY_SEND); + run_query(&cur_con->mysql, q, QUERY_REAP|QUERY_SEND); display_result_vertically= old_display_result_vertically; q->last_argument= q->end; query_executed= 1; @@ -4112,7 +4036,7 @@ int main(int argc, char **argv) q->require_file=require_file; save_file[0]=0; } - error |= run_query(&cur_con->mysql, q, flags); + run_query(&cur_con->mysql, q, flags); query_executed= 1; q->last_argument= q->end; break; @@ -4133,7 +4057,7 @@ int main(int argc, char **argv) query and read the result some time later when reap instruction is given on this connection. */ - error |= run_query(&cur_con->mysql, q, QUERY_SEND); + run_query(&cur_con->mysql, q, QUERY_SEND); query_executed= 1; q->last_argument= q->end; break; @@ -4255,6 +4179,12 @@ int main(int argc, char **argv) parser.current_line += current_line_inc; } + /* + The whole test has been executed sucessfully + Time to compare result or save it to record file + The entire output from test is now kept in ds_res + */ + if (!query_executed && result_file && my_stat(result_file, &res_info, 0)) { /* @@ -4265,39 +4195,46 @@ int main(int argc, char **argv) no query output from the test file, e.g. regarded as no error. */ if (res_info.st_size) - error|= (RESULT_CONTENT_MISMATCH | RESULT_LENGTH_MISMATCH); + die("No queries executed but result file found!"); } - if (ds_res.length && !error) + + if (ds_res.length) { if (result_file) { - if (!record) - error |= check_result(&ds_res, result_file, q->require_file); + if (record) + { + /* Dump the output from test to result file */ + str_to_file(result_file, ds_res.str, ds_res.length); + } else - str_to_file(result_file, ds_res.str, ds_res.length); + { + /* Check that the output from test is equal to result file */ + check_result(&ds_res, result_file, 0); + } } else { - /* Print the result to stdout */ + /* No result_file to compare with, print the result to stdout */ printf("%s", ds_res.str); } + } + else + { + /* The test didn't produce any output */ } dynstr_free(&ds_res); - if (!silent) - { - if (error) - printf("not ok\n"); - else - printf("ok\n"); - } - if (!got_end_timer) timer_output(); /* No end_timer cmd, end it */ free_used_memory(); my_end(MY_CHECK_ERROR); - exit(error ? 1 : 0); - return error ? 1 : 0; /* Keep compiler happy */ + + /* Yes, if we got this far the test has suceeded! Sakila smiles */ + if (!silent) + printf("ok\n"); + exit(0); + return 0; /* Keep compiler happy */ } @@ -5094,12 +5031,6 @@ static int initialize_replace_buffer(void) return 0; } -static void free_replace_buffer(void) -{ - my_free(out_buff,MYF(MY_WME)); -} - - /**************************************************************************** Replace results for a column *****************************************************************************/ diff --git a/mysql-test/include/master-slave.inc b/mysql-test/include/master-slave.inc index 5ec4b4379f8..ea09f4e842b 100644 --- a/mysql-test/include/master-slave.inc +++ b/mysql-test/include/master-slave.inc @@ -8,7 +8,8 @@ connection slave; --disable_warnings stop slave; --enable_warnings -@r/slave-stopped.result show status like 'Slave_running'; +--require r/slave-stopped.result +show status like 'Slave_running'; connection master; --disable_warnings drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; @@ -21,7 +22,8 @@ reset slave; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; --enable_warnings start slave; -@r/slave-running.result show status like 'Slave_running'; +--require r/slave-running.result +show status like 'Slave_running'; # Set the default connection to 'master' connection master; diff --git a/mysql-test/include/ps_query.inc b/mysql-test/include/ps_query.inc index 27a86f88231..e96d666eaec 100644 --- a/mysql-test/include/ps_query.inc +++ b/mysql-test/include/ps_query.inc @@ -52,7 +52,6 @@ execute stmt1; ##### parameter used for keyword like SELECT (must fail) set @arg00='SELECT' ; -# mysqltest gives no output for the next statement, Why ?? --error 1064 @arg00 a from t1 where a=1; --error 1064 diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index 0ad6db8c57e..abcf4d049ed 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -149,6 +149,9 @@ hello mysqltest: At line 1: End of line junk detected: "6" mysqltest: At line 1: End of line junk detected: "6" mysqltest: At line 1: Missing delimiter +mysqltest: End of line junk detected: "sleep 7 +# Another comment +" mysqltest: At line 1: Extra delimiter ";" found mysqltest: At line 1: Extra delimiter ";" found MySQL diff --git a/mysql-test/r/ps_2myisam.result b/mysql-test/r/ps_2myisam.result index c839c8a65b9..603de2afe4e 100644 --- a/mysql-test/r/ps_2myisam.result +++ b/mysql-test/r/ps_2myisam.result @@ -85,6 +85,8 @@ c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c 1 1 1 1 1 1 1 1 1 1 1.0000 1.0000 2004-02-29 2004-02-29 11:11:11 2004-02-29 11:11:11 11:11:11 2004 1 1 a 123456789a 123456789a123456789b123456789c tinyblob tinytext blob text mediumblob mediumtext longblob longtext one monday 9 9 9 9 9 9 9 9 9 9 9.0000 9.0000 2004-02-29 2004-02-29 11:11:11 2004-02-29 11:11:11 11:11:11 2004 1 0 a 123456789a 123456789a123456789b123456789c tinyblob tinytext blob text mediumblob mediumtext longblob longtext two tuesday set @arg00='SELECT' ; +@arg00 a from t1 where a=1; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@arg00 a from t1 where a=1' at line 1 prepare stmt1 from ' ? a from t1 where a=1 '; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? a from t1 where a=1' at line 1 set @arg00=1 ; diff --git a/mysql-test/r/ps_3innodb.result b/mysql-test/r/ps_3innodb.result index 81d6180e41f..9e635f60f14 100644 --- a/mysql-test/r/ps_3innodb.result +++ b/mysql-test/r/ps_3innodb.result @@ -85,6 +85,8 @@ c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c 1 1 1 1 1 1 1 1 1 1 1.0000 1.0000 2004-02-29 2004-02-29 11:11:11 2004-02-29 11:11:11 11:11:11 2004 1 1 a 123456789a 123456789a123456789b123456789c tinyblob tinytext blob text mediumblob mediumtext longblob longtext one monday 9 9 9 9 9 9 9 9 9 9 9.0000 9.0000 2004-02-29 2004-02-29 11:11:11 2004-02-29 11:11:11 11:11:11 2004 1 0 a 123456789a 123456789a123456789b123456789c tinyblob tinytext blob text mediumblob mediumtext longblob longtext two tuesday set @arg00='SELECT' ; +@arg00 a from t1 where a=1; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@arg00 a from t1 where a=1' at line 1 prepare stmt1 from ' ? a from t1 where a=1 '; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? a from t1 where a=1' at line 1 set @arg00=1 ; diff --git a/mysql-test/r/ps_4heap.result b/mysql-test/r/ps_4heap.result index 931e6b7c86c..fd51c71cad6 100644 --- a/mysql-test/r/ps_4heap.result +++ b/mysql-test/r/ps_4heap.result @@ -86,6 +86,8 @@ c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c 1 1 1 1 1 1 1 1 1 1 1.0000 1.0000 2004-02-29 2004-02-29 11:11:11 2004-02-29 11:11:11 11:11:11 2004 1 1 a 123456789a 123456789a123456789b123456789c tinyblob tinytext blob text mediumblob mediumtext longblob longtext one monday 9 9 9 9 9 9 9 9 9 9 9.0000 9.0000 2004-02-29 2004-02-29 11:11:11 2004-02-29 11:11:11 11:11:11 2004 1 0 a 123456789a 123456789a123456789b123456789c tinyblob tinytext blob text mediumblob mediumtext longblob longtext two tuesday set @arg00='SELECT' ; +@arg00 a from t1 where a=1; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@arg00 a from t1 where a=1' at line 1 prepare stmt1 from ' ? a from t1 where a=1 '; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? a from t1 where a=1' at line 1 set @arg00=1 ; diff --git a/mysql-test/r/ps_5merge.result b/mysql-test/r/ps_5merge.result index 3b9244c251f..876f7615672 100644 --- a/mysql-test/r/ps_5merge.result +++ b/mysql-test/r/ps_5merge.result @@ -128,6 +128,8 @@ c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c 1 1 1 1 1 1 1 1 1 1 1.0000 1.0000 2004-02-29 2004-02-29 11:11:11 2004-02-29 11:11:11 11:11:11 2004 1 1 a 123456789a 123456789a123456789b123456789c tinyblob tinytext blob text mediumblob mediumtext longblob longtext one monday 9 9 9 9 9 9 9 9 9 9 9.0000 9.0000 2004-02-29 2004-02-29 11:11:11 2004-02-29 11:11:11 11:11:11 2004 1 0 a 123456789a 123456789a123456789b123456789c tinyblob tinytext blob text mediumblob mediumtext longblob longtext two tuesday set @arg00='SELECT' ; +@arg00 a from t1 where a=1; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@arg00 a from t1 where a=1' at line 1 prepare stmt1 from ' ? a from t1 where a=1 '; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? a from t1 where a=1' at line 1 set @arg00=1 ; @@ -3140,6 +3142,8 @@ c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c 1 1 1 1 1 1 1 1 1 1 1.0000 1.0000 2004-02-29 2004-02-29 11:11:11 2004-02-29 11:11:11 11:11:11 2004 1 1 a 123456789a 123456789a123456789b123456789c tinyblob tinytext blob text mediumblob mediumtext longblob longtext one monday 9 9 9 9 9 9 9 9 9 9 9.0000 9.0000 2004-02-29 2004-02-29 11:11:11 2004-02-29 11:11:11 11:11:11 2004 1 0 a 123456789a 123456789a123456789b123456789c tinyblob tinytext blob text mediumblob mediumtext longblob longtext two tuesday set @arg00='SELECT' ; +@arg00 a from t1 where a=1; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@arg00 a from t1 where a=1' at line 1 prepare stmt1 from ' ? a from t1 where a=1 '; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? a from t1 where a=1' at line 1 set @arg00=1 ; diff --git a/mysql-test/r/ps_6bdb.result b/mysql-test/r/ps_6bdb.result index 643e12f7e2d..c39621d184f 100644 --- a/mysql-test/r/ps_6bdb.result +++ b/mysql-test/r/ps_6bdb.result @@ -85,6 +85,8 @@ c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c 1 1 1 1 1 1 1 1 1 1 1.0000 1.0000 2004-02-29 2004-02-29 11:11:11 2004-02-29 11:11:11 11:11:11 2004 1 1 a 123456789a 123456789a123456789b123456789c tinyblob tinytext blob text mediumblob mediumtext longblob longtext one monday 9 9 9 9 9 9 9 9 9 9 9.0000 9.0000 2004-02-29 2004-02-29 11:11:11 2004-02-29 11:11:11 11:11:11 2004 1 0 a 123456789a 123456789a123456789b123456789c tinyblob tinytext blob text mediumblob mediumtext longblob longtext two tuesday set @arg00='SELECT' ; +@arg00 a from t1 where a=1; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@arg00 a from t1 where a=1' at line 1 prepare stmt1 from ' ? a from t1 where a=1 '; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? a from t1 where a=1' at line 1 set @arg00=1 ; diff --git a/mysql-test/r/ps_7ndb.result b/mysql-test/r/ps_7ndb.result index 9fbe67f581b..7c83099311e 100644 --- a/mysql-test/r/ps_7ndb.result +++ b/mysql-test/r/ps_7ndb.result @@ -85,6 +85,8 @@ c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c 1 1 1 1 1 1 1 1 1 1 1.0000 1.0000 2004-02-29 2004-02-29 11:11:11 2004-02-29 11:11:11 11:11:11 2004 1 1 a 123456789a 123456789a123456789b123456789c tinyblob tinytext blob text mediumblob mediumtext longblob longtext one monday 9 9 9 9 9 9 9 9 9 9 9.0000 9.0000 2004-02-29 2004-02-29 11:11:11 2004-02-29 11:11:11 11:11:11 2004 1 0 a 123456789a 123456789a123456789b123456789c tinyblob tinytext blob text mediumblob mediumtext longblob longtext two tuesday set @arg00='SELECT' ; +@arg00 a from t1 where a=1; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@arg00 a from t1 where a=1' at line 1 prepare stmt1 from ' ? a from t1 where a=1 '; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? a from t1 where a=1' at line 1 set @arg00=1 ; diff --git a/mysql-test/t/alias.test b/mysql-test/t/alias.test index 2746409c7e5..6546581eef2 100644 --- a/mysql-test/t/alias.test +++ b/mysql-test/t/alias.test @@ -61,9 +61,7 @@ INSERT INTO t1 VALUES (3359361,406,3359361,'Mustermann Musterfrau',7001,'2000-05 INSERT INTO t1 VALUES (3359362,406,3359362,'Mustermann Musterfrau',7001,'2000-05-20','workflow','Auftrag erledigt','Originalvertrag eingegangen und geprüft','','privat',1509984,2145874,'+','','P',1909154,'MobilComSuper92000D1(Akquise)',NULL,NULL,'MS9ND1',327,24,'MobilCom Intern',7003,NULL,'auto',20010202105916,'Mobilfunk','PP','','',''); # This died because we used the field Kundentyp twice ---disable_ps_protocol SELECT ELT(FIELD(kundentyp,'PP','PPA','PG','PGA','FK','FKA','FP','FPA','K','KA','V','VA',''), 'Privat (Private Nutzung)','Privat (Private Nutzung) Sitz im Ausland','Privat (geschaeftliche Nutzung)','Privat (geschaeftliche Nutzung) Sitz im Ausland','Firma (Kapitalgesellschaft)','Firma (Kapitalgesellschaft) Sitz im Ausland','Firma (Personengesellschaft)','Firma (Personengesellschaft) Sitz im Ausland','oeff. rechtl. Koerperschaft','oeff. rechtl. Koerperschaft Sitz im Ausland','Eingetragener Verein','Eingetragener Verein Sitz im Ausland','Typ unbekannt') AS Kundentyp ,kategorie FROM t1 WHERE hdl_nr < 2000000 AND kategorie IN ('Prepaid','Mobilfunk') AND st_klasse = 'Workflow' GROUP BY kundentyp ORDER BY kategorie; ---enable_ps_protocol drop table t1; diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test index bf557029a55..fb9835c5d7f 100644 --- a/mysql-test/t/group_by.test +++ b/mysql-test/t/group_by.test @@ -596,9 +596,7 @@ drop table t1; CREATE TABLE t1 (n int); INSERT INTO t1 VALUES (1); ---disable_ps_protocol SELECT n+1 AS n FROM t1 GROUP BY n; ---enable_ps_protocol DROP TABLE t1; # @@ -623,11 +621,9 @@ insert into t1 values ('aaa', 'bb1'), ('aaa', 'bb2'); insert into t2 values ('aaa', 'bb1'), ('aaa', 'bb2'); # query with ambiguous column reference 'c2' ---disable_ps_protocol select t1.c1 as c2 from t1, t2 where t1.c2 = t2.c4 group by c2; show warnings; ---enable_ps_protocol # this query has no ambiguity select t1.c1 as c2 from t1, t2 where t1.c2 = t2.c4 diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index 11fbb023963..a1f7e8b4251 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -364,6 +364,15 @@ select 3 from t1 ; --error 1 --exec $MYSQL_TEST < var/log/mysqltest.sql 2>&1 +# +# Missing delimiter until eof +# The comment will be "sucked into" the sleep command since +# delimiter is missing +--system echo "sleep 7" > var/log/mysqltest.sql +--system echo "# Another comment" >> var/log/mysqltest.sql +--error 1 +--exec $MYSQL_TEST < var/log/mysqltest.sql 2>&1 + # # Extra delimiter # diff --git a/mysql-test/t/union.test b/mysql-test/t/union.test index daa83ef0fa4..a30321470ea 100644 --- a/mysql-test/t/union.test +++ b/mysql-test/t/union.test @@ -27,12 +27,9 @@ select 't1',b,count(*) from t1 group by b UNION select 't2',b,count(*) from t2 g (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by t1.b; explain extended (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc; (select sql_calc_found_rows a,b from t1 limit 2) union all (select a,b from t2 order by a) limit 2; -# PS doesn't work correctly with found_rows: to be fixed ---disable_ps_protocol select found_rows(); select sql_calc_found_rows a,b from t1 union all select a,b from t2 limit 2; select found_rows(); ---enable_ps_protocol # # Test some error conditions with UNION @@ -210,27 +207,15 @@ insert into t2 values (3),(4),(5); # Test global limits (SELECT SQL_CALC_FOUND_ROWS * FROM t1) UNION all (SELECT * FROM t2) LIMIT 1; -# PS doesn't work correctly with found_rows: to be fixed ---disable_ps_protocol select found_rows(); ---enable_ps_protocol (SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1) UNION all (SELECT * FROM t2) LIMIT 2; -# PS doesn't work correctly with found_rows: to be fixed ---disable_ps_protocol select found_rows(); ---enable_ps_protocol # Test cases where found_rows() should return number of returned rows (SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1) UNION all (SELECT * FROM t2); -# PS doesn't work correctly with found_rows: to be fixed ---disable_ps_protocol select found_rows(); ---enable_ps_protocol (SELECT SQL_CALC_FOUND_ROWS * FROM t1) UNION all (SELECT * FROM t2 LIMIT 1); -# PS doesn't work correctly with found_rows: to be fixed ---disable_ps_protocol select found_rows(); ---enable_ps_protocol # This used to work in 4.0 but not anymore in 4.1 --error 1064 (SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1) UNION SELECT * FROM t2 LIMIT 1; @@ -238,15 +223,9 @@ select found_rows(); # In these case found_rows() should work SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1 UNION all SELECT * FROM t2 LIMIT 2; -# PS doesn't work correctly with found_rows: to be fixed ---disable_ps_protocol select found_rows(); ---disable_ps_protocol SELECT SQL_CALC_FOUND_ROWS * FROM t1 UNION all SELECT * FROM t2 LIMIT 2; -# PS doesn't work correctly with found_rows: to be fixed ---disable_ps_protocol select found_rows(); ---disable_ps_protocol # The following examples will not be exact SELECT SQL_CALC_FOUND_ROWS * FROM t1 UNION SELECT * FROM t2 LIMIT 2; From f814e19d3d79ece91fec0cbd1626ccc31446fe2d Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 3 Nov 2005 19:00:37 +0100 Subject: [PATCH 02/68] WL#2930 Adding view and cursor 'protocols' to mysqltest - Part2, actually adding the new functionality client/mysqltest.c: adding the new functionality run with views, cursor and stored procedures mysql-test/mysql-test-run.pl: Adding new switches --- client/mysqltest.c | 353 ++++++++++++++++++++++++++--------- mysql-test/mysql-test-run.pl | 25 +++ 2 files changed, 290 insertions(+), 88 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index b5a0f65f55c..1b24d44bdf3 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -42,7 +42,7 @@ **********************************************************************/ -#define MTEST_VERSION "2.5" +#define MTEST_VERSION "2.6" #include #include @@ -108,7 +108,8 @@ enum {OPT_MANAGER_USER=256,OPT_MANAGER_HOST,OPT_MANAGER_PASSWD, OPT_MANAGER_PORT,OPT_MANAGER_WAIT_TIMEOUT, OPT_SKIP_SAFEMALLOC, OPT_SSL_SSL, OPT_SSL_KEY, OPT_SSL_CERT, OPT_SSL_CA, OPT_SSL_CAPATH, - OPT_SSL_CIPHER,OPT_PS_PROTOCOL}; + OPT_SSL_CIPHER,OPT_PS_PROTOCOL,OPT_SP_PROTOCOL,OPT_CURSOR_PROTOCOL, + OPT_VIEW_PROTOCOL}; /* ************************************************************************ */ /* @@ -158,7 +159,11 @@ static char *db = 0, *pass=0; const char *user = 0, *host = 0, *unix_sock = 0, *opt_basedir="./"; static int port = 0; static my_bool opt_big_test= 0, opt_compress= 0, silent= 0, verbose = 0; -static my_bool tty_password= 0, ps_protocol= 0, ps_protocol_enabled= 0; +static my_bool tty_password= 0; +static my_bool ps_protocol= 0, ps_protocol_enabled= 0; +static my_bool sp_protocol= 0, sp_protocol_enabled= 0; +static my_bool view_protocol= 0, view_protocol_enabled= 0; +static my_bool cursor_protocol= 0, cursor_protocol_enabled= 0; static int parsing_disabled= 0; static uint start_lineno, *lineno; const char *manager_user="root",*manager_host=0; @@ -212,11 +217,14 @@ static int got_end_timer= FALSE; static void timer_output(void); static ulonglong timer_now(void); -static my_regex_t ps_re; /* Holds precompiled re for valid PS statements */ -static void ps_init_re(void); -static int ps_match_re(char *); -static char *ps_eprint(int); -static void ps_free_reg(void); +/* Precompiled re's */ +static my_regex_t ps_re; /* the query can be run using PS protocol */ +static my_regex_t sp_re; /* the query can be run as a SP */ +static my_regex_t view_re; /* the query can be run as a view*/ + +static void init_re(void); +static int match_re(my_regex_t *, char *); +static void free_re(void); static const char *embedded_server_groups[]= { @@ -240,6 +248,7 @@ struct connection { MYSQL mysql; char *name; + MYSQL_STMT* stmt; }; typedef struct @@ -433,7 +442,6 @@ static VAR* var_init(VAR* v, const char *name, int name_len, const char *val, static void var_free(void* v); -int dyn_string_cmp(DYNAMIC_STRING* ds, const char *fname); void dump_result_to_reject_file(const char *record_file, char *buf, int size); int close_connection(struct st_query*); @@ -539,6 +547,9 @@ static void close_cons() DBUG_ENTER("close_cons"); for (--next_con; next_con >= cons; --next_con) { + if (next_con->stmt) + mysql_stmt_close(next_con->stmt); + next_con->stmt= 0; mysql_close(&next_con->mysql); my_free(next_con->name, MYF(MY_ALLOW_ZERO_PTR)); } @@ -593,8 +604,7 @@ static void free_used_memory() my_free(pass,MYF(MY_ALLOW_ZERO_PTR)); free_defaults(default_argv); mysql_server_end(); - if (ps_protocol) - ps_free_reg(); + free_re(); DBUG_VOID_RETURN; } @@ -660,7 +670,7 @@ void init_parser() } -int dyn_string_cmp(DYNAMIC_STRING* ds, const char *fname) +static int dyn_string_cmp(DYNAMIC_STRING* ds, const char *fname) { MY_STAT stat_info; char *tmp, *res_ptr; @@ -2153,7 +2163,7 @@ int do_connect(struct st_query *q) p= safe_get_param(p, &con_db, "Missing connection db"); /* Port */ - VAR* var_port; + VAR *var_port; p= safe_get_param(p, &con_port_str, 0); if (*con_port_str) { @@ -2223,7 +2233,7 @@ int do_connect(struct st_query *q) if (!mysql_init(&next_con->mysql)) die("Failed on mysql_init()"); if (opt_compress || con_compress) - mysql_options(&next_con->mysql,MYSQL_OPT_COMPRESS,NullS); + mysql_options(&next_con->mysql, MYSQL_OPT_COMPRESS, NullS); mysql_options(&next_con->mysql, MYSQL_OPT_LOCAL_INFILE, 0); mysql_options(&next_con->mysql, MYSQL_SET_CHARSET_NAME, charset_name); @@ -2715,6 +2725,15 @@ static struct my_option my_long_options[] = {"ps-protocol", OPT_PS_PROTOCOL, "Use prepared statements protocol for communication", (gptr*) &ps_protocol, (gptr*) &ps_protocol, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"sp-protocol", OPT_SP_PROTOCOL, "Use stored procedures for select", + (gptr*) &sp_protocol, (gptr*) &sp_protocol, 0, + GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"cursor-protocol", OPT_CURSOR_PROTOCOL, "Use cursors for prepared statment", + (gptr*) &cursor_protocol, (gptr*) &cursor_protocol, 0, + GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"view-protocol", OPT_VIEW_PROTOCOL, "Use views for select", + (gptr*) &view_protocol, (gptr*) &view_protocol, 0, + GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"quiet", 's', "Suppress all normal output.", (gptr*) &silent, (gptr*) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"record", 'r', "Record output of test_file into result file.", @@ -2776,8 +2795,6 @@ void usage() #include -#include - static my_bool get_one_option(int optid, const struct my_option *opt __attribute__((unused)), @@ -3222,6 +3239,7 @@ static void append_table_headings(DYNAMIC_STRING* ds, static void append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql) { uint count; + MYSQL_RES *warn_res; DBUG_ENTER("append_warnings"); if (!(count= mysql_warning_count(mysql))) @@ -3237,11 +3255,9 @@ static void append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql) if (mysql_real_query(mysql, "SHOW WARNINGS", 13)) die("Error running query \"SHOW WARNINGS\": %s", mysql_error(mysql)); - MYSQL_RES *warn_res= mysql_store_result(mysql); - if (!warn_res) + if (!(warn_res= mysql_store_result(mysql))) die("Warning count is %u but didn't get any warnings", count); - dynstr_append_mem(ds, "Warnings:\n", 10); append_result(ds, warn_res); @@ -3258,6 +3274,7 @@ static void append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql) run_query_normal mysql - mysql handle command - currrent command pointer + flags -flags indicating wheter to SEND and/or REAP query - query string to execute query_len - length query string to execute ds - output buffer wherte to store result form query @@ -3279,7 +3296,7 @@ static void run_query_normal(MYSQL *mysql, struct st_query *command, if (flags & QUERY_SEND) { /* - Send the query, using the undocumented function mysql_send_query + Send the query */ if (mysql_send_query(mysql, query, query_len)) { @@ -3295,7 +3312,7 @@ static void run_query_normal(MYSQL *mysql, struct st_query *command, do { /* - When on first result set, call mysql_read_query_result to retrrieve + When on first result set, call mysql_read_query_result to retrieve answer to the query sent earlier */ if ((counter==0) && mysql_read_query_result(mysql)) @@ -3526,18 +3543,20 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, { MYSQL_RES *res= NULL; /* Note that here 'res' is meta data result set */ MYSQL_STMT *stmt; + DYNAMIC_STRING ds_prepare_warnings; DBUG_ENTER("run_query_stmt"); DBUG_PRINT("query", ("'%-.60s'", query)); - + /* - We must allocate a new stmt for each query in this program because this - may be a new connection. - - Well, it could be stored togeter with mysql pointer in cur_con struct + Init a new stmt if it's not alreday one created for this connectoon */ - if (!(stmt= mysql_stmt_init(mysql))) - die("unable to init stmt structure"); - + if(!(stmt= cur_con->stmt)) + { + if (!(stmt= mysql_stmt_init(mysql))) + die("unable to init stmt structure"); + cur_con->stmt= stmt; + } + /* Prepare the query */ @@ -3548,11 +3567,36 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, goto end; } + /* + Get the warnings from mysql_stmt_prepare and keep them in a + separate string + */ + + if (!disable_warnings) + { + init_dynamic_string(&ds_prepare_warnings, "", 1024, 1024); + append_warnings(&ds_prepare_warnings, mysql); + } + + /* No need to call mysql_stmt_bind_param() because we have no parameter markers. */ +#ifdef BUG14013_FIXED + /* + Use cursor when retrieving result + */ + if (cursor_protocol_enabled) + { + unsigned long type= CURSOR_TYPE_READ_ONLY; + if (mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type)) + die("mysql_stmt_attr_set(STMT_ATTR_CURSOR_TYPE) failed': %d %s", + mysql_stmt_errno(stmt), mysql_stmt_error(stmt)); + } +#endif + /* Execute the query */ @@ -3571,7 +3615,7 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, { my_bool one= 1; if (mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (void*) &one)) - die("mysql_stmt_attr_set failed': %d %s", + die("mysql_stmt_attr_set(STMT_ATTR_UPDATE_MAX_LENGTH) failed': %d %s", mysql_stmt_errno(stmt), mysql_stmt_error(stmt)); } @@ -3589,14 +3633,14 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, /* If we got here the statement was both executed and read succeesfully */ handle_no_error(command); - /* - Not all statements creates a result set. If there is one we can - now create another normal result set that contains the meta - data. This set can be handled almost like any other non prepared - statement result set. - */ if (!disable_result_log) { + /* + Not all statements creates a result set. If there is one we can + now create another normal result set that contains the meta + data. This set can be handled almost like any other non prepared + statement result set. + */ if ((res= mysql_stmt_result_metadata(stmt)) != NULL) { /* Take the column count from meta info */ @@ -3612,7 +3656,19 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, append_stmt_result(ds, stmt, fields, num_fields); mysql_free_result(res); /* Free normal result set with meta data */ + + } + else + { + /* + This is a query without resultset + */ + /* + Add warnings from prepare to output + */ + if (!disable_warnings) + dynstr_append(ds, ds_prepare_warnings.str); } if (!disable_warnings) @@ -3620,23 +3676,26 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, if (!disable_info) append_info(ds, (ulong)mysql_affected_rows(mysql), mysql_info(mysql)); + } end: free_replace(); + + if (!disable_warnings) + dynstr_free(&ds_prepare_warnings); + /* We save the return code (mysql_stmt_errno(stmt)) from the last call sent to the server into the mysqltest builtin variable $mysql_errno. This variable then can be used from the test case itself. */ var_set_errno(mysql_stmt_errno(stmt)); - mysql_stmt_close(stmt); DBUG_VOID_RETURN; } /* - Run query flags control the phased/stages of query execution to be performed @@ -3653,10 +3712,12 @@ end: static void run_query(MYSQL *mysql, struct st_query *command, int flags) { DYNAMIC_STRING *ds; - DYNAMIC_STRING ds_tmp; + DYNAMIC_STRING ds_result; DYNAMIC_STRING eval_query; char *query; int query_len; + my_bool view_created= 0, sp_created= 0; + my_bool complete_query= ((flags & QUERY_SEND) && (flags & QUERY_REAP)); /* Evaluate query if this is an eval command @@ -3682,35 +3743,122 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) */ if (command->record_file[0]) { - init_dynamic_string(&ds_tmp, "", 16384, 65536); - ds= &ds_tmp; + init_dynamic_string(&ds_result, "", 16384, 65536); + ds= &ds_result; } else ds= &ds_res; - /* Store the query into the output buffer */ + /* + Log the query into the output buffer + */ if (!disable_query_log && (flags & QUERY_SEND)) { - replace_dynstr_append_mem(ds,query, query_len); + replace_dynstr_append_mem(ds, query, query_len); dynstr_append_mem(ds, delimiter, delimiter_length); dynstr_append_mem(ds, "\n", 1); } + if (view_protocol_enabled && + complete_query && + match_re(&view_re, query)) + { + /* + Create the query as a view. + Use replace since view can exist from a failed mysqltest run + */ + DYNAMIC_STRING query_str; + init_dynamic_string(&query_str, + "CREATE OR REPLACE VIEW mysqltest_tmp_v AS ", + query_len+64, 256); + dynstr_append_mem(&query_str, query, query_len); + if (mysql_query(mysql, query_str.str)) + { + /* + Failed to create the view, this is not fatal + just run the query the normal way + */ + DBUG_PRINT("view_create_error", + ("Failed to create view '%s': %d: %s", query_str.str, + mysql_errno(mysql), mysql_error(mysql))); + } + else + { + /* + Yes, it was possible to create this query as a view + */ + view_created= 1; + query= (char*)"SELECT * FROM mysqltest_tmp_v"; + query_len = strlen(query); + } + + dynstr_free(&query_str); + + } + + if (sp_protocol_enabled && + complete_query && + match_re(&sp_re, query)) + { + /* + Create the query as a stored procedure + Drop first since sp can exist from a failed mysqltest run + */ + DYNAMIC_STRING query_str; + init_dynamic_string(&query_str, + "DROP PROCEDURE IF EXISTS mysqltest_tmp_sp;\n", + query_len+64, 256); + mysql_query(mysql, query_str.str); + dynstr_set(&query_str, "CREATE PROCEDURE mysqltest_tmp_sp()\n"); + dynstr_append_mem(&query_str, query, query_len); + if (mysql_query(mysql, query_str.str)) + { + /* + Failed to create the stored procedure for this query, + this is not fatal just run the query the normal way + */ + DBUG_PRINT("sp_create_error", + ("Failed to create sp '%s': %d: %s", query_str.str, + mysql_errno(mysql), mysql_error(mysql))); + } + else + { + sp_created= 1; + + query= (char*)"CALL mysqltest_tmp_sp()"; + query_len = strlen(query); + } + dynstr_free(&query_str); + } + /* Find out how to run this query - We don't have a mysql_stmt_send_execute() so it must be a - complete SEND+REAP to use prepared statement + Always run with normal C API if it's not a complete + SEND + REAP If it is a '?' in the query it may be a SQL level prepared - statement already and we can't do it twice + statement already and we can't do it twice */ if (ps_protocol_enabled && - (flags & QUERY_SEND) && (flags & QUERY_REAP) && - ps_match_re(query)) + complete_query && + match_re(&ps_re, query)) run_query_stmt(mysql, command, query, query_len, ds); else run_query_normal(mysql, command, flags, query, query_len, ds); + + if (sp_created) + { + if (mysql_query(mysql, "DROP PROCEDURE mysqltest_tmp_sp ")) + die("Failed to drop sp: %d: %s", mysql_errno(mysql), mysql_error(mysql)); + } + + if (view_created) + { + if (mysql_query(mysql, "DROP VIEW mysqltest_tmp_v ")) + die("Failed to drop view: %d: %s", + mysql_errno(mysql), mysql_error(mysql)); + } if (record) { @@ -3730,19 +3878,45 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) check_result(ds, command->record_file, command->require_file); } - if (ds == &ds_tmp) - dynstr_free(&ds_tmp); + if (ds == &ds_result) + dynstr_free(&ds_result); if (command->type == Q_EVAL) dynstr_free(&eval_query); } /****************************************************************************\ - * Functions to match SQL statements that can be prepared + * Functions to detect different SQL statements \****************************************************************************/ -static void ps_init_re(void) +static char *re_eprint(int err) { + static char epbuf[100]; + size_t len= my_regerror(REG_ITOA|err, (my_regex_t *)NULL, + epbuf, sizeof(epbuf)); + assert(len <= sizeof(epbuf)); + return(epbuf); +} + +static void init_re_comp(my_regex_t *re, const char* str) +{ + int err= my_regcomp(re, str, (REG_EXTENDED | REG_ICASE | REG_NOSUB), + &my_charset_latin1); + if (err) + { + char erbuf[100]; + int len= my_regerror(err, re, erbuf, sizeof(erbuf)); + die("error %s, %d/%d `%s'\n", + re_eprint(err), len, (int)sizeof(erbuf), erbuf); + } +} + +static void init_re(void) +{ + /* + Filter for queries that can be run using the + MySQL Prepared Statements C API + */ const char *ps_re_str = "^(" "[[:space:]]*REPLACE[[:space:]]|" @@ -3757,50 +3931,48 @@ static void ps_init_re(void) "[[:space:]]*UPDATE[[:space:]]+MULTI[[:space:]]|" "[[:space:]]*INSERT[[:space:]]+SELECT[[:space:]])"; - int err= my_regcomp(&ps_re, ps_re_str, - (REG_EXTENDED | REG_ICASE | REG_NOSUB), - &my_charset_latin1); - if (err) - { - char erbuf[100]; - int len= my_regerror(err, &ps_re, erbuf, sizeof(erbuf)); - fprintf(stderr, "error %s, %d/%d `%s'\n", - ps_eprint(err), len, (int)sizeof(erbuf), erbuf); - exit(1); - } + /* + Filter for queries that can be run using the + Stored procedures + */ + const char *sp_re_str =ps_re_str; + + /* + Filter for queries that can be run as views + */ + const char *view_re_str = + "^(" + "[[:space:]]*SELECT[[:space:]])"; + + init_re_comp(&ps_re, ps_re_str); + init_re_comp(&sp_re, sp_re_str); + init_re_comp(&view_re, view_re_str); } -static int ps_match_re(char *stmt_str) +static int match_re(my_regex_t *re, char *str) { - int err= my_regexec(&ps_re, stmt_str, (size_t)0, NULL, 0); + int err= my_regexec(re, str, (size_t)0, NULL, 0); if (err == 0) return 1; else if (err == REG_NOMATCH) return 0; - else - { + + { char erbuf[100]; - int len= my_regerror(err, &ps_re, erbuf, sizeof(erbuf)); - fprintf(stderr, "error %s, %d/%d `%s'\n", - ps_eprint(err), len, (int)sizeof(erbuf), erbuf); - exit(1); + int len= my_regerror(err, re, erbuf, sizeof(erbuf)); + die("error %s, %d/%d `%s'\n", + re_eprint(err), len, (int)sizeof(erbuf), erbuf); } + return 0; } -static char *ps_eprint(int err) -{ - static char epbuf[100]; - size_t len= my_regerror(REG_ITOA|err, (my_regex_t *)NULL, epbuf, sizeof(epbuf)); - assert(len <= sizeof(epbuf)); - return(epbuf); -} - - -static void ps_free_reg(void) +static void free_re(void) { my_regfree(&ps_re); + my_regfree(&sp_re); + my_regfree(&view_re); } /****************************************************************************/ @@ -3930,8 +4102,7 @@ static void init_var_hash(MYSQL *mysql) v= var_init(0,"MAX_TABLES", 0, (sizeof(ulong) == 4) ? "31" : "62",0); my_hash_insert(&var_hash, (byte*) v); v= var_init(0,"SERVER_VERSION", 0, mysql_get_server_info(mysql), 0); - my_hash_insert(&var_hash, (byte*) v); - v= var_init(0,"DB", 2, db, 0); + my_hash_insert(&var_hash, (byte*) v); v= var_init(0,"DB", 2, db, 0); my_hash_insert(&var_hash, (byte*) v); DBUG_VOID_RETURN; } @@ -3969,7 +4140,7 @@ int main(int argc, char **argv) cur_block= block_stack; cur_block->ok= TRUE; /* Outer block should always be executed */ cur_block->cmd= cmd_none; - + init_dynamic_string(&ds_res, "", 0, 65536); parse_args(argc, argv); @@ -3988,11 +4159,15 @@ int main(int argc, char **argv) if (manager_host) init_manager(); #endif - if (ps_protocol) - { + init_re(); + ps_protocol_enabled= ps_protocol; + sp_protocol_enabled= sp_protocol; + view_protocol_enabled= view_protocol; + cursor_protocol_enabled= cursor_protocol; + /* Cursor protcol implies ps protocol */ + if (cursor_protocol_enabled) ps_protocol_enabled= 1; - ps_init_re(); - } + if (!( mysql_init(&cur_con->mysql))) die("Failed in mysql_init()"); if (opt_compress) @@ -5282,3 +5457,5 @@ FILE *my_popen(const char *cmd, const char *mode __attribute__((unused))) } #endif /* __NETWARE__ or __WIN__*/ + + diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 2ca7e7c5e15..3ab0d016f48 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -191,6 +191,9 @@ our $opt_ssl; our $opt_skip_ssl; our $opt_ssl_supported; our $opt_ps_protocol; +our $opt_sp_protocol; +our $opt_cursor_protocol; +our $opt_view_protocol; our $opt_current_test; our $opt_ddd; @@ -490,6 +493,9 @@ sub command_line_setup () { # Control what engine/variation to run 'embedded-server' => \$opt_embedded_server, 'ps-protocol' => \$opt_ps_protocol, + 'sp-protocol' => \$opt_sp_protocol, + 'view-protocol' => \$opt_view_protocol, + 'cursor-protocol' => \$opt_cursor_protocol, 'ssl|with-openssl' => \$opt_ssl, 'skip-ssl' => \$opt_skip_ssl, 'compress' => \$opt_compress, @@ -2554,6 +2560,21 @@ sub run_mysqltest ($) { mtr_add_arg($args, "--ps-protocol"); } + if ( $opt_sp_protocol ) + { + mtr_add_arg($args, "--sp-protocol"); + } + + if ( $opt_view_protocol ) + { + mtr_add_arg($args, "--view-protocol"); + } + + if ( $opt_cursor_protocol ) + { + mtr_add_arg($args, "--cursor-protocol"); + } + if ( $opt_strace_client ) { $exe= "strace"; # FIXME there are ktrace, .... @@ -2685,6 +2706,10 @@ Options to control what engine/variation to run embedded-server Use the embedded server, i.e. no mysqld daemons ps-protocol Use the binary protocol between client and server + cursor-protocol Use the cursor protocol between client and server + (implies --ps-protocol) + view-protocol Create a view to execute all non updating queries + sp-protocol Create a stored procedure to execute all queries compress Use the compressed protocol between client and server ssl Use ssl protocol between client and server skip-ssl Dont start sterver with support for ssl connections From e012abb17e36eef00edbe63b04f2b39940d8ea57 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 3 Nov 2005 19:32:19 +0100 Subject: [PATCH 03/68] Reapplying patch Check for NULLs only if we don't replace column results, get real results after all checks. (see bug #14254: func_crypt.test fails on FreeBSD with --ps-protocol). Remove two FIXME's client/mysqltest.c: Reapplying patch, lost during merge Check for NULLs only if we don't replace column results, get real results after all checks. (see bug #14254: func_crypt.test fails on FreeBSD with --ps-protocol). Remove FIXME comments since it ssemd like the function handles vertical displays and even wheter the string is terminated or not is not relevant since we only append as much of it to output as "len" says --- client/mysqltest.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index a2b2b3477eb..89f164b9a47 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -3043,8 +3043,6 @@ static void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT* stmt, my_bool *is_null; ulong *length; ulonglong num_rows; - - /* FIXME we don't handle vertical display ..... */ uint col_idx, row_idx; /* Allocate array with bind structs, lengths and NULL flags */ @@ -3088,19 +3086,23 @@ static void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT* stmt, /* Read result from each column */ for (col_idx= 0; col_idx < num_fields; col_idx++) { - /* FIXME is string terminated? */ - const char *val= (const char *)bind[col_idx].buffer; - ulonglong len= *bind[col_idx].length; + const char *val; + ulonglong len; if (col_idx < max_replace_column && replace_column[col_idx]) { val= replace_column[col_idx]; len= strlen(val); } - if (*bind[col_idx].is_null) + else if (*bind[col_idx].is_null) { val= "NULL"; len= 4; } + else + { + val= (const char *) bind[col_idx].buffer; + len= *bind[col_idx].length; + } if (!display_result_vertically) { if (col_idx) /* No tab before first col */ From f2fa347ff085938f7f774d7aa3d38882ae5f5cac Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 4 Nov 2005 12:00:34 +0100 Subject: [PATCH 04/68] Remove trailing whitespace --- client/mysqltest.c | 208 +++++++++++++++++++++++---------------------- 1 file changed, 105 insertions(+), 103 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 89f164b9a47..04ad33bb8bc 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -119,7 +119,7 @@ enum {OPT_MANAGER_USER=256,OPT_MANAGER_HOST,OPT_MANAGER_PASSWD, set to type ERR_EMPTY. When an SQL statement return an error we use this list to check if this is an expected error. */ - + enum match_err_type { ERR_EMPTY= 0, @@ -300,7 +300,7 @@ struct connection* cur_con, *next_con, *cons_end; enum enum_commands { Q_CONNECTION=1, Q_QUERY, -Q_CONNECT, Q_SLEEP, Q_REAL_SLEEP, +Q_CONNECT, Q_SLEEP, Q_REAL_SLEEP, Q_INC, Q_DEC, Q_SOURCE, Q_DISCONNECT, Q_LET, Q_ECHO, @@ -740,14 +740,14 @@ err: /* Check the content of ds against content of file fname - + SYNOPSIS check_result ds - content to be checked fname - name of file to check against - require_option - if set and check fails, the test will be aborted with the special + require_option - if set and check fails, the test will be aborted with the special exit code "not supported test" - + RETURN VALUES error - the function will not return @@ -1645,7 +1645,7 @@ static uint get_errcodes(match_err *to,struct st_query *q) /* SQL error as string */ st_error *e= global_error; char *start= p++; - + for (; *p == '_' || my_isalnum(charset_info, *p); p++) ; for (; e->name; e++) @@ -1919,13 +1919,13 @@ int close_connection(struct st_query *q) SYNOPSIS safe_get_param str - string to get param from - arg - pointer to string where result will be stored + arg - pointer to string where result will be stored msg - Message to display if param is not found if msg is 0 this param is not required and param may be empty - + RETURNS pointer to str after param - + */ char* safe_get_param(char *str, char** arg, const char *msg) @@ -1933,7 +1933,7 @@ char* safe_get_param(char *str, char** arg, const char *msg) DBUG_ENTER("safe_get_param"); if(!*str) { - if (msg) + if (msg) die(msg); *arg= str; DBUG_RETURN(str); @@ -2082,7 +2082,7 @@ int connect_n_handle_errors(struct st_query *q, MYSQL* con, const char* host, *create_conn= 0; goto err; } - else + else { handle_no_error(q); @@ -2528,7 +2528,7 @@ int read_line(char *buf, int size) state= R_Q; } else -state= R_NORMAL; + state= R_NORMAL; break; case R_Q: @@ -2922,9 +2922,9 @@ char* safe_str_append(char *buf, const char *str, int size) } -/* +/* Write the content of str into file - + SYNOPSIS str_to_file fname - name of file to truncate/create and write to @@ -2941,7 +2941,7 @@ static void str_to_file(const char *fname, char *str, int size) fname=buff; } fn_format(buff,fname,"","",4); - + if ((fd = my_open(buff, O_WRONLY | O_CREAT | O_TRUNC, MYF(MY_WME | MY_FFNF))) < 0) die("Could not open %s: errno = %d", buff, errno); @@ -3032,7 +3032,7 @@ static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res) /* - Append all results from ps execution to the dynamic string separated + Append all results from ps execution to the dynamic string separated with '\t'. Values may be converted with 'replace_column' */ @@ -3044,7 +3044,7 @@ static void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT* stmt, ulong *length; ulonglong num_rows; uint col_idx, row_idx; - + /* Allocate array with bind structs, lengths and NULL flags */ bind= (MYSQL_BIND*) my_malloc(num_fields * sizeof(MYSQL_BIND), MYF(MY_WME | MY_FAE | MY_ZEROFILL)); @@ -3052,7 +3052,7 @@ static void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT* stmt, MYF(MY_WME | MY_FAE)); is_null= (my_bool*) my_malloc(num_fields * sizeof(my_bool), MYF(MY_WME | MY_FAE)); - + for (col_idx= 0; col_idx < num_fields; col_idx++) { /* Allocate data for output */ @@ -3062,19 +3062,19 @@ static void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT* stmt, */ uint max_length= max(field[col_idx].max_length + 1, 1024); char *str_data= (char *) my_malloc(max_length, MYF(MY_WME | MY_FAE)); - + bind[col_idx].buffer_type= MYSQL_TYPE_STRING; bind[col_idx].buffer= (char *)str_data; bind[col_idx].buffer_length= max_length; bind[col_idx].is_null= &is_null[col_idx]; bind[col_idx].length= &length[col_idx]; } - + /* Fill in the data into the structures created above */ if (mysql_stmt_bind_result(stmt, bind)) - die("mysql_stmt_bind_result failed: %d: %s", + die("mysql_stmt_bind_result failed: %d: %s", mysql_stmt_errno(stmt), mysql_stmt_error(stmt)); - + /* Read result from each row */ num_rows= mysql_stmt_num_rows(stmt); for (row_idx= 0; row_idx < num_rows; row_idx++) @@ -3082,7 +3082,7 @@ static void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT* stmt, if (mysql_stmt_fetch(stmt)) die("mysql_stmt_fetch failed: %d %s", mysql_stmt_errno(stmt), mysql_stmt_error(stmt)); - + /* Read result from each column */ for (col_idx= 0; col_idx < num_fields; col_idx++) { @@ -3120,13 +3120,13 @@ static void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT* stmt, if (!display_result_vertically) dynstr_append_mem(ds, "\n", 1); } - + if (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) die("fetch didn't end with MYSQL_NO_DATA from statement: %d %s", mysql_stmt_error(stmt), mysql_stmt_errno(stmt)); - + free_replace_column(); - + for (col_idx= 0; col_idx < num_fields; col_idx++) { /* Free data for output */ @@ -3144,7 +3144,7 @@ static void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT* stmt, */ static void append_metadata(DYNAMIC_STRING *ds, - MYSQL_FIELD *field, + MYSQL_FIELD *field, uint num_fields) { MYSQL_FIELD *field_end; @@ -3217,10 +3217,10 @@ static void append_info(DYNAMIC_STRING* ds, ulong affected_rows, } -/* - Display the table headings with the names tab separated +/* + Display the table headings with the names tab separated */ -static void append_table_headings(DYNAMIC_STRING* ds, +static void append_table_headings(DYNAMIC_STRING* ds, MYSQL_FIELD* field, uint num_fields) { @@ -3253,14 +3253,14 @@ static void append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql) we have not read all results... */ DBUG_ASSERT(!mysql_more_results(mysql)); - + if (mysql_real_query(mysql, "SHOW WARNINGS", 13)) die("Error running query \"SHOW WARNINGS\": %s", mysql_error(mysql)); - + if (!(warn_res= mysql_store_result(mysql))) die("Warning count is %u but didn't get any warnings", count); - + dynstr_append_mem(ds, "Warnings:\n", 10); append_result(ds, warn_res); mysql_free_result(warn_res); @@ -3271,7 +3271,7 @@ static void append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql) /* Run query using MySQL C API - + SYNPOSIS run_query_normal mysql - mysql handle @@ -3285,8 +3285,8 @@ static void append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql) error - function will not return */ -static void run_query_normal(MYSQL *mysql, struct st_query *command, - int flags, char *query, int query_len, +static void run_query_normal(MYSQL *mysql, struct st_query *command, + int flags, char *query, int query_len, DYNAMIC_STRING *ds) { MYSQL_RES *res= 0; @@ -3297,7 +3297,7 @@ static void run_query_normal(MYSQL *mysql, struct st_query *command, if (flags & QUERY_SEND) { - /* + /* Send the query */ if (mysql_send_query(mysql, query, query_len)) @@ -3310,11 +3310,11 @@ static void run_query_normal(MYSQL *mysql, struct st_query *command, if (!(flags & QUERY_REAP)) DBUG_VOID_RETURN; - + do { /* - When on first result set, call mysql_read_query_result to retrieve + When on first result set, call mysql_read_query_result to retrieve answer to the query sent earlier */ if ((counter==0) && mysql_read_query_result(mysql)) @@ -3325,8 +3325,8 @@ static void run_query_normal(MYSQL *mysql, struct st_query *command, } - /* - Store the result. If res is NULL, use mysql_field_count to + /* + Store the result. If res is NULL, use mysql_field_count to determine if that was expected */ if (!(res= mysql_store_result(mysql)) && mysql_field_count(mysql)) @@ -3386,7 +3386,7 @@ static void run_query_normal(MYSQL *mysql, struct st_query *command, goto end; } DBUG_ASSERT(err == -1); /* Successful and there are no more results */ - + /* If we come here the query is both executed and read successfully */ handle_no_error(command); @@ -3428,12 +3428,12 @@ static void handle_error(const char *query, struct st_query *q, const char *err_sqlstate, DYNAMIC_STRING *ds) { uint i; - + DBUG_ENTER("handle_error"); if (q->require_file) abort_not_supported_test(); - + if (q->abort_on_error) die("query '%s' failed: %d: %s", query, err_errno, err_error); @@ -3527,7 +3527,7 @@ static void handle_no_error(struct st_query *q) /* Run query using prepared statement C API - + SYNPOSIS run_query_stmt mysql - mysql handle @@ -3540,7 +3540,7 @@ static void handle_no_error(struct st_query *q) error - function will not return */ -static void run_query_stmt(MYSQL *mysql, struct st_query *command, +static void run_query_stmt(MYSQL *mysql, struct st_query *command, char *query, int query_len, DYNAMIC_STRING *ds) { MYSQL_RES *res= NULL; /* Note that here 'res' is meta data result set */ @@ -3548,7 +3548,7 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, DYNAMIC_STRING ds_prepare_warnings; DBUG_ENTER("run_query_stmt"); DBUG_PRINT("query", ("'%-.60s'", query)); - + /* Init a new stmt if it's not alreday one created for this connectoon */ @@ -3558,7 +3558,7 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, die("unable to init stmt structure"); cur_con->stmt= stmt; } - + /* Prepare the query */ @@ -3570,10 +3570,10 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, } /* - Get the warnings from mysql_stmt_prepare and keep them in a - separate string + Get the warnings from mysql_stmt_prepare and keep them in a + separate string */ - + if (!disable_warnings) { init_dynamic_string(&ds_prepare_warnings, "", 1024, 1024); @@ -3594,7 +3594,7 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, { unsigned long type= CURSOR_TYPE_READ_ONLY; if (mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type)) - die("mysql_stmt_attr_set(STMT_ATTR_CURSOR_TYPE) failed': %d %s", + die("mysql_stmt_attr_set(STMT_ATTR_CURSOR_TYPE) failed': %d %s", mysql_stmt_errno(stmt), mysql_stmt_error(stmt)); } #endif @@ -3602,7 +3602,7 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, /* Execute the query */ - if (mysql_stmt_execute(stmt)) + if (mysql_stmt_execute(stmt)) { handle_error(query, command, mysql_stmt_errno(stmt), mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt), ds); @@ -3617,7 +3617,7 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, { my_bool one= 1; if (mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (void*) &one)) - die("mysql_stmt_attr_set(STMT_ATTR_UPDATE_MAX_LENGTH) failed': %d %s", + die("mysql_stmt_attr_set(STMT_ATTR_UPDATE_MAX_LENGTH) failed': %d %s", mysql_stmt_errno(stmt), mysql_stmt_error(stmt)); } @@ -3635,6 +3635,7 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, /* If we got here the statement was both executed and read succeesfully */ handle_no_error(command); if (!disable_result_log) + { /* Not all statements creates a result set. If there is one we can now create another normal result set that contains the meta @@ -3642,27 +3643,28 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, statement result set. */ if ((res= mysql_stmt_result_metadata(stmt)) != NULL) + { /* Take the column count from meta info */ MYSQL_FIELD *fields= mysql_fetch_fields(res); uint num_fields= mysql_num_fields(res); - + if (display_metadata) append_metadata(ds, fields, num_fields); - + if (!display_result_vertically) append_table_headings(ds, fields, num_fields); - - append_stmt_result(ds, stmt, fields, num_fields); - + + append_stmt_result(ds, stmt, fields, num_fields); + mysql_free_result(res); /* Free normal result set with meta data */ - } - else + } + else { /* This is a query without resultset */ - + /* Add warnings from prepare to output */ @@ -3672,15 +3674,15 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, if (!disable_warnings) append_warnings(ds, mysql); - + if (!disable_info) append_info(ds, (ulong)mysql_affected_rows(mysql), mysql_info(mysql)); - + } end: free_replace(); - + if (!disable_warnings) dynstr_free(&ds_prepare_warnings); @@ -3705,7 +3707,7 @@ end: run_query mysql - mysql handle command - currrent command pointer - + */ static void run_query(MYSQL *mysql, struct st_query *command, int flags) @@ -3735,7 +3737,7 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) } /* - When command->record_file is set the output of _this_ query + When command->record_file is set the output of _this_ query should be compared with an already existing file Create a temporary dynamic string to contain the output from this query. @@ -3748,8 +3750,8 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) else ds= &ds_res; - /* - Log the query into the output buffer + /* + Log the query into the output buffer */ if (!disable_query_log && (flags & QUERY_SEND)) { @@ -3762,13 +3764,13 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) complete_query && match_re(&view_re, query)) { - /* + /* Create the query as a view. - Use replace since view can exist from a failed mysqltest run - */ - DYNAMIC_STRING query_str; - init_dynamic_string(&query_str, - "CREATE OR REPLACE VIEW mysqltest_tmp_v AS ", + Use replace since view can exist from a failed mysqltest run + */ + DYNAMIC_STRING query_str; + init_dynamic_string(&query_str, + "CREATE OR REPLACE VIEW mysqltest_tmp_v AS ", query_len+64, 256); dynstr_append_mem(&query_str, query, query_len); if (mysql_query(mysql, query_str.str)) @@ -3777,7 +3779,7 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) Failed to create the view, this is not fatal just run the query the normal way */ - DBUG_PRINT("view_create_error", + DBUG_PRINT("view_create_error", ("Failed to create view '%s': %d: %s", query_str.str, mysql_errno(mysql), mysql_error(mysql))); } @@ -3787,12 +3789,12 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) Yes, it was possible to create this query as a view */ view_created= 1; - query= (char*)"SELECT * FROM mysqltest_tmp_v"; + query= (char*)"SELECT * FROM mysqltest_tmp_v"; query_len = strlen(query); } dynstr_free(&query_str); - + } if (sp_protocol_enabled && @@ -3801,19 +3803,19 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) { /* Create the query as a stored procedure - Drop first since sp can exist from a failed mysqltest run - */ + Drop first since sp can exist from a failed mysqltest run + */ DYNAMIC_STRING query_str; - init_dynamic_string(&query_str, + init_dynamic_string(&query_str, "DROP PROCEDURE IF EXISTS mysqltest_tmp_sp;\n", query_len+64, 256); - mysql_query(mysql, query_str.str); + mysql_query(mysql, query_str.str); dynstr_set(&query_str, "CREATE PROCEDURE mysqltest_tmp_sp()\n"); dynstr_append_mem(&query_str, query, query_len); if (mysql_query(mysql, query_str.str)) { /* - Failed to create the stored procedure for this query, + Failed to create the stored procedure for this query, this is not fatal just run the query the normal way */ DBUG_PRINT("sp_create_error", @@ -3823,8 +3825,8 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) else { sp_created= 1; - - query= (char*)"CALL mysqltest_tmp_sp()"; + + query= (char*)"CALL mysqltest_tmp_sp()"; query_len = strlen(query); } dynstr_free(&query_str); @@ -3833,7 +3835,7 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) /* Find out how to run this query - Always run with normal C API if it's not a complete + Always run with normal C API if it's not a complete SEND + REAP If it is a '?' in the query it may be a SQL level prepared @@ -3845,17 +3847,17 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) run_query_stmt(mysql, command, query, query_len, ds); else run_query_normal(mysql, command, flags, query, query_len, ds); - + if (sp_created) { if (mysql_query(mysql, "DROP PROCEDURE mysqltest_tmp_sp ")) die("Failed to drop sp: %d: %s", mysql_errno(mysql), mysql_error(mysql)); } - + if (view_created) { if (mysql_query(mysql, "DROP VIEW mysqltest_tmp_v ")) - die("Failed to drop view: %d: %s", + die("Failed to drop view: %d: %s", mysql_errno(mysql), mysql_error(mysql)); } @@ -3871,7 +3873,7 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) else if (command->record_file[0]) { /* - The output from _this_ query should be checked against an already + The output from _this_ query should be checked against an already existing file which has been specified using --require or --result */ check_result(ds, command->record_file, command->require_file); @@ -3891,7 +3893,7 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) static char *re_eprint(int err) { static char epbuf[100]; - size_t len= my_regerror(REG_ITOA|err, (my_regex_t *)NULL, + size_t len= my_regerror(REG_ITOA|err, (my_regex_t *)NULL, epbuf, sizeof(epbuf)); assert(len <= sizeof(epbuf)); return(epbuf); @@ -3905,15 +3907,15 @@ static void init_re_comp(my_regex_t *re, const char* str) { char erbuf[100]; int len= my_regerror(err, re, erbuf, sizeof(erbuf)); - die("error %s, %d/%d `%s'\n", + die("error %s, %d/%d `%s'\n", re_eprint(err), len, (int)sizeof(erbuf), erbuf); } } static void init_re(void) { - /* - Filter for queries that can be run using the + /* + Filter for queries that can be run using the MySQL Prepared Statements C API */ const char *ps_re_str = @@ -3930,13 +3932,13 @@ static void init_re(void) "[[:space:]]*UPDATE[[:space:]]+MULTI[[:space:]]|" "[[:space:]]*INSERT[[:space:]]+SELECT[[:space:]])"; - /* - Filter for queries that can be run using the + /* + Filter for queries that can be run using the Stored procedures */ const char *sp_re_str =ps_re_str; - /* + /* Filter for queries that can be run as views */ const char *view_re_str = @@ -3958,7 +3960,7 @@ static int match_re(my_regex_t *re, char *str) else if (err == REG_NOMATCH) return 0; - { + { char erbuf[100]; int len= my_regerror(err, re, erbuf, sizeof(erbuf)); die("error %s, %d/%d `%s'\n", @@ -4093,7 +4095,7 @@ static void init_var_hash(MYSQL *mysql) { VAR *v; DBUG_ENTER("init_var_hash"); - if (hash_init(&var_hash, charset_info, + if (hash_init(&var_hash, charset_info, 1024, 0, 0, get_var_key, var_free, MYF(0))) die("Variable hash initialization failed"); my_hash_insert(&var_hash, (byte*) var_init(0,"BIG_TEST", 0, @@ -4139,7 +4141,7 @@ int main(int argc, char **argv) cur_block= block_stack; cur_block->ok= TRUE; /* Outer block should always be executed */ cur_block->cmd= cmd_none; - + init_dynamic_string(&ds_res, "", 0, 65536); parse_args(argc, argv); @@ -4486,8 +4488,8 @@ int main(int argc, char **argv) /* No result_file to compare with, print the result to stdout */ printf("%s", ds_res.str); } - } - else + } + else { /* The test didn't produce any output */ } @@ -5440,7 +5442,7 @@ static char *subst_env_var(const char *str) */ #undef popen /* Remove wrapper */ -#ifdef __WIN__ +#ifdef __WIN__ #define popen _popen /* redefine for windows */ #endif From cce0a27e2d7eb4059f8eddb31aa08c8420d5d9b9 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 4 Nov 2005 12:15:49 +0100 Subject: [PATCH 05/68] Formatting improved client/mysqltest.c: Remove unused function safe_str_append Fix formatting --- client/mysqltest.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 04ad33bb8bc..224985227cd 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -2912,15 +2912,6 @@ int parse_args(int argc, char **argv) return 0; } -char* safe_str_append(char *buf, const char *str, int size) -{ - int i,c ; - for (i = 0; (c = *str++) && i < size - 1; i++) - *buf++ = c; - *buf = 0; - return buf; -} - /* Write the content of str into file @@ -2931,6 +2922,7 @@ char* safe_str_append(char *buf, const char *str, int size) str - content to write to file size - size of content witten to file */ + static void str_to_file(const char *fname, char *str, int size) { int fd; @@ -2938,11 +2930,11 @@ static void str_to_file(const char *fname, char *str, int size) if (!test_if_hard_path(fname)) { strxmov(buff, opt_basedir, fname, NullS); - fname=buff; + fname= buff; } fn_format(buff,fname,"","",4); - if ((fd = my_open(buff, O_WRONLY | O_CREAT | O_TRUNC, + if ((fd= my_open(buff, O_WRONLY | O_CREAT | O_TRUNC, MYF(MY_WME | MY_FFNF))) < 0) die("Could not open %s: errno = %d", buff, errno); if (my_write(fd, (byte*)str, size, MYF(MY_WME|MY_FNABP))) @@ -2950,6 +2942,7 @@ static void str_to_file(const char *fname, char *str, int size) my_close(fd, MYF(0)); } + void dump_result_to_reject_file(const char *record_file, char *buf, int size) { char reject_file[FN_REFLEN]; @@ -2972,6 +2965,7 @@ static void replace_dynstr_append_mem(DYNAMIC_STRING *ds, const char *val, dynstr_append_mem(ds, val, len); } + /* Append zero-terminated string to ds, with optional replace */ static void replace_dynstr_append(DYNAMIC_STRING *ds, const char *val) @@ -3036,8 +3030,8 @@ static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res) with '\t'. Values may be converted with 'replace_column' */ -static void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT* stmt, - MYSQL_FIELD* field, uint num_fields) +static void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT *stmt, + MYSQL_FIELD *field, uint num_fields) { MYSQL_BIND *bind; my_bool *is_null; @@ -3198,12 +3192,13 @@ static void append_metadata(DYNAMIC_STRING *ds, } } + /* Append affected row count and other info to output */ -static void append_info(DYNAMIC_STRING* ds, ulong affected_rows, - const char* info) +static void append_info(DYNAMIC_STRING *ds, ulong affected_rows, + const char *info) { char buf[40]; sprintf(buf,"affected rows: %lu\n", affected_rows); @@ -3220,8 +3215,9 @@ static void append_info(DYNAMIC_STRING* ds, ulong affected_rows, /* Display the table headings with the names tab separated */ -static void append_table_headings(DYNAMIC_STRING* ds, - MYSQL_FIELD* field, + +static void append_table_headings(DYNAMIC_STRING *ds, + MYSQL_FIELD *field, uint num_fields) { uint col_idx; From bca61bcfde103f2e8bf7b20c436951f3b81a019b Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 3 Dec 2005 18:13:06 +0200 Subject: [PATCH 06/68] Set thread_stack after return from end_thread() Fixes core dump when reusing thread when running debug binary sql-bench/bench-init.pl.sh: Use ENGINE= instead of TYPE= sql-bench/server-cfg.sh: Use ENGINE= instead of TYPE= sql/mysqld.cc: Set thread_stack (to avoid core dump in store_globlas) sql/sql_parse.cc: Set thread_stack after return from end_thread() --- sql-bench/bench-init.pl.sh | 2 +- sql-bench/server-cfg.sh | 10 +++++----- sql/mysqld.cc | 1 + sql/sql_parse.cc | 1 + 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/sql-bench/bench-init.pl.sh b/sql-bench/bench-init.pl.sh index d61551ffb3b..31282d06abf 100644 --- a/sql-bench/bench-init.pl.sh +++ b/sql-bench/bench-init.pl.sh @@ -447,7 +447,7 @@ All benchmarks takes the following options: --create-options=# Extra argument to all create statements. If you for example want to create all MySQL tables as BDB tables use: - --create-options=TYPE=BDB + --create-options=ENGINE=BDB --database (Default $opt_database) In which database the test tables are created. diff --git a/sql-bench/server-cfg.sh b/sql-bench/server-cfg.sh index b0c40102a6b..75528b24b77 100644 --- a/sql-bench/server-cfg.sh +++ b/sql-bench/server-cfg.sh @@ -174,29 +174,29 @@ sub new # Some fixes that depends on the environment if (defined($main::opt_create_options) && - $main::opt_create_options =~ /type=heap/i) + $main::opt_create_options =~ /engine=heap/i) { $limits{'working_blobs'} = 0; # HEAP tables can't handle BLOB's } if (defined($main::opt_create_options) && - $main::opt_create_options =~ /type=innodb/i) + $main::opt_create_options =~ /engine=innodb/i) { $self->{'transactions'} = 1; # Transactions enabled } if (defined($main::opt_create_options) && - $main::opt_create_options =~ /type=ndb/i) + $main::opt_create_options =~ /engine=ndb/i) { $self->{'transactions'} = 1; # Transactions enabled $limits{'max_columns'} = 90; # Max number of columns in table $limits{'max_tables'} = 32; # No comments } if (defined($main::opt_create_options) && - $main::opt_create_options =~ /type=bdb/i) + $main::opt_create_options =~ /engine=bdb/i) { $self->{'transactions'} = 1; # Transactions enabled } if (defined($main::opt_create_options) && - $main::opt_create_options =~ /type=gemini/i) + $main::opt_create_options =~ /engine=gemini/i) { $limits{'working_blobs'} = 0; # Blobs not implemented yet $limits{'max_tables'} = 500; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index b5b95e48889..857658207ba 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1589,6 +1589,7 @@ void end_thread(THD *thd, bool put_in_cache) wake_thread--; thd=thread_cache.get(); thd->real_id=pthread_self(); + thd->thread_stack= (char*) &thd; // For store_globals (void) thd->store_globals(); thd->thr_create_time= time(NULL); threads.append(thd); diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 00124225719..1a9b4ef4db7 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1182,6 +1182,7 @@ end_thread: or this thread has been schedule to handle the next query */ thd= current_thd; + thd->thread_stack= (char*) &thd; } while (!(test_flags & TEST_NO_THREADS)); /* The following is only executed if we are not using --one-thread */ return(0); /* purecov: deadcode */ From 041dec8fc6cf355a9ee2b6bbf650c5f03dd0f823 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 6 Dec 2005 21:28:13 +0100 Subject: [PATCH 07/68] WL#2930 - Updated after review client/mysqltest.c: Remove the mysterious 1024, sed when calculating max_length for bind columns Change affected_rows variables to use ulonglong A little more fiddling with warnings in ps mode needed Add temporary workaround for bug#15518 Use ulong instead of "unsigned long" Print verbose_msg when failure to create view or sp Updated cheks for "zero size result file" and "no queries executed but result file found" The test must produce some output mysql-test/include/have_multi_ndb.inc: Use --require instead of @r mysql-test/r/mysqltest.result: Update resulfiles mysql-test/t/init_file.test: Add "echo" command so that test produces output. mysql-test/t/mysql_client_test.test: Add "echo" command so that test produces output. mysql-test/t/mysqltest.test: Added new test case for "zero size resul file" Added new test case for "no output" Make sure all generated sql files are put in var/tmp dir mysql-test/r/init_file.result: New BitKeeper file ``mysql-test/r/init_file.result'' mysql-test/r/mysql_client_test.result: New BitKeeper file ``mysql-test/r/mysql_client_test.result'' --- client/mysqltest.c | 138 +++++++++++++++++--------- mysql-test/include/have_multi_ndb.inc | 8 +- mysql-test/r/init_file.result | 1 + mysql-test/r/mysql_client_test.result | 1 + mysql-test/r/mysqltest.result | 4 + mysql-test/t/init_file.test | 1 + mysql-test/t/mysql_client_test.test | 2 + mysql-test/t/mysqltest.test | 54 +++++++--- 8 files changed, 146 insertions(+), 63 deletions(-) create mode 100644 mysql-test/r/init_file.result create mode 100644 mysql-test/r/mysql_client_test.result diff --git a/client/mysqltest.c b/client/mysqltest.c index 224985227cd..91791145db5 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -628,6 +628,10 @@ static void die(const char *fmt, ...) va_end(args); free_used_memory(); my_end(MY_CHECK_ERROR); + + if (!silent) + printf("not ok\n"); + exit(1); } @@ -3050,11 +3054,7 @@ static void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT *stmt, for (col_idx= 0; col_idx < num_fields; col_idx++) { /* Allocate data for output */ - /* - FIXME it may be a bug that for non string/blob types - 'max_length' is 0, should try out 'length' in that case - */ - uint max_length= max(field[col_idx].max_length + 1, 1024); + uint max_length= field[col_idx].max_length + 1; char *str_data= (char *) my_malloc(max_length, MYF(MY_WME | MY_FAE)); bind[col_idx].buffer_type= MYSQL_TYPE_STRING; @@ -3062,6 +3062,11 @@ static void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT *stmt, bind[col_idx].buffer_length= max_length; bind[col_idx].is_null= &is_null[col_idx]; bind[col_idx].length= &length[col_idx]; + + DBUG_PRINT("bind", ("col[%d]: buffer_type: %d, buffer_length: %d", + col_idx, + bind[col_idx].buffer_type, + bind[col_idx].buffer_length)); } /* Fill in the data into the structures created above */ @@ -3197,11 +3202,11 @@ static void append_metadata(DYNAMIC_STRING *ds, Append affected row count and other info to output */ -static void append_info(DYNAMIC_STRING *ds, ulong affected_rows, +static void append_info(DYNAMIC_STRING *ds, ulonglong affected_rows, const char *info) { char buf[40]; - sprintf(buf,"affected rows: %lu\n", affected_rows); + sprintf(buf,"affected rows: %llu\n", affected_rows); dynstr_append(ds, buf); if (info) { @@ -3231,17 +3236,20 @@ static void append_table_headings(DYNAMIC_STRING *ds, } /* - Fetch warnings from server and append to output + Fetch warnings from server and append to ds + + RETURN VALUE + Number of warnings appended to ds */ -static void append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql) +static int append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql) { uint count; MYSQL_RES *warn_res; DBUG_ENTER("append_warnings"); if (!(count= mysql_warning_count(mysql))) - DBUG_VOID_RETURN; + DBUG_RETURN(0); /* If one day we will support execution of multi-statements @@ -3257,14 +3265,14 @@ static void append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql) die("Warning count is %u but didn't get any warnings", count); - dynstr_append_mem(ds, "Warnings:\n", 10); append_result(ds, warn_res); mysql_free_result(warn_res); - DBUG_VOID_RETURN; + DBUG_RETURN(count); } + /* Run query using MySQL C API @@ -3287,6 +3295,7 @@ static void run_query_normal(MYSQL *mysql, struct st_query *command, { MYSQL_RES *res= 0; int err= 0, counter= 0; + DYNAMIC_STRING ds_warnings; DBUG_ENTER("run_query_normal"); DBUG_PRINT("enter",("flags: %d", flags)); DBUG_PRINT("enter", ("query: '%-.60s'", query)); @@ -3334,7 +3343,7 @@ static void run_query_normal(MYSQL *mysql, struct st_query *command, if (!disable_result_log) { - ulong affected_rows; /* Ok to be undef if 'disable_info' is set */ + ulonglong affected_rows; /* Ok to be undef if 'disable_info' is set */ LINT_INIT(affected_rows); if (res) @@ -3356,7 +3365,7 @@ static void run_query_normal(MYSQL *mysql, struct st_query *command, query to find the warnings */ if (!disable_info) - affected_rows= (ulong)mysql_affected_rows(mysql); + affected_rows= mysql_affected_rows(mysql); /* Add all warnings to the result. We can't do this if we are in @@ -3364,7 +3373,15 @@ static void run_query_normal(MYSQL *mysql, struct st_query *command, this will break protocol. */ if (!disable_warnings && !mysql_more_results(mysql)) - append_warnings(ds, mysql); + { + init_dynamic_string(&ds_warnings, NULL, 0, 256); + if (append_warnings(&ds_warnings, mysql)) + { + dynstr_append_mem(ds, "Warnings:\n", 10); + dynstr_append_mem(ds, ds_warnings.str, ds_warnings.length); + } + dynstr_free(&ds_warnings); + } if (!disable_info) append_info(ds, affected_rows, mysql_info(mysql)); @@ -3542,6 +3559,7 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, MYSQL_RES *res= NULL; /* Note that here 'res' is meta data result set */ MYSQL_STMT *stmt; DYNAMIC_STRING ds_prepare_warnings; + DYNAMIC_STRING ds_execute_warnings; DBUG_ENTER("run_query_stmt"); DBUG_PRINT("query", ("'%-.60s'", query)); @@ -3562,6 +3580,10 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, { handle_error(query, command, mysql_stmt_errno(stmt), mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt), ds); +#ifndef BUG15518_FIXED + mysql_stmt_close(stmt); + cur_con->stmt= NULL; +#endif goto end; } @@ -3569,10 +3591,10 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, Get the warnings from mysql_stmt_prepare and keep them in a separate string */ - if (!disable_warnings) { - init_dynamic_string(&ds_prepare_warnings, "", 1024, 1024); + init_dynamic_string(&ds_prepare_warnings, NULL, 0, 256); + init_dynamic_string(&ds_execute_warnings, NULL, 0, 256); append_warnings(&ds_prepare_warnings, mysql); } @@ -3588,7 +3610,7 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, */ if (cursor_protocol_enabled) { - unsigned long type= CURSOR_TYPE_READ_ONLY; + ulong type= CURSOR_TYPE_READ_ONLY; if (mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void*) &type)) die("mysql_stmt_attr_set(STMT_ATTR_CURSOR_TYPE) failed': %d %s", mysql_stmt_errno(stmt), mysql_stmt_error(stmt)); @@ -3654,25 +3676,36 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, mysql_free_result(res); /* Free normal result set with meta data */ + /* Clear prepare warnings */ + dynstr_set(&ds_prepare_warnings, NULL); } else { /* This is a query without resultset */ - - /* - Add warnings from prepare to output - */ - if (!disable_warnings) - dynstr_append(ds, ds_prepare_warnings.str); } if (!disable_warnings) - append_warnings(ds, mysql); + { + /* Get the warnings from execute */ + + /* Append warnings to ds - if there are any */ + if (append_warnings(&ds_execute_warnings, mysql) || + ds_prepare_warnings.length) + { + dynstr_append_mem(ds, "Warnings:\n", 10); + if (ds_prepare_warnings.length) + dynstr_append_mem(ds, ds_prepare_warnings.str, + ds_prepare_warnings.length); + if (ds_execute_warnings.length) + dynstr_append_mem(ds, ds_execute_warnings.str, + ds_execute_warnings.length); + } + } if (!disable_info) - append_info(ds, (ulong)mysql_affected_rows(mysql), mysql_info(mysql)); + append_info(ds, mysql_affected_rows(mysql), mysql_info(mysql)); } @@ -3680,7 +3713,10 @@ end: free_replace(); if (!disable_warnings) + { dynstr_free(&ds_prepare_warnings); + dynstr_free(&ds_execute_warnings); + } /* We save the return code (mysql_stmt_errno(stmt)) from the last call sent @@ -3778,6 +3814,10 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) DBUG_PRINT("view_create_error", ("Failed to create view '%s': %d: %s", query_str.str, mysql_errno(mysql), mysql_error(mysql))); + + /* Log error to create view */ + verbose_msg("Failed to create view '%s' %d: %s", query_str.str, + mysql_errno(mysql), mysql_error(mysql)); } else { @@ -3817,6 +3857,11 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) DBUG_PRINT("sp_create_error", ("Failed to create sp '%s': %d: %s", query_str.str, mysql_errno(mysql), mysql_error(mysql))); + + /* Log error to create sp */ + verbose_msg("Failed to create sp '%s' %d: %s", query_str.str, + mysql_errno(mysql), mysql_error(mysql)); + } else { @@ -4446,24 +4491,10 @@ int main(int argc, char **argv) } /* - The whole test has been executed sucessfully + The whole test has been executed _sucessfully_ Time to compare result or save it to record file The entire output from test is now kept in ds_res - */ - - if (!query_executed && result_file && my_stat(result_file, &res_info, 0)) - { - /* - my_stat() successful on result file. Check if we have not run a - single query, but we do have a result file that contains data. - Note that we don't care, if my_stat() fails. For example for - non-existing or non-readable file we assume it's fine to have - no query output from the test file, e.g. regarded as no error. - */ - if (res_info.st_size) - die("No queries executed but result file found!"); - } - + */ if (ds_res.length) { if (result_file) @@ -4475,20 +4506,37 @@ int main(int argc, char **argv) } else { - /* Check that the output from test is equal to result file */ + /* Check that the output from test is equal to result file + - detect missing result file + - detect zero size result file + */ check_result(&ds_res, result_file, 0); } } else { - /* No result_file to compare with, print the result to stdout */ + /* No result_file specified to compare with, print to stdout */ printf("%s", ds_res.str); } } else { - /* The test didn't produce any output */ + die("The test didn't produce any output"); } + + if (!query_executed && result_file && my_stat(result_file, &res_info, 0)) + { + /* + my_stat() successful on result file. Check if we have not run a + single query, but we do have a result file that contains data. + Note that we don't care, if my_stat() fails. For example for + non-existing or non-readable file we assume it's fine to have + no query output from the test file, e.g. regarded as no error. + */ + die("No queries executed but result file found!"); + } + + dynstr_free(&ds_res); if (!got_end_timer) diff --git a/mysql-test/include/have_multi_ndb.inc b/mysql-test/include/have_multi_ndb.inc index ec1a93311fb..45a551274f7 100644 --- a/mysql-test/include/have_multi_ndb.inc +++ b/mysql-test/include/have_multi_ndb.inc @@ -9,8 +9,8 @@ disable_query_log; drop table if exists t1, t2; --enable_warnings flush tables; -@r/have_ndb.require show variables like "have_ndbcluster"; -# @r/server_id.require show variables like "server_id"; +--require r/have_ndb.require +show variables like "have_ndbcluster"; enable_query_log; # Check that server2 has NDB support @@ -20,8 +20,8 @@ disable_query_log; drop table if exists t1, t2; --enable_warnings flush tables; -@r/have_ndb.require show variables like "have_ndbcluster"; -# @r/server_id1.require show variables like "server_id"; +--require r/have_ndb.require +show variables like "have_ndbcluster"; enable_query_log; # Set the default connection to 'server1' diff --git a/mysql-test/r/init_file.result b/mysql-test/r/init_file.result new file mode 100644 index 00000000000..9766475a418 --- /dev/null +++ b/mysql-test/r/init_file.result @@ -0,0 +1 @@ +ok diff --git a/mysql-test/r/mysql_client_test.result b/mysql-test/r/mysql_client_test.result new file mode 100644 index 00000000000..9766475a418 --- /dev/null +++ b/mysql-test/r/mysql_client_test.result @@ -0,0 +1 @@ +ok diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index df4c2091f3b..22c7fb02f00 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -331,6 +331,7 @@ mysqltest: At line 1: Wrong number of arguments to replace_result in 'replace_re mysqltest: At line 1: Wrong number of arguments to replace_result in 'replace_result a;' mysqltest: At line 1: Wrong number of arguments to replace_result in 'replace_result a' mysqltest: At line 1: Wrong number of arguments to replace_result in 'replace_result a ' +OK mysqltest: At line 1: Wrong number of arguments to replace_result in 'replace_result a b c' mysqltest: At line 1: Wrong number of arguments to replace_result in 'replace_result a b c ' select "a" as col1, "c" as col2; @@ -356,6 +357,7 @@ mysqltest: At line 1: Missing connection db mysqltest: At line 1: Could not open connection 'con2': Unknown database 'illegal_db' mysqltest: At line 1: Illegal argument for port: 'illegal_port' mysqltest: At line 1: Illegal option to connect: SMTP +OK mysqltest: In included file "./var/tmp/con.sql": At line 7: Connection limit exhausted - increase MAX_CONS in mysqltest.c mysqltest: In included file "./var/tmp/con.sql": At line 3: connection 'test_con1' not found in connection pool mysqltest: In included file "./var/tmp/con.sql": At line 2: Connection test_con1 already exists @@ -394,3 +396,5 @@ root@localhost -------------------------------------------------------------------------------- this will be executed this will be executed +mysqltest: Result length mismatch +mysqltest: The test didn't produce any output diff --git a/mysql-test/t/init_file.test b/mysql-test/t/init_file.test index de6aca455bd..8b4b788777b 100644 --- a/mysql-test/t/init_file.test +++ b/mysql-test/t/init_file.test @@ -7,3 +7,4 @@ # # End of 4.1 tests +echo ok; diff --git a/mysql-test/t/mysql_client_test.test b/mysql-test/t/mysql_client_test.test index 66b57dd5fb7..9cacb008d09 100644 --- a/mysql-test/t/mysql_client_test.test +++ b/mysql-test/t/mysql_client_test.test @@ -10,3 +10,5 @@ --exec $MYSQL_CLIENT_TEST --getopt-ll-test=25600M # End of 4.1 tests +echo ok; + diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index 26e25af2a8d..f229b5cdc1d 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -368,10 +368,10 @@ select 3 from t1 ; # Missing delimiter until eof # The comment will be "sucked into" the sleep command since # delimiter is missing ---system echo "sleep 7" > var/log/mysqltest.sql ---system echo "# Another comment" >> var/log/mysqltest.sql +--system echo "sleep 7" > var/tmp/mysqltest.sql +--system echo "# Another comment" >> var/tmp/mysqltest.sql --error 1 ---exec $MYSQL_TEST < var/log/mysqltest.sql 2>&1 +--exec $MYSQL_TEST < var/tmp/mysqltest.sql 2>&1 # # Extra delimiter @@ -737,20 +737,20 @@ while ($i) --error 1 --exec echo "{;" | $MYSQL_TEST 2>&1 ---system echo "while (0)" > var/log/mysqltest.sql ---system echo "echo hej;" >> var/log/mysqltest.sql +--system echo "while (0)" > var/tmp/mysqltest.sql +--system echo "echo hej;" >> var/tmp/mysqltest.sql --error 1 ---exec $MYSQL_TEST < var/log/mysqltest.sql 2>&1 +--exec $MYSQL_TEST < var/tmp/mysqltest.sql 2>&1 ---system echo "while (0)" > var/log/mysqltest.sql ---system echo "{echo hej;" >> var/log/mysqltest.sql +--system echo "while (0)" > var/tmp/mysqltest.sql +--system echo "{echo hej;" >> var/tmp/mysqltest.sql --error 1 ---exec $MYSQL_TEST < var/log/mysqltest.sql 2>&1 +--exec $MYSQL_TEST < var/tmp/mysqltest.sql 2>&1 ---system echo "while (0){" > var/log/mysqltest.sql ---system echo "echo hej;" >> var/log/mysqltest.sql +--system echo "while (0){" > var/tmp/mysqltest.sql +--system echo "echo hej;" >> var/tmp/mysqltest.sql --error 1 ---exec $MYSQL_TEST < var/log/mysqltest.sql 2>&1 +--exec $MYSQL_TEST < var/tmp/mysqltest.sql 2>&1 # ---------------------------------------------------------------------------- # Test error messages returned from comments starting with a command @@ -778,7 +778,7 @@ select "a" as col1, "c" as col2; --exec echo "replace_result a;" | $MYSQL_TEST 2>&1 --error 1 --exec echo "replace_result a ;" | $MYSQL_TEST 2>&1 ---exec echo "replace_result a b;" | $MYSQL_TEST 2>&1 +--exec echo "replace_result a b; echo OK;" | $MYSQL_TEST 2>&1 --error 1 --exec echo "--replace_result a b c" | $MYSQL_TEST 2>&1 --error 1 @@ -848,7 +848,7 @@ select "a" as col1, "c" as col2; --exec echo " disconnect test_con1; " >> var/tmp/con.sql --exec echo " dec \$i; " >> var/tmp/con.sql --exec echo "}" >> var/tmp/con.sql ---exec echo "source var/tmp/con.sql;" | $MYSQL_TEST 2>&1 +--exec echo "source var/tmp/con.sql; echo OK;" | $MYSQL_TEST 2>&1 # Repeat connect/disconnect, exceed max number of connections --exec echo "let \$i=200;" > var/tmp/con.sql @@ -954,3 +954,29 @@ select "this will not be executed"; --enable_parsing select "this will be executed"; --enable_query_log + +# +# Test zero length result file. Should not pass +# +--exec touch $MYSQL_TEST_DIR/var/tmp/zero_length_file.result +--exec echo "echo ok;" > $MYSQL_TEST_DIR/var/tmp/query.sql +--error 1 +--exec $MYSQL_TEST -x var/tmp/query.sql -R var/tmp/zero_length_file.result 2>&1 +# +# Test that a test file that does not generate any output fails. +# +--exec echo "let \$i= 1;" > $MYSQL_TEST_DIR/var/tmp/query.sql +--error 1 +--exec $MYSQL_TEST -x var/tmp/query.sql 2>&1 + +# +# Test that mysqltest fails when there are no queries executed +# but a result file exist +# NOTE! This will never happen as long as it's not allowed to have +# test files that does not produce any output +#--exec echo "something" > $MYSQL_TEST_DIR/var/tmp/result_file.result +#--exec echo "let \$i= 1;" > $MYSQL_TEST_DIR/var/tmp/query.sql +#--error 1 +#--exec $MYSQL_TEST -x var/tmp/query.sql -R var/tmp/result_file.result 2>&1 + + From 0e545776c7373650528453c80d6846ade15c6d0a Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 6 Dec 2005 21:34:35 +0100 Subject: [PATCH 08/68] Improved valgrinding of mysqltest mysql-test/mysql-test-run.sh: Add --valgrind-mysqltest and --valgrind-mysqltest-all Send output from mysqltest(and valgrind messages) to var/log/mysqltest.log --- mysql-test/mysql-test-run.sh | 51 ++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/mysql-test/mysql-test-run.sh b/mysql-test/mysql-test-run.sh index 2133043a587..517ce0420e6 100644 --- a/mysql-test/mysql-test-run.sh +++ b/mysql-test/mysql-test-run.sh @@ -110,6 +110,20 @@ wait_for_pid() #$WAIT_PID pid $SLEEP_TIME_FOR_DELETE } +# Check that valgrind is installed +find_valgrind() +{ + FIND_VALGRIND=`which valgrind` # this will print an error if not found + # Give good warning to the user and stop + if [ -z "$FIND_VALGRIND" ] ; then + $ECHO "You need to have the 'valgrind' program in your PATH to run mysql-test-run with option --valgrind. Valgrind's home page is http://valgrind.kde.org ." + exit 1 + fi + # >=2.1.2 requires the --tool option, some versions write to stdout, some to stderr + valgrind --help 2>&1 | grep "\-\-tool" > /dev/null && FIND_VALGRIND="$FIND_VALGRIND --tool=memcheck" + FIND_VALGRIND="$FIND_VALGRIND --alignment=8 --leak-check=yes --num-callers=16 --suppressions=$CWD/valgrind.supp" +} + # No paths below as we can't be sure where the program is! SED=sed @@ -255,7 +269,6 @@ DO_GDB="" MANUAL_GDB="" DO_DDD="" DO_CLIENT_GDB="" -DO_VALGRIND_MYSQL_TEST="" SLEEP_TIME_AFTER_RESTART=1 SLEEP_TIME_FOR_DELETE=10 SLEEP_TIME_FOR_FIRST_MASTER=400 # Enough time to create innodb tables @@ -470,15 +483,8 @@ while test $# -gt 0; do EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --gdb" ;; --valgrind | --valgrind-all) - VALGRIND=`which valgrind` # this will print an error if not found - # Give good warning to the user and stop - if [ -z "$VALGRIND" ] ; then - $ECHO "You need to have the 'valgrind' program in your PATH to run mysql-test-run with option --valgrind. Valgrind's home page is http://valgrind.kde.org ." - exit 1 - fi - # >=2.1.2 requires the --tool option, some versions write to stdout, some to stderr - valgrind --help 2>&1 | grep "\-\-tool" > /dev/null && VALGRIND="$VALGRIND --tool=memcheck" - VALGRIND="$VALGRIND --alignment=8 --leak-check=yes --num-callers=16 --suppressions=$CWD/valgrind.supp" + find_valgrind; + VALGRIND=$FIND_VALGRIND EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --skip-safemalloc --skip-bdb" EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --skip-safemalloc --skip-bdb" SLEEP_TIME_AFTER_RESTART=10 @@ -493,8 +499,13 @@ while test $# -gt 0; do TMP=`$ECHO "$1" | $SED -e "s;--valgrind-options=;;"` VALGRIND="$VALGRIND $TMP" ;; - --valgrind-mysqltest) - DO_VALGRIND_MYSQL_TEST=1 + --valgrind-mysqltest | --valgrind-mysqltest-all) + find_valgrind; + VALGRIND_MYSQLTEST=$FIND_VALGRIND + if test "$1" = "--valgrind-mysqltest-all" + then + VALGRIND_MYSQLTEST="$VALGRIND_MYSQLTEST -v --show-reachable=yes" + fi ;; --skip-ndbcluster | --skip-ndb) USE_NDBCLUSTER="" @@ -599,7 +610,7 @@ DASH72=`$ECHO '-------------------------------------------------------'|$CUT -c if [ x$SOURCE_DIST = x1 ] ; then if [ "x$USE_EMBEDDED_SERVER" = "x1" ] ; then if [ -f "$BASEDIR/libmysqld/examples/mysqltest_embedded" ] ; then - MYSQL_TEST="$VALGRIND $BASEDIR/libmysqld/examples/mysqltest_embedded" + MYSQL_TEST="$BASEDIR/libmysqld/examples/mysqltest_embedded" else echo "Fatal error: Cannot find embedded server 'mysqltest_embedded'" 1>&2 exit 1 @@ -733,7 +744,7 @@ else fi if [ "x$USE_EMBEDDED_SERVER" = "x1" ] ; then if [ -f "$CLIENT_BINDIR/mysqltest_embedded" ] ; then - MYSQL_TEST="$VALGRIND $CLIENT_BINDIR/mysqltest_embedded" + MYSQL_TEST="$CLIENT_BINDIR/mysqltest_embedded" else echo "Fatal error: Cannot find embedded server 'mysqltest_embedded'" 1>&2 exit 1 @@ -744,7 +755,7 @@ else MYSQL_CLIENT_TEST="$CLIENT_BINDIR/mysql_client_test_embedded" fi else - MYSQL_TEST="$VALGRIND_MYSQLTEST $CLIENT_BINDIR/mysqltest" + MYSQL_TEST="$CLIENT_BINDIR/mysqltest" MYSQL_CLIENT_TEST="$CLIENT_BINDIR/mysql_client_test" fi fi @@ -759,8 +770,9 @@ then SLAVE_MYSQLD=$MYSQLD fi -if [ x$DO_VALGRIND_MYSQL_TEST = x1 ] ; then - MYSQL_TEST="$VALGRIND $MYSQL_TEST" +# If mysqltest should be valgrinded, add valgrind and options to MYSQL_TEST +if ! [ -z "$VALGRIND_MYSQLTEST" ] ; then + MYSQL_TEST="$VALGRIND_MYSQLTEST $MYSQL_TEST" fi # If we should run all tests cases, we will use a local server for that @@ -829,6 +841,7 @@ GPROF_DIR=$MYSQL_TMP_DIR/gprof GPROF_MASTER=$GPROF_DIR/master.gprof GPROF_SLAVE=$GPROF_DIR/slave.gprof TIMEFILE="$MYSQL_TEST_DIR/var/log/mysqltest-time" +MYSQLTEST_LOG="$MYSQL_TEST_DIR/var/log/mysqltest.log" if [ -n "$DO_CLIENT_GDB" -o -n "$DO_GDB" ] ; then XTERM=`which xterm` fi @@ -1774,6 +1787,10 @@ run_testcase () res=$? + # Save the testcase log to mysqltest log file + echo "CURRENT_TEST: $tname" >> $MYSQLTEST_LOG + cat $TIMEFILE >> $MYSQLTEST_LOG + pname=`$ECHO "$tname "|$CUT -c 1-24` RES="$pname" From 861dc95767bd412d9ee2688bc8943352bf110fe4 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 7 Dec 2005 14:52:37 +0100 Subject: [PATCH 09/68] Fix memory leak client/mysqltest.c: Call my_regex_end to free global memory allocated regex library --- client/mysqltest.c | 1 + 1 file changed, 1 insertion(+) diff --git a/client/mysqltest.c b/client/mysqltest.c index 91791145db5..285aa0fe033 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -4015,6 +4015,7 @@ static void free_re(void) my_regfree(&ps_re); my_regfree(&sp_re); my_regfree(&view_re); + my_regex_end(); } /****************************************************************************/ From 1b50a968033b0644fe63fb231a564aa1b7b1d0bf Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 7 Dec 2005 14:54:06 +0100 Subject: [PATCH 10/68] valgrind for mysqltest mysql-test/mysql-test-run.sh: Dont add valgrind to the MYSQL_TEST variable --- mysql-test/mysql-test-run.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mysql-test/mysql-test-run.sh b/mysql-test/mysql-test-run.sh index 517ce0420e6..3a8aa8614a2 100644 --- a/mysql-test/mysql-test-run.sh +++ b/mysql-test/mysql-test-run.sh @@ -770,11 +770,6 @@ then SLAVE_MYSQLD=$MYSQLD fi -# If mysqltest should be valgrinded, add valgrind and options to MYSQL_TEST -if ! [ -z "$VALGRIND_MYSQLTEST" ] ; then - MYSQL_TEST="$VALGRIND_MYSQLTEST $MYSQL_TEST" -fi - # If we should run all tests cases, we will use a local server for that if [ -z "$1" -a -z "$DO_STRESS" ] @@ -831,7 +826,10 @@ if [ x$USE_TIMER = x1 ] ; then fi MYSQL_TEST_BIN=$MYSQL_TEST MYSQL_TEST="$MYSQL_TEST $MYSQL_TEST_ARGS" + +# Export MYSQL_TEST variable for use from .test files export MYSQL_TEST + GDB_CLIENT_INIT=$MYSQL_TMP_DIR/gdbinit.client GDB_MASTER_INIT=$MYSQL_TMP_DIR/gdbinit.master GDB_SLAVE_INIT=$MYSQL_TMP_DIR/gdbinit.slave @@ -1780,7 +1778,7 @@ run_testcase () $RM -f r/$tname.*reject mysql_test_args="-R $result_file $EXTRA_MYSQL_TEST_OPT" if [ -z "$DO_CLIENT_GDB" ] ; then - `$MYSQL_TEST $mysql_test_args < $tf 2> $TIMEFILE`; + `$VALGRIND_MYSQLTEST $MYSQL_TEST $mysql_test_args < $tf 2> $TIMEFILE`; else do_gdb_test "$mysql_test_args" "$tf" fi From d8f7fb14259c24bb90d6b7368524e45e7a5ad409 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 8 Dec 2005 16:48:37 +0100 Subject: [PATCH 11/68] WL#2930 mysqltest++ - Updated after valgrinding client/mysqltest.c: Move initialisation of dynamic strings to top of function so that variables are always inited before free The workaround for 15518 moved to last in function Add check for "--" comments without any comment,. to avoid read of uninit memory mysql-test/mysql-test-run.sh: Add printout of valgrind errors from mysqltest when test with valgrind has completed --- client/mysqltest.c | 22 +++++++++++++--------- mysql-test/mysql-test-run.sh | 12 ++++++++++++ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 285aa0fe033..60dfb7a48a7 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -2676,6 +2676,7 @@ int read_query(struct st_query** q_ptr) end: while (*p && my_isspace(charset_info, *p)) p++; + if (!(q->query_buf= q->query= my_strdup(p, MYF(MY_WME)))) die(NullS); @@ -3573,6 +3574,13 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, cur_con->stmt= stmt; } + /* Init dynamic strings for warnings */ + if (!disable_warnings) + { + init_dynamic_string(&ds_prepare_warnings, NULL, 0, 256); + init_dynamic_string(&ds_execute_warnings, NULL, 0, 256); + } + /* Prepare the query */ @@ -3580,10 +3588,6 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, { handle_error(query, command, mysql_stmt_errno(stmt), mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt), ds); -#ifndef BUG15518_FIXED - mysql_stmt_close(stmt); - cur_con->stmt= NULL; -#endif goto end; } @@ -3592,12 +3596,7 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, separate string */ if (!disable_warnings) - { - init_dynamic_string(&ds_prepare_warnings, NULL, 0, 256); - init_dynamic_string(&ds_execute_warnings, NULL, 0, 256); append_warnings(&ds_prepare_warnings, mysql); - } - /* No need to call mysql_stmt_bind_param() because we have no @@ -3724,6 +3723,10 @@ end: variable then can be used from the test case itself. */ var_set_errno(mysql_stmt_errno(stmt)); +#ifndef BUG15518_FIXED + mysql_stmt_close(stmt); + cur_con->stmt= NULL; +#endif DBUG_VOID_RETURN; } @@ -4050,6 +4053,7 @@ void get_query_type(struct st_query* q) q->type= Q_COMMENT; } else if (q->type == Q_COMMENT_WITH_COMMAND && + q->first_word_len && q->query[q->first_word_len-1] == ';') { /* diff --git a/mysql-test/mysql-test-run.sh b/mysql-test/mysql-test-run.sh index 3a8aa8614a2..3454873bca4 100644 --- a/mysql-test/mysql-test-run.sh +++ b/mysql-test/mysql-test-run.sh @@ -1002,6 +1002,18 @@ report_stats () { echo "WARNING: Got errors/warnings while running tests. Please examine" echo "$MY_LOG_DIR/warnings for details." fi + + fi # USE_RUNNING_SERVER + + # Check valgrind errors from mysqltest + if [ ! -z "$VALGRIND_MYSQLTEST" ] + then + if $GREP "ERROR SUMMARY" $MYSQLTEST_LOG | $GREP -v "0 errors" > /dev/null + then + $ECHO "Valgrind detected errors!" + $GREP "ERROR SUMMARY" $MYSQLTEST_LOG | $GREP -v "0 errors" + $ECHO "See $MYSQLTEST_LOG" + fi fi } From 9bf7a9ce148e240a72dad9566c1b175f43fff3ad Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 9 Dec 2005 17:52:29 +0100 Subject: [PATCH 12/68] Made it easier to valgrind mysqltest mysql-test/mysql-test-run.pl: Append mysqltest-time to mysqltest.log at the end of each test case, thus making it possibel to run the whole testsuite with --valgrind-mysqltest and then check the valgrind ouput in mysqltest.log Don't valgrind mysqld when only --valgrind-mysqltest is specified Fix usage --valgrind, will only valgrind mysqld(that's how it was, I didn't change) --- mysql-test/mysql-test-run.pl | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index a1d051846ee..17cc470f1c3 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -151,6 +151,7 @@ our $path_client_bindir; our $path_language; our $path_timefile; our $path_manager_log; # Used by mysqldadmin +our $path_mysqltest_log; our $path_slave_load_tmpdir; # What is this?! our $path_my_basedir; our $opt_vardir; # A path but set directly on cmd line @@ -270,6 +271,7 @@ our $opt_user; our $opt_user_test; our $opt_valgrind; +our $opt_valgrind_mysqld; our $opt_valgrind_mysqltest; our $opt_valgrind_all; our $opt_valgrind_options; @@ -742,6 +744,7 @@ sub command_line_setup () { # "somestring" option is name/path of valgrind executable # Take executable path from any of them, if any + $opt_valgrind_mysqld= $opt_valgrind; $opt_valgrind= $opt_valgrind_mysqltest if $opt_valgrind_mysqltest; $opt_valgrind= $opt_valgrind_all if $opt_valgrind_all; @@ -885,6 +888,7 @@ sub command_line_setup () { } $path_timefile= "$opt_vardir/log/mysqltest-time"; + $path_mysqltest_log= "$opt_vardir/log/mysqltest.log"; } @@ -929,7 +933,19 @@ sub executable_setup () { } else { - $exe_mysqltest= mtr_exe_exists("$path_client_bindir/mysqltest"); + if ( $opt_valgrind_mysqltest ) + { + # client/mysqltest might be a libtool .sh script, so look for real exe + # to avoid valgrinding bash ;) + $exe_mysqltest= + mtr_exe_exists("$path_client_bindir/.libs/lt-mysqltest", + "$path_client_bindir/.libs/mysqltest", + "$path_client_bindir/mysqltest"); + } + else + { + $exe_mysqltest= mtr_exe_exists("$path_client_bindir/mysqltest"); + } $exe_mysql_client_test= mtr_exe_exists("$glob_basedir/tests/mysql_client_test", "/usr/bin/false"); @@ -1859,6 +1875,11 @@ sub run_testcase ($) { } report_failure_and_restart($tinfo); } + # Save info from this testcase run to mysqltest.log + mtr_tofile($path_mysqltest_log,"CURRENT TEST $tname\n"); + my $testcase_log= mtr_fromfile($path_timefile); + mtr_tofile($path_mysqltest_log, + $testcase_log); } # ---------------------------------------------------------------------- @@ -2019,7 +2040,7 @@ sub mysqld_arguments ($$$$$) { mtr_add_arg($args, "%s--language=%s", $prefix, $path_language); mtr_add_arg($args, "%s--tmpdir=$opt_tmpdir", $prefix); - if ( defined $opt_valgrind ) + if ( defined $opt_valgrind_mysqld ) { mtr_add_arg($args, "%s--skip-safemalloc", $prefix); mtr_add_arg($args, "%s--skip-bdb", $prefix); @@ -2245,7 +2266,7 @@ sub mysqld_start ($$$$) { mtr_init_args(\$args); - if ( defined $opt_valgrind ) + if ( defined $opt_valgrind_mysqld ) { valgrind_arguments($args, \$exe); } @@ -2699,6 +2720,7 @@ sub valgrind_arguments { mtr_add_arg($args, split(' ', $opt_valgrind_options)); } + mtr_add_arg($args, $$exe); $$exe= $opt_valgrind || "valgrind"; @@ -2778,9 +2800,8 @@ Options for coverage, profiling etc gcov FIXME gprof FIXME - valgrind[=EXE] Run the "mysqltest" executable as well as the "mysqld" - server using valgrind, optionally specifying the - executable path/name + valgrind[=EXE] Run the "mysqld" server using valgrind, optionally + specifying the executable path/name valgrind-mysqltest[=EXE] In addition, run the "mysqltest" executable with valgrind valgrind-all[=EXE] Adds verbose flag, and --show-reachable to valgrind valgrind-options=ARGS Extra options to give valgrind From 361655780d8a367f20fe9c3d547c9a7685888e5d Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 9 Dec 2005 18:51:45 +0100 Subject: [PATCH 13/68] Fix warnings for running with --view_protocol client/mysqltest.c: Collect warnings from creating the "object" for the query and ouput those after the query has been executed --- client/mysqltest.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 60dfb7a48a7..b500c3dbe1a 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -3269,6 +3269,8 @@ static int append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql) append_result(ds, warn_res); mysql_free_result(warn_res); + DBUG_PRINT("warnings", ("%s", ds->str)); + DBUG_RETURN(count); } @@ -3292,11 +3294,10 @@ static int append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql) static void run_query_normal(MYSQL *mysql, struct st_query *command, int flags, char *query, int query_len, - DYNAMIC_STRING *ds) + DYNAMIC_STRING *ds, DYNAMIC_STRING *ds_warnings) { MYSQL_RES *res= 0; int err= 0, counter= 0; - DYNAMIC_STRING ds_warnings; DBUG_ENTER("run_query_normal"); DBUG_PRINT("enter",("flags: %d", flags)); DBUG_PRINT("enter", ("query: '%-.60s'", query)); @@ -3375,13 +3376,11 @@ static void run_query_normal(MYSQL *mysql, struct st_query *command, */ if (!disable_warnings && !mysql_more_results(mysql)) { - init_dynamic_string(&ds_warnings, NULL, 0, 256); - if (append_warnings(&ds_warnings, mysql)) + if (append_warnings(ds_warnings, mysql) || ds_warnings->length) { dynstr_append_mem(ds, "Warnings:\n", 10); - dynstr_append_mem(ds, ds_warnings.str, ds_warnings.length); + dynstr_append_mem(ds, ds_warnings->str, ds_warnings->length); } - dynstr_free(&ds_warnings); } if (!disable_info) @@ -3555,7 +3554,8 @@ static void handle_no_error(struct st_query *q) */ static void run_query_stmt(MYSQL *mysql, struct st_query *command, - char *query, int query_len, DYNAMIC_STRING *ds) + char *query, int query_len, DYNAMIC_STRING *ds, + DYNAMIC_STRING *ds_warnings) { MYSQL_RES *res= NULL; /* Note that here 'res' is meta data result set */ MYSQL_STMT *stmt; @@ -3691,9 +3691,13 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, /* Append warnings to ds - if there are any */ if (append_warnings(&ds_execute_warnings, mysql) || - ds_prepare_warnings.length) + ds_prepare_warnings.length || + ds_warnings->length) { dynstr_append_mem(ds, "Warnings:\n", 10); + if (ds_warnings->length) + dynstr_append_mem(ds, ds_warnings->str, + ds_warnings->length); if (ds_prepare_warnings.length) dynstr_append_mem(ds, ds_prepare_warnings.str, ds_prepare_warnings.length); @@ -3749,12 +3753,15 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) { DYNAMIC_STRING *ds; DYNAMIC_STRING ds_result; + DYNAMIC_STRING ds_warnings; DYNAMIC_STRING eval_query; char *query; int query_len; my_bool view_created= 0, sp_created= 0; my_bool complete_query= ((flags & QUERY_SEND) && (flags & QUERY_REAP)); + init_dynamic_string(&ds_warnings, NULL, 0, 256); + /* Evaluate query if this is an eval command */ @@ -3830,6 +3837,12 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) view_created= 1; query= (char*)"SELECT * FROM mysqltest_tmp_v"; query_len = strlen(query); + + /* + Collect warnings from create of the view that should otherwise + have been produced when the SELECT was executed + */ + append_warnings(&ds_warnings, mysql); } dynstr_free(&query_str); @@ -3888,9 +3901,10 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) if (ps_protocol_enabled && complete_query && match_re(&ps_re, query)) - run_query_stmt(mysql, command, query, query_len, ds); + run_query_stmt(mysql, command, query, query_len, ds, &ds_warnings); else - run_query_normal(mysql, command, flags, query, query_len, ds); + run_query_normal(mysql, command, flags, query, query_len, + ds, &ds_warnings); if (sp_created) { @@ -3923,6 +3937,7 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) check_result(ds, command->record_file, command->require_file); } + dynstr_free(&ds_warnings); if (ds == &ds_result) dynstr_free(&ds_result); if (command->type == Q_EVAL) From 4d09673065bba0434909ad09b7f9ecd82752c8db Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 9 Dec 2005 15:00:33 -0800 Subject: [PATCH 14/68] Fix crash in BDB from improper cleanup of transactions, and avoid problem in NDB that the fix would cause due to improper registration of a transaction that isn't meant to be seen by the handler layer. (Bug #14212) Thanks to Sergei Golubchik for helping with this. mysql-test/r/bdb.result: Add new result mysql-test/t/bdb.test: Add new regression test sql/ha_ndbcluster.cc: Don't register transaction if transactions are "disabled". sql/handler.cc: Commit statement before trying to end transaction. --- mysql-test/r/bdb.result | 5 +++++ mysql-test/t/bdb.test | 11 +++++++++++ sql/ha_ndbcluster.cc | 14 ++++++++------ sql/handler.cc | 3 ++- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/mysql-test/r/bdb.result b/mysql-test/r/bdb.result index 2bba44d36e9..dd251eed0f0 100644 --- a/mysql-test/r/bdb.result +++ b/mysql-test/r/bdb.result @@ -1895,3 +1895,8 @@ t1 CREATE TABLE `t1` ( ) ENGINE=BerkeleyDB DEFAULT CHARSET=latin1 drop table t1; set storage_engine=MyISAM; +set autocommit=0; +create table t1 (a int) engine=bdb; +commit; +alter table t1 add primary key(a); +drop table t1; diff --git a/mysql-test/t/bdb.test b/mysql-test/t/bdb.test index 3167682f816..bf72a4555b8 100644 --- a/mysql-test/t/bdb.test +++ b/mysql-test/t/bdb.test @@ -973,3 +973,14 @@ drop table t1; # End varchar test eval set storage_engine=$default; + +# +# Bug #14212: Server crash after COMMIT + ALTER TABLE +# +set autocommit=0; +create table t1 (a int) engine=bdb; +commit; +alter table t1 add primary key(a); +drop table t1; + +# End of 5.0 tests diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index a0efcd2c4f9..b3d5d86dc52 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -3221,6 +3221,10 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type) if (lock_type != F_UNLCK) { DBUG_PRINT("info", ("lock_type != F_UNLCK")); + if (!thd->transaction.on) + m_transaction_on= FALSE; + else + m_transaction_on= thd->variables.ndb_use_transactions; if (!thd_ndb->lock_count++) { PRINT_OPTION_FLAGS(thd); @@ -3235,7 +3239,8 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type) ERR_RETURN(ndb->getNdbError()); no_uncommitted_rows_reset(thd); thd_ndb->stmt= trans; - trans_register_ha(thd, FALSE, &ndbcluster_hton); + if (m_transaction_on) + trans_register_ha(thd, FALSE, &ndbcluster_hton); } else { @@ -3250,7 +3255,8 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type) ERR_RETURN(ndb->getNdbError()); no_uncommitted_rows_reset(thd); thd_ndb->all= trans; - trans_register_ha(thd, TRUE, &ndbcluster_hton); + if (m_transaction_on) + trans_register_ha(thd, TRUE, &ndbcluster_hton); /* If this is the start of a LOCK TABLE, a table look @@ -3284,10 +3290,6 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type) m_ha_not_exact_count= !thd->variables.ndb_use_exact_count; m_autoincrement_prefetch= (ha_rows) thd->variables.ndb_autoincrement_prefetch_sz; - if (!thd->transaction.on) - m_transaction_on= FALSE; - else - m_transaction_on= thd->variables.ndb_use_transactions; m_active_trans= thd_ndb->all ? thd_ndb->all : thd_ndb->stmt; DBUG_ASSERT(m_active_trans); diff --git a/sql/handler.cc b/sql/handler.cc index 81e94af5dc7..416455c9bb9 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1910,7 +1910,8 @@ int ha_enable_transaction(THD *thd, bool on) is an optimization hint that storage engine is free to ignore. So, let's commit an open transaction (if any) now. */ - error= end_trans(thd, COMMIT); + if (!(error= ha_commit_stmt(thd))) + error= end_trans(thd, COMMIT); } DBUG_RETURN(error); } From 637232d90bf9c0a7eae7c3a56f8a9889a6b1f971 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 13 Dec 2005 18:07:13 +0100 Subject: [PATCH 15/68] Fix tests after merge Straighten out and comment behaviour for --require and --result in run_query client/mysqltest.c: If --require or --result has been provided for a query command->record_file file be set. In that case it should either dump to file if recording or check with content in file if running. mysql-test/r/mysqltest.result: Fix up tests and results after merge mysql-test/t/mysqltest.test: Fix up tests and results after merge --- client/mysqltest.c | 32 ++++++++++++++++++-------------- mysql-test/r/mysqltest.result | 17 ++++++++--------- mysql-test/t/mysqltest.test | 18 +++++++++--------- 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 135fa370688..3f8b6582eb9 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -3925,22 +3925,26 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) mysql_errno(mysql), mysql_error(mysql)); } - if (record) + if (command->record_file[0]) { - /* Recording in progress */ - if (!command->record_file[0]) - die("Missing result file"); - /* Dump the output from _this_ query to the specified record_file */ - str_to_file(command->record_file, ds->str, ds->length); - } - else if (command->record_file[0]) - { - /* - The output from _this_ query should be checked against an already - existing file which has been specified using --require or --result - */ - check_result(ds, command->record_file, command->require_file); + /* A result file was specified for _this_ query */ + if (record) + { + /* + Recording in progress + Dump the output from _this_ query to the specified record_file + */ + str_to_file(command->record_file, ds->str, ds->length); + + } else { + + /* + The output from _this_ query should be checked against an already + existing file which has been specified using --require or --result + */ + check_result(ds, command->record_file, command->require_file); + } } dynstr_free(&ds_warnings); diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index 8ea3a48e948..2e78f468f93 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -396,12 +396,20 @@ root@localhost -------------------------------------------------------------------------------- this will be executed this will be executed +mysqltest: Result length mismatch +mysqltest: The test didn't produce any output +Failing multi statement query mysqltest: At line 3: query 'create table t1 (a int primary key); insert into t1 values (1); select 'select-me'; insertz 'error query'' failed: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'insertz 'error query'' at line 1 drop table t1; +mysqltest: At line 3: query 'create table t1 (a int primary key); +insert into t1 values (1); +select 'select-me'; +insertz 'error query'' failed: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'insertz 'error query'' at line 1 drop table t1; +Multi statement using expected error create table t1 (a int primary key); insert into t1 values (1); select 'select-me'; @@ -410,13 +418,4 @@ select-me select-me ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'insertz error query' at line 1 drop table t1; -create table t1 (a int primary key); -insert into t1 values (1); -select 'select-me'; -insertz error query|||| -select-me -select-me -ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'insertz error query' at line 1 drop table t1; -mysqltest: Result length mismatch -mysqltest: The test didn't produce any output diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index 1d22705fb8e..132a6329178 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -984,7 +984,7 @@ select "this will be executed"; # non-1st queries # -# Failing multi statement query +echo Failing multi statement query; # PS does not support multi statement --exec echo "--disable_ps_protocol" > var/tmp/bug11731.sql --exec echo "delimiter ||||;" >> var/tmp/bug11731.sql @@ -999,14 +999,13 @@ select "this will be executed"; drop table t1; --error 1 ---exec $MYSQL_TEST --record -x $MYSQL_TEST_DIR/var/tmp/bug11731.sql -R $MYSQL_TEST_DIR/var/tmp/bug11731.out -# The .out file should be empty, cat will fail! ---error 1 ---exec cat $MYSQL_TEST_DIR/var/tmp/bug11731.out +--exec $MYSQL_TEST --record -x $MYSQL_TEST_DIR/var/tmp/bug11731.sql -R $MYSQL_TEST_DIR/var/tmp/bug11731.out 2>&1 +# The .out file should be non existent +--exec test ! -e $MYSQL_TEST_DIR/var/tmp/bug11731.out drop table t1; -# Using expected error +echo Multi statement using expected error; # PS does not support multi statement --exec echo "--disable_ps_protocol" > var/tmp/bug11731.sql --exec echo "delimiter ||||;" >> var/tmp/bug11731.sql @@ -1018,11 +1017,12 @@ drop table t1; --exec echo "delimiter ;||||" >> var/tmp/bug11731.sql # These two should work since the error is expected ---exec $MYSQL_TEST -x $MYSQL_TEST_DIR/var/tmp/bug11731.sql 2>&1 +--exec $MYSQL_TEST -x $MYSQL_TEST_DIR/var/tmp/bug11731.sql 2>&1 drop table t1; ---exec $MYSQL_TEST --record -x $MYSQL_TEST_DIR/var/tmp/bug11731.sql -R $MYSQL_TEST_DIR/var/tmp/bug11731.out ---exec cat $MYSQL_TEST_DIR/var/tmp/bug11731.out +--exec $MYSQL_TEST --record -x $MYSQL_TEST_DIR/var/tmp/bug11731.sql -R $MYSQL_TEST_DIR/var/tmp/bug11731.out 2>&1 +# The .out file should exist +--exec test -s $MYSQL_TEST_DIR/var/tmp/bug11731.out drop table t1; From 152b89c96e4008be0afc5ebe40652aa2de8ed865 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 13 Dec 2005 18:10:53 +0100 Subject: [PATCH 16/68] Remove confusing printout client/mysqltest.c: Remove printout to stderr about expected failure of a command, if we want it logged, it has already been logged to the result. --- client/mysqltest.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 3f8b6582eb9..8938df1944f 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -3500,12 +3500,6 @@ static void handle_error(const char *query, struct st_query *q, q->query, err_sqlstate, q->expected_errno[0].code.sqlstate); } - /* - If we do not abort on error, failure to run the query does not fail the - whole test case. - */ - verbose_msg("query '%s' failed: %d: %s", q->query, err_errno, - err_error); DBUG_VOID_RETURN; } From 58de4d7e28c782341bc2160bd93fcaeb8f9dfd01 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 13 Dec 2005 18:47:34 +0100 Subject: [PATCH 17/68] Remove confusing printouts from expected to fail "system" commands client/mysqltest.c: Add missing DBUG_VOID_RETURN Log failure to run "system" into result log Add DBUG_PRINT for the sleep value used in do_sleep mysql-test/r/mysqltest.result: Update test results mysql-test/t/mysqltest.test: Mask outpu from failed system command --- client/mysqltest.c | 12 ++++++++++-- mysql-test/r/mysqltest.result | 1 + mysql-test/t/mysqltest.test | 3 +-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 8938df1944f..7ba8dc31405 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -1134,6 +1134,7 @@ static void do_exec(struct st_query *query) } free_replace(); + DBUG_VOID_RETURN; } @@ -1300,10 +1301,13 @@ int do_modify_var(struct st_query *query, const char *name, int do_system(struct st_query *q) { + DYNAMIC_STRING *ds; char *p=q->first_argument; VAR v; var_init(&v, 0, 0, 0, 0); eval_expr(&v, p, 0); /* NULL terminated */ + ds= &ds_res; + if (v.str_val_len) { char expr_buf[1024]; @@ -1316,8 +1320,11 @@ int do_system(struct st_query *q) { if (q->abort_on_error) die("system command '%s' failed", expr_buf); - /* If ! abort_on_error, display message and continue */ - verbose_msg("system command '%s' failed", expr_buf); + + /* If ! abort_on_error, log message and continue */ + dynstr_append(ds, "system command '"); + replace_dynstr_append(ds, expr_buf); + dynstr_append(ds, "' failed\n"); } } else @@ -1582,6 +1589,7 @@ int do_sleep(struct st_query *query, my_bool real_sleep) if (opt_sleep && !real_sleep) sleep_val= opt_sleep; + DBUG_PRINT("info", ("sleep_val: %f", sleep_val)); my_sleep((ulong) (sleep_val * 1000000L)); query->last_argument= sleep_end; return 0; diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index 2e78f468f93..0109436fac9 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -304,6 +304,7 @@ mysqltest: At line 1: End of line junk detected: "1000" mysqltest: At line 1: Missing arguments to system, nothing to do! mysqltest: At line 1: Missing arguments to system, nothing to do! mysqltest: At line 1: system command 'false' failed +system command 'NonExistsinfComamdn 2> /dev/null' failed test test2 test3 diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index 132a6329178..3d851605823 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -689,7 +689,7 @@ system echo "hej" > /dev/null; --exec echo "system false;" | $MYSQL_TEST 2>&1 --disable_abort_on_error -system NonExistsinfComamdn; +system NonExistsinfComamdn 2> /dev/null; --enable_abort_on_error @@ -1026,4 +1026,3 @@ drop table t1; drop table t1; - From 4e82e0af516d47aeb34b37f8b64865509189bcf5 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 14 Dec 2005 15:01:02 -0800 Subject: [PATCH 18/68] Fix crash when trying to open table using a disabled storage engine. (Bug #15185) sql/handler.cc: Don't create handler object for engines that are disabled. --- sql/handler.cc | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/sql/handler.cc b/sql/handler.cc index 47010de3002..5a0e0d27b40 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -300,39 +300,56 @@ handler *get_new_handler(TABLE *table, MEM_ROOT *alloc, enum db_type db_type) case DB_TYPE_HASH: return new (alloc) ha_hash(table); #endif + case DB_TYPE_MRG_MYISAM: case DB_TYPE_MRG_ISAM: return new (alloc) ha_myisammrg(table); #ifdef HAVE_BERKELEY_DB case DB_TYPE_BERKELEY_DB: - return new (alloc) ha_berkeley(table); + if (have_berkeley_db == SHOW_OPTION_YES) + return new (alloc) ha_berkeley(table); + return NULL; #endif #ifdef HAVE_INNOBASE_DB case DB_TYPE_INNODB: - return new (alloc) ha_innobase(table); + if (have_innodb == SHOW_OPTION_YES) + return new (alloc) ha_innobase(table); + return NULL; #endif #ifdef HAVE_EXAMPLE_DB case DB_TYPE_EXAMPLE_DB: - return new (alloc) ha_example(table); + if (have_example_db == SHOW_OPTION_YES) + return new (alloc) ha_example(table); + return NULL; #endif #if defined(HAVE_ARCHIVE_DB) && !defined(__NETWARE__) case DB_TYPE_ARCHIVE_DB: - return new (alloc) ha_archive(table); + if (have_archive_db == SHOW_OPTION_YES) + return new (alloc) ha_archive(table); + return NULL; #endif #ifdef HAVE_BLACKHOLE_DB case DB_TYPE_BLACKHOLE_DB: - return new (alloc) ha_blackhole(table); + if (have_blackhole_db == SHOW_OPTION_YES) + return new (alloc) ha_blackhole(table); + return NULL; #endif #ifdef HAVE_FEDERATED_DB case DB_TYPE_FEDERATED_DB: - return new (alloc) ha_federated(table); + if (have_federated_db == SHOW_OPTION_YES) + return new (alloc) ha_federated(table); + return NULL; #endif #ifdef HAVE_CSV_DB case DB_TYPE_CSV_DB: - return new (alloc) ha_tina(table); + if (have_csv_db == SHOW_OPTION_YES) + return new (alloc) ha_tina(table); + return NULL; #endif #ifdef HAVE_NDBCLUSTER_DB case DB_TYPE_NDBCLUSTER: - return new (alloc) ha_ndbcluster(table); + if (have_ndbcluster == SHOW_OPTION_YES) + return new (alloc) ha_ndbcluster(table); + return NULL; #endif case DB_TYPE_HEAP: return new (alloc) ha_heap(table); @@ -346,8 +363,6 @@ handler *get_new_handler(TABLE *table, MEM_ROOT *alloc, enum db_type db_type) /* Fall back to MyISAM */ case DB_TYPE_MYISAM: return new (alloc) ha_myisam(table); - case DB_TYPE_MRG_MYISAM: - return new (alloc) ha_myisammrg(table); } } From e1c614134078b23934555bd76c6cdbd039d8bc28 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 19 Dec 2005 15:52:10 +0400 Subject: [PATCH 19/68] Bug#15581: COALESCE function truncates mutli-byte TINYTEXT values field.cc: BLOB variations have number-in-bytes limit, unlike CHAR/VARCHAR which have number-of-characters limits. A tinyblob column can store up to 255 bytes. In the case of basic Latin letters (which use 1 byte per character) we can store up to 255 characters in a tinyblob column. When passing an utf8 tinyblob column as an argument into a function (e.g. COALESCE) we need to reserve 3*255 bytes. I.e. multiply length in bytes to mbcharlen for the character set. Although in reality a tinyblob column can never be 3*255 bytes long, we need to set max_length to multiply to make fix_length_and_dec() of the function-caller (e.g. COALESCE) calculate the correct max_length for the column being created. ctype_utf8.result, ctype_utf8.test: Adding test case. mysql-test/t/ctype_utf8.test: Adding test case. mysql-test/r/ctype_utf8.result: Adding test case. sql/field.cc: Bug#15581: COALESCE function truncates mutli-byte TINYTEXT values BLOB variations have byte limits, unlike CHAR/VARCHAR which have number-of-character limits. It means tinyblob can store up to 255 bytes. All of them can be basic latin letters which use 1 byte per character. I.e. we can store up to 255 characters in a tinyblob column. When passing a tinyblob column as an argument into a function (for example COALESCE or CONCAT) we need to reserve 3*255 bytes in the case of utf-8. I.e. multiply length in bytes to mbcharlen for the character set. --- mysql-test/r/ctype_utf8.result | 8 ++++++++ mysql-test/t/ctype_utf8.test | 10 ++++++++++ sql/field.cc | 6 +++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index 03d3ab9f22e..cf9426e6b21 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -1070,3 +1070,11 @@ char(a) 1 2 drop table t1; +CREATE TABLE t1 (t TINYTEXT CHARACTER SET utf8); +INSERT INTO t1 VALUES(REPEAT('a', 100)); +CREATE TEMPORARY TABLE t2 SELECT COALESCE(t) AS bug FROM t1; +SELECT LENGTH(bug) FROM t2; +LENGTH(bug) +100 +DROP TABLE t2; +DROP TABLE t1; diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index 8c0e03c0cd3..01bffe9492e 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -882,4 +882,14 @@ set names utf8; select distinct char(a) from t1; drop table t1; +# +# Bug#15581: COALESCE function truncates mutli-byte TINYTEXT values +# +CREATE TABLE t1 (t TINYTEXT CHARACTER SET utf8); +INSERT INTO t1 VALUES(REPEAT('a', 100)); +CREATE TEMPORARY TABLE t2 SELECT COALESCE(t) AS bug FROM t1; +SELECT LENGTH(bug) FROM t2; +DROP TABLE t2; +DROP TABLE t1; + # End of 4.1 tests diff --git a/sql/field.cc b/sql/field.cc index abb5297f458..b1d9167aee2 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -6949,11 +6949,11 @@ uint32 Field_blob::max_length() switch (packlength) { case 1: - return 255; + return 255 * field_charset->mbmaxlen; case 2: - return 65535; + return 65535 * field_charset->mbmaxlen; case 3: - return 16777215; + return 16777215 * field_charset->mbmaxlen; case 4: return (uint32) 4294967295U; default: From 867e01d9fe77c2b808e772d8328237928f350bf3 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 20 Dec 2005 15:34:58 +0100 Subject: [PATCH 20/68] Store the each column from a multi column result set into a separate variable. client/mysqltest.c: Update var_query_set to store every column from a query into a separate variable. The whole result will still be stored as tab separated string in the var that let points at. mysql-test/r/mysqltest.result: Add test results mysql-test/t/mysqltest.test: Add tests for "one variable for each column" from let. --- client/mysqltest.c | 68 +++++++++++++++++++++++++++-------- mysql-test/r/mysqltest.result | 19 ++++++++++ mysql-test/t/mysqltest.test | 36 +++++++++++++++++++ 3 files changed, 109 insertions(+), 14 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 7ba8dc31405..e709dc64ef4 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -1137,26 +1137,50 @@ static void do_exec(struct st_query *query) DBUG_VOID_RETURN; } +/* + Set variable from the result of a query -int var_query_set(VAR* v, const char *p, const char** p_end) + SYNOPSIS + var_query_set() + var variable to set from query + query start of query string to execute + query_end end of the query string to execute + + + DESCRIPTION + let @ = `` + + Execute the query and assign the first row of result to var as + a tab separated strings + + Also assign each column of the result set to + variable "$_" + Thus the tab separated output can be read from $ and + and each individual column can be read as $_ + +*/ + +int var_query_set(VAR* var, const char *query, const char** query_end) { - char* end = (char*)((p_end && *p_end) ? *p_end : p + strlen(p)); + char* end = (char*)((query_end && *query_end) ? + *query_end : query + strlen(query)); MYSQL_RES *res; MYSQL_ROW row; MYSQL* mysql = &cur_con->mysql; LINT_INIT(res); - while (end > p && *end != '`') + while (end > query && *end != '`') --end; - if (p == end) + if (query == end) die("Syntax error in query, missing '`'"); - ++p; + ++query; - if (mysql_real_query(mysql, p, (int)(end - p)) || + if (mysql_real_query(mysql, query, (int)(end - query)) || !(res = mysql_store_result(mysql))) { *end = 0; - die("Error running query '%s': %s", p, mysql_error(mysql)); + die("Error running query '%s': %d: %s", query, + mysql_errno(mysql) ,mysql_error(mysql)); } if ((row = mysql_fetch_row(res)) && row[0]) @@ -1169,21 +1193,39 @@ int var_query_set(VAR* v, const char *p, const char** p_end) uint i; ulong *lengths; char *end; + MYSQL_FIELD *fields= mysql_fetch_fields(res); init_dynamic_string(&result, "", 16384, 65536); lengths= mysql_fetch_lengths(res); for (i=0; i < mysql_num_fields(res); i++) { if (row[0]) + { + /* Add to _ */ + uint j; + char var_col_name[MAX_VAR_NAME]; + uint length= snprintf(var_col_name, MAX_VAR_NAME, + "$%s_%s", var->name, fields[i].name); + /* Convert characters not allowed in variable names to '_' */ + for (j= 1; j < length; j++) + { + if (!my_isvar(charset_info,var_col_name[j])) + var_col_name[j]= '_'; + } + var_set(var_col_name, var_col_name + length, + row[i], row[i] + lengths[i]); + + /* Add column to tab separated string */ dynstr_append_mem(&result, row[i], lengths[i]); + } dynstr_append_mem(&result, "\t", 1); } end= result.str + result.length-1; - eval_expr(v, result.str, (const char**) &end); + eval_expr(var, result.str, (const char**) &end); dynstr_free(&result); } else - eval_expr(v, "", 0); + eval_expr(var, "", 0); mysql_free_result(res); return 0; @@ -4129,12 +4171,10 @@ static VAR *var_init(VAR *v, const char *name, int name_len, const char *val, if (!(tmp_var->str_val = my_malloc(val_alloc_len+1, MYF(MY_WME)))) die("Out of memory"); - memcpy(tmp_var->name, name, name_len); + if (name) + strmake(tmp_var->name, name, name_len); if (val) - { - memcpy(tmp_var->str_val, val, val_len); - tmp_var->str_val[val_len]=0; - } + strmake(tmp_var->str_val, val, val_len); tmp_var->name_len = name_len; tmp_var->str_val_len = val_len; tmp_var->alloced_len = val_alloc_len; diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index 0109436fac9..bf3821555cc 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -222,6 +222,25 @@ mysqltest: At line 1: Missing arguments to let mysqltest: At line 1: Missing variable name in let mysqltest: At line 1: Variable name in =hi does not start with '$' mysqltest: At line 1: Missing assignment operator in let +var1 +hi 1 hi there +hi +1 +hi there +var2 +2 + + +var2 again +2 + +2 + +var3 two columns with same name +1 2 3 +2 +2 +3 mysqltest: At line 1: Missing file name in source mysqltest: At line 1: Could not open file ./non_existingFile mysqltest: In included file "./var/tmp/recursive.sql": At line 1: Source directives are nesting too deep diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index 3d851605823..ae28a66c685 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -539,6 +539,42 @@ echo $novar1; --error 1 --exec echo "let hi;" | $MYSQL_TEST 2>&1 +# ---------------------------------------------------------------------------- +# Test to assign let from query +# let $=``; +# ---------------------------------------------------------------------------- + +echo var1; +let $var1= `select "hi" as "Col", 1 as "Column1", "hi there" as Col3`; +echo $var1; +echo $var1_Col; +echo $var1_Column1; +echo $var1_Col3; + +echo var2; +let $var2= `select 2 as "Column num 2"`; +echo $var2; +echo $var2_Column num 2; +echo $var2_Column; + +echo var2 again; +let $var2= `select 2 as "Column num 2"`; +echo $var2; +echo $var2_Column num 2; +echo $var2_Column_num_2; +echo $var2_Column; + +echo var3 two columns with same name; +let $var3= `select 1 as "Col", 2 as "Col", 3 as "var3"`; +echo $var3; +echo $var3_Col; +echo $var3_Col; +echo $var3_var3; + +#echo failing query in let; +#--error 1 +#--exec echo "let $var2= `failing query;`" | $MYSQL_TEST 2>&1 + # ---------------------------------------------------------------------------- # Test source command # ---------------------------------------------------------------------------- From 79476010fd4b9d84eef9bba962b6afb9e8ab12ac Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 20 Dec 2005 17:06:20 +0100 Subject: [PATCH 21/68] Avoid implicit commits by using a different connection when creating/dropping sp's and views. client/mysqltest.c: Use a different mysql connection when creating/dropping views and sp's. --- client/mysqltest.c | 74 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 17 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index e709dc64ef4..16ae7702857 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -247,6 +247,8 @@ typedef struct struct connection { MYSQL mysql; + /* Used when creating views and sp, to avoid implicit commit */ + MYSQL* util_mysql; char *name; MYSQL_STMT* stmt; }; @@ -551,6 +553,8 @@ static void close_cons() mysql_stmt_close(next_con->stmt); next_con->stmt= 0; mysql_close(&next_con->mysql); + if (next_con->util_mysql) + mysql_close(next_con->util_mysql); my_free(next_con->name, MYF(MY_ALLOW_ZERO_PTR)); } DBUG_VOID_RETURN; @@ -1948,6 +1952,9 @@ int close_connection(struct st_query *q) } #endif mysql_close(&con->mysql); + if (con->util_mysql) + mysql_close(con->util_mysql); + con->util_mysql= 0; my_free(con->name, MYF(0)); /* When the connection is closed set name to "closed_connection" @@ -2040,16 +2047,15 @@ void init_manager() 0 - success, non-0 - failure */ -int safe_connect(MYSQL* con, const char *host, const char *user, - const char *pass, - const char *db, int port, const char *sock) +int safe_connect(MYSQL* mysql, const char *host, const char *user, + const char *pass, const char *db, int port, const char *sock) { int con_error= 1; my_bool reconnect= 1; int i; for (i= 0; i < MAX_CON_TRIES; ++i) { - if (mysql_real_connect(con, host,user, pass, db, port, sock, + if (mysql_real_connect(mysql, host,user, pass, db, port, sock, CLIENT_MULTI_STATEMENTS | CLIENT_REMEMBER_OPTIONS)) { con_error= 0; @@ -2061,7 +2067,7 @@ int safe_connect(MYSQL* con, const char *host, const char *user, TODO: change this to 0 in future versions, but the 'kill' test relies on existing behavior */ - mysql_options(con, MYSQL_OPT_RECONNECT, (char *)&reconnect); + mysql_options(mysql, MYSQL_OPT_RECONNECT, (char *)&reconnect); return con_error; } @@ -2305,10 +2311,10 @@ int do_connect(struct st_query *q) con_db= 0; if (q->abort_on_error) { - if ((safe_connect(&next_con->mysql, con_host, con_user, con_pass, - con_db, con_port, con_sock ? con_sock: 0))) - die("Could not open connection '%s': %s", con_name, - mysql_error(&next_con->mysql)); + if (safe_connect(&next_con->mysql, con_host, con_user, con_pass, + con_db, con_port, con_sock ? con_sock: 0)) + die("Could not open connection '%s': %d %s", con_name, + mysql_errno(&next_con->mysql), mysql_error(&next_con->mysql)); } else error= connect_n_handle_errors(q, &next_con->mysql, con_host, con_user, @@ -3785,6 +3791,39 @@ end: } + +/* + Create a util connection if one does not already exists + and use that to run the query + This is done to avoid implict commit when creating/dropping objects such + as view, sp etc. +*/ + +static int util_query(MYSQL* org_mysql, const char* query){ + + MYSQL* mysql; + DBUG_ENTER("util_query"); + + if(!(mysql= cur_con->util_mysql)) + { + DBUG_PRINT("info", ("Creating util_mysql")); + if (!(mysql= mysql_init(mysql))) + die("Failed in mysql_init()"); + + if (safe_connect(mysql, org_mysql->host, org_mysql->user, + org_mysql->passwd, org_mysql->db, org_mysql->port, + org_mysql->unix_socket)) + die("Could not open util connection: %d %s", + mysql_errno(mysql), mysql_error(mysql)); + + cur_con->util_mysql= mysql; + } + + return mysql_query(mysql, query); +} + + + /* Run query @@ -3865,7 +3904,7 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) "CREATE OR REPLACE VIEW mysqltest_tmp_v AS ", query_len+64, 256); dynstr_append_mem(&query_str, query, query_len); - if (mysql_query(mysql, query_str.str)) + if (util_query(mysql, query_str.str)) { /* Failed to create the view, this is not fatal @@ -3892,7 +3931,7 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) Collect warnings from create of the view that should otherwise have been produced when the SELECT was executed */ - append_warnings(&ds_warnings, mysql); + append_warnings(&ds_warnings, cur_con->util_mysql); } dynstr_free(&query_str); @@ -3909,12 +3948,12 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) */ DYNAMIC_STRING query_str; init_dynamic_string(&query_str, - "DROP PROCEDURE IF EXISTS mysqltest_tmp_sp;\n", + "DROP PROCEDURE IF EXISTS mysqltest_tmp_sp;", query_len+64, 256); - mysql_query(mysql, query_str.str); + util_query(mysql, query_str.str); dynstr_set(&query_str, "CREATE PROCEDURE mysqltest_tmp_sp()\n"); dynstr_append_mem(&query_str, query, query_len); - if (mysql_query(mysql, query_str.str)) + if (util_query(mysql, query_str.str)) { /* Failed to create the stored procedure for this query, @@ -3958,13 +3997,13 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) if (sp_created) { - if (mysql_query(mysql, "DROP PROCEDURE mysqltest_tmp_sp ")) + if (util_query(mysql, "DROP PROCEDURE mysqltest_tmp_sp ")) die("Failed to drop sp: %d: %s", mysql_errno(mysql), mysql_error(mysql)); } if (view_created) { - if (mysql_query(mysql, "DROP VIEW mysqltest_tmp_v ")) + if (util_query(mysql, "DROP VIEW mysqltest_tmp_v ")) die("Failed to drop view: %d: %s", mysql_errno(mysql), mysql_error(mysql)); } @@ -4299,7 +4338,8 @@ int main(int argc, char **argv) die("Out of memory"); if (safe_connect(&cur_con->mysql, host, user, pass, db, port, unix_sock)) - die("Failed in mysql_real_connect(): %s", mysql_error(&cur_con->mysql)); + die("Could not open connection '%s': %d %s", cur_con->name, + mysql_errno(&cur_con->mysql), mysql_error(&cur_con->mysql)); init_var_hash(&cur_con->mysql); From c6a723260f3347cb9d7fe8ae2d9bacca9b82c485 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 29 Dec 2005 09:48:43 +0100 Subject: [PATCH 22/68] Improved error message for failing with wrong error client/mysqltest.c: Display the error message along with error number when query fails with wrong expected error. mysql-test/r/mysqltest.result: Update test results --- client/mysqltest.c | 9 +++++---- mysql-test/r/mysqltest.result | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 16ae7702857..7e7f2699ac7 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -3549,11 +3549,12 @@ static void handle_error(const char *query, struct st_query *q, if (i) { if (q->expected_errno[0].type == ERR_ERRNO) - die("query '%s' failed with wrong errno %d instead of %d...", - q->query, err_errno, q->expected_errno[0].code.errnum); + die("query '%s' failed with wrong errno %d: '%s', instead of %d...", + q->query, err_errno, err_error, q->expected_errno[0].code.errnum); else - die("query '%s' failed with wrong sqlstate %s instead of %s...", - q->query, err_sqlstate, q->expected_errno[0].code.sqlstate); + die("query '%s' failed with wrong sqlstate %s: '%s', instead of %s...", + q->query, err_sqlstate, err_error, + q->expected_errno[0].code.sqlstate); } DBUG_VOID_RETURN; diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index bf3821555cc..2657fb8a409 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -16,7 +16,7 @@ otto mysqltest: At line 1: query 'select otto from (select 1 as otto) as t1' succeeded - should have failed with sqlstate 42S22... select friedrich from (select 1 as otto) as t1; ERROR 42S22: Unknown column 'friedrich' in 'field list' -mysqltest: At line 1: query 'select friedrich from (select 1 as otto) as t1' failed with wrong sqlstate 42S22 instead of 00000... +mysqltest: At line 1: query 'select friedrich from (select 1 as otto) as t1' failed with wrong sqlstate 42S22: 'Unknown column 'friedrich' in 'field list'', instead of 00000... select otto from (select 1 as otto) as t1; otto 1 @@ -133,7 +133,7 @@ ERROR 42S02: Table 'test.t1' doesn't exist select 1146 as "after_!errno_masked_error" ; after_!errno_masked_error 1146 -mysqltest: At line 1: query 'select 3 from t1' failed with wrong errno 1146 instead of 1000... +mysqltest: At line 1: query 'select 3 from t1' failed with wrong errno 1146: 'Table 'test.t1' doesn't exist', instead of 1000... garbage ; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'garbage' at line 1 select 1064 as "after_--enable_abort_on_error" ; @@ -141,7 +141,7 @@ after_--enable_abort_on_error 1064 select 3 from t1 ; ERROR 42S02: Table 'test.t1' doesn't exist -mysqltest: At line 1: query 'select 3 from t1' failed with wrong errno 1146 instead of 1064... +mysqltest: At line 1: query 'select 3 from t1' failed with wrong errno 1146: 'Table 'test.t1' doesn't exist', instead of 1064... hello hello ;;;;;;;; @@ -374,7 +374,7 @@ mysqltest: At line 1: Missing connection user mysqltest: At line 1: Missing connection user mysqltest: At line 1: Missing connection password mysqltest: At line 1: Missing connection db -mysqltest: At line 1: Could not open connection 'con2': Unknown database 'illegal_db' +mysqltest: At line 1: Could not open connection 'con2': 1049 Unknown database 'illegal_db' mysqltest: At line 1: Illegal argument for port: 'illegal_port' mysqltest: At line 1: Illegal option to connect: SMTP OK From d105ee3cc6451b6cbafc77fcdccc0b13810150fc Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 31 Dec 2005 10:54:36 +0100 Subject: [PATCH 23/68] ndb - wl#2972 (4.1) copy detached trigger fix from 5.0 ndb/src/kernel/blocks/dbtup/DbtupCommit.cpp: detached trigger fix from 5.0 --- ndb/src/kernel/blocks/dbtup/DbtupCommit.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ndb/src/kernel/blocks/dbtup/DbtupCommit.cpp b/ndb/src/kernel/blocks/dbtup/DbtupCommit.cpp index 470b98fd04c..e16d3df6d8d 100644 --- a/ndb/src/kernel/blocks/dbtup/DbtupCommit.cpp +++ b/ndb/src/kernel/blocks/dbtup/DbtupCommit.cpp @@ -445,6 +445,7 @@ Dbtup::commitRecord(Signal* signal, befOpPtr.p->changeMask.bitOR(attributeMask); befOpPtr.p->gci = regOperPtr->gci; + befOpPtr.p->optype = opType; operPtr.p = befOpPtr.p; checkDetachedTriggers(signal, befOpPtr.p, @@ -483,6 +484,7 @@ Dbtup::commitRecord(Signal* signal, befOpPtr.p->pageIndex = befOpPtr.p->pageIndexC; befOpPtr.p->gci = regOperPtr->gci; + befOpPtr.p->optype = opType; operPtr.p = befOpPtr.p; checkDetachedTriggers(signal, befOpPtr.p, From 5e7cbbcbbcb871432cf513c89cd5240c754cde29 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 3 Jan 2006 14:25:19 +0400 Subject: [PATCH 24/68] Fix for bug#15533 crash, information_schema, function, view enable view prepared mode during getting metedata for I_S table mysql-test/r/information_schema.result: Fix for bug#15533 crash, information_schema, function, view test case mysql-test/t/information_schema.test: Fix for bug#15533 crash, information_schema, function, view test case --- mysql-test/r/information_schema.result | 16 ++++++++++++++++ mysql-test/t/information_schema.test | 23 +++++++++++++++++++++++ sql/sql_show.cc | 3 +++ 3 files changed, 42 insertions(+) diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index e8d343ad711..05f2118a8c7 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -1074,3 +1074,19 @@ character_maximum_length character_octet_length 32 32 64 64 drop table t1; +CREATE TABLE t1 (f1 BIGINT, f2 VARCHAR(20), f3 BIGINT); +INSERT INTO t1 SET f1 = 1, f2 = 'Schoenenbourg', f3 = 1; +CREATE FUNCTION func2() RETURNS BIGINT RETURN 1; +CREATE FUNCTION func1() RETURNS BIGINT +BEGIN +RETURN ( SELECT COUNT(*) FROM INFORMATION_SCHEMA.VIEWS); +END// +CREATE VIEW v1 AS SELECT 1 FROM t1 +WHERE f3 = (SELECT func2 ()); +SELECT func1(); +func1() +1 +DROP TABLE t1; +DROP VIEW v1; +DROP FUNCTION func1; +DROP FUNCTION func2; diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test index b05798b781f..f835a7148a2 100644 --- a/mysql-test/t/information_schema.test +++ b/mysql-test/t/information_schema.test @@ -767,3 +767,26 @@ create table t1(f1 binary(32), f2 varbinary(64)); select character_maximum_length, character_octet_length from information_schema.columns where table_name='t1'; drop table t1; + +# +# Bug#15533 crash, information_schema, function, view +# +CREATE TABLE t1 (f1 BIGINT, f2 VARCHAR(20), f3 BIGINT); +INSERT INTO t1 SET f1 = 1, f2 = 'Schoenenbourg', f3 = 1; + +CREATE FUNCTION func2() RETURNS BIGINT RETURN 1; + +delimiter //; +CREATE FUNCTION func1() RETURNS BIGINT +BEGIN + RETURN ( SELECT COUNT(*) FROM INFORMATION_SCHEMA.VIEWS); +END// +delimiter ;// + +CREATE VIEW v1 AS SELECT 1 FROM t1 + WHERE f3 = (SELECT func2 ()); +SELECT func1(); +DROP TABLE t1; +DROP VIEW v1; +DROP FUNCTION func1; +DROP FUNCTION func2; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 1b31e8f7dc3..089314078a6 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -2045,6 +2045,8 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) int error= 1; db_type not_used; Open_tables_state open_tables_state_backup; + bool save_view_prepare_mode= lex->view_prepare_mode; + lex->view_prepare_mode= TRUE; DBUG_ENTER("get_all_tables"); LINT_INIT(end); @@ -2230,6 +2232,7 @@ err: lex->derived_tables= derived_tables; lex->all_selects_list= old_all_select_lex; lex->query_tables_last= save_query_tables_last; + lex->view_prepare_mode= save_view_prepare_mode; *save_query_tables_last= 0; lex->sql_command= save_sql_command; DBUG_RETURN(error); From e1fdf8b4f9b47aa5fc2590961c1f21e87b562824 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Jan 2006 10:32:52 +0100 Subject: [PATCH 25/68] Avoid double slash (//) in socket paths, breaks on QNX. --- mysql-test/mysql-test-run.pl | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index d64a487758d..2c53b94a248 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -804,6 +804,12 @@ sub command_line_setup () { } } + # On QNX, /tmp/dir/master.sock and /tmp/dir//master.sock seem to be + # considered different, so avoid the extra slash (/) in the socket + # paths. + my $sockdir = $opt_tmpdir; + $sockdir =~ s|/+$||; + # Put this into a hash, will be a C struct $master->[0]= @@ -812,7 +818,7 @@ sub command_line_setup () { path_myerr => "$opt_vardir/log/master.err", path_mylog => "$opt_vardir/log/master.log", path_mypid => "$opt_vardir/run/master.pid", - path_mysock => "$opt_tmpdir/master.sock", + path_mysock => "$sockdir/master.sock", path_myport => $opt_master_myport, start_timeout => 400, # enough time create innodb tables @@ -825,7 +831,7 @@ sub command_line_setup () { path_myerr => "$opt_vardir/log/master1.err", path_mylog => "$opt_vardir/log/master1.log", path_mypid => "$opt_vardir/run/master1.pid", - path_mysock => "$opt_tmpdir/master1.sock", + path_mysock => "$sockdir/master1.sock", path_myport => $opt_master_myport + 1, start_timeout => 400, # enough time create innodb tables }; @@ -836,7 +842,7 @@ sub command_line_setup () { path_myerr => "$opt_vardir/log/slave.err", path_mylog => "$opt_vardir/log/slave.log", path_mypid => "$opt_vardir/run/slave.pid", - path_mysock => "$opt_tmpdir/slave.sock", + path_mysock => "$sockdir/slave.sock", path_myport => $opt_slave_myport, start_timeout => 400, }; @@ -847,7 +853,7 @@ sub command_line_setup () { path_myerr => "$opt_vardir/log/slave1.err", path_mylog => "$opt_vardir/log/slave1.log", path_mypid => "$opt_vardir/run/slave1.pid", - path_mysock => "$opt_tmpdir/slave1.sock", + path_mysock => "$sockdir/slave1.sock", path_myport => $opt_slave_myport + 1, start_timeout => 300, }; @@ -858,7 +864,7 @@ sub command_line_setup () { path_myerr => "$opt_vardir/log/slave2.err", path_mylog => "$opt_vardir/log/slave2.log", path_mypid => "$opt_vardir/run/slave2.pid", - path_mysock => "$opt_tmpdir/slave2.sock", + path_mysock => "$sockdir/slave2.sock", path_myport => $opt_slave_myport + 2, start_timeout => 300, }; @@ -868,7 +874,7 @@ sub command_line_setup () { path_err => "$opt_vardir/log/im.err", path_log => "$opt_vardir/log/im.log", path_pid => "$opt_vardir/run/im.pid", - path_sock => "$opt_tmpdir/im.sock", + path_sock => "$sockdir/im.sock", port => $im_port, start_timeout => $master->[0]->{'start_timeout'}, admin_login => 'im_admin', @@ -883,7 +889,7 @@ sub command_line_setup () { server_id => 1, port => $im_mysqld1_port, path_datadir => "$opt_vardir/im_mysqld_1.data", - path_sock => "$opt_tmpdir/mysqld_1.sock", + path_sock => "$sockdir/mysqld_1.sock", path_pid => "$opt_vardir/run/mysqld_1.pid", }; @@ -892,7 +898,7 @@ sub command_line_setup () { server_id => 2, port => $im_mysqld2_port, path_datadir => "$opt_vardir/im_mysqld_2.data", - path_sock => "$opt_tmpdir/mysqld_2.sock", + path_sock => "$sockdir/mysqld_2.sock", path_pid => "$opt_vardir/run/mysqld_2.pid", nonguarded => 1, }; From 95cecbf815ee7db84a681181d083dd97b96d1c58 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Jan 2006 15:25:32 +0100 Subject: [PATCH 26/68] BUG#14931: Temporarily add synchronization to avoid sporadic test failures until the bug is fixed. mysql-test/r/rpl_sp.result: BUG#14931: Temporarily add synchronization to avoid sporadic failures until the bug is fixed. mysql-test/t/rpl_sp.test: BUG#14931: Temporarily add synchronization to avoid sporadic failures until the bug is fixed. --- mysql-test/r/rpl_sp.result | 3 +++ mysql-test/t/rpl_sp.test | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/mysql-test/r/rpl_sp.result b/mysql-test/r/rpl_sp.result index 41bcfc7d72c..c9a9e162fa6 100644 --- a/mysql-test/r/rpl_sp.result +++ b/mysql-test/r/rpl_sp.result @@ -57,6 +57,9 @@ insert into t1 values (15); grant CREATE ROUTINE, EXECUTE on mysqltest1.* to "zedjzlcsjhd"@127.0.0.1; grant SELECT on mysqltest1.t1 to "zedjzlcsjhd"@127.0.0.1; grant SELECT, INSERT on mysqltest1.t2 to "zedjzlcsjhd"@127.0.0.1; +SELECT 1; +1 +1 create procedure foo4() deterministic begin diff --git a/mysql-test/t/rpl_sp.test b/mysql-test/t/rpl_sp.test index 386582f8f1b..8fa330584e2 100644 --- a/mysql-test/t/rpl_sp.test +++ b/mysql-test/t/rpl_sp.test @@ -87,6 +87,14 @@ grant CREATE ROUTINE, EXECUTE on mysqltest1.* to "zedjzlcsjhd"@127.0.0.1; grant SELECT on mysqltest1.t1 to "zedjzlcsjhd"@127.0.0.1; grant SELECT, INSERT on mysqltest1.t2 to "zedjzlcsjhd"@127.0.0.1; +# ToDo: BUG#14931: There is a race between the last grant binlogging, and +# the binlogging in the new connection made below, causing sporadic test +# failures due to switched statement order in binlog. To fix this we do +# SELECT 1 in the first connection before starting the second, ensuring +# that binlogging is done in the expected order. +# Please remove this SELECT 1 when BUG#14931 is fixed. +SELECT 1; + connect (con1,127.0.0.1,zedjzlcsjhd,,mysqltest1,$MASTER_MYPORT,); connection con1; From f577d864cdac14d9a5cf7714b3506bab7688b1c7 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Jan 2006 17:35:30 +0300 Subject: [PATCH 27/68] A fix for Bug#7209 "Client error with "Access Denied" on updates when high concurrency": remove HASH::current_record and make it an external search parameter, so that it can not be the cause of a race condition under high concurrent load. The bug was in a race condition in table_hash_search, when column_priv_hash.current_record was overwritten simultaneously by multiple threads, causing the search for a suitable grant record to fail. No test case as the bug is repeatable only under concurrent load. include/hash.h: - remove current_record from HASH, instead modify hash_first, hash_next to accept HASH_SEARCH_STATE as an IN/OUT parameter mysys/hash.c: - remove HASH::current_record - change declarations of functions that use HASH in read-only mode to accept const HASH * instead of HASH *. - implement hash_search; move the old implementation of hash_search to hash_first mysys/testhash.c: - adjust the test case to changed function declarations sql/lock.cc: - adjust to changed declarations of hash_search, hash_next sql/sql_acl.cc: - adjust to changed declarations of hash_search, hash_next sql/sql_base.cc: - adjust to changed declarations of hash_search, hash_nex sql/sql_cache.cc: - adjust to a changed declaration of hash_replace --- include/hash.h | 14 +++++++---- mysys/hash.c | 60 ++++++++++++++++++++++++++++-------------------- mysys/testhash.c | 9 ++++---- sql/lock.cc | 5 ++-- sql/sql_acl.cc | 9 ++++---- sql/sql_base.cc | 22 ++++++++++++------ sql/sql_cache.cc | 10 ++++---- 7 files changed, 79 insertions(+), 50 deletions(-) diff --git a/include/hash.h b/include/hash.h index 9a6d91036e1..8f5ff21ae5e 100644 --- a/include/hash.h +++ b/include/hash.h @@ -33,7 +33,7 @@ typedef void (*hash_free_key)(void *); typedef struct st_hash { uint key_offset,key_length; /* Length of key if const length */ - uint records,blength,current_record; + uint records, blength; uint flags; DYNAMIC_ARRAY array; /* Place for hash_keys */ hash_get_key get_key; @@ -41,6 +41,9 @@ typedef struct st_hash { CHARSET_INFO *charset; } HASH; +/* A search iterator state */ +typedef uint HASH_SEARCH_STATE; + #define hash_init(A,B,C,D,E,F,G,H) _hash_init(A,B,C,D,E,F,G, H CALLER_INFO) my_bool _hash_init(HASH *hash, CHARSET_INFO *charset, uint default_array_elements, uint key_offset, @@ -49,12 +52,15 @@ my_bool _hash_init(HASH *hash, CHARSET_INFO *charset, void hash_free(HASH *tree); void my_hash_reset(HASH *hash); byte *hash_element(HASH *hash,uint idx); -gptr hash_search(HASH *info,const byte *key,uint length); -gptr hash_next(HASH *info,const byte *key,uint length); +gptr hash_search(const HASH *info, const byte *key, uint length); +gptr hash_first(const HASH *info, const byte *key, uint length, + HASH_SEARCH_STATE *state); +gptr hash_next(const HASH *info, const byte *key, uint length, + HASH_SEARCH_STATE *state); my_bool my_hash_insert(HASH *info,const byte *data); my_bool hash_delete(HASH *hash,byte *record); my_bool hash_update(HASH *hash,byte *record,byte *old_key,uint old_key_length); -void hash_replace(HASH *hash, uint idx, byte *new_row); +void hash_replace(HASH *hash, HASH_SEARCH_STATE *state, byte *new_row); my_bool hash_check(HASH *hash); /* Only in debug library */ #define hash_clear(H) bzero((char*) (H),sizeof(*(H))) diff --git a/mysys/hash.c b/mysys/hash.c index ffebdf76144..75135a470c9 100644 --- a/mysys/hash.c +++ b/mysys/hash.c @@ -36,9 +36,10 @@ typedef struct st_hash_info { static uint hash_mask(uint hashnr,uint buffmax,uint maxlength); static void movelink(HASH_LINK *array,uint pos,uint next_link,uint newlink); -static int hashcmp(HASH *hash,HASH_LINK *pos,const byte *key,uint length); +static int hashcmp(const HASH *hash, HASH_LINK *pos, const byte *key, + uint length); -static uint calc_hash(HASH *hash,const byte *key,uint length) +static uint calc_hash(const HASH *hash, const byte *key, uint length) { ulong nr1=1, nr2=4; hash->charset->coll->hash_sort(hash->charset,(uchar*) key,length,&nr1,&nr2); @@ -63,7 +64,6 @@ _hash_init(HASH *hash,CHARSET_INFO *charset, hash->key_offset=key_offset; hash->key_length=key_length; hash->blength=1; - hash->current_record= NO_RECORD; /* For the future */ hash->get_key=get_key; hash->free=free_element; hash->flags=flags; @@ -135,7 +135,6 @@ void my_hash_reset(HASH *hash) reset_dynamic(&hash->array); /* Set row pointers so that the hash can be reused at once */ hash->blength= 1; - hash->current_record= NO_RECORD; DBUG_VOID_RETURN; } @@ -147,7 +146,8 @@ void my_hash_reset(HASH *hash) */ static inline char* -hash_key(HASH *hash,const byte *record,uint *length,my_bool first) +hash_key(const HASH *hash, const byte *record, uint *length, + my_bool first) { if (hash->get_key) return (*hash->get_key)(record,length,first); @@ -163,8 +163,8 @@ static uint hash_mask(uint hashnr,uint buffmax,uint maxlength) return (hashnr & ((buffmax >> 1) -1)); } -static uint hash_rec_mask(HASH *hash,HASH_LINK *pos,uint buffmax, - uint maxlength) +static uint hash_rec_mask(const HASH *hash, HASH_LINK *pos, + uint buffmax, uint maxlength) { uint length; byte *key= (byte*) hash_key(hash,pos->data,&length,0); @@ -186,14 +186,25 @@ unsigned int rec_hashnr(HASH *hash,const byte *record) } - /* Search after a record based on a key */ - /* Sets info->current_ptr to found record */ +gptr hash_search(const HASH *hash, const byte *key, uint length) +{ + HASH_SEARCH_STATE state; + return hash_first(hash, key, length, &state); +} -gptr hash_search(HASH *hash,const byte *key,uint length) +/* + Search after a record based on a key + + NOTE + Assigns the number of the found record to HASH_SEARCH_STATE state +*/ + +gptr hash_first(const HASH *hash, const byte *key, uint length, + HASH_SEARCH_STATE *current_record) { HASH_LINK *pos; uint flag,idx; - DBUG_ENTER("hash_search"); + DBUG_ENTER("hash_first"); flag=1; if (hash->records) @@ -206,7 +217,7 @@ gptr hash_search(HASH *hash,const byte *key,uint length) if (!hashcmp(hash,pos,key,length)) { DBUG_PRINT("exit",("found key at %d",idx)); - hash->current_record= idx; + *current_record= idx; DBUG_RETURN (pos->data); } if (flag) @@ -218,31 +229,32 @@ gptr hash_search(HASH *hash,const byte *key,uint length) } while ((idx=pos->next) != NO_RECORD); } - hash->current_record= NO_RECORD; + *current_record= NO_RECORD; DBUG_RETURN(0); } /* Get next record with identical key */ /* Can only be called if previous calls was hash_search */ -gptr hash_next(HASH *hash,const byte *key,uint length) +gptr hash_next(const HASH *hash, const byte *key, uint length, + HASH_SEARCH_STATE *current_record) { HASH_LINK *pos; uint idx; - if (hash->current_record != NO_RECORD) + if (*current_record != NO_RECORD) { HASH_LINK *data=dynamic_element(&hash->array,0,HASH_LINK*); - for (idx=data[hash->current_record].next; idx != NO_RECORD ; idx=pos->next) + for (idx=data[*current_record].next; idx != NO_RECORD ; idx=pos->next) { pos=data+idx; if (!hashcmp(hash,pos,key,length)) { - hash->current_record= idx; + *current_record= idx; return pos->data; } } - hash->current_record=NO_RECORD; + *current_record= NO_RECORD; } return 0; } @@ -282,7 +294,8 @@ static void movelink(HASH_LINK *array,uint find,uint next_link,uint newlink) > 0 key of record > key */ -static int hashcmp(HASH *hash,HASH_LINK *pos,const byte *key,uint length) +static int hashcmp(const HASH *hash, HASH_LINK *pos, const byte *key, + uint length) { uint rec_keylength; byte *rec_key= (byte*) hash_key(hash,pos->data,&rec_keylength,1); @@ -308,7 +321,6 @@ my_bool my_hash_insert(HASH *info,const byte *record) if (!(empty=(HASH_LINK*) alloc_dynamic(&info->array))) return(TRUE); /* No more memory */ - info->current_record= NO_RECORD; data=dynamic_element(&info->array,0,HASH_LINK*); halfbuff= info->blength >> 1; @@ -451,7 +463,6 @@ my_bool hash_delete(HASH *hash,byte *record) } if ( --(hash->records) < hash->blength >> 1) hash->blength>>=1; - hash->current_record= NO_RECORD; lastpos=data+hash->records; /* Remove link to record */ @@ -544,7 +555,6 @@ my_bool hash_update(HASH *hash,byte *record,byte *old_key,uint old_key_length) if ((idx=pos->next) == NO_RECORD) DBUG_RETURN(1); /* Not found in links */ } - hash->current_record= NO_RECORD; org_link= *pos; empty=idx; @@ -594,10 +604,10 @@ byte *hash_element(HASH *hash,uint idx) isn't changed */ -void hash_replace(HASH *hash, uint idx, byte *new_row) +void hash_replace(HASH *hash, HASH_SEARCH_STATE *current_record, byte *new_row) { - if (idx != NO_RECORD) /* Safety */ - dynamic_element(&hash->array,idx,HASH_LINK*)->data=new_row; + if (*current_record != NO_RECORD) /* Safety */ + dynamic_element(&hash->array, *current_record, HASH_LINK*)->data= new_row; } diff --git a/mysys/testhash.c b/mysys/testhash.c index 72badffdbcd..d15016113cd 100644 --- a/mysys/testhash.c +++ b/mysys/testhash.c @@ -74,7 +74,7 @@ static int do_test() bzero((char*) key1,sizeof(key1[0])*1000); printf("- Creating hash\n"); - if (hash_init(&hash,recant/2,0,6,0,free_record,0)) + if (hash_init(&hash, default_charset_info, recant/2, 0, 6, 0, free_record, 0)) goto err; printf("- Writing records:\n"); @@ -172,15 +172,16 @@ static int do_test() break; if (key1[j] > 1) { + HASH_SEARCH_STATE state; printf("- Testing identical read\n"); sprintf(key,"%6d",j); pos=1; - if (!(recpos=hash_search(&hash,key,0))) + if (!(recpos= hash_first(&hash, key, 0, &state))) { printf("can't find key1: \"%s\"\n",key); goto err; } - while (hash_next(&hash,key,0) && pos < (ulong) (key1[j]+10)) + while (hash_next(&hash, key, 0, &state) && pos < (ulong) (key1[j]+10)) pos++; if (pos != (ulong) key1[j]) { @@ -189,7 +190,7 @@ static int do_test() } } printf("- Creating output heap-file 2\n"); - if (hash_init(&hash2,hash.records,0,0,hash2_key,free_record,0)) + if (hash_init(&hash2, default_charset_info, hash.records, 0, 0, hash2_key, free_record,0)) goto err; printf("- Copying and removing records\n"); diff --git a/sql/lock.cc b/sql/lock.cc index a571b7f8ee8..f65ce69bb80 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -641,6 +641,7 @@ int lock_table_name(THD *thd, TABLE_LIST *table_list) char key[MAX_DBKEY_LENGTH]; char *db= table_list->db; uint key_length; + HASH_SEARCH_STATE state; DBUG_ENTER("lock_table_name"); DBUG_PRINT("enter",("db: %s name: %s", db, table_list->real_name)); @@ -651,9 +652,9 @@ int lock_table_name(THD *thd, TABLE_LIST *table_list) /* Only insert the table if we haven't insert it already */ - for (table=(TABLE*) hash_search(&open_cache,(byte*) key,key_length) ; + for (table=(TABLE*) hash_first(&open_cache, (byte*)key, key_length, &state); table ; - table = (TABLE*) hash_next(&open_cache,(byte*) key,key_length)) + table = (TABLE*) hash_next(&open_cache, (byte*)key, key_length, &state)) if (table->in_use == thd) DBUG_RETURN(0); diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 0ee83424d9f..74f7a1dcf06 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -1988,14 +1988,15 @@ static GRANT_TABLE *table_hash_search(const char *host,const char* ip, char helping [NAME_LEN*2+USERNAME_LENGTH+3]; uint len; GRANT_TABLE *grant_table,*found=0; + HASH_SEARCH_STATE state; len = (uint) (strmov(strmov(strmov(helping,user)+1,db)+1,tname)-helping)+ 1; - for (grant_table=(GRANT_TABLE*) hash_search(&column_priv_hash, - (byte*) helping, - len) ; + for (grant_table=(GRANT_TABLE*) hash_first(&column_priv_hash, + (byte*) helping, + len, &state) ; grant_table ; grant_table= (GRANT_TABLE*) hash_next(&column_priv_hash,(byte*) helping, - len)) + len, &state)) { if (exact) { diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 8b1fa754929..c8443948a4a 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -799,6 +799,7 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name, reg1 TABLE *table; char key[MAX_DBKEY_LENGTH]; uint key_length; + HASH_SEARCH_STATE state; DBUG_ENTER("open_table"); /* find a unused table in the open table cache */ @@ -863,9 +864,11 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name, /* close handler tables which are marked for flush */ mysql_ha_flush(thd, (TABLE_LIST*) NULL, MYSQL_HA_REOPEN_ON_USAGE, TRUE); - for (table=(TABLE*) hash_search(&open_cache,(byte*) key,key_length) ; + for (table= (TABLE*) hash_first(&open_cache, (byte*) key, key_length, + &state); table && table->in_use ; - table = (TABLE*) hash_next(&open_cache,(byte*) key,key_length)) + table= (TABLE*) hash_next(&open_cache, (byte*) key, key_length, + &state)) { if (table->version != refresh_version) { @@ -1236,12 +1239,14 @@ bool table_is_used(TABLE *table, bool wait_for_name_lock) { do { + HASH_SEARCH_STATE state; char *key= table->table_cache_key; uint key_length=table->key_length; - for (TABLE *search=(TABLE*) hash_search(&open_cache, - (byte*) key,key_length) ; + for (TABLE *search= (TABLE*) hash_first(&open_cache, (byte*) key, + key_length, &state); search ; - search = (TABLE*) hash_next(&open_cache,(byte*) key,key_length)) + search= (TABLE*) hash_next(&open_cache, (byte*) key, + key_length, &state)) { if (search->locked_by_flush || search->locked_by_name && wait_for_name_lock || @@ -2958,11 +2963,14 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name, key_length=(uint) (strmov(strmov(key,db)+1,table_name)-key)+1; for (;;) { + HASH_SEARCH_STATE state; result= signalled= 0; - for (table=(TABLE*) hash_search(&open_cache,(byte*) key,key_length) ; + for (table= (TABLE*) hash_first(&open_cache, (byte*) key, key_length, + &state); table; - table = (TABLE*) hash_next(&open_cache,(byte*) key,key_length)) + table= (TABLE*) hash_next(&open_cache, (byte*) key, key_length, + &state)) { THD *in_use; table->version=0L; /* Free when thread is ready */ diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index b40257511f7..457478e90db 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -2873,6 +2873,7 @@ my_bool Query_cache::move_by_type(byte **border, } case Query_cache_block::TABLE: { + HASH_SEARCH_STATE record_idx; DBUG_PRINT("qcache", ("block 0x%lx TABLE", (ulong) block)); if (*border == 0) break; @@ -2890,7 +2891,7 @@ my_bool Query_cache::move_by_type(byte **border, byte *key; uint key_length; key=query_cache_table_get_key((byte*) block, &key_length, 0); - hash_search(&tables, (byte*) key, key_length); + hash_first(&tables, (byte*) key, key_length, &record_idx); block->destroy(); new_block->init(len); @@ -2924,7 +2925,7 @@ my_bool Query_cache::move_by_type(byte **border, /* Fix pointer to table name */ new_block->table()->table(new_block->table()->db() + tablename_offset); /* Fix hash to point at moved block */ - hash_replace(&tables, tables.current_record, (byte*) new_block); + hash_replace(&tables, &record_idx, (byte*) new_block); DBUG_PRINT("qcache", ("moved %lu bytes to 0x%lx, new gap at 0x%lx", len, (ulong) new_block, (ulong) *border)); @@ -2932,6 +2933,7 @@ my_bool Query_cache::move_by_type(byte **border, } case Query_cache_block::QUERY: { + HASH_SEARCH_STATE record_idx; DBUG_PRINT("qcache", ("block 0x%lx QUERY", (ulong) block)); if (*border == 0) break; @@ -2949,7 +2951,7 @@ my_bool Query_cache::move_by_type(byte **border, byte *key; uint key_length; key=query_cache_query_get_key((byte*) block, &key_length, 0); - hash_search(&queries, (byte*) key, key_length); + hash_first(&queries, (byte*) key, key_length, &record_idx); // Move table of used tables memmove((char*) new_block->table(0), (char*) block->table(0), ALIGN_SIZE(n_tables*sizeof(Query_cache_block_table))); @@ -3017,7 +3019,7 @@ my_bool Query_cache::move_by_type(byte **border, net->query_cache_query= (gptr) new_block; } /* Fix hash to point at moved block */ - hash_replace(&queries, queries.current_record, (byte*) new_block); + hash_replace(&queries, &record_idx, (byte*) new_block); DBUG_PRINT("qcache", ("moved %lu bytes to 0x%lx, new gap at 0x%lx", len, (ulong) new_block, (ulong) *border)); break; From b6e0d940d61ad7eda9e04ea31a24c1505967ad71 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Jan 2006 16:02:41 +0100 Subject: [PATCH 28/68] Fix QNX test abort in release builds and pushbuild, avoid killing our parent when we are not the process group leader. --- mysql-test/lib/mtr_process.pl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mysql-test/lib/mtr_process.pl b/mysql-test/lib/mtr_process.pl index b3a243444c1..4d88c9b3322 100644 --- a/mysql-test/lib/mtr_process.pl +++ b/mysql-test/lib/mtr_process.pl @@ -890,7 +890,14 @@ sub mtr_exit ($) { # cluck("Called mtr_exit()"); mtr_timer_stop_all($::glob_timers); local $SIG{HUP} = 'IGNORE'; - kill('HUP', -$$); + # ToDo: Signalling -$$ will only work if we are the process group + # leader (in fact on QNX it will signal our session group leader, + # which might be Do-compile or Pushbuild, causing tests to be + # aborted). So we only do it if we are the group leader. We might + # set ourselves as the group leader at startup (with + # POSIX::setpgrp(0,0)), but then care must be needed to always do + # proper child process cleanup. + kill('HUP', -$$) if $$ == getpgrp(); sleep 2; exit($code); } From a6b0029f4d446adc730b09206b9cd838b0da3f7c Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Jan 2006 16:38:54 +0100 Subject: [PATCH 29/68] EADDRINUSE is not defined on Windows. --- include/my_global.h | 3 +++ sql/mysqld.cc | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/my_global.h b/include/my_global.h index e62f6c269aa..0df9ac78eb2 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -862,6 +862,7 @@ typedef off_t os_off_t; #define SOCKET_EAGAIN WSAEINPROGRESS #define SOCKET_ETIMEDOUT WSAETIMEDOUT #define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK +#define SOCKET_EADDRINUSE WSAEADDRINUSE #define SOCKET_ENFILE ENFILE #define SOCKET_EMFILE EMFILE #elif defined(OS2) @@ -870,6 +871,7 @@ typedef off_t os_off_t; #define SOCKET_EAGAIN SOCEINPROGRESS #define SOCKET_ETIMEDOUT SOCKET_EINTR #define SOCKET_EWOULDBLOCK SOCEWOULDBLOCK +#define SOCKET_EADDRINUSE SOCEADDRINUSE #define SOCKET_ENFILE SOCENFILE #define SOCKET_EMFILE SOCEMFILE #define closesocket(A) soclose(A) @@ -880,6 +882,7 @@ typedef off_t os_off_t; #define SOCKET_EAGAIN EAGAIN #define SOCKET_ETIMEDOUT SOCKET_EINTR #define SOCKET_EWOULDBLOCK EWOULDBLOCK +#define SOCKET_EADDRINUSE EADDRINUSE #define SOCKET_ENFILE ENFILE #define SOCKET_EMFILE EMFILE #endif diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 14cbaf28ae3..8934b872c94 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1401,7 +1401,7 @@ static void network_init(void) { if (((ret= bind(ip_sock, my_reinterpret_cast(struct sockaddr *) (&IPaddr), sizeof(IPaddr))) >= 0) || - (socket_errno != EADDRINUSE) || + (socket_errno != SOCKET_EADDRINUSE) || (waited >= mysqld_port_timeout)) break; sql_print_information("Retrying bind on TCP/IP port %u", mysqld_port); From 58d4830c6352422177630ce31160d0d0aaa9aab1 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Jan 2006 21:39:39 +0300 Subject: [PATCH 30/68] Post-merge fixes. sql/sql_acl.cc: A post-merge fix. sql/sql_base.cc: A post-merge fix. --- sql/sql_acl.cc | 1 - sql/sql_base.cc | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 22fecda2599..66a1b1f9b11 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -2245,7 +2245,6 @@ static GRANT_NAME *name_hash_search(HASH *name_hash, uint len; GRANT_NAME *grant_name,*found=0; HASH_SEARCH_STATE state; - GRANT_TABLE *grant_table,*found=0; len = (uint) (strmov(strmov(strmov(helping,user)+1,db)+1,tname)-helping)+ 1; for (grant_name= (GRANT_NAME*) hash_first(name_hash, (byte*) helping, diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 290f16a09d6..0b414f59223 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1624,7 +1624,8 @@ bool table_is_used(TABLE *table, bool wait_for_name_lock) { char *key= table->s->table_cache_key; uint key_length= table->s->key_length; - for (TABLE *search= (TABLE*) hash_search(&open_cache, (byte*) key, + HASH_SEARCH_STATE state; + for (TABLE *search= (TABLE*) hash_first(&open_cache, (byte*) key, key_length, &state); search ; search= (TABLE*) hash_next(&open_cache, (byte*) key, From f6bcc388da522c4428d47ab023a4556dd4930e8f Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 5 Jan 2006 23:39:45 +0100 Subject: [PATCH 31/68] Port to Win64/x64 in Visual Studio 2005 include/config-win.h: Port to Win64/x64 in Visual Studio 2005. Avoid endless deprecation warnings. --- include/config-win.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/config-win.h b/include/config-win.h index 528bc8a8cdd..cebc4c8b82b 100644 --- a/include/config-win.h +++ b/include/config-win.h @@ -22,6 +22,11 @@ functions */ #define _WIN32_WINNT 0x0500 #endif +#if defined(_MSC_VER) && _MSC_VER >= 1400 +/* Avoid endless warnings about sprintf() etc. being unsafe. */ +#define _CRT_SECURE_NO_DEPRECATE 1 +#endif + #include #include #include /* Because of rint() */ @@ -325,6 +330,11 @@ inline double ulonglong2double(ulonglong value) #define HAVE_SETFILEPOINTER #define HAVE_VIO_READ_BUFF +#if defined(_WIN64) && defined(_M_X64) +/* Avoid type conflicts with built-in functions. */ +#define HAVE_STRNLEN +#endif + #ifndef __NT__ #undef FILE_SHARE_DELETE #define FILE_SHARE_DELETE 0 /* Not implemented on Win 98/ME */ From 64206b1850bc93c74f93c3e0dd2e2e909240fcda Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 6 Jan 2006 00:47:49 +0200 Subject: [PATCH 32/68] Review fixes of new pushed code - Fixed tests - Optimized new code - Fixed some unlikely core dumps - Better bug fixes for: - #14397 - OPTIMIZE TABLE with an open HANDLER causes a crash - #14850 (ERROR 1062 when a quering a view using a Group By on a column that can be null mysql-test/r/create.result: Update results after removing wrong warnings for CREATE ... SELECT New tests mysql-test/r/handler.result: Drop used tables mysql-test/r/kill.result: Make test portable mysql-test/r/mysqlshow.result: Drop tables used by previous test mysql-test/r/trigger.result: Reuse old procedure name mysql-test/r/view.result: Extra tests mysql-test/t/create.test: New tests to test fix of removing wrong warnings for CREATE ... SELECT mysql-test/t/disabled.def: Enable 'kill' test (should now be portable) mysql-test/t/handler.test: Drop used tables mysql-test/t/kill.test: Make test portable even if kill doesn't work at once mysql-test/t/mysqlshow.test: Drop tables used by previous test mysql-test/t/trigger.test: Reuse old procedure name mysql-test/t/view.test: Extra tests sql/field.cc: Removed compiler warning sql/ha_federated.cc: my_snprintf -> strmake() (Simple optimization) sql/ha_ndbcluster.cc: Indentation cleanups and trival optimization sql/item.cc: Moved save_org_in_field() to item.cc to make it easier to test Remove setting of null_value as this is not needed sql/item.h: Moved save_org_in_field() to item.cc to make it easier to test sql/log_event.cc: Remove inline of slave_load_file_stem() Added 'extension' parameter to slave_load_file_stem() to get smaller code Removed not critical (or needed) DBUG_ASSERT()'s Cleaned up usage of slave_load_file_stem() to not depend on constant string lengths Indentation fixes sql/opt_range.cc: Moved code from declaration to function body (To make it more readable) sql/parse_file.cc: Fixed DBUG_PRINT sql/sp.cc: Simple cleanups - Removed not needed {} level - Ensure saved variables starts with old_ sql/sp_head.cc: Indentation fixes Remove core dump when using --debug when m_next_cached_sp == 0 Fixed compiler warnings Trivial optimizations sql/sp_head.h: Changed argument to set_definer() to const Added THD argument to recursion_level_error() to avoid call to current_thd sql/sql_acl.cc: Removed not needed test (first_not_own_table is the guard) sql/sql_base.cc: Removed extra empty line sql/sql_handler.cc: Don't test table version in mysql_ha_read() as this is already tested in lock_tables() Moved call to insert_fields to be after lock_table() to guard aganst reopen of tables (Better fix for Bug#14397 - OPTIMIZE TABLE with an open HANDLER causes a crash) sql/sql_insert.cc: Mark fields that are set in CREATE ... SELECT as used (Removed wrong warnings about field not having a default value) sql/sql_parse.cc: Removed not needed test of 'tables' (first_not_own_table is the guard) Simplify code sql/sql_select.cc: Use group->field to check if value is null instead of item called by 'save_org_in_field' This is a better bug fix for #14850 (ERROR 1062 when a quering a view using a Group By on a column that can be null) sql/sql_trigger.cc: Move sql_modes_parameters outside of function Indentation fixes Fixed compiler warning Ensure that thd->lex->query_tables_own_last is set properly before calling check_table_access() (This allows us to remove the extra test in check_grant() and check_table_access()) --- mysql-test/r/create.result | 43 ++++++++++------ mysql-test/r/handler.result | 2 +- mysql-test/r/kill.result | 2 - mysql-test/r/mysqlshow.result | 2 +- mysql-test/r/trigger.result | 7 ++- mysql-test/r/view.result | 3 ++ mysql-test/t/create.test | 16 ++++++ mysql-test/t/disabled.def | 1 - mysql-test/t/handler.test | 2 +- mysql-test/t/kill.test | 13 +++-- mysql-test/t/mysqlshow.test | 2 +- mysql-test/t/trigger.test | 9 ++-- mysql-test/t/view.test | 1 + sql/field.cc | 4 +- sql/ha_federated.cc | 3 +- sql/ha_ndbcluster.cc | 22 +++++---- sql/item.cc | 6 +++ sql/item.h | 6 +-- sql/log_event.cc | 93 ++++++++++++++++++++--------------- sql/opt_range.cc | 14 ++++-- sql/parse_file.cc | 2 +- sql/sp.cc | 70 +++++++++++++------------- sql/sp_head.cc | 68 ++++++++++++++----------- sql/sp_head.h | 4 +- sql/sql_acl.cc | 2 +- sql/sql_base.cc | 1 - sql/sql_handler.cc | 35 +++---------- sql/sql_insert.cc | 6 ++- sql/sql_parse.cc | 12 ++--- sql/sql_select.cc | 2 +- sql/sql_trigger.cc | 32 +++++++----- 31 files changed, 269 insertions(+), 216 deletions(-) diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result index a201af78518..199fdd1eb5d 100644 --- a/mysql-test/r/create.result +++ b/mysql-test/r/create.result @@ -287,7 +287,6 @@ a b create table if not exists t1 select 3 as 'a',4 as 'b'; Warnings: Note 1050 Table 't1' already exists -Warning 1364 Field 'a' doesn't have a default value create table if not exists t1 select 3 as 'a',3 as 'b'; ERROR 23000: Duplicate entry '3' for key 1 select * from t1; @@ -645,8 +644,6 @@ create table t1 ( a varchar(112) charset utf8 collate utf8_bin not null, primary key (a) ) select 'test' as a ; -Warnings: -Warning 1364 Field 'a' doesn't have a default value show create table t1; Table Create Table t1 CREATE TABLE `t1` ( @@ -662,9 +659,6 @@ create table t1 ( a varchar(12) charset utf8 collate utf8_bin not null, b int not null, primary key (a) ) select a, 1 as b from t2 ; -Warnings: -Warning 1364 Field 'a' doesn't have a default value -Warning 1364 Field 'b' doesn't have a default value show create table t1; Table Create Table t1 CREATE TABLE `t1` ( @@ -674,12 +668,37 @@ t1 CREATE TABLE `t1` ( ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; create table t1 ( +a varchar(12) charset utf8 collate utf8_bin not null, +b int not null, primary key (a) +) select a, 1 as c from t2 ; +Warnings: +Warning 1364 Field 'b' doesn't have a default value +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` int(11) NOT NULL, + `a` varchar(12) character set utf8 collate utf8_bin NOT NULL, + `c` bigint(1) NOT NULL default '0', + PRIMARY KEY (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +create table t1 ( +a varchar(12) charset utf8 collate utf8_bin not null, +b int null, primary key (a) +) select a, 1 as c from t2 ; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` int(11) default NULL, + `a` varchar(12) character set utf8 collate utf8_bin NOT NULL, + `c` bigint(1) NOT NULL default '0', + PRIMARY KEY (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +create table t1 ( a varchar(12) charset utf8 collate utf8_bin not null, b int not null, primary key (a) ) select 'a' as a , 1 as b from t2 ; -Warnings: -Warning 1364 Field 'a' doesn't have a default value -Warning 1364 Field 'b' doesn't have a default value show create table t1; Table Create Table t1 CREATE TABLE `t1` ( @@ -692,8 +711,6 @@ create table t1 ( a varchar(12) charset utf8 collate utf8_bin, b int not null, primary key (a) ) select 'a' as a , 1 as b from t2 ; -Warnings: -Warning 1364 Field 'b' doesn't have a default value show create table t1; Table Create Table t1 CREATE TABLE `t1` ( @@ -712,8 +729,6 @@ a1 varchar(12) charset utf8 collate utf8_bin not null, a2 int, a3 int, a4 int, a5 int, a6 int, a7 int, a8 int, a9 int, primary key (a1) ) select a1,a2,a3,a4,a5,a6,a7,a8,a9 from t1 ; -Warnings: -Warning 1364 Field 'a1' doesn't have a default value drop table t2; create table t2 ( a1 varchar(12) charset utf8 collate utf8_bin, @@ -729,8 +744,6 @@ a1 varchar(12) charset utf8 collate utf8_bin not null, a2 int, a3 int, a4 int, a5 int, a6 int, a7 int, a8 int, a9 int, primary key (a1) ) select a1,a2,a3,a4,a5,a6,a7,a8,a9 from t1 ; -Warnings: -Warning 1364 Field 'a1' doesn't have a default value drop table t2; create table t2 ( a int default 3, b int default 3) select a1,a2 from t1; diff --git a/mysql-test/r/handler.result b/mysql-test/r/handler.result index 133683fb273..104025e83eb 100644 --- a/mysql-test/r/handler.result +++ b/mysql-test/r/handler.result @@ -1,4 +1,4 @@ -drop table if exists t1; +drop table if exists t1,t3,t4,t5; create table t1 (a int, b char(10), key a(a), key b(a,b)); insert into t1 values (17,"ddd"),(18,"eee"),(19,"fff"),(19,"yyy"), diff --git a/mysql-test/r/kill.result b/mysql-test/r/kill.result index 754568093ff..2413834be4f 100644 --- a/mysql-test/r/kill.result +++ b/mysql-test/r/kill.result @@ -5,8 +5,6 @@ select ((@id := kill_id) - kill_id) from t1; ((@id := kill_id) - kill_id) 0 kill @id; -select 1; -Got one of the listed errors select ((@id := kill_id) - kill_id) from t1; ((@id := kill_id) - kill_id) 0 diff --git a/mysql-test/r/mysqlshow.result b/mysql-test/r/mysqlshow.result index 355c20fdad3..942cde83f21 100644 --- a/mysql-test/r/mysqlshow.result +++ b/mysql-test/r/mysqlshow.result @@ -1,4 +1,4 @@ -DROP TABLE IF EXISTS t1,t2; +DROP TABLE IF EXISTS t1,t2,test1,test2; CREATE TABLE t1 (a int); INSERT INTO t1 VALUES (1),(2),(3); CREATE TABLE t2 (a int, b int); diff --git a/mysql-test/r/trigger.result b/mysql-test/r/trigger.result index ff92fc543d4..0ad5c485b28 100644 --- a/mysql-test/r/trigger.result +++ b/mysql-test/r/trigger.result @@ -767,8 +767,7 @@ deallocate prepare stmt1; drop procedure p1; drop table t1, t2, t3; create table t1 (a int); -drop procedure if exists p2; -CREATE PROCEDURE `p2`() +CREATE PROCEDURE `p1`() begin insert into t1 values (1); end// @@ -777,6 +776,6 @@ begin declare done int default 0; set done= not done; end// -CALL p2(); -drop procedure p2; +CALL p1(); +drop procedure p1; drop table t1; diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index ebb2c190eb1..c26671ac937 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -2418,6 +2418,9 @@ drop view v1; drop table t1; create table t1(f1 int, f2 int); insert into t1 values (null, 10), (null,2); +select f1, sum(f2) from t1 group by f1; +f1 sum(f2) +NULL 12 create view v1 as select * from t1; select f1, sum(f2) from v1 group by f1; f1 sum(f2) diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index 470a7bcbb59..fcbdff7ec5b 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -571,6 +571,22 @@ create table t1 ( show create table t1; drop table t1; +--warning 1364 +create table t1 ( + a varchar(12) charset utf8 collate utf8_bin not null, + b int not null, primary key (a) +) select a, 1 as c from t2 ; +show create table t1; +drop table t1; + +--warning 1364 +create table t1 ( + a varchar(12) charset utf8 collate utf8_bin not null, + b int null, primary key (a) +) select a, 1 as c from t2 ; +show create table t1; +drop table t1; + --warning 1364 create table t1 ( a varchar(12) charset utf8 collate utf8_bin not null, diff --git a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def index fe95a543fb5..b96aa7befd9 100644 --- a/mysql-test/t/disabled.def +++ b/mysql-test/t/disabled.def @@ -14,4 +14,3 @@ sp-goto : GOTO is currently is disabled - will be fixed in the future rpl_relayrotate : Unstable test case, bug#12429 rpl_until : Unstable test case, bug#12429 rpl_deadlock : Unstable test case, bug#12429 -kill : Unstable test case, bug#9712 diff --git a/mysql-test/t/handler.test b/mysql-test/t/handler.test index f3e14c3cd2b..3fb09df5f2f 100644 --- a/mysql-test/t/handler.test +++ b/mysql-test/t/handler.test @@ -3,7 +3,7 @@ # --disable_warnings -drop table if exists t1; +drop table if exists t1,t3,t4,t5; --enable_warnings create table t1 (a int, b char(10), key a(a), key b(a,b)); diff --git a/mysql-test/t/kill.test b/mysql-test/t/kill.test index 7f3a9932d31..c50c35825fc 100644 --- a/mysql-test/t/kill.test +++ b/mysql-test/t/kill.test @@ -25,11 +25,18 @@ select ((@id := kill_id) - kill_id) from t1; kill @id; connection con1; ---sleep 1 +--sleep 2 -# this statement should fail ---error 2006,2013 +--disable_query_log +--disable_result_log +# One of the following statements should fail +--error 0,2006,2013 select 1; +--error 0,2006,2013 +select 1; +--enable_query_log +--enable_result_log + --enable_reconnect # this should work, and we should have a new connection_id() select ((@id := kill_id) - kill_id) from t1; diff --git a/mysql-test/t/mysqlshow.test b/mysql-test/t/mysqlshow.test index 1e2e97a4e07..78c4ae2b531 100644 --- a/mysql-test/t/mysqlshow.test +++ b/mysql-test/t/mysqlshow.test @@ -2,7 +2,7 @@ -- source include/not_embedded.inc --disable_warnings -DROP TABLE IF EXISTS t1,t2; +DROP TABLE IF EXISTS t1,t2,test1,test2; --enable_warnings # diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test index d4fa5268762..acd3297e12a 100644 --- a/mysql-test/t/trigger.test +++ b/mysql-test/t/trigger.test @@ -928,11 +928,8 @@ drop table t1, t2, t3; # operator. # create table t1 (a int); ---disable_warnings -drop procedure if exists p2; ---enable_warnings DELIMITER //; -CREATE PROCEDURE `p2`() +CREATE PROCEDURE `p1`() begin insert into t1 values (1); end// @@ -942,7 +939,7 @@ begin set done= not done; end// DELIMITER ;// -CALL p2(); -drop procedure p2; +CALL p1(); +drop procedure p1; drop table t1; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index ac103278f08..bc54287afb2 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -2276,6 +2276,7 @@ drop table t1; # create table t1(f1 int, f2 int); insert into t1 values (null, 10), (null,2); +select f1, sum(f2) from t1 group by f1; create view v1 as select * from t1; select f1, sum(f2) from v1 group by f1; drop view v1; diff --git a/sql/field.cc b/sql/field.cc index b70e2a92618..9e73c132d68 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -6204,8 +6204,8 @@ Field *Field_string::new_field(MEM_ROOT *root, struct st_table *new_table) This is done to ensure that ALTER TABLE will convert old VARCHAR fields to now VARCHAR fields. */ - if (new_field= new Field_varstring(field_length, maybe_null(), - field_name, new_table, charset())) + if ((new_field= new Field_varstring(field_length, maybe_null(), + field_name, new_table, charset()))) { /* delayed_insert::get_local_table() needs a ptr copied from old table. diff --git a/sql/ha_federated.cc b/sql/ha_federated.cc index d2f827989f5..14b79a9a418 100644 --- a/sql/ha_federated.cc +++ b/sql/ha_federated.cc @@ -2616,8 +2616,7 @@ int ha_federated::stash_remote_error() { DBUG_ENTER("ha_federated::stash_remote_error()"); remote_error_number= mysql_errno(mysql); - my_snprintf(remote_error_buf, sizeof(remote_error_buf), "%s", - mysql_error(mysql)); + strmake(remote_error_buf, mysql_error(mysql), sizeof(remote_error_buf)-1); DBUG_RETURN(HA_FEDERATED_ERROR_WITH_REMOTE_SYSTEM); } diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index cdd406d473c..81d11e0a27c 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -300,7 +300,8 @@ Thd_ndb::~Thd_ndb() if (ndb) { #ifndef DBUG_OFF - Ndb::Free_list_usage tmp; tmp.m_name= 0; + Ndb::Free_list_usage tmp; + tmp.m_name= 0; while (ndb->get_free_list_usage(&tmp)) { uint leaked= (uint) tmp.m_created - tmp.m_free; @@ -312,8 +313,8 @@ Thd_ndb::~Thd_ndb() } #endif delete ndb; + ndb= NULL; } - ndb= NULL; changed_tables.empty(); } @@ -4883,7 +4884,8 @@ bool ndbcluster_end() if (g_ndb) { #ifndef DBUG_OFF - Ndb::Free_list_usage tmp; tmp.m_name= 0; + Ndb::Free_list_usage tmp; + tmp.m_name= 0; while (g_ndb->get_free_list_usage(&tmp)) { uint leaked= (uint) tmp.m_created - tmp.m_free; @@ -4895,10 +4897,9 @@ bool ndbcluster_end() } #endif delete g_ndb; + g_ndb= NULL; } - g_ndb= NULL; - if (g_ndb_cluster_connection) - delete g_ndb_cluster_connection; + delete g_ndb_cluster_connection; g_ndb_cluster_connection= NULL; hash_free(&ndbcluster_open_tables); @@ -7443,7 +7444,8 @@ ndbcluster_show_status(THD* thd) if (have_ndbcluster != SHOW_OPTION_YES) { my_message(ER_NOT_SUPPORTED_YET, - "Cannot call SHOW NDBCLUSTER STATUS because skip-ndbcluster is defined", + "Cannot call SHOW NDBCLUSTER STATUS because skip-ndbcluster is " + "defined", MYF(0)); DBUG_RETURN(TRUE); } @@ -7454,13 +7456,15 @@ ndbcluster_show_status(THD* thd) field_list.push_back(new Item_return_int("free", 10,MYSQL_TYPE_LONG)); field_list.push_back(new Item_return_int("sizeof", 10,MYSQL_TYPE_LONG)); - if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) + if (protocol->send_fields(&field_list, + Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) DBUG_RETURN(TRUE); if (get_thd_ndb(thd) && get_thd_ndb(thd)->ndb) { Ndb* ndb= (get_thd_ndb(thd))->ndb; - Ndb::Free_list_usage tmp; tmp.m_name= 0; + Ndb::Free_list_usage tmp; + tmp.m_name= 0; while (ndb->get_free_list_usage(&tmp)) { protocol->prepare_for_resend(); diff --git a/sql/item.cc b/sql/item.cc index 6d5855cd0ca..dadbd31c81f 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -4843,6 +4843,12 @@ int Item_ref::save_in_field(Field *to, bool no_conversions) } +void Item_ref::save_org_in_field(Field *field) +{ + (*ref)->save_org_in_field(field); +} + + void Item_ref::make_field(Send_field *field) { (*ref)->make_field(field); diff --git a/sql/item.h b/sql/item.h index 4201790e907..c64e6586d5f 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1612,11 +1612,7 @@ public: void make_field(Send_field *field); bool fix_fields(THD *, Item **); int save_in_field(Field *field, bool no_conversions); - void save_org_in_field(Field *field) - { - (*ref)->save_org_in_field(field); - null_value= (*ref)->null_value; - } + void save_org_in_field(Field *field); enum Item_result result_type () const { return (*ref)->result_type(); } enum_field_types field_type() const { return (*ref)->field_type(); } Field *get_tmp_table_field() diff --git a/sql/log_event.cc b/sql/log_event.cc index 056bcca1a02..519b077b17b 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -114,13 +114,24 @@ static char *pretty_print_str(char *packet, char *str, int len) /* - slave_load_file_stem() + Creates a temporary name for load data infile: + + SYNOPSIS + slave_load_file_stem() + buf Store new filename here + file_id File_id (part of file name) + event_server_id Event_id (part of file name) + ext Extension for file name + + RETURN + Pointer to start of extension */ #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) -static inline char* slave_load_file_stem(char*buf, uint file_id, - int event_server_id) +static char *slave_load_file_stem(char *buf, uint file_id, + int event_server_id, const char *ext) { + char *res; fn_format(buf,"SQL_LOAD-",slave_load_tmpdir, "", MY_UNPACK_FILENAME); to_unix_path(buf); @@ -129,7 +140,9 @@ static inline char* slave_load_file_stem(char*buf, uint file_id, *buf++ = '-'; buf = int10_to_str(event_server_id, buf, 10); *buf++ = '-'; - return int10_to_str(file_id, buf, 10); + res= int10_to_str(file_id, buf, 10); + strmov(res, ext); // Add extension last + return res; // Pointer to extension } #endif @@ -901,7 +914,6 @@ void Log_event::print_header(FILE* file, PRINT_EVENT_INFO* print_event_info) /* Pretty-print event common header if header is exactly 19 bytes */ if (print_event_info->common_header_len == LOG_EVENT_MINIMAL_HEADER_LEN) { - DBUG_ASSERT(hexdump_from == (unsigned long) hexdump_from); fprintf(file, "# Position Timestamp Type Master ID " "Size Master Pos Flags \n"); fprintf(file, "# %8.8lx %02x %02x %02x %02x %02x " @@ -927,7 +939,6 @@ void Log_event::print_header(FILE* file, PRINT_EVENT_INFO* print_event_info) if (i % 16 == 15) { - DBUG_ASSERT(hexdump_from == (unsigned long) hexdump_from); fprintf(file, "# %8.8lx %-48.48s |%16s|\n", (unsigned long) (hexdump_from + (i & 0xfffffff0)), hex_string, char_string); @@ -941,12 +952,10 @@ void Log_event::print_header(FILE* file, PRINT_EVENT_INFO* print_event_info) *c= '\0'; /* Non-full last line */ - if (hex_string[0]) { - DBUG_ASSERT(hexdump_from == (unsigned long) hexdump_from); + if (hex_string[0]) fprintf(file, "# %8.8lx %-48.48s |%s|\n# ", (unsigned long) (hexdump_from + (i & 0xfffffff0)), hex_string, char_string); - } } } @@ -4160,16 +4169,15 @@ void Create_file_log_event::pack_info(Protocol *protocol) #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) int Create_file_log_event::exec_event(struct st_relay_log_info* rli) { - char proc_info[17+FN_REFLEN+10], *fname_buf= proc_info+17; - char *p; + char proc_info[17+FN_REFLEN+10], *fname_buf; + char *ext; int fd = -1; IO_CACHE file; int error = 1; bzero((char*)&file, sizeof(file)); - p = slave_load_file_stem(fname_buf, file_id, server_id); - strmov(p, ".info"); // strmov takes less code than memcpy - strnmov(proc_info, STRING_WITH_LEN("Making temp file ")); // no end 0 + fname_buf= strmov(proc_info, "Making temp file "); + ext= slave_load_file_stem(fname_buf, file_id, server_id, ".info"); thd->proc_info= proc_info; my_delete(fname_buf, MYF(0)); // old copy may exist already if ((fd= my_create(fname_buf, CREATE_MODE, @@ -4178,19 +4186,21 @@ int Create_file_log_event::exec_event(struct st_relay_log_info* rli) init_io_cache(&file, fd, IO_SIZE, WRITE_CACHE, (my_off_t)0, 0, MYF(MY_WME|MY_NABP))) { - slave_print_error(rli,my_errno, "Error in Create_file event: could not open file '%s'", fname_buf); + slave_print_error(rli,my_errno, + "Error in Create_file event: could not open file '%s'", + fname_buf); goto err; } // a trick to avoid allocating another buffer - strmov(p, ".data"); - fname = fname_buf; - fname_len = (uint)(p-fname) + 5; + fname= fname_buf; + fname_len= (uint) (strmov(ext, ".data") - fname); if (write_base(&file)) { - strmov(p, ".info"); // to have it right in the error message + strmov(ext, ".info"); // to have it right in the error message slave_print_error(rli,my_errno, - "Error in Create_file event: could not write to file '%s'", + "Error in Create_file event: could not write to file " + "'%s'", fname_buf); goto err; } @@ -4203,12 +4213,16 @@ int Create_file_log_event::exec_event(struct st_relay_log_info* rli) O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW, MYF(MY_WME))) < 0) { - slave_print_error(rli,my_errno, "Error in Create_file event: could not open file '%s'", fname_buf); + slave_print_error(rli,my_errno, + "Error in Create_file event: could not open file '%s'", + fname_buf); goto err; } if (my_write(fd, (byte*) block, block_len, MYF(MY_WME+MY_NABP))) { - slave_print_error(rli,my_errno, "Error in Create_file event: write to '%s' failed", fname_buf); + slave_print_error(rli,my_errno, + "Error in Create_file event: write to '%s' failed", + fname_buf); goto err; } error=0; // Everything is ok @@ -4332,13 +4346,12 @@ int Append_block_log_event::get_create_or_append() const int Append_block_log_event::exec_event(struct st_relay_log_info* rli) { char proc_info[17+FN_REFLEN+10], *fname= proc_info+17; - char *p= slave_load_file_stem(fname, file_id, server_id); int fd; int error = 1; DBUG_ENTER("Append_block_log_event::exec_event"); - memcpy(p, ".data", 6); - strnmov(proc_info, STRING_WITH_LEN("Making temp file ")); // no end 0 + fname= strmov(proc_info, "Making temp file "); + slave_load_file_stem(fname, file_id, server_id, ".data"); thd->proc_info= proc_info; if (get_create_or_append()) { @@ -4464,10 +4477,9 @@ void Delete_file_log_event::pack_info(Protocol *protocol) int Delete_file_log_event::exec_event(struct st_relay_log_info* rli) { char fname[FN_REFLEN+10]; - char *p= slave_load_file_stem(fname, file_id, server_id); - memcpy(p, ".data", 6); + char *ext= slave_load_file_stem(fname, file_id, server_id, ".data"); (void) my_delete(fname, MYF(MY_WME)); - memcpy(p, ".info", 6); + strmov(ext, ".info"); (void) my_delete(fname, MYF(MY_WME)); return Log_event::exec_event(rli); } @@ -4560,19 +4572,21 @@ void Execute_load_log_event::pack_info(Protocol *protocol) int Execute_load_log_event::exec_event(struct st_relay_log_info* rli) { char fname[FN_REFLEN+10]; - char *p= slave_load_file_stem(fname, file_id, server_id); + char *ext; int fd; - int error = 1; + int error= 1; IO_CACHE file; - Load_log_event* lev = 0; + Load_log_event *lev= 0; - memcpy(p, ".info", 6); + ext= slave_load_file_stem(fname, file_id, server_id, ".info"); if ((fd = my_open(fname, O_RDONLY | O_BINARY | O_NOFOLLOW, MYF(MY_WME))) < 0 || init_io_cache(&file, fd, IO_SIZE, READ_CACHE, (my_off_t)0, 0, MYF(MY_WME|MY_NABP))) { - slave_print_error(rli,my_errno, "Error in Exec_load event: could not open file '%s'", fname); + slave_print_error(rli,my_errno, + "Error in Exec_load event: could not open file '%s'", + fname); goto err; } if (!(lev = (Load_log_event*)Log_event::read_log_event(&file, @@ -4580,7 +4594,9 @@ int Execute_load_log_event::exec_event(struct st_relay_log_info* rli) rli->relay_log.description_event_for_exec)) || lev->get_type_code() != NEW_LOAD_EVENT) { - slave_print_error(rli,0, "Error in Exec_load event: file '%s' appears corrupted", fname); + slave_print_error(rli,0, + "Error in Exec_load event: file '%s' appears corrupted", + fname); goto err; } @@ -4625,7 +4641,7 @@ int Execute_load_log_event::exec_event(struct st_relay_log_info* rli) fd= -1; } (void) my_delete(fname, MYF(MY_WME)); - memcpy(p, ".data", 6); + memcpy(ext, ".data", 6); (void) my_delete(fname, MYF(MY_WME)); error = 0; @@ -4823,11 +4839,10 @@ Execute_load_query_log_event::exec_event(struct st_relay_log_info* rli) memcpy(p, query, fn_pos_start); p+= fn_pos_start; fname= (p= strmake(p, STRING_WITH_LEN(" INFILE \'"))); - p= slave_load_file_stem(p, file_id, server_id); - fname_end= (p= strmake(p, STRING_WITH_LEN(".data"))); + p= slave_load_file_stem(p, file_id, server_id, ".data"); + fname_end= p= strend(p); // Safer than p=p+5 *(p++)='\''; - switch (dup_handling) - { + switch (dup_handling) { case LOAD_DUP_IGNORE: p= strmake(p, STRING_WITH_LEN(" IGNORE")); break; diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 323e829f219..12b00a62012 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -5737,6 +5737,7 @@ bool QUICK_ROR_UNION_SELECT::check_if_keys_used(List *fields) /* Create quick select from ref/ref_or_null scan. + SYNOPSIS get_quick_select_for_ref() thd Thread handle @@ -5756,15 +5757,18 @@ bool QUICK_ROR_UNION_SELECT::check_if_keys_used(List *fields) QUICK_RANGE_SELECT *get_quick_select_for_ref(THD *thd, TABLE *table, TABLE_REF *ref, ha_rows records) { - MEM_ROOT *old_root= thd->mem_root; - /* The following call may change thd->mem_root */ - QUICK_RANGE_SELECT *quick= new QUICK_RANGE_SELECT(thd, table, ref->key, 0); - /* save mem_root set by QUICK_RANGE_SELECT constructor */ - MEM_ROOT *alloc= thd->mem_root; + MEM_ROOT *old_root, *alloc; + QUICK_RANGE_SELECT *quick; KEY *key_info = &table->key_info[ref->key]; KEY_PART *key_part; QUICK_RANGE *range; uint part; + + old_root= thd->mem_root; + /* The following call may change thd->mem_root */ + quick= new QUICK_RANGE_SELECT(thd, table, ref->key, 0); + /* save mem_root set by QUICK_RANGE_SELECT constructor */ + alloc= thd->mem_root; /* return back default mem_root (thd->mem_root) changed by QUICK_RANGE_SELECT constructor diff --git a/sql/parse_file.cc b/sql/parse_file.cc index 69757e0be06..041b770ac0b 100644 --- a/sql/parse_file.cc +++ b/sql/parse_file.cc @@ -944,6 +944,6 @@ File_parser_dummy_hook::process_unknown_string(char *&unknown_key, char *end) { DBUG_ENTER("file_parser_dummy_hook::process_unknown_string"); - DBUG_PRINT("info", ("unknown key:%60s", unknown_key)); + DBUG_PRINT("info", ("Unknown key: '%60s'", unknown_key)); DBUG_RETURN(FALSE); } diff --git a/sql/sp.cc b/sql/sp.cc index 8991cc78b5e..983addb2db7 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -399,14 +399,14 @@ db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp, const char *body, st_sp_chistics &chistics, const char *definer, longlong created, longlong modified) { - LEX *oldlex= thd->lex, newlex; - sp_rcontext *save_spcont= thd->spcont; + LEX *old_lex= thd->lex, newlex; String defstr; char olddb[128]; bool dbchanged; ulong old_sql_mode= thd->variables.sql_mode; - ha_rows select_limit= thd->variables.select_limit; - int ret= SP_INTERNAL_ERROR; + ha_rows old_select_limit= thd->variables.select_limit; + sp_rcontext *old_spcont= thd->spcont; + int ret; thd->variables.sql_mode= sql_mode; thd->variables.select_limit= HA_POS_ERROR; @@ -422,7 +422,10 @@ db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp, returns, strlen(returns), body, strlen(body), &chistics)) + { + ret= SP_INTERNAL_ERROR; goto end; + } dbchanged= FALSE; if ((ret= sp_use_new_db(thd, name->m_db.str, olddb, sizeof(olddb), @@ -451,10 +454,10 @@ db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp, (*sphp)->optimize(); } end: - thd->spcont= save_spcont; + thd->spcont= old_spcont; thd->variables.sql_mode= old_sql_mode; - thd->variables.select_limit= select_limit; - thd->lex= oldlex; + thd->variables.select_limit= old_select_limit; + thd->lex= old_lex; return ret; } @@ -926,7 +929,6 @@ sp_find_routine(THD *thd, int type, sp_name *name, sp_cache **cp, ulong depth= (type == TYPE_ENUM_PROCEDURE ? thd->variables.max_sp_recursion_depth : 0); - DBUG_ENTER("sp_find_routine"); DBUG_PRINT("enter", ("name: %.*s.%.*s, type: %d, cache only %d", name->m_db.length, name->m_db.str, @@ -936,6 +938,11 @@ sp_find_routine(THD *thd, int type, sp_name *name, sp_cache **cp, if ((sp= sp_cache_lookup(cp, name))) { ulong level; + sp_head *new_sp; + const char *returns= ""; + char definer[HOSTNAME_LENGTH+USERNAME_LENGTH+2]; + String retstr(64); + DBUG_PRINT("info", ("found: 0x%lx", (ulong)sp)); if (sp->m_first_free_instance) { @@ -946,7 +953,7 @@ sp_find_routine(THD *thd, int type, sp_name *name, sp_cache **cp, DBUG_ASSERT(!(sp->m_first_free_instance->m_flags & sp_head::IS_INVOKED)); if (sp->m_first_free_instance->m_recursion_level > depth) { - sp->recursion_level_error(); + sp->recursion_level_error(thd); DBUG_RETURN(0); } DBUG_RETURN(sp->m_first_free_instance); @@ -954,37 +961,32 @@ sp_find_routine(THD *thd, int type, sp_name *name, sp_cache **cp, level= sp->m_last_cached_sp->m_recursion_level + 1; if (level > depth) { - sp->recursion_level_error(); + sp->recursion_level_error(thd); DBUG_RETURN(0); } + + strxmov(definer, sp->m_definer_user.str, "@", + sp->m_definer_host.str, NullS); + if (type == TYPE_ENUM_FUNCTION) { - sp_head *new_sp; - const char *returns= ""; - char definer[HOSTNAME_LENGTH+USERNAME_LENGTH+2]; - String retstr(64); - strxmov(definer, sp->m_definer_user.str, "@", - sp->m_definer_host.str, NullS); - if (type == TYPE_ENUM_FUNCTION) - { - sp_returns_type(thd, retstr, sp); - returns= retstr.ptr(); - } - if (db_load_routine(thd, type, name, &new_sp, - sp->m_sql_mode, sp->m_params.str, returns, - sp->m_body.str, *sp->m_chistics, definer, - sp->m_created, sp->m_modified) == SP_OK) - { - sp->m_last_cached_sp->m_next_cached_sp= new_sp; - new_sp->m_recursion_level= level; - new_sp->m_first_instance= sp; - sp->m_last_cached_sp= sp->m_first_free_instance= new_sp; - DBUG_PRINT("info", ("added level: 0x%lx, level: %lu, flags %x", + sp_returns_type(thd, retstr, sp); + returns= retstr.ptr(); + } + if (db_load_routine(thd, type, name, &new_sp, + sp->m_sql_mode, sp->m_params.str, returns, + sp->m_body.str, *sp->m_chistics, definer, + sp->m_created, sp->m_modified) == SP_OK) + { + sp->m_last_cached_sp->m_next_cached_sp= new_sp; + new_sp->m_recursion_level= level; + new_sp->m_first_instance= sp; + sp->m_last_cached_sp= sp->m_first_free_instance= new_sp; + DBUG_PRINT("info", ("added level: 0x%lx, level: %lu, flags %x", (ulong)new_sp, new_sp->m_recursion_level, new_sp->m_flags)); - DBUG_RETURN(new_sp); - } - DBUG_RETURN(0); + DBUG_RETURN(new_sp); } + DBUG_RETURN(0); } if (!cache_only) { diff --git a/sql/sp_head.cc b/sql/sp_head.cc index a6e88c08789..576830a6587 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -24,11 +24,17 @@ #include "sp_rcontext.h" #include "sp_cache.h" +/* + Sufficient max length of printed destinations and frame offsets (all uints). +*/ +#define SP_INSTR_UINT_MAXLEN 8 +#define SP_STMT_PRINT_MAXLEN 40 + + Item_result sp_map_result_type(enum enum_field_types type) { - switch (type) - { + switch (type) { case MYSQL_TYPE_TINY: case MYSQL_TYPE_SHORT: case MYSQL_TYPE_LONG: @@ -891,17 +897,17 @@ static bool subst_spvars(THD *thd, sp_instr *instr, LEX_STRING *query_str) SYNOPSIS sp_head::recursion_level_error() + thd Thread handle NOTE For functions and triggers we return error about prohibited recursion. For stored procedures we return about reaching recursion limit. */ -void sp_head::recursion_level_error() +void sp_head::recursion_level_error(THD *thd) { if (m_type == TYPE_ENUM_PROCEDURE) { - THD *thd= current_thd; my_error(ER_SP_RECURSION_LIMIT, MYF(0), thd->variables.max_sp_recursion_depth, m_name); @@ -952,10 +958,15 @@ int sp_head::execute(THD *thd) DBUG_ASSERT(!(m_flags & IS_INVOKED)); m_flags|= IS_INVOKED; m_first_instance->m_first_free_instance= m_next_cached_sp; - DBUG_PRINT("info", ("first free for 0x%lx ++: 0x%lx->0x%lx, level: %lu, flags %x", - (ulong)m_first_instance, this, m_next_cached_sp, - m_next_cached_sp->m_recursion_level, - m_next_cached_sp->m_flags)); + if (m_next_cached_sp) + { + DBUG_PRINT("info", + ("first free for 0x%lx ++: 0x%lx->0x%lx level: %lu flags %x", + (ulong)m_first_instance, (ulong) this, + (ulong) m_next_cached_sp, + m_next_cached_sp->m_recursion_level, + m_next_cached_sp->m_flags)); + } /* Check that if there are not any instances after this one then pointer to the last instance points on this instance or if there are @@ -1140,9 +1151,9 @@ int sp_head::execute(THD *thd) } m_flags&= ~IS_INVOKED; DBUG_PRINT("info", ("first free for 0x%lx --: 0x%lx->0x%lx, level: %lu, flags %x", - (ulong)m_first_instance, - m_first_instance->m_first_free_instance, this, - m_recursion_level, m_flags)); + (ulong) m_first_instance, + (ulong) m_first_instance->m_first_free_instance, + (ulong) this, m_recursion_level, m_flags)); /* Check that we have one of following: @@ -1152,7 +1163,7 @@ int sp_head::execute(THD *thd) 2) There are some free instances which mean that first free instance should go just after this one and recursion level of that free instance - should be on 1 more then recursion leven of this instance. + should be on 1 more then recursion level of this instance. */ DBUG_ASSERT((m_first_instance->m_first_free_instance == 0 && this == m_first_instance->m_last_cached_sp && @@ -1684,16 +1695,16 @@ sp_head::set_info(longlong created, longlong modified, void -sp_head::set_definer(char *definer, uint definerlen) + +sp_head::set_definer(const char *definer, uint definerlen) { char *p= strrchr(definer, '@'); if (!p) { - m_definer_user.str= strmake_root(mem_root, "", 0); + m_definer_user.str= (char*) ""; m_definer_user.length= 0; - - m_definer_host.str= strmake_root(mem_root, "", 0); + m_definer_host.str= (char*) ""; m_definer_host.length= 0; } else @@ -1788,9 +1799,9 @@ sp_head::show_create_procedure(THD *thd) byte *sql_mode_str; ulong sql_mode_len; bool full_access; - DBUG_ENTER("sp_head::show_create_procedure"); DBUG_PRINT("info", ("procedure %s", m_name.str)); + LINT_INIT(sql_mode_str); LINT_INIT(sql_mode_len); @@ -2143,12 +2154,7 @@ sp_instr_stmt::execute(THD *thd, uint *nextp) DBUG_RETURN(res); } -/* - Sufficient max length of printed destinations and frame offsets (all uints). -*/ -#define SP_INSTR_UINT_MAXLEN 8 -#define SP_STMT_PRINT_MAXLEN 40 void sp_instr_stmt::print(String *str) { @@ -2170,16 +2176,16 @@ sp_instr_stmt::print(String *str) /* Copy the query string and replace '\n' with ' ' in the process */ for (i= 0 ; i < len ; i++) { - if (m_query.str[i] == '\n') - str->qs_append(' '); - else - str->qs_append(m_query.str[i]); + char c= m_query.str[i]; + if (c == '\n') + c= ' '; + str->qs_append(c); } if (m_query.length > SP_STMT_PRINT_MAXLEN) str->qs_append(STRING_WITH_LEN("...")); /* Indicate truncated string */ str->qs_append('"'); } -#undef SP_STMT_PRINT_MAXLEN + int sp_instr_stmt::exec_core(THD *thd, uint *nextp) @@ -2523,6 +2529,7 @@ sp_instr_hpush_jump::execute(THD *thd, uint *nextp) DBUG_RETURN(0); } + void sp_instr_hpush_jump::print(String *str) { @@ -2533,8 +2540,7 @@ sp_instr_hpush_jump::print(String *str) str->qs_append(m_dest); str->qs_append(' '); str->qs_append(m_frame); - switch (m_type) - { + switch (m_type) { case SP_HANDLER_NONE: str->qs_append(STRING_WITH_LEN(" NONE")); // This would be a bug break; @@ -2548,11 +2554,13 @@ sp_instr_hpush_jump::print(String *str) str->qs_append(STRING_WITH_LEN(" UNDO")); break; default: - str->qs_append(STRING_WITH_LEN(" UNKNOWN:")); // This would be a bug as well + // This would be a bug as well + str->qs_append(STRING_WITH_LEN(" UNKNOWN:")); str->qs_append(m_type); } } + uint sp_instr_hpush_jump::opt_mark(sp_head *sp) { diff --git a/sql/sp_head.h b/sql/sp_head.h index 6334bca0fc6..6f4a2de1518 100644 --- a/sql/sp_head.h +++ b/sql/sp_head.h @@ -283,7 +283,7 @@ public: void set_info(longlong created, longlong modified, st_sp_chistics *chistics, ulong sql_mode); - void set_definer(char *definer, uint definerlen); + void set_definer(const char *definer, uint definerlen); void reset_thd_mem_root(THD *thd); @@ -292,7 +292,7 @@ public: void optimize(); void opt_mark(uint ip); - void recursion_level_error(); + void recursion_level_error(THD *thd); inline sp_instr * get_instr(uint i) diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 46be74ae972..8d3bb316630 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -3537,7 +3537,7 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables, of other queries). For simple queries first_not_own_table is 0. */ for (i= 0, table= tables; - table && table != first_not_own_table && i < number; + table != first_not_own_table && i < number; table= table->next_global, i++) { /* Remove SHOW_VIEW_ACL, because it will be checked during making view */ diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 39e15675e47..598e6d46a60 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -5135,7 +5135,6 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name, bool result=0, signalled= 0; DBUG_ENTER("remove_table_from_cache"); - key_length=(uint) (strmov(strmov(key,db)+1,table_name)-key)+1; for (;;) { diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index da72d283259..545cf41eeeb 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -227,6 +227,7 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen) /* add to hash */ if (my_hash_insert(&thd->handler_tables_hash, (byte*) hash_tables)) { + my_free((char*) hash_tables, MYF(0)); mysql_ha_close(thd, tables); goto err; } @@ -369,28 +370,6 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables, DBUG_PRINT("info-in-hash",("'%s'.'%s' as '%s' tab %p", hash_tables->db, hash_tables->table_name, hash_tables->alias, table)); - /* Table might have been flushed. */ - if (table && (table->s->version != refresh_version)) - { - /* - We must follow the thd->handler_tables chain, as we need the - address of the 'next' pointer referencing this table - for close_thread_table(). - */ - for (table_ptr= &(thd->handler_tables); - *table_ptr && (*table_ptr != table); - table_ptr= &(*table_ptr)->next) - {} - (*table_ptr)->file->ha_index_or_rnd_end(); - VOID(pthread_mutex_lock(&LOCK_open)); - if (close_thread_table(thd, table_ptr)) - { - /* Tell threads waiting for refresh that something has happened */ - VOID(pthread_cond_broadcast(&COND_refresh)); - } - VOID(pthread_mutex_unlock(&LOCK_open)); - table= hash_tables->table= NULL; - } if (!table) { /* @@ -448,12 +427,6 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables, } } - if (insert_fields(thd, &thd->lex->select_lex.context, - tables->db, tables->alias, &it, 0)) - goto err0; - - protocol->send_fields(&list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF); - HANDLER_TABLES_HACK(thd); lock= mysql_lock_tables(thd, &tables->table, 1, 0, ¬_used); HANDLER_TABLES_HACK(thd); @@ -461,6 +434,12 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables, if (!lock) goto err0; // mysql_lock_tables() printed error message already + if (insert_fields(thd, &thd->lex->select_lex.context, + tables->db, tables->alias, &it, 0)) + goto err0; + + protocol->send_fields(&list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF); + /* In ::external_lock InnoDB resets the fields which tell it that the handle is used in the HANDLER interface. Tell it again that diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 5e9ca203632..a291a824e61 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -2492,7 +2492,11 @@ select_create::prepare(List &values, SELECT_LEX_UNIT *u) } /* First field to copy */ - field=table->field+table->s->fields - values.elements; + field= table->field+table->s->fields - values.elements; + + /* Mark all fields that are given values */ + for (Field **f= field ; *f ; f++) + (*f)->query_id= thd->query_id; /* Don't set timestamp if used */ table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 1a9b4ef4db7..065406d1f0c 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4843,7 +4843,6 @@ end_with_restore_list: if (thd->one_shot_set && lex->sql_command != SQLCOM_SET_OPTION) reset_one_shot_variables(thd); - /* The return value for ROW_COUNT() is "implementation dependent" if the statement is not DELETE, INSERT or UPDATE (or a CALL executing @@ -4851,13 +4850,10 @@ end_with_restore_list: */ if (lex->sql_command != SQLCOM_CALL && uc_update_queries[lex->sql_command]<2) thd->row_count_func= -1; - goto cleanup; + DBUG_RETURN(res || thd->net.report_error); error: - res= 1; - -cleanup: - DBUG_RETURN(res || thd->net.report_error); + DBUG_RETURN(1); } @@ -5080,7 +5076,7 @@ check_table_access(THD *thd, ulong want_access,TABLE_LIST *tables, the given table list refers to the list for prelocking (contains tables of other queries). For simple queries first_not_own_table is 0. */ - for (; tables && tables != first_not_own_table; tables= tables->next_global) + for (; tables != first_not_own_table; tables= tables->next_global) { if (tables->schema_table && (want_access & ~(SELECT_ACL | EXTRA_ACL | FILE_ACL))) @@ -7558,7 +7554,7 @@ LEX_USER *create_definer(THD *thd, LEX_STRING *user_name, LEX_STRING *host_name) /* Create and initialize. */ - if (! (definer= (LEX_USER*) thd->alloc(sizeof (LEX_USER)))) + if (! (definer= (LEX_USER*) thd->alloc(sizeof(LEX_USER)))) return 0; definer->user= *user_name; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 470015f8869..52070aa8983 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -10628,7 +10628,7 @@ end_update(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)), item->save_org_in_field(group->field); /* Store in the used key if the field was 0 */ if (item->maybe_null) - group->buff[-1]=item->null_value ? 1 : 0; + group->buff[-1]= (char) group->field->is_null(); } if (!table->file->index_read(table->record[1], join->tmp_table_param.group_buff,0, diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index 296b55679a3..d3fda132f50 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -51,6 +51,13 @@ static File_option triggers_file_parameters[]= { { 0, 0 }, 0, FILE_OPTIONS_STRING } }; +File_option sql_modes_parameters= +{ + {STRING_WITH_LEN("sql_modes") }, + offsetof(class Table_triggers_list, definition_modes_list), + FILE_OPTIONS_ULLLIST +}; + /* This must be kept up to date whenever a new option is added to the list above, as it specifies the number of required parameters of the trigger in @@ -428,7 +435,7 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables, #ifndef NO_EMBEDDED_ACCESS_CHECKS if (!is_acl_user(lex->definer->host.str, - lex->definer->user.str)) + lex->definer->user.str)) { push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, @@ -771,7 +778,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, sizeof(LEX_STRING)))) DBUG_RETURN(1); // EOM - trg_definer->str= ""; + trg_definer->str= (char*) ""; trg_definer->length= 0; while (it++) @@ -1164,7 +1171,7 @@ bool Table_triggers_list::process_triggers(THD *thd, trg_event_type event, if (is_special_var_used(event, time_type)) { - TABLE_LIST table_list; + TABLE_LIST table_list, **save_query_tables_own_last; bzero((char *) &table_list, sizeof (table_list)); table_list.db= (char *) table->s->db; table_list.db_length= strlen(table_list.db); @@ -1172,8 +1179,12 @@ bool Table_triggers_list::process_triggers(THD *thd, trg_event_type event, table_list.table_name_length= strlen(table_list.table_name); table_list.alias= (char *) table->alias; table_list.table= table; + save_query_tables_own_last= thd->lex->query_tables_own_last; + thd->lex->query_tables_own_last= 0; - if (check_table_access(thd, SELECT_ACL | UPDATE_ACL, &table_list, 0)) + res= check_table_access(thd, SELECT_ACL | UPDATE_ACL, &table_list, 0); + thd->lex->query_tables_own_last= save_query_tables_own_last; + if (res) { sp_restore_security_context(thd, save_ctx); return TRUE; @@ -1215,32 +1226,29 @@ bool Table_triggers_list::process_triggers(THD *thd, trg_event_type event, TRUE Error */ +#define INVALID_SQL_MODES_LENGTH 13 + bool Handle_old_incorrect_sql_modes_hook::process_unknown_string(char *&unknown_key, gptr base, MEM_ROOT *mem_root, char *end) { -#define INVALID_SQL_MODES_LENGTH 13 DBUG_ENTER("handle_old_incorrect_sql_modes"); DBUG_PRINT("info", ("unknown key:%60s", unknown_key)); + if (unknown_key + INVALID_SQL_MODES_LENGTH + 1 < end && unknown_key[INVALID_SQL_MODES_LENGTH] == '=' && !memcmp(unknown_key, STRING_WITH_LEN("sql_modes"))) { + char *ptr= unknown_key + INVALID_SQL_MODES_LENGTH + 1; + DBUG_PRINT("info", ("sql_modes affected by BUG#14090 detected")); push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_OLD_FILE_FORMAT, ER(ER_OLD_FILE_FORMAT), (char *)path, "TRIGGER"); - File_option sql_modes_parameters= - { - {STRING_WITH_LEN("sql_modes") }, - offsetof(class Table_triggers_list, definition_modes_list), - FILE_OPTIONS_ULLLIST - }; - char *ptr= unknown_key + INVALID_SQL_MODES_LENGTH + 1; if (get_file_options_ulllist(ptr, end, unknown_key, base, &sql_modes_parameters, mem_root)) { From 360a5e3c2a4f3f37e52ea12810a50aefd0f05d04 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 6 Jan 2006 12:48:14 +0200 Subject: [PATCH 33/68] After merge fix and a safety fix for handler sql/sql_handler.cc: Move lock tables before conditions as lock tables may reopen tables sql/sql_trigger.cc: After merge fix --- sql/sql_handler.cc | 14 +++++++------- sql/sql_trigger.cc | 5 +++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index 545cf41eeeb..fae48c7d164 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -414,6 +414,13 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables, } tables->table=table; + HANDLER_TABLES_HACK(thd); + lock= mysql_lock_tables(thd, &tables->table, 1, 0, ¬_used); + HANDLER_TABLES_HACK(thd); + + if (!lock) + goto err0; // mysql_lock_tables() printed error message already + if (cond && ((!cond->fixed && cond->fix_fields(thd, &cond)) || cond->check_cols(1))) goto err0; @@ -427,13 +434,6 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables, } } - HANDLER_TABLES_HACK(thd); - lock= mysql_lock_tables(thd, &tables->table, 1, 0, ¬_used); - HANDLER_TABLES_HACK(thd); - - if (!lock) - goto err0; // mysql_lock_tables() printed error message already - if (insert_fields(thd, &thd->lex->select_lex.context, tables->db, tables->alias, &it, 0)) goto err0; diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index 5f2d269ed1e..bbc32950c2d 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -1189,9 +1189,10 @@ bool Table_triggers_list::process_triggers(THD *thd, trg_event_type event, save_query_tables_own_last= thd->lex->query_tables_own_last; thd->lex->query_tables_own_last= 0; - res= check_table_access(thd, SELECT_ACL | UPDATE_ACL, &table_list, 0); + err_status= check_table_access(thd, SELECT_ACL | UPDATE_ACL, + &table_list, 0); thd->lex->query_tables_own_last= save_query_tables_own_last; - if (res) + if (err_status) { sp_restore_security_context(thd, save_ctx); return TRUE; From f3915a41647978a71aedb209a28f8b61f1dd4cd5 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 6 Jan 2006 14:30:25 +0100 Subject: [PATCH 34/68] Fix compile failure on QNX. --- sql/sp_head.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sp_head.cc b/sql/sp_head.cc index d6db9a47748..12f9260e7b1 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -1755,7 +1755,7 @@ void sp_head::set_definer(const char *definer, uint definerlen) { - char *p= strrchr(definer, '@'); + const char *p= strrchr(definer, '@'); if (!p) { From 2dcedd9cbc4effee5a1c7e4c8045f2e8adced065 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 6 Jan 2006 21:42:17 +0200 Subject: [PATCH 35/68] Fixes during review of new pushed code: Remove wrong fix for Bug#14397 - OPTIMIZE TABLE with an open HANDLER causes a crash Safety fix for bug #13855 "select distinct with group by caused server crash" client/mysqlimport.c: Remove not used variable myisam/myisam_ftdump.c: Fixed compiler warning sql/item_cmpfunc.cc: Removed compiler warning sql/sql_handler.cc: Remove wrong fix for Bug#14397 - OPTIMIZE TABLE with an open HANDLER causes a crash. It's better to let mysql_lock_tables reopen the TABLE object in case of OPTIMIZE TABLE and fix items AFTER mysql_lock_table() instead of before sql/sql_select.cc: Safety fix for bug #13855 "select distinct with group by caused server crash" The previous patch only removed the symptomps, this fix removed the cause of the problem (Which was that not all hidden_fields was stored in the temporary table) --- client/mysqlimport.c | 1 - myisam/myisam_ftdump.c | 2 +- sql/item_cmpfunc.cc | 2 +- sql/sql_handler.cc | 46 +++++++++++------------------------------- sql/sql_select.cc | 9 ++++++++- 5 files changed, 22 insertions(+), 38 deletions(-) diff --git a/client/mysqlimport.c b/client/mysqlimport.c index 0932cf7432a..2dcb1d4eb6d 100644 --- a/client/mysqlimport.c +++ b/client/mysqlimport.c @@ -252,7 +252,6 @@ static int write_to_table(char *filename, MYSQL *sock) { char tablename[FN_REFLEN], hard_path[FN_REFLEN], sql_statement[FN_REFLEN*16+256], *end; - my_bool local_file; DBUG_ENTER("write_to_table"); DBUG_PRINT("enter",("filename: %s",filename)); diff --git a/myisam/myisam_ftdump.c b/myisam/myisam_ftdump.c index 838f90feae5..005d15376fb 100644 --- a/myisam/myisam_ftdump.c +++ b/myisam/myisam_ftdump.c @@ -66,7 +66,7 @@ int main(int argc,char *argv[]) struct { MI_INFO *info; } aio0, *aio=&aio0; /* for GWS_IN_USE */ MY_INIT(argv[0]); - if (error=handle_options(&argc, &argv, my_long_options, get_one_option)) + if ((error= handle_options(&argc, &argv, my_long_options, get_one_option))) exit(error); if (count || dump) verbose=0; diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 107a17815ae..db6c4d9789b 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -659,7 +659,7 @@ bool Item_func_nullif::is_null() { if (!(this->*cmp_func)()) - return null_value=1; + return (null_value= 1); return 0; } diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index 28e94d1a477..58b75e667b5 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -380,27 +380,6 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, DBUG_PRINT("info-in-hash",("'%s'.'%s' as '%s' tab %p", hash_tables->db, hash_tables->real_name, hash_tables->alias, table)); - /* Table might have been flushed. */ - if (table && (table->version != refresh_version)) - { - /* - We must follow the thd->handler_tables chain, as we need the - address of the 'next' pointer referencing this table - for close_thread_table(). - */ - for (table_ptr= &(thd->handler_tables); - *table_ptr && (*table_ptr != table); - table_ptr= &(*table_ptr)->next) - {} - VOID(pthread_mutex_lock(&LOCK_open)); - if (close_thread_table(thd, table_ptr)) - { - /* Tell threads waiting for refresh that something has happened */ - VOID(pthread_cond_broadcast(&COND_refresh)); - } - VOID(pthread_mutex_unlock(&LOCK_open)); - table= hash_tables->table= NULL; - } if (!table) { /* @@ -447,11 +426,16 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, } tables->table=table; + HANDLER_TABLES_HACK(thd); + lock= mysql_lock_tables(thd, &tables->table, 1, 0); + HANDLER_TABLES_HACK(thd); + + if (!lock) + goto err0; // mysql_lock_tables() printed error message already + if (cond && cond->fix_fields(thd,tables)) goto err0; - table->file->init_table_handle_for_HANDLER(); // Only InnoDB requires it - if (keyname) { if ((keyno=find_type(keyname, &table->keynames, 1+2)-1)<0) @@ -462,6 +446,11 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, } table->file->index_init(keyno); } + + byte *key; + uint key_len; + LINT_INIT(key); + LINT_INIT(key_len); if (insert_fields(thd,tables,tables->db,tables->alias,&it)) goto err0; @@ -469,17 +458,6 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, select_limit+=offset_limit; send_fields(thd,list,1); - HANDLER_TABLES_HACK(thd); - lock= mysql_lock_tables(thd, &tables->table, 1, 0); - HANDLER_TABLES_HACK(thd); - - byte *key; - uint key_len; - LINT_INIT(key); - LINT_INIT(key_len); - if (!lock) - goto err0; // mysql_lock_tables() printed error message already - table->file->init_table_handle_for_HANDLER(); // Only InnoDB requires it for (num_rows=0; num_rows < select_limit; ) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 6dd68a60f88..32658f92416 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -4082,7 +4082,14 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List &fields, *(reg_field++) =new_field; } if (!--hidden_field_count) + { hidden_null_count=null_count; + /* + We need to update hidden_field_count as we may have stored group + functions with constant arguments + */ + param->hidden_field_count= (uint) (reg_field - table->field); + } } DBUG_ASSERT(field_count >= (uint) (reg_field - table->field)); field_count= (uint) (reg_field - table->field); @@ -4270,7 +4277,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List &fields, } } - if (distinct) + if (distinct && field_count != param->hidden_field_count) { /* Create an unique key or an unique constraint over all columns From 312c2f4759514c6594e630e6d1237b8875022328 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 6 Jan 2006 22:28:26 -0800 Subject: [PATCH 36/68] Fixed bug #16016: MIN/MAX optimization was not applied to views. mysql-test/r/view.result: Added a test case for bug #16016. mysql-test/t/view.test: Added a test case for bug #16016. sql/opt_sum.cc: Fixed bug #16016: MIN/MAX optimization was not applied to views. The fix employs the standard way of handling direct references to view fields. --- mysql-test/r/view.result | 29 +++++++++++++++++++++++++++++ mysql-test/t/view.test | 24 ++++++++++++++++++++++++ sql/opt_sum.cc | 10 +++++----- 3 files changed, 58 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index b9380dcf033..8b6d0787ada 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -2475,3 +2475,32 @@ alias1 alias2 5 5 drop view v2, v1; drop table t1; +CREATE TABLE t1 (a int PRIMARY KEY, b int); +INSERT INTO t1 VALUES (2,20), (3,10), (1,10), (0,30), (5,10); +CREATE VIEW v1 AS SELECT * FROM t1; +SELECT MAX(a) FROM t1; +MAX(a) +5 +SELECT MAX(a) FROM v1; +MAX(a) +5 +EXPLAIN SELECT MAX(a) FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +EXPLAIN SELECT MAX(a) FROM v1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +SELECT MIN(a) FROM t1; +MIN(a) +0 +SELECT MIN(a) FROM v1; +MIN(a) +0 +EXPLAIN SELECT MIN(a) FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +EXPLAIN SELECT MIN(a) FROM v1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +DROP VIEW v1; +DROP TABLE t1; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index db6c12fdacb..5f3678215f2 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -2339,3 +2339,27 @@ order by v2.receipt_id; drop view v2, v1; drop table t1; + +# +# Bug#16016: MIN/MAX optimization for views +# + +CREATE TABLE t1 (a int PRIMARY KEY, b int); +INSERT INTO t1 VALUES (2,20), (3,10), (1,10), (0,30), (5,10); + +CREATE VIEW v1 AS SELECT * FROM t1; + +SELECT MAX(a) FROM t1; +SELECT MAX(a) FROM v1; + +EXPLAIN SELECT MAX(a) FROM t1; +EXPLAIN SELECT MAX(a) FROM v1; + +SELECT MIN(a) FROM t1; +SELECT MIN(a) FROM v1; + +EXPLAIN SELECT MIN(a) FROM t1; +EXPLAIN SELECT MIN(a) FROM v1; + +DROP VIEW v1; +DROP TABLE t1; diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc index 37acce2934b..ed8e694dcb7 100644 --- a/sql/opt_sum.cc +++ b/sql/opt_sum.cc @@ -180,14 +180,14 @@ int opt_sum_query(TABLE_LIST *tables, List &all_fields,COND *conds) indexes to find the key. */ Item *expr=item_sum->args[0]; - if (expr->type() == Item::FIELD_ITEM) + if (expr->real_item()->type() == Item::FIELD_ITEM) { byte key_buff[MAX_KEY_LENGTH]; TABLE_REF ref; uint range_fl, prefix_len; ref.key_buff= key_buff; - Item_field *item_field= ((Item_field*) expr); + Item_field *item_field= (Item_field*) (expr->real_item()); TABLE *table= item_field->field->table; /* @@ -267,14 +267,14 @@ int opt_sum_query(TABLE_LIST *tables, List &all_fields,COND *conds) indexes to find the key. */ Item *expr=item_sum->args[0]; - if (expr->type() == Item::FIELD_ITEM) + if (expr->real_item()->type() == Item::FIELD_ITEM) { byte key_buff[MAX_KEY_LENGTH]; TABLE_REF ref; - uint range_fl, prefix_len; + uint range_fl, prefix_len; ref.key_buff= key_buff; - Item_field *item_field= ((Item_field*) expr); + Item_field *item_field= (Item_field*) (expr->real_item()); TABLE *table= item_field->field->table; /* From e6dff4236702cb240d3dc9336e891cd95f9eb291 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 8 Jan 2006 07:42:40 +0100 Subject: [PATCH 37/68] BUG#16282: Remove unused gcc.cpp linker input that causes failure in make -j. BitKeeper/deleted/.del-gcc.cpp~3d2e013cfac48838: Delete: ndb/src/common/portlib/gcc.cpp --- ndb/config/common.mk.am | 2 +- ndb/src/common/portlib/Makefile.am | 2 -- ndb/src/common/portlib/gcc.cpp | 7 ------- 3 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 ndb/src/common/portlib/gcc.cpp diff --git a/ndb/config/common.mk.am b/ndb/config/common.mk.am index 869e2fae91d..6fda12d33b0 100644 --- a/ndb/config/common.mk.am +++ b/ndb/config/common.mk.am @@ -7,6 +7,6 @@ ndbapiincludedir = "$(pkgincludedir)/ndb/ndbapi" mgmapiincludedir = "$(pkgincludedir)/ndb/mgmapi" INCLUDES = $(INCLUDES_LOC) -LDADD = $(top_srcdir)/ndb/src/common/portlib/gcc.cpp $(LDADD_LOC) +LDADD = $(LDADD_LOC) DEFS = @DEFS@ @NDB_DEFS@ $(DEFS_LOC) $(NDB_EXTRA_FLAGS) NDB_CXXFLAGS=@ndb_cxxflags_fix@ $(NDB_CXXFLAGS_LOC) diff --git a/ndb/src/common/portlib/Makefile.am b/ndb/src/common/portlib/Makefile.am index 99138a7414e..1e27d713495 100644 --- a/ndb/src/common/portlib/Makefile.am +++ b/ndb/src/common/portlib/Makefile.am @@ -1,5 +1,3 @@ -noinst_HEADERS = gcc.cpp - noinst_LTLIBRARIES = libportlib.la libportlib_la_SOURCES = \ diff --git a/ndb/src/common/portlib/gcc.cpp b/ndb/src/common/portlib/gcc.cpp deleted file mode 100644 index 4e49d787d3c..00000000000 --- a/ndb/src/common/portlib/gcc.cpp +++ /dev/null @@ -1,7 +0,0 @@ - -/** - * GCC linking problem... - */ -#if 0 -extern "C" { int __cxa_pure_virtual() { return 0;} } -#endif From 770e0e8118065a27c1e9583b1707864ab4c3120c Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 7 Jan 2006 23:00:06 -0800 Subject: [PATCH 38/68] Fixed bug #14274: a query with a having clause containing only set function returned a wrong result set. mysql-test/r/having.result: Added a test case for bug #14274. mysql-test/t/having.test: Added a test case for bug #14274. sql/sql_select.cc: Fixed bug #14274: a query with a having clause containing only set function returned a wrong result set. It happened because processing of the set functions in having started with a call of the split_sum_func method, instead of the split_sum_func2 method. --- mysql-test/r/having.result | 13 +++++++++++++ mysql-test/t/having.test | 12 ++++++++++++ sql/sql_select.cc | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/having.result b/mysql-test/r/having.result index 218276406b1..9730f9f81bf 100644 --- a/mysql-test/r/having.result +++ b/mysql-test/r/having.result @@ -128,3 +128,16 @@ id description c 1 test 0 2 test2 0 drop table t1,t2,t3; +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (3), (4), (1), (3), (1); +SELECT SUM(a) FROM t1 GROUP BY a HAVING SUM(a)>0; +SUM(a) +2 +6 +4 +SELECT SUM(a) FROM t1 GROUP BY a HAVING SUM(a); +SUM(a) +2 +6 +4 +DROP TABLE t1; diff --git a/mysql-test/t/having.test b/mysql-test/t/having.test index 920a3b752ab..3dd9ace6a1b 100644 --- a/mysql-test/t/having.test +++ b/mysql-test/t/having.test @@ -123,4 +123,16 @@ group by a.id, a.description having (a.description is not null) and (c=0); drop table t1,t2,t3; +# +# Bug #14274: HAVING clause containing only set function +# + +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (3), (4), (1), (3), (1); + +SELECT SUM(a) FROM t1 GROUP BY a HAVING SUM(a)>0; +SELECT SUM(a) FROM t1 GROUP BY a HAVING SUM(a); + +DROP TABLE t1; + # End of 4.1 tests diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 5e29c98e2c8..09900c89307 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -287,7 +287,7 @@ JOIN::prepare(Item ***rref_pointer_array, if (having_fix_rc || thd->net.report_error) DBUG_RETURN(-1); /* purecov: inspected */ if (having->with_sum_func) - having->split_sum_func(thd, ref_pointer_array, all_fields); + having->split_sum_func2(thd, ref_pointer_array, all_fields, &having); } // Is it subselect From 51525a9b82f59ec7d135c1a906a11ca3900caba4 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 9 Jan 2006 01:09:42 +0100 Subject: [PATCH 39/68] ndb - wl#2972 ndb api test_event_merge 5.0+5.1 ndb/test/ndbapi/test_event_merge.cpp: 5.0 passes. 5.1 has many problems --- ndb/test/ndbapi/test_event_merge.cpp | 1245 ++++++++++++++++++-------- 1 file changed, 877 insertions(+), 368 deletions(-) diff --git a/ndb/test/ndbapi/test_event_merge.cpp b/ndb/test/ndbapi/test_event_merge.cpp index 1332455cdc5..f57667caf62 100644 --- a/ndb/test/ndbapi/test_event_merge.cpp +++ b/ndb/test/ndbapi/test_event_merge.cpp @@ -27,6 +27,9 @@ #undef version50 #endif +// until rbr in 5.1 +#undef version51rbr + #if !defined(min) || !defined(max) #define min(x, y) ((x) < (y) ? (x) : (y)) #define max(x, y) ((x) > (y) ? (x) : (y)) @@ -42,13 +45,20 @@ * 2) In event API version >= 5.1 separate commits within same GCI are * by default merged. This is required to read blob data via NdbBlob. * - * This test program ignores Blob columns in version 5.0. + * Option --separate-events disables GCI merge and implies --no-blobs. + * This is used to test basic events functionality. + * + * Option --no-blobs omits blob attributes. This is used to test GCI + * merge without getting into blob bugs. + * + * Option --no-multiops allows 1 operation per commit. This avoids TUP + * and blob multi-operation bugs. * * There are 5 ways (ignoring NUL operand) to compose 2 ops: * 5.0 bugs 5.1 bugs * INS o DEL = NUL - * INS o UPD = INS 5.1 - * DEL o INS = UPD type=INS 5.1 + * INS o UPD = INS type=INS + * DEL o INS = UPD type=INS type=INS * UPD o DEL = DEL no event * UPD o UPD = UPD */ @@ -59,41 +69,69 @@ struct Opts { uint loop; uint maxops; uint maxpk; - const char* opstr; + my_bool no_blobs; + my_bool no_multiops; + my_bool one_blob; + const char* opstring; uint seed; my_bool separate_events; my_bool use_table; }; static Opts g_opts; -static const uint g_maxops = 10000; static const uint g_maxpk = 100; +static const uint g_maxopstringpart = 100; +static const char* g_opstringpart[g_maxopstringpart]; +static uint g_opstringparts = 0; +static uint g_loop = 0; static Ndb_cluster_connection* g_ncc = 0; static Ndb* g_ndb = 0; static NdbDictionary::Dictionary* g_dic = 0; static NdbTransaction* g_con = 0; static NdbOperation* g_op = 0; +static NdbScanOperation* g_scan_op = 0; static const char* g_tabname = "tem1"; static const char* g_evtname = "tem1ev1"; static const uint g_charlen = 5; +static const char* g_charval = "abcdefgh"; static const char* g_csname = "latin1_swedish_ci"; +static uint g_blobinlinesize = 256; +static uint g_blobpartsize = 2000; +static uint g_blobstripesize = 2; +static const uint g_maxblobsize = 100000; + static const NdbDictionary::Table* g_tab = 0; static const NdbDictionary::Event* g_evt = 0; static NdbEventOperation* g_evt_op = 0; +static NdbBlob* g_bh = 0; static uint -urandom(uint n) +urandom() { uint r = (uint)random(); - if (n != 0) - r = r % n; return r; } +static uint +urandom(uint m) +{ + if (m == 0) + return 0; + uint r = urandom(); + r = r % m; + return r; +} + +static bool +urandom(uint per, uint cent) +{ + return urandom(cent) < per; +} + static int& g_loglevel = g_opts.loglevel; // default log level #define chkdb(x) \ @@ -138,11 +176,21 @@ errdb() if (e.code != 0) ll0(++any << " op: error " << e); } + if (g_scan_op != 0) { + const NdbError& e = g_scan_op->getNdbError(); + if (e.code != 0) + ll0(++any << " scan_op: error " << e); + } if (g_evt_op != 0) { const NdbError& e = g_evt_op->getNdbError(); if (e.code != 0) ll0(++any << " evt_op: error " << e); } + if (g_bh != 0) { + const NdbError& e = g_bh->getNdbError(); + if (e.code != 0) + ll0(++any << " evt_op: error " << e); + } if (! any) ll0("unknown db error"); } @@ -155,31 +203,47 @@ struct Col { bool nullable; uint length; uint size; + bool isblob() const { + return type == NdbDictionary::Column::Text; + } }; static Col g_col[] = { { 0, "pk1", NdbDictionary::Column::Unsigned, true, false, 1, 4 }, { 1, "pk2", NdbDictionary::Column::Char, true, false, g_charlen, g_charlen }, { 2, "seq", NdbDictionary::Column::Unsigned, false, false, 1, 4 }, - { 3, "cc1", NdbDictionary::Column::Char, false, true, g_charlen, g_charlen } + { 3, "cc1", NdbDictionary::Column::Char, false, true, g_charlen, g_charlen }, + { 4, "tx1", NdbDictionary::Column::Text, false, true, 0, 0 }, + { 5, "tx2", NdbDictionary::Column::Text, false, true, 0, 0 } }; -static const uint g_ncol = sizeof(g_col)/sizeof(g_col[0]); +static const uint g_maxcol = sizeof(g_col)/sizeof(g_col[0]); + +static uint +ncol() +{ + uint n = g_maxcol; + if (g_opts.no_blobs) + n -= 2; + else if (g_opts.one_blob) + n -= 1; + return n; +} static const Col& getcol(uint i) { - if (i < g_ncol) + if (i < ncol()) return g_col[i]; assert(false); - return g_col[g_ncol]; + return g_col[0]; } static const Col& getcol(const char* name) { uint i; - for (i = 0; i < g_ncol; i++) + for (i = 0; i < ncol(); i++) if (strcmp(g_col[i].name, name) == 0) break; return getcol(i); @@ -194,7 +258,7 @@ createtable() CHARSET_INFO* cs; chkrc((cs = get_charset_by_name(g_csname, MYF(0))) != 0); uint i; - for (i = 0; i < g_ncol; i++) { + for (i = 0; i < ncol(); i++) { const Col& c = g_col[i]; NdbDictionary::Column col(c.name); col.setType(c.type); @@ -209,6 +273,12 @@ createtable() col.setLength(c.length); col.setCharset(cs); break; + case NdbDictionary::Column::Text: + col.setInlineSize(g_blobinlinesize); + col.setPartSize(g_blobpartsize); + col.setStripeSize(g_blobstripesize); + col.setCharset(cs); + break; default: assert(false); break; @@ -229,9 +299,9 @@ createtable() chkdb((g_op = g_con->getNdbOperation(g_tabname)) != 0); chkdb(g_op->insertTuple() == 0); Uint32 pk1; - char pk2[g_charlen]; + char pk2[g_charlen + 1]; pk1 = g_maxpk; - memset(pk2, 0x20, g_charlen); + sprintf(pk2, "%-*u", g_charlen, pk1); chkdb(g_op->equal("pk1", (char*)&pk1) == 0); chkdb(g_op->equal("pk2", (char*)&pk2[0]) == 0); chkdb(g_con->execute(Commit) == 0); @@ -255,34 +325,86 @@ droptable() } struct Data { + struct Txt { char* val; uint len; }; + union Ptr { Uint32* u32; char* ch; Txt* txt; void* v; }; Uint32 pk1; - char pk2[g_charlen]; + char pk2[g_charlen + 1]; Uint32 seq; - char cc1[g_charlen]; - void* ptr[g_ncol]; - int ind[g_ncol]; // -1 = no data, 1 = NULL, 0 = not NULL + char cc1[g_charlen + 1]; + Txt tx1; + Txt tx2; + Ptr ptr[g_maxcol]; + int ind[g_maxcol]; // -1 = no data, 1 = NULL, 0 = not NULL + uint noop; // bit: omit in NdbOperation (implicit NULL INS or no UPD) + uint ppeq; // bit: post/pre data value equal in GCI data[0]/data[1] void init() { uint i; pk1 = 0; memset(pk2, 0, sizeof(pk2)); seq = 0; memset(cc1, 0, sizeof(cc1)); - ptr[0] = &pk1; - ptr[1] = pk2; - ptr[2] = &seq; - ptr[3] = cc1; - for (i = 0; i < g_ncol; i++) + tx1.val = tx2.val = 0; + tx1.len = tx2.len = 0; + ptr[0].u32 = &pk1; + ptr[1].ch = pk2; + ptr[2].u32 = &seq; + ptr[3].ch = cc1; + ptr[4].txt = &tx1; + ptr[5].txt = &tx2; + for (i = 0; i < g_maxcol; i++) ind[i] = -1; + noop = 0; + ppeq = 0; + } + void free() { + delete [] tx1.val; + delete [] tx2.val; + init(); } }; +static int +cmpcol(const Col& c, const Data& d1, const Data& d2) +{ + uint i = c.no; + if (d1.ind[i] != d2.ind[i]) + return 1; + if (d1.ind[i] == 0) { + switch (c.type) { + case NdbDictionary::Column::Unsigned: + if (*d1.ptr[i].u32 != *d2.ptr[i].u32) + return 1; + break; + case NdbDictionary::Column::Char: + if (memcmp(d1.ptr[i].ch, d2.ptr[i].ch, c.size) != 0) + return 1; + break; + case NdbDictionary::Column::Text: + { + const Data::Txt& t1 = *d1.ptr[i].txt; + const Data::Txt& t2 = *d2.ptr[i].txt; + if (t1.len != t2.len) + return 1; + if (memcmp(t1.val, t2.val, t1.len) != 0) + return 1; + } + break; + default: + assert(false); + break; + } + } + return 0; +} + static NdbOut& operator<<(NdbOut& out, const Data& d) { uint i; - for (i = 0; i < g_ncol; i++) { + for (i = 0; i < ncol(); i++) { const Col& c = getcol(i); - out << (i == 0 ? "" : " ") << c.name << "="; + out << (i == 0 ? "" : " ") << c.name; + out << (! (d.noop & (1 << i)) ? "=" : ":"); if (d.ind[i] == -1) continue; if (d.ind[i] == 1) { @@ -291,12 +413,12 @@ operator<<(NdbOut& out, const Data& d) } switch (c.type) { case NdbDictionary::Column::Unsigned: - out << *(Uint32*)d.ptr[i]; + out << *d.ptr[i].u32; break; case NdbDictionary::Column::Char: { char buf[g_charlen + 1]; - memcpy(buf, d.ptr[i], g_charlen); + memcpy(buf, d.ptr[i].ch, g_charlen); uint n = g_charlen; while (1) { buf[n] = 0; @@ -304,11 +426,30 @@ operator<<(NdbOut& out, const Data& d) break; n--; } - out << buf; + out << "'" << buf << "'"; + } + break; + case NdbDictionary::Column::Text: + { + Data::Txt& t = *d.ptr[i].txt; + bool first = true; + uint j = 0; + while (j < t.len) { + char c[2]; + c[0] = t.val[j++]; + c[1] = 0; + uint m = 1; + while (j < t.len && t.val[j] == c[0]) + j++, m++; + if (! first) + out << "+"; + first = false; + out << m << c; + } } break; default: - out << "?"; + assert(false); break; } } @@ -329,18 +470,26 @@ struct Op { // single or composite Type type; Op* next_op; // within one commit Op* next_com; // next commit chain or next event + Op* next_gci; // groups commit chains (unless --separate-events) + Op* next_ev; + Op* next_free; // free list + bool free; // on free list uint num_op; uint num_com; Data data[2]; // 0-post 1-pre bool match; // matched to event - void init() { + Uint32 gci; // defined for com op and event + void init(Kind a_kind) { + kind = a_kind; assert(kind == OP || kind == EV); type = NUL; - next_op = next_com = 0; + next_op = next_com = next_gci = next_ev = next_free = 0; + free = false; num_op = num_com = 0; data[0].init(); data[1].init(); match = false; + gci = 0; } }; @@ -370,9 +519,11 @@ operator<<(NdbOut& out, Op::Type t) static NdbOut& operator<<(NdbOut& out, const Op& op) { - out << "t=" << op.type; + out << op.type; out << " " << op.data[0]; out << " [" << op.data[1] << "]"; + if (op.gci != 0) + out << " gci:" << op.gci; return out; } @@ -398,75 +549,104 @@ seteventtype(Op* ev, NdbDictionary::Event::TableEvent te) return 0; } +static Op* g_opfree = 0; +static uint g_freeops = 0; static uint g_usedops = 0; -static uint g_usedevs = 0; -static Op g_oplist[g_maxops]; -static Op g_evlist[g_maxops]; -static uint g_maxcom = 8; // max ops per commit - +static uint g_maxcom = 10; // max ops per commit static Op* g_pk_op[g_maxpk]; static Op* g_pk_ev[g_maxpk]; static uint g_seq = 0; - -static NdbRecAttr* g_ra[2][g_ncol]; // 0-post 1-pre +static NdbRecAttr* g_ev_ra[2][g_maxcol]; // 0-post 1-pre +static NdbBlob* g_ev_bh[2][g_maxcol]; // 0-post 1-pre static Op* g_rec_ev; -static uint g_ev_cnt[g_maxpk]; - -static uint -getfreeops() -{ - assert(g_opts.maxops >= g_usedops); - return g_opts.maxops - g_usedops; -} - -static uint -getfreeevs() -{ - assert(g_opts.maxops >= g_usedevs); - return g_opts.maxops - g_usedevs; -} +static uint g_ev_pos[g_maxpk]; static Op* -getop() +getop(Op::Kind a_kind) { - if (g_usedops < g_opts.maxops) { - Op* op = &g_oplist[g_usedops++]; - op->kind = Op::OP; - op->init(); - return op; + if (g_opfree == 0) { + assert(g_freeops == 0); + Op* op = new Op; + assert(op != 0); + op->next_free = g_opfree; + g_opfree = op; + op->free = true; + g_freeops++; } - assert(false); - return 0; + Op* op = g_opfree; + g_opfree = op->next_free; + assert(g_freeops != 0); + g_freeops--; + g_usedops++; + op->init(a_kind); + return op; } -static Op* -getev() +static void +freeop(Op* op) { - if (g_usedevs < g_opts.maxops) { - Op* ev = &g_evlist[g_usedevs++]; - ev->kind = Op::EV; - ev->init(); - return ev; - } - assert(false); - return 0; + assert(! op->free); + op->data[0].free(); + op->data[1].free(); + op->free = true; + op->next_free = g_opfree; + g_opfree = op; + g_freeops++; + assert(g_usedops != 0); + g_usedops--; } static void resetmem() { int i, j; - for (j = 0; j < 2; j++) - for (i = 0; i < g_ncol; i++) - g_ra[j][i] = 0; - g_rec_ev = 0; - for (i = 0; i < g_opts.maxpk; i++) - g_pk_op[i] = 0; - for (i = 0; i < g_opts.maxpk; i++) - g_ev_cnt[i] = 0; - g_seq = 0; - g_usedops = 0; - g_usedevs = 0; + for (j = 0; j < 2; j++) { + for (i = 0; i < g_maxcol; i++) { + g_ev_ra[j][i] = 0; + g_ev_bh[j][i] = 0; + } + } + if (g_rec_ev != 0) { + freeop(g_rec_ev); + g_rec_ev = 0; + } + Uint32 pk1; + for (pk1 = 0; pk1 < g_opts.maxpk; pk1++) + g_ev_pos[pk1] = 0; + // leave g_seq + for (pk1 = 0; pk1 < g_opts.maxpk; pk1++) { + if (g_pk_op[pk1] != 0) { + Op* tot_op = g_pk_op[pk1]; + while (tot_op->next_gci != 0) { + Op* gci_op = tot_op->next_gci; + while (gci_op->next_com != 0) { + Op* com_op = gci_op->next_com; + while (com_op->next_op != 0) { + Op* op = com_op->next_op; + com_op->next_op = op->next_op; + freeop(op); + } + gci_op->next_com = com_op->next_com; + freeop(com_op); + } + tot_op->next_gci = gci_op->next_gci; + freeop(gci_op); + } + freeop(tot_op); + g_pk_op[pk1] = 0; + } + if (g_pk_ev[pk1] != 0) { + Op* tot_op = g_pk_ev[pk1]; + while (tot_op->next_ev != 0) { + Op* ev = tot_op->next_ev; + tot_op->next_ev = ev->next_ev; + freeop(ev); + } + freeop(tot_op); + g_pk_ev[pk1] = 0; + } + } + assert(g_usedops == 0); } struct Comp { @@ -487,43 +667,43 @@ static const uint g_ncomp = sizeof(g_comp)/sizeof(g_comp[0]); static int checkop(const Op* op, Uint32& pk1) { - const Data (&d)[2] = op->data; Op::Type t = op->type; - chkrc(t == Op::NUL || t == Op::INS || t == Op::DEL || t == Op::UPD); - { const Col& c = getcol("pk1"); - chkrc(d[0].ind[c.no] == 0); - pk1 = d[0].pk1; + if (t == Op::NUL) + return 0; + chkrc(t == Op::INS || t == Op::DEL || t == Op::UPD); + const Data& d0 = op->data[0]; + const Data& d1 = op->data[1]; + { + const Col& c = getcol("pk1"); + chkrc(d0.ind[c.no] == 0); + pk1 = d0.pk1; chkrc(pk1 < g_opts.maxpk); } uint i; - for (i = 0; i < g_ncol; i++) { + for (i = 0; i < ncol(); i++) { const Col& c = getcol(i); - if (t != Op::NUL) { - if (c.pk) { - chkrc(d[0].ind[i] == 0); // even DEL has PK in post data - if (t == Op::INS) { - chkrc(d[1].ind[i] == -1); - } else if (t == Op::DEL) { -#ifdef ndb_event_cares_about_pk_pre_data - chkrc(d[1].ind[i] == -1); -#endif - } else { -#ifdef ndb_event_cares_about_pk_pre_data - chkrc(d[1].ind[i] == 0); -#endif - } - } else { - if (t == Op::INS) { - chkrc(d[0].ind[i] >= 0); - chkrc(d[1].ind[i] == -1); - } else if (t == Op::DEL) { - chkrc(d[0].ind[i] == -1); - chkrc(d[1].ind[i] >= 0); - } else if (op->kind == Op::OP) { - chkrc(d[0].ind[i] >= 0); - chkrc(d[1].ind[i] >= 0); - } - } + const int ind0 = d0.ind[i]; + const int ind1 = d1.ind[i]; + // the rules are the rules.. + if (c.pk) { + chkrc(ind0 == 0); // always PK in post data + if (t == Op::INS) + chkrc(ind1 == -1); + if (t == Op::DEL) + chkrc(ind1 == -1); // no PK in pre data + if (t == Op::UPD) + chkrc(ind1 == 0); + } + if (! c.pk) { + if (t == Op::INS) + chkrc(ind0 >= 0 && ind1 == -1); + if (t == Op::DEL) + chkrc(ind0 == -1 && ind1 >= 0); // always non-PK in pre data + if (t == Op::UPD) + chkrc(ind0 == -1 || ind1 >= 0); // update must have pre data + } + if (! c.nullable) { + chkrc(ind0 <= 0 && ind1 <= 0); } } return 0; @@ -542,28 +722,51 @@ comptype(Op::Type t1, Op::Type t2) // only non-NUL static void copycol(const Col& c, const Data& d1, Data& d3) { - if ((d3.ind[c.no] = d1.ind[c.no]) != -1) - memmove(d3.ptr[c.no], d1.ptr[c.no], c.size); + uint i = c.no; + if ((d3.ind[i] = d1.ind[i]) == 0) { + if (! c.isblob()) { + memmove(d3.ptr[i].v, d1.ptr[i].v, c.size); + } else { + Data::Txt& t1 = *d1.ptr[i].txt; + Data::Txt& t3 = *d3.ptr[i].txt; + delete [] t3.val; + t3.val = new char [t1.len]; + t3.len = t1.len; + memcpy(t3.val, t1.val, t1.len); + } + } } static void -copykeys(const Data& d1, Data& d3) +copydata(const Data& d1, Data& d3, bool pk, bool nonpk) { uint i; - for (i = 0; i < g_ncol; i++) { + for (i = 0; i < ncol(); i++) { const Col& c = g_col[i]; - if (c.pk) + if (c.pk && pk || ! c.pk && nonpk) copycol(c, d1, d3); } } static void -copydata(const Data& d1, Data& d3) +compdata(const Data& d1, const Data& d2, Data& d3, bool pk, bool nonpk) { uint i; - for (i = 0; i < g_ncol; i++) { + for (i = 0; i < ncol(); i++) { const Col& c = g_col[i]; - copycol(c, d1, d3); + if (c.pk && pk || ! c.pk && nonpk) { + const Data* d = 0; + if (d1.ind[i] == -1 && d2.ind[i] == -1) + d3.ind[i] = -1; + else if (d1.ind[i] == -1 && d2.ind[i] != -1) + d = &d2; + else if (d1.ind[i] != -1 && d2.ind[i] == -1) + d = &d1; + else + d = &d2; + if (d != 0) + copycol(c, *d, d3); + } } } @@ -571,33 +774,13 @@ static void copyop(const Op* op1, Op* op3) { op3->type = op1->type; - copydata(op1->data[0], op3->data[0]); - copydata(op1->data[1], op3->data[1]); + copydata(op1->data[0], op3->data[0], true, true); + copydata(op1->data[1], op3->data[1], true, true); + op3->gci = op1->gci; Uint32 pk1_tmp; reqrc(checkop(op3, pk1_tmp) == 0); } -// not needed for ops -static void -compdata(const Data& d1, const Data& d2, Data& d3) // d2 overrides d1 -{ - uint i; - for (i = 0; i < g_ncol; i++) { - const Col& c = g_col[i]; - const Data* d = 0; - if (d1.ind[i] == -1 && d2.ind[i] == -1) - d3.ind[i] = -1; - else if (d1.ind[i] == -1 && d2.ind[i] != -1) - d = &d2; - else if (d1.ind[i] != -1 && d2.ind[i] == -1) - d = &d1; - else - d = &d2; - if (d != 0) - copycol(c, *d, d3); - } -} - static int compop(const Op* op1, const Op* op2, Op* op3) // op1 o op2 = op3 { @@ -610,16 +793,38 @@ compop(const Op* op1, const Op* op2, Op* op3) // op1 o op2 = op3 copyop(op2, op3); return 0; } + Op::Kind kind = + op1->kind == Op::OP && op2->kind == Op::OP ? Op::OP : Op::EV; + Op* res_op = getop(kind); chkrc((comp = comptype(op1->type, op2->type)) != 0); - op3->type = comp->t3; - copykeys(op2->data[0], op3->data[0]); - if (op3->type != Op::DEL) - copydata(op2->data[0], op3->data[0]); - if (op3->type != Op::INS) - copydata(op1->data[1], op3->data[1]); + res_op->type = comp->t3; + if (res_op->type == Op::INS) { + // INS o UPD + compdata(op1->data[0], op2->data[0], res_op->data[0], true, true); + // pre = undef + } + if (res_op->type == Op::DEL) { + // UPD o DEL + copydata(op2->data[0], res_op->data[0], true, false); // PK + copydata(op1->data[1], res_op->data[1], false, true); // non-PK + } + if (res_op->type == Op::UPD && op1->type == Op::DEL) { + // DEL o INS + copydata(op2->data[0], res_op->data[0], true, true); + copydata(op1->data[0], res_op->data[1], true, false); // PK + copydata(op1->data[1], res_op->data[1], false, true); // non-PK + } + if (res_op->type == Op::UPD && op1->type == Op::UPD) { + // UPD o UPD + compdata(op1->data[0], op2->data[0], res_op->data[0], true, true); + compdata(op2->data[1], op1->data[1], res_op->data[1], true, true); + } + assert(op1->gci == op2->gci); + res_op->gci = op2->gci; Uint32 pk1_tmp; - reqrc(checkop(op3, pk1_tmp) == 0); - // not eliminating identical post-pre fields + reqrc(checkop(res_op, pk1_tmp) == 0); + copyop(res_op, op3); + freeop(res_op); return 0; } @@ -632,12 +837,14 @@ createevent() NdbDictionary::Event evt(g_evtname); evt.setTable(*g_tab); evt.addTableEvent(NdbDictionary::Event::TE_ALL); - // pk always - evt.addEventColumn("pk1"); - evt.addEventColumn("pk2"); - // simple cols - evt.addEventColumn("seq"); - evt.addEventColumn("cc1"); + uint i; + for (i = 0; i < ncol(); i++) { + const Col& c = g_col[i]; + evt.addEventColumn(c.name); + } +#ifdef version51rbr + evt.separateEvents(g_opts.separate_events); +#endif if (g_dic->getEvent(evt.getName()) != 0) chkdb(g_dic->dropEvent(evt.getName()) == 0); chkdb(g_dic->createEvent(evt) == 0); @@ -666,20 +873,22 @@ createeventop() chkdb((g_evt_op = g_ndb->createEventOperation(g_evt->getName(), bsz)) != 0); #else chkdb((g_evt_op = g_ndb->createEventOperation(g_evt->getName())) != 0); +#ifdef version51rbr + g_evt_op->separateEvents(g_opts.separate_events); // not yet inherited +#endif #endif uint i; - for (i = 0; i < g_ncol; i++) { + for (i = 0; i < ncol(); i++) { const Col& c = g_col[i]; Data (&d)[2] = g_rec_ev->data; - switch (c.type) { - case NdbDictionary::Column::Unsigned: - case NdbDictionary::Column::Char: - chkdb((g_ra[0][i] = g_evt_op->getValue(c.name, (char*)d[0].ptr[i])) != 0); - chkdb((g_ra[1][i] = g_evt_op->getPreValue(c.name, (char*)d[1].ptr[i])) != 0); - break; - default: - assert(false); - break; + if (! c.isblob()) { + chkdb((g_ev_ra[0][i] = g_evt_op->getValue(c.name, (char*)d[0].ptr[i].v)) != 0); + chkdb((g_ev_ra[1][i] = g_evt_op->getPreValue(c.name, (char*)d[1].ptr[i].v)) != 0); + } else { +#ifdef version51rbr + chkdb((g_ev_bh[0][i] = g_evt_op->getBlobHandle(c.name)) != 0); + chkdb((g_ev_bh[1][i] = g_evt_op->getPreBlobHandle(c.name)) != 0); +#endif } } return 0; @@ -705,9 +914,9 @@ waitgci() // wait for event to be installed and for at least 1 GCI to pass chkdb((g_con = g_ndb->startTransaction()) != 0); { // forced to exec a dummy op Uint32 pk1; - char pk2[g_charlen]; + char pk2[g_charlen + 1]; pk1 = g_maxpk; - memset(pk2, 0x20, g_charlen); + sprintf(pk2, "%-*u", g_charlen, pk1); chkdb((g_op = g_con->getNdbOperation(g_tabname)) != 0); chkdb(g_op->readTuple() == 0); chkdb(g_op->equal("pk1", (char*)&pk1) == 0); @@ -723,61 +932,153 @@ waitgci() // wait for event to be installed and for at least 1 GCI to pass break; } i = 1; + sleep(1); } return 0; } +// scan table and set current tot_op for each pk1 static int -makeop(Op* op, Uint32 pk1, Op::Type t, const Op* prev_op) +scantab() { - op->type = t; - if (t != Op::INS) - copydata(prev_op->data[0], op->data[1]); + NdbRecAttr* ra[g_maxcol]; + NdbBlob* bh[g_maxcol]; + Op* rec_op = getop(Op::OP); + Data& d0 = rec_op->data[0]; + chkdb((g_con = g_ndb->startTransaction()) != 0); + chkdb((g_scan_op = g_con->getNdbScanOperation(g_tabname)) != 0); + chkdb(g_scan_op->readTuples() == 0); uint i; - for (i = 0; i < g_ncol; i++) { + for (i = 0; i < ncol(); i++) { const Col& c = getcol(i); - Data (&d)[2] = op->data; - if (i == getcol("pk1").no) { - d[0].pk1 = pk1; - d[0].ind[i] = 0; - continue; + if (! c.isblob()) { + chkdb((ra[i] = g_scan_op->getValue(c.name, (char*)d0.ptr[i].v)) != 0); + } else { + chkdb((bh[i] = g_scan_op->getBlobHandle(c.name)) != 0); } - if (i == getcol("pk2").no) { - sprintf(d[0].pk2, "%-*u", g_charlen, d[0].pk1); - d[0].ind[i] = 0; - continue; - } - if (t == Op::DEL) { - d[0].ind[i] = -1; - continue; - } - if (i == getcol("seq").no) { - d[0].seq = g_seq++; - d[0].ind[i] = 0; - continue; - } - uint u; - u = urandom(100); - if (c.nullable && u < 20) { - d[0].ind[i] = 1; + } + chkdb(g_con->execute(NoCommit) == 0); + int ret; + while ((ret = g_scan_op->nextResult()) == 0) { + Uint32 pk1 = d0.pk1; + if (pk1 >= g_opts.maxpk) continue; + rec_op->type = Op::INS; + for (i = 0; i < ncol(); i++) { + const Col& c = getcol(i); + int ind; + if (! c.isblob()) { + ind = ra[i]->isNULL(); + } else { +#ifdef version51rbr + int ret; + ret = bh[i]->getDefined(ind); + assert(ret == 0); + if (ind == 0) { + Data::Txt& t = *d0.ptr[i].txt; + Uint64 len64; + ret = bh[i]->getLength(len64); + assert(ret == 0); + t.len = (uint)len64; + delete [] t.val; + t.val = new char [t.len]; + memset(t.val, 'X', t.len); + Uint32 len = t.len; + ret = bh[i]->readData(t.val, len); + assert(ret == 0 && len == t.len); + } +#endif + } + assert(ind >= 0); + d0.ind[i] = ind; } + assert(g_pk_op[pk1] == 0); + Op* tot_op = g_pk_op[pk1] = getop(Op::OP); + copyop(rec_op, tot_op); + tot_op->type = Op::INS; + } + chkdb(ret == 1); + g_ndb->closeTransaction(g_con); + g_scan_op = 0; + g_con = 0; + freeop(rec_op); + return 0; +} + +static void +makedata(const Col& c, Data& d, Uint32 pk1, Op::Type t) +{ + uint i = c.no; + if (c.pk) { switch (c.type) { case NdbDictionary::Column::Unsigned: { - u = urandom(0); - Uint32* p = (Uint32*)d[0].ptr[i]; + Uint32* p = d.ptr[i].u32; + *p = pk1; + } + break; + case NdbDictionary::Column::Char: + { + char* p = d.ptr[i].ch; + sprintf(p, "%-*u", g_charlen, pk1); + } + break; + default: + assert(false); + break; + } + d.ind[i] = 0; + } else if (t == Op::DEL) { + ; + } else if (i == getcol("seq").no) { + d.seq = g_seq++; + d.ind[i] = 0; + } else if (t == Op::INS && c.nullable && urandom(10, 100)) { + d.noop |= (1 << i); + d.ind[i] = 1; // implicit NULL value is known + } else if (t == Op::UPD && urandom(10, 100)) { + d.noop |= (1 << i); + d.ind[i] = -1; // fixed up in caller + } else if (c.nullable && urandom(10, 100)) { + d.ind[i] = 1; + } else { + switch (c.type) { + case NdbDictionary::Column::Unsigned: + { + Uint32* p = d.ptr[i].u32; + uint u = urandom(); *p = u; } break; case NdbDictionary::Column::Char: { - u = urandom(g_charlen); - char* p = (char*)d[0].ptr[i]; + char* p = d.ptr[i].ch; + uint u = urandom(g_charlen); uint j; for (j = 0; j < g_charlen; j++) { - uint v = urandom(3); - p[j] = j < u ? "abcde"[v] : 0x20; + uint v = urandom(strlen(g_charval)); + p[j] = j < u ? g_charval[v] : 0x20; + } + } + break; + case NdbDictionary::Column::Text: + { + Data::Txt& t = *d.ptr[i].txt; + uint u = urandom(g_maxblobsize); + u = urandom(u); // 4x bias for smaller blobs + u = urandom(u); + delete [] t.val; + t.val = new char [u]; + t.len = u; + uint j = 0; + while (j < u) { + assert(u > 0); + uint k = 1 + urandom(u - 1); + if (k > u - j) + k = u - j; + uint v = urandom(strlen(g_charval)); + memset(&t.val[j], g_charval[v], k); + j += k; } } break; @@ -785,74 +1086,78 @@ makeop(Op* op, Uint32 pk1, Op::Type t, const Op* prev_op) assert(false); break; } - d[0].ind[i] = 0; + d.ind[i] = 0; } - Uint32 pk1_tmp = ~(Uint32)0; - chkrc(checkop(op, pk1_tmp) == 0); - reqrc(pk1 == pk1_tmp); - return 0; } static void -makeop(Op* tot_op, Op* com_op, Uint32 pk1, Op::Type t) +makeop(const Op* prev_op, Op* op, Uint32 pk1, Op::Type t) { - Op tmp_op; - tmp_op.kind = Op::OP; - Op* op = getop(); - reqrc(makeop(op, pk1, t, tot_op) == 0); - // add to end - Op* last_op = com_op; - while (last_op->next_op != 0) - last_op = last_op->next_op; - last_op->next_op = op; - // merge into chain head - tmp_op.init(); - reqrc(compop(com_op, op, &tmp_op) == 0); - copyop(&tmp_op, com_op); - // merge into total op - tmp_op.init(); - reqrc(compop(tot_op, op, &tmp_op) == 0); - copyop(&tmp_op, tot_op); - // counts - com_op->num_op += 1; - tot_op->num_op += 1; + op->type = t; + const Data& dp = prev_op->data[0]; + Data& d0 = op->data[0]; + Data& d1 = op->data[1]; + uint i; + for (i = 0; i < ncol(); i++) { + const Col& c = getcol(i); + makedata(c, d0, pk1, t); + if (t == Op::INS) { + d1.ind[i] = -1; + } else if (t == Op::DEL) { + assert(dp.ind[i] >= 0); + if (c.pk) + d1.ind[i] = -1; + else + copycol(c, dp, d1); + } else if (t == Op::UPD) { + assert(dp.ind[i] >= 0); + if (d0.ind[i] == -1) // not updating this col + copycol(c, dp, d0); // must keep track of data + copycol(c, dp, d1); + } else { + assert(false); + } + } + Uint32 pk1_tmp = ~(Uint32)0; + reqrc(checkop(op, pk1_tmp) == 0); + reqrc(pk1 == pk1_tmp); } static void makeops() { ll1("makeops"); - uint resv = g_opts.opstr == 0 ? 2 * g_opts.maxpk : 0; // for final deletes - uint next = g_opts.opstr == 0 ? g_maxcom : strlen(g_opts.opstr); - Op tmp_op; - tmp_op.kind = Op::OP; Uint32 pk1 = 0; - while (getfreeops() >= resv + 2 + next && pk1 < g_opts.maxpk) { - if (g_opts.opstr == 0) + while (g_usedops < g_opts.maxops && pk1 < g_opts.maxpk) { + if (g_opts.opstring == 0) pk1 = urandom(g_opts.maxpk); - ll2("makeops: pk1=" << pk1 << " free=" << getfreeops()); + ll2("makeops: pk1=" << pk1); // total op on the pk so far // optype either NUL=initial/deleted or INS=created Op* tot_op = g_pk_op[pk1]; if (tot_op == 0) - tot_op = g_pk_op[pk1] = getop(); //1 + tot_op = g_pk_op[pk1] = getop(Op::OP); assert(tot_op->type == Op::NUL || tot_op->type == Op::INS); // add new commit chain to end - Op* last_com = tot_op; - while (last_com->next_com != 0) - last_com = last_com->next_com; - Op* com_op = getop(); //2 - last_com->next_com = com_op; + Op* last_gci = tot_op; + while (last_gci->next_gci != 0) + last_gci = last_gci->next_gci; + Op* gci_op = getop(Op::OP); + last_gci->next_gci = gci_op; + Op* com_op = getop(Op::OP); + gci_op->next_com = com_op; // length of random chain uint len = ~0; - if (g_opts.opstr == 0) + if (g_opts.opstring == 0) { len = 1 + urandom(g_maxcom - 1); + len = 1 + urandom(len - 1); // 2x bias for short chain + } ll2("makeops: com chain"); uint n = 0; while (1) { - // random or from g_opts.opstr + // random or from current g_opts.opstring part Op::Type t; - if (g_opts.opstr == 0) { + if (g_opts.opstring == 0) { if (n == len) break; do { @@ -860,10 +1165,11 @@ makeops() } while (tot_op->type == Op::NUL && (t == Op::DEL || t == Op::UPD) || tot_op->type == Op::INS && t == Op::INS); } else { - uint m = strlen(g_opts.opstr); + const char* str = g_opstringpart[g_loop % g_opstringparts]; + uint m = strlen(str); uint k = tot_op->num_com + tot_op->num_op; assert(k < m); - char c = g_opts.opstr[k]; + char c = str[k]; if (c == 'c') { if (k + 1 == m) pk1 += 1; @@ -874,30 +1180,27 @@ makeops() assert(q != 0); t = (Op::Type)(q - p); } - makeop(tot_op, com_op, pk1, t); + Op* op = getop(Op::OP); + makeop(tot_op, op, pk1, t); + // add to end + Op* last_op = com_op; + while (last_op->next_op != 0) + last_op = last_op->next_op; + last_op->next_op = op; + // merge into chain head and total op + reqrc(compop(com_op, op, com_op) == 0); + reqrc(compop(tot_op, op, tot_op) == 0); assert(tot_op->type == Op::NUL || tot_op->type == Op::INS); + // counts + com_op->num_op += 1; + tot_op->num_op += 1; n++; } + // copy to gci level + copyop(com_op, gci_op); tot_op->num_com += 1; } - assert(getfreeops() >= resv); - // terminate with DEL if necessary - for (pk1 = 0; pk1 < g_opts.maxpk; pk1++) { - Op* tot_op = g_pk_op[pk1]; - if (tot_op == 0) - continue; - if (tot_op->type == Op::NUL) - continue; - assert(g_opts.opstr == 0); - Op* last_com = tot_op; - while (last_com->next_com != 0) - last_com = last_com->next_com; - Op* com_op = getop(); //1 - last_com->next_com = com_op; - makeop(tot_op, com_op, pk1, Op::DEL); - assert(tot_op->type == Op::NUL); - tot_op->num_com += 1; - } + ll1("makeops: used ops = " << g_usedops); } static int @@ -919,23 +1222,36 @@ addndbop(Op* op) break; } uint i; - for (i = 0; i < g_ncol; i++) { + for (i = 0; i < ncol(); i++) { const Col& c = getcol(i); const Data& d = op->data[0]; if (! c.pk) continue; - chkdb(g_op->equal(c.name, (char*)d.ptr[i]) == 0); + chkdb(g_op->equal(c.name, (const char*)d.ptr[i].v) == 0); } if (op->type != Op::DEL) { - for (i = 0; i < g_ncol; i++) { + for (i = 0; i < ncol(); i++) { const Col& c = getcol(i); const Data& d = op->data[0]; if (c.pk) continue; - if (d.ind[i] == -1) + if (d.noop & (1 << i)) continue; - const char* ptr = d.ind[i] == 0 ? (char*)d.ptr[i] : 0; - chkdb(g_op->setValue(c.name, ptr) == 0); + assert(d.ind[i] >= 0); + if (! c.isblob()) { + if (d.ind[i] == 0) + chkdb(g_op->setValue(c.name, (const char*)d.ptr[i].v) == 0); + else + chkdb(g_op->setValue(c.name, (const char*)0) == 0); + } else { + const Data::Txt& t = *d.ptr[i].txt; + g_bh = g_op->getBlobHandle(c.name); + if (d.ind[i] == 0) + chkdb(g_bh->setValue(t.val, t.len) == 0); + else + chkdb(g_bh->setValue(0, 0) == 0); + g_bh = 0; + } } } g_op = 0; @@ -947,40 +1263,43 @@ runops() { ll1("runops"); Uint32 pk1; - const Op* com_op[g_maxpk]; - uint left = 0; + Op* gci_op[g_maxpk]; + uint left = 0; // number of pks with ops for (pk1 = 0; pk1 < g_opts.maxpk; pk1++) { - com_op[pk1] = 0; + gci_op[pk1] = 0; // total op on the pk Op* tot_op = g_pk_op[pk1]; if (tot_op == 0) continue; // first commit chain - assert(tot_op->next_com != 0); - com_op[pk1] = tot_op->next_com; + assert(tot_op->next_gci != 0); + gci_op[pk1] = tot_op->next_gci; left++; } while (left != 0) { pk1 = urandom(g_opts.maxpk); - if (com_op[pk1] == 0) + if (gci_op[pk1] == 0) continue; // do the ops in one transaction - ll2("runops: pk1=" << pk1); chkdb((g_con = g_ndb->startTransaction()) != 0); + Op* com_op = gci_op[pk1]->next_com; + assert(com_op != 0); // first op in chain - Op* op = com_op[pk1]->next_op; + Op* op = com_op->next_op; assert(op != 0); while (op != 0) { - ll2("add op:" << *op); + ll2("runops:" << *op); chkrc(addndbop(op) == 0); op = op->next_op; } chkdb(g_con->execute(Commit) == 0); + gci_op[pk1]->gci = com_op->gci = g_con->getGCI(); + ll2("commit: gci=" << com_op->gci); g_ndb->closeTransaction(g_con); g_con = 0; // next chain - com_op[pk1] = com_op[pk1]->next_com; - if (com_op[pk1] == 0) { + gci_op[pk1] = gci_op[pk1]->next_gci; + if (gci_op[pk1] == 0) { assert(left != 0); left--; } @@ -989,13 +1308,106 @@ runops() return 0; } +// move com chains with same gci under same gci entry +static int +mergeops() +{ + ll1("mergeops"); + uint mergecnt = 0; + Uint32 pk1; + for (pk1 = 0; pk1 < g_opts.maxpk; pk1++) { + Op* tot_op = g_pk_op[pk1]; + if (tot_op == 0) + continue; + Op* gci_op = tot_op->next_gci; + assert(gci_op != 0); + while (gci_op != 0) { + Op* com_op = gci_op->next_com; + assert(com_op != 0 && com_op->next_com == 0); + assert(gci_op->gci == com_op->gci); + Op* last_com = com_op; + Op* gci_op2 = gci_op->next_gci; + while (gci_op2 != 0 && gci_op->gci == gci_op2->gci) { + // move link to com level + last_com = last_com->next_com = gci_op2->next_com; + // merge to gci + reqrc(compop(gci_op, gci_op2, gci_op) == 0); + // move to next and discard + Op* tmp_op = gci_op2; + gci_op2 = gci_op2->next_gci; + freeop(tmp_op); + mergecnt++; + } + gci_op = gci_op->next_gci = gci_op2; + } + } + ll1("mergeops: used ops = " << g_usedops); + ll1("mergeops: merged " << mergecnt << " gci entries"); + return 0; +} + +// set bit for equal post/pre data in UPD, for use in event match +static void +cmppostpre() +{ + ll1("cmppostpre"); + Uint32 pk1; + for (pk1 = 0; pk1 < g_opts.maxpk; pk1++) { + Op* tot_op = g_pk_op[pk1]; + Op* gci_op = tot_op ? tot_op->next_gci : 0; + while (gci_op != 0) { + if (gci_op->type == Op::UPD) { + Data (&d)[2] = gci_op->data; + uint i; + for (i = 0; i < ncol(); i++) { + const Col& c = getcol(i); + bool eq = + d[0].ind[i] == 1 && d[1].ind[i] == 1 || + d[0].ind[i] == 0 && d[1].ind[i] == 0 && cmpcol(c, d[0], d[1]) == 0; + if (eq) { + d[0].ppeq |= (1 << i); + d[1].ppeq |= (1 << i); + } + } + } + gci_op = gci_op->next_gci; + } + } +} +static int +cmpopevdata(const Data& d1, const Data& d2) +{ + uint i; + for (i = 0; i < ncol(); i++) { + const Col& c = getcol(i); + if (cmpcol(c, d1, d2) != 0) { + if ((d1.ppeq & (1 << i)) && d2.ind[i] == -1) + ; // post/pre data equal and no event data returned is OK + else + return 1; + } + } + return 0; +} + +// compare operation to event data +static int +cmpopevdata(const Data (&d1)[2], const Data (&d2)[2]) +{ + if (cmpopevdata(d1[0], d2[0]) != 0) + return 1; + if (cmpopevdata(d1[1], d2[1]) != 0) + return 1; + return 0; +} + static int matchevent(Op* ev) { Op::Type t = ev->type; - Data (&d)[2] = ev->data; + Data (&d2)[2] = ev->data; // get PK - Uint32 pk1 = d[0].pk1; + Uint32 pk1 = d2[0].pk1; chkrc(pk1 < g_opts.maxpk); // on error repeat and print details uint loop = 0; @@ -1004,42 +1416,59 @@ matchevent(Op* ev) ll1("matchevent: pk1=" << pk1 << " type=" << t); ll2("EVT: " << *ev); Op* tot_op = g_pk_op[pk1]; - Op* com_op = tot_op ? tot_op->next_com : 0; - uint cnt = 0; + Op* gci_op = tot_op ? tot_op->next_gci : 0; + uint pos = 0; bool ok = false; - while (com_op != 0) { - ll2("COM: " << *com_op); - Op* op = com_op->next_op; - assert(op != 0); - while (op != 0) { - ll2("---: " << *op); - op = op->next_op; + while (gci_op != 0) { + ll2("GCI: " << *gci_op); + // print details + Op* com_op = gci_op->next_com; + assert(com_op != 0); + while (com_op != 0) { + ll2("COM: " << *com_op); + Op* op = com_op->next_op; + assert(op != 0); + while (op != 0) { + ll2("OP : " << *op); + op = op->next_op; + } + com_op = com_op->next_com; } - if (com_op->type != Op::NUL) { - if (com_op->type == t) { - const Data (&d2)[2] = com_op->data; - if (t == Op::INS && d2[0].seq == d[0].seq || - t == Op::DEL && d2[1].seq == d[1].seq || - t == Op::UPD && d2[0].seq == d[0].seq) { - if (cnt == g_ev_cnt[pk1]) { - if (! com_op->match) { - ll2("match pos " << cnt); - ok = com_op->match = true; - } else { - ll2("duplicate match"); - } - } else { - ll2("match bad pos event=" << g_ev_cnt[pk1] << " op=" << cnt); - } + // match agains GCI op + if (gci_op->type != Op::NUL) { + const Data (&d1)[2] = gci_op->data; + if (cmpopevdata(d1, d2) == 0) { + bool tmpok = true; + if (gci_op->type != t) { + ll2("***: wrong type " << gci_op->type << " != " << t); + tmpok = false; + } + if (gci_op->match) { + ll2("***: duplicate match"); + tmpok = false; + } + if (pos != g_ev_pos[pk1]) { + ll2("***: wrong pos " << pos << " != " << g_ev_pos[pk1]); + tmpok = false; + } + if (gci_op->gci != ev->gci) { + ll2("***: wrong gci " << gci_op->gci << " != " << ev->gci); + tmpok = false; + } + if (tmpok) { + ok = gci_op->match = true; + ll2("===: match"); } } - cnt++; + pos++; } - com_op = com_op->next_com; + gci_op = gci_op->next_gci; } - if (ok) + if (ok) { + ll1("matchevent: match"); return 0; - ll2("no match"); + } + ll1("matchevent: ERROR: no match"); if (g_loglevel >= 2) return -1; loop++; @@ -1056,12 +1485,12 @@ matchevents() Op* tot_ev = g_pk_ev[pk1]; if (tot_ev == 0) continue; - Op* com_ev = tot_ev->next_com; - while (com_ev != 0) { - if (matchevent(com_ev) < 0) + Op* ev = tot_ev->next_ev; + while (ev != 0) { + if (matchevent(ev) < 0) nomatch++; - g_ev_cnt[pk1]++; - com_ev = com_ev->next_com; + g_ev_pos[pk1]++; + ev = ev->next_ev; } } chkrc(nomatch == 0); @@ -1095,22 +1524,58 @@ matchops() return 0; } +static void +geteventdata() +{ + Data (&d)[2] = g_rec_ev->data; + int i, j; + for (j = 0; j < 2; j++) { + for (i = 0; i < ncol(); i++) { + const Col& c = getcol(i); + int ind, ret; + if (! c.isblob()) { + NdbRecAttr* ra = g_ev_ra[j][i]; + ind = ra->isNULL(); + } else { +#ifdef version51rbr + NdbBlob* bh = g_ev_bh[j][i]; + ret = bh->getDefined(ind); + assert(ret == 0); + if (ind == 0) { // value was returned and is not NULL + Data::Txt& t = *d[j].ptr[i].txt; + Uint64 len64; + ret = bh->getLength(len64); + assert(ret == 0); + t.len = (uint)len64; + delete [] t.val; + t.val = new char [t.len]; + memset(t.val, 'X', t.len); + Uint32 len = t.len; + ret = bh->readData(t.val, len); + assert(ret == 0 && len == t.len); + } +#endif + } + d[j].ind[i] = ind; + } + } +} + static int runevents() { ll1("runevents"); - NdbEventOperation* evt_op; - uint npoll = 3; + uint mspoll = 1000; + uint npoll = 6; // strangely long delay while (npoll != 0) { npoll--; int ret; ll1("poll"); - ret = g_ndb->pollEvents(1000); + ret = g_ndb->pollEvents(mspoll); if (ret <= 0) continue; while (1) { - g_rec_ev->init(); - Data (&d)[2] = g_rec_ev->data; + g_rec_ev->init(Op::EV); #ifdef version50 int overrun = g_opts.maxops; chkdb((ret = g_evt_op->next(&overrun)) >= 0); @@ -1124,32 +1589,35 @@ runevents() reqrc(g_evt_op == tmp_op); #endif chkrc(seteventtype(g_rec_ev, g_evt_op->getEventType()) == 0); - // get indicators - { int i, j; - for (j = 0; j < 2; j++) - for (i = 0; i < g_ncol; i++) - d[j].ind[i] = g_ra[j][i]->isNULL(); + geteventdata(); + g_rec_ev->gci = g_evt_op->getGCI(); +#ifdef version50 + // fix to match 5.1 + if (g_rec_ev->type == Op::UPD) { + Uint32 pk1 = g_rec_ev->data[0].pk1; + makedata(getcol("pk1"), g_rec_ev->data[1], pk1, Op::UPD); + makedata(getcol("pk2"), g_rec_ev->data[1], pk1, Op::UPD); } +#endif + // get indicators and blob value ll2("runevents: EVT: " << *g_rec_ev); // check basic sanity Uint32 pk1 = ~(Uint32)0; chkrc(checkop(g_rec_ev, pk1) == 0); // add to events - chkrc(getfreeevs() >= 2); Op* tot_ev = g_pk_ev[pk1]; if (tot_ev == 0) - tot_ev = g_pk_ev[pk1] = getev(); //1 - Op* last_com = tot_ev; - while (last_com->next_com != 0) - last_com = last_com->next_com; + tot_ev = g_pk_ev[pk1] = getop(Op::EV); + Op* last_ev = tot_ev; + while (last_ev->next_ev != 0) + last_ev = last_ev->next_ev; // copy and add - Op* ev = getev(); //3 + Op* ev = getop(Op::EV); copyop(g_rec_ev, ev); - last_com->next_com = ev; + last_ev->next_ev = ev; } } - chkrc(matchevents() == 0); - chkrc(matchops() == 0); + ll1("runevents: used ops = " << g_usedops); return 0; } @@ -1179,18 +1647,23 @@ runtest() setseed(-1); chkrc(createtable() == 0); chkrc(createevent() == 0); - uint n; - for (n = 0; n < g_opts.loop; n++) { - ll0("loop " << n); - setseed(n); + for (g_loop = 0; g_opts.loop == 0 || g_loop < g_opts.loop; g_loop++) { + ll0("loop " << g_loop); + setseed(g_loop); resetmem(); - g_rec_ev = getev(); + chkrc(scantab() == 0); // alternative: save tot_op for loop > 0 + makeops(); + g_rec_ev = getop(Op::EV); chkrc(createeventop() == 0); chkdb(g_evt_op->execute() == 0); chkrc(waitgci() == 0); - makeops(); chkrc(runops() == 0); + if (! g_opts.separate_events) + chkrc(mergeops() == 0); + cmppostpre(); chkrc(runevents() == 0); + chkrc(matchevents() == 0); + chkrc(matchops() == 0); chkrc(dropeventop() == 0); } chkrc(dropevent() == 0); @@ -1204,31 +1677,41 @@ static struct my_option my_long_options[] = { NDB_STD_OPTS("test_event_merge"), - { "abort-on-error", 1008, "Do abort() on any error", + { "abort-on-error", 1001, "Do abort() on any error", (gptr*)&g_opts.abort_on_error, (gptr*)&g_opts.abort_on_error, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 }, - { "loglevel", 1001, "Logging level in this program (default 0)", + { "loglevel", 1002, "Logging level in this program (default 0)", (gptr*)&g_opts.loglevel, (gptr*)&g_opts.loglevel, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, - { "loop", 1002, "Number of test loops (default 1, 0=forever)", + { "loop", 1003, "Number of test loops (default 2, 0=forever)", (gptr*)&g_opts.loop, (gptr*)&g_opts.loop, 0, - GET_INT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0 }, - { "maxops", 1003, "Number of PK operations (default 2000)", + GET_INT, REQUIRED_ARG, 2, 0, 0, 0, 0, 0 }, + { "maxops", 1004, "Approx number of PK operations (default 1000)", (gptr*)&g_opts.maxops, (gptr*)&g_opts.maxops, 0, - GET_UINT, REQUIRED_ARG, 2000, 0, g_maxops, 0, 0, 0 }, - { "maxpk", 1004, "Number of different PK values (default 10)", + GET_UINT, REQUIRED_ARG, 1000, 0, 0, 0, 0, 0 }, + { "maxpk", 1005, "Number of different PK values (default 10)", (gptr*)&g_opts.maxpk, (gptr*)&g_opts.maxpk, 0, GET_UINT, REQUIRED_ARG, 10, 1, g_maxpk, 0, 0, 0 }, - { "opstr", 1005, "Ops to run e.g. idiucdc (c = commit, default random)", - (gptr*)&g_opts.opstr, (gptr*)&g_opts.opstr, 0, + { "no-blobs", 1006, "Omit blob attributes (5.0: true)", + (gptr*)&g_opts.no_blobs, (gptr*)&g_opts.no_blobs, 0, + GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 }, + { "no-multiops", 1007, "Allow only 1 operation per commit", + (gptr*)&g_opts.no_multiops, (gptr*)&g_opts.no_multiops, 0, + GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 }, + { "one-blob", 1008, "Only one blob attribute (defautt 2)", + (gptr*)&g_opts.one_blob, (gptr*)&g_opts.one_blob, 0, + GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 }, + { "opstring", 1009, "Operations to run e.g. idiucdc (c is commit) or" + " iuuc:uudc (the : separates loops)", + (gptr*)&g_opts.opstring, (gptr*)&g_opts.opstring, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, - { "seed", 1006, "Random seed (0=loop number, default -1=random)", + { "seed", 1010, "Random seed (0=loop number, default -1=random)", (gptr*)&g_opts.seed, (gptr*)&g_opts.seed, 0, GET_INT, REQUIRED_ARG, -1, 0, 0, 0, 0, 0 }, - { "separate-events", 1007, "Do not combine events per GCI >5.0", + { "separate-events", 1011, "Do not combine events per GCI (5.0: true)", (gptr*)&g_opts.separate_events, (gptr*)&g_opts.separate_events, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 }, - { "use-table", 1008, "Use existing table 'tem1'", + { "use-table", 1012, "Use existing table 'tem1'", (gptr*)&g_opts.use_table, (gptr*)&g_opts.use_table, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, @@ -1245,14 +1728,36 @@ usage() static int checkopts() { - if (g_opts.opstr != 0) { - const char* s = g_opts.opstr; - uint n = strlen(s); - if (n < 3 || s[0] != 'i' || s[n-2] != 'd' || s[n-1] != 'c') - return -1; - while (*s != 0) - if (strchr("iduc", *s++) == 0) +#ifdef version50 + g_opts.separate_events = true; +#endif + if (g_opts.separate_events) { + g_opts.no_blobs = true; + } + if (g_opts.no_multiops) { + g_maxcom = 1; + } + if (g_opts.opstring != 0) { + uint len = strlen(g_opts.opstring); + char* str = new char [len + 1]; + memcpy(str, g_opts.opstring, len + 1); + char* s = str; + while (1) { + g_opstringpart[g_opstringparts++] = s; + s = strchr(s, ':'); + if (s == 0) + break; + *s++ = 0; + } + uint i; + for (i = 0; i < g_opstringparts; i++) { + const char* s = g_opstringpart[i]; + while (*s != 0) + if (strchr("iduc", *s++) == 0) + return -1; + if (s == g_opstringpart[i] || s[-1] != 'c') return -1; + } } return 0; } @@ -1280,6 +1785,10 @@ main(int argc, char** argv) return NDBT_ProgramExit(NDBT_OK); } } + if (g_evt_op != 0) { + (void)dropeventop(); + g_evt_op = 0; + } delete g_ndb; delete g_ncc; return NDBT_ProgramExit(NDBT_FAILED); From fca6cf46d3423cc01e2463a7c8ffcf56600b5476 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 9 Jan 2006 10:01:07 +0100 Subject: [PATCH 40/68] Add yassl libs to libmysqlclient_r as well. Add a symlink to extra/yassl/include/openssl to inlude/ when compiling with yassl Similiar to readline) config/ac-macros/yassl.m4: Symlink extra/yassl/include/openssl dir to include/ include/Makefile.am: Call yassl_h_ln_cmd when linking sources, this will create symlink to openssl in include when compiling with yassl libmysql_r/Makefile.am: Inlude yassl libs into libmysqlclient_r(just as we do in libmysqlclient) --- config/ac-macros/yassl.m4 | 4 +++- include/Makefile.am | 3 ++- libmysql_r/Makefile.am | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/config/ac-macros/yassl.m4 b/config/ac-macros/yassl.m4 index 77208faee0c..b4160ad2a99 100644 --- a/config/ac-macros/yassl.m4 +++ b/config/ac-macros/yassl.m4 @@ -30,7 +30,9 @@ AC_DEFUN([MYSQL_CHECK_YASSL], [ ;; esac AC_SUBST([yassl_taocrypt_extra_cxxflags]) - + # Link extra/yassl/include/openssl subdir to include/ + yassl_h_ln_cmd="\$(LN) -s \$(top_srcdir)/extra/yassl/include/openssl openssl" + AC_SUBST(yassl_h_ln_cmd) else yassl_dir="" AC_MSG_RESULT(no) diff --git a/include/Makefile.am b/include/Makefile.am index 8ad63f088ac..12b8c301b8d 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -33,7 +33,7 @@ noinst_HEADERS = config-win.h config-os2.h config-netware.h \ mysql_version.h.in my_handler.h my_time.h decimal.h # mysql_version.h are generated -CLEANFILES = mysql_version.h my_config.h readline +CLEANFILES = mysql_version.h my_config.h readline openssl # Some include files that may be moved and patched by configure DISTCLEANFILES = sched.h $(CLEANFILES) @@ -41,6 +41,7 @@ DISTCLEANFILES = sched.h $(CLEANFILES) link_sources: -$(RM) -fr readline @readline_h_ln_cmd@ + @yassl_h_ln_cmd@ my_config.h: ../config.h $(CP) ../config.h my_config.h diff --git a/libmysql_r/Makefile.am b/libmysql_r/Makefile.am index ee6dd4cfded..11e65a28a19 100644 --- a/libmysql_r/Makefile.am +++ b/libmysql_r/Makefile.am @@ -22,7 +22,7 @@ target = libmysqlclient_r.la target_defs = -DDONT_USE_RAID -DMYSQL_CLIENT @LIB_EXTRA_CCFLAGS@ -LIBS = @LIBS@ @ZLIB_LIBS@ @openssl_libs@ @yassl_libs@ +LIBS = @LIBS@ @ZLIB_LIBS@ @openssl_libs@ INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include \ $(openssl_includes) $(yassl_includes) @ZLIB_INCLUDES@ @@ -32,7 +32,7 @@ include $(top_srcdir)/libmysql/Makefile.shared libmysql_dir = $(top_srcdir)/libmysql libmysqlclient_r_la_SOURCES = $(target_sources) -libmysqlclient_r_la_LIBADD = $(target_libadd) +libmysqlclient_r_la_LIBADD = $(target_libadd) $(yassl_libs_with_path) libmysqlclient_r_la_LDFLAGS = $(target_ldflags) # This is called from the toplevel makefile From e12bc697db8509602cd7c765fbd95d8543ad6308 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 9 Jan 2006 11:10:49 +0200 Subject: [PATCH 41/68] After merge fix (Lines lost in manual merge) --- sql/sql_handler.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index a69bf04cc48..765a057f740 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -454,6 +454,9 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, if (insert_fields(thd,tables,tables->db,tables->alias,&it)) goto err0; + select_limit+=offset_limit; + protocol->send_fields(&list,1); + /* In ::external_lock InnoDB resets the fields which tell it that the handle is used in the HANDLER interface. Tell it again that From 16257e8b356c105fcc9fa8c8851338da60ece8f2 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 9 Jan 2006 10:31:07 +0100 Subject: [PATCH 42/68] Bug #15598 Server crashes in specific case during setting new password - When acl_user->host.hostname is NULL compare it as "" mysql-test/r/grant.result: Test user with host '' mysql-test/t/grant.test: Test user with host '' sql/sql_acl.cc: If acl_user->host.hostname is NULL compare it as "" --- mysql-test/r/grant.result | 9 +++++++++ mysql-test/t/grant.test | 12 ++++++++++++ sql/sql_acl.cc | 5 +++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/grant.result b/mysql-test/r/grant.result index 0a406c1ffc2..13593ec2a88 100644 --- a/mysql-test/r/grant.result +++ b/mysql-test/r/grant.result @@ -464,3 +464,12 @@ show grants for root@localhost; Grants for root@localhost GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION set names latin1; +insert into mysql.user (host, user) values ('', 'mysqltest_7'); +flush privileges; +set password for mysqltest_7@ = password('systpass'); +show grants for mysqltest_7@; +Grants for mysqltest_7@ +GRANT USAGE ON *.* TO 'mysqltest_7'@'' IDENTIFIED BY PASSWORD '*2FB071A056F9BB745219D9C876814231DAF46517' +drop user mysqltest_7@; +show grants for mysqltest_7@; +ERROR 42000: There is no such grant defined for user 'mysqltest_7' on host '' diff --git a/mysql-test/t/grant.test b/mysql-test/t/grant.test index 039e41dcf34..805fa881399 100644 --- a/mysql-test/t/grant.test +++ b/mysql-test/t/grant.test @@ -421,4 +421,16 @@ revoke all privileges on show grants for root@localhost; set names latin1; +# +# Bug #15598 Server crashes in specific case during setting new password +# - Caused by a user with host '' +# +insert into mysql.user (host, user) values ('', 'mysqltest_7'); +flush privileges; +set password for mysqltest_7@ = password('systpass'); +show grants for mysqltest_7@; +drop user mysqltest_7@; +--error 1141 +show grants for mysqltest_7@; + # End of 4.1 tests diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 1ade6ce3064..119952eeda9 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -1371,7 +1371,8 @@ find_acl_user(const char *host, const char *user, my_bool exact) acl_user->user && !strcmp(user,acl_user->user)) { if (exact ? !my_strcasecmp(&my_charset_latin1, host, - acl_user->host.hostname) : + acl_user->host.hostname ? + acl_user->host.hostname : "") : compare_hostname(&acl_user->host,host,host)) { DBUG_RETURN(acl_user); @@ -3604,7 +3605,7 @@ ACL_USER *check_acl_user(LEX_USER *user_name, if (!(user=acl_user->user)) user= ""; if (!(host=acl_user->host.hostname)) - host= "%"; + host= ""; if (!strcmp(user_name->user.str,user) && !my_strcasecmp(system_charset_info, user_name->host.str, host)) break; From 9cfcc3252140fcaaa8c84124bee839a5702759e5 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 9 Jan 2006 17:12:26 +0100 Subject: [PATCH 43/68] Bug #15598 Server crashes in specific case during setting new password - Comparing host string against NULL caused crash. - If host.hostname is NULL treat it as "" mysql-test/r/grant.result: Update test results mysql-test/t/grant.test: Add test for user with host "" --- mysql-test/r/grant.result | 18 +++++++++--------- mysql-test/t/grant.test | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/mysql-test/r/grant.result b/mysql-test/r/grant.result index 304294057d7..eea29161de8 100644 --- a/mysql-test/r/grant.result +++ b/mysql-test/r/grant.result @@ -437,15 +437,6 @@ delete from mysql.columns_priv where user="mysqltest_3"; flush privileges; drop database mysqltest_1; drop database mysqltest_2; -insert into mysql.user (host, user) values ('', 'mysqltest_7'); -flush privileges; -set password for mysqltest_7@ = password('systpass'); -show grants for mysqltest_7@; -Grants for mysqltest_7@ -GRANT USAGE ON *.* TO 'mysqltest_7'@'' IDENTIFIED BY PASSWORD '*2FB071A056F9BB745219D9C876814231DAF46517' -drop user mysqltest_7@; -show grants for mysqltest_7@; -ERROR 42000: There is no such grant defined for user 'mysqltest_7' on host '' SHOW PRIVILEGES; Privilege Context Comment Alter Tables To alter the table @@ -624,3 +615,12 @@ show grants for root@localhost; Grants for root@localhost GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION set names latin1; +create user mysqltest_7@; +set password for mysqltest_7@ = password('systpass'); +show grants for mysqltest_7@; +Grants for mysqltest_7@ +GRANT USAGE ON *.* TO 'mysqltest_7'@'' IDENTIFIED BY PASSWORD '*2FB071A056F9BB745219D9C876814231DAF46517' +drop user mysqltest_7@; +flush privileges; +show grants for mysqltest_7@; +ERROR 42000: There is no such grant defined for user 'mysqltest_7' on host '' diff --git a/mysql-test/t/grant.test b/mysql-test/t/grant.test index d8deb379cd4..9a8b7a19c59 100644 --- a/mysql-test/t/grant.test +++ b/mysql-test/t/grant.test @@ -503,11 +503,11 @@ set names latin1; # Bug #15598 Server crashes in specific case during setting new password # - Caused by a user with host '' # -insert into mysql.user (host, user) values ('', 'mysqltest_7'); -flush privileges; +create user mysqltest_7@; set password for mysqltest_7@ = password('systpass'); show grants for mysqltest_7@; drop user mysqltest_7@; +flush privileges; # BUG#16297(flush should be removed when that bug is fixed) --error 1141 show grants for mysqltest_7@; From 8fd14af83afbd3bdf6886c3c9e4ecb8541842674 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 9 Jan 2006 21:44:42 -0800 Subject: [PATCH 44/68] Ajustement after merge --- sql/sql_select.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 4619f7134f0..c282a5bd42c 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -365,7 +365,8 @@ JOIN::prepare(Item ***rref_pointer_array, if (having_fix_rc || thd->net.report_error) DBUG_RETURN(-1); /* purecov: inspected */ if (having->with_sum_func) - having->split_sum_func2(thd, ref_pointer_array, all_fields, &having); + having->split_sum_func2(thd, ref_pointer_array, all_fields, + &having, TRUE); thd->lex->allow_sum_func= save_allow_sum_func; } if (select_lex->inner_sum_func_list) From b49b86aed35d98e3a410abae9012941b7c82d513 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 10 Jan 2006 13:44:08 +0200 Subject: [PATCH 45/68] BUG#9483 test was overworked to account reviews finally to leave only REVOKE check. There is a specific rpl_ignore_grant test case for GRANT. mysql-test/r/rpl_ignore_revoke.result: New BitKeeper file ``mysql-test/r/rpl_ignore_revoke.result'' mysql-test/t/rpl_ignore_revoke-slave.opt: New BitKeeper file ``mysql-test/t/rpl_ignore_revoke-slave.opt'' mysql-test/t/rpl_ignore_revoke.test: New BitKeeper file ``mysql-test/t/rpl_ignore_revoke.test'' --- mysql-test/r/rpl_ignore_revoke.result | 28 +++++++++++++++ mysql-test/t/rpl_ignore_revoke-slave.opt | 1 + mysql-test/t/rpl_ignore_revoke.test | 43 ++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 mysql-test/r/rpl_ignore_revoke.result create mode 100644 mysql-test/t/rpl_ignore_revoke-slave.opt create mode 100644 mysql-test/t/rpl_ignore_revoke.test diff --git a/mysql-test/r/rpl_ignore_revoke.result b/mysql-test/r/rpl_ignore_revoke.result new file mode 100644 index 00000000000..094b571f4f4 --- /dev/null +++ b/mysql-test/r/rpl_ignore_revoke.result @@ -0,0 +1,28 @@ +stop slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +reset master; +reset slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +start slave; +grant select on *.* to 'user_foo'@'%' identified by 'user_foopass'; +revoke select on *.* from 'user_foo'@'%'; +select select_priv from mysql.user where user='user_foo' /* master:must be N */; +select_priv +N +grant select on *.* to 'user_foo'@'%' identified by 'user_foopass'; +revoke select on *.* from 'user_foo'@'%'; +select select_priv from mysql.user where user='user_foo' /* slave:must be N */; +select_priv +N +grant select on *.* to 'user_foo'@'%' identified by 'user_foopass'; +select select_priv from mysql.user where user='user_foo' /* slave:must be Y */; +select_priv +Y +revoke select on *.* from 'user_foo'; +select select_priv from mysql.user where user='user_foo' /* master:must be N */; +select_priv +N +select select_priv from mysql.user where user='user_foo' /* slave:must get Y */; +select_priv +Y +revoke select on *.* FROM 'user_foo'; diff --git a/mysql-test/t/rpl_ignore_revoke-slave.opt b/mysql-test/t/rpl_ignore_revoke-slave.opt new file mode 100644 index 00000000000..e931bfbd37e --- /dev/null +++ b/mysql-test/t/rpl_ignore_revoke-slave.opt @@ -0,0 +1 @@ +--replicate-wild-ignore-table=mysql.% diff --git a/mysql-test/t/rpl_ignore_revoke.test b/mysql-test/t/rpl_ignore_revoke.test new file mode 100644 index 00000000000..e5b5bafb3c5 --- /dev/null +++ b/mysql-test/t/rpl_ignore_revoke.test @@ -0,0 +1,43 @@ +# test verifies that REVOKE must not be replicated when +# slave server starts with --replicate-wild-ignore-table=mysql.% +# the option is set in rpl_ignore_revoke-slave.opt +# The first part of BUG#9483 for GRANT is checked by +# existed specific rpl_ignore_grant test case (BUG#980) + + +source include/master-slave.inc; + +### CLEAN-UP: create an account and manually duplicate it on the slave + +connection master; +grant select on *.* to 'user_foo'@'%' identified by 'user_foopass'; +revoke select on *.* from 'user_foo'@'%'; +select select_priv from mysql.user where user='user_foo' /* master:must be N */; + +sync_slave_with_master; +#connection slave; +grant select on *.* to 'user_foo'@'%' identified by 'user_foopass'; +revoke select on *.* from 'user_foo'@'%'; +select select_priv from mysql.user where user='user_foo' /* slave:must be N */; + + +### TEST + +#connection slave; +grant select on *.* to 'user_foo'@'%' identified by 'user_foopass'; +select select_priv from mysql.user where user='user_foo' /* slave:must be Y */; + +connection master; +revoke select on *.* from 'user_foo'; +select select_priv from mysql.user where user='user_foo' /* master:must be N */; + +sync_slave_with_master; +#connection slave; +select select_priv from mysql.user where user='user_foo' /* slave:must get Y */; + +### CLEAN-UP + +connection slave; +--disable_abort_on_error +revoke select on *.* FROM 'user_foo'; +--enable_abort_on_error From 935ad7e8f376805f435d6e105d337efb54a31379 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 10 Jan 2006 15:56:30 +0100 Subject: [PATCH 46/68] Fix for crashing mysqltest client/mysqltest.c: Allocate one extra byte for string terminator in varname --- client/mysqltest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index dbb910c2e3d..c31e8bc693b 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -4207,7 +4207,7 @@ static VAR *var_init(VAR *v, const char *name, int name_len, const char *val, val_len = strlen(val) ; val_alloc_len = val_len + 16; /* room to grow */ if (!(tmp_var=v) && !(tmp_var = (VAR*)my_malloc(sizeof(*tmp_var) - + name_len, MYF(MY_WME)))) + + name_len+1, MYF(MY_WME)))) die("Out of memory"); tmp_var->name = (name) ? (char*) tmp_var + sizeof(*tmp_var) : 0; From 29818203eb54980c4ceeca4681592617882505df Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 10 Jan 2006 17:57:46 +0300 Subject: [PATCH 47/68] Commenting out testcases which cause type_time.test failure. To be uncommented after fixing bug 15805. mysql-test/r/type_time.result: Fixing testcases results. mysql-test/t/type_time.test: Temporaly commented out testcases which cause type_time.test failure. To be uncommented after fixing bug 15805. --- mysql-test/r/type_time.result | 24 ------------------------ mysql-test/t/type_time.test | 16 ++++++++++------ 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/mysql-test/r/type_time.result b/mysql-test/r/type_time.result index cb76f699cd9..025cf2a57f1 100644 --- a/mysql-test/r/type_time.result +++ b/mysql-test/r/type_time.result @@ -85,27 +85,3 @@ sec_to_time(time_to_sec(t)) 13:00:00 09:00:00 drop table t1; -SELECT CAST(235959.123456 AS TIME); -CAST(235959.123456 AS TIME) -23:59:59.123456 -SELECT CAST(0.235959123456e+6 AS TIME); -CAST(0.235959123456e+6 AS TIME) -23:59:59.123456 -SELECT CAST(235959123456e-6 AS TIME); -CAST(235959123456e-6 AS TIME) -23:59:59.123456 -SELECT CAST(235959.1234567 AS TIME); -CAST(235959.1234567 AS TIME) -23:59:59.123456 -Warnings: -Warning 1292 Truncated incorrect time value: '235959.1234567' -SELECT CAST(0.2359591234567e6 AS TIME); -CAST(0.2359591234567e6 AS TIME) -23:59:59.123456 -Warnings: -Warning 1292 Truncated incorrect time value: '235959.1234567' -SELECT CAST(0.2359591234567e+30 AS TIME); -CAST(0.2359591234567e+30 AS TIME) -NULL -Warnings: -Warning 1292 Truncated incorrect time value: '2.359591234567e+29' diff --git a/mysql-test/t/type_time.test b/mysql-test/t/type_time.test index 9abfe914335..cb7e4f85ad1 100644 --- a/mysql-test/t/type_time.test +++ b/mysql-test/t/type_time.test @@ -26,13 +26,17 @@ drop table t1; # long fraction part and/or large exponent part. # # These must return normal result: -SELECT CAST(235959.123456 AS TIME); -SELECT CAST(0.235959123456e+6 AS TIME); -SELECT CAST(235959123456e-6 AS TIME); +# ########################################################## +# To be uncommented after fix BUG #15805 +# ########################################################## +# SELECT CAST(235959.123456 AS TIME); +# SELECT CAST(0.235959123456e+6 AS TIME); +# SELECT CAST(235959123456e-6 AS TIME); # These must cut fraction part and produce warning: -SELECT CAST(235959.1234567 AS TIME); -SELECT CAST(0.2359591234567e6 AS TIME); +# SELECT CAST(235959.1234567 AS TIME); +# SELECT CAST(0.2359591234567e6 AS TIME); # This must return NULL and produce warning: -SELECT CAST(0.2359591234567e+30 AS TIME); +# SELECT CAST(0.2359591234567e+30 AS TIME); +# ########################################################## # End of 4.1 tests From 55499cad0dc7403832b45ac072359cc2a62aa890 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 10 Jan 2006 18:56:23 +0200 Subject: [PATCH 48/68] Fixed refresh_status function. sql/sql_class.cc: Improved documentation on add_to_status(). sql/sql_parse.cc: Changed refresh status to take thd as argument to avoid current_thd. Removed add_to_status away from loop, as it is not necessary for each variable, only required for each thread. In this case only the current thread. --- sql/sql_class.cc | 7 ++++++- sql/sql_parse.cc | 16 +++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/sql/sql_class.cc b/sql/sql_class.cc index ed2089546da..ca86c077a3a 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -445,7 +445,12 @@ THD::~THD() /* - Add to one status variable another status variable + Add all status variables to another status variable array + + SYNOPSIS + add_to_status() + to_var add to this array + from_var from this array NOTES This function assumes that all variables are long/ulong. diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 9cdb288c045..e322fd466d3 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -6538,7 +6538,7 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables, if (options & REFRESH_HOSTS) hostname_cache_refresh(); if (thd && (options & REFRESH_STATUS)) - refresh_status(); + refresh_status(thd); if (options & REFRESH_THREADS) flush_thread_cache(); #ifdef HAVE_REPLICATION @@ -6624,20 +6624,18 @@ void kill_one_thread(THD *thd, ulong id, bool only_kill_query) /* Clear most status variables */ -static void refresh_status(void) +static void refresh_status(THD *thd) { pthread_mutex_lock(&LOCK_status); + + /* We must update the global status before cleaning up the thread */ + add_to_status(&global_status_var, &thd->status_var); + bzero((char*) &thd->status_var, sizeof(thd->status_var)); + for (struct show_var_st *ptr=status_vars; ptr->name; ptr++) { if (ptr->type == SHOW_LONG) *(ulong*) ptr->value= 0; - else if (ptr->type == SHOW_LONG_STATUS) - { - THD *thd= current_thd; - /* We must update the global status before cleaning up the thread */ - add_to_status(&global_status_var, &thd->status_var); - bzero((char*) &thd->status_var, sizeof(thd->status_var)); - } } /* Reset the counters of all key caches (default and named). */ process_key_caches(reset_key_cache_counters); From af024409afac7b9ded1f5c431e08f3b26699bcf6 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 10 Jan 2006 19:13:12 +0200 Subject: [PATCH 49/68] Re-run fix-fields on condition if table was reopened in HANDLERREAD sql/sql_base.cc: Added more comments sql/sql_handler.cc: Re-run fix-fields on condition if table was reopened --- sql/sql_base.cc | 20 ++++++++++++++++---- sql/sql_handler.cc | 11 ++++++++--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/sql/sql_base.cc b/sql/sql_base.cc index c8443948a4a..ea013bb4e1e 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1012,10 +1012,20 @@ TABLE *find_locked_table(THD *thd, const char *db,const char *table_name) /**************************************************************************** -** Reopen an table because the definition has changed. The date file for the -** table is already closed. -** Returns 0 if ok. -** If table can't be reopened, the entry is unchanged. + Reopen an table because the definition has changed. The date file for the + table is already closed. + + SYNOPSIS + reopen_table() + table Table to be opened + locked 1 if we have already a lock on LOCK_open + + NOTES + table->query_id will be 0 if table was reopened + + RETURN + 0 ok + 1 error ('table' is unchanged if table couldn't be reopened) ****************************************************************************/ bool reopen_table(TABLE *table,bool locked) @@ -1085,8 +1095,10 @@ bool reopen_table(TABLE *table,bool locked) (*field)->table_name=table->table_name; } for (key=0 ; key < table->keys ; key++) + { for (part=0 ; part < table->key_info[key].usable_key_parts ; part++) table->key_info[key].key_part[part].field->table= table; + } VOID(pthread_cond_broadcast(&COND_refresh)); error=0; diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index 765a057f740..1c5381a9fa0 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -437,9 +437,14 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, if (!lock) goto err0; // mysql_lock_tables() printed error message already - if (cond && ((!cond->fixed && - cond->fix_fields(thd, tables, &cond)) || cond->check_cols(1))) - goto err0; + if (cond) + { + if (table->query_id != thd->query_id) + cond->cleanup(); // File was reopened + if ((!cond->fixed && + cond->fix_fields(thd, tables, &cond)) || cond->check_cols(1)) + goto err0; + } if (keyname) { From 26e7bf4aee7a2570db20957eb92b11044162d816 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 10 Jan 2006 19:19:56 +0200 Subject: [PATCH 50/68] Changed function prototype. --- sql/sql_parse.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index e322fd466d3..58594cce293 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -73,7 +73,7 @@ static void decrease_user_connections(USER_CONN *uc); static bool check_db_used(THD *thd,TABLE_LIST *tables); static bool check_multi_update_lock(THD *thd); static void remove_escape(char *name); -static void refresh_status(void); +static void refresh_status(THD *thd); static bool append_file_to_dir(THD *thd, const char **filename_ptr, const char *table_name); From ffc206d9be17b67f1daed509e5939c63519960f0 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 10 Jan 2006 21:03:02 +0300 Subject: [PATCH 51/68] Post-merge changes mysql-test/t/disabled.def: Enabling type_time.test --- mysql-test/t/disabled.def | 1 - 1 file changed, 1 deletion(-) diff --git a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def index a209088f202..46f15983dc3 100644 --- a/mysql-test/t/disabled.def +++ b/mysql-test/t/disabled.def @@ -12,4 +12,3 @@ sp-goto : GOTO is currently is disabled - will be fixed in the future subselect : Bug#15706 -type_time : Bug#15805 From d4d29edb836c697d744bb75496b58b76554fcb68 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Jan 2006 02:07:40 +0300 Subject: [PATCH 52/68] Fix for BUG#15110: mysqldump --triggers: does not include DEFINER clause There are two main idea of this fix: - introduce a common function for server and client to split user value (@) into user name and host name parts; - dump DEFINER clause in correct format in mysqldump. BitKeeper/etc/ignore: added client/my_user.c libmysqld/my_user.c sql/my_user.c client/Makefile.am: Use my_user.c in linking of mysqldump executable. client/mysqldump.c: Fix for BUG#15110(mysqldump --triggers: does not include DEFINER clause) include/Makefile.am: Add my_user.c include/mysql_com.h: Introduce a constant for max user length. libmysqld/Makefile.am: Add my_user.c mysql-test/r/mysqldump.result: Update result file. sql-common/Makefile.am: Add my_user.c sql/Makefile.am: Add my_user.c sql/sp.cc: Use constant for max user length. sql/sp_head.cc: Use common function to parse user value. sql/sql_acl.cc: Use constant for max user length. sql/sql_parse.cc: Use constant for max user length. sql/sql_show.cc: Use constant for max user length. sql/sql_trigger.cc: Use constant for max user length. include/my_user.h: A header file for parse_user(). sql-common/my_user.c: A new file for parse_user() implementation. --- .bzrignore | 3 ++ client/Makefile.am | 7 +++-- client/mysqldump.c | 35 +++++++++++++++++++-- include/Makefile.am | 3 +- include/my_user.h | 35 +++++++++++++++++++++ include/mysql_com.h | 8 +++++ libmysqld/Makefile.am | 2 +- mysql-test/r/mysqldump.result | 12 ++++---- sql-common/Makefile.am | 2 +- sql-common/my_user.c | 57 +++++++++++++++++++++++++++++++++++ sql/Makefile.am | 4 ++- sql/sp.cc | 4 +-- sql/sp_head.cc | 30 ++++++++---------- sql/sql_acl.cc | 4 +-- sql/sql_parse.cc | 4 +-- sql/sql_show.cc | 6 ++-- sql/sql_trigger.cc | 2 +- 17 files changed, 175 insertions(+), 43 deletions(-) create mode 100644 include/my_user.h create mode 100644 sql-common/my_user.c diff --git a/.bzrignore b/.bzrignore index 6e1da35a08f..109f9e536a9 100644 --- a/.bzrignore +++ b/.bzrignore @@ -1269,3 +1269,6 @@ vio/viotest.cpp zlib/*.ds? zlib/*.vcproj libmysqld/ha_blackhole.cc +client/my_user.c +libmysqld/my_user.c +sql/my_user.c diff --git a/client/Makefile.am b/client/Makefile.am index 804f194085f..2c513d3d7c7 100644 --- a/client/Makefile.am +++ b/client/Makefile.am @@ -46,7 +46,7 @@ mysqltestmanager_pwgen_SOURCES = mysqlmanager-pwgen.c mysqltestmanagerc_SOURCES= mysqlmanagerc.c $(yassl_dummy_link_fix) mysqlcheck_SOURCES= mysqlcheck.c $(yassl_dummy_link_fix) mysqlshow_SOURCES= mysqlshow.c $(yassl_dummy_link_fix) -mysqldump_SOURCES= mysqldump.c $(yassl_dummy_link_fix) +mysqldump_SOURCES= mysqldump.c my_user.c $(yassl_dummy_link_fix) mysqlimport_SOURCES= mysqlimport.c $(yassl_dummy_link_fix) sql_src=log_event.h mysql_priv.h log_event.cc my_decimal.h my_decimal.cc strings_src=decimal.c @@ -62,7 +62,10 @@ link_sources: for f in $(strings_src) ; do \ rm -f $(srcdir)/$$f; \ @LN_CP_F@ $(top_srcdir)/strings/$$f $$f; \ - done; + done; \ + rm -f $(srcdir)/my_user.c; \ + @LN_CP_F@ $(top_srcdir)/sql-common/my_user.c my_user.c; + # Don't update the files from bitkeeper %::SCCS/s.% diff --git a/client/mysqldump.c b/client/mysqldump.c index 454fc0df84e..b24d67ec302 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -41,6 +41,7 @@ #include #include +#include #include #include #include @@ -1840,9 +1841,37 @@ static void dump_triggers_for_table (char *table, char *db) DELIMITER ;;\n"); while ((row= mysql_fetch_row(result))) { - fprintf(sql_file, "/*!50003 SET SESSION SQL_MODE=\"%s\" */;;\n\ -/*!50003 CREATE TRIGGER %s %s %s ON %s FOR EACH ROW%s%s */;;\n\n", - row[6], /* sql_mode */ + fprintf(sql_file, + "/*!50003 SET SESSION SQL_MODE=\"%s\" */;;\n" + "/*!50003 CREATE */ ", + row[6] /* sql_mode */); + + if (mysql_num_fields(result) > 7) + { + /* + mysqldump can be run against the server, that does not support definer + in triggers (there is no DEFINER column in SHOW TRIGGERS output). So, + we should check if we have this column before accessing it. + */ + + uint user_name_len; + char user_name_str[USERNAME_LENGTH + 1]; + char quoted_user_name_str[USERNAME_LENGTH * 2 + 3]; + uint host_name_len; + char host_name_str[HOSTNAME_LENGTH + 1]; + char quoted_host_name_str[HOSTNAME_LENGTH * 2 + 3]; + + parse_user(row[7], strlen(row[7]), user_name_str, &user_name_len, + host_name_str, &host_name_len); + + fprintf(sql_file, + "/*!50017 DEFINER=%s@%s */ ", + quote_name(user_name_str, quoted_user_name_str, FALSE), + quote_name(host_name_str, quoted_host_name_str, FALSE)); + } + + fprintf(sql_file, + "/*!50003 TRIGGER %s %s %s ON %s FOR EACH ROW%s%s */;;\n\n", quote_name(row[0], name_buff, 0), /* Trigger */ row[4], /* Timing */ row[1], /* Event */ diff --git a/include/Makefile.am b/include/Makefile.am index 12b8c301b8d..07c32e3127b 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -30,7 +30,8 @@ noinst_HEADERS = config-win.h config-os2.h config-netware.h \ my_nosys.h my_alarm.h queues.h rijndael.h sha1.h \ my_aes.h my_tree.h hash.h thr_alarm.h \ thr_lock.h t_ctype.h violite.h md5.h base64.h \ - mysql_version.h.in my_handler.h my_time.h decimal.h + mysql_version.h.in my_handler.h my_time.h decimal.h \ + my_user.h # mysql_version.h are generated CLEANFILES = mysql_version.h my_config.h readline openssl diff --git a/include/my_user.h b/include/my_user.h new file mode 100644 index 00000000000..2bd4208a34c --- /dev/null +++ b/include/my_user.h @@ -0,0 +1,35 @@ +/* Copyright (C) 2005 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* + This is a header for libraries containing functions used in both server and + only some of clients (but not in libmysql)... +*/ + +#ifndef _my_user_h_ +#define _my_user_h_ + +#include + +C_MODE_START + +void parse_user(const char *user_id_str, uint user_id_len, + char *user_name_str, uint *user_name_len, + char *host_name_str, uint *host_name_len); + +C_MODE_END + +#endif /* _my_user_h_ */ diff --git a/include/mysql_com.h b/include/mysql_com.h index 1e595cdbba3..ec1c133799f 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -27,6 +27,14 @@ #define SERVER_VERSION_LENGTH 60 #define SQLSTATE_LENGTH 5 +/* + USER_HOST_BUFF_SIZE -- length of string buffer, that is enough to contain + username and hostname parts of the user identifier with trailing zero in + MySQL standard format: + user_name_part@host_name_part\0 +*/ +#define USER_HOST_BUFF_SIZE HOSTNAME_LENGTH + USERNAME_LENGTH + 2 + #define LOCAL_HOST "localhost" #define LOCAL_HOST_NAMEDPIPE "." diff --git a/libmysqld/Makefile.am b/libmysqld/Makefile.am index f07bbacba02..5ec9cdfe5bf 100644 --- a/libmysqld/Makefile.am +++ b/libmysqld/Makefile.am @@ -63,7 +63,7 @@ sqlsources = derror.cc field.cc field_conv.cc strfunc.cc filesort.cc \ spatial.cc gstream.cc sql_help.cc tztime.cc sql_cursor.cc \ sp_head.cc sp_pcontext.cc sp.cc sp_cache.cc sp_rcontext.cc \ parse_file.cc sql_view.cc sql_trigger.cc my_decimal.cc \ - ha_blackhole.cc ha_archive.cc + ha_blackhole.cc ha_archive.cc my_user.c libmysqld_int_a_SOURCES= $(libmysqld_sources) $(libmysqlsources) $(sqlsources) $(sqlexamplessources) libmysqld_a_SOURCES= diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index 62d2b46e617..4e2564c69da 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -1986,7 +1986,7 @@ UNLOCK TABLES; /*!50003 SET @OLD_SQL_MODE=@@SQL_MODE*/; DELIMITER ;; /*!50003 SET SESSION SQL_MODE="" */;; -/*!50003 CREATE TRIGGER `trg1` BEFORE INSERT ON `t1` FOR EACH ROW +/*!50003 CREATE */ /*!50017 DEFINER=`root`@`localhost` */ /*!50003 TRIGGER `trg1` BEFORE INSERT ON `t1` FOR EACH ROW begin if new.a > 10 then set new.a := 10; @@ -1995,12 +1995,12 @@ end if; end */;; /*!50003 SET SESSION SQL_MODE="" */;; -/*!50003 CREATE TRIGGER `trg2` BEFORE UPDATE ON `t1` FOR EACH ROW begin +/*!50003 CREATE */ /*!50017 DEFINER=`root`@`localhost` */ /*!50003 TRIGGER `trg2` BEFORE UPDATE ON `t1` FOR EACH ROW begin if old.a % 2 = 0 then set new.b := 12; end if; end */;; /*!50003 SET SESSION SQL_MODE="STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER" */;; -/*!50003 CREATE TRIGGER `trg3` AFTER UPDATE ON `t1` FOR EACH ROW +/*!50003 CREATE */ /*!50017 DEFINER=`root`@`localhost` */ /*!50003 TRIGGER `trg3` AFTER UPDATE ON `t1` FOR EACH ROW begin if new.a = -1 then set @fired:= "Yes"; @@ -2023,7 +2023,7 @@ UNLOCK TABLES; /*!50003 SET @OLD_SQL_MODE=@@SQL_MODE*/; DELIMITER ;; /*!50003 SET SESSION SQL_MODE="STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER" */;; -/*!50003 CREATE TRIGGER `trg4` BEFORE INSERT ON `t2` FOR EACH ROW +/*!50003 CREATE */ /*!50017 DEFINER=`root`@`localhost` */ /*!50003 TRIGGER `trg4` BEFORE INSERT ON `t2` FOR EACH ROW begin if new.a > 10 then set @fired:= "No"; @@ -2376,7 +2376,7 @@ UNLOCK TABLES; /*!50003 SET @OLD_SQL_MODE=@@SQL_MODE*/; DELIMITER ;; /*!50003 SET SESSION SQL_MODE="" */;; -/*!50003 CREATE TRIGGER `test trig` BEFORE INSERT ON `t1 test` FOR EACH ROW BEGIN +/*!50003 CREATE */ /*!50017 DEFINER=`root`@`localhost` */ /*!50003 TRIGGER `test trig` BEFORE INSERT ON `t1 test` FOR EACH ROW BEGIN INSERT INTO `t2 test` SET a2 = NEW.a1; END */;; DELIMITER ; @@ -2532,7 +2532,7 @@ UNLOCK TABLES; /*!50003 SET @OLD_SQL_MODE=@@SQL_MODE*/; DELIMITER ;; /*!50003 SET SESSION SQL_MODE="IGNORE_SPACE" */;; -/*!50003 CREATE TRIGGER `tr1` BEFORE INSERT ON `t1` FOR EACH ROW BEGIN +/*!50003 CREATE */ /*!50017 DEFINER=`root`@`localhost` */ /*!50003 TRIGGER `tr1` BEFORE INSERT ON `t1` FOR EACH ROW BEGIN SET new.a = 0; END */;; diff --git a/sql-common/Makefile.am b/sql-common/Makefile.am index 6bd42d70e4f..d71523a741c 100644 --- a/sql-common/Makefile.am +++ b/sql-common/Makefile.am @@ -15,7 +15,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## Process this file with automake to create Makefile.in -EXTRA_DIST = client.c pack.c my_time.c +EXTRA_DIST = client.c pack.c my_time.c my_user.c # Don't update the files from bitkeeper %::SCCS/s.% diff --git a/sql-common/my_user.c b/sql-common/my_user.c new file mode 100644 index 00000000000..c39f08e520f --- /dev/null +++ b/sql-common/my_user.c @@ -0,0 +1,57 @@ +/* Copyright (C) 2005 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#include +#include + + +/* + Parse user value to user name and host name parts. + + SYNOPSIS + user_id_str [IN] User value string (the source). + user_id_len [IN] Length of the user value. + user_name_str [OUT] Buffer to store user name part. + Must be not less than USERNAME_LENGTH + 1. + user_name_len [OUT] A place to store length of the user name part. + host_name_str [OUT] Buffer to store host name part. + Must be not less than HOSTNAME_LENGTH + 1. + host_name_len [OUT] A place to store length of the host name part. +*/ + +void parse_user(const char *user_id_str, uint user_id_len, + char *user_name_str, uint *user_name_len, + char *host_name_str, uint *host_name_len) +{ + char *p= strrchr(user_id_str, '@'); + + if (!p) + { + *user_name_len= 0; + *host_name_len= 0; + } + else + { + *user_name_len= p - user_id_str; + *host_name_len= user_id_len - *user_name_len - 1; + + memcpy(user_name_str, user_id_str, *user_name_len); + memcpy(host_name_str, p + 1, *host_name_len); + } + + user_name_str[*user_name_len]= 0; + host_name_str[*host_name_len]= 0; +} diff --git a/sql/Makefile.am b/sql/Makefile.am index 1437751bf2f..d701c18a4d7 100644 --- a/sql/Makefile.am +++ b/sql/Makefile.am @@ -97,7 +97,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc \ stacktrace.c repl_failsafe.h repl_failsafe.cc \ sql_olap.cc sql_view.cc \ gstream.cc spatial.cc sql_help.cc sql_cursor.cc \ - tztime.cc my_time.c my_decimal.cc\ + tztime.cc my_time.c my_user.c my_decimal.cc\ sp_head.cc sp_pcontext.cc sp_rcontext.cc sp.cc \ sp_cache.cc parse_file.cc sql_trigger.cc \ examples/ha_example.cc ha_archive.cc \ @@ -133,6 +133,8 @@ link_sources: mysql_tzinfo_to_sql.cc @LN_CP_F@ $(top_srcdir)/sql-common/client.c client.c rm -f my_time.c @LN_CP_F@ $(top_srcdir)/sql-common/my_time.c my_time.c + rm -f my_user.c + @LN_CP_F@ $(top_srcdir)/sql-common/my_user.c my_user.c mysql_tzinfo_to_sql.o: $(mysql_tzinfo_to_sql_SOURCES) $(CXXCOMPILE) -c $(INCLUDES) -DTZINFO2SQL $< diff --git a/sql/sp.cc b/sql/sp.cc index a9b1a462d5f..37a9c02124e 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -480,7 +480,7 @@ db_create_routine(THD *thd, int type, sp_head *sp) { int ret; TABLE *table; - char definer[HOSTNAME_LENGTH+USERNAME_LENGTH+2]; + char definer[USER_HOST_BUFF_SIZE]; char olddb[128]; bool dbchanged; DBUG_ENTER("db_create_routine"); @@ -940,7 +940,7 @@ sp_find_routine(THD *thd, int type, sp_name *name, sp_cache **cp, ulong level; sp_head *new_sp; const char *returns= ""; - char definer[HOSTNAME_LENGTH+USERNAME_LENGTH+2]; + char definer[USER_HOST_BUFF_SIZE]; String retstr(64); DBUG_PRINT("info", ("found: 0x%lx", (ulong)sp)); diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 12f9260e7b1..d3045467f91 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -31,6 +31,8 @@ #define SP_STMT_PRINT_MAXLEN 40 +#include + Item_result sp_map_result_type(enum enum_field_types type) { @@ -1752,29 +1754,21 @@ sp_head::set_info(longlong created, longlong modified, void - sp_head::set_definer(const char *definer, uint definerlen) { - const char *p= strrchr(definer, '@'); + uint user_name_len; + char user_name_str[USERNAME_LENGTH + 1]; + uint host_name_len; + char host_name_str[HOSTNAME_LENGTH + 1]; - if (!p) - { - m_definer_user.str= (char*) ""; - m_definer_user.length= 0; - m_definer_host.str= (char*) ""; - m_definer_host.length= 0; - } - else - { - const uint user_name_len= p - definer; - const uint host_name_len= definerlen - user_name_len - 1; + parse_user(definer, definerlen, user_name_str, &user_name_len, + host_name_str, &host_name_len); - m_definer_user.str= strmake_root(mem_root, definer, user_name_len); - m_definer_user.length= user_name_len; + m_definer_user.str= strmake_root(mem_root, user_name_str, user_name_len); + m_definer_user.length= user_name_len; - m_definer_host.str= strmake_root(mem_root, p + 1, host_name_len); - m_definer_host.length= host_name_len; - } + m_definer_host.str= strmake_root(mem_root, host_name_str, host_name_len); + m_definer_host.length= host_name_len; } diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 7bb84895da5..130674b47f9 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -2490,7 +2490,7 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table, ulong rights, ulong col_rights, bool revoke_grant) { - char grantor[HOSTNAME_LENGTH+USERNAME_LENGTH+2]; + char grantor[USER_HOST_BUFF_SIZE]; int old_row_exists = 1; int error=0; ulong store_table_rights, store_col_rights; @@ -2608,7 +2608,7 @@ static int replace_routine_table(THD *thd, GRANT_NAME *grant_name, const char *db, const char *routine_name, bool is_proc, ulong rights, bool revoke_grant) { - char grantor[HOSTNAME_LENGTH+USERNAME_LENGTH+2]; + char grantor[USER_HOST_BUFF_SIZE]; int old_row_exists= 1; int error=0; ulong store_proc_rights; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 9cdb288c045..76d24ede8f5 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -214,7 +214,7 @@ static int get_or_create_user_conn(THD *thd, const char *user, { int return_val= 0; uint temp_len, user_len; - char temp_user[USERNAME_LENGTH+HOSTNAME_LENGTH+2]; + char temp_user[USER_HOST_BUFF_SIZE]; struct user_conn *uc; DBUG_ASSERT(user != 0); @@ -743,7 +743,7 @@ static void reset_mqh(LEX_USER *lu, bool get_them= 0) { USER_CONN *uc; uint temp_len=lu->user.length+lu->host.length+2; - char temp_user[USERNAME_LENGTH+HOSTNAME_LENGTH+2]; + char temp_user[USER_HOST_BUFF_SIZE]; memcpy(temp_user,lu->user.str,lu->user.length); memcpy(temp_user+lu->user.length+1,lu->host.str,lu->host.length); diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 089314078a6..d15df686e40 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -2887,7 +2887,7 @@ int fill_schema_proc(THD *thd, TABLE_LIST *tables, COND *cond) int res= 0; TABLE *table= tables->table; bool full_access; - char definer[HOSTNAME_LENGTH+USERNAME_LENGTH+2]; + char definer[USER_HOST_BUFF_SIZE]; Open_tables_state open_tables_state_backup; DBUG_ENTER("fill_schema_proc"); @@ -3029,7 +3029,7 @@ static int get_schema_views_record(THD *thd, struct st_table_list *tables, { CHARSET_INFO *cs= system_charset_info; DBUG_ENTER("get_schema_views_record"); - char definer[HOSTNAME_LENGTH + USERNAME_LENGTH + 2]; + char definer[USER_HOST_BUFF_SIZE]; uint definer_len; if (tables->view) @@ -3213,7 +3213,7 @@ static int get_schema_triggers_record(THD *thd, struct st_table_list *tables, LEX_STRING trigger_name; LEX_STRING trigger_stmt; ulong sql_mode; - char definer_holder[HOSTNAME_LENGTH + USERNAME_LENGTH + 2]; + char definer_holder[USER_HOST_BUFF_SIZE]; LEX_STRING definer_buffer; definer_buffer.str= definer_holder; if (triggers->get_trigger_info(thd, (enum trg_event_type) event, diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index bbc32950c2d..c70914edc31 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -317,7 +317,7 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables, LEX_STRING dir, file, trigname_file; LEX_STRING *trg_def, *name; ulonglong *trg_sql_mode; - char trg_definer_holder[HOSTNAME_LENGTH + USERNAME_LENGTH + 2]; + char trg_definer_holder[USER_HOST_BUFF_SIZE]; LEX_STRING *trg_definer; Item_trigger_field *trg_field; struct st_trigname trigname; From bbec7eda631db68ef9b124c869193b2eceac24ec Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Jan 2006 00:24:57 +0100 Subject: [PATCH 53/68] Disable code for "let" to assign each column from query to it's own variable client/mysqltest.c: Disable "let" assign each column of query to own var mysql-test/r/mysqltest.result: Remove test results for disabled test mysql-test/t/mysqltest.test: Disable test for "let assigns each column of query to own var" --- client/mysqltest.c | 3 ++- mysql-test/r/mysqltest.result | 19 ------------------- mysql-test/t/mysqltest.test | 4 ++-- 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index c31e8bc693b..a073df979f2 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -1205,6 +1205,7 @@ int var_query_set(VAR* var, const char *query, const char** query_end) { if (row[0]) { +#ifdef NOT_YET /* Add to _ */ uint j; char var_col_name[MAX_VAR_NAME]; @@ -1218,7 +1219,7 @@ int var_query_set(VAR* var, const char *query, const char** query_end) } var_set(var_col_name, var_col_name + length, row[i], row[i] + lengths[i]); - +#endif /* Add column to tab separated string */ dynstr_append_mem(&result, row[i], lengths[i]); } diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index 2657fb8a409..d0db0269a98 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -222,25 +222,6 @@ mysqltest: At line 1: Missing arguments to let mysqltest: At line 1: Missing variable name in let mysqltest: At line 1: Variable name in =hi does not start with '$' mysqltest: At line 1: Missing assignment operator in let -var1 -hi 1 hi there -hi -1 -hi there -var2 -2 - - -var2 again -2 - -2 - -var3 two columns with same name -1 2 3 -2 -2 -3 mysqltest: At line 1: Missing file name in source mysqltest: At line 1: Could not open file ./non_existingFile mysqltest: In included file "./var/tmp/recursive.sql": At line 1: Source directives are nesting too deep diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index ae28a66c685..ee309fbd7c9 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -543,7 +543,7 @@ echo $novar1; # Test to assign let from query # let $=``; # ---------------------------------------------------------------------------- - +--disable_parsing echo var1; let $var1= `select "hi" as "Col", 1 as "Column1", "hi there" as Col3`; echo $var1; @@ -574,7 +574,7 @@ echo $var3_var3; #echo failing query in let; #--error 1 #--exec echo "let $var2= `failing query;`" | $MYSQL_TEST 2>&1 - +--enable_parsing # ---------------------------------------------------------------------------- # Test source command # ---------------------------------------------------------------------------- From b5fb52dc4971354342126f3a018160366d09b30c Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Jan 2006 11:06:26 +0100 Subject: [PATCH 54/68] Fix problem with strange printout of line numbers, detected on aix52, but existing on all platforms, just being masked by init of vars to zero. client/mysqltest.c: Remove lineno_stack, instead use the already existing file_stack and add a new variable lineno to keep track of what line in the file we are at. mysql-test/r/mysqltest.result: Correct test result, "At line 1" should be printed --- client/mysqltest.c | 31 ++++++++++++++++--------------- mysql-test/r/mysqltest.result | 2 +- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index a073df979f2..31fd4992650 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -165,7 +165,6 @@ static my_bool sp_protocol= 0, sp_protocol_enabled= 0; static my_bool view_protocol= 0, view_protocol_enabled= 0; static my_bool cursor_protocol= 0, cursor_protocol_enabled= 0; static int parsing_disabled= 0; -static uint start_lineno, *lineno; const char *manager_user="root",*manager_host=0; char *manager_pass=0; int manager_port=MYSQL_MANAGER_PORT; @@ -180,13 +179,14 @@ typedef struct { FILE* file; const char *file_name; + uint lineno; /* Current line in file */ } test_file; static test_file file_stack[MAX_INCLUDE_DEPTH]; static test_file* cur_file; static test_file* file_stack_end; +uint start_lineno; /* Start line of query */ -static uint lineno_stack[MAX_INCLUDE_DEPTH]; static char TMPDIR[FN_REFLEN]; static char delimiter[MAX_DELIMITER]= DEFAULT_DELIMITER; static uint delimiter_length= 1; @@ -662,7 +662,7 @@ static void verbose_msg(const char *fmt, ...) va_start(args, fmt); fprintf(stderr, "mysqltest: "); - if (start_lineno > 0) + if (start_lineno != 0) fprintf(stderr, "At line %u: ", start_lineno); vfprintf(stderr, fmt, args); fprintf(stderr, "\n"); @@ -900,7 +900,7 @@ int open_file(const char *name) die("Could not open file %s", buff); } cur_file->file_name= my_strdup(buff, MYF(MY_FAE)); - *++lineno=1; + cur_file->lineno=1; DBUG_RETURN(0); } @@ -2497,7 +2497,7 @@ int read_line(char *buf, int size) DBUG_ENTER("read_line"); LINT_INIT(quote); - start_lineno= *lineno; + start_lineno= cur_file->lineno; for (; p < buf_end ;) { no_save= 0; @@ -2512,28 +2512,25 @@ int read_line(char *buf, int size) } my_free((gptr)cur_file->file_name, MYF(MY_ALLOW_ZERO_PTR)); cur_file->file_name= 0; - lineno--; - start_lineno= *lineno; if (cur_file == file_stack) { /* We're back at the first file, check if all { have matching } */ if (cur_block != block_stack) - { - start_lineno= *(lineno+1); die("Missing end of block"); - } + DBUG_PRINT("info", ("end of file")); DBUG_RETURN(1); } cur_file--; + start_lineno= cur_file->lineno; continue; } /* Line counting is independent of state */ if (c == '\n') - (*lineno)++; + cur_file->lineno++; switch(state) { case R_NORMAL: @@ -2562,14 +2559,15 @@ int read_line(char *buf, int size) break; case R_LINE_START: /* Only accept start of comment if this is the first line in query */ - if ((*lineno == start_lineno) && (c == '#' || c == '-' || parsing_disabled)) + if ((cur_file->lineno == start_lineno) && + (c == '#' || c == '-' || parsing_disabled)) { state = R_COMMENT; } else if (my_isspace(charset_info, c)) { if (c == '\n') - start_lineno= *lineno; /* Query hasn't started yet */ + start_lineno= cur_file->lineno; /* Query hasn't started yet */ no_save= 1; } else if (c == '}') @@ -2895,6 +2893,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(0)))) die("Could not open %s: errno = %d", buff, errno); cur_file->file_name= my_strdup(buff, MYF(MY_FAE)); + cur_file->lineno= 1; break; } case 'm': @@ -4291,7 +4290,7 @@ int main(int argc, char **argv) memset(&master_pos, 0, sizeof(master_pos)); file_stack_end= file_stack + MAX_INCLUDE_DEPTH - 1; cur_file= file_stack; - lineno = lineno_stack; + my_init_dynamic_array(&q_lines, sizeof(struct st_query*), INIT_Q_LINES, INIT_Q_LINES); @@ -4313,8 +4312,8 @@ int main(int argc, char **argv) { cur_file->file= stdin; cur_file->file_name= my_strdup("", MYF(MY_WME)); + cur_file->lineno= 1; } - *lineno=1; #ifndef EMBEDDED_LIBRARY if (manager_host) init_manager(); @@ -4609,6 +4608,8 @@ int main(int argc, char **argv) parser.current_line += current_line_inc; } + start_lineno= 0; + /* The whole test has been executed _sucessfully_ Time to compare result or save it to record file diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index d0db0269a98..067054510c2 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -149,7 +149,7 @@ hello mysqltest: At line 1: End of line junk detected: "6" mysqltest: At line 1: End of line junk detected: "6" mysqltest: At line 1: Missing delimiter -mysqltest: End of line junk detected: "sleep 7 +mysqltest: At line 1: End of line junk detected: "sleep 7 # Another comment " mysqltest: At line 1: Extra delimiter ";" found From c5451d02ad12a66b9be067be9db77e184651a12b Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Jan 2006 11:07:17 +0100 Subject: [PATCH 55/68] Remove obsolete comment --- client/mysqltest.c | 1 - 1 file changed, 1 deletion(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 31fd4992650..552d8c4ee29 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -2669,7 +2669,6 @@ int read_line(char *buf, int size) The advantage with this approach is to be able to execute commands terminated by new line '\n' regardless how many "delimiter" it contain. - If query starts with @ this will specify a file to .... */ static char read_query_buf[MAX_QUERY]; From 113290fe2f8846802edbe2688c72ca49f304091f Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Jan 2006 11:10:58 +0100 Subject: [PATCH 56/68] Add comments that groups and describes the inits client/mysqltest.c: Add comments Group inits logically --- client/mysqltest.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 552d8c4ee29..6a2a7b072de 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -4280,25 +4280,30 @@ int main(int argc, char **argv) save_file[0]=0; TMPDIR[0]=0; + + /* Init cons */ memset(cons, 0, sizeof(cons)); cons_end = cons + MAX_CONS; next_con = cons + 1; cur_con = cons; + /* Init file stack */ memset(file_stack, 0, sizeof(file_stack)); - memset(&master_pos, 0, sizeof(master_pos)); file_stack_end= file_stack + MAX_INCLUDE_DEPTH - 1; cur_file= file_stack; - my_init_dynamic_array(&q_lines, sizeof(struct st_query*), INIT_Q_LINES, - INIT_Q_LINES); - + /* Init block stack */ memset(block_stack, 0, sizeof(block_stack)); block_stack_end= block_stack + BLOCK_STACK_DEPTH - 1; cur_block= block_stack; cur_block->ok= TRUE; /* Outer block should always be executed */ cur_block->cmd= cmd_none; + my_init_dynamic_array(&q_lines, sizeof(struct st_query*), INIT_Q_LINES, + INIT_Q_LINES); + + memset(&master_pos, 0, sizeof(master_pos)); + init_dynamic_string(&ds_res, "", 0, 65536); parse_args(argc, argv); From 31ff9e9a1077d24287a36a3ff1e9e946e11a6a38 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Jan 2006 17:31:52 +0300 Subject: [PATCH 57/68] A fix for Bug#13944 "libmysqlclient exporting sha1_result function": rename sha1_* to mysql_sha1_* include/sha1.h: rename sha1_* to mysql_sha1_* mysys/sha1.c: rename sha1_* to mysql_sha1_* sql/item_strfunc.cc: rename sha1_* to mysql_sha1_* sql/password.c: rename sha1_* to mysql_sha1_* --- include/sha1.h | 6 +++--- mysys/sha1.c | 16 ++++++++-------- sql/item_strfunc.cc | 8 +++++--- sql/password.c | 46 ++++++++++++++++++++++----------------------- 4 files changed, 39 insertions(+), 37 deletions(-) diff --git a/include/sha1.h b/include/sha1.h index 1c345469d3c..e67acbf96b8 100644 --- a/include/sha1.h +++ b/include/sha1.h @@ -60,8 +60,8 @@ typedef struct SHA1_CONTEXT C_MODE_START -int sha1_reset( SHA1_CONTEXT* ); -int sha1_input( SHA1_CONTEXT*, const uint8 *, unsigned int ); -int sha1_result( SHA1_CONTEXT* , uint8 Message_Digest[SHA1_HASH_SIZE] ); +int mysql_sha1_reset(SHA1_CONTEXT*); +int mysql_sha1_input(SHA1_CONTEXT*, const uint8 *, unsigned int); +int mysql_sha1_result(SHA1_CONTEXT* , uint8 Message_Digest[SHA1_HASH_SIZE]); C_MODE_END diff --git a/mysys/sha1.c b/mysys/sha1.c index d93b4571baf..110d24f8bfc 100644 --- a/mysys/sha1.c +++ b/mysys/sha1.c @@ -69,7 +69,7 @@ static void SHA1ProcessMessageBlock(SHA1_CONTEXT*); Initialize SHA1Context SYNOPSIS - sha1_reset() + mysql_sha1_reset() context [in/out] The context to reset. DESCRIPTION @@ -92,7 +92,7 @@ const uint32 sha_const_key[5]= }; -int sha1_reset(SHA1_CONTEXT *context) +int mysql_sha1_reset(SHA1_CONTEXT *context) { #ifndef DBUG_OFF if (!context) @@ -119,7 +119,7 @@ int sha1_reset(SHA1_CONTEXT *context) Return the 160-bit message digest into the array provided by the caller SYNOPSIS - sha1_result() + mysql_sha1_result() context [in/out] The context to use to calculate the SHA-1 hash. Message_Digest: [out] Where the digest is returned. @@ -132,8 +132,8 @@ int sha1_reset(SHA1_CONTEXT *context) != SHA_SUCCESS sha Error Code. */ -int sha1_result(SHA1_CONTEXT *context, - uint8 Message_Digest[SHA1_HASH_SIZE]) +int mysql_sha1_result(SHA1_CONTEXT *context, + uint8 Message_Digest[SHA1_HASH_SIZE]) { int i; @@ -165,7 +165,7 @@ int sha1_result(SHA1_CONTEXT *context, Accepts an array of octets as the next portion of the message. SYNOPSIS - sha1_input() + mysql_sha1_input() context [in/out] The SHA context to update message_array An array of characters representing the next portion of the message. @@ -176,8 +176,8 @@ int sha1_result(SHA1_CONTEXT *context, != SHA_SUCCESS sha Error Code. */ -int sha1_input(SHA1_CONTEXT *context, const uint8 *message_array, - unsigned length) +int mysql_sha1_input(SHA1_CONTEXT *context, const uint8 *message_array, + unsigned length) { if (!length) return SHA_SUCCESS; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 60cb3348590..04765e18191 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -131,11 +131,13 @@ String *Item_func_sha::val_str(String *str) SHA1_CONTEXT context; /* Context used to generate SHA1 hash */ /* Temporary buffer to store 160bit digest */ uint8 digest[SHA1_HASH_SIZE]; - sha1_reset(&context); /* We do not have to check for error here */ + mysql_sha1_reset(&context); /* We do not have to check for error here */ /* No need to check error as the only case would be too long message */ - sha1_input(&context,(const unsigned char *) sptr->ptr(), sptr->length()); + mysql_sha1_input(&context, + (const unsigned char *) sptr->ptr(), sptr->length()); /* Ensure that memory is free and we got result */ - if (!( str->alloc(SHA1_HASH_SIZE*2) || (sha1_result(&context,digest)))) + if (!( str->alloc(SHA1_HASH_SIZE*2) || + (mysql_sha1_result(&context,digest)))) { sprintf((char *) str->ptr(), "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\ diff --git a/sql/password.c b/sql/password.c index 04b3a46bd48..94b9dc440be 100644 --- a/sql/password.c +++ b/sql/password.c @@ -392,15 +392,15 @@ make_scrambled_password(char *to, const char *password) SHA1_CONTEXT sha1_context; uint8 hash_stage2[SHA1_HASH_SIZE]; - sha1_reset(&sha1_context); + mysql_sha1_reset(&sha1_context); /* stage 1: hash password */ - sha1_input(&sha1_context, (uint8 *) password, strlen(password)); - sha1_result(&sha1_context, (uint8 *) to); + mysql_sha1_input(&sha1_context, (uint8 *) password, strlen(password)); + mysql_sha1_result(&sha1_context, (uint8 *) to); /* stage 2: hash stage1 output */ - sha1_reset(&sha1_context); - sha1_input(&sha1_context, (uint8 *) to, SHA1_HASH_SIZE); + mysql_sha1_reset(&sha1_context); + mysql_sha1_input(&sha1_context, (uint8 *) to, SHA1_HASH_SIZE); /* separate buffer is used to pass 'to' in octet2hex */ - sha1_result(&sha1_context, hash_stage2); + mysql_sha1_result(&sha1_context, hash_stage2); /* convert hash_stage2 to hex string */ *to++= PVERSION41_CHAR; octet2hex(to, hash_stage2, SHA1_HASH_SIZE); @@ -431,20 +431,20 @@ scramble(char *to, const char *message, const char *password) uint8 hash_stage1[SHA1_HASH_SIZE]; uint8 hash_stage2[SHA1_HASH_SIZE]; - sha1_reset(&sha1_context); + mysql_sha1_reset(&sha1_context); /* stage 1: hash password */ - sha1_input(&sha1_context, (uint8 *) password, strlen(password)); - sha1_result(&sha1_context, hash_stage1); + mysql_sha1_input(&sha1_context, (uint8 *) password, strlen(password)); + mysql_sha1_result(&sha1_context, hash_stage1); /* stage 2: hash stage 1; note that hash_stage2 is stored in the database */ - sha1_reset(&sha1_context); - sha1_input(&sha1_context, hash_stage1, SHA1_HASH_SIZE); - sha1_result(&sha1_context, hash_stage2); + mysql_sha1_reset(&sha1_context); + mysql_sha1_input(&sha1_context, hash_stage1, SHA1_HASH_SIZE); + mysql_sha1_result(&sha1_context, hash_stage2); /* create crypt string as sha1(message, hash_stage2) */; - sha1_reset(&sha1_context); - sha1_input(&sha1_context, (const uint8 *) message, SCRAMBLE_LENGTH); - sha1_input(&sha1_context, hash_stage2, SHA1_HASH_SIZE); + mysql_sha1_reset(&sha1_context); + mysql_sha1_input(&sha1_context, (const uint8 *) message, SCRAMBLE_LENGTH); + mysql_sha1_input(&sha1_context, hash_stage2, SHA1_HASH_SIZE); /* xor allows 'from' and 'to' overlap: lets take advantage of it */ - sha1_result(&sha1_context, (uint8 *) to); + mysql_sha1_result(&sha1_context, (uint8 *) to); my_crypt(to, (const uchar *) to, hash_stage1, SCRAMBLE_LENGTH); } @@ -477,17 +477,17 @@ check_scramble(const char *scramble, const char *message, uint8 buf[SHA1_HASH_SIZE]; uint8 hash_stage2_reassured[SHA1_HASH_SIZE]; - sha1_reset(&sha1_context); + mysql_sha1_reset(&sha1_context); /* create key to encrypt scramble */ - sha1_input(&sha1_context, (const uint8 *) message, SCRAMBLE_LENGTH); - sha1_input(&sha1_context, hash_stage2, SHA1_HASH_SIZE); - sha1_result(&sha1_context, buf); + mysql_sha1_input(&sha1_context, (const uint8 *) message, SCRAMBLE_LENGTH); + mysql_sha1_input(&sha1_context, hash_stage2, SHA1_HASH_SIZE); + mysql_sha1_result(&sha1_context, buf); /* encrypt scramble */ my_crypt((char *) buf, buf, (const uchar *) scramble, SCRAMBLE_LENGTH); /* now buf supposedly contains hash_stage1: so we can get hash_stage2 */ - sha1_reset(&sha1_context); - sha1_input(&sha1_context, buf, SHA1_HASH_SIZE); - sha1_result(&sha1_context, hash_stage2_reassured); + mysql_sha1_reset(&sha1_context); + mysql_sha1_input(&sha1_context, buf, SHA1_HASH_SIZE); + mysql_sha1_result(&sha1_context, hash_stage2_reassured); return memcmp(hash_stage2, hash_stage2_reassured, SHA1_HASH_SIZE); } From 65bffb0f6dbb2f034c327d68b5bc49cc2125dd61 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Jan 2006 16:18:11 -0600 Subject: [PATCH 58/68] simple Windows compile fixes. include/config-win.h: use the ll and ull postfix codes for create longlong and ulonglong symbols. This allows ULL(a) and LL(a) to be used in more complex macro definitions than the previous definitions. This may work on other compilers but we just tested on Visual 7.1 and 8.0 Also, define HAVE_STRNLEN for all windows platforms. Our own strnlen offers no performance improvements over the CRT version. --- include/config-win.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/include/config-win.h b/include/config-win.h index 53483f3f39d..b2bd63efc30 100644 --- a/include/config-win.h +++ b/include/config-win.h @@ -108,11 +108,17 @@ functions */ #undef _REENTRANT /* Crashes something for win32 */ #undef SAFE_MUTEX /* Can't be used on windows */ -#define LONGLONG_MIN ((__int64) 0x8000000000000000) -#define LONGLONG_MAX ((__int64) 0x7FFFFFFFFFFFFFFF) -#define ULONGLONG_MAX ((unsigned __int64) 0xFFFFFFFFFFFFFFFF) -#define LL(A) ((__int64) A) -#define ULL(A) ((unsigned __int64) A) +#if defined(_MSC_VER) && _MSC_VER >= 1310 +#define LL(A) A##ll +#define ULL(A) A##ull +#else +#define LL(A) ((__int64) A) +#define ULL(A) ((unsigned __int64) A) +#endif + +#define LONGLONG_MIN LL(0x8000000000000000) +#define LONGLONG_MAX LL(0x7FFFFFFFFFFFFFFF) +#define ULONGLONG_MAX ULL(0xFFFFFFFFFFFFFFFF) /* Type information */ @@ -333,11 +339,7 @@ inline double ulonglong2double(ulonglong value) #define SPRINTF_RETURNS_INT #define HAVE_SETFILEPOINTER #define HAVE_VIO_READ_BUFF - -#if defined(_WIN64) && defined(_M_X64) -/* Avoid type conflicts with built-in functions. */ #define HAVE_STRNLEN -#endif #ifndef __NT__ #undef FILE_SHARE_DELETE From f315b0b8a74edac5acd369c4024e82b4c26a098f Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Jan 2006 03:02:52 +0300 Subject: [PATCH 59/68] Fix for BUG#15103: SHOW TRIGGERS: small output alignment problem. mysql-test/r/information_schema.result: Remove extra spaces from result file. mysql-test/r/mysqldump.result: Remove extra spaces from result file. mysql-test/r/rpl_ddl.result: Remove extra spaces from result file. mysql-test/r/trigger-compat.result: Remove extra spaces from result file. mysql-test/r/trigger-grant.result: Remove extra spaces from result file. mysql-test/r/trigger.result: Remove extra spaces from result file. sql/sql_yacc.yy: Remove leading spaces. --- mysql-test/r/information_schema.result | 18 ++++++---------- mysql-test/r/mysqldump.result | 30 ++++++++++---------------- mysql-test/r/rpl_ddl.result | 4 ++-- mysql-test/r/trigger-compat.result | 6 ++---- mysql-test/r/trigger-grant.result | 21 ++++++------------ mysql-test/r/trigger.result | 4 ++-- sql/sql_yacc.yy | 2 ++ 7 files changed, 32 insertions(+), 53 deletions(-) diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index 05f2118a8c7..e7d82f48691 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -816,40 +816,34 @@ end if; end| show triggers; Trigger Event Table Statement Timing Created sql_mode Definer -trg1 INSERT t1 -begin +trg1 INSERT t1 begin if new.j > 10 then set new.j := 10; end if; end BEFORE NULL root@localhost -trg2 UPDATE t1 -begin +trg2 UPDATE t1 begin if old.i % 2 = 0 then set new.j := -1; end if; end BEFORE NULL root@localhost -trg3 UPDATE t1 -begin +trg3 UPDATE t1 begin if new.j = -1 then set @fired:= "Yes"; end if; end AFTER NULL root@localhost select * from information_schema.triggers; TRIGGER_CATALOG TRIGGER_SCHEMA TRIGGER_NAME EVENT_MANIPULATION EVENT_OBJECT_CATALOG EVENT_OBJECT_SCHEMA EVENT_OBJECT_TABLE ACTION_ORDER ACTION_CONDITION ACTION_STATEMENT ACTION_ORIENTATION ACTION_TIMING ACTION_REFERENCE_OLD_TABLE ACTION_REFERENCE_NEW_TABLE ACTION_REFERENCE_OLD_ROW ACTION_REFERENCE_NEW_ROW CREATED SQL_MODE DEFINER -NULL test trg1 INSERT NULL test t1 0 NULL -begin +NULL test trg1 INSERT NULL test t1 0 NULL begin if new.j > 10 then set new.j := 10; end if; end ROW BEFORE NULL NULL OLD NEW NULL root@localhost -NULL test trg2 UPDATE NULL test t1 0 NULL -begin +NULL test trg2 UPDATE NULL test t1 0 NULL begin if old.i % 2 = 0 then set new.j := -1; end if; end ROW BEFORE NULL NULL OLD NEW NULL root@localhost -NULL test trg3 UPDATE NULL test t1 0 NULL -begin +NULL test trg3 UPDATE NULL test t1 0 NULL begin if new.j = -1 then set @fired:= "Yes"; end if; diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index 4e2564c69da..717d9f67774 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -1937,18 +1937,16 @@ end| set sql_mode=default| show triggers like "t1"; Trigger Event Table Statement Timing Created sql_mode Definer -trg1 INSERT t1 -begin +trg1 INSERT t1 begin if new.a > 10 then set new.a := 10; set new.a := 11; end if; end BEFORE 0000-00-00 00:00:00 root@localhost -trg2 UPDATE t1 begin +trg2 UPDATE t1 begin if old.a % 2 = 0 then set new.b := 12; end if; end BEFORE 0000-00-00 00:00:00 root@localhost -trg3 UPDATE t1 -begin +trg3 UPDATE t1 begin if new.a = -1 then set @fired:= "Yes"; end if; @@ -1986,8 +1984,7 @@ UNLOCK TABLES; /*!50003 SET @OLD_SQL_MODE=@@SQL_MODE*/; DELIMITER ;; /*!50003 SET SESSION SQL_MODE="" */;; -/*!50003 CREATE */ /*!50017 DEFINER=`root`@`localhost` */ /*!50003 TRIGGER `trg1` BEFORE INSERT ON `t1` FOR EACH ROW -begin +/*!50003 CREATE */ /*!50017 DEFINER=`root`@`localhost` */ /*!50003 TRIGGER `trg1` BEFORE INSERT ON `t1` FOR EACH ROW begin if new.a > 10 then set new.a := 10; set new.a := 11; @@ -2000,8 +1997,7 @@ if old.a % 2 = 0 then set new.b := 12; end if; end */;; /*!50003 SET SESSION SQL_MODE="STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER" */;; -/*!50003 CREATE */ /*!50017 DEFINER=`root`@`localhost` */ /*!50003 TRIGGER `trg3` AFTER UPDATE ON `t1` FOR EACH ROW -begin +/*!50003 CREATE */ /*!50017 DEFINER=`root`@`localhost` */ /*!50003 TRIGGER `trg3` AFTER UPDATE ON `t1` FOR EACH ROW begin if new.a = -1 then set @fired:= "Yes"; end if; @@ -2023,8 +2019,7 @@ UNLOCK TABLES; /*!50003 SET @OLD_SQL_MODE=@@SQL_MODE*/; DELIMITER ;; /*!50003 SET SESSION SQL_MODE="STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER" */;; -/*!50003 CREATE */ /*!50017 DEFINER=`root`@`localhost` */ /*!50003 TRIGGER `trg4` BEFORE INSERT ON `t2` FOR EACH ROW -begin +/*!50003 CREATE */ /*!50017 DEFINER=`root`@`localhost` */ /*!50003 TRIGGER `trg4` BEFORE INSERT ON `t2` FOR EACH ROW begin if new.a > 10 then set @fired:= "No"; end if; @@ -2096,24 +2091,21 @@ t1 t2 show triggers; Trigger Event Table Statement Timing Created sql_mode Definer -trg1 INSERT t1 -begin +trg1 INSERT t1 begin if new.a > 10 then set new.a := 10; set new.a := 11; end if; end BEFORE # root@localhost -trg2 UPDATE t1 begin +trg2 UPDATE t1 begin if old.a % 2 = 0 then set new.b := 12; end if; end BEFORE # root@localhost -trg3 UPDATE t1 -begin +trg3 UPDATE t1 begin if new.a = -1 then set @fired:= "Yes"; end if; end AFTER # STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER root@localhost -trg4 INSERT t2 -begin +trg4 INSERT t2 begin if new.a > 10 then set @fired:= "No"; end if; @@ -2141,7 +2133,7 @@ a2 1 SHOW TRIGGERS; Trigger Event Table Statement Timing Created sql_mode Definer -testref INSERT test1 BEGIN +testref INSERT test1 BEGIN INSERT INTO test2 SET a2 = NEW.a1; END BEFORE NULL root@localhost SELECT * FROM `test1`; a1 diff --git a/mysql-test/r/rpl_ddl.result b/mysql-test/r/rpl_ddl.result index 4d8f2f11d4a..c56c9f20cf8 100644 --- a/mysql-test/r/rpl_ddl.result +++ b/mysql-test/r/rpl_ddl.result @@ -1466,12 +1466,12 @@ flush logs; -------- switch to master ------- SHOW TRIGGERS; Trigger Event Table Statement Timing Created sql_mode Definer -trg1 INSERT t1 SET @a:=1 BEFORE NULL root@localhost +trg1 INSERT t1 SET @a:=1 BEFORE NULL root@localhost -------- switch to slave ------- SHOW TRIGGERS; Trigger Event Table Statement Timing Created sql_mode Definer -trg1 INSERT t1 SET @a:=1 BEFORE NULL root@localhost +trg1 INSERT t1 SET @a:=1 BEFORE NULL root@localhost ######## DROP TRIGGER trg1 ######## diff --git a/mysql-test/r/trigger-compat.result b/mysql-test/r/trigger-compat.result index 5c104a2d2d5..7721a55449b 100644 --- a/mysql-test/r/trigger-compat.result +++ b/mysql-test/r/trigger-compat.result @@ -34,7 +34,5 @@ Warning 1454 No definer attribute for trigger 'mysqltest_db1'.'wl2818_trg1'. The SELECT * FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name; TRIGGER_CATALOG TRIGGER_SCHEMA TRIGGER_NAME EVENT_MANIPULATION EVENT_OBJECT_CATALOG EVENT_OBJECT_SCHEMA EVENT_OBJECT_TABLE ACTION_ORDER ACTION_CONDITION ACTION_STATEMENT ACTION_ORIENTATION ACTION_TIMING ACTION_REFERENCE_OLD_TABLE ACTION_REFERENCE_NEW_TABLE ACTION_REFERENCE_OLD_ROW ACTION_REFERENCE_NEW_ROW CREATED SQL_MODE DEFINER -NULL mysqltest_db1 wl2818_trg1 INSERT NULL mysqltest_db1 t1 0 NULL -INSERT INTO t2 VALUES(CURRENT_USER()) ROW BEFORE NULL NULL OLD NEW NULL -NULL mysqltest_db1 wl2818_trg2 INSERT NULL mysqltest_db1 t1 0 NULL -INSERT INTO t2 VALUES(CURRENT_USER()) ROW AFTER NULL NULL OLD NEW NULL mysqltest_dfn@localhost +NULL mysqltest_db1 wl2818_trg1 INSERT NULL mysqltest_db1 t1 0 NULL INSERT INTO t2 VALUES(CURRENT_USER()) ROW BEFORE NULL NULL OLD NEW NULL +NULL mysqltest_db1 wl2818_trg2 INSERT NULL mysqltest_db1 t1 0 NULL INSERT INTO t2 VALUES(CURRENT_USER()) ROW AFTER NULL NULL OLD NEW NULL mysqltest_dfn@localhost diff --git a/mysql-test/r/trigger-grant.result b/mysql-test/r/trigger-grant.result index eda1adfdf65..858cab7a04a 100644 --- a/mysql-test/r/trigger-grant.result +++ b/mysql-test/r/trigger-grant.result @@ -185,10 +185,8 @@ INSERT INTO t1 VALUES(6); ERROR 42000: Access denied; you need the SUPER privilege for this operation SHOW TRIGGERS; Trigger Event Table Statement Timing Created sql_mode Definer -trg1 INSERT t1 -SET @new_sum = 0 BEFORE NULL mysqltest_inv@localhost -trg2 INSERT t1 -SET @new_sum = 0 AFTER NULL mysqltest_nonexs@localhost +trg1 INSERT t1 SET @new_sum = 0 BEFORE NULL mysqltest_inv@localhost +trg2 INSERT t1 SET @new_sum = 0 AFTER NULL mysqltest_nonexs@localhost DROP TRIGGER trg1; DROP TRIGGER trg2; CREATE TRIGGER trg1 BEFORE INSERT ON t1 @@ -219,16 +217,11 @@ Warning 1454 No definer attribute for trigger 'mysqltest_db1'.'trg1'. The trigge SELECT * FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name; TRIGGER_CATALOG TRIGGER_SCHEMA TRIGGER_NAME EVENT_MANIPULATION EVENT_OBJECT_CATALOG EVENT_OBJECT_SCHEMA EVENT_OBJECT_TABLE ACTION_ORDER ACTION_CONDITION ACTION_STATEMENT ACTION_ORIENTATION ACTION_TIMING ACTION_REFERENCE_OLD_TABLE ACTION_REFERENCE_NEW_TABLE ACTION_REFERENCE_OLD_ROW ACTION_REFERENCE_NEW_ROW CREATED SQL_MODE DEFINER -NULL mysqltest_db1 trg1 INSERT NULL mysqltest_db1 t1 0 NULL -SET @a = 1 ROW BEFORE NULL NULL OLD NEW NULL -NULL mysqltest_db1 trg2 INSERT NULL mysqltest_db1 t1 0 NULL -SET @a = 2 ROW AFTER NULL NULL OLD NEW NULL @ -NULL mysqltest_db1 trg3 UPDATE NULL mysqltest_db1 t1 0 NULL -SET @a = 3 ROW BEFORE NULL NULL OLD NEW NULL @abc@def@@ -NULL mysqltest_db1 trg4 UPDATE NULL mysqltest_db1 t1 0 NULL -SET @a = 4 ROW AFTER NULL NULL OLD NEW NULL @hostname -NULL mysqltest_db1 trg5 DELETE NULL mysqltest_db1 t1 0 NULL -SET @a = 5 ROW BEFORE NULL NULL OLD NEW NULL @abcdef@@@hostname +NULL mysqltest_db1 trg1 INSERT NULL mysqltest_db1 t1 0 NULL SET @a = 1 ROW BEFORE NULL NULL OLD NEW NULL +NULL mysqltest_db1 trg2 INSERT NULL mysqltest_db1 t1 0 NULL SET @a = 2 ROW AFTER NULL NULL OLD NEW NULL @ +NULL mysqltest_db1 trg3 UPDATE NULL mysqltest_db1 t1 0 NULL SET @a = 3 ROW BEFORE NULL NULL OLD NEW NULL @abc@def@@ +NULL mysqltest_db1 trg4 UPDATE NULL mysqltest_db1 t1 0 NULL SET @a = 4 ROW AFTER NULL NULL OLD NEW NULL @hostname +NULL mysqltest_db1 trg5 DELETE NULL mysqltest_db1 t1 0 NULL SET @a = 5 ROW BEFORE NULL NULL OLD NEW NULL @abcdef@@@hostname ---> connection: default DROP USER mysqltest_dfn@localhost; diff --git a/mysql-test/r/trigger.result b/mysql-test/r/trigger.result index 38dff6f8ca5..9cfecde7610 100644 --- a/mysql-test/r/trigger.result +++ b/mysql-test/r/trigger.result @@ -613,7 +613,7 @@ select @a; show triggers; Trigger Event Table Statement Timing Created sql_mode Definer t1_bi INSERT t1 set new."t1 column" = 5 BEFORE # REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ANSI root@localhost -t1_af INSERT t1 set @a=10 AFTER # root@localhost +t1_af INSERT t1 set @a=10 AFTER # root@localhost drop table t1; set sql_mode="traditional"; create table t1 (a date); @@ -634,7 +634,7 @@ t1 CREATE TABLE `t1` ( ) ENGINE=MyISAM DEFAULT CHARSET=latin1 show triggers; Trigger Event Table Statement Timing Created sql_mode Definer -t1_bi INSERT t1 set new.a = '2004-01-00' BEFORE # root@localhost +t1_bi INSERT t1 set new.a = '2004-01-00' BEFORE # root@localhost drop table t1; create table t1 (id int); create trigger t1_ai after insert on t1 for each row flush tables; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 25e10362ece..ce0cb35dcf8 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -9103,6 +9103,8 @@ trigger_tail: bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics)); lex->sphead->m_chistics= &lex->sp_chistics; lex->sphead->m_body_begin= lex->ptr; + while (my_isspace(system_charset_info, lex->sphead->m_body_begin[0])) + ++lex->sphead->m_body_begin; } sp_proc_stmt { From 8d9ffc6ad4ad487cd7adfe8d8bb2028cf0920a44 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Jan 2006 10:48:27 +0300 Subject: [PATCH 60/68] BUG#16166, "Can't use index_merge with FORCE INDEX": adjust the heurstics check to take into account that "FORCE INDEX" disables full table scans, and not range/index_merge scans. (with post-review fixes) mysql-test/r/index_merge.result: Testcase for BUG#16166 mysql-test/t/index_merge.test: Testcase for BUG#16166 sql/sql_select.cc: BUG#16166: "Can't use index_merge with FORCE INDEX": adjust the heuristics check: if (force-index-is-used && there-is-possible-ref-access && + THERE IS NO POSSIBLE RANGE/INDEX_MERGE ACCESS) { ... --- mysql-test/r/index_merge.result | 18 +++++++++++++++++ mysql-test/t/index_merge.test | 30 ++++++++++++++++++++++++++++ sql/sql_select.cc | 35 ++++++++++++++++++++++++++------- 3 files changed, 76 insertions(+), 7 deletions(-) diff --git a/mysql-test/r/index_merge.result b/mysql-test/r/index_merge.result index d039d5a04c9..db87253e19a 100644 --- a/mysql-test/r/index_merge.result +++ b/mysql-test/r/index_merge.result @@ -384,3 +384,21 @@ max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4 + A.ke 8186 set join_buffer_size= @save_join_buffer_size; drop table t0, t1, t2, t3, t4; +CREATE TABLE t1 ( +cola char(3) not null, colb char(3) not null, filler char(200), +key(cola), key(colb) +); +INSERT INTO t1 VALUES ('foo','bar', 'ZZ'),('fuz','baz', 'ZZ'); +OPTIMIZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 optimize status OK +select count(*) from t1; +count(*) +8704 +explain select * from t1 WHERE cola = 'foo' AND colb = 'bar'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index_merge cola,colb cola,colb 3,3 NULL 24 Using intersect(cola,colb); Using where +explain select * from t1 force index(cola,colb) WHERE cola = 'foo' AND colb = 'bar'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index_merge cola,colb cola,colb 3,3 NULL 24 Using intersect(cola,colb); Using where +drop table t1; diff --git a/mysql-test/t/index_merge.test b/mysql-test/t/index_merge.test index 42175a757c2..10512902409 100644 --- a/mysql-test/t/index_merge.test +++ b/mysql-test/t/index_merge.test @@ -327,3 +327,33 @@ set join_buffer_size= @save_join_buffer_size; drop table t0, t1, t2, t3, t4; +# BUG#16166 +CREATE TABLE t1 ( + cola char(3) not null, colb char(3) not null, filler char(200), + key(cola), key(colb) +); +INSERT INTO t1 VALUES ('foo','bar', 'ZZ'),('fuz','baz', 'ZZ'); + +--disable_query_log +let $1=9; +while ($1) +{ + eval INSERT INTO t1 SELECT * from t1 WHERE cola = 'foo'; + dec $1; +} + +let $1=13; +while ($1) +{ + eval INSERT INTO t1 SELECT * from t1 WHERE cola <> 'foo'; + dec $1; +} + +--enable_query_log + +OPTIMIZE TABLE t1; +select count(*) from t1; +explain select * from t1 WHERE cola = 'foo' AND colb = 'bar'; +explain select * from t1 force index(cola,colb) WHERE cola = 'foo' AND colb = 'bar'; +drop table t1; + diff --git a/sql/sql_select.cc b/sql/sql_select.cc index c282a5bd42c..4a31a297c25 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -3471,13 +3471,32 @@ best_access_path(JOIN *join, parts of the row from any of the used index. This is because table scans uses index and we would not win anything by using a table scan. + + A word for word translation of the below if-statement in psergey's + understanding: we check if we should use table scan if: + (1) The found 'ref' access produces more records than a table scan + (or index scan, or quick select), or 'ref' is more expensive than + any of them. + (2) This doesn't hold: the best way to perform table scan is to to perform + 'range' access using index IDX, and the best way to perform 'ref' + access is to use the same index IDX, with the same or more key parts. + (note: it is not clear how this rule is/should be extended to + index_merge quick selects) + (3) See above note about InnoDB. + (4) NOT ("FORCE INDEX(...)" is used for table and there is 'ref' access + path, but there is no quick select) + If the condition in the above brackets holds, then the only possible + "table scan" access method is ALL/index (there is no quick select). + Since we have a 'ref' access path, and FORCE INDEX instructs us to + choose it over ALL/index, there is no need to consider a full table + scan. */ - if ((records >= s->found_records || best > s->read_time) && - !(s->quick && best_key && s->quick->index == best_key->key && - best_max_key_part >= s->table->quick_key_parts[best_key->key]) && - !((s->table->file->table_flags() & HA_TABLE_SCAN_ON_INDEX) && - ! s->table->used_keys.is_clear_all() && best_key) && - !(s->table->force_index && best_key)) + if ((records >= s->found_records || best > s->read_time) && // (1) + !(s->quick && best_key && s->quick->index == best_key->key && // (2) + best_max_key_part >= s->table->quick_key_parts[best_key->key]) &&// (2) + !((s->table->file->table_flags() & HA_TABLE_SCAN_ON_INDEX) && // (3) + ! s->table->used_keys.is_clear_all() && best_key) && // (3) + !(s->table->force_index && best_key && !s->quick)) // (4) { // Check full join ha_rows rnd_records= s->found_records; /* @@ -4460,13 +4479,15 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count, parts of the row from any of the used index. This is because table scans uses index and we would not win anything by using a table scan. + (see comment in best_access_path() for more details on the below + condition) */ if ((records >= s->found_records || best > s->read_time) && !(s->quick && best_key && s->quick->index == best_key->key && best_max_key_part >= s->table->quick_key_parts[best_key->key]) && !((s->table->file->table_flags() & HA_TABLE_SCAN_ON_INDEX) && ! s->table->used_keys.is_clear_all() && best_key) && - !(s->table->force_index && best_key)) + !(s->table->force_index && best_key & !s->quick)) { // Check full join ha_rows rnd_records= s->found_records; /* From 9878a35a6a170720d7b09e55790f2e189bb1d636 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Jan 2006 11:11:16 +0300 Subject: [PATCH 61/68] Fix typo bug in previous cset --- sql/sql_select.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 4a31a297c25..e8f2cb2c6a0 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -4487,7 +4487,7 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count, best_max_key_part >= s->table->quick_key_parts[best_key->key]) && !((s->table->file->table_flags() & HA_TABLE_SCAN_ON_INDEX) && ! s->table->used_keys.is_clear_all() && best_key) && - !(s->table->force_index && best_key & !s->quick)) + !(s->table->force_index && best_key && !s->quick)) { // Check full join ha_rows rnd_records= s->found_records; /* From cd1f75e9cb3aeb61c31a739db515065bbe6f4df4 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Jan 2006 13:08:49 +0400 Subject: [PATCH 62/68] ctype_utf8.result: After merge fix: fixing order of results. mysql-test/r/ctype_utf8.result: After merge fix: fixing order of results. --- mysql-test/r/ctype_utf8.result | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index fee561941f0..b2a22036cb5 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -1058,6 +1058,14 @@ char(a) 1 2 drop table t1; +CREATE TABLE t1 (t TINYTEXT CHARACTER SET utf8); +INSERT INTO t1 VALUES(REPEAT('a', 100)); +CREATE TEMPORARY TABLE t2 SELECT COALESCE(t) AS bug FROM t1; +SELECT LENGTH(bug) FROM t2; +LENGTH(bug) +100 +DROP TABLE t2; +DROP TABLE t1; CREATE TABLE t1(id varchar(20) NOT NULL) DEFAULT CHARSET=utf8; INSERT INTO t1 VALUES ('xxx'), ('aa'), ('yyy'), ('aa'); SELECT id FROM t1; @@ -1167,11 +1175,3 @@ set @a:=null; execute my_stmt using @a; a b drop table if exists t1; -CREATE TABLE t1 (t TINYTEXT CHARACTER SET utf8); -INSERT INTO t1 VALUES(REPEAT('a', 100)); -CREATE TEMPORARY TABLE t2 SELECT COALESCE(t) AS bug FROM t1; -SELECT LENGTH(bug) FROM t2; -LENGTH(bug) -100 -DROP TABLE t2; -DROP TABLE t1; From 46fdcba4f13ad54cb617dd3a649ee02f64bb8652 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Jan 2006 16:05:46 +0400 Subject: [PATCH 63/68] sql_show.cc: after-merge fix for bug#15581 COALESCE function truncates mutli-byte TINYTEXT values sql/sql_show.cc: after-merge fix for bug#15581 COALESCE function truncates mutli-byte TINYTEXT values , --- sql/sql_show.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sql/sql_show.cc b/sql/sql_show.cc index d15df686e40..59008b1b77f 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -2623,12 +2623,15 @@ static int get_schema_column_record(THD *thd, struct st_table_list *tables, field->real_type() == MYSQL_TYPE_VARCHAR || // For varbinary type field->real_type() == MYSQL_TYPE_STRING) // For binary type { + uint32 octet_max_length= field->max_length(); + if (octet_max_length != (uint32) 4294967295U) + octet_max_length /= field->charset()->mbmaxlen; longlong char_max_len= is_blob ? - (longlong) field->max_length() / field->charset()->mbminlen : - (longlong) field->max_length() / field->charset()->mbmaxlen; + (longlong) octet_max_length / field->charset()->mbminlen : + (longlong) octet_max_length / field->charset()->mbmaxlen; table->field[8]->store(char_max_len, TRUE); table->field[8]->set_notnull(); - table->field[9]->store((longlong) field->max_length(), TRUE); + table->field[9]->store((longlong) octet_max_length, TRUE); table->field[9]->set_notnull(); } From 2946f9a64f664293010777e422e7b66058ce323a Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Jan 2006 15:10:12 +0200 Subject: [PATCH 64/68] NetWare specific change to increase thread stack size. Changes to Netware specific mysqld_safe.c include/config-netware.h: NetWare specific change to increase thread stack size. innobase/os/os0thread.c: NetWare specific change to increase thread stack size. netware/mysqld_safe.c: NetWare specific change to make multiple mysqld_safe instances work when called through a NCF file. sql/mysqld.cc: NetWare specific change to increase thread stack size. --- include/config-netware.h | 3 +++ innobase/os/os0thread.c | 9 +++++++++ netware/mysqld_safe.c | 42 ++++++++++++++-------------------------- sql/mysqld.cc | 5 +++++ 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/include/config-netware.h b/include/config-netware.h index e07e972ba4b..43ee05e39ee 100644 --- a/include/config-netware.h +++ b/include/config-netware.h @@ -92,6 +92,9 @@ extern "C" { /* On NetWare, stack grows towards lower address*/ #define STACK_DIRECTION -1 +/* On NetWare, we need to set stack size for threads, otherwise default 16K is used */ +#define NW_THD_STACKSIZE 65536 + /* On NetWare, to fix the problem with the deletion of open files */ #define CANT_DELETE_OPEN_FILES 1 diff --git a/innobase/os/os0thread.c b/innobase/os/os0thread.c index 59d0fdbd8c9..cb72310f23d 100644 --- a/innobase/os/os0thread.c +++ b/innobase/os/os0thread.c @@ -147,6 +147,15 @@ os_thread_create( "InnoDB: Error: pthread_attr_setstacksize returned %d\n", ret); exit(1); } +#endif +#ifdef __NETWARE__ + ret = pthread_attr_setstacksize(&attr, + (size_t) NW_THD_STACKSIZE); + if (ret) { + fprintf(stderr, + "InnoDB: Error: pthread_attr_setstacksize returned %d\n", ret); + exit(1); + } #endif os_mutex_enter(os_sync_mutex); os_thread_count++; diff --git a/netware/mysqld_safe.c b/netware/mysqld_safe.c index dbb49882140..5f65e2f45b7 100644 --- a/netware/mysqld_safe.c +++ b/netware/mysqld_safe.c @@ -252,51 +252,39 @@ void finish_defaults() ******************************************************************************/ void read_defaults(arg_list_t *pal) { - arg_list_t al; - char defaults_file[PATH_MAX]; char mydefaults[PATH_MAX]; + char mydefaults_command[3*PATH_MAX]; char line[PATH_MAX]; FILE *fp; - // defaults output file - snprintf(defaults_file, PATH_MAX, "%s/bin/defaults.out", basedir); - remove(defaults_file); - - // mysqladmin file + // my_print_defaults file snprintf(mydefaults, PATH_MAX, "%s/bin/my_print_defaults", basedir); - // args - init_args(&al); - add_arg(&al, mydefaults); - if (default_option[0]) add_arg(&al, default_option); - add_arg(&al, "mysqld"); - add_arg(&al, "server"); - add_arg(&al, "mysqld_safe"); - add_arg(&al, "safe_mysqld"); - - spawn(mydefaults, &al, TRUE, NULL, defaults_file, NULL); - - free_args(&al); - + // args to my_print_defaults + if (default_option[0]) + { + snprintf(mydefaults_command, 3*PATH_MAX, "%s %s mysqld server mysqld_safe safe_mysqld", mydefaults, default_option); + } + else + { + snprintf(mydefaults_command, 3*PATH_MAX, "%s mysqld server mysqld_safe safe_mysqld", mydefaults); + } // gather defaults - if((fp = fopen(defaults_file, "r")) != NULL) + if((fp = popen(mydefaults_command, "r")) != NULL) { while(fgets(line, PATH_MAX, fp)) { char *p; // remove end-of-line character - if ((p = strrchr(line, '\n')) != NULL) *p = '\0'; + if ((p = strrchr(line, '\n')) != NULL) + *p = '\0'; // add the option as an argument add_arg(pal, line); } - - fclose(fp); + pclose(fp); } - - // remove file - remove(defaults_file); } /****************************************************************************** diff --git a/sql/mysqld.cc b/sql/mysqld.cc index f7df7233795..00bcdbf7132 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2401,6 +2401,11 @@ You should consider changing lower_case_table_names to 1 or 2", thread_stack= stack_size; } } +#endif +#ifdef __NETWARE__ + /* Increasing stacksize of threads on NetWare */ + + pthread_attr_setstacksize(&connection_attrib, NW_THD_STACKSIZE); #endif if (!(opt_specialflag & SPECIAL_NO_PRIOR)) my_pthread_attr_setprio(&connection_attrib,WAIT_PRIOR); From 7b77b4c7bb23195f712f8fe6141082e0c468b042 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Jan 2006 18:19:57 +0100 Subject: [PATCH 65/68] Use "test ! -s" to check that file does not exist --- mysql-test/t/mysqltest.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index ee309fbd7c9..5cf49185c30 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -1037,7 +1037,7 @@ drop table t1; --error 1 --exec $MYSQL_TEST --record -x $MYSQL_TEST_DIR/var/tmp/bug11731.sql -R $MYSQL_TEST_DIR/var/tmp/bug11731.out 2>&1 # The .out file should be non existent ---exec test ! -e $MYSQL_TEST_DIR/var/tmp/bug11731.out +--exec test ! -s $MYSQL_TEST_DIR/var/tmp/bug11731.out drop table t1; From 5c28e9c8d0f79931e39c9ad1eb51434328e702cd Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Jan 2006 20:31:00 +0200 Subject: [PATCH 66/68] Fix for Netware build. --- netware/BUILD/compile-linux-tools | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netware/BUILD/compile-linux-tools b/netware/BUILD/compile-linux-tools index 14422ea5a3f..fab92b8d4df 100755 --- a/netware/BUILD/compile-linux-tools +++ b/netware/BUILD/compile-linux-tools @@ -57,7 +57,7 @@ make cp extra/comp_err extra/comp_err.linux cp libmysql/conf_to_src libmysql/conf_to_src.linux #cp libmysql_r/conf_to_src libmysql_r/conf_to_src.linux -cp sql/gen_lex_hash sql/gen_lex_hash.linux +cp sql/.libs/gen_lex_hash sql/gen_lex_hash.linux cp strings/conf_to_src strings/conf_to_src.linux # Delete mysql_version.h From 0f4962c338716bbc72ba8dd7102052fcbcfd4f80 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Jan 2006 20:49:47 +0200 Subject: [PATCH 67/68] Fixed a bug in merge. --- sql/sql_handler.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index 3370a0a1957..e9e1e79daaf 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -426,9 +426,7 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables, { if (table->query_id != thd->query_id) cond->cleanup(); // File was reopened - if ((!cond->fixed && - cond->fix_fields(thd, tables, &cond)) || cond->check_cols(1)) - goto err0; + goto err0; } if (keyname) From c12a3dfefd29b3bb4a93fee4778e0e94b1e00871 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 13 Jan 2006 01:51:56 +0300 Subject: [PATCH 68/68] Fix for bug #12198 "Temporary table aliasing does not work inside stored functions". We should ignore alias when we check if table was already marked as temporary when we calculate set of tables to be prelocked. Otherwise we will erroneously treat tables which are used in same routine and have same name but different alias as non-temporary. mysql-test/r/sp.result: Added test for bug #12198 "Temporary table aliasing does not work inside stored functions" and other tests which cover handling of temporary tables in prelocked mode. mysql-test/t/sp.test: Added test for bug #12198 "Temporary table aliasing does not work inside stored functions" and other tests which cover handling of temporary tables in prelocked mode. sql/sp_head.cc: sp_head::merge_table_list(): We should ignore alias when we check if table was already marked as temporary when we calculate set of tables to be prelocked. Otherwise we will erroneously treat tables which are used in same routine and have same name but different alias as non-temporary. --- mysql-test/r/sp.result | 67 +++++++++++++++++++++++++++++++++++ mysql-test/t/sp.test | 80 ++++++++++++++++++++++++++++++++++++++++-- sql/sp_head.cc | 31 +++++++++++----- 3 files changed, 168 insertions(+), 10 deletions(-) diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 231ca329f3d..6d231b35a89 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -918,6 +918,11 @@ drop function if exists f5| drop function if exists f6| drop function if exists f7| drop function if exists f8| +drop function if exists f9| +drop function if exists f10| +drop function if exists f11| +drop function if exists f12_1| +drop function if exists f12_2| drop view if exists v0| drop view if exists v1| drop view if exists v2| @@ -1087,6 +1092,62 @@ ERROR HY000: Table 't1' was not locked with LOCK TABLES select f4()| ERROR HY000: Table 't2' was not locked with LOCK TABLES unlock tables| +create function f9() returns int +begin +declare a, b int; +drop temporary table if exists t3; +create temporary table t3 (id int); +insert into t3 values (1), (2), (3); +set a:= (select count(*) from t3); +set b:= (select count(*) from t3 t3_alias); +return a + b; +end| +select f9()| +f9() +6 +Warnings: +Note 1051 Unknown table 't3' +select f9() from t1 limit 1| +f9() +6 +create function f10() returns int +begin +drop temporary table if exists t3; +create temporary table t3 (id int); +insert into t3 select id from t4; +return (select count(*) from t3); +end| +select f10()| +ERROR 42S02: Table 'test.t4' doesn't exist +create table t4 as select 1 as id| +select f10()| +f10() +1 +create function f11() returns int +begin +drop temporary table if exists t3; +create temporary table t3 (id int); +insert into t3 values (1), (2), (3); +return (select count(*) from t3 as a, t3 as b); +end| +select f11()| +ERROR HY000: Can't reopen table: 'a' +select f11() from t1| +ERROR HY000: Can't reopen table: 'a' +create function f12_1() returns int +begin +drop temporary table if exists t3; +create temporary table t3 (id int); +insert into t3 values (1), (2), (3); +return f12_2(); +end| +create function f12_2() returns int +return (select count(*) from t3)| +drop temporary table t3| +select f12_1()| +ERROR 42S02: Table 'test.t3' doesn't exist +select f12_1() from t1 limit 1| +ERROR 42S02: Table 'test.t3' doesn't exist drop function f0| drop function f1| drop function f2| @@ -1096,11 +1157,17 @@ drop function f5| drop function f6| drop function f7| drop function f8| +drop function f9| +drop function f10| +drop function f11| +drop function f12_1| +drop function f12_2| drop view v0| drop view v1| drop view v2| delete from t1 | delete from t2 | +drop table t4| drop table if exists fac| create table fac (n int unsigned not null primary key, f bigint unsigned)| drop procedure if exists ifac| diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index fba3cfcbfbc..6aa27969299 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -1154,6 +1154,11 @@ drop function if exists f5| drop function if exists f6| drop function if exists f7| drop function if exists f8| +drop function if exists f9| +drop function if exists f10| +drop function if exists f11| +drop function if exists f12_1| +drop function if exists f12_2| drop view if exists v0| drop view if exists v1| drop view if exists v2| @@ -1233,8 +1238,6 @@ create function f7() returns int select f6()| select id, f6() from t1| -# TODO Test temporary table handling - # # Let us test how new locking work with views # @@ -1318,6 +1321,73 @@ select * from v1, t1| select f4()| unlock tables| +# Tests for handling of temporary tables in functions. +# +# Unlike for permanent tables we should be able to create, use +# and drop such tables in functions. +# +# Simplest function using temporary table. It is also test case for bug +# #12198 "Temporary table aliasing does not work inside stored functions" +create function f9() returns int +begin + declare a, b int; + drop temporary table if exists t3; + create temporary table t3 (id int); + insert into t3 values (1), (2), (3); + set a:= (select count(*) from t3); + set b:= (select count(*) from t3 t3_alias); + return a + b; +end| +# This will emit warning as t3 was not existing before. +select f9()| +select f9() from t1 limit 1| + +# Function which uses both temporary and permanent tables. +create function f10() returns int +begin + drop temporary table if exists t3; + create temporary table t3 (id int); + insert into t3 select id from t4; + return (select count(*) from t3); +end| +# Check that we don't ignore completely tables used in function +--error ER_NO_SUCH_TABLE +select f10()| +create table t4 as select 1 as id| +select f10()| + +# Practical cases which we don't handle well (yet) +# +# Function which does not work because of well-known and documented +# limitation of MySQL. We can't use the several instances of the +# same temporary table in statement. +create function f11() returns int +begin + drop temporary table if exists t3; + create temporary table t3 (id int); + insert into t3 values (1), (2), (3); + return (select count(*) from t3 as a, t3 as b); +end| +--error ER_CANT_REOPEN_TABLE +select f11()| +--error ER_CANT_REOPEN_TABLE +select f11() from t1| +# We don't handle temporary tables used by nested functions well +create function f12_1() returns int +begin + drop temporary table if exists t3; + create temporary table t3 (id int); + insert into t3 values (1), (2), (3); + return f12_2(); +end| +create function f12_2() returns int + return (select count(*) from t3)| +# We need clean start to get error +drop temporary table t3| +--error ER_NO_SUCH_TABLE +select f12_1()| +--error ER_NO_SUCH_TABLE +select f12_1() from t1 limit 1| # Cleanup drop function f0| @@ -1329,11 +1399,17 @@ drop function f5| drop function f6| drop function f7| drop function f8| +drop function f9| +drop function f10| +drop function f11| +drop function f12_1| +drop function f12_2| drop view v0| drop view v1| drop view v2| delete from t1 | delete from t2 | +drop table t4| # End of non-bug tests diff --git a/sql/sp_head.cc b/sql/sp_head.cc index a6e88c08789..8d0212a31da 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -2992,7 +2992,14 @@ sp_restore_security_context(THD *thd, Security_context *backup) typedef struct st_sp_table { - LEX_STRING qname; /* Multi-set key: db_name\0table_name\0alias\0 */ + /* + Multi-set key: + db_name\0table_name\0alias\0 - for normal tables + db_name\0table_name\0 - for temporary tables + Note that in both cases we don't take last '\0' into account when + we count length of key. + */ + LEX_STRING qname; uint db_length, table_name_length; bool temp; /* true if corresponds to a temporary table */ thr_lock_type lock_type; /* lock type used for prelocking */ @@ -3062,10 +3069,14 @@ sp_head::merge_table_list(THD *thd, TABLE_LIST *table, LEX *lex_for_tmp_check) tname[tlen]= '\0'; /* - It is safe to store pointer to table list elements in hash, - since they are supposed to have the same lifetime. + We ignore alias when we check if table was already marked as temporary + (and therefore should not be prelocked). Otherwise we will erroneously + treat table with same name but with different alias as non-temporary. */ - if ((tab= (SP_TABLE *)hash_search(&m_sptabs, (byte *)tname, tlen))) + if ((tab= (SP_TABLE *)hash_search(&m_sptabs, (byte *)tname, tlen)) || + ((tab= (SP_TABLE *)hash_search(&m_sptabs, (byte *)tname, + tlen - alen - 1)) && + tab->temp)) { if (tab->lock_type < table->lock_type) tab->lock_type= table->lock_type; // Use the table with the highest lock type @@ -3077,14 +3088,18 @@ sp_head::merge_table_list(THD *thd, TABLE_LIST *table, LEX *lex_for_tmp_check) { if (!(tab= (SP_TABLE *)thd->calloc(sizeof(SP_TABLE)))) return FALSE; - tab->qname.length= tlen; - tab->qname.str= (char*) thd->memdup(tname, tab->qname.length + 1); - if (!tab->qname.str) - return FALSE; if (lex_for_tmp_check->sql_command == SQLCOM_CREATE_TABLE && lex_for_tmp_check->query_tables == table && lex_for_tmp_check->create_info.options & HA_LEX_CREATE_TMP_TABLE) + { tab->temp= TRUE; + tab->qname.length= tlen - alen - 1; + } + else + tab->qname.length= tlen; + tab->qname.str= (char*) thd->memdup(tname, tab->qname.length + 1); + if (!tab->qname.str) + return FALSE; tab->table_name_length= table->table_name_length; tab->db_length= table->db_length; tab->lock_type= table->lock_type;