diff options
author | unknown <Sinisa@sinisa.nasamreza.org> | 2004-05-17 13:47:51 +0300 |
---|---|---|
committer | unknown <Sinisa@sinisa.nasamreza.org> | 2004-05-17 13:47:51 +0300 |
commit | 0f8cd01a1ef88f8eeeb87bf9437a807d4ab046af (patch) | |
tree | 031f7cce64007f80ef71d60f887e2101a1760346 | |
parent | d146ea1a0f442e2e3410763051a752f81f03525e (diff) | |
parent | 1915bfebcb9005102c72028221bb89aa5f0204e4 (diff) | |
download | mariadb-git-0f8cd01a1ef88f8eeeb87bf9437a807d4ab046af.tar.gz |
Merge sinisa@bk-internal.mysql.com:/home/bk/mysql-4.1
into sinisa.nasamreza.org:/mnt/work/mysql-4.1
78 files changed, 700 insertions, 565 deletions
diff --git a/client/mysql.cc b/client/mysql.cc index ddc6441f08a..cf80a5594e4 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -2404,6 +2404,10 @@ static int com_shell(String *buffer, char *line __attribute__((unused))) { char *shell_cmd; + + /* Skip space from line begin */ + while (isspace(*line)) + line++; if (!(shell_cmd = strchr(line, ' '))) { put_info("Usage: \\! shell-command", INFO_ERROR); diff --git a/client/mysqldump.c b/client/mysqldump.c index 20792f8c025..97ae0070e04 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -1264,18 +1264,32 @@ static char *field_escape(char *to,const char *from,uint length) } /* field_escape */ +static char *alloc_query_str(ulong size) +{ + char *query; + + if (!(query= (char*) my_malloc(size, MYF(MY_WME)))) + { + ignore_errors= 0; /* Fatal error */ + safe_exit(EX_MYSQLERR); /* Force exit */ + } + return query; +} + /* ** dumpTable saves database contents as a series of INSERT statements. */ static void dumpTable(uint numFields, char *table) { - char query[QUERY_LENGTH], *end, buff[256],table_buff[NAME_LEN+3]; + char query_buf[QUERY_LENGTH], *end, buff[256],table_buff[NAME_LEN+3]; char *result_table, table_buff2[NAME_LEN*2+3], *opt_quoted_table; + char *query= query_buf; MYSQL_RES *res; MYSQL_FIELD *field; MYSQL_ROW row; ulong rownr, row_break, total_length, init_length; const char *table_type; + int error= 0; result_table= quote_name(table,table_buff, 1); opt_quoted_table= quote_name(table, table_buff2, 0); @@ -1321,8 +1335,11 @@ static void dumpTable(uint numFields, char *table) sprintf(buff," FROM %s", result_table); end= strmov(end,buff); if (where) - end= strxmov(end, " WHERE ",where,NullS); - if (mysql_query(sock, query)) + { + query= alloc_query_str((ulong) (strlen(where) + (end - query) + 10)); + end= strxmov(query, query_buf, " WHERE ", where, NullS); + } + if (mysql_real_query(sock, query, (uint) (end - query))) { DBerror(sock, "when executing 'SELECT INTO OUTFILE'"); return; @@ -1339,14 +1356,16 @@ static void dumpTable(uint numFields, char *table) { if (!opt_xml && opt_comments) fprintf(md_result_file,"-- WHERE: %s\n",where); - strxmov(strend(query), " WHERE ",where,NullS); + query= alloc_query_str((ulong) (strlen(where) + strlen(query) + 10)); + strxmov(query, query_buf, " WHERE ", where, NullS); } if (!opt_xml && !opt_compact) fputs("\n", md_result_file); if (mysql_query(sock, query)) { DBerror(sock, "when retrieving data from server"); - return; + error= EX_CONSCHECK; + goto err; } if (quick) res=mysql_use_result(sock); @@ -1355,7 +1374,8 @@ static void dumpTable(uint numFields, char *table) if (!res) { DBerror(sock, "when retrieving data from server"); - return; + error= EX_CONSCHECK; + goto err; } if (verbose) fprintf(stderr, "-- Retrieving rows...\n"); @@ -1363,8 +1383,8 @@ static void dumpTable(uint numFields, char *table) { fprintf(stderr,"%s: Error in field count for table: %s ! Aborting.\n", my_progname, result_table); - safe_exit(EX_CONSCHECK); - return; + error= EX_CONSCHECK; + goto err; } if (opt_disable_keys) @@ -1402,8 +1422,8 @@ static void dumpTable(uint numFields, char *table) sprintf(query,"%s: Not enough fields from table %s! Aborting.\n", my_progname, result_table); fputs(query,stderr); - safe_exit(EX_CONSCHECK); - return; + error= EX_CONSCHECK; + goto err; } if (extended_insert) { @@ -1422,7 +1442,8 @@ static void dumpTable(uint numFields, char *table) if (dynstr_realloc(&extended_row,length * 2+2)) { fputs("Aborting dump (out of memory)",stderr); - safe_exit(EX_EOM); + error= EX_EOM; + goto err; } dynstr_append(&extended_row,"'"); extended_row.length += @@ -1458,7 +1479,8 @@ static void dumpTable(uint numFields, char *table) else if (dynstr_append(&extended_row,"NULL")) { fputs("Aborting dump (out of memory)",stderr); - safe_exit(EX_EOM); + error= EX_EOM; + goto err; } } else @@ -1552,8 +1574,8 @@ static void dumpTable(uint numFields, char *table) result_table, rownr); fputs(query,stderr); - safe_exit(EX_CONSCHECK); - return; + error= EX_CONSCHECK; + goto err; } if (opt_lock) fputs("UNLOCK TABLES;\n", md_result_file); @@ -1563,7 +1585,16 @@ static void dumpTable(uint numFields, char *table) if (opt_autocommit) fprintf(md_result_file, "commit;\n"); mysql_free_result(res); - } + if (query != query_buf) + my_free(query, MYF(MY_ALLOW_ZERO_PTR)); + } + return; + +err: + if (query != query_buf) + my_free(query, MYF(MY_ALLOW_ZERO_PTR)); + safe_exit(error); + return; } /* dumpTable */ diff --git a/client/mysqltest.c b/client/mysqltest.c index be5dac1c9d9..2cd395a02b8 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -1097,7 +1097,7 @@ int do_sync_with_master2(const char* p) MYSQL_ROW row; MYSQL* mysql = &cur_con->mysql; char query_buf[FN_REFLEN+128]; - int offset = 0; + int offset= 0, tries= 0; int rpl_parse; if (!master_pos.file[0]) @@ -1112,6 +1112,9 @@ int do_sync_with_master2(const char* p) sprintf(query_buf, "select master_pos_wait('%s', %ld)", master_pos.file, master_pos.pos + offset); + +wait_for_position: + if (mysql_query(mysql, query_buf)) die("line %u: failed in %s: %d: %s", start_lineno, query_buf, mysql_errno(mysql), mysql_error(mysql)); @@ -1122,8 +1125,20 @@ int do_sync_with_master2(const char* p) if (!(row = mysql_fetch_row(res))) die("line %u: empty result in %s", start_lineno, query_buf); if (!row[0]) - die("line %u: could not sync with master ('%s' returned NULL)", - start_lineno, query_buf); + { + /* + It may be that the slave SQL thread has not started yet, though START + SLAVE has been issued ? + */ + if (tries++ == 3) + { + die("line %u: could not sync with master ('%s' returned NULL)", + start_lineno, query_buf); + } + sleep(1); /* So at most we will wait 3 seconds and make 4 tries */ + mysql_free_result(res); + goto wait_for_position; + } mysql_free_result(res); last_result=0; if (rpl_parse) diff --git a/heap/hp_hash.c b/heap/hp_hash.c index d040f37aea0..38ed581fe58 100644 --- a/heap/hp_hash.c +++ b/heap/hp_hash.c @@ -29,19 +29,15 @@ hp_rb_records_in_range() info HEAP handler inx Index to use - start_key Start of range. Null pointer if from first key - start_key_len Length of start key - start_search_flag Flag if start key should be included or not - end_key End of range. Null pointer if to last key - end_key_len Length of end key - end_search_flag Flag if start key should be included or not + min_key Min key. Is = 0 if no min range + max_key Max key. Is = 0 if no max range NOTES - start_search_flag can have one of the following values: + min_key.flag can have one of the following values: HA_READ_KEY_EXACT Include the key in the range HA_READ_AFTER_KEY Don't include key in range - end_search_flag can have one of the following values: + max_key.flag can have one of the following values: HA_READ_BEFORE_KEY Don't include key in range HA_READ_AFTER_KEY Include all 'end_key' values in the range @@ -52,11 +48,8 @@ the range. */ -ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, const byte *start_key, - uint start_key_len, - enum ha_rkey_function start_search_flag, - const byte *end_key, uint end_key_len, - enum ha_rkey_function end_search_flag) +ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, key_range *min_key, + key_range *max_key) { ha_rows start_pos, end_pos; HP_KEYDEF *keyinfo= info->s->keydef + inx; @@ -67,12 +60,12 @@ ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, const byte *start_key, info->lastinx= inx; custom_arg.keyseg= keyinfo->seg; custom_arg.search_flag= SEARCH_FIND | SEARCH_SAME; - if (start_key) + if (min_key) { custom_arg.key_length= hp_rb_pack_key(keyinfo, (uchar*) info->recbuf, - (uchar*) start_key, - start_key_len); - start_pos= tree_record_pos(rb_tree, info->recbuf, start_search_flag, + (uchar*) min_key->key, + min_key->length); + start_pos= tree_record_pos(rb_tree, info->recbuf, min_key->flag, &custom_arg); } else @@ -80,11 +73,12 @@ ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, const byte *start_key, start_pos= 0; } - if (end_key) + if (max_key) { custom_arg.key_length= hp_rb_pack_key(keyinfo, (uchar*) info->recbuf, - (uchar*) end_key, end_key_len); - end_pos= tree_record_pos(rb_tree, info->recbuf, end_search_flag, + (uchar*) max_key->key, + max_key->length); + end_pos= tree_record_pos(rb_tree, info->recbuf, max_key->flag, &custom_arg); } else @@ -100,12 +94,13 @@ ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, const byte *start_key, (end_pos == start_pos ? (ha_rows) 1 : end_pos - start_pos)); } + /* Search after a record based on a key */ /* Sets info->current_ptr to found record */ /* next_flag: Search=0, next=1, prev =2, same =3 */ byte *hp_search(HP_INFO *info, HP_KEYDEF *keyinfo, const byte *key, - uint nextflag) + uint nextflag) { reg1 HASH_INFO *pos,*prev_ptr; int flag; diff --git a/include/heap.h b/include/heap.h index b536937c8c0..63f2abbabc7 100644 --- a/include/heap.h +++ b/include/heap.h @@ -182,11 +182,8 @@ extern int heap_disable_indexes(HP_INFO *info); extern int heap_enable_indexes(HP_INFO *info); extern int heap_indexes_are_disabled(HP_INFO *info); extern void heap_update_auto_increment(HP_INFO *info, const byte *record); -ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, const byte *start_key, - uint start_key_len, - enum ha_rkey_function start_search_flag, - const byte *end_key, uint end_key_len, - enum ha_rkey_function end_search_flag); +ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, key_range *min_key, + key_range *max_key); int heap_rkey(HP_INFO *info, byte *record, int inx, const byte *key, uint key_len, enum ha_rkey_function find_flag); extern gptr heap_find(HP_INFO *info,int inx,const byte *key); diff --git a/include/my_base.h b/include/my_base.h index 4a2f3f85083..f912cb4278c 100644 --- a/include/my_base.h +++ b/include/my_base.h @@ -349,6 +349,16 @@ enum data_file_type { STATIC_RECORD,DYNAMIC_RECORD,COMPRESSED_RECORD }; +/* For key ranges */ + +typedef struct st_key_range +{ + const byte *key; + uint length; + enum ha_rkey_function flag; +} key_range; + + /* For number of records */ #ifdef BIG_TABLES #define rows2double(A) ulonglong2double(A) diff --git a/include/my_bitmap.h b/include/my_bitmap.h index 5b3da011f54..a4511bf3414 100644 --- a/include/my_bitmap.h +++ b/include/my_bitmap.h @@ -55,6 +55,12 @@ extern void bitmap_set_bit(MY_BITMAP *map, uint bitmap_bit); extern void bitmap_set_prefix(MY_BITMAP *map, uint prefix_size); extern void bitmap_subtract(MY_BITMAP *map, const MY_BITMAP *map2); extern void bitmap_union(MY_BITMAP *map, const MY_BITMAP *map2); + +/* Fast, not thread safe, bitmap functions */ +#define bitmap_fast_set_bit(MAP, BIT) (MAP)->bitmap[(BIT) / 8] |= (1 << ((BIT) & 7)) +#define bitmap_fast_clear_bit(MAP, BIT) (MAP)->bitmap[(BIT) / 8] &= ~ (1 << ((BIT) & 7)) +#define bitmap_fast_is_set(MAP, BIT) (MAP)->bitmap[(BIT) / 8] & (1 << ((BIT) & 7)) + #ifdef __cplusplus } #endif diff --git a/include/myisam.h b/include/myisam.h index 93e2dc15574..c99e9a30b08 100644 --- a/include/myisam.h +++ b/include/myisam.h @@ -231,10 +231,7 @@ extern int mi_extra(struct st_myisam_info *file, enum ha_extra_function function, void *extra_arg); extern ha_rows mi_records_in_range(struct st_myisam_info *info,int inx, - const byte *start_key,uint start_key_len, - enum ha_rkey_function start_search_flag, - const byte *end_key,uint end_key_len, - enum ha_rkey_function end_search_flag); + key_range *min_key, key_range *max_key); extern int mi_log(int activate_log); extern int mi_is_changed(struct st_myisam_info *info); extern int mi_delete_all_rows(struct st_myisam_info *info); diff --git a/include/myisammrg.h b/include/myisammrg.h index 8b09e1a9231..de8a36c2d0a 100644 --- a/include/myisammrg.h +++ b/include/myisammrg.h @@ -101,10 +101,7 @@ extern int myrg_extra(MYRG_INFO *file,enum ha_extra_function function, void *extra_arg); extern void myrg_extrafunc(MYRG_INFO *info,invalidator_by_filename inv); extern ha_rows myrg_records_in_range(MYRG_INFO *info,int inx, - const byte *start_key,uint start_key_len, - enum ha_rkey_function start_search_flag, - const byte *end_key,uint end_key_len, - enum ha_rkey_function end_search_flag); + key_range *min_key, key_range *max_key); extern ulonglong myrg_position(MYRG_INFO *info); #ifdef __cplusplus diff --git a/innobase/btr/btr0btr.c b/innobase/btr/btr0btr.c index 8388009dc9c..09f5c66f687 100644 --- a/innobase/btr/btr0btr.c +++ b/innobase/btr/btr0btr.c @@ -883,7 +883,7 @@ btr_page_reorganize_low( fprintf(stderr, "InnoDB: Error: page old data size %lu new data size %lu\n" "InnoDB: Error: page old max ins size %lu new max ins size %lu\n" -"InnoDB: Make a detailed bug report and send it to mysql@lists.mysql.com\n", +"InnoDB: Submit a detailed bug report to http://bugs.mysql.com\n", (unsigned long) data_size1, (unsigned long) data_size2, (unsigned long) max_ins_size1, (unsigned long) max_ins_size2); diff --git a/innobase/dict/dict0dict.c b/innobase/dict/dict0dict.c index b22d93d6bd8..c9e3ac5ec66 100644 --- a/innobase/dict/dict0dict.c +++ b/innobase/dict/dict0dict.c @@ -4287,5 +4287,5 @@ dict_index_name_print( fputs("index ", file); ut_print_name(file, index->name); fputs(" of table ", file); - ut_print_name(stderr, index->table_name); + ut_print_name(file, index->table_name); } diff --git a/innobase/dict/dict0load.c b/innobase/dict/dict0load.c index abb06b15ea7..bf8b4582f63 100644 --- a/innobase/dict/dict0load.c +++ b/innobase/dict/dict0load.c @@ -849,7 +849,7 @@ dict_load_table( "InnoDB: the foreign key table or the referenced table!\n" "InnoDB: The data dictionary of InnoDB is corrupt. You may need to drop\n" "InnoDB: and recreate the foreign key table or the referenced table.\n" -"InnoDB: Send a detailed bug report to mysql@lists.mysql.com\n" +"InnoDB: Submit a detailed bug report to http://bugs.mysql.com\n" "InnoDB: Latest foreign key error printout:\n%s\n", dict_foreign_err_buf); mutex_exit(&dict_foreign_err_mutex); diff --git a/innobase/ibuf/ibuf0ibuf.c b/innobase/ibuf/ibuf0ibuf.c index 7dc0bd98001..9246bb03138 100644 --- a/innobase/ibuf/ibuf0ibuf.c +++ b/innobase/ibuf/ibuf0ibuf.c @@ -2770,7 +2770,7 @@ ibuf_insert_to_index_page( fprintf(stderr, "Bitmap bits %lu\n", (ulong) old_bits); fputs( -"InnoDB: Send a detailed bug report to mysql@lists.mysql.com!\n", stderr); +"InnoDB: Submit a detailed bug report to http://bugs.mysql.com\n", stderr); } } } @@ -2833,7 +2833,7 @@ ibuf_delete_rec( if (!success) { fprintf(stderr, - "InnoDB: ERROR: Send the output to mysql@lists.mysql.com\n" + "InnoDB: ERROR: Submit the output to http://bugs.mysql.com\n" "InnoDB: ibuf cursor restoration fails!\n" "InnoDB: ibuf record inserted to page %lu\n", (ulong) page_no); fflush(stderr); @@ -3025,8 +3025,7 @@ ibuf_merge_or_delete_for_page( "InnoDB: We try to resolve the problem by skipping the insert buffer\n" "InnoDB: merge for this page. Please run CHECK TABLE on your tables\n" "InnoDB: to determine if they are corrupt after this.\n\n" -"InnoDB: Please make a detailed bug report and send it to\n" -"InnoDB: mysql@lists.mysql.com\n\n", +"InnoDB: Please submit a detailed bug report to http://bugs.mysql.com\n\n", (ulong) page_no, (ulong) fil_page_get_type(page)); } diff --git a/innobase/include/trx0trx.h b/innobase/include/trx0trx.h index 71269cb1e4e..07d5e5a8215 100644 --- a/innobase/include/trx0trx.h +++ b/innobase/include/trx0trx.h @@ -275,13 +275,15 @@ trx_commit_step( que_thr_t* thr); /* in: query thread */ /************************************************************************** Prints info about a transaction to the standard output. The caller must -own the kernel mutex. */ +own the kernel mutex and must have called +innobase_mysql_prepare_print_arbitrary_thd(), unless he knows that MySQL or +InnoDB cannot meanwhile change the info printed here. */ void trx_print( /*======*/ FILE* f, /* in: output stream */ - trx_t* trx); /* in: transaction */ + trx_t* trx); /* in: transaction */ /* Signal to a transaction */ diff --git a/innobase/lock/lock0lock.c b/innobase/lock/lock0lock.c index 056d502e858..223d9af78d1 100644 --- a/innobase/lock/lock0lock.c +++ b/innobase/lock/lock0lock.c @@ -17,6 +17,32 @@ Created 5/7/1996 Heikki Tuuri #include "dict0mem.h" #include "trx0sys.h" + +/* 2 function prototypes copied from ha_innodb.cc: */ + +/***************************************************************** +If you want to print a thd that is not associated with the current thread, +you must call this function before reserving the InnoDB kernel_mutex, to +protect MySQL from setting thd->query NULL. If you print a thd of the current +thread, we know that MySQL cannot modify thd->query, and it is not necessary +to call this. Call innobase_mysql_end_print_arbitrary_thd() after you release +the kernel_mutex. +NOTE that /mysql/innobase/lock/lock0lock.c must contain the prototype for this +function! */ + +void +innobase_mysql_prepare_print_arbitrary_thd(void); +/*============================================*/ + +/***************************************************************** +Relases the mutex reserved by innobase_mysql_prepare_print_arbitrary_thd(). +NOTE that /mysql/innobase/lock/lock0lock.c must contain the prototype for this +function! */ + +void +innobase_mysql_end_print_arbitrary_thd(void); +/*========================================*/ + /* Restricts the length of search we will do in the waits-for graph of transactions */ #define LOCK_MAX_N_STEPS_IN_DEADLOCK_CHECK 1000000 @@ -1629,7 +1655,8 @@ lock_rec_enqueue_waiting( " InnoDB: Error: a record lock wait happens in a dictionary operation!\n" "InnoDB: Table name ", stderr); ut_print_name(stderr, index->table_name); - fputs(". Send a bug report to mysql@lists.mysql.com\n", + fputs(".\n" +"InnoDB: Submit a detailed bug report to http://bugs.mysql.com\n", stderr); } @@ -3269,7 +3296,8 @@ lock_table_enqueue_waiting( " InnoDB: Error: a table lock wait happens in a dictionary operation!\n" "InnoDB: Table name ", stderr); ut_print_name(stderr, table->name); - fputs(". Send a bug report to mysql@lists.mysql.com\n", + fputs(".\n" +"InnoDB: Submit a detailed bug report to http://bugs.mysql.com\n", stderr); } @@ -3975,6 +4003,11 @@ lock_print_info( ulint i; mtr_t mtr; + /* We must protect the MySQL thd->query field with a MySQL mutex, and + because the MySQL mutex must be reserved before the kernel_mutex of + InnoDB, we call innobase_mysql_prepare_print_arbitrary_thd() here. */ + + innobase_mysql_prepare_print_arbitrary_thd(); lock_mutex_enter_kernel(); if (lock_deadlock_found) { @@ -4038,6 +4071,7 @@ loop: if (trx == NULL) { lock_mutex_exit_kernel(); + innobase_mysql_end_print_arbitrary_thd(); ut_ad(lock_validate()); @@ -4102,6 +4136,7 @@ loop: if (load_page_first) { lock_mutex_exit_kernel(); + innobase_mysql_end_print_arbitrary_thd(); mtr_start(&mtr); @@ -4111,6 +4146,7 @@ loop: load_page_first = FALSE; + innobase_mysql_prepare_print_arbitrary_thd(); lock_mutex_enter_kernel(); goto loop; diff --git a/innobase/os/os0file.c b/innobase/os/os0file.c index 79185c30f79..1a158372563 100644 --- a/innobase/os/os0file.c +++ b/innobase/os/os0file.c @@ -387,15 +387,17 @@ os_file_lock( /*=========*/ /* out: 0 on success */ int fd, /* in: file descriptor */ - const char* name) /* in: file name */ + const char* name, /* in: file name */ + uint lock_type) /* in: lock_type */ { struct flock lk; - lk.l_type = F_WRLCK; + lk.l_type = lock_type; lk.l_whence = SEEK_SET; lk.l_start = lk.l_len = 0; if (fcntl(fd, F_SETLK, &lk) == -1) { fprintf(stderr, - "InnoDB: Unable to lock %s", name); + "InnoDB: Unable to lock %s with lock %d, error: %d", + name, lock_type, errno); perror (": fcntl"); close(fd); return(-1); @@ -862,7 +864,7 @@ try_again: goto try_again; } #ifdef USE_FILE_LOCK - } else if (os_file_lock(file, name)) { + } else if (os_file_lock(file, name, F_WRLCK)) { *success = FALSE; file = -1; #endif @@ -971,7 +973,7 @@ os_file_create_simple_no_error_handling( if (file == -1) { *success = FALSE; #ifdef USE_FILE_LOCK - } else if (os_file_lock(file, name)) { + } else if (os_file_lock(file, name, F_WRLCK)) { *success = FALSE; file = -1; #endif @@ -1182,7 +1184,7 @@ try_again: goto try_again; } #ifdef USE_FILE_LOCK - } else if (os_file_lock(file, name)) { + } else if (os_file_lock(file, name, F_WRLCK)) { *success = FALSE; file = -1; #endif @@ -1383,6 +1385,9 @@ os_file_close( #else int ret; +#ifdef USE_FILE_LOCK + (void) os_file_lock(file, "unknown", F_UNLCK); +#endif ret = close(file); if (ret == -1) { @@ -1419,6 +1424,9 @@ os_file_close_no_error_handling( #else int ret; +#ifdef USE_FILE_LOCK + (void) os_file_lock(file, "unknown", F_UNLCK); +#endif ret = close(file); if (ret == -1) { diff --git a/innobase/row/row0ins.c b/innobase/row/row0ins.c index a3f883b49c6..062f21369a7 100644 --- a/innobase/row/row0ins.c +++ b/innobase/row/row0ins.c @@ -803,8 +803,7 @@ row_ins_foreign_check_on_constraint( "InnoDB: clustered record ", stderr); rec_print(stderr, clust_rec); fputs("\n" - "InnoDB: Make a detailed bug report and send it\n" - "InnoDB: to mysql@lists.mysql.com\n", stderr); +"InnoDB: Submit a detailed bug report to http://bugs.mysql.com\n", stderr); err = DB_SUCCESS; diff --git a/innobase/row/row0mysql.c b/innobase/row/row0mysql.c index 5432add37f7..154da11da58 100644 --- a/innobase/row/row0mysql.c +++ b/innobase/row/row0mysql.c @@ -714,7 +714,7 @@ run_again: trx_start_if_not_started(trx); - err = lock_table(0, prebuilt->table, prebuilt->select_lock_type, thr); + err = lock_table(0, prebuilt->table, LOCK_AUTO_INC, thr); trx->error_state = err; @@ -2526,10 +2526,11 @@ row_drop_database_for_mysql( dict_table_t* table; char* table_name; int err = DB_SUCCESS; + ulint namelen = strlen(name); ut_ad(trx->mysql_thread_id == os_thread_get_curr_id()); ut_a(name != NULL); - ut_a(name[strlen(name) - 1] == '/'); + ut_a(name[namelen - 1] == '/'); trx->op_info = (char *) "dropping database"; @@ -2538,7 +2539,7 @@ loop: row_mysql_lock_data_dictionary(trx); while ((table_name = dict_get_first_table_name_in_db(name))) { - ut_a(strcmp(table_name, name) == 0); + ut_a(memcmp(table_name, name, namelen) == 0); table = dict_table_get_low(table_name); diff --git a/innobase/row/row0sel.c b/innobase/row/row0sel.c index 4c43f75125c..47d61459d47 100644 --- a/innobase/row/row0sel.c +++ b/innobase/row/row0sel.c @@ -2410,8 +2410,7 @@ row_sel_get_clust_rec_for_mysql( trx_print(stderr, thr_get_trx(thr)); fputs("\n" - "InnoDB: Make a detailed bug report and send it\n" - "InnoDB: to mysql@lists.mysql.com\n", stderr); +"InnoDB: Submit a detailed bug report to http://bugs.mysql.com\n", stderr); } clust_rec = NULL; diff --git a/innobase/row/row0umod.c b/innobase/row/row0umod.c index 3c181ed5493..d47227166f3 100644 --- a/innobase/row/row0umod.c +++ b/innobase/row/row0umod.c @@ -441,8 +441,7 @@ row_undo_mod_del_unmark_sec_and_undo_update( putc('\n', stderr); trx_print(stderr, thr_get_trx(thr)); fputs("\n" - "InnoDB: Make a detailed bug report and send it\n" - "InnoDB: to mysql@lists.mysql.com\n", stderr); +"InnoDB: Submit a detailed bug report to http://bugs.mysql.com\n", stderr); } else { btr_cur_t* btr_cur = btr_pcur_get_btr_cur(&pcur); diff --git a/innobase/row/row0upd.c b/innobase/row/row0upd.c index 82eb112fc77..724e7bf91e7 100644 --- a/innobase/row/row0upd.c +++ b/innobase/row/row0upd.c @@ -1236,8 +1236,7 @@ row_upd_sec_index_entry( trx_print(stderr, thr_get_trx(thr)); fputs("\n" - "InnoDB: Make a detailed bug report and send it\n" - "InnoDB: to mysql@lists.mysql.com\n", stderr); +"InnoDB: Submit a detailed bug report to http://bugs.mysql.com\n", stderr); } else { /* Delete mark the old index record; it can already be delete marked if we return after a lock wait in diff --git a/innobase/trx/trx0rec.c b/innobase/trx/trx0rec.c index 16f9f3d093d..382f723a05c 100644 --- a/innobase/trx/trx0rec.c +++ b/innobase/trx/trx0rec.c @@ -823,17 +823,16 @@ trx_undo_update_rec_get_update( if (field_no >= dict_index_get_n_fields(index)) { fprintf(stderr, - "InnoDB: Error: trying to access" - " update undo rec field %lu in ", (ulong) field_no); +"InnoDB: Error: trying to access update undo rec field %lu in ", (ulong) field_no); dict_index_name_print(stderr, index); fprintf(stderr, "\n" - "InnoDB: but index has only %lu fields\n" - "InnoDB: Send a detailed bug report to mysql@lists.mysql.com\n" - "InnoDB: Run also CHECK TABLE ", +"InnoDB: but index has only %lu fields\n" +"InnoDB: Submit a detailed bug report to http://bugs.mysql.com\n" +"InnoDB: Run also CHECK TABLE ", (ulong) dict_index_get_n_fields(index)); ut_print_name(stderr, index->table_name); fprintf(stderr, "\n" - "InnoDB: n_fields = %lu, i = %lu, ptr %p\n", +"InnoDB: n_fields = %lu, i = %lu, ptr %p\n", (ulong) n_fields, (ulong) i, ptr); return(NULL); } @@ -1271,8 +1270,7 @@ trx_undo_prev_version_build( " update undo rec for non-clustered ", stderr); dict_index_name_print(stderr, index); fputs("\n" - "InnoDB: Send a detailed bug report to" - " mysql@lists.mysql.com\n" +"InnoDB: Submit a detailed bug report to http://bugs.mysql.com\n" "InnoDB: index record ", stderr); rec_print(stderr, index_rec); fputs("\n" @@ -1320,11 +1318,9 @@ trx_undo_prev_version_build( " update undo rec for table ", stderr); ut_print_name(stderr, index->table_name); fputs("\n" - "InnoDB: but the table id in the" - " undo record is wrong\n" - "InnoDB: Send a detailed bug report to " - "mysql@lists.mysql.com\n" - "InnoDB: Run also CHECK TABLE ", stderr); +"InnoDB: but the table id in the undo record is wrong\n" +"InnoDB: Submit a detailed bug report to http://bugs.mysql.com\n" +"InnoDB: Run also CHECK TABLE ", stderr); ut_print_name(stderr, index->table_name); putc('\n', stderr); } diff --git a/innobase/trx/trx0trx.c b/innobase/trx/trx0trx.c index fc0a67278d2..8128c8de13e 100644 --- a/innobase/trx/trx0trx.c +++ b/innobase/trx/trx0trx.c @@ -1564,7 +1564,9 @@ trx_mark_sql_stat_end( /************************************************************************** Prints info about a transaction to the standard output. The caller must -own the kernel mutex. */ +own the kernel mutex and must have called +innobase_mysql_prepare_print_arbitrary_thd(), unless he knows that MySQL or +InnoDB cannot meanwhile change the info printed here. */ void trx_print( diff --git a/innobase/ut/ut0dbg.c b/innobase/ut/ut0dbg.c index 3697e31050f..65703ec1c86 100644 --- a/innobase/ut/ut0dbg.c +++ b/innobase/ut/ut0dbg.c @@ -23,7 +23,7 @@ const char* ut_dbg_msg_assert_fail = "InnoDB: Assertion failure in thread %lu in file %s line %lu\n"; const char* ut_dbg_msg_trap = "InnoDB: We intentionally generate a memory trap.\n" -"InnoDB: Send a detailed bug report to mysql@lists.mysql.com.\n" +"InnoDB: Submit a detailed bug report to http://bugs.mysql.com.\n" "InnoDB: If you get repeated assertion failures or crashes, even\n" "InnoDB: immediately after the mysqld startup, there may be\n" "InnoDB: corruption in the InnoDB tablespace. See section 6.1 of\n" diff --git a/myisam/mi_dynrec.c b/myisam/mi_dynrec.c index 30a4762abe0..f64e774810d 100644 --- a/myisam/mi_dynrec.c +++ b/myisam/mi_dynrec.c @@ -311,7 +311,7 @@ static int update_backward_delete_link(MI_INFO *info, my_off_t delete_block, DBUG_RETURN(1); /* Wrong delete link */ } } - return 0; + DBUG_RETURN(0); } /* Delete datarecord from database */ diff --git a/myisam/mi_range.c b/myisam/mi_range.c index caa57ce6187..db01ada16dd 100644 --- a/myisam/mi_range.c +++ b/myisam/mi_range.c @@ -30,15 +30,27 @@ static uint _mi_keynr(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *page, uchar *keypos,uint *ret_max_key); - /* If start_key = 0 assume read from start */ - /* If end_key = 0 assume read to end */ - /* Returns HA_POS_ERROR on error */ - -ha_rows mi_records_in_range(MI_INFO *info, int inx, const byte *start_key, - uint start_key_len, - enum ha_rkey_function start_search_flag, - const byte *end_key, uint end_key_len, - enum ha_rkey_function end_search_flag) +/* + Estimate how many records there is in a given range + + SYNOPSIS + mi_records_in_range() + info MyISAM handler + inx Index to use + min_key Min key. Is = 0 if no min range + max_key Max key. Is = 0 if no max range + + NOTES + We should ONLY return 0 if there is no rows in range + + RETURN + HA_POS_ERROR error (or we can't estimate number of rows) + number Estimated number of rows +*/ + + +ha_rows mi_records_in_range(MI_INFO *info, int inx, key_range *min_key, + key_range *max_key) { ha_rows start_pos,end_pos,res; DBUG_ENTER("mi_records_in_range"); @@ -54,27 +66,31 @@ ha_rows mi_records_in_range(MI_INFO *info, int inx, const byte *start_key, switch(info->s->keyinfo[inx].key_alg){ case HA_KEY_ALG_RTREE: - { - uchar * key_buff; - if (start_key_len == 0) - start_key_len=USE_WHOLE_KEY; - key_buff=info->lastkey+info->s->base.max_key_length; - start_key_len= _mi_pack_key(info,inx,key_buff,(uchar*) start_key, - start_key_len, (HA_KEYSEG**) 0); - res=rtree_estimate(info, inx, key_buff, start_key_len, myisam_read_vec[start_search_flag]); - res=res?res:1; - break; - } + { + uchar * key_buff; + uint start_key_len; + + key_buff= info->lastkey+info->s->base.max_key_length; + start_key_len= _mi_pack_key(info,inx, key_buff, + (uchar*) min_key->key, min_key->length, + (HA_KEYSEG**) 0); + res= rtree_estimate(info, inx, key_buff, start_key_len, + myisam_read_vec[min_key->flag]); + res= res ? res : 1; /* Don't return 0 */ + break; + } case HA_KEY_ALG_BTREE: default: - start_pos= (start_key ? - _mi_record_pos(info,start_key,start_key_len,start_search_flag) : - (ha_rows) 0); - end_pos= (end_key ? - _mi_record_pos(info,end_key,end_key_len,end_search_flag) : - info->state->records+ (ha_rows) 1); - res=end_pos < start_pos ? (ha_rows) 0 : - (end_pos == start_pos ? (ha_rows) 1 : end_pos-start_pos); + start_pos= (min_key ? + _mi_record_pos(info, min_key->key, min_key->length, + min_key->flag) : + (ha_rows) 0); + end_pos= (max_key ? + _mi_record_pos(info, max_key->key, max_key->length, + max_key->flag) : + info->state->records+ (ha_rows) 1); + res= (end_pos < start_pos ? (ha_rows) 0 : + (end_pos == start_pos ? (ha_rows) 1 : end_pos-start_pos)); if (start_pos == HA_POS_ERROR || end_pos == HA_POS_ERROR) res=HA_POS_ERROR; } diff --git a/myisam/mi_test2.c b/myisam/mi_test2.c index d3c3cc2c492..56d8357536a 100644 --- a/myisam/mi_test2.c +++ b/myisam/mi_test2.c @@ -606,13 +606,20 @@ int main(int argc, char *argv[]) mi_status(file,&info,HA_STATUS_VARIABLE); for (i=0 ; i < info.keys ; i++) { + key_range min_key, max_key; if (mi_rfirst(file,read_record,(int) i) || mi_rlast(file,read_record2,(int) i)) goto err; copy_key(file,(uint) i,(uchar*) read_record,(uchar*) key); copy_key(file,(uint) i,(uchar*) read_record2,(uchar*) key2); - range_records=mi_records_in_range(file,(int) i,key,0,HA_READ_KEY_EXACT, - key2,0,HA_READ_AFTER_KEY); + min_key.key= key; + min_key.length= USE_WHOLE_KEY; + min_key.flag= HA_READ_KEY_EXACT; + max_key.key= key2; + max_key.length= USE_WHOLE_KEY; + max_key.flag= HA_READ_AFTER_KEY; + + range_records= mi_records_in_range(file,(int) i, &min_key, &max_key); if (range_records < info.records*8/10 || range_records > info.records*12/10) { @@ -634,12 +641,19 @@ int main(int argc, char *argv[]) for (k=rnd(1000)+1 ; k>0 && key1[k] == 0 ; k--) ; if (j != 0 && k != 0) { + key_range min_key, max_key; if (j > k) swap(int,j,k); sprintf(key,"%6d",j); sprintf(key2,"%6d",k); - range_records=mi_records_in_range(file,0,key,0,HA_READ_AFTER_KEY, - key2,0,HA_READ_BEFORE_KEY); + + min_key.key= key; + min_key.length= USE_WHOLE_KEY; + min_key.flag= HA_READ_AFTER_KEY; + max_key.key= key2; + max_key.length= USE_WHOLE_KEY; + max_key.flag= HA_READ_BEFORE_KEY; + range_records= mi_records_in_range(file, 0, &min_key, &max_key); records=0; for (j++ ; j < k ; j++) records+=key1[j]; diff --git a/myisam/rt_test.c b/myisam/rt_test.c index bbeb8fce2d1..c1126c1939a 100644 --- a/myisam/rt_test.c +++ b/myisam/rt_test.c @@ -39,7 +39,6 @@ int main(int argc __attribute__((unused)),char *argv[] __attribute__((unused))) } - int run_test(const char *filename) { MI_INFO *file; @@ -48,6 +47,7 @@ int run_test(const char *filename) MI_COLUMNDEF recinfo[20]; MI_KEYDEF keyinfo[20]; HA_KEYSEG keyseg[20]; + key_range range; int silent=0; int opt_unique=0; @@ -66,15 +66,12 @@ int run_test(const char *filename) int upd= 10; ha_rows hrows; - - /* Define a column for NULLs and DEL markers*/ recinfo[0].type=FIELD_NORMAL; recinfo[0].length=1; /* For NULL bits */ rec_length=1; - /* Define 2*ndims columns for coordinates*/ for (i=1; i<=2*ndims ;i++){ @@ -83,7 +80,6 @@ int run_test(const char *filename) rec_length+=key_length; } - /* Define a key with 2*ndims segments */ keyinfo[0].seg=keyseg; @@ -101,8 +97,7 @@ int run_test(const char *filename) keyinfo[0].seg[i].language=default_charset_info->number; } - - if(!silent) + if (!silent) printf("- Creating isam-file\n"); bzero((char*) &create_info,sizeof(create_info)); @@ -115,15 +110,11 @@ int run_test(const char *filename) recinfo,uniques,&uniquedef,&create_info,create_flag)) goto err; - - - - if(!silent) + if (!silent) printf("- Open isam-file\n"); if (!(file=mi_open(filename,2,HA_OPEN_ABORT_IF_LOCKED))) goto err; - if (!silent) printf("- Writing key:s\n"); @@ -144,11 +135,9 @@ int run_test(const char *filename) } } - - if((error=read_with_pos(file,silent))) + if ((error=read_with_pos(file,silent))) goto err; - if (!silent) printf("- Reading rows with key\n"); @@ -160,12 +149,12 @@ int run_test(const char *filename) bzero((char*) read_record,MAX_REC_LENGTH); error=mi_rkey(file,read_record,0,record+1,0,HA_READ_MBR_EQUAL); - if(error && error!=HA_ERR_KEY_NOT_FOUND) + if (error && error!=HA_ERR_KEY_NOT_FOUND) { printf(" mi_rkey: %3d errno: %3d\n",error,my_errno); goto err; } - if(error == HA_ERR_KEY_NOT_FOUND) + if (error == HA_ERR_KEY_NOT_FOUND) { print_record(record,mi_position(file)," NOT FOUND\n"); continue; @@ -173,10 +162,6 @@ int run_test(const char *filename) print_record(read_record,mi_position(file),"\n"); } - - - - if (!silent) printf("- Deleting rows\n"); for (i=0; i < nrecords/4; i++) @@ -184,7 +169,7 @@ int run_test(const char *filename) my_errno=0; bzero((char*) read_record,MAX_REC_LENGTH); error=mi_rrnd(file,read_record,i == 0 ? 0L : HA_OFFSET_ERROR); - if(error) + if (error) { printf("pos: %2d mi_rrnd: %3d errno: %3d\n",i,error,my_errno); goto err; @@ -192,14 +177,13 @@ int run_test(const char *filename) print_record(read_record,mi_position(file),"\n"); error=mi_delete(file,read_record); - if(error) + if (error) { printf("pos: %2d mi_delete: %3d errno: %3d\n",i,error,my_errno); goto err; } } - if (!silent) printf("- Updating rows with position\n"); for (i=0; i < (nrecords - nrecords/4) ; i++) @@ -207,9 +191,9 @@ int run_test(const char *filename) my_errno=0; bzero((char*) read_record,MAX_REC_LENGTH); error=mi_rrnd(file,read_record,i == 0 ? 0L : HA_OFFSET_ERROR); - if(error) + if (error) { - if(error==HA_ERR_RECORD_DELETED) + if (error==HA_ERR_RECORD_DELETED) continue; printf("pos: %2d mi_rrnd: %3d errno: %3d\n",i,error,my_errno); goto err; @@ -219,19 +203,16 @@ int run_test(const char *filename) printf("\t-> "); print_record(record,mi_position(file),"\n"); error=mi_update(file,read_record,record); - if(error) + if (error) { printf("pos: %2d mi_update: %3d errno: %3d\n",i,error,my_errno); goto err; } } - - if((error=read_with_pos(file,silent))) + if ((error=read_with_pos(file,silent))) goto err; - - if (!silent) printf("- Test mi_rkey then a sequence of mi_rnext_same\n"); @@ -246,25 +227,20 @@ int run_test(const char *filename) print_record(read_record,mi_position(file)," mi_rkey\n"); row_count=1; - - do { - if((error=mi_rnext_same(file,read_record))) + for (;;) + { + if ((error=mi_rnext_same(file,read_record))) { - if(error==HA_ERR_END_OF_FILE) + if (error==HA_ERR_END_OF_FILE) break; printf("mi_next: %3d errno: %3d\n",error,my_errno); goto err; } print_record(read_record,mi_position(file)," mi_rnext_same\n"); row_count++; - }while(1); + } printf(" %d rows\n",row_count); - - - - - if (!silent) printf("- Test mi_rfirst then a sequence of mi_rnext\n"); @@ -277,10 +253,11 @@ int run_test(const char *filename) row_count=1; print_record(read_record,mi_position(file)," mi_frirst\n"); - for(i=0;i<nrecords;i++) { - if((error=mi_rnext(file,read_record,0))) + for (i=0;i<nrecords;i++) + { + if ((error=mi_rnext(file,read_record,0))) { - if(error==HA_ERR_END_OF_FILE) + if (error==HA_ERR_END_OF_FILE) break; printf("mi_next: %3d errno: %3d\n",error,my_errno); goto err; @@ -290,16 +267,18 @@ int run_test(const char *filename) } printf(" %d rows\n",row_count); - if (!silent) printf("- Test mi_records_in_range()\n"); create_record1(record, nrecords*4/5); print_record(record,0,"\n"); - hrows=mi_records_in_range(file,0,record+1,0,HA_READ_MBR_INTERSECT,record+1,0,0); + + range.key= record+1; + range.length= 1000; /* Big enough */ + range.flag= HA_READ_MBR_INTERSECT; + hrows= mi_records_in_range(file,0, &range, (key_range*) 0); printf(" %ld rows\n", (long) hrows); - if (mi_close(file)) goto err; my_end(MY_CHECK_ERROR); @@ -325,11 +304,11 @@ static int read_with_pos (MI_INFO * file,int silent) my_errno=0; bzero((char*) read_record,MAX_REC_LENGTH); error=mi_rrnd(file,read_record,i == 0 ? 0L : HA_OFFSET_ERROR); - if(error) + if (error) { - if(error==HA_ERR_END_OF_FILE) + if (error==HA_ERR_END_OF_FILE) break; - if(error==HA_ERR_RECORD_DELETED) + if (error==HA_ERR_RECORD_DELETED) continue; printf("pos: %2d mi_rrnd: %3d errno: %3d\n",i,error,my_errno); return error; diff --git a/myisam/sp_test.c b/myisam/sp_test.c index 5cbf5e87579..29c5f47471a 100644 --- a/myisam/sp_test.c +++ b/myisam/sp_test.c @@ -32,10 +32,10 @@ static void print_key(const char *key,const char * tail); static int run_test(const char *filename); static int read_with_pos(MI_INFO * file, int silent); -static int rtree_CreateLineStringWKB(double *ords, uint n_dims, uint n_points, uchar *wkb); +static int rtree_CreateLineStringWKB(double *ords, uint n_dims, uint n_points, + uchar *wkb); static void rtree_PrintWKB(uchar *wkb, uint n_dims); - static char blob_key[MAX_REC_LENGTH]; @@ -46,7 +46,6 @@ int main(int argc __attribute__((unused)),char *argv[]) } - int run_test(const char *filename) { MI_INFO *file; @@ -55,7 +54,7 @@ int run_test(const char *filename) MI_COLUMNDEF recinfo[20]; MI_KEYDEF keyinfo[20]; HA_KEYSEG keyseg[20]; - + key_range min_range, max_range; int silent=0; int create_flag=0; int null_fields=0; @@ -100,7 +99,7 @@ int run_test(const char *filename) keyinfo[0].seg[0].bit_start=4; /* Long BLOB */ - if(!silent) + if (!silent) printf("- Creating isam-file\n"); bzero((char*) &create_info,sizeof(create_info)); @@ -113,17 +112,12 @@ int run_test(const char *filename) recinfo,uniques,&uniquedef,&create_info,create_flag)) goto err; - - - - if(!silent) + if (!silent) printf("- Open isam-file\n"); if (!(file=mi_open(filename,2,HA_OPEN_ABORT_IF_LOCKED))) goto err; - - if (!silent) printf("- Writing key:s\n"); @@ -143,11 +137,9 @@ int run_test(const char *filename) } } - - if((error=read_with_pos(file,silent))) + if ((error=read_with_pos(file,silent))) goto err; - if (!silent) printf("- Deleting rows with position\n"); for (i=0; i < nrecords/4; i++) @@ -155,23 +147,20 @@ int run_test(const char *filename) my_errno=0; bzero((char*) read_record,MAX_REC_LENGTH); error=mi_rrnd(file,read_record,i == 0 ? 0L : HA_OFFSET_ERROR); - if(error) + if (error) { printf("pos: %2d mi_rrnd: %3d errno: %3d\n",i,error,my_errno); goto err; } print_record(read_record,mi_position(file),"\n"); error=mi_delete(file,read_record); - if(error) + if (error) { printf("pos: %2d mi_delete: %3d errno: %3d\n",i,error,my_errno); goto err; } } - - - if (!silent) printf("- Updating rows with position\n"); for (i=0; i < nrecords/2 ; i++) @@ -179,9 +168,9 @@ int run_test(const char *filename) my_errno=0; bzero((char*) read_record,MAX_REC_LENGTH); error=mi_rrnd(file,read_record,i == 0 ? 0L : HA_OFFSET_ERROR); - if(error) + if (error) { - if(error==HA_ERR_RECORD_DELETED) + if (error==HA_ERR_RECORD_DELETED) continue; printf("pos: %2d mi_rrnd: %3d errno: %3d\n",i,error,my_errno); goto err; @@ -191,20 +180,16 @@ int run_test(const char *filename) printf("\t-> "); print_record(record,mi_position(file),"\n"); error=mi_update(file,read_record,record); - if(error) + if (error) { printf("pos: %2d mi_update: %3d errno: %3d\n",i,error,my_errno); goto err; } } - - - if((error=read_with_pos(file,silent))) + if ((error=read_with_pos(file,silent))) goto err; - - if (!silent) printf("- Test mi_rkey then a sequence of mi_rnext_same\n"); @@ -219,25 +204,20 @@ int run_test(const char *filename) print_record(read_record,mi_position(file)," mi_rkey\n"); row_count=1; - - do { - if((error=mi_rnext_same(file,read_record))) + for (;;) + { + if ((error=mi_rnext_same(file,read_record))) { - if(error==HA_ERR_END_OF_FILE) + if (error==HA_ERR_END_OF_FILE) break; printf("mi_next: %3d errno: %3d\n",error,my_errno); goto err; } print_record(read_record,mi_position(file)," mi_rnext_same\n"); row_count++; - }while(1); + } printf(" %d rows\n",row_count); - - - - - if (!silent) printf("- Test mi_rfirst then a sequence of mi_rnext\n"); @@ -251,9 +231,9 @@ int run_test(const char *filename) print_record(read_record,mi_position(file)," mi_frirst\n"); for(i=0;i<nrecords;i++) { - if((error=mi_rnext(file,read_record,0))) + if ((error=mi_rnext(file,read_record,0))) { - if(error==HA_ERR_END_OF_FILE) + if (error==HA_ERR_END_OF_FILE) break; printf("mi_next: %3d errno: %3d\n",error,my_errno); goto err; @@ -263,22 +243,22 @@ int run_test(const char *filename) } printf(" %d rows\n",row_count); - - - if (!silent) printf("- Test mi_records_in_range()\n"); create_key(key, nrecords*upd); print_key(key," INTERSECT\n"); - hrows=mi_records_in_range(file,0,key,0,HA_READ_MBR_INTERSECT,record+1,0, - HA_READ_KEY_EXACT); + min_range.key= key; + min_range.length= 1000; /* Big enough */ + min_range.flag= HA_READ_MBR_INTERSECT; + max_range.key= record+1; + max_range.length= 1000; /* Big enough */ + max_range.flag= HA_READ_KEY_EXACT; + hrows= mi_records_in_range(file,0, &min_range, &max_range); printf(" %ld rows\n", (long) hrows); - if (mi_close(file)) goto err; my_end(MY_CHECK_ERROR); - return 0; err: @@ -287,7 +267,6 @@ err: } - static int read_with_pos (MI_INFO * file,int silent) { int error; @@ -302,11 +281,11 @@ static int read_with_pos (MI_INFO * file,int silent) my_errno=0; bzero((char*) read_record,MAX_REC_LENGTH); error=mi_rrnd(file,read_record,i == 0 ? 0L : HA_OFFSET_ERROR); - if(error) + if (error) { - if(error==HA_ERR_END_OF_FILE) + if (error==HA_ERR_END_OF_FILE) break; - if(error==HA_ERR_RECORD_DELETED) + if (error==HA_ERR_RECORD_DELETED) continue; printf("pos: %2d mi_rrnd: %3d errno: %3d\n",i,error,my_errno); return error; @@ -351,7 +330,7 @@ static void print_record(char * record, my_off_t offs,const char * tail) pos+=4; printf(" len=%d ",len); memcpy_fixed(&ptr,pos,sizeof(char*)); - if(ptr) + if (ptr) rtree_PrintWKB((uchar*) ptr,SPDIMS); else printf("<NULL> "); @@ -360,7 +339,6 @@ static void print_record(char * record, my_off_t offs,const char * tail) } - #ifdef NOT_USED static void create_point(char *record,uint rownr) { @@ -447,7 +425,6 @@ static void print_key(const char *key,const char * tail) } - #ifdef NOT_USED static int rtree_CreatePointWKB(double *ords, uint n_dims, uchar *wkb) @@ -489,6 +466,7 @@ static int rtree_CreateLineStringWKB(double *ords, uint n_dims, uint n_points, return 9 + n_points * n_dims * 8; } + static void rtree_PrintWKB(uchar *wkb, uint n_dims) { uint wkb_type; diff --git a/myisammrg/myrg_range.c b/myisammrg/myrg_range.c index 7644ae40c7b..aafdf70525c 100644 --- a/myisammrg/myrg_range.c +++ b/myisammrg/myrg_range.c @@ -16,20 +16,15 @@ #include "myrg_def.h" -ha_rows myrg_records_in_range(MYRG_INFO *info, int inx, const byte *start_key, - uint start_key_len, - enum ha_rkey_function start_search_flag, - const byte *end_key, uint end_key_len, - enum ha_rkey_function end_search_flag) +ha_rows myrg_records_in_range(MYRG_INFO *info, int inx, + key_range *min_key, key_range *max_key) { ha_rows records=0, res; MYRG_TABLE *table; for (table=info->open_tables ; table != info->end_table ; table++) { - res=mi_records_in_range(table->table, inx, - start_key, start_key_len, start_search_flag, - end_key, end_key_len, end_search_flag); + res= mi_records_in_range(table->table, inx, min_key, max_key); if (res == HA_POS_ERROR) return HA_POS_ERROR; if (records > HA_POS_ERROR - res) diff --git a/mysql-test/r/fulltext.result b/mysql-test/r/fulltext.result index f93f7401081..3106602e718 100644 --- a/mysql-test/r/fulltext.result +++ b/mysql-test/r/fulltext.result @@ -142,6 +142,8 @@ a b MySQL has now support for full-text search select * from t1 where MATCH a,b AGAINST ('"text i"' IN BOOLEAN MODE); a b +select * from t1 where MATCH a,b AGAINST ('"xt indexes"' IN BOOLEAN MODE); +a b select * from t1 where MATCH a,b AGAINST ('+(support collections) +foobar*' IN BOOLEAN MODE); a b select * from t1 where MATCH a,b AGAINST ('+(+(support collections)) +foobar*' IN BOOLEAN MODE); diff --git a/mysql-test/r/innodb.result b/mysql-test/r/innodb.result index 700fe1a4111..981ef23c779 100644 --- a/mysql-test/r/innodb.result +++ b/mysql-test/r/innodb.result @@ -467,7 +467,7 @@ ERROR 23000: Duplicate entry 'test2' for key 2 select * from t1; id ggid email passwd 1 this will work -4 test2 this will work +3 test2 this will work select * from t1 where id=1; id ggid email passwd 1 this will work diff --git a/mysql-test/r/order_by.result b/mysql-test/r/order_by.result index 5edffdacc98..694dc26bcde 100644 --- a/mysql-test/r/order_by.result +++ b/mysql-test/r/order_by.result @@ -89,10 +89,10 @@ create table t1 ( pk int primary key, name varchar(255) not null, number v insert into t1 values (1, 'Gamma', '123'), (2, 'Gamma Ext', '123a'), (3, 'Alpha', '001'), (4, 'Beta', '200c'); select distinct t1.name as 'Building Name',t1.number as 'Building Number' from t1 order by t1.name asc; Building Name Building Number -Gamma 123 -Gamma Ext 123a Alpha 001 Beta 200c +Gamma 123 +Gamma Ext 123a drop table t1; create table t1 (id int not null,col1 int not null,col2 int not null,index(col1)); insert into t1 values(1,2,2),(2,2,1),(3,1,2),(4,1,1),(5,1,4),(6,2,3),(7,3,1),(8,2,4); diff --git a/mysql-test/r/rpl_server_id2.result b/mysql-test/r/rpl_server_id2.result index fde7251497a..82ab1ff85a7 100644 --- a/mysql-test/r/rpl_server_id2.result +++ b/mysql-test/r/rpl_server_id2.result @@ -4,9 +4,6 @@ reset master; reset slave; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; start slave; -drop table if exists t1; -Warnings: -Note 1051 Unknown table 't1' create table t1 (n int); reset master; stop slave; diff --git a/mysql-test/r/type_float.result b/mysql-test/r/type_float.result index 71ac229601d..f044ced2342 100644 --- a/mysql-test/r/type_float.result +++ b/mysql-test/r/type_float.result @@ -70,6 +70,21 @@ select min(a) from t1; min(a) -0.010 drop table t1; +create table t1 (c1 double, c2 varchar(20)); +insert t1 values (121,"16"); +select c1 + c1 * (c2 / 100) as col from t1; +col +140.36 +create table t2 select c1 + c1 * (c2 / 100) as col from t1; +select * from t2; +col +140.36 +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `col` double default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1,t2; create table t1 (a float); insert into t1 values (1); select max(a),min(a),avg(a) from t1; diff --git a/mysql-test/t/fulltext.test b/mysql-test/t/fulltext.test index 50a3d522e3d..ac88125965a 100644 --- a/mysql-test/t/fulltext.test +++ b/mysql-test/t/fulltext.test @@ -63,6 +63,7 @@ select * from t1 where MATCH a,b AGAINST ('"text search" "now support"' IN BOOL select * from t1 where MATCH a,b AGAINST ('"text search" -"now support"' IN BOOLEAN MODE); select * from t1 where MATCH a,b AGAINST ('"text search" +"now support"' IN BOOLEAN MODE); select * from t1 where MATCH a,b AGAINST ('"text i"' IN BOOLEAN MODE); +select * from t1 where MATCH a,b AGAINST ('"xt indexes"' IN BOOLEAN MODE); select * from t1 where MATCH a,b AGAINST ('+(support collections) +foobar*' IN BOOLEAN MODE); select * from t1 where MATCH a,b AGAINST ('+(+(support collections)) +foobar*' IN BOOLEAN MODE); diff --git a/mysql-test/t/rpl000015.test b/mysql-test/t/rpl000015.test index 38e0d1bff6c..b0119526deb 100644 --- a/mysql-test/t/rpl000015.test +++ b/mysql-test/t/rpl000015.test @@ -12,7 +12,7 @@ show slave status; change master to master_host='127.0.0.1'; # The following needs to be cleaned up when change master is fixed ---replace_result $MASTER_MYPORT MASTER_PORT 3306 MASTER_PORT 3334 MASTER_PORT +--replace_result $MASTER_MYPORT MASTER_PORT 3306 MASTER_PORT --replace_column 1 # 33 # show slave status; --replace_result $MASTER_MYPORT MASTER_PORT diff --git a/mysql-test/t/rpl_error_ignored_table.test b/mysql-test/t/rpl_error_ignored_table.test index 4e4e79adf67..0062a67ff1a 100644 --- a/mysql-test/t/rpl_error_ignored_table.test +++ b/mysql-test/t/rpl_error_ignored_table.test @@ -14,7 +14,7 @@ connection slave; sync_with_master; # The port number is different when doing the release build with # Do-compile, hence we have to replace the port number here accordingly ---replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT +--replace_result $MASTER_MYPORT MASTER_PORT --replace_column 1 # 33 # show slave status; # check that the table has been ignored, because otherwise the test is nonsense diff --git a/mysql-test/t/rpl_log.test b/mysql-test/t/rpl_log.test index 7ae0a4dc3c2..8fdccdd068d 100644 --- a/mysql-test/t/rpl_log.test +++ b/mysql-test/t/rpl_log.test @@ -89,11 +89,11 @@ connection slave; start slave; sync_with_master; show binary logs; ---replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT $VERSION VERSION +--replace_result $MASTER_MYPORT MASTER_PORT $VERSION VERSION show binlog events in 'slave-bin.000001' from 4; ---replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT $VERSION VERSION +--replace_result $MASTER_MYPORT MASTER_PORT $VERSION VERSION show binlog events in 'slave-bin.000002' from 4; ---replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT +--replace_result $MASTER_MYPORT MASTER_PORT --replace_column 1 # 33 # show slave status; diff --git a/mysql-test/t/rpl_log_pos.test b/mysql-test/t/rpl_log_pos.test index 2e54c98c014..a40736577c8 100644 --- a/mysql-test/t/rpl_log_pos.test +++ b/mysql-test/t/rpl_log_pos.test @@ -4,7 +4,7 @@ source include/master-slave.inc; show master status; sync_slave_with_master; ---replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT +--replace_result $MASTER_MYPORT MASTER_PORT --replace_column 1 # 33 # show slave status; stop slave; @@ -14,19 +14,19 @@ sleep 5; stop slave; change master to master_log_pos=73; ---replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT +--replace_result $MASTER_MYPORT MASTER_PORT --replace_column 1 # 33 # show slave status; start slave; sleep 5; ---replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT +--replace_result $MASTER_MYPORT MASTER_PORT --replace_column 1 # 33 # show slave status; stop slave; change master to master_log_pos=173; start slave; sleep 2; ---replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT +--replace_result $MASTER_MYPORT MASTER_PORT --replace_column 1 # 33 # show slave status; connection master; diff --git a/mysql-test/t/rpl_max_relay_size.test b/mysql-test/t/rpl_max_relay_size.test index a28aed52ec8..cbcc115a942 100644 --- a/mysql-test/t/rpl_max_relay_size.test +++ b/mysql-test/t/rpl_max_relay_size.test @@ -28,7 +28,7 @@ set global max_relay_log_size=8192-1; # mapped to 4096 select @@global.max_relay_log_size; start slave; sync_with_master; ---replace_result $MASTER_MYPORT MASTER_PORT 3306 MASTER_PORT 3334 MASTER_PORT +--replace_result $MASTER_MYPORT MASTER_PORT --replace_column 1 # 33 # show slave status; stop slave; @@ -37,7 +37,7 @@ set global max_relay_log_size=(5*4096); select @@global.max_relay_log_size; start slave; sync_with_master; ---replace_result $MASTER_MYPORT MASTER_PORT 3306 MASTER_PORT 3334 MASTER_PORT +--replace_result $MASTER_MYPORT MASTER_PORT --replace_column 1 # 33 # show slave status; stop slave; @@ -46,7 +46,7 @@ set global max_relay_log_size=0; select @@global.max_relay_log_size; start slave; sync_with_master; ---replace_result $MASTER_MYPORT MASTER_PORT 3306 MASTER_PORT 3334 MASTER_PORT +--replace_result $MASTER_MYPORT MASTER_PORT --replace_column 1 # 33 # show slave status; @@ -57,7 +57,7 @@ reset slave; # test of relay log rotation when the slave is stopped # (to make sure it does not crash). flush logs; ---replace_result $MASTER_MYPORT MASTER_PORT 3306 MASTER_PORT 3334 MASTER_PORT +--replace_result $MASTER_MYPORT MASTER_PORT --replace_column 1 # 33 # show slave status; @@ -73,7 +73,7 @@ create table t1 (a int); save_master_pos; connection slave; sync_with_master; ---replace_result $MASTER_MYPORT MASTER_PORT 3306 MASTER_PORT 3334 MASTER_PORT +--replace_result $MASTER_MYPORT MASTER_PORT --replace_column 1 # 33 # show slave status; # one more rotation, to be sure Relay_Log_Space is correctly updated @@ -83,7 +83,7 @@ drop table t1; save_master_pos; connection slave; sync_with_master; ---replace_result $MASTER_MYPORT MASTER_PORT 3306 MASTER_PORT 3334 MASTER_PORT +--replace_result $MASTER_MYPORT MASTER_PORT --replace_column 1 # 33 # show slave status; diff --git a/mysql-test/t/rpl_rotate_logs.test b/mysql-test/t/rpl_rotate_logs.test index 0d447b8d1a3..da4d5f0bce1 100644 --- a/mysql-test/t/rpl_rotate_logs.test +++ b/mysql-test/t/rpl_rotate_logs.test @@ -31,14 +31,14 @@ system chmod 600 var/slave-data/master.info; # init_strvar_from_file() in init_master_info()). --error 1201 start slave; ---replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT +--replace_result $MASTER_MYPORT MASTER_PORT # CHANGE MASTER will fail because it first parses master.info before changing # it (so when master.info is bad, people have to use RESET SLAVE first). --error 1201 eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root'; reset slave; ---replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT +--replace_result $MASTER_MYPORT MASTER_PORT eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root'; connection master; reset master; @@ -54,7 +54,7 @@ insert into temp_table values ("testing temporary tables"); create table t1 (s text); insert into t1 values('Could not break slave'),('Tried hard'); sync_slave_with_master; ---replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT +--replace_result $MASTER_MYPORT MASTER_PORT --replace_column 1 # 33 # show slave status; select * from t1; @@ -107,7 +107,7 @@ purge master logs before now(); show binary logs; insert into t2 values (65); sync_slave_with_master; ---replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT +--replace_result $MASTER_MYPORT MASTER_PORT --replace_column 1 # 33 # show slave status; select * from t2; @@ -139,7 +139,7 @@ connection slave; sync_with_master; select * from t4; ---replace_result 3306 MASTER_PORT 9306 MASTER_PORT 3334 MASTER_PORT 3336 MASTER_PORT +--replace_result $MASTER_MYPORT MASTER_PORT --replace_column 1 # 33 # show slave status; # because of concurrent insert, the table may not be up to date diff --git a/mysql-test/t/rpl_server_id2.test b/mysql-test/t/rpl_server_id2.test index dc8f733b7ed..7bbac358ada 100644 --- a/mysql-test/t/rpl_server_id2.test +++ b/mysql-test/t/rpl_server_id2.test @@ -3,7 +3,6 @@ source include/master-slave.inc; connection slave; -drop table if exists t1; create table t1 (n int); reset master; # replicate ourselves diff --git a/mysql-test/t/type_float.test b/mysql-test/t/type_float.test index 7d3b90aabeb..d3ddecfc314 100644 --- a/mysql-test/t/type_float.test +++ b/mysql-test/t/type_float.test @@ -31,6 +31,14 @@ select a from t1 order by a; select min(a) from t1; drop table t1; +create table t1 (c1 double, c2 varchar(20)); +insert t1 values (121,"16"); +select c1 + c1 * (c2 / 100) as col from t1; +create table t2 select c1 + c1 * (c2 / 100) as col from t1; +select * from t2; +show create table t2; +drop table t1,t2; + # Bug #1022: When a table contains a 'float' field, # and one of the functions MAX, MIN, or AVG is used on that field, # the system crashes. diff --git a/mysys/my_bitmap.c b/mysys/my_bitmap.c index da16457c299..0f8984e6b3d 100644 --- a/mysys/my_bitmap.c +++ b/mysys/my_bitmap.c @@ -104,7 +104,7 @@ void bitmap_set_bit(MY_BITMAP *map, uint bitmap_bit) { DBUG_ASSERT(map->bitmap && bitmap_bit < map->bitmap_size*8); bitmap_lock(map); - map->bitmap[bitmap_bit / 8] |= (1 << (bitmap_bit & 7)); + bitmap_fast_set_bit(map, bitmap_bit); bitmap_unlock(map); } @@ -144,7 +144,7 @@ void bitmap_clear_bit(MY_BITMAP *map, uint bitmap_bit) { DBUG_ASSERT(map->bitmap && bitmap_bit < map->bitmap_size*8); bitmap_lock(map); - map->bitmap[bitmap_bit / 8] &= ~ (1 << (bitmap_bit & 7)); + bitmap_fast_clear_bit(map, bitmap_bit); bitmap_unlock(map); } @@ -220,7 +220,7 @@ my_bool bitmap_is_set_all(const MY_BITMAP *map) my_bool bitmap_is_set(const MY_BITMAP *map, uint bitmap_bit) { DBUG_ASSERT(map->bitmap && bitmap_bit < map->bitmap_size*8); - return map->bitmap[bitmap_bit / 8] & (1 << (bitmap_bit & 7)); + return bitmap_fast_is_set(map, bitmap_bit); } diff --git a/scripts/make_binary_distribution.sh b/scripts/make_binary_distribution.sh index 3261ec309d4..da83e195943 100644 --- a/scripts/make_binary_distribution.sh +++ b/scripts/make_binary_distribution.sh @@ -224,6 +224,7 @@ $CP mysql-test/t/*test mysql-test/t/*.opt mysql-test/t/*.slave-mi mysql-test/t/* $CP mysql-test/r/*result mysql-test/r/*.require $BASE/mysql-test/r if [ $BASE_SYSTEM != "netware" ] ; then + chmod a+x $BASE/bin/* $CP scripts/* $BASE/bin $BASE/bin/replace \@localstatedir\@ ./data \@bindir\@ ./bin \@scriptdir\@ ./bin \@libexecdir\@ ./bin \@sbindir\@ ./bin \@prefix\@ . \@HOSTNAME\@ @HOSTNAME@ \@pkgdatadir\@ ./support-files < $SOURCE/scripts/mysql_install_db.sh > $BASE/scripts/mysql_install_db $BASE/bin/replace \@prefix\@ /usr/local/mysql \@bindir\@ ./bin \@MYSQLD_USER\@ root \@localstatedir\@ /usr/local/mysql/data \@HOSTNAME\@ @HOSTNAME@ < $SOURCE/support-files/mysql.server.sh > $BASE/support-files/mysql.server diff --git a/sql/examples/ha_example.cc b/sql/examples/ha_example.cc index b8ae5967475..2d17caf1a83 100644 --- a/sql/examples/ha_example.cc +++ b/sql/examples/ha_example.cc @@ -625,14 +625,11 @@ int ha_example::rename_table(const char * from, const char * to) Called from opt_range.cc by check_quick_keys(). */ -ha_rows ha_example::records_in_range(int inx, - const byte *start_key,uint start_key_len, - enum ha_rkey_function start_search_flag, - const byte *end_key,uint end_key_len, - enum ha_rkey_function end_search_flag) +ha_rows ha_example::records_in_range(uint inx, key_range *min_key, + key_range *max_key) { - DBUG_ENTER("ha_example::records_in_range "); - DBUG_RETURN(records); + DBUG_ENTER("ha_example::records_in_range"); + DBUG_RETURN(10); // low number to force index usage } diff --git a/sql/field.cc b/sql/field.cc index edaa29dbaa0..1ad7e039363 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -4252,12 +4252,13 @@ int Field_string::cmp(const char *a_ptr, const char *b_ptr) like in latin_de 'ae' and 0xe4 */ return field_charset->coll->strnncollsp(field_charset, - (const uchar*) a_ptr, field_length, - (const uchar*) b_ptr, field_length); + (const uchar*) a_ptr, field_length, + (const uchar*) b_ptr, + field_length); } return field_charset->coll->strnncoll(field_charset, - (const uchar*) a_ptr, field_length, - (const uchar*) b_ptr, field_length); + (const uchar*) a_ptr, field_length, + (const uchar*) b_ptr, field_length); } void Field_string::sort_string(char *to,uint length) diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc index 593b9575fb6..4dde893116f 100644 --- a/sql/ha_berkeley.cc +++ b/sql/ha_berkeley.cc @@ -1542,7 +1542,7 @@ int ha_berkeley::index_next_same(byte * buf, const byte *key, uint keylen) { error=read_row(cursor->c_get(cursor, &last_key, &row, DB_NEXT), (char*) buf, active_index, &row, &last_key, 1); - if (!error && ::key_cmp(table, key, active_index, keylen)) + if (!error && ::key_cmp_if_same(table, key, active_index, keylen)) error=HA_ERR_END_OF_FILE; } DBUG_RETURN(error); @@ -1987,11 +1987,8 @@ double ha_berkeley::scan_time() return rows2double(records/3); } -ha_rows ha_berkeley::records_in_range(int keynr, - const byte *start_key,uint start_key_len, - enum ha_rkey_function start_search_flag, - const byte *end_key,uint end_key_len, - enum ha_rkey_function end_search_flag) +ha_rows ha_berkeley::records_in_range(uint keynr, key_range *start_key, + key_range *end_key) { DBT key; DB_KEY_RANGE start_range, end_range; @@ -2000,25 +1997,27 @@ ha_rows ha_berkeley::records_in_range(int keynr, DBUG_ENTER("records_in_range"); if ((start_key && kfile->key_range(kfile,transaction, - pack_key(&key, keynr, key_buff, start_key, - start_key_len), - &start_range,0)) || + pack_key(&key, keynr, key_buff, + start_key->key, + start_key->length), + &start_range,0)) || (end_key && kfile->key_range(kfile,transaction, - pack_key(&key, keynr, key_buff, end_key, - end_key_len), + pack_key(&key, keynr, key_buff, + end_key->key, + end_key->length), &end_range,0))) DBUG_RETURN(HA_BERKELEY_RANGE_COUNT); // Better than returning an error /* purecov: inspected */ if (!start_key) - start_pos=0.0; - else if (start_search_flag == HA_READ_KEY_EXACT) + start_pos= 0.0; + else if (start_key->flag == HA_READ_KEY_EXACT) start_pos=start_range.less; else start_pos=start_range.less+start_range.equal; if (!end_key) - end_pos=1.0; - else if (end_search_flag == HA_READ_BEFORE_KEY) + end_pos= 1.0; + else if (end_key->flag == HA_READ_BEFORE_KEY) end_pos=end_range.less; else end_pos=end_range.less+end_range.equal; diff --git a/sql/ha_berkeley.h b/sql/ha_berkeley.h index 88af2326eac..4bc8e3a5777 100644 --- a/sql/ha_berkeley.h +++ b/sql/ha_berkeley.h @@ -143,12 +143,7 @@ class ha_berkeley: public handler int optimize(THD* thd, HA_CHECK_OPT* check_opt); int check(THD* thd, HA_CHECK_OPT* check_opt); - ha_rows records_in_range(int inx, - const byte *start_key,uint start_key_len, - enum ha_rkey_function start_search_flag, - const byte *end_key,uint end_key_len, - enum ha_rkey_function end_search_flag); - + ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key); int create(const char *name, register TABLE *form, HA_CREATE_INFO *create_info); int delete_table(const char *name); diff --git a/sql/ha_heap.cc b/sql/ha_heap.cc index 12b922e6fc0..c375614ac95 100644 --- a/sql/ha_heap.cc +++ b/sql/ha_heap.cc @@ -363,28 +363,20 @@ int ha_heap::rename_table(const char * from, const char * to) return heap_rename(from,to); } -ha_rows ha_heap::records_in_range(int inx, - const byte *start_key,uint start_key_len, - enum ha_rkey_function start_search_flag, - const byte *end_key,uint end_key_len, - enum ha_rkey_function end_search_flag) + +ha_rows ha_heap::records_in_range(uint inx, key_range *min_key, + key_range *max_key) { - KEY *pos=table->key_info+inx; - if (pos->algorithm == HA_KEY_ALG_BTREE) - { - return hp_rb_records_in_range(file, inx, start_key, start_key_len, - start_search_flag, end_key, end_key_len, - end_search_flag); - } - else - { - if (start_key_len != end_key_len || - start_key_len != pos->key_length || - start_search_flag != HA_READ_KEY_EXACT || - end_search_flag != HA_READ_AFTER_KEY) - return HA_POS_ERROR; // Can't only use exact keys - return 10; // Good guess - } + KEY *key=table->key_info+inx; + if (key->algorithm == HA_KEY_ALG_BTREE) + return hp_rb_records_in_range(file, inx, min_key, max_key); + + if (min_key->length != max_key->length || + min_key->length != key->key_length || + min_key->flag != HA_READ_KEY_EXACT || + max_key->flag != HA_READ_AFTER_KEY) + return HA_POS_ERROR; // Can only use exact keys + return 10; // Good guess } diff --git a/sql/ha_heap.h b/sql/ha_heap.h index 2f849d2574b..f55eda91149 100644 --- a/sql/ha_heap.h +++ b/sql/ha_heap.h @@ -86,10 +86,7 @@ class ha_heap: public handler int disable_indexes(uint mode); int enable_indexes(uint mode); int indexes_are_disabled(void); - ha_rows records_in_range(int inx, const byte *start_key,uint start_key_len, - enum ha_rkey_function start_search_flag, - const byte *end_key,uint end_key_len, - enum ha_rkey_function end_search_flag); + ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key); int delete_table(const char *from); int rename_table(const char * from, const char * to); int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info); diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index 201ec8f183f..8a40af90541 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -325,6 +325,35 @@ convert_error_code_to_mysql( } /***************************************************************** +If you want to print a thd that is not associated with the current thread, +you must call this function before reserving the InnoDB kernel_mutex, to +protect MySQL from setting thd->query NULL. If you print a thd of the current +thread, we know that MySQL cannot modify thd->query, and it is not necessary +to call this. Call innobase_mysql_end_print_arbitrary_thd() after you release +the kernel_mutex. +NOTE that /mysql/innobase/lock/lock0lock.c must contain the prototype for this +function! */ +extern "C" +void +innobase_mysql_prepare_print_arbitrary_thd(void) +/*============================================*/ +{ + VOID(pthread_mutex_lock(&LOCK_thread_count)); +} + +/***************************************************************** +Relases the mutex reserved by innobase_mysql_prepare_print_arbitrary_thd(). +NOTE that /mysql/innobase/lock/lock0lock.c must contain the prototype for this +function! */ +extern "C" +void +innobase_mysql_end_print_arbitrary_thd(void) +/*========================================*/ +{ + VOID(pthread_mutex_unlock(&LOCK_thread_count)); +} + +/***************************************************************** Prints info of a THD object (== user session thread) to the standard output. NOTE that /mysql/innobase/trx/trx0trx.c must contain the prototype for this function! */ @@ -335,9 +364,11 @@ innobase_mysql_print_thd( FILE* f, /* in: output stream */ void* input_thd)/* in: pointer to a MySQL THD object */ { - THD* thd; + const THD* thd; + const char* s; + char buf[301]; - thd = (THD*) input_thd; + thd = (const THD*) input_thd; fprintf(f, "MySQL thread id %lu, query id %lu", thd->thread_id, thd->query_id); @@ -356,14 +387,31 @@ innobase_mysql_print_thd( fputs(thd->user, f); } - if (thd->proc_info) { + if ((s = thd->proc_info)) { putc(' ', f); - fputs(thd->proc_info, f); + fputs(s, f); } - if (thd->query) { - putc(' ', f); - fputs(thd->query, f); + if ((s = thd->query)) { + /* determine the length of the query string */ + uint32 i, len; + + len = thd->query_length; + + if (len > 300) { + len = 300; /* ADDITIONAL SAFETY: print at most + 300 chars to reduce the probability of + a seg fault if there is a race in + thd->query_length in MySQL; after + May 14, 2004 probably no race any more, + but better be safe */ + } + + /* Use strmake to reduce the timeframe + for a race, compared to fwrite() */ + i= (uint) (strmake(buf, s, len) - buf); + putc('\n', f); + fwrite(buf, 1, i, f); } putc('\n', f); @@ -3925,18 +3973,11 @@ ha_innobase::records_in_range( /*==========================*/ /* out: estimated number of rows */ - int keynr, /* in: index number */ - const mysql_byte* start_key, /* in: start key value of the - range, may also be empty */ - uint start_key_len, /* in: start key val len, may - also be 0 */ - enum ha_rkey_function start_search_flag,/* in: start search condition - e.g., 'greater than' */ - const mysql_byte* end_key, /* in: range end key val, may - also be empty */ - uint end_key_len, /* in: range end key val len, - may also be 0 */ - enum ha_rkey_function end_search_flag)/* in: range end search cond */ + uint keynr, /* in: index number */ + key_range *min_key, /* in: start key value of the + range, may also be 0 */ + key_range *max_key) /* in: range end key val, may + also be 0 */ { row_prebuilt_t* prebuilt = (row_prebuilt_t*) innobase_prebuilt; KEY* key; @@ -3957,12 +3998,6 @@ ha_innobase::records_in_range( DBUG_ENTER("records_in_range"); - /* We do not know if MySQL can call this function before calling - external_lock(). To be safe, update the thd of the current table - handle. */ - - update_thd(current_thd); - prebuilt->trx->op_info = (char*)"estimating records in index range"; /* In case MySQL calls this in the middle of a SELECT query, release @@ -3986,17 +4021,21 @@ ha_innobase::records_in_range( range_start, (byte*) key_val_buff, (ulint)upd_and_key_val_buff_len, index, - (byte*) start_key, - (ulint) start_key_len); + (byte*) (min_key ? min_key->key : + (const mysql_byte*) 0), + (ulint) (min_key ? min_key->length : 0)); row_sel_convert_mysql_key_to_innobase( range_end, (byte*) key_val_buff2, buff2_len, index, - (byte*) end_key, - (ulint) end_key_len); - - mode1 = convert_search_mode_to_innobase(start_search_flag); - mode2 = convert_search_mode_to_innobase(end_search_flag); + (byte*) (max_key ? max_key->key : + (const mysql_byte*) 0), + (ulint) (max_key ? max_key->length : 0)); + + mode1 = convert_search_mode_to_innobase(min_key ? min_key->flag : + HA_READ_KEY_EXACT); + mode2 = convert_search_mode_to_innobase(max_key ? max_key->flag : + HA_READ_KEY_EXACT); n_rows = btr_estimate_n_rows_in_range(index, range_start, mode1, range_end, mode2); diff --git a/sql/ha_innodb.h b/sql/ha_innodb.h index 83a3edc4126..c585fd9c463 100644 --- a/sql/ha_innodb.h +++ b/sql/ha_innodb.h @@ -166,11 +166,7 @@ class ha_innobase: public handler int start_stmt(THD *thd); void position(byte *record); - ha_rows records_in_range(int inx, - const byte *start_key,uint start_key_len, - enum ha_rkey_function start_search_flag, - const byte *end_key,uint end_key_len, - enum ha_rkey_function end_search_flag); + ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key); ha_rows estimate_number_of_rows(); int create(const char *name, register TABLE *form, diff --git a/sql/ha_isam.cc b/sql/ha_isam.cc index 09c2aeceafc..85ab25a31d9 100644 --- a/sql/ha_isam.cc +++ b/sql/ha_isam.cc @@ -382,18 +382,21 @@ int ha_isam::create(const char *name, register TABLE *form, } +static key_range no_range= { (byte*) 0, 0, HA_READ_KEY_EXACT }; -ha_rows ha_isam::records_in_range(int inx, - const byte *start_key,uint start_key_len, - enum ha_rkey_function start_search_flag, - const byte *end_key,uint end_key_len, - enum ha_rkey_function end_search_flag) +ha_rows ha_isam::records_in_range(uint inx, key_range *min_key, + key_range *max_key) { + /* ISAM checks if 'key' pointer <> 0 to know if there is no range */ + if (!min_key) + min_key= &no_range; + if (!max_key) + max_key= &no_range; return (ha_rows) nisam_records_in_range(file, - inx, - start_key,start_key_len, - start_search_flag, - end_key,end_key_len, - end_search_flag); + (int) inx, + min_key->key, min_key->length, + min_key->flag, + max_key->key, max_key->length, + max_key->flag); } #endif /* HAVE_ISAM */ diff --git a/sql/ha_isam.h b/sql/ha_isam.h index 2c8ec274145..8a887ababde 100644 --- a/sql/ha_isam.h +++ b/sql/ha_isam.h @@ -70,11 +70,7 @@ class ha_isam: public handler void info(uint); int extra(enum ha_extra_function operation); int external_lock(THD *thd, int lock_type); - ha_rows records_in_range(int inx, - const byte *start_key,uint start_key_len, - enum ha_rkey_function start_search_flag, - const byte *end_key,uint end_key_len, - enum ha_rkey_function end_search_flag); + ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key); int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info); THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc index 1b24633953d..feac5c51dce 100644 --- a/sql/ha_myisam.cc +++ b/sql/ha_myisam.cc @@ -1515,19 +1515,15 @@ longlong ha_myisam::get_auto_increment() SYNOPSIS records_in_range() inx Index to use - start_key Start of range. Null pointer if from first key - start_key_len Length of start key - start_search_flag Flag if start key should be included or not - end_key End of range. Null pointer if to last key - end_key_len Length of end key - end_search_flag Flag if start key should be included or not + min_key Start of range. Null pointer if from first key + max_key End of range. Null pointer if to last key NOTES - start_search_flag can have one of the following values: + min_key.flag can have one of the following values: HA_READ_KEY_EXACT Include the key in the range HA_READ_AFTER_KEY Don't include key in range - end_search_flag can have one of the following values: + max_key.flag can have one of the following values: HA_READ_BEFORE_KEY Don't include key in range HA_READ_AFTER_KEY Include all 'end_key' values in the range @@ -1538,18 +1534,10 @@ longlong ha_myisam::get_auto_increment() the range. */ -ha_rows ha_myisam::records_in_range(int inx, - const byte *start_key,uint start_key_len, - enum ha_rkey_function start_search_flag, - const byte *end_key,uint end_key_len, - enum ha_rkey_function end_search_flag) +ha_rows ha_myisam::records_in_range(uint inx, key_range *min_key, + key_range *max_key) { - return (ha_rows) mi_records_in_range(file, - inx, - start_key,start_key_len, - start_search_flag, - end_key,end_key_len, - end_search_flag); + return (ha_rows) mi_records_in_range(file, (int) inx, min_key, max_key); } diff --git a/sql/ha_myisam.h b/sql/ha_myisam.h index 206a1c62a2f..77887220903 100644 --- a/sql/ha_myisam.h +++ b/sql/ha_myisam.h @@ -110,11 +110,7 @@ class ha_myisam: public handler int indexes_are_disabled(void); void start_bulk_insert(ha_rows rows); int end_bulk_insert(); - ha_rows records_in_range(int inx, - const byte *start_key,uint start_key_len, - enum ha_rkey_function start_search_flag, - const byte *end_key,uint end_key_len, - enum ha_rkey_function end_search_flag); + ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key); void update_create_info(HA_CREATE_INFO *create_info); int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info); THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, diff --git a/sql/ha_myisammrg.cc b/sql/ha_myisammrg.cc index 041d9eaead3..9aa6d039efb 100644 --- a/sql/ha_myisammrg.cc +++ b/sql/ha_myisammrg.cc @@ -199,20 +199,14 @@ void ha_myisammrg::position(const byte *record) ha_store_ptr(ref, ref_length, (my_off_t) position); } -ha_rows ha_myisammrg::records_in_range(int inx, - const byte *start_key,uint start_key_len, - enum ha_rkey_function start_search_flag, - const byte *end_key,uint end_key_len, - enum ha_rkey_function end_search_flag) + +ha_rows ha_myisammrg::records_in_range(uint inx, key_range *min_key, + key_range *max_key) { - return (ha_rows) myrg_records_in_range(file, - inx, - start_key,start_key_len, - start_search_flag, - end_key,end_key_len, - end_search_flag); + return (ha_rows) myrg_records_in_range(file, (int) inx, min_key, max_key); } + void ha_myisammrg::info(uint flag) { MYMERGE_INFO info; diff --git a/sql/ha_myisammrg.h b/sql/ha_myisammrg.h index c0f81a77a1e..fd36c78202d 100644 --- a/sql/ha_myisammrg.h +++ b/sql/ha_myisammrg.h @@ -70,11 +70,7 @@ class ha_myisammrg: public handler int rnd_next(byte *buf); int rnd_pos(byte * buf, byte *pos); void position(const byte *record); - ha_rows records_in_range(int inx, - const byte *start_key,uint start_key_len, - enum ha_rkey_function start_search_flag, - const byte *end_key,uint end_key_len, - enum ha_rkey_function end_search_flag); + ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key); my_off_t row_position() { return myrg_position(file); } void info(uint); int extra(enum ha_extra_function operation); diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 3bc322878d1..21056ef4a8f 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -2748,22 +2748,19 @@ void ha_ndbcluster::set_dbname(const char *path_name) ha_rows -ha_ndbcluster::records_in_range(int inx, - const byte *start_key,uint start_key_len, - enum ha_rkey_function start_search_flag, - const byte *end_key,uint end_key_len, - enum ha_rkey_function end_search_flag) -{ - ha_rows records= 10; - KEY* key_info= table->key_info + inx; +ha_ndbcluster::records_in_range(uint inx, key_range *min_key, + key_range *max_key) +{ + ha_rows records= 10; /* Good guess when you don't know anything */ + KEY *key_info= table->key_info + inx; uint key_length= key_info->key_length; DBUG_ENTER("records_in_range"); - DBUG_PRINT("enter", ("inx: %d", inx)); - DBUG_PRINT("enter", ("start_key: %x, start_key_len: %d", start_key, start_key_len)); - DBUG_PRINT("enter", ("start_search_flag: %d", start_search_flag)); - DBUG_PRINT("enter", ("end_key: %x, end_key_len: %d", end_key, end_key_len)); - DBUG_PRINT("enter", ("end_search_flag: %d", end_search_flag)); + DBUG_PRINT("enter", ("inx: %u", inx)); + DBUG_DUMP("start_key", min_key->key, min_key->length); + DBUG_DUMP("end_key", max_key->key, max_key->length); + DBUG_PRINT("enter", ("start_search_flag: %u end_search_flag: %u", + min_key->flag, max_key->flag)); /* Check that start_key_len is equal to @@ -2772,7 +2769,7 @@ ha_ndbcluster::records_in_range(int inx, */ NDB_INDEX_TYPE idx_type= get_index_type(inx); if ((idx_type == UNIQUE_INDEX || idx_type == PRIMARY_KEY_INDEX) && - start_key_len < key_length) + min_key->length < key_length) { DBUG_PRINT("warning", ("Tried to use index which required" "full key length: %d, HA_POS_ERROR", diff --git a/sql/ha_ndbcluster.h b/sql/ha_ndbcluster.h index bd601f39fc4..029ebc11e46 100644 --- a/sql/ha_ndbcluster.h +++ b/sql/ha_ndbcluster.h @@ -121,12 +121,7 @@ class ha_ndbcluster: public handler } double scan_time(); - ha_rows records_in_range(int inx, - const byte *start_key,uint start_key_len, - enum ha_rkey_function start_search_flag, - const byte *end_key,uint end_key_len, - enum ha_rkey_function end_search_flag); - + ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key); static Ndb* seize_ndb(); static void release_ndb(Ndb* ndb); diff --git a/sql/handler.cc b/sql/handler.cc index 7374242ebf8..f8eca1b93ef 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1184,7 +1184,7 @@ int handler::index_next_same(byte *buf, const byte *key, uint keylen) int error; if (!(error=index_next(buf))) { - if (key_cmp(table, key, active_index, keylen)) + if (key_cmp_if_same(table, key, active_index, keylen)) { table->status=STATUS_NOT_FOUND; error=HA_ERR_END_OF_FILE; @@ -1388,6 +1388,7 @@ int ha_discover(const char* dbname, const char* name, read_range_first() start_key Start key. Is 0 if no min range end_key End key. Is 0 if no max range + eq_range_arg Set to 1 if start_key == end_key sorted Set to 1 if result should be sorted per key NOTES @@ -1401,11 +1402,12 @@ int ha_discover(const char* dbname, const char* name, int handler::read_range_first(const key_range *start_key, const key_range *end_key, - bool sorted) + bool eq_range_arg, bool sorted) { int result; DBUG_ENTER("handler::read_range_first"); + eq_range= eq_range_arg; end_range= 0; if (end_key) { @@ -1416,7 +1418,6 @@ int handler::read_range_first(const key_range *start_key, } range_key_part= table->key_info[active_index].key_part; - if (!start_key) // Read first record result= index_first(table->record[0]); else @@ -1438,7 +1439,6 @@ int handler::read_range_first(const key_range *start_key, SYNOPSIS read_range_next() - eq_range Set to 1 if start_key == end_key NOTES Record is read into table->record[0] @@ -1449,17 +1449,19 @@ int handler::read_range_first(const key_range *start_key, # Error code */ -int handler::read_range_next(bool eq_range) +int handler::read_range_next() { int result; DBUG_ENTER("handler::read_range_next"); if (eq_range) - result= index_next_same(table->record[0], - end_range->key, - end_range->length); - else - result= index_next(table->record[0]); + { + /* We trust that index_next_same always gives a row in range */ + DBUG_RETURN(index_next_same(table->record[0], + end_range->key, + end_range->length)); + } + result= index_next(table->record[0]); if (result) DBUG_RETURN(result); DBUG_RETURN(compare_key(end_range) <= 0 ? 0 : HA_ERR_END_OF_FILE); @@ -1467,16 +1469,18 @@ int handler::read_range_next(bool eq_range) /* - Compare if found key is over max-value + Compare if found key (in row) is over max-value SYNOPSIS compare_key - range key to compare to row + range range to compare to row. May be 0 for no range NOTES - For this to work, the row must be stored in table->record[0] + See key.cc::key_cmp() for details RETURN + The return value is SIGN(key_in_row - range_key): + 0 Key is equal to range or 'range' == 0 (no range) -1 Key is less than range 1 Key is larger than range @@ -1484,37 +1488,11 @@ int handler::read_range_next(bool eq_range) int handler::compare_key(key_range *range) { - KEY_PART_INFO *key_part= range_key_part; - uint store_length; - + int cmp; if (!range) return 0; // No max range - - for (const char *key= (const char*) range->key, *end=key+range->length; - key < end; - key+= store_length, key_part++) - { - int cmp; - store_length= key_part->store_length; - if (key_part->null_bit) - { - if (*key) - { - if (!key_part->field->is_null()) - return 1; - continue; - } - else if (key_part->field->is_null()) - return 0; - key++; // Skip null byte - store_length--; - } - if ((cmp=key_part->field->key_cmp((byte*) key, key_part->length)) < 0) - return -1; - if (cmp > 0) - return 1; - } - return key_compare_result_on_equal; + cmp= key_cmp(range_key_part, range->key, range->length); + if (!cmp) + cmp= key_compare_result_on_equal; + return cmp; } - - diff --git a/sql/handler.h b/sql/handler.h index 4f721a01412..bbeefa7c916 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -234,14 +234,6 @@ typedef struct st_ha_check_opt } HA_CHECK_OPT; -typedef struct st_key_range -{ - const byte *key; - uint length; - enum ha_rkey_function flag; -} key_range; - - class handler :public Sql_alloc { protected: @@ -268,6 +260,7 @@ public: key_range save_end_range, *end_range; KEY_PART_INFO *range_key_part; int key_compare_result_on_equal; + bool eq_range; uint errkey; /* Last dup key */ uint sortkey, key_used_on_scan; @@ -330,13 +323,14 @@ public: return (my_errno=HA_ERR_WRONG_COMMAND); } virtual int read_range_first(const key_range *start_key, - const key_range *end_key, - bool sorted); - virtual int read_range_next(bool eq_range); + const key_range *end_key, + bool eq_range, bool sorted); + virtual int read_range_next(); int compare_key(key_range *range); virtual int ft_init() { return -1; } - virtual FT_INFO *ft_init_ext(uint flags,uint inx,const byte *key, uint keylen) + virtual FT_INFO *ft_init_ext(uint flags,uint inx,const byte *key, + uint keylen) { return NULL; } virtual int ft_read(byte *buf) { return -1; } virtual int rnd_init(bool scan=1)=0; @@ -345,11 +339,8 @@ public: virtual int rnd_pos(byte * buf, byte *pos)=0; virtual int read_first_row(byte *buf, uint primary_key); virtual int restart_rnd_next(byte *buf, byte *pos); - virtual ha_rows records_in_range(int inx, - const byte *start_key,uint start_key_len, - enum ha_rkey_function start_search_flag, - const byte *end_key,uint end_key_len, - enum ha_rkey_function end_search_flag) + virtual ha_rows records_in_range(uint inx, key_range *min_key, + key_range *max_key) { return (ha_rows) 10; } virtual void position(const byte *record)=0; virtual my_off_t row_position() { return HA_OFFSET_ERROR; } diff --git a/sql/item_func.cc b/sql/item_func.cc index aaea676fee1..f221e0dcc5c 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -612,6 +612,7 @@ longlong Item_func_div::val_int() void Item_func_div::fix_length_and_dec() { decimals=max(args[0]->decimals,args[1]->decimals)+2; + set_if_smaller(decimals, NOT_FIXED_DEC); max_length=args[0]->max_length - args[0]->decimals + decimals; uint tmp=float_length(decimals); set_if_smaller(max_length,tmp); diff --git a/sql/key.cc b/sql/key.cc index a2c3b2c8989..9425a368669 100644 --- a/sql/key.cc +++ b/sql/key.cc @@ -156,9 +156,28 @@ void key_restore(TABLE *table,byte *key,uint idx,uint key_length) } /* key_restore */ - /* Compare if a key has changed */ +/* + Compare if a key has changed + + SYNOPSIS + key_cmp_if_same() + table TABLE + key key to compare to row + idx Index used + key_length Length of key + + NOTES + In theory we could just call field->cmp() for all field types, + but as we are only interested if a key has changed (not if the key is + larger or smaller than the previous value) we can do things a bit + faster by using memcmp() instead. + + RETURN + 0 If key is equal + 1 Key has changed +*/ -int key_cmp(TABLE *table,const byte *key,uint idx,uint key_length) +bool key_cmp_if_same(TABLE *table,const byte *key,uint idx,uint key_length) { uint length; KEY_PART_INFO *key_part; @@ -281,3 +300,56 @@ bool check_if_key_used(TABLE *table, uint idx, List<Item> &fields) return check_if_key_used(table, table->primary_key, fields); return 0; } + + +/* + Compare key in row to a given key + + SYNOPSIS + key_cmp() + key_part Key part handler + key Key to compare to value in table->record[0] + key_length length of 'key' + + RETURN + The return value is SIGN(key_in_row - range_key): + + 0 Key is equal to range or 'range' == 0 (no range) + -1 Key is less than range + 1 Key is larger than range +*/ + +int key_cmp(KEY_PART_INFO *key_part, const byte *key, uint key_length) +{ + uint store_length; + + for (const byte *end=key + key_length; + key < end; + key+= store_length, key_part++) + { + int cmp; + store_length= key_part->store_length; + if (key_part->null_bit) + { + /* This key part allows null values; NULL is lower than everything */ + register bool field_is_null= key_part->field->is_null(); + if (*key) // If range key is null + { + /* the range is expecting a null value */ + if (!field_is_null) + return 1; // Found key is > range + /* null -- exact match, go to next key part */ + continue; + } + else if (field_is_null) + return -1; // NULL is less than any value + key++; // Skip null byte + store_length--; + } + if ((cmp=key_part->field->key_cmp((byte*) key, key_part->length)) < 0) + return -1; + if (cmp > 0) + return 1; + } + return 0; // Keys are equal +} diff --git a/sql/log_event.cc b/sql/log_event.cc index b3ec1f0fe55..abbccb32034 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -1058,6 +1058,7 @@ end: VOID(pthread_mutex_lock(&LOCK_thread_count)); thd->db= 0; // prevent db from being freed thd->query= 0; // just to be sure + thd->query_length= 0; VOID(pthread_mutex_unlock(&LOCK_thread_count)); // assume no convert for next query unless set explictly #ifdef TO_BE_REMOVED @@ -1674,6 +1675,7 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli, thd->db= (char*) rewrite_db(db); DBUG_ASSERT(thd->query == 0); thd->query= 0; // Should not be needed + thd->query_length= 0; // Should not be needed thd->query_error= 0; clear_all_errors(thd, rli); if (!use_rli_only_for_errors) diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 8cae95e5070..14bd16332ef 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -754,11 +754,12 @@ void mysql_print_status(THD *thd); int find_ref_key(TABLE *form,Field *field, uint *offset); void key_copy(byte *key,TABLE *form,uint index,uint key_length); void key_restore(TABLE *form,byte *key,uint index,uint key_length); -int key_cmp(TABLE *form,const byte *key,uint index,uint key_length); +bool key_cmp_if_same(TABLE *form,const byte *key,uint index,uint key_length); void key_unpack(String *to,TABLE *form,uint index); bool check_if_key_used(TABLE *table, uint idx, List<Item> &fields); -bool init_errmessage(void); +int key_cmp(KEY_PART_INFO *key_part, const byte *key, uint key_length); +bool init_errmessage(void); void sql_perror(const char *message); void sql_print_error(const char *format,...) __attribute__ ((format (printf, 1, 2))); diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 1e7bf90738c..3cc64c35223 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -1800,8 +1800,8 @@ SEL_ARG * SEL_ARG::insert(SEL_ARG *key) { SEL_ARG *element,**par,*last_element; - LINT_INIT(par); LINT_INIT(last_element); + for (element= this; element != &null_element ; ) { last_element=element; @@ -2296,26 +2296,32 @@ check_quick_keys(PARAM *param,uint idx,SEL_ARG *key_tree, { if (tmp_min_flag & GEOM_FLAG) { - tmp= param->table->file-> - records_in_range((int) keynr, (byte*)(param->min_key), - min_key_length, - (ha_rkey_function)(tmp_min_flag ^ GEOM_FLAG), - (byte *)NullS, 0, HA_READ_KEY_EXACT); + key_range min_range; + min_range.key= (byte*) param->min_key; + min_range.length= min_key_length; + /* In this case tmp_min_flag contains the handler-read-function */ + min_range.flag= (ha_rkey_function) (tmp_min_flag ^ GEOM_FLAG); + + tmp= param->table->file->records_in_range(keynr, &min_range, + (key_range*) 0); } else { - tmp=param->table->file-> - records_in_range((int) keynr, - (byte*) (!min_key_length ? NullS : - param->min_key), - min_key_length, - tmp_min_flag & NEAR_MIN ? - HA_READ_AFTER_KEY : HA_READ_KEY_EXACT, - (byte*) (!max_key_length ? NullS : - param->max_key), - max_key_length, - (tmp_max_flag & NEAR_MAX ? - HA_READ_BEFORE_KEY : HA_READ_AFTER_KEY)); + key_range min_range, max_range; + + min_range.key= (byte*) param->min_key; + min_range.length= min_key_length; + min_range.flag= (tmp_min_flag & NEAR_MIN ? HA_READ_AFTER_KEY : + HA_READ_KEY_EXACT); + max_range.key= param->max_key; + max_range.length= max_key_length; + max_range.flag= (tmp_max_flag & NEAR_MAX ? + HA_READ_BEFORE_KEY : HA_READ_AFTER_KEY); + tmp=param->table->file->records_in_range(keynr, + (min_key_length ? &min_range : + (key_range*) 0), + (max_key_length ? &max_range : + (key_range*) 0)); } } end: @@ -2604,7 +2610,7 @@ int QUICK_SELECT::get_next() if (range) { // Already read through key - result= file->read_range_next(test(range->flag & EQ_RANGE)); + result= file->read_range_next(); if (result != HA_ERR_END_OF_FILE) DBUG_RETURN(result); } @@ -2628,6 +2634,7 @@ int QUICK_SELECT::get_next() result= file->read_range_first(range->min_length ? &start_key : 0, range->max_length ? &end_key : 0, + test(range->flag & EQ_RANGE), sorted); if (range->flag == (UNIQUE_RANGE | EQ_RANGE)) range=0; // Stop searching @@ -2815,40 +2822,14 @@ int QUICK_SELECT_DESC::get_next() int QUICK_SELECT_DESC::cmp_prev(QUICK_RANGE *range_arg) { + int cmp; if (range_arg->flag & NO_MIN_RANGE) return 0; /* key can't be to small */ - KEY_PART *key_part = key_parts; - uint store_length; - - for (char *key = range_arg->min_key, *end = key + range_arg->min_length; - key < end; - key += store_length, key_part++) - { - int cmp; - store_length= key_part->store_length; - if (key_part->null_bit) - { - // this key part allows null values; NULL is lower than everything else - if (*key) - { - // the range is expecting a null value - if (!key_part->field->is_null()) - return 0; // not null -- still inside the range - continue; // null -- exact match, go to next key part - } - else if (key_part->field->is_null()) - return 1; // null -- outside the range - key++; - store_length--; - } - if ((cmp = key_part->field->key_cmp((byte*) key, - key_part->length)) > 0) - return 0; - if (cmp < 0) - return 1; - } - return (range_arg->flag & NEAR_MIN) ? 1 : 0; // Exact match + cmp= key_cmp(key_part_info, range_arg->min_key, range_arg->min_length); + if (cmp > 0 || cmp == 0 && !(range_arg->flag & NEAR_MIN)) + return 0; + return 1; // outside of range } diff --git a/sql/opt_range.h b/sql/opt_range.h index 2df9d93e1ef..2072ded15d1 100644 --- a/sql/opt_range.h +++ b/sql/opt_range.h @@ -80,13 +80,18 @@ public: MEM_ROOT alloc; KEY_PART *key_parts; + KEY_PART_INFO *key_part_info; ha_rows records; double read_time; QUICK_SELECT(THD *thd, TABLE *table,uint index_arg,bool no_alloc=0); virtual ~QUICK_SELECT(); void reset(void) { next=0; it.rewind(); } - int init() { return error=file->index_init(index); } + int init() + { + key_part_info= head->key_info[index].key_part; + return error=file->index_init(index); + } virtual int get_next(); virtual bool reverse_sorted() { return 0; } bool unique_key_range(); diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc index 4fdcd093132..8c1cd9ce1cb 100644 --- a/sql/opt_sum.cc +++ b/sql/opt_sum.cc @@ -716,7 +716,7 @@ static bool find_key_for_maxmin(bool max_fl, TABLE_REF *ref, static int reckey_in_range(bool max_fl, TABLE_REF *ref, Field* field, COND *cond, uint range_fl, uint prefix_len) { - if (key_cmp(field->table, ref->key_buff, ref->key, prefix_len)) + if (key_cmp_if_same(field->table, ref->key_buff, ref->key, prefix_len)) return 1; if (!cond || (range_fl & (max_fl ? NO_MIN_RANGE : NO_MAX_RANGE))) return 0; diff --git a/sql/slave.cc b/sql/slave.cc index 12fec28ec49..4ce8d5939bc 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -3156,6 +3156,7 @@ err: IO_RPL_LOG_NAME, llstr(mi->master_log_pos,llbuff)); VOID(pthread_mutex_lock(&LOCK_thread_count)); thd->query = thd->db = 0; // extra safety + thd->query_length = 0; VOID(pthread_mutex_unlock(&LOCK_thread_count)); if (mysql) { @@ -3321,6 +3322,7 @@ the slave SQL thread with \"SLAVE START\". We stopped at log \ err: VOID(pthread_mutex_lock(&LOCK_thread_count)); thd->query = thd->db = 0; // extra safety + thd->query_length = 0; VOID(pthread_mutex_unlock(&LOCK_thread_count)); thd->proc_info = "Waiting for slave mutex on exit"; pthread_mutex_lock(&rli->run_lock); diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 880b6eb74ee..fbd47d4954d 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -1820,7 +1820,7 @@ GRANT_TABLE::GRANT_TABLE(TABLE *form, TABLE *col_privs) } my_hash_insert(&hash_columns, (byte *) mem_check); } while (!col_privs->file->index_next(col_privs->record[0]) && - !key_cmp(col_privs,key,0,key_len)); + !key_cmp_if_same(col_privs,key,0,key_len)); } } @@ -2043,7 +2043,7 @@ static int replace_column_table(GRANT_TABLE *g_t, } } } while (!table->file->index_next(table->record[0]) && - !key_cmp(table,key,0,key_length)); + !key_cmp_if_same(table,key,0,key_length)); } end: diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 14a54a410a2..e3fbfb2d0e3 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2103,7 +2103,9 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter, => we have to check presence of name before compare */ if (item_field->name && - !my_strcasecmp(system_charset_info, item_field->name, field_name)) + (!my_strcasecmp(system_charset_info, item_field->name, field_name) || + !my_strcasecmp(system_charset_info, + item_field->field_name, field_name))) { if (!table_name) { diff --git a/sql/sql_class.h b/sql/sql_class.h index e602b7d6d5f..2566385a6d9 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -598,7 +598,24 @@ public: struct rand_struct rand; // used for authentication struct system_variables variables; // Changeable local variables pthread_mutex_t LOCK_delete; // Locked before thd is deleted - + /* + Note that (A) if we set query = NULL, we must at the same time set + query_length = 0, and protect the whole operation with the + LOCK_thread_count mutex. And (B) we are ONLY allowed to set query to a + non-NULL value if its previous value is NULL. We do not need to protect + operation (B) with any mutex. To avoid crashes in races, if we do not + know that thd->query cannot change at the moment, one should print + thd->query like this: + (1) reserve the LOCK_thread_count mutex; + (2) check if thd->query is NULL; + (3) if not NULL, then print at most thd->query_length characters from + it. We will see the query_length field as either 0, or the right value + for it. + Assuming that the write and read of an n-bit memory field in an n-bit + computer is atomic, we can avoid races in the above way. + This printing is needed at least in SHOW PROCESSLIST and SHOW INNODB + STATUS. + */ /* all prepared statements and cursors of this connection */ Statement_map stmt_map; /* diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index e949d40625d..f2458068633 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1475,9 +1475,9 @@ bool dispatch_command(enum enum_server_command command, THD *thd, packet++; length--; } + VOID(pthread_mutex_lock(&LOCK_thread_count)); thd->query_length= length; thd->query= packet; - VOID(pthread_mutex_lock(&LOCK_thread_count)); thd->query_id= query_id++; VOID(pthread_mutex_unlock(&LOCK_thread_count)); #ifndef EMBEDDED_LIBRARY @@ -1768,6 +1768,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thd->proc_info=0; thd->command=COM_SLEEP; thd->query=0; + thd->query_length=0; thread_running--; VOID(pthread_mutex_unlock(&LOCK_thread_count)); thd->packet.shrink(thd->variables.net_buffer_length); // Reclaim some memory @@ -1807,6 +1808,7 @@ bool alloc_query(THD *thd, char *packet, ulong packet_length) packet_length--; } /* We must allocate some extra memory for query cache */ + thd->query_length= 0; // Extra safety: Avoid races if (!(thd->query= (char*) thd->memdup_w_gap((gptr) (packet), packet_length, thd->db_length+ 1 + diff --git a/sql/sql_select.cc b/sql/sql_select.cc index a89ef6b05ea..4325edc3502 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -6160,8 +6160,8 @@ join_read_prev_same(READ_RECORD *info) if ((error=table->file->index_prev(table->record[0]))) return report_error(table, error); - if (key_cmp(table, tab->ref.key_buff, tab->ref.key, - tab->ref.key_length)) + if (key_cmp_if_same(table, tab->ref.key_buff, tab->ref.key, + tab->ref.key_length)) { table->status=STATUS_NOT_FOUND; error= -1; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 51b44af63ec..80634c68ac7 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1597,10 +1597,13 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) thd_info->query=0; if (tmp->query) { - /* query_length is always set before tmp->query */ + /* + query_length is always set to 0 when we set query = NULL; see + the comment in sql_class.h why this prevents crashes in possible + races with query_length + */ uint length= min(max_query_length, tmp->query_length); - thd_info->query=(char*) thd->memdup(tmp->query,length+1); - thd_info->query[length]=0; + thd_info->query=(char*) thd->strmake(tmp->query,length); } thread_infos.append(thd_info); } |