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

Performance regression starting in 10.6: unlimited "select order by limit" always using temporary, taking between 60x and 2000x longer in 10.6, 10.7, and 10.8 than in 10.5

Details

    Description

      Attached file reproduces: a simple select using no where clause but using limit, with order-by on an unindexed attribute, against a table with a little over 500,000 rows, takes about 0.150s in 10.5.15, while in 10.6.8, 10.7.4, and 10.8.3 the same query consistently takes about 10s. When an index is added, the difference is much more dramatic. 10.5 drops from 0.150s to 0.004s, while 10.6, 10.7, and 10.8 all remain unchanged at 10s.

      The explain plan shows that 10.6-10.8 always create a temporary table in addition to using filesort (or an index), while 10.5 just uses filesort in the first case and index in the second w/o needing to create a temporary table in either case. Increasing sort_buffer_size up to 512M makes no difference. One significant change is that the metadata (system) character set in 10.5 is utf8, whereas starting with 10.6 it's utf8mb3.

      MariaDB [test]> show create table TEST_Table\G
      *************************** 1. row ***************************
             Table: TEST_Table
      Create Table: CREATE TABLE `TEST_Table` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `categoryLookupId` int(11) DEFAULT NULL,
        `date` datetime DEFAULT NULL,
        PRIMARY KEY (`id`),
        KEY `aap_category` (`categoryLookupId`),
        KEY `TEST_Table_date_cat` (`date`,`categoryLookupId`)
      ) ENGINE=InnoDB AUTO_INCREMENT=599441 DEFAULT CHARSET=utf8mb3
      1 row in set (0.001 sec)
      

      select date, `TEST_RETURN_LOOKUP_VALUE`(`categoryLookupId`) AS `propertyCategory` from `TEST_Table` order by date desc limit 25;
      

      Unindexed 10.5 explain:

      +------+-------------+------------+------+---------------+------+---------+------+--------+----------------+
      | id   | select_type | table      | type | possible_keys | key  | key_len | ref  | rows   | Extra          |
      +------+-------------+------------+------+---------------+------+---------+------+--------+----------------+
      |    1 | SIMPLE      | TEST_Table | ALL  | NULL          | NULL | NULL    | NULL | 598694 | Using filesort |
      +------+-------------+------------+------+---------------+------+---------+------+--------+----------------+
      

      Unindexed 10.6, 10.7, 10.8 explain

      +------+-------------+------------+------+---------------+------+---------+------+------+---------------------------------+
      | id   | select_type | table      | type | possible_keys | key  | key_len | ref  | rows | Extra                           |
      +------+-------------+------------+------+---------------+------+---------+------+------+---------------------------------+
      |    1 | SIMPLE      | TEST_Table | ALL  | NULL          | NULL | NULL    | NULL | 1    | Using temporary; Using filesort |
      +------+-------------+------------+------+---------------+------+---------+------+------+---------------------------------+
      

      Typical indexed 10.5 performance

      MariaDB [test]> select date, `TEST_RETURN_LOOKUP_VALUE`(`categoryLookupId`) AS `propertyCategory` from `TEST_Table` order by date desc limit 5;
      +---------------------+----------------------------------+
      | date                | propertyCategory                 |
      +---------------------+----------------------------------+
      | 2022-07-18 19:49:09 | 74968a188eb4f4dcc022669eff344f0f |
      | 2022-07-18 19:49:09 | 1a110af0481e6221693ec1ac8f9ebee6 |
      | 2022-07-18 19:49:04 | 74968a188eb4f4dcc022669eff344f0f |
      | 2022-07-18 19:49:01 | b323588d8d57ba607870ccf1df312b5c |
      | 2022-07-18 19:48:57 | 822b38cf00f26ad6cdc0c59f5b0f6016 |
      +---------------------+----------------------------------+
      5 rows in set (0.002 sec)
      

      Typical unindexed 10.5 performance

      MariaDB [test]> select date, `TEST_RETURN_LOOKUP_VALUE`(`categoryLookupId`) AS `propertyCategory` from `TEST_Table` order by date desc limit 5;
      +---------------------+----------------------------------+
      | date                | propertyCategory                 |
      +---------------------+----------------------------------+
      | 2022-07-18 19:49:09 | 1a110af0481e6221693ec1ac8f9ebee6 |
      | 2022-07-18 19:49:09 | 74968a188eb4f4dcc022669eff344f0f |
      | 2022-07-18 19:49:04 | 74968a188eb4f4dcc022669eff344f0f |
      | 2022-07-18 19:49:01 | b323588d8d57ba607870ccf1df312b5c |
      | 2022-07-18 19:48:57 | 822b38cf00f26ad6cdc0c59f5b0f6016 |
      +---------------------+----------------------------------+
      5 rows in set (0.104 sec)
      

      Typical indexed 10.6 through 10.8 performance

      MariaDB [test]> select date, `TEST_RETURN_LOOKUP_VALUE`(`categoryLookupId`) AS `propertyCategory` from `TEST_Table` order by date desc limit 5;
      +---------------------+----------------------------------+
      | date                | propertyCategory                 |
      +---------------------+----------------------------------+
      | 2022-07-18 19:49:05 | 47fddf54db605db008ba78df7ab6c02e |
      | 2022-07-18 19:49:05 | 19736280721c57a798064fad686b684a |
      | 2022-07-18 19:49:04 | 19736280721c57a798064fad686b684a |
      | 2022-07-18 19:49:03 | 47fddf54db605db008ba78df7ab6c02e |
      | 2022-07-18 19:49:00 | 5c884e67b699c62af82394735b4dfe1a |
      +---------------------+----------------------------------+
      5 rows in set (9.803 sec)
      

      Typical unindexed 10.6 through 10.8 performance

      MariaDB [test]> select date, `TEST_RETURN_LOOKUP_VALUE`(`categoryLookupId`) AS `propertyCategory` from `TEST_Table` order by date desc limit 5;
      +---------------------+----------------------------------+
      | date                | propertyCategory                 |
      +---------------------+----------------------------------+
      | 2022-07-18 19:49:05 | 47fddf54db605db008ba78df7ab6c02e |
      | 2022-07-18 19:49:05 | 19736280721c57a798064fad686b684a |
      | 2022-07-18 19:49:04 | 19736280721c57a798064fad686b684a |
      | 2022-07-18 19:49:03 | 47fddf54db605db008ba78df7ab6c02e |
      | 2022-07-18 19:49:00 | 5c884e67b699c62af82394735b4dfe1a |
      +---------------------+----------------------------------+
      5 rows in set (9.681 sec)
      

      Attachments

        Issue Links

          Activity

            juan.vera Juan created issue -
            juan.vera Juan made changes -
            Field Original Value New Value
            Attachment cs0412805-20220718-simplified-issue-reproduction.sql [ 64725 ]
            elenst Elena Stepanova made changes -
            Fix Version/s 10.6 [ 24028 ]
            Fix Version/s 10.7 [ 24805 ]
            Fix Version/s 10.8 [ 26121 ]
            Fix Version/s 10.9 [ 26905 ]
            Assignee Sergei Petrunia [ psergey ]
            elenst Elena Stepanova made changes -
            Status Open [ 1 ] Confirmed [ 10101 ]
            ccalender Chris Calender (Inactive) made changes -
            Priority Major [ 3 ] Critical [ 2 ]
            ccalender Chris Calender (Inactive) made changes -
            Labels regression
            ccalender Chris Calender (Inactive) made changes -
            Labels regression regression regression-10.6 regression-10.7 regression-10.8
            psergei Sergei Petrunia made changes -
            Status Confirmed [ 10101 ] In Progress [ 3 ]
            psergei Sergei Petrunia made changes -
            Assignee Sergei Petrunia [ psergey ] Oleg Smirnov [ JIRAUSER50405 ]
            oleg.smirnov Oleg Smirnov made changes -
            psergei Sergei Petrunia made changes -
            Status In Progress [ 3 ] Needs Feedback [ 10501 ]
            psergei Sergei Petrunia made changes -
            Status Needs Feedback [ 10501 ] Open [ 1 ]
            oleg.smirnov Oleg Smirnov made changes -
            Fix Version/s 10.11.0 [ 28411 ]
            Fix Version/s 10.6 [ 24028 ]
            Fix Version/s 10.7 [ 24805 ]
            Fix Version/s 10.8 [ 26121 ]
            Fix Version/s 10.9 [ 26905 ]
            Resolution Won't Fix [ 2 ]
            Status Open [ 1 ] Closed [ 6 ]
            ccalender Chris Calender (Inactive) made changes -
            Resolution Won't Fix [ 2 ]
            Status Closed [ 6 ] Stalled [ 10000 ]
            ralf.gebhardt Ralf Gebhardt made changes -
            Fix Version/s 10.6 [ 24028 ]
            Fix Version/s 10.7 [ 24805 ]
            Fix Version/s 10.8 [ 26121 ]
            Fix Version/s 10.9 [ 26905 ]
            Fix Version/s 10.11.0 [ 28411 ]
            Assignee Oleg Smirnov [ JIRAUSER50405 ] Sergei Petrunia [ psergey ]
            julien.fritsch Julien Fritsch made changes -
            Fix Version/s 10.10 [ 27530 ]
            Fix Version/s 10.11 [ 27614 ]
            kyle.hutchinson Kyle Hutchinson made changes -
            maxmether Max Mether made changes -
            maxmether Max Mether made changes -
            psergei Sergei Petrunia made changes -
            Fix Version/s 10.6.12 [ 28513 ]
            Fix Version/s 10.7.8 [ 28515 ]
            Fix Version/s 10.8.7 [ 28517 ]
            Fix Version/s 10.9.5 [ 28519 ]
            Fix Version/s 10.10.3 [ 28521 ]
            Fix Version/s 10.11.2 [ 28523 ]
            Fix Version/s 10.6 [ 24028 ]
            Fix Version/s 10.7 [ 24805 ]
            Fix Version/s 10.8 [ 26121 ]
            Fix Version/s 10.9 [ 26905 ]
            Fix Version/s 10.10 [ 27530 ]
            Fix Version/s 10.11 [ 27614 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            rob.schwyzer@mariadb.com Rob Schwyzer (Inactive) made changes -
            vlad.lesin Vladislav Lesin made changes -
            mariadb-jira-automation Jira Automation (IT) made changes -
            Zendesk Related Tickets 147150 201658 141520 199901 189718
            Zendesk active tickets 201658
            mariadb-jira-automation Jira Automation (IT) made changes -
            Zendesk active tickets 201658 CS0000 201658

            People

              psergei Sergei Petrunia
              juan.vera Juan
              Votes:
              4 Vote for this issue
              Watchers:
              17 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.