From 0d71a36d46abeaec07d138e4ca449bd1be7cd146 Mon Sep 17 00:00:00 2001 From: Annamalai Gurusami Date: Wed, 10 Jul 2013 10:49:17 +0530 Subject: [PATCH] Bug #14017206 WITH CONSISTENT SNAPSHOT DOES NOT WORK WITH ISOLATION LEVEL SERIALIZABLE Problem: The documentation claims that WITH CONSISTENT SNAPSHOT will work for both REPEATABLE READ and SERIALIZABLE isolation levels. But it will work only for REPEATABLE READ isolation level. Also, the clause WITH CONSISTENT SNAPSHOT is silently ignored when it is not applicable to the given isolation level. Solution: Generate a warning when the clause WITH CONSISTENT SNAPSHOT is ignored. rb#2797 approved by Kevin. Note: Support team wanted to push this to 5.5+. --- sql/sql_class.cc | 4 ++++ storage/innobase/handler/ha_innodb.cc | 29 +++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/sql/sql_class.cc b/sql/sql_class.cc index fb4ed99b8bb..03b8cff3e25 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -3552,6 +3552,10 @@ extern "C" unsigned long thd_get_thread_id(const MYSQL_THD thd) return((unsigned long)thd->thread_id); } +extern "C" enum_tx_isolation thd_get_trx_isolation(const MYSQL_THD thd) +{ + return thd->tx_isolation; +} #ifdef INNODB_COMPATIBILITY_HOOKS extern "C" struct charset_info_st *thd_charset(MYSQL_THD thd) diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 02bae038192..163c89d6cc5 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -87,6 +87,9 @@ extern "C" { #include "ha_prototypes.h" #include "ut0mem.h" #include "ibuf0ibuf.h" + +enum_tx_isolation thd_get_trx_isolation(const THD* thd); + } #include "ha_innodb.h" @@ -391,6 +394,15 @@ innobase_alter_table_flags( /*=======================*/ uint flags); +/******************************************************************//** +Maps a MySQL trx isolation level code to the InnoDB isolation level code +@return InnoDB isolation level */ +static inline +ulint +innobase_map_isolation_level( +/*=========================*/ + enum_tx_isolation iso); /*!< in: MySQL isolation level code */ + static const char innobase_hton_name[]= "InnoDB"; /*************************************************************//** @@ -2705,9 +2717,22 @@ innobase_start_trx_and_assign_read_view( trx_start_if_not_started(trx); - /* Assign a read view if the transaction does not have it yet */ + /* Assign a read view if the transaction does not have it yet. + Do this only if transaction is using REPEATABLE READ isolation + level. */ + trx->isolation_level = innobase_map_isolation_level( + thd_get_trx_isolation(thd)); - trx_assign_read_view(trx); + if (trx->isolation_level == TRX_ISO_REPEATABLE_READ) { + trx_assign_read_view(trx); + } else { + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, + HA_ERR_UNSUPPORTED, + "InnoDB: WITH CONSISTENT SNAPSHOT " + "was ignored because this phrase " + "can only be used with " + "REPEATABLE READ isolation level."); + } /* Set the MySQL flag to mark that there is an active transaction */