Commit 8b0a676e authored by Timothy Smith's avatar Timothy Smith

Apply InnoDB snapshot innodb-5.1-ss2637, part 1. Fixes

Bug #37885: row_search_for_mysql may gap lock unnecessarily with SQL comments in query


Detailed revision comments:

r2603 | marko | 2008-08-21 16:25:05 +0300 (Thu, 21 Aug 2008) | 10 lines
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.
parent 980ec41f
...@@ -507,6 +507,18 @@ thd_has_edited_nontrans_tables( ...@@ -507,6 +507,18 @@ thd_has_edited_nontrans_tables(
return((ibool) thd_non_transactional_update((THD*) thd)); 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. */ Obtain the InnoDB transaction of a MySQL thread. */
inline inline
......
...@@ -63,5 +63,14 @@ thd_has_edited_nontrans_tables( ...@@ -63,5 +63,14 @@ thd_has_edited_nontrans_tables(
been edited */ been edited */
void* thd); /* in: thread handle (THD*) */ 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
#endif #endif
...@@ -32,6 +32,7 @@ Created 12/19/1997 Heikki Tuuri ...@@ -32,6 +32,7 @@ Created 12/19/1997 Heikki Tuuri
#include "row0mysql.h" #include "row0mysql.h"
#include "read0read.h" #include "read0read.h"
#include "buf0lru.h" #include "buf0lru.h"
#include "ha_prototypes.h"
/* Maximum number of rows to prefetch; MySQL interface has another parameter */ /* Maximum number of rows to prefetch; MySQL interface has another parameter */
#define SEL_MAX_N_PREFETCH 16 #define SEL_MAX_N_PREFETCH 16
...@@ -3578,20 +3579,12 @@ row_search_for_mysql( ...@@ -3578,20 +3579,12 @@ row_search_for_mysql(
if (trx->isolation_level <= TRX_ISO_READ_COMMITTED if (trx->isolation_level <= TRX_ISO_READ_COMMITTED
&& prebuilt->select_lock_type != LOCK_NONE && prebuilt->select_lock_type != LOCK_NONE
&& trx->mysql_thd != NULL && trx->mysql_thd != NULL
&& trx->mysql_query_str != NULL && thd_is_select(trx->mysql_thd)) {
&& *trx->mysql_query_str != NULL) {
/* 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 /* It is a plain locking SELECT and the isolation
level is low: do not lock gaps */ 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 /* Note that if the search mode was GE or G, then the cursor
naturally moves upward (in fetch next) in alphabetical order, naturally moves upward (in fetch next) in alphabetical order,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment