commit 25b6ae86a98fa0346f23e346a3e3cf2f59428129
Author: Sachin Setiya <sachinsetia1001@gmail.com>
Date:   Thu May 3 18:14:19 2018 +0530

    MDEV-14472 Assertion `is_current_stmt_binlog_format_row()' failed in...
    THD::binlog_write_table_map
    
    Commit Message it is really very long , will be added after review

diff --git a/mysql-test/suite/binlog/r/mdev_14472.result b/mysql-test/suite/binlog/r/mdev_14472.result
new file mode 100644
index 00000000000..0a2483678f1
--- /dev/null
+++ b/mysql-test/suite/binlog/r/mdev_14472.result
@@ -0,0 +1,12 @@
+CREATE TABLE t1 (f1 INT);
+CREATE TABLE t2 (f2 INT);
+CREATE TABLE t3 (f3 INT);
+CREATE TABLE t4 (pk INT AUTO_INCREMENT PRIMARY KEY);
+CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 VALUES ();
+CREATE TRIGGER tr2 AFTER INSERT ON t1 FOR EACH ROW INSERT INTO t3 VALUES ();
+CREATE TRIGGER tr3 BEFORE INSERT ON t2 FOR EACH ROW INSERT INTO t4 VALUES ();
+LOCK TABLE t1 WRITE;
+INSERT INTO t2 () VALUES ();
+INSERT INTO t3 VALUES ();
+UNLOCK TABLES;
+DROP TABLE t1, t2, t3, t4;
diff --git a/mysql-test/suite/binlog/t/mdev_14472.test b/mysql-test/suite/binlog/t/mdev_14472.test
new file mode 100644
index 00000000000..fd892a44f5c
--- /dev/null
+++ b/mysql-test/suite/binlog/t/mdev_14472.test
@@ -0,0 +1,22 @@
+--source include/have_log_bin.inc
+--source include/have_binlog_format_mixed.inc
+
+# Reproducible with MyISAM, InnoDB, Aria
+
+CREATE TABLE t1 (f1 INT);
+CREATE TABLE t2 (f2 INT);
+CREATE TABLE t3 (f3 INT);
+CREATE TABLE t4 (pk INT AUTO_INCREMENT PRIMARY KEY);
+
+CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t2 VALUES ();
+CREATE TRIGGER tr2 AFTER INSERT ON t1 FOR EACH ROW INSERT INTO t3 VALUES ();
+CREATE TRIGGER tr3 BEFORE INSERT ON t2 FOR EACH ROW INSERT INTO t4 VALUES ();
+
+LOCK TABLE t1 WRITE;
+INSERT INTO t2 () VALUES ();
+INSERT INTO t3 VALUES ();
+
+# Cleanup
+
+UNLOCK TABLES;
+DROP TABLE t1, t2, t3, t4;
diff --git a/sql/handler.cc b/sql/handler.cc
index 06c407b572a..c0c9d39856b 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -5650,7 +5650,10 @@ inline bool handler::check_table_binlog_row_based(bool binlog_row)
 {
   if (unlikely((table->in_use->variables.sql_log_bin_off)))
     return 0;                            /* Called by partitioning engine */
-  if (unlikely((!check_table_binlog_row_based_done)))
+  /* Dont use cached result when current binlog format is stmt */
+  if (unlikely(check_table_binlog_row_based_result &&
+              !table->in_use->is_current_stmt_binlog_format_row() ||
+               (!check_table_binlog_row_based_done)))
   {
     check_table_binlog_row_based_done= 1;
     check_table_binlog_row_based_result=
--
Regards
Sachin Setiya
Software Engineer at  MariaDB