From 625f7f0d5565c90ce3d2ea3cf14706f28fc5c0e5 Mon Sep 17 00:00:00 2001
From: "mats@mysql.com" <>
Date: Tue, 15 Feb 2005 11:02:01 +0100
Subject: [PATCH] Bug#7879: Using TL_READ_NO_INSERT locks instead of TL_READ
 locks when reading tables in "complex" SQL statements. If inserts happen in a
 table being read, the statements have no serialization order and the change
 can therefore not be reproduced on the slave.

---
 sql/sql_update.cc | 5 ++++-
 sql/sql_yacc.yy   | 4 ++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 4f7e34ec74f..bff360d02dc 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -479,7 +479,10 @@ int mysql_multi_update(THD *thd,
       else
       {
 	DBUG_PRINT("info",("setting table `%s` for read-only", tl->alias));
-	tl->lock_type= TL_READ;
+	// If we are using the binary log, we need TL_READ_NO_INSERT to get
+	// correct order of statements. Otherwise, we use a TL_READ lock to
+	// improve performance.
+	tl->lock_type= using_update_log ? TL_READ_NO_INSERT : TL_READ;
 	tl->updating= 0;
 	wants= SELECT_ACL;
       }
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 7b72c73a915..3e45e35c618 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -822,7 +822,7 @@ create_select:
           SELECT_SYM
           {
 	    LEX *lex=Lex;
-	    lex->lock_option= (using_update_log) ? TL_READ_NO_INSERT : TL_READ;
+	    lex->lock_option= using_update_log ? TL_READ_NO_INSERT : TL_READ;
 	    if (lex->sql_command == SQLCOM_INSERT)
 	      lex->sql_command= SQLCOM_INSERT_SELECT;
 	    else if (lex->sql_command == SQLCOM_REPLACE)
@@ -1532,7 +1532,7 @@ select_part2:
 	{
 	  LEX *lex=Lex;
 	  lex->lock_option=TL_READ;
-	   mysql_init_select(lex);
+          mysql_init_select(lex);
 	}
 	select_options select_item_list select_into select_lock_type;