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

Slow query due to Optimizer picking the wrong table for join order

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Blocker
    • Resolution: Not a Bug
    • 10.6.12
    • N/A
    • Optimizer
    • None
    • Ubuntu 22.04 (10.6.12-MariaDB-0ubuntu0.22.04.1-log)

    Description

      We have two big tables (> 1 and 10 mio entries). Query looks like this:

      EXPLAIN SELECT
      	`assets`.*,
      	`asset_media`.`media_id` AS `pivot_media_id`,
      	`asset_media`.`asset_id` AS `pivot_asset_id` 
      FROM
      	`assets`
      	INNER JOIN `asset_media` ON `assets`.`id` = `asset_media`.`asset_id` 
      WHERE
      	`asset_media`.`media_id` = 479877 
      	AND `assets`.`deleted_at` IS NULL
      

      After upgrade to MariaDB 10.6 (From 10.3) the query optimizer is not able to choose the correct order (See screenshots and dump). Dump needed to get reduced to get it uploaded to Jira (10MB).

      Expected:
      First use `asset_media` and then `assets` table.

      Result:
      Wrong order

      This causes our statement(s) to significantly loose performance (from 0.5sec to 9sec)

      Attachments

        1. ANALYZE_Result.png
          ANALYZE_Result.png
          83 kB
        2. mariadb-10.3.37.json
          1.0 kB
        3. mariadb-10.3.37.png
          mariadb-10.3.37.png
          135 kB
        4. mariadb-10.6.12.json
          1 kB
        5. mariadb-10.6.12.png
          mariadb-10.6.12.png
          105 kB
        6. test-db.sql.bz2
          8.28 MB

        Activity

          People

            Unassigned Unassigned
            patriziotomato Patrick Thomas
            Votes:
            0 Vote for this issue
            Watchers:
            2 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.