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

Allow USE / FORCE on an index the optimizer would never consider using

    XMLWordPrintable

Details

    • Task
    • Status: Open (View Workflow)
    • Minor
    • Resolution: Unresolved
    • None
    • Optimizer
    • None

    Description

      For a query like

      SELECT * FROM t1  WHERE val1 < val2;
      

      an index on (val1,val2) is never considered as a candidate, and so USE or FORCE can't be used on it, and a full table scan is done instead unless there's a covering index over all result columns.

      There are edge cases though where only a small minority of rows actually fulfill the "val1 < val2" condition, I tested this with only 0.1% of rows matching. In that case an index scan with following random row lookups of the matching rows turns out to be faster than a full table scan.

      The optimizer itself can't decide on this as it does not have statistics on the "less than" relationship between val1 and val2, and so will never consider using an index scan here.

      A user may know about the data distribution, and so be able to decide that a FORCE INDEX may make sense here, but as the index is not even considered as a candidate it is also not available for FORCE

      Attachments

        Activity

          People

            Unassigned Unassigned
            hholzgra Hartmut Holzgraefe
            Votes:
            0 Vote for this issue
            Watchers:
            3 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.