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

Statistics: If stat tables get corrupted, queries use wrong statistical data

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 10.0.1
    • Component/s: None
    • Labels:
      None

      Description

      From IRC:

      <igor> elenst: could you come up with the test case where e.g. mysql.stat_table is corrupted somehow, then we 1) flush table t1; 2) set use_stat_tables='preferably' 3) run explain select * from t1;
      <igor> elenst: in this case the result of explain is expected the same as we do not use ant stat tables (+ some warning).
      <igor> elenst: I'm afraid now we just have rows == 0 in the explain output with this scenario, which not correct of course.

      The provided test case confirms the suspicion: EXPLAIN shows 0 rows while the real number is 2.

      Test case

      # Run as perl ./mtr <testname>
       
      CREATE TABLE t1 (i INT) ENGINE=MyISAM;
      INSERT INTO t1 VALUES (1),(2);
      --move_file $MYSQLTEST_VARDIR/mysqld.1/data/mysql/table_stat.MYD $MYSQLTEST_VARDIR/mysqld.1/data/mysql/table_stat.MYD.save
       
      FLUSH TABLES;
      SET use_stat_tables=PREFERABLY;
       
      EXPLAIN SELECT * FROM t1;
       
      # Cleanup
      --move_file $MYSQLTEST_VARDIR/mysqld.1/data/mysql/table_stat.MYD.save $MYSQLTEST_VARDIR/mysqld.1/data/mysql/table_stat.MYD
       
      SET use_stat_tables=DEFAULT;
      DROP TABLE t1;

      Actual result:

      CREATE TABLE t1 (i INT) ENGINE=MyISAM;
      INSERT INTO t1 VALUES (1),(2);
      FLUSH TABLES;
      SET use_stat_tables=PREFERABLY;
      EXPLAIN SELECT * FROM t1;
      id     select_type     table   type    possible_keys   key     key_len ref     rows    Extra
      1      SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    0
      Warnings:
      Error  29      File './mysql/table_stat.MYD' not found (Errcode: 2)
      Error  1017    Can't find file: 'table_stat' (errno: 2)
      SET use_stat_tables=DEFAULT;
      DROP TABLE t1;

      bzr version-info

      revision-id: elenst@ubuntu11.home-20120903180152-r1n87m6pcvzffh63
      date: 2012-09-03 22:01:52 +0400
      build-date: 2012-09-09 01:58:25 +0300
      revno: 3367

      Workaround: if EXPLAIN produces warnings about corrupted stat tables, set use_stat_tables to NEVER.

        Attachments

          Activity

            People

            • Assignee:
              igor Igor Babaev
              Reporter:
              elenst Elena Stepanova
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: