diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index 4ef3760..b973255 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -3617,6 +3617,7 @@ int ha_partition::external_lock(THD *thd, int lock_type)
   uint error;
   uint i, first_used_partition;
   MY_BITMAP *used_partitions;
+  bool delay_lock= false;
   DBUG_ENTER("ha_partition::external_lock");

   DBUG_ASSERT(!auto_increment_lock && !auto_increment_safe_stmt_log_lock);
@@ -3624,7 +3625,11 @@ int ha_partition::external_lock(THD *thd, int lock_type)
   if (lock_type == F_UNLCK)
     used_partitions= &m_locked_partitions;
   else
+  {
     used_partitions= &(m_part_info->lock_partitions);
+    if (thd->delay_prune_partition)
+      delay_lock= true;
+  }

   first_used_partition= bitmap_get_first_set(used_partitions);

@@ -3636,6 +3641,10 @@ int ha_partition::external_lock(THD *thd, int lock_type)
     DBUG_ASSERT(bad_file[i] <= 1);
     if (bad_file[i])
       continue;
+
+    if (delay_lock)
+      DBUG_RETURN(0);
+
     if ((error= m_file[i]->ha_external_lock(thd, lock_type)))
     {
       if (lock_type != F_UNLCK)
@@ -3736,7 +3745,6 @@ THR_LOCK_DATA **ha_partition::store_lock(THD *thd,
   uint i;
   DBUG_ENTER("ha_partition::store_lock");
   DBUG_ASSERT(thd == current_thd);
-
   /*
     This can be called from get_lock_data() in mysql_lock_abort_for_thread(),
     even when thd != table->in_use. In that case don't use partition pruning,
@@ -3751,6 +3759,8 @@ THR_LOCK_DATA **ha_partition::store_lock(THD *thd,
         continue;
       //no cover end
       to= m_file[i]->store_lock(thd, to, lock_type);
+      if (thd->delay_prune_partition)
+        DBUG_RETURN(to);
     }
   }
   else
@@ -3764,6 +3774,8 @@ THR_LOCK_DATA **ha_partition::store_lock(THD *thd,
       if (bad_file[i])
         continue;
       to= m_file[i]->store_lock(thd, to, lock_type);
+      if (thd->delay_prune_partition)
+        DBUG_RETURN(to);
     }
   }
   DBUG_RETURN(to);
@@ -4038,6 +4050,13 @@ int ha_partition::write_row(uchar * buf)
     error= HA_ERR_NOT_IN_LOCK_PARTITIONS;
     goto exit;
   }
+  if (!bitmap_is_set(&m_locked_partitions, part_id))
+  {
+    DBUG_ASSERT(thd->delay_prune_partition);
+    if ((error= m_file[part_id]->ha_external_lock(thd, get_lock_type())))
+      goto exit;
+    bitmap_set_bit(&m_locked_partitions, part_id);
+  }
   m_last_part= part_id;
   DBUG_PRINT("info", ("Insert in partition %d", part_id));
   start_part_bulk_insert(thd, part_id);
@@ -4133,6 +4152,21 @@ int ha_partition::update_row(const uchar *old_data, uchar *new_data)

   m_last_part= new_part_id;
   start_part_bulk_insert(thd, new_part_id);
+
+  if (!bitmap_is_set(&m_locked_partitions, new_part_id))
+  {
+    DBUG_ASSERT(thd->delay_prune_partition);
+    if ((error= m_file[new_part_id]->ha_external_lock(thd, get_lock_type())))
+      goto exit;
+    bitmap_set_bit(&m_locked_partitions, new_part_id);
+  }
+  if (!bitmap_is_set(&m_locked_partitions, old_part_id))
+  {
+    DBUG_ASSERT(thd->delay_prune_partition);
+    if ((error= m_file[old_part_id]->ha_external_lock(thd, get_lock_type())))
+      goto exit;
+    bitmap_set_bit(&m_locked_partitions, old_part_id);
+  }
   if (new_part_id == old_part_id)
   {
     DBUG_PRINT("info", ("Update in partition %d", new_part_id));
@@ -4278,6 +4312,14 @@ int ha_partition::delete_row(const uchar *buf)
     DBUG_RETURN(HA_ERR_ROW_IN_WRONG_PARTITION);
   }

+  if (!bitmap_is_set(&m_locked_partitions, part_id))
+  {
+    DBUG_ASSERT(thd->delay_prune_partition);
+    if ((error= m_file[part_id]->ha_external_lock(thd, get_lock_type())))
+      DBUG_RETURN(error);
+    bitmap_set_bit(&m_locked_partitions, part_id);
+  }
+
   m_last_part= part_id;
   tmp_disable_binlog(thd);
   error= m_file[part_id]->ha_delete_row(buf);
@@ -4954,11 +4996,19 @@ int ha_partition::rnd_pos(uchar * buf, uchar *pos)

 int ha_partition::rnd_pos_by_record(uchar *record)
 {
+  int error;
   DBUG_ENTER("ha_partition::rnd_pos_by_record");

   if (unlikely(get_part_for_delete(record, m_rec0, m_part_info, &m_last_part)))
     DBUG_RETURN(1);

+  if (!bitmap_is_set(&m_locked_partitions, m_last_part) && ha_thd()->delay_prune_partition)
+  {
+    if ((error= m_file[m_last_part]->ha_external_lock(ha_thd(), get_lock_type())))
+      DBUG_RETURN(error);
+    bitmap_set_bit(&m_locked_partitions, m_last_part);
+  }
+
   DBUG_RETURN(m_file[m_last_part]->rnd_pos_by_record(record));
 }

@@ -5173,6 +5223,13 @@ int ha_partition::index_init(uint inx, bool sorted)
        i < m_tot_parts;
        i= bitmap_get_next_set(&m_part_info->read_partitions, i))
   {
+    if (!bitmap_is_set(&m_locked_partitions, i) && ha_thd()->delay_prune_partition)
+    {
+      if ((error= m_file[i]->ha_external_lock(ha_thd(), get_lock_type())))
+        goto err;
+      bitmap_set_bit(&m_locked_partitions, i);
+    }
+
     if ((error= m_file[i]->ha_index_init(inx, sorted)))
       goto err;

diff --git a/sql/log_event.cc b/sql/log_event.cc
index 87e60ab..91415b2 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -11878,6 +11878,9 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli)
     used in the transaction and proceed with execution of the actual
     event.
   */
+
+  if (opt_rds_perf_thr_lock_partition)
+    thd->delay_prune_partition= true;
   if (!thd->lock)
   {
     /*
@@ -11959,6 +11962,7 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli)
                     (actual_error ? thd->get_stmt_da()->message() :
                      "unexpected success or fatal error"));
         thd->is_slave_error= 1;
+        thd->delay_prune_partition= false;
       }
       const_cast<Relay_log_info*>(rli)->slave_close_thread_tables(thd);
       DBUG_RETURN(actual_error);
@@ -12012,6 +12016,7 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli)
             having severe errors which should not be skiped.
           */
           thd->is_slave_error= 1;
+          thd->delay_prune_partition= false;
           const_cast<Relay_log_info*>(rli)->slave_close_thread_tables(thd);
           DBUG_RETURN(ERR_BAD_TABLE_DEF);
         }
@@ -12298,6 +12303,7 @@ AFTER_MAIN_EXEC_ROW_LOOP:
     */
     thd->reset_current_stmt_binlog_format_row();
     thd->is_slave_error= 1;
+    thd->delay_prune_partition= false;
     DBUG_RETURN(error);
   }

@@ -12329,6 +12335,7 @@ AFTER_MAIN_EXEC_ROW_LOOP:
       free_root(thd->mem_root, MYF(MY_KEEP_PREALLOC));
     }
   }
+  thd->delay_prune_partition= false;
   DBUG_RETURN(error);
 }

diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index f9802a6..daf723a 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -670,6 +670,8 @@ my_bool opt_rds_binlog_savepoint_release= FALSE;
 my_bool opt_rds_binlog_replace_stmt_in_row= FALSE;
 my_bool rds_rpl_consistency_sync_enabled= FALSE;

+my_bool opt_rds_perf_thr_lock_partition= false;
+
 my_bool ic_reduce_hint_enable= 0;
 HASH ic_gather_hash;
 pthread_mutex_t ic_gather_hash_lock;
diff --git a/sql/mysqld.h b/sql/mysqld.h
index 961d2bf..84f3010 100644
--- a/sql/mysqld.h
+++ b/sql/mysqld.h
@@ -533,6 +533,7 @@ extern ulong rds_max_exec_plan_caches;
 extern my_bool opt_rds_binlog_savepoint_release;
 extern my_bool opt_rds_binlog_replace_stmt_in_row;
 extern my_bool rds_rpl_consistency_sync_enabled;
+extern my_bool opt_rds_perf_thr_lock_partition;
 /* Start of Flashback */
 extern char *rds_flashback_user, *rds_flashback_pass;
 extern char *rds_flashback_log_path, *rds_flashback_tool_path, *rds_flashback_mysql_path;
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 238585c..c2fef04 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -1270,6 +1270,7 @@ THD::THD(bool enable_plugins)
   rds_audit_log_buffer.str=
     (char *) my_malloc(rds_audit_log_buffer.length, MYF(MY_WME));
   atm_ctx.reset();
+  delay_prune_partition= false;
 }

 void THD::print_proc_info(const char *, ...)
diff --git a/sql/sql_class.h b/sql/sql_class.h
index d27b348..35f33ab 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -4607,6 +4607,7 @@ public:
   uint gen_rds_audit_log(char *rds_query, uint query_len,
                          enum enum_rds_audit_sql_command command);

+  bool delay_prune_partition;
   void init_iops_status()
   {
     start_logical_read= status_var.logical_read;
diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc
index eb307f7..d82fd2a 100644
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@ -6442,6 +6442,12 @@ static Sys_var_mybool Sys_rds_binlog_savepoint_release(
        GLOBAL_VAR(opt_rds_binlog_savepoint_release), CMD_LINE(OPT_ARG),
        DEFAULT(FALSE));

+static Sys_var_mybool Sys_opt_rds_perf_thr_lock_partition(
+       "opt_rds_perf_thr_lock_partition",
+       "Only thr lock the first partition if enabled",
+       GLOBAL_VAR(opt_rds_perf_thr_lock_partition), CMD_LINE(OPT_ARG),
+       DEFAULT(FALSE));
+
 static Sys_var_mybool Sys_rds_binlog_replace_stmt_in_row(
        "rds_binlog_replace_stmt_in_row", "whether REPLACE INTO or INSERT IGNORE "
        "flag should be set(check) when writting to(reading from) binary(relay) "

diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index b973255..485d0a0 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -4710,6 +4710,13 @@ int ha_partition::rnd_init(bool scan)
     */
     rnd_end();
     late_extra_cache(part_id);
+    if (!bitmap_is_set(&m_locked_partitions, part_id) && ha_thd()->delay_prune_partition)
+    {
+      if ((error= m_file[part_id]->ha_external_lock(ha_thd(), get_lock_type())))
+        goto err;
+      bitmap_set_bit(&m_locked_partitions, part_id);
+    }
+
     if ((error= m_file[part_id]->ha_rnd_init(scan)))
       goto err;
   }
@@ -4719,6 +4726,12 @@ int ha_partition::rnd_init(bool scan)
          i < m_tot_parts;
          i= bitmap_get_next_set(&m_part_info->read_partitions, i))
     {
+    if (!bitmap_is_set(&m_locked_partitions, i) && ha_thd()->delay_prune_partition)
+    {
+      if ((error= m_file[i]->ha_external_lock(ha_thd(), get_lock_type())))
+        goto err;
+      bitmap_set_bit(&m_locked_partitions, i);
+    }
       if ((error= m_file[i]->ha_rnd_init(scan)))
         goto err;
     }
@@ -4859,6 +4872,14 @@ int ha_partition::rnd_next(uchar *buf)
     m_last_part= part_id;
     m_part_spec.start_part= part_id;
     file= m_file[part_id];
+
+    if (!bitmap_is_set(&m_locked_partitions, part_id) && ha_thd()->delay_prune_partition)
+    {
+      if ((result= m_file[part_id]->ha_external_lock(ha_thd(), get_lock_type())))
+        break;
+      bitmap_set_bit(&m_locked_partitions, part_id);
+    }
+
     DBUG_PRINT("info", ("rnd_init on partition %d", part_id));
     if ((result= file->ha_rnd_init(1)))
       break;
