From 06be45c3d17e2a06841b294f67f0989932646ed3 Mon Sep 17 00:00:00 2001 From: marko <> Date: Thu, 21 Aug 2008 12:25:05 +0000 Subject: [PATCH] branches/5.1: Identify SELECT statements by thd_sql_command() == SQLCOM_SELECT instead of parsing the query string. This fixes MySQL Bug #37885 without us having to implement lexical analysis of SQL comments in yet another place. thd_is_select(): A new predicate. row_search_for_mysql(): Use thd_is_select(). Approved by Heikki. --- handler/ha_innodb.cc | 12 ++++++++++++ include/ha_prototypes.h | 9 +++++++++ row/row0sel.c | 17 +++++------------ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/handler/ha_innodb.cc b/handler/ha_innodb.cc index 4b7c5b1246a..8a8d9698ac1 100644 --- a/handler/ha_innodb.cc +++ b/handler/ha_innodb.cc @@ -507,6 +507,18 @@ thd_has_edited_nontrans_tables( return((ibool) thd_non_transactional_update((THD*) thd)); } +/********************************************************************** +Returns true if the thread is executing a SELECT statement. */ +extern "C" +ibool +thd_is_select( +/*==========*/ + /* out: true if thd is executing SELECT */ + const void* thd) /* in: thread handle (THD*) */ +{ + return(thd_sql_command((const THD*) thd) == SQLCOM_SELECT); +} + /************************************************************************ Obtain the InnoDB transaction of a MySQL thread. */ inline diff --git a/include/ha_prototypes.h b/include/ha_prototypes.h index ef0722321af..6bfc43579b3 100644 --- a/include/ha_prototypes.h +++ b/include/ha_prototypes.h @@ -63,5 +63,14 @@ thd_has_edited_nontrans_tables( been edited */ void* thd); /* in: thread handle (THD*) */ +/********************************************************************** +Returns true if the thread is executing a SELECT statement. */ + +ibool +thd_is_select( +/*==========*/ + /* out: true if thd is executing SELECT */ + const void* thd); /* in: thread handle (THD*) */ + #endif #endif diff --git a/row/row0sel.c b/row/row0sel.c index c6a93d4e0d5..79f107ce77d 100644 --- a/row/row0sel.c +++ b/row/row0sel.c @@ -32,6 +32,7 @@ Created 12/19/1997 Heikki Tuuri #include "row0mysql.h" #include "read0read.h" #include "buf0lru.h" +#include "ha_prototypes.h" /* Maximum number of rows to prefetch; MySQL interface has another parameter */ #define SEL_MAX_N_PREFETCH 16 @@ -3578,19 +3579,11 @@ shortcut_fails_too_big_rec: if (trx->isolation_level <= TRX_ISO_READ_COMMITTED && prebuilt->select_lock_type != LOCK_NONE && trx->mysql_thd != NULL - && trx->mysql_query_str != NULL - && *trx->mysql_query_str != NULL) { + && thd_is_select(trx->mysql_thd)) { + /* It is a plain locking SELECT and the isolation + level is low: do not lock gaps */ - /* Scan the MySQL query string; check if SELECT is the first - word there */ - - if (dict_str_starts_with_keyword( - trx->mysql_thd, *trx->mysql_query_str, "SELECT")) { - /* It is a plain locking SELECT and the isolation - level is low: do not lock gaps */ - - set_also_gap_locks = FALSE; - } + set_also_gap_locks = FALSE; } /* Note that if the search mode was GE or G, then the cursor