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.
@@ -2891,7 +2918,7 @@ int test_quick_select(THD *thd, key_map keys_to_use,
       thd->no_errors=0;
       thd->pop_internal_handler();
       free_root(&alloc,MYF(0));			// Return memory & allocator
-      DBUG_RETURN(0);				// Can't use range
+      DBUG_RETURN_MESSAGE(0, thd, head, ("alloc of key_parts failed"));
     }
     key_parts= param.key_parts;
     thd->mem_root= &alloc;
@@ -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
@@ -41,6 +41,7 @@ Created Jan 06, 2010 Vasil Dimov
 #include <algorithm>
 #include <map>
 #include <vector>
+#include <execinfo.h>
 
 /* Sampling algorithm description @{
 
@@ -3190,6 +3191,17 @@ dict_stats_update(
 			have less indexes than the real object 'table'. */
 			dict_stats_empty_table(table);
 
+                        DBUG_EXECUTE_IF("innodb_wait_with_empty_stats", 
+                        {
+                          fprintf(stderr, "AAA empty  stats at:\n");
+                          void *mybuf123[100];
+                          int res123= backtrace(mybuf123,100);
+                          backtrace_symbols_fd(mybuf123, res123, fileno(stderr));
+                          //my_sleep(1200ull*1000ULL*1000);
+                          my_sleep(30ull*1000ULL*1000);
+                        }
+                        );
+
 			dict_stats_copy(table, t);
 
 			dict_stats_assert_initialized(table);
