How MySQL ‘queries’ and ‘questions’ are measured

MySQL has status variables “questions” and “queries” which are rather close but also a bit different, making it confusing for many people. The manual describing it might not be very easy to understand:

In a nutshell if you’re not using prepared statements the big difference between those is what “Questions” would count stored procedure calls as a single statement where “Queries” will count all statements called inside of stored procedures as well.

There seems to be also more subtle difference between them:

Running on MySQL 5.6.17 having created a new connection I see…

Which tells me what “queries” is a global status variable while “questions” is a session and can be used to see how many statements were issued to the server through the current connection.

There is also a global questions variable that shows the number for a server since the start:

When it comes to global values neither “queries” nor “questions” are reset when FLUSH STATUS is called.

What the manual does not describe in detail though is: When exactly those counters are incremented? This might look irrelevant but really it is not, especially if you’re capturing those values with high resolution and using them to diagnose non trivial MySQL performance incidents.

If you would count queries when they start – when a spike in the amount of queries in the given second could be due to the spike in the traffic, however, and if you measure queries at the completion – spikes could also mean that some critical resource became available which allowed for many queries to complete. Think for example of table-level locks or row-level locks with Innodb as very common cause.

So what is the case with MySQL? MySQL increments this counter Before executing the query so you may well see a very uniform rate of questions when actually a lot of queries were started but were not completing quickly due to waiting on some resource.

To check for unusual numbers of queries running concurrently and struggling to complete in time looking at threads_running status variable is a great idea.

Share this post

Comments (6)

  • Fadi (itoctopus)

    Hi Peter,

    A not-that-interesting question. Is there a way to reset the global counters for the questions and the queries? Will restarting MySQL reset those counters?

    June 3, 2014 at 9:52 am
  • Peter Zaitsev


    Nope FLUSH STATUS does not resent them. This command BTW is quite confusing which resets local (connection) counters flushing them to global counters but when it also zeroes out some of the global counters but not all of them.

    As such it is much better to compute deltas in the application if you’re using it for monitoring.

    June 3, 2014 at 8:59 pm
  • Johan De Meersman

    Another interesting detail would be wether or not those include the queries/questions that have been handled by the query cache, or wether it’s only those that are actually parsed and executed.

    Looking for that very information now, because InnoTop gets it’s qps figure from the questions variable 🙂

    January 21, 2016 at 2:48 am
  • Ahmad Ali

    I am using ipage hosting when I run some nested queries it shows that you have exhasted the limit. When I have checked the limit it is 300,000 questions set per hour. Please help me how it exhausts in just few queries.

    June 8, 2016 at 12:59 am
  • Alexey Zilber

    “capturing those values with high resolution” link is broken.

    December 21, 2016 at 9:16 pm
  • Peter Zaitsev

    Alexey. Thank you for the comment. We will check why that link is not up. In general that service (Percona Cloud Tools) was decommissioned and we have created Percona Monitoring and Management instead:

    December 21, 2016 at 9:34 pm

Comments are closed.

Use Percona's Technical Forum to ask any follow-up questions on this blog topic.