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

Selectivity for BIT columns in filtered column for EXPLAIN is incorrect

Details

    Description

      SET optimizer_use_condition_selectivity=4;
      SET histogram_size=255;
      SET use_stat_tables='preferably';
      CREATE TABLE t1 (a BIT(32), b INT);
      INSERT INTO t1 VALUES (80, 80), (81, 81), (82, 82);
      ANALYZE TABLE t1 PERSISTENT FOR ALL;
      

      MariaDB [test]> EXPLAIN EXTENDED SELECT * from t1 where t1.a >= 81;
      +------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
      | id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
      +------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
      |    1 | SIMPLE      | t1    | ALL  | NULL          | NULL | NULL    | NULL |    3 |    99.61 | Using where |
      +------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
      1 row in set, 1 warning (0.00 sec)
      

      So filtered here shows 99.61 % which is incorrect, selectivity should be ~66%

      Lets try with INT instead of BIT(32)

      MariaDB [test]> EXPLAIN EXTENDED SELECT * from t1 where t1.b >= 81;
      +------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
      | id   | select_type | table | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
      +------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
      |    1 | SIMPLE      | t1    | ALL  | NULL          | NULL | NULL    | NULL |    3 |    66.41 | Using where |
      +------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
      1 row in set, 1 warning (0.00 sec)
      

      Filtered here is ~66%, so this looks correct.

      Attachments

        Issue Links

          Activity

            varun Varun Gupta (Inactive) created issue -
            varun Varun Gupta (Inactive) made changes -
            Field Original Value New Value
            Description {code:sql}
            SET optimizer_use_condition_selectivity=4;
            SET histogram_size=255;
            SET use_stat_tables='preferably';
            CREATE TABLE t1 (a BIT(32), b INT);
            INSERT INTO t1 VALUES (80, 80), (81, 81), (82, 82);
            ANALYZE TABLE t1 PERSISTENT FOR ALL;
            {code}


            {noformat}
            MariaDB [test]> EXPLAIN EXTENDED SELECT * from t1 where t1.a >= 81;
            +------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
            | id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
            +------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
            | 1 | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | 3 | 99.61 | Using where |
            +------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
            1 row in set, 1 warning (0.00 sec)
            {noformat}

            So filtered here shows 99.61 % which is incorrect, selectivity should be ~66%

            Lets try with INT instead of BIT(32)

            {noformat}
            MariaDB [test]> EXPLAIN EXTENDED SELECT * from t1 where t1.b >= 81;
            +------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
            | id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
            +------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
            | 1 | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | 3 | 66.41 | Using where |
            +------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
            1 row in set, 1 warning (0.00 sec)
            {noformat}
            Filtered here is ~66%, so this looks correct.

            varun Varun Gupta (Inactive) made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            bar Alexander Barkov made changes -
            varun Varun Gupta (Inactive) made changes -
            Assignee Varun Gupta [ varun ] Sergei Petrunia [ psergey ]
            Status In Progress [ 3 ] In Review [ 10002 ]
            varun Varun Gupta (Inactive) made changes -
            Assignee Sergei Petrunia [ psergey ] Igor Babaev [ igor ]
            julien.fritsch Julien Fritsch made changes -
            Fix Version/s 10.1 [ 16100 ]
            varun Varun Gupta (Inactive) made changes -
            Assignee Igor Babaev [ igor ] Michael Widenius [ monty ]
            varun Varun Gupta (Inactive) made changes -
            Assignee Michael Widenius [ monty ] Varun Gupta [ varun ]
            varun Varun Gupta (Inactive) made changes -
            Status In Review [ 10002 ] Stalled [ 10000 ]
            varun Varun Gupta (Inactive) made changes -
            Fix Version/s 10.2.37 [ 25112 ]
            Fix Version/s 10.3.28 [ 25111 ]
            Fix Version/s 10.4.18 [ 25110 ]
            Fix Version/s 10.5.9 [ 25109 ]
            Fix Version/s 10.2 [ 14601 ]
            Fix Version/s 10.3 [ 22126 ]
            Fix Version/s 10.4 [ 22408 ]
            Fix Version/s 10.5 [ 23123 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            dbart Daniel Bartholomew made changes -
            Fix Version/s 10.2.38 [ 25207 ]
            Fix Version/s 10.2.37 [ 25112 ]
            psergei Sergei Petrunia made changes -
            Fix Version/s 10.5.10 [ 25204 ]
            Fix Version/s 10.4.19 [ 25205 ]
            Fix Version/s 10.3.29 [ 25206 ]
            Fix Version/s 10.5.9 [ 25109 ]
            Fix Version/s 10.4.18 [ 25110 ]
            Fix Version/s 10.2.38 [ 25207 ]
            psergei Sergei Petrunia made changes -
            Fix Version/s 10.2.38 [ 25207 ]
            Fix Version/s 10.3.29 [ 25206 ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 108778 ] MariaDB v4 [ 157783 ]

            People

              varun Varun Gupta (Inactive)
              varun Varun Gupta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 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.