[MDEV-32338] session_track_transaction_info=CHARACTERISTICS disables the query cache Created: 2023-10-02  Updated: 2023-11-28

Status: Confirmed
Project: MariaDB Server
Component/s: Query Cache
Affects Version/s: 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10, 10.11, 11.0
Fix Version/s: 10.4, 10.5, 10.6, 10.11, 11.0

Type: Bug Priority: Major
Reporter: markus makela Assignee: Oleksandr Byelkin
Resolution: Unresolved Votes: 0
Labels: None
Environment:

Docker images from dockerhub



 Description   

With this configuration, the query cache is disabled.

docker run --name=maria --network=host -ti --rm -e MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=1 mariadb:10.11 --query-cache-size=$((1024*1024*1024)) --query-cache-type=1 --session-track-transaction-info=CHARACTERISTICS
 
... in other window
 
[markusjm@monolith docker-compose]$ mariadb --host=127.0.0.1 --port=3306 --user=root -e "CREATE DATABASE IF NOT EXISTS test; CREATE TABLE IF NOT EXISTS test.t1 AS SELECT seq FROM test.seq_0_to_50; SELECT COUNT(*) FROM test.t1; SHOW GLOBAL STATUS LIKE 'qcache%'"
+----------+
| COUNT(*) |
+----------+
|       51 |
+----------+
+-------------------------+------------+
| Variable_name           | Value      |
+-------------------------+------------+
| Qcache_free_blocks      | 1          |
| Qcache_free_memory      | 1073723392 |
| Qcache_hits             | 0          |
| Qcache_inserts          | 0          |
| Qcache_lowmem_prunes    | 0          |
| Qcache_not_cached       | 0          |
| Qcache_queries_in_cache | 0          |
| Qcache_total_blocks     | 1          |
+-------------------------+------------+

Removing session_track_transaction_info=CHARACTERISTICS makes the query cache work again:

docker run --name=maria --network=host -ti --rm -e MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=1 mariadb:10.11 --query-cache-size=$((1024*1024*1024)) --query-cache-type=1
 
... in another window
 
[markusjm@monolith docker-compose]$ mariadb --host=127.0.0.1 --port=3306 --user=root -e "CREATE DATABASE IF NOT EXISTS test; CREATE TABLE IF NOT EXISTS test.t1 AS SELECT seq FROM test.seq_0_to_50; SELECT COUNT(*) FROM test.t1; SHOW GLOBAL STATUS LIKE 'qcache%'"
+----------+
| COUNT(*) |
+----------+
|       51 |
+----------+
+-------------------------+------------+
| Variable_name           | Value      |
+-------------------------+------------+
| Qcache_free_blocks      | 1          |
| Qcache_free_memory      | 1073721856 |
| Qcache_hits             | 0          |
| Qcache_inserts          | 1          |
| Qcache_lowmem_prunes    | 0          |
| Qcache_not_cached       | 0          |
| Qcache_queries_in_cache | 1          |
| Qcache_total_blocks     | 4          |
+-------------------------+------------+
[markusjm@monolith docker-compose]$ mariadb --host=127.0.0.1 --port=3306 --user=root -e "CREATE DATABASE IF NOT EXISTS test; CREATE TABLE IF NOT EXISTS test.t1 AS SELECT seq FROM test.seq_0_to_50; SELECT COUNT(*) FROM test.t1; SHOW GLOBAL STATUS LIKE 'qcache%'"
+----------+
| COUNT(*) |
+----------+
|       51 |
+----------+
+-------------------------+------------+
| Variable_name           | Value      |
+-------------------------+------------+
| Qcache_free_blocks      | 1          |
| Qcache_free_memory      | 1073721856 |
| Qcache_hits             | 1          |
| Qcache_inserts          | 1          |
| Qcache_lowmem_prunes    | 0          |
| Qcache_not_cached       | 0          |
| Qcache_queries_in_cache | 1          |
| Qcache_total_blocks     | 4          |
+-------------------------+------------+



 Comments   
Comment by Sergei Golubchik [ 2023-10-12 ]

Appears to be intentional:

sql/sql_cache.cc

1391
  /*
1392
    Do not store queries while tracking transaction state.
1393
    The tracker already flags queries that actually have
1394
    transaction tracker items, but this will make behavior
1395
    more straight forward.
1396
  */
1397
#ifndef EMBEDDED_LIBRARY
1398
  if (thd->variables.session_track_transaction_info != TX_TRACK_NONE)
1399
  {
1400
    DBUG_PRINT("qcache", ("Do not work with transaction tracking"));
1401
    DBUG_VOID_RETURN;
1402
  }
1403
#endif //EMBEDDED_LIBRARY

Comment by Oleksandr Byelkin [ 2023-10-12 ]

The problem is that reply of the same SQL can be different depending on how changed other tables in the transaction. The query cache store answer to the user and so there are two ways to deal with it:

1. just do not use it with query cache (now)
2. store current state of the transaction as a part of key for query cache (how we do it with text of the query and some variables which have influence on the query response)

Comment by markus makela [ 2023-10-12 ]

Perhaps just documenting this or warning about it would be enough.

Generated at Thu Feb 08 10:30:35 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.