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

For stored functions INDEX_STATISTICS.QUERIES only counts the top-most query

    XMLWordPrintable

Details

    Description

      Unlike for procedure calls, where INDEX_STATISTICS.QUERIES counts relevant queries within the procedure, for functions it only counts the upper query, the one which executes the functions, regardless how many times the functions are executed and how many relevant queries they run inside.
      Maybe it is intentional, but it's not clear from MDEV-33152 where the counter was added. If it's intentional, please convert it into a documentation request.

      SET @userstat.save= @@userstat;
      set global userstat= 1;
       
      create table t (a int, key(a)) engine=MyISAM;
      insert into t values (1),(2),(3),(4),(1);
      --delimiter $
      create function f() returns int
      begin
        declare x int default 0;
        declare y int default 0;
        select count(*) into x from t where a = 1;
        select count(*) into y from t where a = 2;
        return x + y;
      end $
      --delimiter ;
      flush index_statistics;
      select f() + f();
      show index_statistics;
       
      # Cleanup
      set global userstat= @userstat.save;
      drop table t;
      drop function f;
      

      bb-11.5-MDEV-33152-index-statistics 802e89b176efd8ef995cdd456a04ac6452f0e284

      show index_statistics;
      Table_schema	Table_name	Index_name	Rows_read	Queries
      test	t	a	6	1
      

      Attachments

        Issue Links

          Activity

            People

              monty Michael Widenius
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              2 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.