[MDEV-7216] COM_Select goes up together with Qcache_hits Created: 2014-11-26  Updated: 2016-02-09  Resolved: 2016-02-07

Status: Closed
Project: MariaDB Server
Component/s: Documentation, Query Cache
Affects Version/s: 5.5.39, 10.0.14
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Hartmut Holzgraefe Assignee: Oleksandr Byelkin
Resolution: Fixed Votes: 1
Labels: None

Issue Links:
Relates
relates to MDEV-4981 Account for queries handled by query-... Closed
Sprint: 5.5.48-0

 Description   

According to the KnowledgeBase:

"Note that queries returned from the query cache do not increment the Com_select status variable, so to find the total number of valid queries run on the server, add Com_select to Qcache_hits."
( https://mariadb.com/kb/en/mariadb/documentation/optimization-and-tuning/buffers-caches-and-threads/query-cache/ )

This is true for MySQL, but not for MariaDB where Com_select actually does seem to get incremented even on query cache hits. Not sure whether this was an intended change (IMHO the MariaDB behaviour is the more correct one), but it is in contradiction to the documented state for sure.

MariaDB [test]> CREATE TABLE t1 (id INT PRIMARY KEY);
Query OK, 0 rows affected (0.06 sec)
 
MariaDB [test]> INSERT INTO t1 VALUES (1);
Query OK, 1 row affected (0.02 sec)
 
MariaDB [test]> SHOW GLOBAL STATUS WHERE Variable_name IN ('Com_select', 'Qcache_hits');
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Com_select    | 0     |
| Qcache_hits   | 0     |
+---------------+-------+
2 rows in set (0.00 sec)
 
MariaDB [test]> SELECT * FROM t1;
+----+
| id |
+----+
|  1 |
+----+
1 row in set (0.00 sec)
 
MariaDB [test]> SHOW GLOBAL STATUS WHERE Variable_name IN ('Com_select', 'Qcache_hits');
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Com_select    | 1     |
| Qcache_hits   | 0     |
+---------------+-------+
2 rows in set (0.00 sec)
 
MariaDB [test]> SELECT * FROM t1;
+----+
| id |
+----+
|  1 |
+----+
1 row in set (0.00 sec)
 
MariaDB [test]> SHOW GLOBAL STATUS WHERE Variable_name IN ('Com_select', 'Qcache_hits');
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Com_select    | 2     |
| Qcache_hits   | 1     |
+---------------+-------+
2 rows in set (0.00 sec)
 
MariaDB [test]> SELECT * FROM t1;
+----+
| id |
+----+
|  1 |
+----+
1 row in set (0.00 sec)
 
MariaDB [test]> SHOW GLOBAL STATUS WHERE Variable_name IN ('Com_select', 'Qcache_hits');
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Com_select    | 3     |
| Qcache_hits   | 2     |
+---------------+-------+
2 rows in set (0.00 sec)



 Comments   
Comment by Elena Stepanova [ 2014-11-26 ]

It appears to be an intentional change, made in scope of MDEV-4981. Assigning to sanja to double-check that it was really thought through, and if so, get the documentation be updated accordingly.

Comment by Lucas Rolff [ 2015-02-07 ]

Would love to get this double-checked as well, a lot of tools to measure query stats depend heavily on the Com_select and Qcache_hits values, this also means people using tools such as Munin, or Graphite will need to make very MariaDB specific code, since else you'll get graphs like this:

It would be nice if we can use most MySQL plugins for monitoring, since MariaDB is advertised as "An enhanced, drop-in replacement for MySQL". Then we should also be able to measure data/statistics the same way, but with additional features. I believe you can achieve the same data you want in MDEV-4981 by combining some numbers from the Com_* and Qcache_* variables.

Comment by Lucas Rolff [ 2015-02-21 ]

Oleksandr Byelkin will you look into this?

Comment by Oleksandr Byelkin [ 2015-02-22 ]

Of course I will (when come its time)

Comment by Oleksandr Byelkin [ 2015-02-22 ]

The case is looks simple, but there is non-simple question why it was changed which needs time to figure out.

Comment by Lucas Rolff [ 2015-08-18 ]

Any news about this?

Comment by Oleksandr Byelkin [ 2016-02-07 ]

OK, it is bug in the documentation. the work was done according to https://mariadb.atlassian.net/browse/MDEV-4981.
Docs will be fixed soon.

Comment by Lucas Rolff [ 2016-02-07 ]

@sanja / Oleksandr - so there won't be done anything regarding this issue? It still doesn't count correctly.
A Com_select should never get incremented if you also have a Qcache_hit

Comment by Oleksandr Byelkin [ 2016-02-07 ]

Thank you a lot! I've fixed the documentation.

Comment by Lucas Rolff [ 2016-02-07 ]

It's not documentation, but it actually counts wrong in the internals. Try launch mytop, or mysqltuner, or anything that calculates your query hit ratio, you'll never get above 50% because MariaDB increments Com_select on a query cache hit.
Looking at MySQL it doesn't do this, which makes completely sense, it breaks every graph made for MySQL (and MariaDB since it's a drop-in replacement).

Comment by Lucas Rolff [ 2016-02-07 ]

Oleksandr,

https://screenshots.lucasrolff.com/2016_02_07_k4k0gl3pojf0h70.png

As you can see - according to the graph I'm doing 994.67 queries per second - what I actually do on the server is 557 queries per second.

Here's a screenshot from when we switched to MariaDB - our queries didn't increase, but since MariaDB increments Com_select when it shouldn't it results in graphs that are wrong:
https://screenshots.lucasrolff.com/2016_02_07_2vxrdrebh9zi198.png

Comment by Lucas Rolff [ 2016-02-07 ]

Please reopen this.

Comment by Oleksandr Byelkin [ 2016-02-08 ]

Just to make it clear. in 5.5 behaviour changed and you should not add QC hits. And we are really sorry for the mess in the documentation but we have just fixed it.

So if you upgraded to 5.5 and up you should calculate statistics in other way.

Comment by Lucas Rolff [ 2016-02-08 ]

We use munin official mysql plugins - these calculate correctly in MySQL (both version 5.1, 5.5, 5.6) but in MariaDB counts incorrectly.

MySQL 5.5+ does not increase Com_select when Qcache_hits gets incremented.

Comment by Oleksandr Byelkin [ 2016-02-09 ]

You probably have to complain to the plugin producer.

Sorry, but mariadb has different set of statistics in general and in this particular place also.

Generated at Thu Feb 08 07:17:53 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.