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

Account cost of subqueries in conditions attached to tables

    XMLWordPrintable

Details

    • New Feature
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 13.3
    • Optimizer
    • None

    Description

      When optimizing queries shaped like

      SELECT ... FROM t_state s JOIN t_big b ON b.state_id = s.id
        WHERE s.name IN ('a','b')
          AND (SELECT val FROM t_attr WHERE t_attr.obj_id = b.id) = 'X';
      

      the optimizer doesn't take into account the cost of the subquery which is re-evaluated for every row. Optimizer's WHERE_COST constant is calculated expecting two simple conditions in the WHERE part. That sometimes lead to selection of inefficient execution plans like shown in the scripts attached.

      Investigate whether it's possible to account correlated subqueries in attached conditions too.

      Attachments

        1. where_cost_subquery.result
          3 kB
          Oleg Smirnov
        2. where_cost_subquery.test
          3 kB
          Oleg Smirnov

        Activity

          People

            oleg.smirnov Oleg Smirnov
            oleg.smirnov Oleg Smirnov
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - 0d
                0d
                Remaining:
                Remaining Estimate - 0d
                0d
                Logged:
                Time Spent - 1d
                1d

                Git Integration

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