@ -5489,7 +5489,7 @@ ha_innobase::change_active_index(
dtuple_set_n_fields ( prebuilt - > search_tuple , prebuilt - > index - > n_fields ) ;
dict_index_copy_types ( prebuilt - > search_tuple , prebuilt - > index ,
prebuilt - > index - > n_fields ) ;
prebuilt - > index - > n_fields ) ;
/* MySQL changes the active index for a handle also during some
queries , for example SELECT MAX ( a ) , SUM ( a ) first retrieves the MAX ( )
@ -7626,8 +7626,13 @@ ha_innobase::check(
HA_CHECK_OPT * check_opt ) /*!< in: check options, currently
ignored */
{
ulint ret ;
dict_index_t * index ;
ulint n_rows ;
ulint n_rows_in_table = ULINT_UNDEFINED ;
ibool is_ok = TRUE ;
ulint old_isolation_level ;
DBUG_ENTER ( " ha_innobase::check " ) ;
DBUG_ASSERT ( thd = = ha_thd ( ) ) ;
ut_a ( prebuilt - > trx ) ;
ut_a ( prebuilt - > trx - > magic_n = = TRX_MAGIC_N ) ;
@ -7640,17 +7645,140 @@ ha_innobase::check(
build_template ( prebuilt , NULL , table , ROW_MYSQL_WHOLE_ROW ) ;
}
ret = row_check_table_for_mysql ( prebuilt ) ;
if ( prebuilt - > table - > ibd_file_missing ) {
sql_print_error ( " InnoDB: Error: \n "
" InnoDB: MySQL is trying to use a table handle "
" but the .ibd file for \n "
" InnoDB: table %s does not exist. \n "
" InnoDB: Have you deleted the .ibd file "
" from the database directory under \n "
" InnoDB: the MySQL datadir, or have you "
" used DISCARD TABLESPACE? \n "
" InnoDB: Please refer to \n "
" InnoDB: " REFMAN " innodb-troubleshooting.html \n "
" InnoDB: how you can resolve the problem. \n " ,
prebuilt - > table - > name ) ;
DBUG_RETURN ( HA_ADMIN_CORRUPT ) ;
}
prebuilt - > trx - > op_info = " checking table " ;
switch ( ret ) {
case DB_SUCCESS :
return ( HA_ADMIN_OK ) ;
case DB_INTERRUPTED :
old_isolation_level = prebuilt - > trx - > isolation_level ;
/* We must run the index record counts at an isolation level
> = READ COMMITTED , because a dirty read can see a wrong number
of records in some index ; to play safe , we use always
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 ) ;
for ( index = dict_table_get_first_index ( prebuilt - > table ) ;
index ! = NULL ;
index = dict_table_get_next_index ( index ) ) {
#if 0
fputs ( " Validating index " , stderr ) ;
ut_print_name ( stderr , trx , FALSE , index - > name ) ;
putc ( ' \n ' , stderr ) ;
# endif
if ( ! btr_validate_index ( index , prebuilt - > trx ) ) {
is_ok = FALSE ;
push_warning_printf ( thd , MYSQL_ERROR : : WARN_LEVEL_WARN ,
ER_NOT_KEYFILE ,
" InnoDB: The B-tree of "
" index '%-.200s' is corrupted. " ,
index - > name ) ;
continue ;
}
/* Instead of invoking change_active_index(), set up
a dummy template for non - locking reads , disabling
access to the clustered index . */
prebuilt - > index = index ;
prebuilt - > index_usable = row_merge_is_index_usable (
prebuilt - > trx , prebuilt - > index ) ;
if ( UNIV_UNLIKELY ( ! prebuilt - > index_usable ) ) {
push_warning_printf ( thd , MYSQL_ERROR : : WARN_LEVEL_WARN ,
HA_ERR_TABLE_DEF_CHANGED ,
" InnoDB: Insufficient history for "
" index '%-.200s' " ,
index - > name ) ;
continue ;
}
prebuilt - > sql_stat_start = TRUE ;
prebuilt - > template_type = ROW_MYSQL_DUMMY_TEMPLATE ;
prebuilt - > n_template = 0 ;
prebuilt - > need_to_access_clustered = FALSE ;
dtuple_set_n_fields ( prebuilt - > search_tuple , 0 ) ;
prebuilt - > select_lock_type = LOCK_NONE ;
if ( ! row_check_index_for_mysql ( prebuilt , index , & n_rows ) ) {
push_warning_printf ( thd , MYSQL_ERROR : : WARN_LEVEL_WARN ,
ER_NOT_KEYFILE ,
" InnoDB: The B-tree of "
" index '%-.200s' is corrupted. " ,
index - > name ) ;
is_ok = FALSE ;
}
if ( thd_killed ( user_thd ) ) {
break ;
}
#if 0
fprintf ( stderr , " %lu entries in index %s \n " , n_rows ,
index - > name ) ;
# endif
if ( index = = dict_table_get_first_index ( prebuilt - > table ) ) {
n_rows_in_table = n_rows ;
} else if ( n_rows ! = n_rows_in_table ) {
push_warning_printf ( thd , MYSQL_ERROR : : WARN_LEVEL_WARN ,
ER_NOT_KEYFILE ,
" InnoDB: Index '%-.200s' "
" contains %lu entries, "
" should be %lu. " ,
index - > name ,
( ulong ) n_rows ,
( ulong ) n_rows_in_table ) ;
is_ok = FALSE ;
}
}
/* Restore the original isolation level */
prebuilt - > trx - > isolation_level = old_isolation_level ;
/* We validate also the whole adaptive hash index for all tables
at every CHECK TABLE */
if ( ! btr_search_validate ( ) ) {
push_warning ( thd , MYSQL_ERROR : : WARN_LEVEL_WARN ,
ER_NOT_KEYFILE ,
" InnoDB: The adaptive hash index is corrupted. " ) ;
is_ok = FALSE ;
}
/* 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 = " " ;
if ( thd_killed ( user_thd ) ) {
my_error ( ER_QUERY_INTERRUPTED , MYF ( 0 ) ) ;
return ( - 1 ) ;
default :
return ( HA_ADMIN_CORRUPT ) ;
}
DBUG_RETURN ( is_ok ? HA_ADMIN_OK : HA_ADMIN_CORRUPT ) ;
}
/*************************************************************/ /**