Skip to content

Commit afef9a5

Browse files
committed
Bug#18383169: QUERIES WITH RANDOM_BYTES() ENTER QUERY CACHE
The problem was that queries using RANDOM_BYTES, AES_ENCRYPT or AES_DECRYPT could be cached in the query cache. RANDOM_BYTES is random and AES_* are dependent on block_encryption_mode system variable. This patch fixes the problem by tagging queries using these functions as unsafe to cache.
1 parent aeb72f4 commit afef9a5

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

mysql-test/r/query_cache.result

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,3 +1811,23 @@ Level Code Message
18111811

18121812
DROP TABLE t1;
18131813
SET SESSION query_cache_type=@qc_type;
1814+
#
1815+
# Bug#18383169: QUERIES WITH RANDOM_BYTES() ENTER QUERY CACHE
1816+
#
1817+
CREATE TABLE t1(a INT);
1818+
INSERT INTO t1 VALUES (1);
1819+
FLUSH STATUS;
1820+
# Test that RANDOM_BYTES queries are not cached
1821+
SELECT * FROM t1 WHERE RANDOM_BYTES(16);
1822+
a
1823+
SHOW STATUS LIKE 'Qcache_not_cached';
1824+
Variable_name Value
1825+
Qcache_not_cached 1
1826+
# same with AES_ENCRYPT
1827+
SELECT * FROM t1 WHERE AES_ENCRYPT('a','a');
1828+
a
1829+
SHOW STATUS LIKE 'Qcache_not_cached';
1830+
Variable_name Value
1831+
Qcache_not_cached 2
1832+
DROP TABLE t1;
1833+
FLUSH STATUS;

mysql-test/t/query_cache.test

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,3 +1419,22 @@ SHOW WARNINGS;
14191419
DROP TABLE t1;
14201420

14211421
SET SESSION query_cache_type=@qc_type;
1422+
1423+
--echo #
1424+
--echo # Bug#18383169: QUERIES WITH RANDOM_BYTES() ENTER QUERY CACHE
1425+
--echo #
1426+
1427+
CREATE TABLE t1(a INT);
1428+
INSERT INTO t1 VALUES (1);
1429+
FLUSH STATUS;
1430+
1431+
--echo # Test that RANDOM_BYTES queries are not cached
1432+
SELECT * FROM t1 WHERE RANDOM_BYTES(16);
1433+
SHOW STATUS LIKE 'Qcache_not_cached';
1434+
1435+
--echo # same with AES_ENCRYPT
1436+
SELECT * FROM t1 WHERE AES_ENCRYPT('a','a');
1437+
SHOW STATUS LIKE 'Qcache_not_cached';
1438+
1439+
DROP TABLE t1;
1440+
FLUSH STATUS;

sql/item_create.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ class Create_func_aes_base : public Create_native_func
250250
/* Unsafe for SBR since result depends on a session variable */
251251
thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
252252

253+
/* Not safe to cache either */
254+
thd->lex->set_uncacheable(UNCACHEABLE_SIDEEFFECT);
255+
253256
if (item_list != NULL)
254257
arg_count= item_list->elements;
255258

@@ -337,6 +340,8 @@ class Create_func_random_bytes : public Create_func_arg1
337340
{
338341
/* it is unsafe for SBR since it uses crypto random from the ssl library */
339342
thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
343+
/* Not safe to cache either */
344+
thd->lex->set_uncacheable(UNCACHEABLE_RAND);
340345
return new (thd->mem_root) Item_func_random_bytes(arg1);
341346
}
342347
static Create_func_random_bytes s_singleton;

0 commit comments

Comments
 (0)