[MDEV-30845] filesort still select when desc/asc index matches ORDER BY Created: 2023-03-14  Updated: 2023-10-27

Status: Open
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.11.5
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Daniel Black Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Problem/Incident
is caused by MDEV-13756 Implement descending index: KEY (a DE... Closed
Relates
relates to MDEV-27419 MariaDB doesn't choose DESC index for... Confirmed

 Description   

from mysql-test/main/order_by.test (without forcing the index to something that should be used)

create table t1 (a int, b int, c int, key r (a desc, b asc));
insert t1 select seq % 10, seq div 10, seq from seq_1_to_55;
insert t1 values (NULL, NULL, NULL), (9, NULL, NULL);
 
MariaDB [test]> explain format=json select * from t1 order by a desc,b asc\G
*************************** 1. row ***************************
EXPLAIN: {
  "query_block": {
    "select_id": 1,
    "nested_loop": [
      {
        "read_sorted_file": {
          "filesort": {
            "sort_key": "t1.a desc, t1.b",
            "table": {
              "table_name": "t1",
              "access_type": "ALL",
              "rows": 57,
              "filtered": 100
            }
          }
        }
      }
    ]
  }
}

expected result, index r used for the query.

same with the inverse:

MariaDB [test]> explain format=json select * from t1 order by a asc,b desc\G
*************************** 1. row ***************************
EXPLAIN: {
  "query_block": {
    "select_id": 1,
    "nested_loop": [
      {
        "read_sorted_file": {
          "filesort": {
            "sort_key": "t1.a, t1.b desc",
            "table": {
              "table_name": "t1",
              "access_type": "ALL",
              "rows": 57,
              "filtered": 100
            }
          }
        }
      }
    ]
  }
}


Generated at Thu Feb 08 10:19:20 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.