Commit a424d011 authored by unknown's avatar unknown

fixed bug 209 (SQL_SELECT_LIMIT and query cache incompatibility)


mysql-test/r/query_cache.result:
  test of SET OPTION SQL_SELECT_LIMIT
mysql-test/t/query_cache.test:
  test of SET OPTION SQL_SELECT_LIMIT
sql/sql_cache.cc:
  layout fixed
  SQL_SELECT_LIMIT stored in query cache now
sql/sql_parse.cc:
  room for SQL_SELECT_LAYOUT storing added
parent 280a1e4a
...@@ -581,3 +581,21 @@ show status like "Qcache_queries_in_cache"; ...@@ -581,3 +581,21 @@ show status like "Qcache_queries_in_cache";
Variable_name Value Variable_name Value
Qcache_queries_in_cache 0 Qcache_queries_in_cache 0
drop table t1; drop table t1;
create table t1 (a int);
insert into t1 values (1),(2);
show status like "Qcache_queries_in_cache";
Variable_name Value
Qcache_queries_in_cache 0
select * from t1;
a
1
2
SET OPTION SQL_SELECT_LIMIT=1;
select * from t1;
a
1
show status like "Qcache_queries_in_cache";
Variable_name Value
Qcache_queries_in_cache 2
SET OPTION SQL_SELECT_LIMIT=DEFAULT;
drop table t1;
...@@ -401,7 +401,6 @@ select * from t1 where id=2; ...@@ -401,7 +401,6 @@ select * from t1 where id=2;
# #
# Load data invalidation test # Load data invalidation test
# #
create table t1 (word char(20) not null); create table t1 (word char(20) not null);
select * from t1; select * from t1;
show status like "Qcache_queries_in_cache"; show status like "Qcache_queries_in_cache";
...@@ -412,7 +411,6 @@ drop table t1; ...@@ -412,7 +411,6 @@ drop table t1;
# #
# INTO OUTFILE/DUMPFILE test # INTO OUTFILE/DUMPFILE test
# #
drop table if exists t1; drop table if exists t1;
create table t1 (a int); create table t1 (a int);
insert into t1 values (1),(2),(3); insert into t1 values (1),(2),(3);
...@@ -421,3 +419,16 @@ select * from t1 into outfile "query_caceh.out.file"; ...@@ -421,3 +419,16 @@ select * from t1 into outfile "query_caceh.out.file";
select * from t1 limit 1 into dumpfile "query_cache.dump.file"; select * from t1 limit 1 into dumpfile "query_cache.dump.file";
show status like "Qcache_queries_in_cache"; show status like "Qcache_queries_in_cache";
drop table t1; drop table t1;
#
# test of SQL_SELECT_LIMIT
#
create table t1 (a int);
insert into t1 values (1),(2);
show status like "Qcache_queries_in_cache";
select * from t1;
SET OPTION SQL_SELECT_LIMIT=1;
select * from t1;
show status like "Qcache_queries_in_cache";
SET OPTION SQL_SELECT_LIMIT=DEFAULT;
drop table t1;
...@@ -743,11 +743,11 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used) ...@@ -743,11 +743,11 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used)
if (query_cache_size == 0) if (query_cache_size == 0)
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
if ((local_tables = is_cacheable(thd, thd->query_length, if ((local_tables= is_cacheable(thd, thd->query_length,
thd->query, &thd->lex, tables_used))) thd->query, &thd->lex, tables_used)))
{ {
NET *net = &thd->net; NET *net= &thd->net;
byte flags = (thd->client_capabilities & CLIENT_LONG_FLAG ? 0x80 : 0); byte flags= (thd->client_capabilities & CLIENT_LONG_FLAG ? 0x80 : 0);
STRUCT_LOCK(&structure_guard_mutex); STRUCT_LOCK(&structure_guard_mutex);
if (query_cache_size == 0) if (query_cache_size == 0)
...@@ -775,8 +775,10 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used) ...@@ -775,8 +775,10 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used)
flags|= (byte) thd->variables.convert_set->number(); flags|= (byte) thd->variables.convert_set->number();
DBUG_ASSERT(thd->variables.convert_set->number() < 128); DBUG_ASSERT(thd->variables.convert_set->number() < 128);
} }
tot_length=thd->query_length+thd->db_length+2; tot_length= thd->query_length+thd->db_length+2+sizeof(ha_rows);
thd->query[tot_length-1] = (char) flags; thd->query[tot_length-1]= (char) flags;
memcpy((void *)(thd->query + (tot_length-sizeof(ha_rows)-1)),
(const void *)&thd->variables.select_limit, sizeof(ha_rows));
/* Check if another thread is processing the same query? */ /* Check if another thread is processing the same query? */
Query_cache_block *competitor = (Query_cache_block *) Query_cache_block *competitor = (Query_cache_block *)
...@@ -910,7 +912,7 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length) ...@@ -910,7 +912,7 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
} }
Query_cache_block *query_block; Query_cache_block *query_block;
tot_length=query_length+thd->db_length+2; tot_length= query_length+thd->db_length+2+sizeof(ha_rows);
if (thd->db_length) if (thd->db_length)
{ {
memcpy(sql+query_length+1, thd->db, thd->db_length); memcpy(sql+query_length+1, thd->db, thd->db_length);
...@@ -926,15 +928,18 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length) ...@@ -926,15 +928,18 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
Most significant bit - CLIENT_LONG_FLAG, Most significant bit - CLIENT_LONG_FLAG,
Other - charset number (0 no charset convertion) Other - charset number (0 no charset convertion)
*/ */
flags = (thd->client_capabilities & CLIENT_LONG_FLAG ? 0x80 : 0); flags= (thd->client_capabilities & CLIENT_LONG_FLAG ? 0x80 : 0);
if (thd->variables.convert_set != 0) if (thd->variables.convert_set != 0)
{ {
flags |= (byte) thd->variables.convert_set->number(); flags|= (byte) thd->variables.convert_set->number();
DBUG_ASSERT(thd->variables.convert_set->number() < 128); DBUG_ASSERT(thd->variables.convert_set->number() < 128);
} }
sql[tot_length-1] = (char) flags; sql[tot_length-1]= (char) flags;
query_block = (Query_cache_block *) hash_search(&queries, (byte*) sql, memcpy((void *)(sql + (tot_length-sizeof(ha_rows)-1)),
(const void *)&thd->variables.select_limit, sizeof(ha_rows));
query_block= (Query_cache_block *) hash_search(&queries, (byte*) sql,
tot_length); tot_length);
/* Quick abort on unlocked data */ /* Quick abort on unlocked data */
if (query_block == 0 || if (query_block == 0 ||
query_block->query()->result() == 0 || query_block->query()->result() == 0 ||
......
...@@ -1029,7 +1029,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, ...@@ -1029,7 +1029,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
/* We must allocate some extra memory for query cache */ /* We must allocate some extra memory for query cache */
if (!(thd->query= (char*) thd->memdup_w_gap((gptr) (packet), if (!(thd->query= (char*) thd->memdup_w_gap((gptr) (packet),
packet_length, packet_length,
thd->db_length+2))) thd->db_length+2+
sizeof(ha_rows))))
break; break;
thd->query[packet_length]=0; thd->query[packet_length]=0;
thd->packet.shrink(thd->variables.net_buffer_length);// Reclaim some memory thd->packet.shrink(thd->variables.net_buffer_length);// Reclaim some memory
......
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