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

INDEX_STATISTICS is not updated if query returns empty resultset

    XMLWordPrintable

Details

    Description

      If a query uses an index, and as a result all rows are filtered out, the query is not included in INDEX_STATISTICS. It seems strange – if the goal is to measure the efficiency of the index, then queries where the index allows to exclude all rows should surely be taken into account.

      SET @userstat.save= @@userstat;
       
      CREATE TABLE t (a INT, KEY(a)) ENGINE=MyISAM;
      INSERT INTO t VALUES (1),(2),(3),(4),(5);
      SET GLOBAL userstat= 1;
      FLUSH INDEX_STATISTICS;
      EXPLAIN SELECT a FROM t WHERE a = 6;
      SELECT a FROM t WHERE a = 6;
      SHOW INDEX_STATISTICS;
       
      # Cleanup
      DROP TABLE t;
      SET GLOBAL userstat= @userstat.save;
      

      10.4 662bb176b412993a085fe329af559ddc3dc83ec3

      EXPLAIN SELECT a FROM t WHERE a = 6;
      id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
      1	SIMPLE	t	ref	a	a	5	const	1	Using index
      SELECT a FROM t WHERE a = 6;
      a
      SHOW INDEX_STATISTICS;
      Table_schema	Table_name	Index_name	Rows_read
      DROP TABLE t;
      

      Consequently, even if the index already exists in INDEX_STATISTICS due to previous resultive queries, THE QUERIES counter introduced in MDEV-33152 is not incremented on such an occasion.

      Attachments

        Activity

          People

            monty Michael Widenius
            elenst Elena Stepanova
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

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