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

Wrong result (missing rows) upon condition pushdown on table with DESC key

    XMLWordPrintable

Details

    • Q1/2026 Server Maintenance

    Description

      Set to critical because, while it was introduced in a rolling release 12.0, it will soon be a regression in LTS 12.3 comparing to LTS 11.8, on a very basic use case.

      CREATE TABLE t (a INT, b INT, KEY(b DESC));
      INSERT INTO t VALUES (2,8),(9,1),(4,6);
       
      SELECT a, b FROM t GROUP BY b HAVING b != 0 ORDER BY a;
      set optimizer_switch = 'condition_pushdown_from_having=off';
      SELECT a, b FROM t GROUP BY b HAVING b != 0 ORDER BY a;
       
      DROP TABLE t;
      

      12.2 d640758b9478f4da9ac0023b1ac389ffc23aa9bb

      SELECT a, b FROM t GROUP BY b HAVING b != 0 ORDER BY a;
      a	b
      set optimizer_switch = 'condition_pushdown_from_having=off';
      SELECT a, b FROM t GROUP BY b HAVING b != 0 ORDER BY a;
      a	b
      2	8
      4	6
      9	1
      

      The expected result is 3 rows, as with pushdown OFF.

      ANALYZE with pushdown ON

      ANALYZE FORMAT=JSON SELECT a, b FROM t GROUP BY b HAVING b != 0 ORDER BY a;
      ANALYZE
      {
        "query_optimization": {
          "r_total_time_ms": 0.631530132
        },
        "query_block": {
          "select_id": 1,
          "cost": 0.005628033,
          "r_loops": 1,
          "r_total_time_ms": 0.210688036,
          "filesort": {
            "sort_key": "t.a",
            "r_loops": 1,
            "r_total_time_ms": 0.048360241,
            "r_used_priority_queue": false,
            "r_output_rows": 0,
            "r_buffer_size": "320",
            "r_sort_mode": "sort_key,rowid",
            "temporary_table": {
              "nested_loop": [
                {
                  "table": {
                    "table_name": "t",
                    "access_type": "range",
                    "possible_keys": ["b"],
                    "key": "b",
                    "key_length": "5",
                    "loops": 1,
                    "r_loops": 1,
                    "rows": 3,
                    "r_index_rows": 0,
                    "r_rows": 0,
                    "cost": 0.005628033,
                    "r_table_time_ms": 0.034859331,
                    "r_other_time_ms": 0.061537373,
                    "r_engine_stats": {},
                    "filtered": 100,
                    "r_total_filtered": 100,
                    "index_condition": "t.b <> 0",
                    "r_icp_filtered": 0,
                    "r_filtered": 100
                  }
                }
              ]
            }
          }
        }
      }
      

      The failure started happening after this commit in 12.0:

      commit 7e4233746e28cf33a24d6d61e31b82f9838d635d
      Author: Dave Gosselin
      Date:   Mon Feb 10 13:56:25 2025 -0500
       
          MDEV-34413 Index Condition Pushdown for reverse ordered scans
      

      Attachments

        Issue Links

          Activity

            People

              Gosselin Dave Gosselin
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              5 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.