From c07e346ca647037b109a99560fb9be3f799f2d24 Mon Sep 17 00:00:00 2001
From: Monty <monty@mariadb.org>
Date: Fri, 19 Apr 2019 13:20:15 +0300
Subject: [PATCH] MDEV-19252 Problem with DBUG_ASSERT_AS_PRINTF and
 marked_for_write()

Problem was that DBUG_FIX_WRITE_SET was not enabled when using
DBUG_ASSERT_AS_PRINTF
---
 mysql-test/main/unique.result |  4 ++++
 mysql-test/main/unique.test   | 12 ++++++++++++
 sql/field.cc                  | 15 ++++++++++-----
 sql/table.cc                  |  4 ++--
 4 files changed, 28 insertions(+), 7 deletions(-)
 create mode 100644 mysql-test/main/unique.result
 create mode 100644 mysql-test/main/unique.test

diff --git a/mysql-test/main/unique.result b/mysql-test/main/unique.result
new file mode 100644
index 00000000000..fbd937f0434
--- /dev/null
+++ b/mysql-test/main/unique.result
@@ -0,0 +1,4 @@
+CREATE TABLE t2 (n BLOB, UNIQUE(n));
+INSERT INTO t2 VALUES (1);
+DELETE FROM t2 WHERE n = 1;
+DROP TABLE t2;
diff --git a/mysql-test/main/unique.test b/mysql-test/main/unique.test
new file mode 100644
index 00000000000..549336bfcd1
--- /dev/null
+++ b/mysql-test/main/unique.test
@@ -0,0 +1,12 @@
+--source include/have_innodb.inc
+
+#
+# MDEV-19252 Warning about assertion failure marked_for_write_or_computed()
+# printed by release build with DBUG_ASSERT_AS_PRINTF, but no failure on debug
+# build
+#
+
+CREATE TABLE t2 (n BLOB, UNIQUE(n));
+INSERT INTO t2 VALUES (1);
+DELETE FROM t2 WHERE n = 1;
+DROP TABLE t2;
diff --git a/sql/field.cc b/sql/field.cc
index 72dc52143a0..e899a1ec4d6 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -67,14 +67,19 @@ inline bool Field::marked_for_read() const
           ptr < table->record[0] + table->s->reclength)));
 }
 
+/*
+  The name of this function is a bit missleading as in 10.4 we don't
+  have to test anymore if the field is computed. Instead we mark
+  changed fields with DBUG_FIX_WRITE_SET() in table.cc
+*/
 
 inline bool Field::marked_for_write_or_computed() const
 {
-  return is_stat_field || !table ||
-         (!table->write_set ||
-          bitmap_is_set(table->write_set, field_index) ||
-          (!(ptr >= table->record[0] &&
-          ptr < table->record[0] + table->s->reclength)));
+  return (is_stat_field || !table ||
+          (!table->write_set ||
+           bitmap_is_set(table->write_set, field_index) ||
+           (!(ptr >= table->record[0] &&
+              ptr < table->record[0] + table->s->reclength))));
 }
 
 
diff --git a/sql/table.cc b/sql/table.cc
index f605ebf9d31..e0330294c14 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -8080,10 +8080,10 @@ public:
 
 
 /*
-  to satisfy ASSERT_COLUMN_MARKED_FOR_WRITE Field's assert we temporarily
+  to satisfy marked_for_write_or_computed() Field's assert we temporarily
   mark field for write before storing the generated value in it
 */
-#ifndef DBUG_OFF
+#ifdef DBUG_ASSERT_EXISTS
 #define DBUG_FIX_WRITE_SET(f) bool _write_set_fixed= !bitmap_fast_test_and_set(write_set, (f)->field_index)
 #define DBUG_RESTORE_WRITE_SET(f) if (_write_set_fixed) bitmap_clear_bit(write_set, (f)->field_index)
 #else