From 45485da7027b5cd65bfdb569fa046f91547c302f Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 12 Jul 2004 14:12:53 +0300 Subject: [PATCH 01/12] srv0start.c: innobase_start_or_create_for_mysql(): Rename innodb.status. to innodb_status. to avoid problems on VMS innobase/srv/srv0start.c: innobase_start_or_create_for_mysql(): Rename innodb.status. to innodb_status. to avoid problems on VMS --- innobase/srv/srv0start.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/innobase/srv/srv0start.c b/innobase/srv/srv0start.c index 0fb8da9fe3a..3223854652f 100644 --- a/innobase/srv/srv0start.c +++ b/innobase/srv/srv0start.c @@ -1026,7 +1026,7 @@ NetWare. */ srv_monitor_file_name = mem_alloc( strlen(fil_path_to_mysql_datadir) + 20 + sizeof "/innodb_status."); - sprintf(srv_monitor_file_name, "%s/innodb.status.%lu", + sprintf(srv_monitor_file_name, "%s/innodb_status.%lu", fil_path_to_mysql_datadir, os_proc_get_number()); srv_monitor_file = fopen(srv_monitor_file_name, "w+"); if (!srv_monitor_file) { From 7b6fc58ffff432df623d78511eab7e19ddb32f50 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 12 Jul 2004 15:13:18 +0300 Subject: [PATCH 02/12] InnoDB: Increment the lock wait watchdog timeout during CHECK TABLE (Bug #2694) innobase/include/srv0srv.h: Add srv_fatal_semaphore_wait_threshold innobase/include/sync0arr.h: Improve comment of sync_array_print_long_waits() innobase/row/row0mysql.c: Lengthen the srv_fatal_semaphore_wait_threshold by 2 hours during CHECK TABLE innobase/srv/srv0srv.c: Add srv_fatal_semaphore_wait_threshold innobase/sync/sync0arr.c: Improve comment of sync_array_print_long_waits(). Replace the fixed timeout of 600 seconds with srv_fatal_semaphore_wait_threshold. --- innobase/include/srv0srv.h | 1 + innobase/include/sync0arr.h | 2 +- innobase/row/row0mysql.c | 12 +++++++++++- innobase/srv/srv0srv.c | 3 +++ innobase/sync/sync0arr.c | 12 +++++++----- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/innobase/include/srv0srv.h b/innobase/include/srv0srv.h index 40a96e79973..0be13528fd7 100644 --- a/innobase/include/srv0srv.h +++ b/innobase/include/srv0srv.h @@ -149,6 +149,7 @@ extern ulint srv_test_n_mutexes; extern ulint srv_test_array_size; extern ulint srv_activity_count; +extern ulint srv_fatal_semaphore_wait_threshold; extern mutex_t* kernel_mutex_temp;/* mutex protecting the server, trx structs, query threads, and lock table: we allocate diff --git a/innobase/include/sync0arr.h b/innobase/include/sync0arr.h index 383d0c69fb2..4324f2d3f2c 100644 --- a/innobase/include/sync0arr.h +++ b/innobase/include/sync0arr.h @@ -95,7 +95,7 @@ void sync_arr_wake_threads_if_sema_free(void); /*====================================*/ /************************************************************************** -Prints warnings of long semaphore waits to stderr. Currently > 120 sec. */ +Prints warnings of long semaphore waits to stderr. */ void sync_array_print_long_waits(void); diff --git a/innobase/row/row0mysql.c b/innobase/row/row0mysql.c index b7779e5b7a3..e559ef739cc 100644 --- a/innobase/row/row0mysql.c +++ b/innobase/row/row0mysql.c @@ -2805,7 +2805,12 @@ row_check_table_for_mysql( REPEATABLE READ here */ prebuilt->trx->isolation_level = TRX_ISO_REPEATABLE_READ; - + + /* Enlarge the fatal lock wait timeout during CHECK TABLE. */ + mutex_enter(&kernel_mutex); + srv_fatal_semaphore_wait_threshold += 7200; /* 2 hours */ + mutex_exit(&kernel_mutex); + index = dict_table_get_first_index(table); while (index != NULL) { @@ -2853,6 +2858,11 @@ row_check_table_for_mysql( ret = DB_ERROR; } + /* Restore the fatal lock wait timeout after CHECK TABLE. */ + mutex_enter(&kernel_mutex); + srv_fatal_semaphore_wait_threshold -= 7200; /* 2 hours */ + mutex_exit(&kernel_mutex); + prebuilt->trx->op_info = (char *) ""; return(ret); diff --git a/innobase/srv/srv0srv.c b/innobase/srv/srv0srv.c index a78bd0d864c..174214f9efe 100644 --- a/innobase/srv/srv0srv.c +++ b/innobase/srv/srv0srv.c @@ -55,6 +55,9 @@ ibool srv_lower_case_table_names = FALSE; in the server */ ulint srv_activity_count = 0; +/* The following is the maximum allowed duration of a lock wait. */ +ulint srv_fatal_semaphore_wait_threshold = 600; + ibool srv_lock_timeout_and_monitor_active = FALSE; ibool srv_error_monitor_active = FALSE; diff --git a/innobase/sync/sync0arr.c b/innobase/sync/sync0arr.c index 944503aa0e2..176aedb6ae3 100644 --- a/innobase/sync/sync0arr.c +++ b/innobase/sync/sync0arr.c @@ -890,7 +890,7 @@ sync_arr_wake_threads_if_sema_free(void) } /************************************************************************** -Prints warnings of long semaphore waits to stderr. Currently > 120 sec. */ +Prints warnings of long semaphore waits to stderr. */ void sync_array_print_long_waits(void) @@ -900,6 +900,7 @@ sync_array_print_long_waits(void) ibool old_val; ibool noticed = FALSE; ulint i; + ulint fatal_timeout = srv_fatal_semaphore_wait_threshold; for (i = 0; i < sync_primary_wait_array->n_cells; i++) { @@ -914,12 +915,13 @@ sync_array_print_long_waits(void) } if (cell->wait_object != NULL - && difftime(time(NULL), cell->reservation_time) > 600) { + && difftime(time(NULL), cell->reservation_time) + > fatal_timeout) { - fputs( -"InnoDB: Error: semaphore wait has lasted > 600 seconds\n" + fprintf(stderr, +"InnoDB: Error: semaphore wait has lasted > %lu seconds\n" "InnoDB: We intentionally crash the server, because it appears to be hung.\n", - stderr); + fatal_timeout); ut_error; } From fbc420ba0ee7bcd951a44aefff4c771578bc9ac2 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 12 Jul 2004 16:47:22 +0300 Subject: [PATCH 03/12] InnoDB: LOCK TABLE clean-up innobase/include/lock0lock.h: Improve comments regarding LOCK_TABLE_EXP innobase/include/row0mysql.h: Rename row_unlock_table_for_mysql() to row_unlock_tables_for_mysql() and improve its comment innobase/include/trx0trx.h: Rename n_tables_locked to n_lock_table_exp innobase/lock/lock0lock.c: Rename n_tables_locked to n_lock_table_exp Increment n_lock_table_exp already in lock_table_create() Replace some ut_ad() assertions with ut_a() innobase/row/row0mysql.c: Rename n_tables_locked to n_lock_table_exp Rename row_unlock_table_for_mysql() to row_unlock_tables_for_mysql() and improve its comment innobase/trx/trx0trx.c: Rename n_tables_locked to n_lock_table_exp sql/ha_innodb.cc: Rename n_tables_locked to n_lock_table_exp Rename row_unlock_table_for_mysql() to row_unlock_tables_for_mysql() --- innobase/include/lock0lock.h | 5 +++-- innobase/include/row0mysql.h | 7 ++++--- innobase/include/trx0trx.h | 5 +++-- innobase/lock/lock0lock.c | 32 +++++++++++++++++--------------- innobase/row/row0mysql.c | 9 +++++---- innobase/trx/trx0trx.c | 4 ++-- sql/ha_innodb.cc | 4 ++-- 7 files changed, 36 insertions(+), 30 deletions(-) diff --git a/innobase/include/lock0lock.h b/innobase/include/lock0lock.h index 9c5f35c6674..9f525042dcc 100644 --- a/innobase/include/lock0lock.h +++ b/innobase/include/lock0lock.h @@ -418,7 +418,8 @@ lock_release_off_kernel( /*====================*/ trx_t* trx); /* in: transaction */ /************************************************************************* -Releases table locks, and releases possible other transactions waiting +Releases table locks explicitly requested with LOCK TABLES (indicated by +lock type LOCK_TABLE_EXP), and releases possible other transactions waiting because of these locks. */ void @@ -548,7 +549,7 @@ extern lock_sys_t* lock_sys; /* Lock types */ #define LOCK_TABLE 16 /* these type values should be so high that */ #define LOCK_REC 32 /* they can be ORed to the lock mode */ -#define LOCK_TABLE_EXP 80 /* explicit table lock */ +#define LOCK_TABLE_EXP 80 /* explicit table lock (80 = 16 + 64) */ #define LOCK_TYPE_MASK 0xF0UL /* mask used to extract lock type from the type_mode field in a lock */ /* Waiting lock flag */ diff --git a/innobase/include/row0mysql.h b/innobase/include/row0mysql.h index e088071a1c4..0ab70db2dea 100644 --- a/innobase/include/row0mysql.h +++ b/innobase/include/row0mysql.h @@ -153,11 +153,12 @@ row_lock_table_autoinc_for_mysql( row_prebuilt_t* prebuilt); /* in: prebuilt struct in the MySQL table handle */ /************************************************************************* -Unlocks a table lock possibly reserved by trx. */ +Unlocks all table locks explicitly requested by trx (with LOCK TABLES, +lock type LOCK_TABLE_EXP). */ void -row_unlock_table_for_mysql( -/*=======================*/ +row_unlock_tables_for_mysql( +/*========================*/ trx_t* trx); /* in: transaction */ /************************************************************************* Sets a table lock on the table mentioned in prebuilt. */ diff --git a/innobase/include/trx0trx.h b/innobase/include/trx0trx.h index 07d5e5a8215..3be16e8f46d 100644 --- a/innobase/include/trx0trx.h +++ b/innobase/include/trx0trx.h @@ -423,8 +423,9 @@ struct trx_struct{ lock_t* auto_inc_lock; /* possible auto-inc lock reserved by the transaction; note that it is also in the lock list trx_locks */ - ulint n_tables_locked;/* number of table locks reserved by - the transaction, stored in trx_locks */ + ulint n_lock_table_exp;/* number of explicit table locks + (LOCK TABLES) reserved by the + transaction, stored in trx_locks */ UT_LIST_NODE_T(trx_t) trx_list; /* list of transactions */ UT_LIST_NODE_T(trx_t) diff --git a/innobase/lock/lock0lock.c b/innobase/lock/lock0lock.c index 11bd1f93808..1c82d892d5f 100644 --- a/innobase/lock/lock0lock.c +++ b/innobase/lock/lock0lock.c @@ -2023,9 +2023,8 @@ lock_grant( lock->trx->auto_inc_lock = lock; } else if (lock_get_type(lock) == LOCK_TABLE_EXP) { - ut_ad(lock_get_mode(lock) == LOCK_S + ut_a(lock_get_mode(lock) == LOCK_S || lock_get_mode(lock) == LOCK_X); - lock->trx->n_tables_locked++; } if (lock_print_waits) { @@ -3203,6 +3202,10 @@ lock_table_create( lock->type_mode = type_mode | LOCK_TABLE; lock->trx = trx; + if ((lock->type_mode & LOCK_TABLE_EXP) == LOCK_TABLE_EXP) { + lock->trx->n_lock_table_exp++; + } + lock->un_member.tab_lock.table = table; UT_LIST_ADD_LAST(un_member.tab_lock.locks, table->locks, lock); @@ -3386,7 +3389,7 @@ lock_table( return(DB_SUCCESS); } - ut_ad(flags == 0 || flags == LOCK_TABLE_EXP); + ut_a(flags == 0 || flags == LOCK_TABLE_EXP); trx = thr_get_trx(thr); @@ -3418,10 +3421,7 @@ lock_table( lock_table_create(table, mode | flags, trx); - if (flags) { - ut_ad(mode == LOCK_S || mode == LOCK_X); - trx->n_tables_locked++; - } + ut_a(!flags || mode == LOCK_S || mode == LOCK_X); lock_mutex_exit_kernel(); @@ -3502,7 +3502,7 @@ lock_table_dequeue( #ifdef UNIV_SYNC_DEBUG ut_ad(mutex_own(&kernel_mutex)); #endif /* UNIV_SYNC_DEBUG */ - ut_ad(lock_get_type(in_lock) == LOCK_TABLE || + ut_a(lock_get_type(in_lock) == LOCK_TABLE || lock_get_type(in_lock) == LOCK_TABLE_EXP); lock = UT_LIST_GET_NEXT(un_member.tab_lock.locks, in_lock); @@ -3607,9 +3607,9 @@ lock_release_off_kernel( lock_table_dequeue(lock); if (lock_get_type(lock) == LOCK_TABLE_EXP) { - ut_ad(lock_get_mode(lock) == LOCK_S + ut_a(lock_get_mode(lock) == LOCK_S || lock_get_mode(lock) == LOCK_X); - trx->n_tables_locked--; + trx->n_lock_table_exp--; } } @@ -3630,11 +3630,12 @@ lock_release_off_kernel( mem_heap_empty(trx->lock_heap); ut_a(trx->auto_inc_lock == NULL); - ut_a(trx->n_tables_locked == 0); + ut_a(trx->n_lock_table_exp == 0); } /************************************************************************* -Releases table locks, and releases possible other transactions waiting +Releases table locks explicitly requested with LOCK TABLES (indicated by +lock type LOCK_TABLE_EXP), and releases possible other transactions waiting because of these locks. */ void @@ -3659,7 +3660,7 @@ lock_release_tables_off_kernel( count++; if (lock_get_type(lock) == LOCK_TABLE_EXP) { - ut_ad(lock_get_mode(lock) == LOCK_S + ut_a(lock_get_mode(lock) == LOCK_S || lock_get_mode(lock) == LOCK_X); if (trx->insert_undo || trx->update_undo) { @@ -3675,7 +3676,8 @@ lock_release_tables_off_kernel( } lock_table_dequeue(lock); - trx->n_tables_locked--; + trx->n_lock_table_exp--; + lock = UT_LIST_GET_LAST(trx->trx_locks); continue; } @@ -3696,7 +3698,7 @@ lock_release_tables_off_kernel( mem_heap_empty(trx->lock_heap); - ut_a(trx->n_tables_locked == 0); + ut_a(trx->n_lock_table_exp == 0); } /************************************************************************* diff --git a/innobase/row/row0mysql.c b/innobase/row/row0mysql.c index e559ef739cc..98ab1a1e754 100644 --- a/innobase/row/row0mysql.c +++ b/innobase/row/row0mysql.c @@ -723,14 +723,15 @@ run_again: } /************************************************************************* -Unlocks a table lock possibly reserved by trx. */ +Unlocks all table locks explicitly requested by trx (with LOCK TABLES, +lock type LOCK_TABLE_EXP). */ void -row_unlock_table_for_mysql( -/*=======================*/ +row_unlock_tables_for_mysql( +/*========================*/ trx_t* trx) /* in: transaction */ { - if (!trx->n_tables_locked) { + if (!trx->n_lock_table_exp) { return; } diff --git a/innobase/trx/trx0trx.c b/innobase/trx/trx0trx.c index 335e1f69228..576827966ab 100644 --- a/innobase/trx/trx0trx.c +++ b/innobase/trx/trx0trx.c @@ -151,7 +151,7 @@ trx_create( trx->n_tickets_to_enter_innodb = 0; trx->auto_inc_lock = NULL; - trx->n_tables_locked = 0; + trx->n_lock_table_exp = 0; trx->read_view_heap = mem_heap_create(256); trx->read_view = NULL; @@ -279,7 +279,7 @@ trx_free( ut_a(!trx->has_search_latch); ut_a(!trx->auto_inc_lock); - ut_a(!trx->n_tables_locked); + ut_a(!trx->n_lock_table_exp); ut_a(trx->dict_operation_lock_mode == 0); diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index df193bde947..21dd7f748c2 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -4656,8 +4656,8 @@ ha_innobase::external_lock( trx->n_mysql_tables_in_use--; prebuilt->mysql_has_locked = FALSE; auto_inc_counter_for_this_stat = 0; - if (trx->n_tables_locked) { - row_unlock_table_for_mysql(trx); + if (trx->n_lock_table_exp) { + row_unlock_tables_for_mysql(trx); } /* If the MySQL lock count drops to zero we know that the current SQL From 63c915c7b96c0d1a8429938b1ce59a3ff191f9ca Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 12 Jul 2004 17:14:13 +0300 Subject: [PATCH 04/12] InnoDB: LOCK TABLES clean-up, part 2 innobase/lock/lock0lock.c: Decrement n_lock_table_exp in lock_table_dequeue(), not elsewhere --- innobase/lock/lock0lock.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/innobase/lock/lock0lock.c b/innobase/lock/lock0lock.c index 1c82d892d5f..bc03a27c874 100644 --- a/innobase/lock/lock0lock.c +++ b/innobase/lock/lock0lock.c @@ -3508,6 +3508,10 @@ lock_table_dequeue( lock = UT_LIST_GET_NEXT(un_member.tab_lock.locks, in_lock); lock_table_remove_low(in_lock); + + if (lock_get_type(in_lock) == LOCK_TABLE_EXP) { + in_lock->trx->n_lock_table_exp--; + } /* Check if waiting locks in the queue can now be granted: grant locks if there are no conflicting locks ahead. */ @@ -3609,7 +3613,6 @@ lock_release_off_kernel( if (lock_get_type(lock) == LOCK_TABLE_EXP) { ut_a(lock_get_mode(lock) == LOCK_S || lock_get_mode(lock) == LOCK_X); - trx->n_lock_table_exp--; } } @@ -3676,7 +3679,6 @@ lock_release_tables_off_kernel( } lock_table_dequeue(lock); - trx->n_lock_table_exp--; lock = UT_LIST_GET_LAST(trx->trx_locks); continue; From 7ee050590f6775254185ffa7cff52adffd3a3bfb Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 13 Jul 2004 12:30:34 +0300 Subject: [PATCH 05/12] lock0lock.c: Decrement n_lock_table_exp in lock_table_remove_low() instead of lock_table_dequeue(). Do not empty lock_heap in lock_release_tables_off_kernel(). innobase/lock/lock0lock.c: Decrement n_lock_table_exp in lock_table_remove_low() instead of lock_table_dequeue(). Do not empty lock_heap in lock_release_tables_off_kernel(). --- innobase/lock/lock0lock.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/innobase/lock/lock0lock.c b/innobase/lock/lock0lock.c index bc03a27c874..68dd2aa18c1 100644 --- a/innobase/lock/lock0lock.c +++ b/innobase/lock/lock0lock.c @@ -3202,7 +3202,7 @@ lock_table_create( lock->type_mode = type_mode | LOCK_TABLE; lock->trx = trx; - if ((lock->type_mode & LOCK_TABLE_EXP) == LOCK_TABLE_EXP) { + if (lock_get_type(lock) == LOCK_TABLE_EXP) { lock->trx->n_lock_table_exp++; } @@ -3241,7 +3241,11 @@ lock_table_remove_low( if (lock == trx->auto_inc_lock) { trx->auto_inc_lock = NULL; } - + + if (lock_get_type(lock) == LOCK_TABLE_EXP) { + lock->trx->n_lock_table_exp--; + } + UT_LIST_REMOVE(trx_locks, trx->trx_locks, lock); UT_LIST_REMOVE(un_member.tab_lock.locks, table->locks, lock); } @@ -3509,10 +3513,6 @@ lock_table_dequeue( lock_table_remove_low(in_lock); - if (lock_get_type(in_lock) == LOCK_TABLE_EXP) { - in_lock->trx->n_lock_table_exp--; - } - /* Check if waiting locks in the queue can now be granted: grant locks if there are no conflicting locks ahead. */ @@ -3698,8 +3698,6 @@ lock_release_tables_off_kernel( lock = UT_LIST_GET_PREV(trx_locks, lock); } - mem_heap_empty(trx->lock_heap); - ut_a(trx->n_lock_table_exp == 0); } From 1e23a0efef15a81e1212541c1f745bbeeac8e3b8 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 13 Jul 2004 13:54:20 +0300 Subject: [PATCH 06/12] A fix for a long standing bug in LOAD DATA .. LOCAL ..' sql/sql_load.cc: A fix for a long standing bug in LOAD DATA .. LOCAL ..' When the error occurs, a link is broken instead of simply returning the error message and maintaining the same connection. --- sql/sql_load.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sql/sql_load.cc b/sql/sql_load.cc index a3ba14373b2..501852b5de8 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -291,6 +291,9 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, { if (transactional_table) ha_autocommit_or_rollback(thd,error); + if (read_file_from_client) + while (!read_info.next_line()) + ; if (mysql_bin_log.is_open()) { /* From d2415e8188302a6ccbc3414896405dabed9691eb Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 13 Jul 2004 21:03:30 +0200 Subject: [PATCH 07/12] - Move checking of the MD5 checksumming to the correct place - fix calling of my_md5sum --- Build-tools/Do-compile | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Build-tools/Do-compile b/Build-tools/Do-compile index 40a5cf38121..1650e3d4a09 100755 --- a/Build-tools/Do-compile +++ b/Build-tools/Do-compile @@ -169,6 +169,17 @@ info("PATH is $ENV{PATH}"); log_timestamp(); +$md5_result= safe_system("perl $ENV{HOME}/my_md5sum -c ${opt_distribution}.md5"); + +if ($md5_result != 0) +{ + abort("MD5 check failed for $opt_distribution!"); +} +else +{ + info("SUCCESS: MD5 checks for $opt_distribution"); +} + if (-x "$host/bin/mysqladmin") { log_system("$host/bin/mysqladmin $mysqladmin_args -S $mysql_unix_port -s shutdown"); @@ -202,17 +213,6 @@ if ($opt_stage == 0) safe_cd($host); if ($opt_stage == 0 && ! $opt_use_old_distribution) { - $md5_result= safe_system("./my_md5sum -c ${opt_distribution}.md5"); - - if ($md5_result != 0) - { - abort("MD5 failed for $opt_distribution!"); - } - else - { - info("SUCCESS: MD5 checks for $opt_distribution"); - } - safe_system("gunzip < $opt_distribution | $tar xf -"); # Fix file times; This is needed because the time for files may be @@ -332,7 +332,9 @@ $tar_file=<$pwd/$host/mysql*.t*gz>; abort ("Could not find tarball!") unless ($tar_file); # Generate the MD5 for the binary distribution -safe_system("./my_md5sum $tar_file > ${tar_file}.md5}"); +$tar_file=~ /(mysql[^\/]*)\.(tar\.gz|tgz)/; +$tar_file_lite= "$1.$2"; +system("cd $pwd/$host; perl $ENV{HOME}/my_md5sum $tar_file_lite > ${tar_file_lite}.md5"); # # Unpack the binary distribution From 9e6f619834527dfa031df16cf494765de3098720 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 15 Jul 2004 09:08:51 +0300 Subject: [PATCH 08/12] btr0cur.c: Do not add + 1 to the InnoDB index cardinality estimate if the B-tree just contains one page; the fix made in March 2004 caused InnoDB systematically to overestimate the cardinality of empty or small tables by 1 innobase/btr/btr0cur.c: Do not add + 1 to the InnoDB index cardinality estimate if the B-tree just contains one page; the fix made in March 2004 caused InnoDB systematically to overestimate the cardinality of empty or small tables by 1 --- innobase/btr/btr0cur.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/innobase/btr/btr0cur.c b/innobase/btr/btr0cur.c index 8974200efe8..b07b06765e6 100644 --- a/innobase/btr/btr0cur.c +++ b/innobase/btr/btr0cur.c @@ -2707,8 +2707,11 @@ btr_estimate_number_of_different_key_vals( rec = page_rec_get_next(rec); } + if (n_cols == dict_index_get_n_unique_in_tree(index)) { - /* We add one because we know that the first record + + /* If there is more than one leaf page in the tree, + we add one because we know that the first record on the page certainly had a different prefix than the last record on the previous index page in the alphabetical order. Before this fix, if there was @@ -2716,7 +2719,11 @@ btr_estimate_number_of_different_key_vals( algorithm grossly underestimated the number of rows in the table. */ - n_diff[n_cols]++; + if (btr_page_get_prev(page, &mtr) != FIL_NULL + || btr_page_get_next(page, &mtr) != FIL_NULL) { + + n_diff[n_cols]++; + } } total_external_size += From 139855210b9b1c8ce098ecc40bf66e0057d0c8df Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 15 Jul 2004 15:46:22 +0300 Subject: [PATCH 09/12] InnoDB: limit the recursion depth for ON (UPDATE|DELETE) CASCADE (Bug #4446) innobase/row/row0ins.c: row_ins_foreign_check_on_constraint(): limit recursion for UPDATE too mysql-test/r/innodb.result: Add test for recursion depth limit mysql-test/t/innodb.test: Add test for recursion depth limit --- innobase/row/row0ins.c | 78 +++++++++++++++++++++++++++++++------- mysql-test/r/innodb.result | 12 ++++++ mysql-test/t/innodb.test | 14 +++++++ 3 files changed, 91 insertions(+), 13 deletions(-) diff --git a/innobase/row/row0ins.c b/innobase/row/row0ins.c index 93d360eaaeb..458970da4e2 100644 --- a/innobase/row/row0ins.c +++ b/innobase/row/row0ins.c @@ -370,6 +370,32 @@ row_ins_cascade_ancestor_updates_table( return(FALSE); } +/************************************************************************* +Returns the number of ancestor UPDATE or DELETE nodes of a +cascaded update/delete node. */ +static +ulint +row_ins_cascade_n_ancestors( +/*========================*/ + /* out: number of ancestors */ + que_node_t* node) /* in: node in a query graph */ +{ + que_node_t* parent; + ulint n_ancestors = 0; + + parent = que_node_get_parent(node); + + while (que_node_get_type(parent) == QUE_NODE_UPDATE) { + n_ancestors++; + + parent = que_node_get_parent(parent); + + ut_a(parent); + } + + return(n_ancestors); +} + /********************************************************************** Calculates the update vector node->cascade->update for a child table in a cascaded update. */ @@ -615,6 +641,34 @@ row_ins_foreign_report_add_err( mutex_exit(&dict_foreign_err_mutex); } +/************************************************************************* +Invalidate the query cache for the given table. */ +static +void +row_ins_invalidate_query_cache( +/*===========================*/ + que_thr_t* thr, /* in: query thread whose run_node + is an update node */ + const char* name) /* in: table name prefixed with + database name and a '/' character */ +{ + char* buf; + char* ptr; + ulint len = strlen(name) + 1; + + buf = mem_strdupl(name, len); + + ptr = strchr(buf, '/'); + ut_a(ptr); + *ptr = '\0'; + + /* We call a function in ha_innodb.cc */ +#ifndef UNIV_HOTBACKUP + innobase_invalidate_query_cache(thr_get_trx(thr), buf, len); +#endif + mem_free(buf); +} + /************************************************************************* Perform referential actions or checks when a parent row is deleted or updated and the constraint had an ON DELETE or ON UPDATE condition which was not @@ -650,26 +704,14 @@ row_ins_foreign_check_on_constraint( ulint n_to_update; ulint err; ulint i; - char* ptr; - char table_name_buf[1000]; ut_a(thr && foreign && pcur && mtr); /* Since we are going to delete or update a row, we have to invalidate the MySQL query cache for table */ - ut_a(ut_strlen(table->name) < 998); - strcpy(table_name_buf, table->name); + row_ins_invalidate_query_cache(thr, table->name); - ptr = strchr(table_name_buf, '/'); - ut_a(ptr); - *ptr = '\0'; - - /* We call a function in ha_innodb.cc */ -#ifndef UNIV_HOTBACKUP - innobase_invalidate_query_cache(thr_get_trx(thr), table_name_buf, - ut_strlen(table->name) + 1); -#endif node = thr->run_node; if (node->is_delete && 0 == (foreign->type & @@ -756,6 +798,16 @@ row_ins_foreign_check_on_constraint( goto nonstandard_exit_func; } + if (row_ins_cascade_n_ancestors(cascade) >= 15) { + err = DB_ROW_IS_REFERENCED; + + row_ins_foreign_report_err( +(char*)"Trying a too deep cascaded delete or update\n", + thr, foreign, btr_pcur_get_rec(pcur), entry); + + goto nonstandard_exit_func; + } + index = btr_pcur_get_btr_cur(pcur)->index; ut_a(index == foreign->foreign_index); diff --git a/mysql-test/r/innodb.result b/mysql-test/r/innodb.result index 6a67bbc6f8b..c282ec68c78 100644 --- a/mysql-test/r/innodb.result +++ b/mysql-test/r/innodb.result @@ -1259,3 +1259,15 @@ Cannot delete or update a parent row: a foreign key constraint fails update t3 set t3.id=7 where t1.id =1 and t2.id = t1.id and t3.id = t2.id; Unknown table 't1' in where clause drop table t3,t2,t1; +create table t1( +id int primary key, +pid int, +index(pid), +foreign key(pid) references t1(id) on delete cascade) type=innodb; +insert into t1 values(0,0),(1,0),(2,1),(3,2),(4,3),(5,4),(6,5),(7,6), +(8,7),(9,8),(10,9),(11,10),(12,11),(13,12),(14,13),(15,14); +delete from t1 where id=0; +Cannot delete or update a parent row: a foreign key constraint fails +delete from t1 where id=15; +delete from t1 where id=0; +drop table t1; diff --git a/mysql-test/t/innodb.test b/mysql-test/t/innodb.test index 04642ddd619..34eabcc22df 100644 --- a/mysql-test/t/innodb.test +++ b/mysql-test/t/innodb.test @@ -896,3 +896,17 @@ update t1,t2,t3 set t3.id=5, t2.id=6, t1.id=7 where t1.id =1 and t2.id = t1.id --error 1109 update t3 set t3.id=7 where t1.id =1 and t2.id = t1.id and t3.id = t2.id; drop table t3,t2,t1; + +create table t1( + id int primary key, + pid int, + index(pid), + foreign key(pid) references t1(id) on delete cascade) type=innodb; +insert into t1 values(0,0),(1,0),(2,1),(3,2),(4,3),(5,4),(6,5),(7,6), + (8,7),(9,8),(10,9),(11,10),(12,11),(13,12),(14,13),(15,14); +-- error 1217 +delete from t1 where id=0; +delete from t1 where id=15; +delete from t1 where id=0; + +drop table t1; From cf8dbcc683b94b6e7f6c44d51b7241c45813decd Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 17 Jul 2004 16:58:16 +0200 Subject: [PATCH 10/12] Fixes for BUG#4506 "mysqlbinlog --position --read-from-remote-server has wrong "# at" lines", BUG#4553 "Multi-table DROP TABLE replicates improperly for nonexistent table" with a test file. It was not possible to add a test for BUG#4506 as in the test suite we must use --short-form which does not display the "# at" lines. client/mysqlbinlog.cc: Fix for BUG#4506 "mysqlbinlog --position --read-from-remote-server has wrong "# at" lines" when reading a remote binlog, the start position is not always BIN_LOG_HEADER_SIZE (4). sql/sql_table.cc: Fix for BUG#4553 "Multi-table DROP TABLE replicates improperly for nonexistent table" we must my_error() _before_ we write to the binlog, so that a meaningful error code is available in thd->net.last_errno for storage of the DROP TABLE statement into the binlog. --- client/mysqlbinlog.cc | 4 ++-- mysql-test/r/rpl_drop.result | 10 ++++++++++ mysql-test/t/rpl_drop.test | 10 ++++++++++ sql/sql_table.cc | 35 +++++++++++++++++++---------------- 4 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 mysql-test/r/rpl_drop.result create mode 100644 mysql-test/t/rpl_drop.test diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 7bceedea4fe..7c3d22c4900 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -723,8 +723,8 @@ static int dump_remote_log_entries(const char* logname) */ if (old_off) old_off+= len-1; - else - old_off= BIN_LOG_HEADER_SIZE; + else // first event, so it's a fake Rotate event + old_off= position; } return 0; } diff --git a/mysql-test/r/rpl_drop.result b/mysql-test/r/rpl_drop.result new file mode 100644 index 00000000000..ce1f5b6ee81 --- /dev/null +++ b/mysql-test/r/rpl_drop.result @@ -0,0 +1,10 @@ +slave stop; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +reset master; +reset slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +slave start; +drop table if exists t1, t2; +create table t1 (a int); +drop table t1, t2; +Unknown table 't2' diff --git a/mysql-test/t/rpl_drop.test b/mysql-test/t/rpl_drop.test new file mode 100644 index 00000000000..6fc2500fc97 --- /dev/null +++ b/mysql-test/t/rpl_drop.test @@ -0,0 +1,10 @@ +# Testcase for BUG#4552 (DROP on two tables, one of which does not +# exist, must be binlogged with a non-zero error code) +source include/master-slave.inc; +drop table if exists t1, t2; +create table t1 (a int); +--error 1051; +drop table t1, t2; +save_master_pos; +connection slave; +sync_with_master; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 1b956779832..9ab4859bc13 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -230,23 +230,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, wrong_tables.append(String(table->real_name)); } } - if (some_tables_deleted || tmp_table_deleted) - { - query_cache_invalidate3(thd, tables, 0); - if (!dont_log_query) - { - mysql_update_log.write(thd, thd->query,thd->query_length); - if (mysql_bin_log.is_open()) - { - thd->clear_error(); - Query_log_event qinfo(thd, thd->query, thd->query_length, - tmp_table_deleted && !some_tables_deleted); - mysql_bin_log.write(&qinfo); - } - } - } - unlock_table_names(thd, tables); error= 0; if (wrong_tables.length()) { @@ -256,6 +240,25 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, my_error(ER_ROW_IS_REFERENCED,MYF(0)); error= 1; } + + if (some_tables_deleted || tmp_table_deleted) + { + query_cache_invalidate3(thd, tables, 0); + if (!dont_log_query) + { + mysql_update_log.write(thd, thd->query,thd->query_length); + if (mysql_bin_log.is_open()) + { + if (!error) + thd->clear_error(); + Query_log_event qinfo(thd, thd->query, thd->query_length, + tmp_table_deleted && !some_tables_deleted); + mysql_bin_log.write(&qinfo); + } + } + } + + unlock_table_names(thd, tables); DBUG_RETURN(error); } From 382ff793bb52de384ce49074c61ce81fc2ce3236 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 18 Jul 2004 14:34:35 +0200 Subject: [PATCH 11/12] Fix for BUG#4551 "Temporary InnoDB tables not replicated properly with CREATE TABLE .. SELECT" The problem was that (for any storage engine), the created temporary table was not removed if CREATE SELECT failed (because of a constraint violation for example). This was not consistent with the manual and with CREATE SELECT (no TEMPORARY). sql/sql_insert.cc: Fix for BUG#4551 "Temporary InnoDB tables not replicated properly with CREATE TABLE .. SELECT" The problem was that (for any storage engine), the created temporary table was not removed if CREATE SELECT failed (because of a constraint violation for example). This was not consistent with the manual and with CREATE SELECT (no TEMPORARY). And it led to the above bug, because the binlogging of CREATE SELECT is done by select_insert::send_eof() (same function as INSERT SELECT) and so, if the table is transactional and there is a failure, the statement is considered as rolled back and so nothing is written in the binlog. So temp table MUST be deleted. --- mysql-test/r/create_select_tmp.result | 19 +++++++++++++++++++ mysql-test/t/create_select_tmp.test | 27 +++++++++++++++++++++++++++ sql/sql_insert.cc | 8 ++++++-- 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 mysql-test/r/create_select_tmp.result create mode 100644 mysql-test/t/create_select_tmp.test diff --git a/mysql-test/r/create_select_tmp.result b/mysql-test/r/create_select_tmp.result new file mode 100644 index 00000000000..610ee70b3e3 --- /dev/null +++ b/mysql-test/r/create_select_tmp.result @@ -0,0 +1,19 @@ +drop table if exists t1, t2; +CREATE TABLE t1 ( a int ); +INSERT INTO t1 VALUES (1),(2),(1); +CREATE TABLE t2 ( PRIMARY KEY (a) ) TYPE=INNODB SELECT a FROM t1; +Duplicate entry '1' for key 1 +select * from t2; +Table 'test.t2' doesn't exist +CREATE TEMPORARY TABLE t2 ( PRIMARY KEY (a) ) TYPE=INNODB SELECT a FROM t1; +Duplicate entry '1' for key 1 +select * from t2; +Table 'test.t2' doesn't exist +CREATE TABLE t2 ( PRIMARY KEY (a) ) TYPE=MYISAM SELECT a FROM t1; +Duplicate entry '1' for key 1 +select * from t2; +Table 'test.t2' doesn't exist +CREATE TEMPORARY TABLE t2 ( PRIMARY KEY (a) ) TYPE=MYISAM SELECT a FROM t1; +Duplicate entry '1' for key 1 +select * from t2; +Table 'test.t2' doesn't exist diff --git a/mysql-test/t/create_select_tmp.test b/mysql-test/t/create_select_tmp.test new file mode 100644 index 00000000000..36292abd899 --- /dev/null +++ b/mysql-test/t/create_select_tmp.test @@ -0,0 +1,27 @@ +# Testcase for BUG#4551 +# The bug was that when the table was TEMPORARY, it was not deleted if +# the CREATE SELECT failed (the code intended too, but it actually +# didn't). And as the CREATE TEMPORARY TABLE was not written to the +# binlog if it was a transactional table, it resulted in an +# inconsistency between binlog and the internal list of temp tables. + +-- source include/have_innodb.inc +drop table if exists t1, t2; +CREATE TABLE t1 ( a int ); +INSERT INTO t1 VALUES (1),(2),(1); +--error 1062; +CREATE TABLE t2 ( PRIMARY KEY (a) ) TYPE=INNODB SELECT a FROM t1; +--error 1146; +select * from t2; +--error 1062; +CREATE TEMPORARY TABLE t2 ( PRIMARY KEY (a) ) TYPE=INNODB SELECT a FROM t1; +--error 1146; +select * from t2; +--error 1062; +CREATE TABLE t2 ( PRIMARY KEY (a) ) TYPE=MYISAM SELECT a FROM t1; +--error 1146; +select * from t2; +--error 1062; +CREATE TEMPORARY TABLE t2 ( PRIMARY KEY (a) ) TYPE=MYISAM SELECT a FROM t1; +--error 1146; +select * from t2; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 94e2f8f8850..8912c1faf2a 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1545,9 +1545,13 @@ void select_create::abort() table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY); enum db_type table_type=table->db_type; if (!table->tmp_table) + { hash_delete(&open_cache,(byte*) table); - if (!create_info->table_existed) - quick_rm_table(table_type,db,name); + if (!create_info->table_existed) + quick_rm_table(table_type, db, name); + } + else if (!create_info->table_existed) + close_temporary_table(thd, db, name); table=0; } VOID(pthread_mutex_unlock(&LOCK_open)); From d0934eca168de02eff87eef7002fdf84d1a66d53 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 19 Jul 2004 12:32:36 +0200 Subject: [PATCH 12/12] - only include the GPL license in the LICENSE text, not the FOSS exception (it only applies to 4.0 and above) --- Docs/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Docs/Makefile.am b/Docs/Makefile.am index eea93380b35..5d66d236df1 100644 --- a/Docs/Makefile.am +++ b/Docs/Makefile.am @@ -139,7 +139,7 @@ INSTALL-BINARY: mysql.info $(GT) perl -w $(GT) mysql.info "Installing binary" "Installing source" > $@ ../COPYING: mysql.info $(GT) - perl -w $(GT) mysql.info "GPL license" "LGPL license" > $@ + perl -w $(GT) mysql.info "GPL license" "MySQL FOSS License Exception" > $@ # Don't update the files from bitkeeper %::SCCS/s.%