Skip to content

Commit cf5dd72

Browse files
Davi ArnautDavi Arnaut
Davi Arnaut
authored and
Davi Arnaut
committed
Merge from 5.0-bugteam
2 parents 6dd7ac7 + 50a8cdc commit cf5dd72

File tree

6 files changed

+158
-9
lines changed

6 files changed

+158
-9
lines changed

mysql-test/r/cache_innodb.result

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ a
6767
2
6868
show status like "Qcache_queries_in_cache";
6969
Variable_name Value
70-
Qcache_queries_in_cache 3
70+
Qcache_queries_in_cache 6
7171
show status like "Qcache_hits";
7272
Variable_name Value
73-
Qcache_hits 3
73+
Qcache_hits 0
7474
insert into t1 values (3);
7575
insert into t2 values (3);
7676
insert into t1 values (4);
@@ -91,14 +91,14 @@ a
9191
2
9292
show status like "Qcache_queries_in_cache";
9393
Variable_name Value
94-
Qcache_queries_in_cache 1
94+
Qcache_queries_in_cache 2
9595
show status like "Qcache_hits";
9696
Variable_name Value
97-
Qcache_hits 4
97+
Qcache_hits 1
9898
commit;
9999
show status like "Qcache_queries_in_cache";
100100
Variable_name Value
101-
Qcache_queries_in_cache 1
101+
Qcache_queries_in_cache 2
102102
drop table t3,t2,t1;
103103
CREATE TABLE t1 (id int(11) NOT NULL auto_increment, PRIMARY KEY (id));
104104
select count(*) from t1;

mysql-test/r/query_cache.result

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,57 @@ Qcache_hits 1
16561656
DROP TABLE t1;
16571657
SET GLOBAL concurrent_insert= @save_concurrent_insert;
16581658
SET GLOBAL query_cache_size= default;
1659+
DROP TABLE IF EXISTS t1;
1660+
FLUSH STATUS;
1661+
SET GLOBAL query_cache_size=1048576;
1662+
CREATE TABLE t1 (a INT);
1663+
INSERT INTO t1 VALUES (1),(2),(3),(4),(5);
1664+
SHOW STATUS LIKE 'Qcache_queries_in_cache';
1665+
Variable_name Value
1666+
Qcache_queries_in_cache 0
1667+
SELECT * FROM t1;
1668+
a
1669+
1
1670+
2
1671+
3
1672+
4
1673+
5
1674+
BEGIN;
1675+
SELECT * FROM t1;
1676+
a
1677+
1
1678+
2
1679+
3
1680+
4
1681+
5
1682+
COMMIT;
1683+
SHOW STATUS LIKE 'Qcache_queries_in_cache';
1684+
Variable_name Value
1685+
Qcache_queries_in_cache 2
1686+
SHOW STATUS LIKE "Qcache_hits";
1687+
Variable_name Value
1688+
Qcache_hits 0
1689+
SELECT * FROM t1;
1690+
a
1691+
1
1692+
2
1693+
3
1694+
4
1695+
5
1696+
BEGIN;
1697+
SELECT * FROM t1;
1698+
a
1699+
1
1700+
2
1701+
3
1702+
4
1703+
5
1704+
COMMIT;
1705+
SHOW STATUS LIKE "Qcache_hits";
1706+
Variable_name Value
1707+
Qcache_hits 2
1708+
DROP TABLE t1;
1709+
SET GLOBAL query_cache_size= default;
16591710
End of 5.0 tests
16601711
CREATE TABLE t1 (a ENUM('rainbow'));
16611712
INSERT INTO t1 VALUES (),(),(),(),();

mysql-test/t/query_cache.test

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,33 @@ DROP TABLE t1;
12611261
SET GLOBAL concurrent_insert= @save_concurrent_insert;
12621262
SET GLOBAL query_cache_size= default;
12631263

1264+
#
1265+
# Bug#36326: nested transaction and select
1266+
#
1267+
1268+
--disable_warnings
1269+
DROP TABLE IF EXISTS t1;
1270+
--enable_warnings
1271+
1272+
FLUSH STATUS;
1273+
SET GLOBAL query_cache_size=1048576;
1274+
CREATE TABLE t1 (a INT);
1275+
INSERT INTO t1 VALUES (1),(2),(3),(4),(5);
1276+
SHOW STATUS LIKE 'Qcache_queries_in_cache';
1277+
SELECT * FROM t1;
1278+
BEGIN;
1279+
SELECT * FROM t1;
1280+
COMMIT;
1281+
SHOW STATUS LIKE 'Qcache_queries_in_cache';
1282+
SHOW STATUS LIKE "Qcache_hits";
1283+
SELECT * FROM t1;
1284+
BEGIN;
1285+
SELECT * FROM t1;
1286+
COMMIT;
1287+
SHOW STATUS LIKE "Qcache_hits";
1288+
DROP TABLE t1;
1289+
SET GLOBAL query_cache_size= default;
1290+
12641291
--echo End of 5.0 tests
12651292

12661293
#

sql/mysql_priv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,8 @@ struct Query_cache_query_flags
862862
unsigned int client_protocol_41:1;
863863
unsigned int result_in_binary_protocol:1;
864864
unsigned int more_results_exists:1;
865+
unsigned int in_trans:1;
866+
unsigned int autocommit:1;
865867
unsigned int pkt_nr;
866868
uint character_set_client_num;
867869
uint character_set_results_num;

sql/sql_cache.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,8 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used)
10011001
flags.result_in_binary_protocol= (unsigned int) thd->protocol->type();
10021002
flags.more_results_exists= test(thd->server_status &
10031003
SERVER_MORE_RESULTS_EXISTS);
1004+
flags.in_trans= test(thd->server_status & SERVER_STATUS_IN_TRANS);
1005+
flags.autocommit= test(thd->server_status & SERVER_STATUS_AUTOCOMMIT);
10041006
flags.pkt_nr= net->pkt_nr;
10051007
flags.character_set_client_num=
10061008
thd->variables.character_set_client->number;
@@ -1022,7 +1024,7 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used)
10221024
long %d, 4.1: %d, bin_proto: %d, more results %d, pkt_nr: %d, \
10231025
CS client: %u, CS result: %u, CS conn: %u, limit: %lu, TZ: 0x%lx, \
10241026
sql mode: 0x%lx, sort len: %lu, conncat len: %lu, div_precision: %lu, \
1025-
def_week_frmt: %lu",
1027+
def_week_frmt: %lu, in_trans: %d, autocommit: %d",
10261028
(int)flags.client_long_flag,
10271029
(int)flags.client_protocol_41,
10281030
(int)flags.result_in_binary_protocol,
@@ -1037,7 +1039,10 @@ def_week_frmt: %lu",
10371039
flags.max_sort_length,
10381040
flags.group_concat_max_len,
10391041
flags.div_precision_increment,
1040-
flags.default_week_format));
1042+
flags.default_week_format,
1043+
(int)flags.in_trans,
1044+
(int)flags.autocommit));
1045+
10411046
/*
10421047
Make InnoDB to release the adaptive hash index latch before
10431048
acquiring the query cache mutex.
@@ -1269,6 +1274,8 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
12691274
flags.result_in_binary_protocol= (unsigned int)thd->protocol->type();
12701275
flags.more_results_exists= test(thd->server_status &
12711276
SERVER_MORE_RESULTS_EXISTS);
1277+
flags.in_trans= test(thd->server_status & SERVER_STATUS_IN_TRANS);
1278+
flags.autocommit= test(thd->server_status & SERVER_STATUS_AUTOCOMMIT);
12721279
flags.pkt_nr= thd->net.pkt_nr;
12731280
flags.character_set_client_num= thd->variables.character_set_client->number;
12741281
flags.character_set_results_num=
@@ -1288,7 +1295,7 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
12881295
long %d, 4.1: %d, bin_proto: %d, more results %d, pkt_nr: %d, \
12891296
CS client: %u, CS result: %u, CS conn: %u, limit: %lu, TZ: 0x%lx, \
12901297
sql mode: 0x%lx, sort len: %lu, conncat len: %lu, div_precision: %lu, \
1291-
def_week_frmt: %lu",
1298+
def_week_frmt: %lu, in_trans: %d, autocommit: %d",
12921299
(int)flags.client_long_flag,
12931300
(int)flags.client_protocol_41,
12941301
(int)flags.result_in_binary_protocol,
@@ -1303,7 +1310,9 @@ def_week_frmt: %lu",
13031310
flags.max_sort_length,
13041311
flags.group_concat_max_len,
13051312
flags.div_precision_increment,
1306-
flags.default_week_format));
1313+
flags.default_week_format,
1314+
(int)flags.in_trans,
1315+
(int)flags.autocommit));
13071316
memcpy((uchar *)(sql + (tot_length - QUERY_CACHE_FLAGS_SIZE)),
13081317
(uchar*) &flags, QUERY_CACHE_FLAGS_SIZE);
13091318
query_block = (Query_cache_block *) hash_search(&queries, (uchar*) sql,

tests/mysql_client_test.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17712,6 +17712,63 @@ static void test_bug40365(void)
1771217712

1771317713
DBUG_VOID_RETURN;
1771417714
}
17715+
17716+
17717+
/**
17718+
Bug#36326: nested transaction and select
17719+
*/
17720+
17721+
#ifdef HAVE_QUERY_CACHE
17722+
17723+
static void test_bug36326()
17724+
{
17725+
int rc;
17726+
17727+
DBUG_ENTER("test_bug36326");
17728+
myheader("test_bug36326");
17729+
17730+
rc= mysql_autocommit(mysql, TRUE);
17731+
myquery(rc);
17732+
rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
17733+
myquery(rc);
17734+
rc= mysql_query(mysql, "CREATE TABLE t1 (a INTEGER)");
17735+
myquery(rc);
17736+
rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1)");
17737+
myquery(rc);
17738+
rc= mysql_query(mysql, "SET GLOBAL query_cache_type = 1");
17739+
myquery(rc);
17740+
rc= mysql_query(mysql, "SET GLOBAL query_cache_size = 1048576");
17741+
myquery(rc);
17742+
DIE_UNLESS(!(mysql->server_status & SERVER_STATUS_IN_TRANS));
17743+
DIE_UNLESS(mysql->server_status & SERVER_STATUS_AUTOCOMMIT);
17744+
rc= mysql_query(mysql, "BEGIN");
17745+
myquery(rc);
17746+
DIE_UNLESS(mysql->server_status & SERVER_STATUS_IN_TRANS);
17747+
rc= mysql_query(mysql, "SELECT * FROM t1");
17748+
myquery(rc);
17749+
rc= my_process_result(mysql);
17750+
DIE_UNLESS(rc == 1);
17751+
rc= mysql_rollback(mysql);
17752+
myquery(rc);
17753+
rc= mysql_query(mysql, "ROLLBACK");
17754+
myquery(rc);
17755+
DIE_UNLESS(!(mysql->server_status & SERVER_STATUS_IN_TRANS));
17756+
rc= mysql_query(mysql, "SELECT * FROM t1");
17757+
myquery(rc);
17758+
DIE_UNLESS(!(mysql->server_status & SERVER_STATUS_IN_TRANS));
17759+
rc= my_process_result(mysql);
17760+
DIE_UNLESS(rc == 1);
17761+
rc= mysql_query(mysql, "DROP TABLE t1");
17762+
myquery(rc);
17763+
rc= mysql_query(mysql, "SET GLOBAL query_cache_size = 0");
17764+
myquery(rc);
17765+
17766+
DBUG_VOID_RETURN;
17767+
}
17768+
17769+
#endif
17770+
17771+
1771517772
/*
1771617773
Read and parse arguments and MySQL options from my.cnf
1771717774
*/
@@ -18024,6 +18081,9 @@ static struct my_tests_st my_tests[]= {
1802418081
{ "test_bug40365", test_bug40365 },
1802518082
#ifdef HAVE_SPATIAL
1802618083
{ "test_bug37956", test_bug37956 },
18084+
#endif
18085+
#ifdef HAVE_QUERY_CACHE
18086+
{ "test_bug36326", test_bug36326 },
1802718087
#endif
1802818088
{ 0, 0 }
1802918089
};

0 commit comments

Comments
 (0)