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

InnoDB's doubling of rec_per_key estimates causes poor query plans

Details

    Description

      InnoDB is known to produce overly-optimistic index estimates for index lookups.
      This was done intentionally, see this piece in ha_innobase::info_low:

                                      /* Since MySQL seems to favor table scans
                                      too much over index searches, we pretend
                                      index selectivity is 2 times better than
                                      our estimate: */
       
                                      rec_per_key_int = rec_per_key_int / 2;
      

      However in some cases that can cause poor query plans.

      in 11.0, this was removed by this commit:

      commit 01c82173dd8b6ea627dec949dbc57dfcc94a656d
      Author: Monty <monty@mariadb.org>
      Date:   Thu Jan 26 11:38:31 2023 +0200
       
          Removed /2 of InnoDB ref_per_key[] estimates
          
          The original code was there to favor index search over table scan.
          This is not needed anymore as the cost calculations for table scans
          and index lookups are now more exact.
      

      This MDEV is about adding a capability to remove the /2 in versions before 11.0

      Attachments

        Activity

          psergei Sergei Petrunia created issue -
          psergei Sergei Petrunia made changes -
          Field Original Value New Value
          Status Open [ 1 ] In Progress [ 3 ]
          psergei Sergei Petrunia made changes -
          Assignee Sergei Petrunia [ psergey ] Michael Widenius [ monty ]
          psergei Sergei Petrunia added a comment - https://github.com/MariaDB/server/pull/3432
          psergei Sergei Petrunia made changes -
          Affects Version/s 10.5 [ 23123 ]
          Affects Version/s 10.11 [ 27614 ]
          psergei Sergei Petrunia made changes -
          Description InnoDB is known to produce overly-optimistic index estimates for index lookups.
          This was done intentionally, see this piece in {{ha_innobase::info_low}}:

          {code:cpp}
                                          /* Since MySQL seems to favor table scans
                                          too much over index searches, we pretend
                                          index selectivity is 2 times better than
                                          our estimate: */

                                          rec_per_key_int = rec_per_key_int / 2;
          {code}

          However in some cases that can cause poor query plans.
          InnoDB is known to produce overly-optimistic index estimates for index lookups.
          This was done intentionally, see this piece in {{ha_innobase::info_low}}:

          {code:cpp}
                                          /* Since MySQL seems to favor table scans
                                          too much over index searches, we pretend
                                          index selectivity is 2 times better than
                                          our estimate: */

                                          rec_per_key_int = rec_per_key_int / 2;
          {code}

          However in some cases that can cause poor query plans.

          in 11.0, this was removed by this commit:
          {code}
          commit 01c82173dd8b6ea627dec949dbc57dfcc94a656d
          Author: Monty <monty@mariadb.org>
          Date: Thu Jan 26 11:38:31 2023 +0200

              Removed /2 of InnoDB ref_per_key[] estimates
              
              The original code was there to favor index search over table scan.
              This is not needed anymore as the cost calculations for table scans
              and index lookups are now more exact.
          {code}
          This MDEV is about adding a capability to remove the /2 in versions before 11.0
          psergei Sergei Petrunia made changes -
          Assignee Michael Widenius [ monty ] Sergei Petrunia [ psergey ]
          psergei Sergei Petrunia made changes -
          Fix Version/s 10.6.19 [ 29833 ]
          Fix Version/s 10.11.9 [ 29834 ]
          Fix Version/s 11.1.6 [ 29835 ]
          Fix Version/s 11.2.5 [ 29836 ]
          Fix Version/s 11.4.3 [ 29837 ]
          Fix Version/s 11.5.2 [ 29838 ]
          Fix Version/s 11.6.1 [ 29847 ]
          Fix Version/s 10.6 [ 24028 ]
          Resolution Fixed [ 1 ]
          Status In Progress [ 3 ] Closed [ 6 ]

          People

            psergei Sergei Petrunia
            psergei Sergei Petrunia
            Votes:
            0 Vote for this issue
            Watchers:
            1 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.