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

ICP, Reverse scan: range access will scan whole index for range w/o max endpoint

    XMLWordPrintable

Details

    • Bug
    • Status: In Review (View Workflow)
    • Blocker
    • Resolution: Unresolved
    • 12.3
    • 12.3
    • Optimizer
    • None
    • Q1/2026 Server Development

    Description

       
      create table t1 (
        a int,
        b int,
        index(a)
      );
       
      insert into t1 select seq, seq from seq_1_to_10000;
       
      analyze format=json 
      select * from t1 
      where a > 9900 and (a+1 > 9901) 
      order by a desc;
      

      gives this output

      {
        "query_optimization": {
          "r_total_time_ms": 0.674235924
        },
        "query_block": {
          "select_id": 1,
          "cost": 0.026931824,
          "r_loops": 1,
          "r_total_time_ms": 11286.65038,
          "nested_loop": [
            {
              "table": {
                "table_name": "t1",
                "access_type": "range",
                "possible_keys": ["a"],
                "key": "a",
                "key_length": "5",
                "used_key_parts": ["a"],
                "loops": 1,
                "r_loops": 1,
                "rows": 10,
                "r_index_rows": 10000,
                "r_rows": 0,
                "cost": 0.02056344,
                "r_table_time_ms": 27.22319728,
                "r_other_time_ms": 0.028516076,
                "r_engine_stats": {
                  "pages_accessed": 14
                },
                "filtered": 100,
                "r_total_filtered": 0,
                "index_condition": "t1.a + 1 > 999991 and t1.a > 9990",
                "r_icp_filtered": 0,
                "r_filtered": 100
              }
            }
          ]
        }
      }
      

      Note the

                "r_index_rows": 10000,
      

      This happened because set_end_range() call was not made, and index_last() walked off the left endoint of the t1.a > 9990 range and scanned the whole table.

      Attachments

        Issue Links

          Activity

            People

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