MXS-1043: Handle @@identity like @@last_insert_id

The type of @@identity, @@last_insert_id and last_insert_id() is
now the same, that is, QUERY_TYPE_READ|QUERY_TYPE_MASTER_READ.
This commit is contained in:
Johan Wikman
2016-12-02 10:58:21 +02:00
parent ac0f975f9c
commit 0218ac9e9c
4 changed files with 32 additions and 6 deletions

View File

@ -913,11 +913,23 @@ static uint32_t resolve_query_type(parsing_info_t *pi, THD* thd)
/** System session variable */ /** System session variable */
case Item_func::GSYSVAR_FUNC: case Item_func::GSYSVAR_FUNC:
{
const char* name = item->name;
if (name &&
((strcasecmp(name, "@@last_insert_id") == 0) ||
(strcasecmp(name, "@@identity") == 0)))
{
func_qtype |= QUERY_TYPE_MASTER_READ;
}
else
{
func_qtype |= QUERY_TYPE_SYSVAR_READ; func_qtype |= QUERY_TYPE_SYSVAR_READ;
}
MXS_DEBUG("%lu [resolve_query_type] " MXS_DEBUG("%lu [resolve_query_type] "
"functype GSYSVAR_FUNC, system " "functype GSYSVAR_FUNC, system "
"variable read.", "variable read.",
pthread_self()); pthread_self());
}
break; break;
/** User-defined variable read */ /** User-defined variable read */

View File

@ -669,10 +669,18 @@ static void update_affected_fields(QC_SQLITE_INFO* info,
info->types |= QUERY_TYPE_GSYSVAR_WRITE; info->types |= QUERY_TYPE_GSYSVAR_WRITE;
} }
else else
{
if ((strcasecmp(&zToken[2], "identity") == 0) ||
(strcasecmp(&zToken[2], "last_insert_id") == 0))
{
info->types |= QUERY_TYPE_MASTER_READ;
}
else
{ {
info->types |= QUERY_TYPE_SYSVAR_READ; info->types |= QUERY_TYPE_SYSVAR_READ;
} }
} }
}
else else
{ {
if ((prev_token == TK_EQ) && (pos == QC_TOKEN_LEFT)) if ((prev_token == TK_EQ) && (pos == QC_TOKEN_LEFT))

View File

@ -12,3 +12,6 @@ QUERY_TYPE_BEGIN_TRX
QUERY_TYPE_ROLLBACK QUERY_TYPE_ROLLBACK
QUERY_TYPE_COMMIT QUERY_TYPE_COMMIT
QUERY_TYPE_SESSION_WRITE QUERY_TYPE_SESSION_WRITE
QUERY_TYPE_READ|QUERY_TYPE_MASTER_READ
QUERY_TYPE_READ|QUERY_TYPE_MASTER_READ
QUERY_TYPE_READ|QUERY_TYPE_MASTER_READ

View File

@ -12,3 +12,6 @@ BEGIN;
ROLLBACK; ROLLBACK;
COMMIT; COMMIT;
use X; use X;
select last_insert_id();
select @@last_insert_id;
select @@identity;