diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 89ccd12..8d3dd26 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -126,9 +126,36 @@ #include "opt_hints.h" // hint_key_state #include "mysys_err.h" // EE_CAPACITY_EXCEEDED +#include "debug_sync.h" + using std::min; using std::max; +#define DBUG_WRITE_MESSAGE(THD,TBL,MSG) \ +{ \ + if ((THD)->lex->sql_command == SQLCOM_UPDATE || \ + (THD)->lex->sql_command == SQLCOM_UPDATE) \ + { \ + longlong tmp_records= (TBL)->file->stats.records; \ + (TBL)->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK); \ + sql_print_warning("DEBUG: Full table scan on table %s. Reason: '%s' Records2: %lld Records3: %lld Optimizer_flag: %llu Query: %1000s", \ + (TBL)->s->table_name.str, \ + MSG, \ + (longlong) tmp_records, \ + (longlong) (TBL)->file->stats.records, \ + ((THD)->variables.optimizer_switch), \ + (THD)->query().str); \ + } \ +} + +#define DBUG_RETURN_MESSAGE(RET,THD,TBL,MSG) \ +{ \ + DBUG_WRITE_MESSAGE(THD,TBL,MSG); \ + DBUG_RETURN(RET); \ + } \ + + + /* Convert double value to #rows. Currently this does floor(), and we might consider using round() instead. @@ -3163,12 +3190,19 @@ free_mem: DBUG_EXECUTE("info", print_quick(*quick, needed_reg);); } + DEBUG_SYNC(thd,"opt_range_wait_for_innodb_stats"); /* Assume that if the user is using 'limit' we will only need to scan limit rows if we are using a key */ - DBUG_RETURN(records ? MY_TEST(*quick) : -1); + //DBUG_RETURN(records ? MY_TEST(*quick) : -1); + if (!records) + DBUG_RETURN_MESSAGE(-1, thd, head, ("records == 0")); + if (!*quick) + DBUG_RETURN_MESSAGE(0, thd, head, ("quick == 0")); + DBUG_RETURN(1); + } /**************************************************************************** diff --git a/storage/innobase/dict/dict0stats.cc b/storage/innobase/dict/dict0stats.cc index e3a9a6a..dced6da 100644 --- a/storage/innobase/dict/dict0stats.cc +++ b/storage/innobase/dict/dict0stats.cc @@ -3190,6 +3191,12 @@ dict_stats_update( have less indexes than the real object 'table'. */ dict_stats_empty_table(table); + DBUG_EXECUTE_IF("innodb_wait_with_empty_stats", + { + my_sleep(30ull*1000ULL*1000); + } + ); + dict_stats_copy(table, t); dict_stats_assert_initialized(table);