diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index d256ba2e294..948c598c3eb 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -8337,7 +8337,7 @@ bool setup_tables(THD *thd, Name_resolution_context *context,
   if (select_lex->first_cond_optimization)
   {
     leaves.empty();
-    if (select_lex->prep_leaf_list_state != SELECT_LEX::SAVED)
+    if (1) // was: (select_lex->prep_leaf_list_state != SELECT_LEX::SAVED)
     {
       /*
         For INSERT ... SELECT statements we must not include the first table
@@ -8347,16 +8347,8 @@ bool setup_tables(THD *thd, Name_resolution_context *context,
           select_insert ? first_select_table : tables;
       make_leaves_list(thd, leaves, tables_for_leaves, full_table_list,
                        first_select_table);
-      select_lex->prep_leaf_list_state= SELECT_LEX::READY;
       select_lex->leaf_tables_exec.empty();
     }
-    else
-    {
-      List_iterator_fast <TABLE_LIST> ti(select_lex->leaf_tables_prep);
-      while ((table_list= ti++))
-        leaves.push_back(table_list, thd->mem_root);
-    }
-      
     List_iterator<TABLE_LIST> ti(leaves);
     while ((table_list= ti++))
     {
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 3768420abb7..5669eb2a87b 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -948,7 +948,6 @@ THD::THD(my_thread_id id, bool is_wsrep_applier)
   invoker.init();
   prepare_derived_at_open= FALSE;
   create_tmp_table_for_derived= FALSE;
-  save_prep_leaf_list= FALSE;
   reset_sp_cache= false;
   org_charset= 0;
   /* Restore THR_THD */
diff --git a/sql/sql_class.h b/sql/sql_class.h
index d0e72335fdb..859afe2d50e 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -2984,8 +2984,6 @@ class THD: public THD_count, /* this must be first */
   */ 
   bool create_tmp_table_for_derived;
 
-  bool save_prep_leaf_list;
-
   /**
     The data member reset_sp_cache is to signal that content of sp_cache
     must be reset (all items be removed from it).
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 2428eff2af0..2dbb0acc2be 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -2999,7 +2999,6 @@ void st_select_lex::init_query()
   top_join_list.empty();
   join_list= &top_join_list;
   embedding= 0;
-  leaf_tables_prep.empty();
   leaf_tables.empty();
   item_list.empty();
   fix_after_optimize.empty();
@@ -3057,7 +3056,6 @@ void st_select_lex::init_query()
   context_analysis_place= NO_MATTER;
   nest_level= 0;
   link_next= 0;
-  prep_leaf_list_state= UNINIT;
   bzero((char*) expr_cache_may_be_used, sizeof(expr_cache_may_be_used));
   select_list_tables= 0;
   rownum_in_field_list= 0;
@@ -5747,64 +5745,6 @@ bool st_select_lex::save_leaf_tables(THD *thd)
 }
 
 
-bool LEX::save_prep_leaf_tables()
-{
-  if (!thd->save_prep_leaf_list)
-    return FALSE;
-
-  Query_arena *arena= thd->stmt_arena, backup;
-  arena= thd->activate_stmt_arena_if_needed(&backup);
-  //It is used for DETETE/UPDATE so top level has only one SELECT
-  DBUG_ASSERT(first_select_lex()->next_select() == NULL);
-  bool res= first_select_lex()->save_prep_leaf_tables(thd);
-
-  if (arena)
-    thd->restore_active_arena(arena, &backup);
-
-  if (res)
-    return TRUE;
-
-  thd->save_prep_leaf_list= FALSE;
-  return FALSE;
-}
-
-
-bool st_select_lex::save_prep_leaf_tables(THD *thd)
-{
-  if (prep_leaf_list_state == SAVED)
-    return FALSE;
-
-  List_iterator_fast<TABLE_LIST> li(leaf_tables);
-  TABLE_LIST *table;
-
-  /*
-    Check that the SELECT_LEX was really prepared and so tables are setup.
-
-    It can be subquery in SET clause of UPDATE which was not prepared yet, so
-    its tables are not yet setup and ready for storing.
-  */
-  if (prep_leaf_list_state != READY)
-    return FALSE;
-
-  while ((table= li++))
-  {
-    if (leaf_tables_prep.push_back(table))
-      return TRUE;
-  }
-  prep_leaf_list_state= SAVED;
-  for (SELECT_LEX_UNIT *u= first_inner_unit(); u; u= u->next_unit())
-  {
-    for (SELECT_LEX *sl= u->first_select(); sl; sl= sl->next_select())
-    {
-      if (sl->save_prep_leaf_tables(thd))
-        return TRUE;
-    }
-  }
-
-  return FALSE;
-}
-
-
 /**
   Set exclude_from_table_unique_test for selects of this select and all selects
   belonging to the underlying units of derived tables or views
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 97e06f9355f..042eebf68c7 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -1210,7 +1210,6 @@ class st_select_lex: public st_select_lex_node
   List<Item_func_in> in_funcs;
   List<TABLE_LIST> leaf_tables;
   List<TABLE_LIST> leaf_tables_exec;
-  List<TABLE_LIST> leaf_tables_prep;
 
   /* current index hint kind. used in filling up index_hints */
   enum index_hint_type current_index_hint_type;
@@ -1349,8 +1348,6 @@ class st_select_lex: public st_select_lex_node
   enum_parsing_place parsing_place; /* where we are parsing expression */
   enum_parsing_place save_parsing_place;
   enum_parsing_place context_analysis_place; /* where we are in prepare */
-  enum leaf_list_state {UNINIT, READY, SAVED};
-  enum leaf_list_state prep_leaf_list_state;
   enum olap_type olap;
   /* SELECT [FOR UPDATE/LOCK IN SHARE MODE] [SKIP LOCKED] */
   enum select_lock_type {NONE, IN_SHARE_MODE, FOR_UPDATE};
@@ -1588,7 +1585,6 @@ class st_select_lex: public st_select_lex_node
   void mark_const_derived(bool empty);
 
   bool save_leaf_tables(THD *thd);
-  bool save_prep_leaf_tables(THD *thd);
 
   void set_unique_exclude();
 
@@ -3911,8 +3907,6 @@ struct LEX: public Query_tables_list
     return FALSE;
   }
 
-  bool save_prep_leaf_tables();
-
   int print_explain(select_result_sink *output, uint8 explain_flags,
                     bool is_analyze, bool is_json_format,
                     bool *printed_anything);
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 62aa1882823..137c84ceedd 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -7482,8 +7482,6 @@ void THD::reset_for_next_command(bool do_clear_error)
   reset_current_stmt_binlog_format_row();
   binlog_unsafe_warning_flags= 0;
 
-  save_prep_leaf_list= false;
-
 #if defined(WITH_WSREP) && !defined(DBUG_OFF)
   if (mysql_bin_log.is_open())
     DBUG_PRINT("info",
