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

A prefix index on a VIRTUAL generated column becomes corrupted (missing entries) when a DESC index on the same column also exists.

    XMLWordPrintable

Details

    Description

      Problem

      When a table has a VIRTUAL generated column (e.g., `UPPER(c2)`), creating both a DESC index and a prefix index on that same virtual column causes the prefix index B-tree to be corrupted. Specifically, 3 out of 10 index entries are missing from the prefix index.

      Root Cause Analysis

      The bug requires all of the following conditions to trigger:
      1. A *VIRTUAL* (not STORED) generated column
      2. A *DESC* index on the virtual column
      3. A *prefix index* (e.g., `col(3)`) on the same virtual column

      Removing any one of these conditions eliminates the bug. The order matters: the DESC index must be created before the prefix index.

      Minimal Reproduction

      sql:

      DROP DATABASE IF EXISTS min_db3;
      CREATE DATABASE min_db3;
      USE min_db3;
      CREATE TABLE IF NOT EXISTS idx_t2 (c0 INT NOT NULL, c1 INT NOT NULL, c2 VARCHAR(64), c3 INT NOT NULL, c4 VARCHAR(64) NOT NULL, c5 VARCHAR(64) NOT NULL, c6 INT, c7 INT NOT NULL);
      INSERT IGNORE INTO idx_t2 VALUES (181, 130, '_H/', 235, 'iy', 'sW!|', 13, 170), (205, 215, 'YNA', 22, 'C?,r', '-1148459980', 54, 77), (195, 182, '0.8253042552397039', 38, 'G{|6tY쎪B', '0.03268182386113161', 91, 7), (48, 212, '-1617255706', 133, 'o', '0.8238061916181155', 134, 105), (212, 183, '

      {\nO', 56, '?(Ud&#3', '1859083421', 13, 124), (234, 138, '-1617255706', 152, '⇯k', '', 68, 115), (211, 39, '', 12, 'Jr', '45wpR>g}

      ', 165, 13), (205, 54, 'I', 159, 'v', '386058876', 73, 155), (34, 64, '', 184, '-263138592', '2', 157, 156), (210, 6, '{荱', 214, '1?ⱨ', 'o', 206, 9);
      ALTER TABLE idx_t2 ADD COLUMN gen_col_3119_2_3 VARCHAR(255) GENERATED ALWAYS AS (UPPER(c2)) VIRTUAL;
      CREATE INDEX desc_1701_4 ON idx_t2 (gen_col_3119_2_3 DESC);
      CREATE INDEX prefix_gen_col_3119_2_3_701 ON idx_t2 (gen_col_3119_2_3(3));
      CHECK TABLE idx_t2 EXTENDED;

      Expected Result

      ```
      Table Op Msg_type Msg_text
      test_db.t check status OK
      ```

      Actual Result

      ```
      Table Op Msg_type Msg_text
      test_db.t check Warning InnoDB: Index 'prefix_idx' contains 6 entries, should be 10.
      test_db.t check error Corrupt
      ```

      Additional Notes

      • Without the DESC index, the prefix index is built correctly
      • This affects data integrity as queries using the prefix index may return incomplete results

      Attachments

        Activity

          People

            thiru Thirunarayanan Balathandayuthapani
            ZyanNo1 Zeyan Li
            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.