|
|
|
@ -462,6 +462,7 @@ static void make_base_query(String *new_query, |
|
|
|
DBUG_ASSERT(query[query_length] == 0); |
|
|
|
DBUG_ASSERT(!is_white_space(query[0])); |
|
|
|
|
|
|
|
new_query->length(0); // Don't copy anything from old buffer
|
|
|
|
if (new_query->realloc(query_length + additional_length)) |
|
|
|
{ |
|
|
|
/*
|
|
|
|
@ -540,8 +541,11 @@ insert_space: |
|
|
|
} |
|
|
|
if (buffer == last_space) |
|
|
|
buffer--; // Remove the last space
|
|
|
|
*buffer= 0; |
|
|
|
*buffer= 0; // End zero after query
|
|
|
|
new_query->length((size_t) (buffer - new_query->ptr())); |
|
|
|
|
|
|
|
/* Copy db_length */ |
|
|
|
memcpy(buffer+1, query_end+1, QUERY_CACHE_DB_LENGTH_SIZE); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1473,8 +1477,8 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d", |
|
|
|
/* Key is query + database + flag */ |
|
|
|
if (thd->db_length) |
|
|
|
{ |
|
|
|
memcpy((char*) (query + query_length + 1 + sizeof(size_t)), thd->db, |
|
|
|
thd->db_length); |
|
|
|
memcpy((char*) (query + query_length + 1 + QUERY_CACHE_DB_LENGTH_SIZE), |
|
|
|
thd->db, thd->db_length); |
|
|
|
DBUG_PRINT("qcache", ("database: %s length: %u", |
|
|
|
thd->db, (unsigned) thd->db_length)); |
|
|
|
} |
|
|
|
@ -1482,8 +1486,8 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d", |
|
|
|
{ |
|
|
|
DBUG_PRINT("qcache", ("No active database")); |
|
|
|
} |
|
|
|
tot_length= query_length + thd->db_length + 1 + sizeof(size_t) + |
|
|
|
QUERY_CACHE_FLAGS_SIZE; |
|
|
|
tot_length= (query_length + thd->db_length + 1 + |
|
|
|
QUERY_CACHE_DB_LENGTH_SIZE + QUERY_CACHE_FLAGS_SIZE); |
|
|
|
/*
|
|
|
|
We should only copy structure (don't use it location directly) |
|
|
|
because of alignment issue |
|
|
|
@ -1642,7 +1646,7 @@ Query_cache::send_result_to_client(THD *thd, char *org_sql, uint query_length) |
|
|
|
Query_cache_block_table *block_table, *block_table_end; |
|
|
|
ulong tot_length; |
|
|
|
Query_cache_query_flags flags; |
|
|
|
const char *sql, *sql_end; |
|
|
|
const char *sql, *sql_end, *found_brace= 0; |
|
|
|
DBUG_ENTER("Query_cache::send_result_to_client"); |
|
|
|
|
|
|
|
/*
|
|
|
|
@ -1716,9 +1720,16 @@ Query_cache::send_result_to_client(THD *thd, char *org_sql, uint query_length) |
|
|
|
case '\n': |
|
|
|
case '\t': |
|
|
|
case ' ': |
|
|
|
case '(': // To handle (select a from t1) union (select a from t1);
|
|
|
|
sql++; |
|
|
|
continue; |
|
|
|
case '(': // To handle (select a from t1) union (select a from t1);
|
|
|
|
if (!found_brace) |
|
|
|
{ |
|
|
|
found_brace= sql; |
|
|
|
sql++; |
|
|
|
continue; |
|
|
|
} |
|
|
|
/* fall trough */ |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
@ -1752,8 +1763,7 @@ Query_cache::send_result_to_client(THD *thd, char *org_sql, uint query_length) |
|
|
|
sure the new current database has a name with the same length |
|
|
|
as the previous one. |
|
|
|
*/ |
|
|
|
size_t db_len; |
|
|
|
memcpy((char *) &db_len, (sql + query_length + 1), sizeof(size_t)); |
|
|
|
size_t db_len= uint2korr(sql_end+1); |
|
|
|
if (thd->db_length != db_len) |
|
|
|
{ |
|
|
|
/*
|
|
|
|
@ -1788,8 +1798,11 @@ Query_cache::send_result_to_client(THD *thd, char *org_sql, uint query_length) |
|
|
|
Query_cache_block *query_block; |
|
|
|
if (opt_query_cache_strip_comments) |
|
|
|
{ |
|
|
|
if (found_brace) |
|
|
|
sql= found_brace; |
|
|
|
make_base_query(&thd->base_query, sql, (size_t) (sql_end - sql), |
|
|
|
thd->db_length + 1 + QUERY_CACHE_FLAGS_SIZE); |
|
|
|
thd->db_length + 1 + QUERY_CACHE_DB_LENGTH_SIZE + |
|
|
|
QUERY_CACHE_FLAGS_SIZE); |
|
|
|
sql= thd->base_query.ptr(); |
|
|
|
query_length= thd->base_query.length(); |
|
|
|
} |
|
|
|
@ -1799,15 +1812,15 @@ Query_cache::send_result_to_client(THD *thd, char *org_sql, uint query_length) |
|
|
|
thd->base_query.set(sql, query_length, system_charset_info); |
|
|
|
} |
|
|
|
|
|
|
|
tot_length= query_length + 1 + sizeof(size_t) + |
|
|
|
thd->db_length + QUERY_CACHE_FLAGS_SIZE; |
|
|
|
tot_length= (query_length + 1 + QUERY_CACHE_DB_LENGTH_SIZE + |
|
|
|
thd->db_length + QUERY_CACHE_FLAGS_SIZE); |
|
|
|
|
|
|
|
if (thd->db_length) |
|
|
|
{ |
|
|
|
memcpy((char*) (sql+query_length+1+ sizeof(size_t)), thd->db, |
|
|
|
thd->db_length); |
|
|
|
memcpy((uchar*) sql + query_length + 1 + QUERY_CACHE_DB_LENGTH_SIZE, |
|
|
|
thd->db, thd->db_length); |
|
|
|
DBUG_PRINT("qcache", ("database: '%s' length: %u", |
|
|
|
thd->db, (unsigned)thd->db_length)); |
|
|
|
thd->db, (uint) thd->db_length)); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
@ -1929,7 +1942,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d", |
|
|
|
{ |
|
|
|
DBUG_PRINT("qcache", |
|
|
|
("Temporary table detected: '%s.%s'", |
|
|
|
table_list.db, table_list.alias)); |
|
|
|
tmptable->s->db.str, tmptable->alias.c_ptr())); |
|
|
|
unlock(); |
|
|
|
/*
|
|
|
|
We should not store result of this query because it contain |
|
|
|
|