Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-4981

Account for queries handled by query-cache in USER_STATISTICS (and in HOST_STATISTICS)

Details

    • Task
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • None
    • None
    • None

    Description

      [Affected version: at least 5.5.28a-MariaDB-log]

      When a user performs queries handled by query-cache theses are not taken into account by USER_STATISTICS (and probably neither by HOST_STATISTICS).

      They should properly increment COMMAND_SELECT, SENT_ROWS and when appropriate EMPTY_QUERIES.

      Without updating those a user that performs the same SELECT over and over, each time hitting query cache will appear as performing no queries, just burning CPU time and exchanging bytes.

      Attachments

        Issue Links

          Activity

            After some digging into sources I found that EMPTY_QUERIES counts really empty queries (when parser faces EOF and put SQLCOM_EMPTY_QUERY as a command, which is irrelevant to SQLCOM_SELECT completely)

            sanja Oleksandr Byelkin added a comment - After some digging into sources I found that EMPTY_QUERIES counts really empty queries (when parser faces EOF and put SQLCOM_EMPTY_QUERY as a command, which is irrelevant to SQLCOM_SELECT completely)

            The description at https://mariadb.com/kb/en/user-statistics/ seems to not really agree on the meaning of this field:

            CLIENT_STATISTICS
            EMPTY_QUERIES int(21) The number of times this client's connections sent queries that returned no results to the server.

            USER_STATISTICS
            EMPTY_QUERIES int(21) The number of times this user's connections sent empty queries to the server.

            bprest Bruno Prémont added a comment - The description at https://mariadb.com/kb/en/user-statistics/ seems to not really agree on the meaning of this field: CLIENT_STATISTICS EMPTY_QUERIES int(21) The number of times this client's connections sent queries that returned no results to the server. USER_STATISTICS EMPTY_QUERIES int(21) The number of times this user's connections sent empty queries to the server.

            Above is definitely bug in the description (of CLIENT_STATISTICS), I filed it here https://mariadb.atlassian.net/browse/MDEV-5083

            USER_STATISTICS description is correct but maybe is not clear.

            sanja Oleksandr Byelkin added a comment - Above is definitely bug in the description (of CLIENT_STATISTICS), I filed it here https://mariadb.atlassian.net/browse/MDEV-5083 USER_STATISTICS description is correct but maybe is not clear.

            Test suite for the bug

            – source include/have_query_cache.inc

            #

            1. Tests with query cache
              #
              SET GLOBAL userstat=1;
              set GLOBAL query_cache_size=1355776;
              FLUSH USER_STATISTICS;
              FLUSH CLIENT_STATISTICS;
              reset query cache;
              flush status;

            create table t1 (a int);
            insert into t1 values (1);
            select * from t1;
            select SELECT_COMMANDS,ROWS_SENT from INFORMATION_SCHEMA.CLIENT_STATISTICS
            where CLIENT="localhost";
            select SELECT_COMMANDS,ROWS_SENT from INFORMATION_SCHEMA.USER_STATISTICS
            where USER="root";
            show status like "Qcache_hits";
            select * from t1;
            select * from t1;
            select SELECT_COMMANDS,ROWS_SENT from INFORMATION_SCHEMA.CLIENT_STATISTICS
            where CLIENT="localhost";
            select SELECT_COMMANDS,ROWS_SENT from INFORMATION_SCHEMA.USER_STATISTICS
            where USER="root";
            show status like "Qcache_hits";

            drop table t1;
            SET GLOBAL query_cache_size=default;
            SET GLOBAL userstat=default;

            sanja Oleksandr Byelkin added a comment - Test suite for the bug – source include/have_query_cache.inc # Tests with query cache # SET GLOBAL userstat=1; set GLOBAL query_cache_size=1355776; FLUSH USER_STATISTICS; FLUSH CLIENT_STATISTICS; reset query cache; flush status; create table t1 (a int); insert into t1 values (1); select * from t1; select SELECT_COMMANDS,ROWS_SENT from INFORMATION_SCHEMA.CLIENT_STATISTICS where CLIENT="localhost"; select SELECT_COMMANDS,ROWS_SENT from INFORMATION_SCHEMA.USER_STATISTICS where USER="root"; show status like "Qcache_hits"; select * from t1; select * from t1; select SELECT_COMMANDS,ROWS_SENT from INFORMATION_SCHEMA.CLIENT_STATISTICS where CLIENT="localhost"; select SELECT_COMMANDS,ROWS_SENT from INFORMATION_SCHEMA.USER_STATISTICS where USER="root"; show status like "Qcache_hits"; drop table t1; SET GLOBAL query_cache_size=default; SET GLOBAL userstat=default;
            sanja Oleksandr Byelkin added a comment - - edited

            When SELECT_COMMANDS is a matter for discussing (which we will), but ROWS_SENT is definitely a bug (information is present in QC and returned in EOF packet so the problem is somewhere in information schema or statistics collection).

            sanja Oleksandr Byelkin added a comment - - edited When SELECT_COMMANDS is a matter for discussing (which we will), but ROWS_SENT is definitely a bug (information is present in QC and returned in EOF packet so the problem is somewhere in information schema or statistics collection).

            QC should be transparent, so SELECT_COMMANDS should count QC answers.

            sanja Oleksandr Byelkin added a comment - QC should be transparent, so SELECT_COMMANDS should count QC answers.

            Normal execution is fixed. now have to check SP and PS.

            sanja Oleksandr Byelkin added a comment - Normal execution is fixed. now have to check SP and PS.

            EMPTY_QUERIES (both) counts queries with empty results (So I was wrong initially).

            sanja Oleksandr Byelkin added a comment - EMPTY_QUERIES (both) counts queries with empty results (So I was wrong initially).

            Committed for review.

            sanja Oleksandr Byelkin added a comment - Committed for review.

            pushed to 5.5

            sanja Oleksandr Byelkin added a comment - pushed to 5.5

            People

              sanja Oleksandr Byelkin
              bprest Bruno Prémont
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.