diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc
index 2731211db72..6b1e11011c7 100644
--- a/storage/innobase/btr/btr0cur.cc
+++ b/storage/innobase/btr/btr0cur.cc
@@ -5653,19 +5653,18 @@ It is assumed that the mtr has an x-latch on the page where the cursor is
 positioned, but no latch on the whole tree.
 @return TRUE if success, i.e., the page did not become too empty */
 ibool
-btr_cur_optimistic_delete_func(
+btr_cur_optimistic_delete(
 /*===========================*/
 	btr_cur_t*	cursor,	/*!< in: cursor on leaf page, on the record to
 				delete; cursor stays valid: if deletion
 				succeeds, on function exit it points to the
 				successor of the deleted record */
-#ifdef UNIV_DEBUG
 	ulint		flags,	/*!< in: BTR_CREATE_FLAG or 0 */
-#endif /* UNIV_DEBUG */
-	mtr_t*		mtr)	/*!< in: mtr; if this function returns
+	mtr_t*		mtr,	/*!< in: mtr; if this function returns
 				TRUE on a leaf page of a secondary
 				index, the mtr must be committed
 				before latching any further pages */
+	bool interesting)
 {
 	buf_block_t*	block;
 	rec_t*		rec;
@@ -5719,7 +5718,7 @@ btr_cur_optimistic_delete_func(
 			    && rec_is_add_metadata(first_rec, *index));
 		if (UNIV_LIKELY(empty_table)) {
 			if (UNIV_LIKELY(!is_metadata)) {
-				lock_update_delete(block, rec);
+				lock_update_delete(block, rec, interesting);
 			}
 			btr_page_empty(block, buf_block_get_page_zip(block),
 				       index, 0, mtr);
@@ -5764,7 +5763,7 @@ btr_cur_optimistic_delete_func(
 					    cursor->index, mtr);
 			goto func_exit;
 		} else {
-			lock_update_delete(block, rec);
+		  	lock_update_delete(block, rec, interesting);
 
 			btr_search_update_hash_on_delete(cursor);
 		}
@@ -5842,7 +5841,8 @@ btr_cur_pessimistic_delete(
 				deleted record on function exit */
 	ulint		flags,	/*!< in: BTR_CREATE_FLAG or 0 */
 	bool		rollback,/*!< in: performing rollback? */
-	mtr_t*		mtr)	/*!< in: mtr */
+	mtr_t*		mtr,	/*!< in: mtr */
+	bool		interesting)
 {
 	buf_block_t*	block;
 	page_t*		page;
@@ -5923,7 +5923,7 @@ btr_cur_pessimistic_delete(
 			ut_ad(index->table->supports_instant());
 			ut_ad(index->is_primary());
 		} else if (flags == 0) {
-			lock_update_delete(block, rec);
+			lock_update_delete(block, rec, interesting);
 		}
 
 		if (block->page.id.page_no() != index->page) {
diff --git a/storage/innobase/include/btr0cur.h b/storage/innobase/include/btr0cur.h
index b28fc48405d..c8953775434 100644
--- a/storage/innobase/include/btr0cur.h
+++ b/storage/innobase/include/btr0cur.h
@@ -509,27 +509,19 @@ that the mtr has an x-latch on the page where the cursor is positioned,
 but no latch on the whole tree.
 @return TRUE if success, i.e., the page did not become too empty */
 ibool
-btr_cur_optimistic_delete_func(
+btr_cur_optimistic_delete(
 /*===========================*/
 	btr_cur_t*	cursor,	/*!< in: cursor on the record to delete;
 				cursor stays valid: if deletion succeeds,
 				on function exit it points to the successor
 				of the deleted record */
-# ifdef UNIV_DEBUG
 	ulint		flags,	/*!< in: BTR_CREATE_FLAG or 0 */
-# endif /* UNIV_DEBUG */
-	mtr_t*		mtr)	/*!< in: mtr; if this function returns
+	mtr_t*		mtr,	/*!< in: mtr; if this function returns
 				TRUE on a leaf page of a secondary
 				index, the mtr must be committed
 				before latching any further pages */
+	bool interesting=false)
 	MY_ATTRIBUTE((nonnull, warn_unused_result));
-# ifdef UNIV_DEBUG
-#  define btr_cur_optimistic_delete(cursor, flags, mtr)		\
-	btr_cur_optimistic_delete_func(cursor, flags, mtr)
-# else /* UNIV_DEBUG */
-#  define btr_cur_optimistic_delete(cursor, flags, mtr)		\
-	btr_cur_optimistic_delete_func(cursor, mtr)
-# endif /* UNIV_DEBUG */
 /*************************************************************//**
 Removes the record on which the tree cursor is positioned. Tries
 to compress the page if its fillfactor drops below a threshold
@@ -556,7 +548,8 @@ btr_cur_pessimistic_delete(
 				deleted record on function exit */
 	ulint		flags,	/*!< in: BTR_CREATE_FLAG or 0 */
 	bool		rollback,/*!< in: performing rollback? */
-	mtr_t*		mtr)	/*!< in: mtr */
+	mtr_t*		mtr,	/*!< in: mtr */
+	bool interesting=false)
 	MY_ATTRIBUTE((nonnull));
 /** Delete the node pointer in a parent page.
 @param[in,out]	parent	cursor pointing to parent record
diff --git a/storage/innobase/include/lock0lock.h b/storage/innobase/include/lock0lock.h
index 8ae0b062729..65c3a676801 100644
--- a/storage/innobase/include/lock0lock.h
+++ b/storage/innobase/include/lock0lock.h
@@ -220,7 +220,8 @@ void
 lock_update_delete(
 /*===============*/
 	const buf_block_t*	block,	/*!< in: buffer block containing rec */
-	const rec_t*		rec);	/*!< in: the record to be removed */
+	const rec_t*		rec,	/*!< in: the record to be removed */
+	bool interesting = false);
 /*********************************************************************//**
 Stores on the page infimum record the explicit locks of another record.
 This function is used to store the lock state of a record when it is
diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc
index 23b3b9f4d14..ae8ba1badb7 100644
--- a/storage/innobase/lock/lock0lock.cc
+++ b/storage/innobase/lock/lock0lock.cc
@@ -2420,8 +2420,9 @@ lock_rec_inherit_to_gap(
 						this record */
 	ulint			heir_heap_no,	/*!< in: heap_no of the
 						inheriting record */
-	ulint			heap_no)	/*!< in: heap_no of the
+	ulint			heap_no,	/*!< in: heap_no of the
 						donating record */
+	bool interesting=false)
 {
 	lock_t*	lock;
 
@@ -2436,13 +2437,15 @@ lock_rec_inherit_to_gap(
 	for (lock = lock_rec_get_first(lock_sys.rec_hash, block, heap_no);
 	     lock != NULL;
 	     lock = lock_rec_get_next(heap_no, lock)) {
-
 		if (!lock_rec_get_insert_intention(lock)
 		    && !((srv_locks_unsafe_for_binlog
 			  || lock->trx->isolation_level
 			  <= TRX_ISO_READ_COMMITTED)
 			 && lock_get_mode(lock) ==
 			 (lock->trx->duplicates ? LOCK_S : LOCK_X))) {
+
+			ut_a(!interesting || !(lock->type_mode & LOCK_WAIT));
+
 			lock_rec_add_to_queue(
 				LOCK_REC | LOCK_GAP
 				| ulint(lock_get_mode(lock)),
@@ -3361,7 +3364,8 @@ void
 lock_update_delete(
 /*===============*/
 	const buf_block_t*	block,	/*!< in: buffer block containing rec */
-	const rec_t*		rec)	/*!< in: the record to be removed */
+	const rec_t*		rec,	/*!< in: the record to be removed */
+	bool interesting)
 {
 	const page_t*	page = block->frame;
 	ulint		heap_no;
@@ -3386,7 +3390,7 @@ lock_update_delete(
 
 	/* Let the next record inherit the locks from rec, in gap mode */
 
-	lock_rec_inherit_to_gap(block, block, next_heap_no, heap_no);
+	lock_rec_inherit_to_gap(block, block, next_heap_no, heap_no, interesting);
 
 	/* Reset the lock bits on rec and release waiting transactions */
 
diff --git a/storage/innobase/row/row0purge.cc b/storage/innobase/row/row0purge.cc
index 04dfcbad0d3..adb22fa2630 100644
--- a/storage/innobase/row/row0purge.cc
+++ b/storage/innobase/row/row0purge.cc
@@ -141,13 +141,13 @@ row_purge_remove_clust_if_poss_low(
 
 	if (mode == BTR_MODIFY_LEAF) {
 		success = btr_cur_optimistic_delete(
-			btr_pcur_get_btr_cur(&node->pcur), 0, &mtr);
+			btr_pcur_get_btr_cur(&node->pcur), 0, &mtr, true);
 	} else {
 		dberr_t	err;
 		ut_ad(mode == (BTR_MODIFY_TREE | BTR_LATCH_FOR_DELETE));
 		btr_cur_pessimistic_delete(
 			&err, FALSE, btr_pcur_get_btr_cur(&node->pcur), 0,
-			false, &mtr);
+			false, &mtr, true);
 
 		switch (err) {
 		case DB_SUCCESS:
@@ -469,7 +469,7 @@ row_purge_remove_sec_if_poss_tree(
 
 		btr_cur_pessimistic_delete(&err, FALSE,
 					   btr_pcur_get_btr_cur(&pcur),
-					   0, false, &mtr);
+					   0, false, &mtr, true);
 		switch (UNIV_EXPECT(err, DB_SUCCESS)) {
 		case DB_SUCCESS:
 			break;
@@ -639,7 +639,7 @@ row_purge_remove_sec_if_poss_leaf(
 				}
 			}
 
-			if (!btr_cur_optimistic_delete(btr_cur, 0, &mtr)) {
+			if (!btr_cur_optimistic_delete(btr_cur, 0, &mtr, true)) {
 
 				/* The index entry could not be deleted. */
 				success = false;
