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

Virtual column rewrite may disable some query plans

    XMLWordPrintable

Details

    Description

      create table t20 (
        col1 date , 
        vcol date as (col1),
        index i1(col1),
        index i2(vcol)
      );
       
      insert into t20 (col1) select 
        date_add(now(), interval seq day)
      from seq_1_to_10000;
      

      In 10.11, index i1 is used:

      MariaDB [test]>  explain select * from t20 where col1 ='2026-06-01';
      +------+-------------+-------+------+---------------+------+---------+-------+------+-------+
      | id   | select_type | table | type | possible_keys | key  | key_len | ref   | rows | Extra |
      +------+-------------+-------+------+---------------+------+---------+-------+------+-------+
      |    1 | SIMPLE      | t20   | ref  | i1            | i1   | 4       | const | 1    |       |
      +------+-------------+-------+------+---------------+------+---------+-------+------+-------+
      

      in 12.2, col1=... is rewritten into vcol=....
      This enables use of index i2 but disables use of index i1:

      MariaDB [test]> explain select * from t20 where col1 ='2026-06-01';
      +------+-------------+-------+------+---------------+------+---------+-------+------+-------+
      | id   | select_type | table | type | possible_keys | key  | key_len | ref   | rows | Extra |
      +------+-------------+-------+------+---------------+------+---------+-------+------+-------+
      |    1 | SIMPLE      | t20   | ref  | i2            | i2   | 4       | const | 1    |       |
      +------+-------------+-------+------+---------------+------+---------+-------+------+-------+
      

      TODO: does this apply to meaningful virtual column definitions (not "vcol as (col1)"?)

      Attachments

        Activity

          People

            Unassigned Unassigned
            psergei Sergei Petrunia
            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.