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

Slow query with multiple Joins and subquery (30000 times slower than on version 10.4.)

    XMLWordPrintable

Details

    • Bug
    • Status: Stalled (View Workflow)
    • Critical
    • Resolution: Unresolved
    • 10.5, 10.6, 10.9, 10.10, 10.11, 10.5.22, 10.6.15, 10.9.8, 10.10.6, 10.11.5
    • 10.5, 10.6, 10.11
    • None
    • tested on both Linux and Windows

    Description

      This query

      SELECT d0_.id AS id_0, d0_.root_id AS sclr_1, d1_.internal_amount AS internal_amount_2 
      FROM d_product d0_ 
      LEFT JOIN d_product_stock d1_ ON d0_.stock_id = d1_.id 
      LEFT JOIN d_producer d2_ ON d0_.producer_id = d2_.id 
      LEFT JOIN d_product_categories_all d4_ ON d0_.id = d4_.product_id 
      LEFT JOIN structure_node s3_ ON s3_.id = d4_.structure_node_id
      JOIN (
      	SELECT d0_.root_id AS root_id, d0_.id AS id_0, d0_.root_id AS sclr_1, MAX(d1_.internal_amount) AS internal_amount_2 
      	FROM d_product d0_ 
      	LEFT JOIN d_product_stock d1_ ON d0_.stock_id = d1_.id 
      	LEFT JOIN d_producer d2_ ON d0_.producer_id = d2_.id 
      	LEFT JOIN d_product_categories_all d4_ ON d0_.id = d4_.product_id 
      	LEFT JOIN structure_node s3_ ON s3_.id = d4_.structure_node_id 
      	WHERE d0_.visible = 1 AND s3_.id = 7 AND d2_.id IN (0x11ede8e0ac4cb26e90e7ac1f6bf1f375) AND d1_.internal_amount > 0 
      	GROUP BY d0_.root_id
            ) subq ON subq.root_id = d0_.root_id 
      WHERE subq.internal_amount_2 = d1_.internal_amount AND d0_.visible = 1 AND s3_.id = 7 AND d2_.id IN
      (0x11ede8e0ac4cb26e90e7ac1f6bf1f375) AND d1_.internal_amount > 0 
      GROUP BY d0_.root_id 
      ORDER BY d0_.purchasable_variant DESC, d1_.internal_amount_2 DESC, d0_.id ASC
      

      on version 10.3.31 and 10.4.31 runs cca 2ms
      with same dataset on 10.5+ it runs 60000ms and more

      I provide test data, where the problem is obvious, if you import this data and run the query above.

      Attachments

        Activity

          People

            psergei Sergei Petrunia
            forgie Ján Forgáč
            Votes:
            0 Vote for this issue
            Watchers:
            6 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.