diff --git a/libmariadb b/libmariadb
index c8dd089..923e619 160000
--- a/libmariadb
+++ b/libmariadb
@@ -1 +1 @@
-Subproject commit c8dd0899d484ad698ec2da5bc8e3d19ff8b623b9
+Subproject commit 923e6199b9d98c0d947c827ec6b2e0ba29d1f07a-dirty
diff --git a/sql/field.cc b/sql/field.cc
index e4ecb74..609d44f 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -10821,3 +10821,43 @@ bool Field::validate_value_in_record_with_warn(THD *thd, const uchar *record)
   dbug_tmp_restore_column_map(table->read_set, old_map);
   return rc;
 }
+
+
+bool Field::save_in_field_default_value(bool view_error_processing)
+{
+  THD *thd= table->in_use;
+
+  if (flags & NO_DEFAULT_VALUE_FLAG &&
+      real_type() != MYSQL_TYPE_ENUM)
+  {
+    if (reset())
+    {
+      my_message(ER_CANT_CREATE_GEOMETRY_OBJECT,
+                 ER_THD(thd, ER_CANT_CREATE_GEOMETRY_OBJECT), MYF(0));
+      return -1;
+    }
+
+    if (view_error_processing)
+    {
+      TABLE_LIST *view= table->pos_in_table_list->top_table();
+      push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
+                          ER_NO_DEFAULT_FOR_VIEW_FIELD,
+                          ER_THD(thd, ER_NO_DEFAULT_FOR_VIEW_FIELD),
+                          view->view_db.str,
+                          view->view_name.str);
+    }
+    else
+    {
+      push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
+                          ER_NO_DEFAULT_FOR_FIELD,
+                          ER_THD(thd, ER_NO_DEFAULT_FOR_FIELD),
+                          field_name);
+    }
+    return 1;
+  }
+  set_default();
+  return
+    !is_null() &&
+    validate_value_in_record_with_warn(thd, table->record[0]) &&
+    thd->is_error() ? -1 : 0;
+}
diff --git a/sql/field.h b/sql/field.h
index f550dad..c9d7509 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -1451,6 +1451,9 @@ class Field: public Value_source
     // Exactly the same rules with REF access
     return can_optimize_keypart_ref(cond, item);
   }
+
+  bool save_in_field_default_value(bool view_eror_processing);
+
   friend int cre_myisam(char * name, register TABLE *form, uint options,
 			ulonglong auto_increment_value);
   friend class Copy_field;
diff --git a/sql/item.cc b/sql/item.cc
index e52e7f5..56d0b04 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -818,13 +818,6 @@ bool Item_ident::collect_outer_ref_processor(void *param)
   return FALSE;
 }
 
-void Item_ident::set_default_value_target(Item *item)
-{
-  if ((default_value_target= item) && fixed &&
-      type() == FIELD_ITEM)
-    default_value_target->set_default_value_source(((Item_field *)this)->
-                                                   field);
-}
 
 /**
   Store the pointer to this item field into a list if not already there.
@@ -2547,10 +2540,6 @@ void Item_field::set_field(Field *field_par)
   max_length= adjust_max_effective_column_length(field_par, max_length);
 
   fixed= 1;
-  if (default_value_target != 0)
-  {
-    default_value_target->set_default_value_source(field);
-  }
   if (field->table->s->tmp_table == SYSTEM_TMP_TABLE)
     any_privileges= 0;
 }
@@ -3244,7 +3233,7 @@ Item_param::Item_param(THD *thd, uint pos_in_query_arg):
   Item_basic_value(thd),
   Rewritable_query_parameter(pos_in_query_arg, 1),
   Type_handler_hybrid_field_type(MYSQL_TYPE_VARCHAR),
-  state(NO_VALUE), default_value_ref(NULL), default_value_source(NULL),
+  state(NO_VALUE),
   indicators(0), indicator(STMT_INDICATOR_NONE),
   /* Don't pretend to be a literal unless value for this item is set. */
   item_type(PARAM_ITEM),
@@ -3577,8 +3566,6 @@ void Item_param::reset()
   state= NO_VALUE;
   maybe_null= 1;
   null_value= 0;
-  default_value_source= NULL;
-  default_value_ref= NULL;
   /*
     Don't reset item_type to PARAM_ITEM: it's only needed to guard
     us from item optimizations at prepare stage, when item doesn't yet
@@ -3612,6 +3599,10 @@ int Item_param::save_in_field(Field *field, bool no_conversions)
                         str_value.charset());
   case NULL_VALUE:
     return set_field_to_null_with_conversions(field, no_conversions);
+  case DEFAULT_VALUE:
+    return field->save_in_field_default_value(field->table->pos_in_table_list->
+                                              top_table() !=
+                                              field->table->pos_in_table_list);
   case NO_VALUE:
   default:
     DBUG_ASSERT(0);
@@ -3657,6 +3648,9 @@ double Item_param::val_real()
     return TIME_to_double(&value.time);
   case NULL_VALUE:
     return 0.0;
+  case DEFAULT_VALUE:
+    my_message(ER_INVALID_DEFAULT_PARAM,
+               ER_THD(current_thd, ER_INVALID_DEFAULT_PARAM), MYF(0));
   default:
     DBUG_ASSERT(0);
   }
@@ -3684,6 +3678,9 @@ longlong Item_param::val_int()
     }
   case TIME_VALUE:
     return (longlong) TIME_to_ulonglong(&value.time);
+  case DEFAULT_VALUE:
+    my_message(ER_INVALID_DEFAULT_PARAM,
+               ER_THD(current_thd, ER_INVALID_DEFAULT_PARAM), MYF(0));
   case NULL_VALUE:
     return 0; 
   default:
@@ -3711,6 +3708,9 @@ my_decimal *Item_param::val_decimal(my_decimal *dec)
   {
     return TIME_to_my_decimal(&value.time, dec);
   }
+  case DEFAULT_VALUE:
+    my_message(ER_INVALID_DEFAULT_PARAM,
+               ER_THD(current_thd, ER_INVALID_DEFAULT_PARAM), MYF(0));
   case NULL_VALUE:
     return 0; 
   default:
@@ -3746,6 +3746,9 @@ String *Item_param::val_str(String* str)
     str->set_charset(&my_charset_bin);
     return str;
   }
+  case DEFAULT_VALUE:
+    my_message(ER_INVALID_DEFAULT_PARAM,
+               ER_THD(current_thd, ER_INVALID_DEFAULT_PARAM), MYF(0));
   case NULL_VALUE:
     return NULL; 
   default:
@@ -3824,6 +3827,9 @@ const String *Item_param::query_val_str(THD *thd, String* str) const
                           thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES);
       break;
     }
+  case DEFAULT_VALUE:
+    my_message(ER_INVALID_DEFAULT_PARAM,
+               ER_THD(current_thd, ER_INVALID_DEFAULT_PARAM), MYF(0));
   case NULL_VALUE:
     return &my_null_string;
   default:
@@ -3874,6 +3880,9 @@ Item_param::clone_item(THD *thd)
 {
   MEM_ROOT *mem_root= thd->mem_root;
   switch (state) {
+  case DEFAULT_VALUE:
+    my_message(ER_INVALID_DEFAULT_PARAM,
+               ER_THD(current_thd, ER_INVALID_DEFAULT_PARAM), MYF(0));
   case NULL_VALUE:
     return new (mem_root) Item_null(thd, name);
   case INT_VALUE:
@@ -3906,6 +3915,9 @@ Item_param::eq(const Item *item, bool binary_cmp) const
     return FALSE;
 
   switch (state) {
+  case DEFAULT_VALUE:
+    my_message(ER_INVALID_DEFAULT_PARAM,
+               ER_THD(current_thd, ER_INVALID_DEFAULT_PARAM), MYF(0));
   case NULL_VALUE:
     return null_eq(item);
   case INT_VALUE:
@@ -3929,6 +3941,10 @@ void Item_param::print(String *str, enum_query_type query_type)
   {
     str->append('?');
   }
+  else if (state == DEFAULT_VALUE)
+  {
+    str->append("default");
+  }
   else
   {
     char buffer[STRING_BUFFER_USUAL_SIZE];
@@ -3973,9 +3989,6 @@ Item_param::set_param_type_and_swap_value(Item_param *src)
   null_value= src->null_value;
   state= src->state;
   value= src->value;
-  default_value_ref= src->default_value_ref;
-  default_value_source= src->default_value_source;
-
 
   decimal_value.swap(src->decimal_value);
   str_value.swap(src->str_value);
@@ -3983,28 +3996,9 @@ Item_param::set_param_type_and_swap_value(Item_param *src)
 }
 
 
-bool Item_param::set_default(bool can_be_missed)
+void Item_param::set_default()
 {
-  if (!default_value_ref)
-  {
-    if (can_be_missed)
-      return FALSE;
-    my_message(ER_INVALID_DEFAULT_PARAM,
-               ER_THD(current_thd, ER_INVALID_DEFAULT_PARAM), MYF(0));
-    return TRUE;
-  }
-  THD *thd= default_value_ref->table->in_use;
-  if (!default_value_source)
-  {
-    default_value_source= new (thd->mem_root)
-      Item_default_value(thd, &thd->lex->select_lex.context, default_value_ref);
-    if (!default_value_source ||
-        default_value_source->fix_fields(thd, (Item **)&default_value_source))
-      return TRUE;
-    bitmap_set_bit(default_value_ref->table->read_set,
-                   default_value_ref->field_index);
-  }
-  return set_value(thd, NULL, (Item**)&default_value_source);
+  state= DEFAULT_VALUE;
 }
 
 /**
@@ -4165,17 +4159,6 @@ bool Item_param::append_for_log(THD *thd, String *str)
   return str->append(*val);
 }
 
-
-bool Item_param::walk(Item_processor processor, bool walk_subquery, void *arg)
-{
-  if (default_value_source &&
-      default_value_source->walk(processor, walk_subquery, arg))
-  {
-    return TRUE;
-  }
-  return (this->*processor)(arg);
-}
-
 /****************************************************************************
   Item_copy
 ****************************************************************************/
@@ -7334,7 +7317,6 @@ bool Item_ref::fix_fields(THD *thd, Item **reference)
         Item_field* fld;
         if (!(fld= new (thd->mem_root) Item_field(thd, from_field)))
           goto error;
-        fld->set_default_value_target(default_value_target);
         thd->change_item_tree(reference, fld);
         mark_as_dependent(thd, last_checked_context->select_lex,
                           current_sel, fld, fld);
@@ -8521,38 +8503,36 @@ bool Item_default_value::eq(const Item *item, bool binary_cmp) const
 bool Item_default_value::fix_fields(THD *thd, Item **items)
 {
   Item *real_arg;
+  Item_field *field_arg;
   Field *def_field;
   DBUG_ASSERT(fixed == 0);
 
-  if (!arg && !arg_fld)
+  if (!arg)
   {
     fixed= 1;
     return FALSE;
   }
-  if (arg)
-  {
-    if (!arg->fixed && arg->fix_fields(thd, &arg))
-      goto error;
-
+  if (!arg->fixed && arg->fix_fields(thd, &arg))
+    goto error;
 
-    real_arg= arg->real_item();
-    if (real_arg->type() != FIELD_ITEM)
-    {
-      my_error(ER_NO_DEFAULT_FOR_FIELD, MYF(0), arg->name);
-      goto error;
-    }
 
-    arg_fld= ((Item_field *)real_arg)->field;
+  real_arg= arg->real_item();
+  if (real_arg->type() != FIELD_ITEM)
+  {
+    my_error(ER_NO_DEFAULT_FOR_FIELD, MYF(0), arg->name);
+    goto error;
   }
-  if ((arg_fld->flags & NO_DEFAULT_VALUE_FLAG))
+
+  field_arg= (Item_field *)real_arg;
+  if ((field_arg->field->flags & NO_DEFAULT_VALUE_FLAG))
   {
-    my_error(ER_NO_DEFAULT_FOR_FIELD, MYF(0), arg_fld->field_name);
+    my_error(ER_NO_DEFAULT_FOR_FIELD, MYF(0), field_arg->field->field_name);
     goto error;
   }
-  if (!(def_field= (Field*) thd->alloc(arg_fld->size_of())))
+  if (!(def_field= (Field*) thd->alloc(field_arg->field->size_of())))
     goto error;
-  memcpy((void *)def_field, (void *)arg_fld,
-         arg_fld->size_of());
+  memcpy((void *)def_field, (void *)field_arg->field,
+         field_arg->field->size_of());
   def_field->move_field_offset((my_ptrdiff_t)
                                (def_field->table->s->default_values -
                                 def_field->table->record[0]));
@@ -8632,42 +8612,8 @@ int Item_default_value::save_in_field(Field *field_arg, bool no_conversions)
     calculate();
   else
   {
-    TABLE *table= field_arg->table;
-    THD *thd= table->in_use;
-
-    if (field_arg->flags & NO_DEFAULT_VALUE_FLAG &&
-        field_arg->real_type() != MYSQL_TYPE_ENUM)
-    {
-      if (field_arg->reset())
-      {
-        my_message(ER_CANT_CREATE_GEOMETRY_OBJECT,
-                   ER_THD(thd, ER_CANT_CREATE_GEOMETRY_OBJECT), MYF(0));
-        return -1;
-      }
-
-      if (context->error_processor == &view_error_processor)
-      {
-        TABLE_LIST *view= table->pos_in_table_list->top_table();
-        push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
-                            ER_NO_DEFAULT_FOR_VIEW_FIELD,
-                            ER_THD(thd, ER_NO_DEFAULT_FOR_VIEW_FIELD),
-                            view->view_db.str,
-                            view->view_name.str);
-      }
-      else
-      {
-        push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
-                            ER_NO_DEFAULT_FOR_FIELD,
-                            ER_THD(thd, ER_NO_DEFAULT_FOR_FIELD),
-                            field_arg->field_name);
-      }
-      return 1;
-    }
-    field_arg->set_default();
-    return
-      !field_arg->is_null() &&
-       field_arg->validate_value_in_record_with_warn(thd, table->record[0]) &&
-       thd->is_error() ? -1 : 0;
+    return field_arg->save_in_field_default_value(context->error_processor ==
+                                                  &view_error_processor);
   }
   return Item_field::save_in_field(field_arg, no_conversions);
 }
diff --git a/sql/item.h b/sql/item.h
index 0915cc2..f3736a4 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -1946,9 +1946,6 @@ class Item: public Value_source,
   {
     marker &= ~EXTRACTION_MASK;
   }
-
-  virtual void set_default_value_source(Field *fld) {};
-  virtual bool set_default_if_needed() { return FALSE; };
 };
 
 
@@ -2474,7 +2471,6 @@ class Item_ident :public Item_result_field
   virtual void print(String *str, enum_query_type query_type);
   virtual bool change_context_processor(void *cntx)
     { context= (Name_resolution_context *)cntx; return FALSE; }
-  void set_default_value_target(Item *item);
   /**
     Collect outer references
   */
@@ -2807,7 +2803,7 @@ class Item_param :public Item_basic_value,
   {
     NO_VALUE, NULL_VALUE, INT_VALUE, REAL_VALUE,
     STRING_VALUE, TIME_VALUE, LONG_DATA_VALUE,
-    DECIMAL_VALUE
+    DECIMAL_VALUE, DEFAULT_VALUE
   } state;
 
   struct CONVERSION_INFO
@@ -2851,14 +2847,12 @@ class Item_param :public Item_basic_value,
     }
   };
 
-  Field *default_value_ref;
-  Item_default_value *default_value_source;
   /*
     Used for bulk protocol. Indicates if we should expect
     indicators byte before value of the parameter
   */
   my_bool indicators;
-  uint indicator;
+  enum enum_indicator_type indicator;
 
   /*
     A buffer for string and long data values. Historically all allocated
@@ -2900,10 +2894,7 @@ class Item_param :public Item_basic_value,
   bool get_date(MYSQL_TIME *tm, ulonglong fuzzydate);
   int  save_in_field(Field *field, bool no_conversions);
 
-  virtual void set_default_value_source(Field *fld)
-  { default_value_ref= fld; }
-
-  bool set_default(bool can_be_missed);
+  void set_default();
   void set_null();
   void set_int(longlong i, uint32 max_length_arg);
   void set_double(double i);
@@ -2972,19 +2963,10 @@ class Item_param :public Item_basic_value,
   virtual void set_out_param_info(Send_field *info);
 
 public:
-  bool set_default_if_needed()
-  {
-    if (state == NO_VALUE && indicator == STMT_INDICATOR_DEFAULT &&
-        set_default(FALSE))
-      return TRUE;
-    return FALSE;
-  }
-
   virtual const Send_field *get_out_param_info() const;
 
   virtual void make_field(THD *thd, Send_field *field);
 
-  virtual bool walk(Item_processor processor, bool walk_subquery, void *arg);
 private:
   Send_field *m_out_param_info;
 };
@@ -5109,19 +5091,18 @@ class Item_default_value : public Item_field
   void calculate();
 public:
   Item *arg;
-  Field *arg_fld;
   Item_default_value(THD *thd, Name_resolution_context *context_arg)
     :Item_field(thd, context_arg, (const char *)NULL, (const char *)NULL,
                (const char *)NULL),
-     arg(NULL), arg_fld(NULL) {}
+     arg(NULL) {}
   Item_default_value(THD *thd, Name_resolution_context *context_arg, Item *a)
     :Item_field(thd, context_arg, (const char *)NULL, (const char *)NULL,
                 (const char *)NULL),
-     arg(a), arg_fld(NULL) {}
+     arg(a) {}
   Item_default_value(THD *thd, Name_resolution_context *context_arg, Field *a)
     :Item_field(thd, context_arg, (const char *)NULL, (const char *)NULL,
                 (const char *)NULL),
-     arg(NULL), arg_fld(a) {}
+     arg(NULL) {}
   enum Type type() const { return DEFAULT_VALUE_ITEM; }
   bool eq(const Item *item, bool binary_cmp) const;
   bool fix_fields(THD *, Item **);
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index fe4aec7..2d40631 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -7821,8 +7821,6 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values,
                           ER_THD(thd, ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN),
                           rfield->field_name, table->s->table_name.str);
     }
-    if (value->set_default_if_needed())
-      goto err;
     if (rfield->stored_in_db() &&
         (value->save_in_field(rfield, 0)) < 0 && !ignore_errors)
     {
@@ -8063,19 +8061,19 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List<Item> &values,
     value=v++;
     if (field->field_index == autoinc_index)
       table->auto_increment_field_not_null= TRUE;
-    Item::Type type= value->type();
-    if (field->vcol_info &&
-        type != Item::DEFAULT_VALUE_ITEM &&
-        type != Item::NULL_ITEM &&
-        table->s->table_category != TABLE_CATEGORY_TEMPORARY)
+    if (field->vcol_info)
     {
-      push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
-                          ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN,
-                          ER_THD(thd, ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN),
-                          field->field_name, table->s->table_name.str);
+      Item::Type type= value->type();
+      if (type != Item::DEFAULT_VALUE_ITEM &&
+          type != Item::NULL_ITEM &&
+          table->s->table_category != TABLE_CATEGORY_TEMPORARY)
+      {
+        push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
+                            ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN,
+                            ER_THD(thd, ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN),
+                            field->field_name, table->s->table_name.str);
+      }
     }
-    if (value->set_default_if_needed())
-      goto err;
 
     if (use_value)
       value->save_val(field);
diff --git a/sql/sql_class.h b/sql/sql_class.h
index d6dd45c..93d3a4a 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -3445,7 +3445,7 @@ class THD :public Statement,
     bulk_param= bulk;
     m_stmt_da->set_bulk_execution(MY_TEST(bulk));
   }
-  bool is_bulk_op() const { return m_stmt_da->is_bulk_op(); }
+  bool is_bulk_op() const { return MY_TEST(bulk_param); }
 
   /// Returns Diagnostics-area for the current statement.
   Diagnostics_area *get_stmt_da()
diff --git a/sql/sql_error.cc b/sql/sql_error.cc
index 34d608f..d14c7b8 100644
--- a/sql/sql_error.cc
+++ b/sql/sql_error.cc
@@ -384,10 +384,12 @@ Diagnostics_area::set_ok_status(ulonglong affected_rows,
   */
   if (is_error() || is_disabled())
     return;
-
+  /*
+    When running a bulk operation, m_status will be DA_OK for the first
+    operation and set to DA_OK_BULK for all following operations.
+  */
   if (m_status == DA_OK_BULK)
   {
-    DBUG_ASSERT(is_bulk_op());
     m_statement_warn_count+= current_statement_warn_count();
     m_affected_rows+= affected_rows;
   }
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index be99bdd..432f8b6 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -638,66 +638,6 @@ static void save_insert_query_plan(THD* thd, TABLE_LIST *table_list)
 }
 
 
-inline static void set_defaults_relation(Item *fld, Item *val)
-{
-  Item::Type type= fld->type();
-  if (type == Item::FIELD_ITEM)
-  {
-    Item_field *item_field= (Item_field *)fld;
-    if (item_field->fixed)
-      val->set_default_value_source(item_field->field);
-    else
-      item_field->set_default_value_target(val);
-  }
-  else if (type == Item::REF_ITEM)
-  {
-    Item_ref *item_field= (Item_ref *)fld;
-    // may turn to Item_field after fix_fields()
-    if (!item_field->fixed)
-      item_field->set_default_value_target(val);
-  }
-}
-
-void setup_deault_parameters(TABLE_LIST *table, List<Item> *fields,
-                             List<Item> *values)
-{
-
-  List_iterator_fast<Item> itv(*values);
-  Item *val;
-  if (fields->elements)
-  {
-    List_iterator_fast<Item> itf(*fields);
-    Item *fld;
-    while((fld= itf++) && (val= itv++))
-    {
-      set_defaults_relation(fld->real_item(), val);
-    }
-  }
-  else if (table != NULL)
-  {
-    if (table->view)
-    {
-      Field_iterator_view field_it;
-      field_it.set(table);
-      for (; !field_it.end_of_fields() && (val= itv++); field_it.next())
-      {
-        set_defaults_relation(field_it.item()->real_item(), val);
-      }
-    }
-    else
-    {
-      Field_iterator_table_ref field_it;
-      field_it.set(table);
-      for (; !field_it.end_of_fields() && (val= itv++); field_it.next())
-      {
-        Field *fld= field_it.field();
-        val->set_default_value_source(fld);
-      }
-    }
-  }
-}
-
-
 /**
   INSERT statement implementation
 
@@ -722,6 +662,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
   bool using_bulk_insert= 0;
   uint value_count;
   ulong counter = 1;
+  ulong iteration= 0;
   ulonglong id;
   ulong bulk_iterations= bulk_parameters_iterations(thd);
   COPY_INFO info;
@@ -787,6 +728,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
   THD_STAGE_INFO(thd, stage_init);
   thd->lex->used_tables=0;
   values= its++;
+  if (bulk_parameters_set(thd))
+    DBUG_RETURN(TRUE);
   value_count= values->elements;
 
   DBUG_ASSERT(bulk_iterations > 0);
@@ -833,7 +776,6 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
     if (setup_fields(thd, Ref_ptr_array(), *values, MARK_COLUMNS_READ, 0, 0))
       goto abort;
     switch_to_nullable_trigger_fields(*values, table);
-    setup_deault_parameters(table_list, &fields, values);
   }
   its.rewind ();
  
@@ -949,9 +891,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
       goto values_loop_end;
     }
   }
-  for (ulong iteration= 0; iteration < bulk_iterations; iteration++)
+  do
   {
-
     if (iteration && bulk_parameters_set(thd))
       goto abort;
 
@@ -1010,7 +951,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
           /* Fix undefined null_bits. */
           if (share->null_bytes > 1 && share->last_null_bit_pos)
           {
-            table->record[0][share->null_bytes - 1]= 
+            table->record[0][share->null_bytes - 1]=
               share->default_values[share->null_bytes - 1];
           }
         }
@@ -1056,7 +997,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
       thd->get_stmt_da()->inc_current_row_for_warning();
     }
     its.rewind();
-  }
+    iteration++;
+  } while (iteration < bulk_iterations);
 
 values_loop_end:
   free_underlaid_joins(thd, &thd->lex->select_lex);
@@ -1517,7 +1459,6 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list,
   /* Prepare the fields in the statement. */
   if (values)
   {
-
     /* if we have INSERT ... VALUES () we cannot have a GROUP BY clause */
     DBUG_ASSERT (!select_lex->group_list.elements);
 
@@ -1536,10 +1477,6 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list,
           check_insert_fields(thd, context->table_list, fields, *values,
                               !insert_into_view, 0, &map));
 
-    setup_deault_parameters(table_list, &fields, values);
-    if (bulk_parameters_set(thd))
-      DBUG_RETURN(TRUE);
-
     if (!res && check_fields)
     {
       bool saved_abort_on_warning= thd->abort_on_warning;
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 47f296d..80e6f8f 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -992,12 +992,13 @@ static bool insert_bulk_params(Prepared_statement *stmt,
     if (param->state != Item_param::LONG_DATA_VALUE)
     {
       if (param->indicators)
-        param->indicator= *((*read_pos)++);
+        param->indicator= (enum enum_indicator_type) *((*read_pos)++);
       else
         param->indicator= STMT_INDICATOR_NONE;
       if ((*read_pos) > data_end)
         DBUG_RETURN(1);
-      switch (param->indicator) {
+      switch (param->indicator)
+      {
       case STMT_INDICATOR_NONE:
         if ((*read_pos) >= data_end)
           DBUG_RETURN(1);
@@ -1009,17 +1010,10 @@ static bool insert_bulk_params(Prepared_statement *stmt,
         param->set_null();
         break;
       case STMT_INDICATOR_DEFAULT:
-        if (param->set_default(TRUE))
-          DBUG_RETURN(1);
+        param->set_default();
         break;
       }
     }
-    /*
-      A long data stream was supplied for this parameter marker.
-      This was done after prepare, prior to providing a placeholder
-      type (the types are supplied at execute). Check that the
-      supplied type of placeholder can accept a data stream.
-    */
     else
       DBUG_RETURN(1); // long is not supported here
   }
@@ -3095,7 +3089,7 @@ void mysqld_stmt_execute(THD *thd, char *packet_arg, uint packet_length)
   thd->profiling.set_query_source(stmt->query(), stmt->query_length());
 #endif
   DBUG_PRINT("exec_query", ("%s", stmt->query()));
-  DBUG_PRINT("info",("stmt: 0x%lx iterations: %lu", (long) stmt, iterations));
+  DBUG_PRINT("info",("stmt: 0x%p iterations: %lu", stmt, iterations));
 
   open_cursor= MY_TEST(flags & (ulong) CURSOR_TYPE_READ_ONLY);
 
@@ -4152,7 +4146,7 @@ my_bool Prepared_statement::set_bulk_parameters(bool reset)
 #ifndef EMBEDDED_LIBRARY
     if ((*set_bulk_params)(this, &packet, packet_end, reset))
 #else
-      DBUG_ASSERT(0); //TODO: support bulk parameters for embedded server
+    // bulk parameters are not supported for embedded, so it will an error
 #endif
     {
       my_error(ER_WRONG_ARGUMENTS, MYF(0),
@@ -4209,7 +4203,7 @@ Prepared_statement::execute_bulk_loop(String *expanded_query,
 #ifndef EMBEDDED_LIBRARY
   if (setup_conversion_functions(this, &packet, packet_end, TRUE))
 #else
-  DBUG_ASSERT(0); //TODO: support bulk parameters for embedded server
+  // bulk parameters are not supported for embedded, so it will an error
 #endif
   {
     my_error(ER_WRONG_ARGUMENTS, MYF(0),
@@ -4229,10 +4223,15 @@ Prepared_statement::execute_bulk_loop(String *expanded_query,
   }
 #endif
 
-  while((iterations || start_param) && !error && !thd->is_error())
+  // iterations changed by set_bulk_parameters
+  while ((iterations || start_param) && !error && !thd->is_error())
   {
     int reprepare_attempt= 0;
 
+    /*
+      Here we set parameters for not optimized commands,
+      optimized commands do it inside thier internal loop.
+    */
     if (!(sql_command_flags[lex->sql_command] & CF_SP_BULK_OPTIMIZED))
     {
       if (set_bulk_parameters(TRUE))
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index ecd32e2..b452e4f 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -221,8 +221,6 @@ static void prepare_record_for_error_message(int error, TABLE *table)
   DBUG_VOID_RETURN;
 }
 
-void setup_deault_parameters(TABLE_LIST *table, List<Item> *fields,
-                             List<Item> *values);
 
 /*
   Process usual UPDATE
@@ -356,8 +354,6 @@ int mysql_update(THD *thd,
     DBUG_RETURN(1);
   }
 
-  setup_deault_parameters(NULL, &fields, &values);
-
 #ifndef NO_EMBEDDED_ACCESS_CHECKS
   /* Check values */
   table_list->grant.want_privilege= table->grant.want_privilege=
