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

Long running SELECT in MariaDB version > 10.4

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Critical
    • Resolution: Unresolved
    • 10.6
    • 10.6, 10.11
    • None
    • None

    Description

      Hello,

      we are using this SQL:

      SELECT FLOOR(MIN(IF (sp.id_specific_price IS NULL, (p_shop.price + IFNULL(pas.price, 0))*((IFNULL(t.rate,0)/100) + 1),IF (sp.reduction_type = 'percentage',IF(sp.price = -1, (p_shop.price + IFNULL(pas.price, 0)), (sp.price + IFNULL(pas.price, 0))) * ((IFNULL(t.rate,0)/100) + 1) * (1 - sp.reduction),(IF(sp.price = -1, (p_shop.price + IFNULL(pas.price, 0)), (sp.price + IFNULL(pas.price, 0))) * ((IFNULL(t.rate,0)/100) + 1)) - sp.reduction)))) AS min_price, CEIL(MAX(IF (sp.id_specific_price IS NULL, (p_shop.price + IFNULL(pas.price, 0))*((IFNULL(t.rate,0)/100) + 1),IF (sp.reduction_type = 'percentage',IF(sp.price = -1, (p_shop.price + IFNULL(pas.price, 0)), (sp.price + IFNULL(pas.price, 0))) * ((IFNULL(t.rate,0)/100) + 1) * (1 - sp.reduction),(IF(sp.price = -1, (p_shop.price + IFNULL(pas.price, 0)), (sp.price + IFNULL(pas.price, 0))) * ((IFNULL(t.rate,0)/100) + 1)) - sp.reduction)))) AS max_price
      FROM `ps_product` p
      INNER JOIN `ps_product_shop` p_shop ON p_shop.id_product = p.id_product AND p_shop.id_shop = 1
      INNER JOIN `ps_category_product` cpro_p ON cpro_p.id_product = p_shop.id_product
      INNER JOIN `ps_category_shop` cshop_p ON cshop_p.id_category = cpro_p.id_category AND cshop_p.id_shop = 1
      LEFT JOIN `ps_product_attribute_shop` `pas` ON pas.id_product = p_shop.id_product AND pas.id_shop = 1
      LEFT JOIN `ps_tax_rules_group` `trg` ON trg.id_tax_rules_group = p_shop.id_tax_rules_group
      LEFT JOIN `ps_tax_rules_group_shop` `trgs` ON trgs.id_tax_rules_group = trg.id_tax_rules_group AND trgs.id_shop = 1
      LEFT JOIN `ps_tax_rule` `tr` ON trg.`id_tax_rules_group` = tr.`id_tax_rules_group` AND tr.`id_country` = 37 AND tr.`id_state` = 0 AND tr.`zipcode_from` = 0
      LEFT JOIN `ps_tax` `t` ON t.id_tax = tr.id_tax
      LEFT JOIN `ps_specific_price` `sp` ON p_shop.id_product = sp.id_product AND sp.id_specific_price = (SELECT spc.id_specific_price
      FROM `ps_specific_price` spc
      WHERE (spc.id_product = p.id_product) AND (spc.id_shop IN (0, 1)) AND (spc.id_currency IN (0, 1)) AND (spc.id_country IN (0, 37)) AND (spc.id_group IN (0, 3)) AND (spc.from = '0000-00-00 00:00:00' OR '2022-05-31 23:12:00' >= spc.from) AND (spc.to = '0000-00-00 00:00:00' OR '2022-05-31 23:12:00' <= spc.to) AND (spc.id_product_attribute = 0)
      ORDER BY spc.id_product_attribute DESC, spc.from_quantity DESC, (IF(spc.id_group = 3, 2, 0) + IF(spc.id_country = 37, 4, 0) + IF(spc.id_currency = 1, 8, 0) + IF(spc.id_shop = 1, 16, 0) + IF(spc.id_customer = 0, 32, 0)) DESC, spc.to DESC, spc.from DESC
      LIMIT 1) 
      INNER JOIN `ps_stock_available` stock_0 ON stock_0.id_product = p.id_product AND stock_0.id_product_attribute = IFNULL(pas.id_product_attribute, 0)
      WHERE (p_shop.active = 1) AND (p_shop.visibility IN ("both", "catalog")) AND (cshop_p.id_category = 12 OR cshop_p.id_category IN (SELECT c.id_category
      FROM `ps_category` c
      WHERE (c.nleft >= 3) AND (c.nright <= 100)
      )) AND (stock_0.quantity > 0) LIMIT 1;
      

      I performed several testing cases with this result:
      MariaDB 10.4. - 0.98s
      MariaDB 10.6. - 13.49s
      MariaDB 10.11. - 11.5s
      MySQL 8.0 - 1.15
      Percona 5.7 - 0.8s

      Looking that version of MariaDB higher than 10.4 spend a lot of time on Creating sort index (96%). Can you advise what is wrong if there is any parameter that can be changed? We are using default configuration

      Attachments

        1. 334924939_611458853843888_8138429930301132971_n.png
          334924939_611458853843888_8138429930301132971_n.png
          40 kB
        2. MariaDB-10.4.png
          MariaDB-10.4.png
          111 kB
        3. MariaDB-latest.png
          MariaDB-latest.png
          112 kB
        4. MySQL-latest.png
          MySQL-latest.png
          132 kB
        5. Percona-latest.png
          Percona-latest.png
          131 kB
        6. Maria-10-4.json
          8 kB
        7. Maria-latest.json
          10 kB
        8. MySQL-latest.json
          16 kB
        9. s08_a_a-2024-01-19-12-02-01.sql
          143 kB
        10. 10_11.png
          10_11.png
          87 kB
        11. 10_6.png
          10_6.png
          67 kB
        12. 10_4.png
          10_4.png
          135 kB
        13. 2.txt
          7 kB
        14. 2_force_index.txt
          7 kB
        15. 3.txt
          5 kB
        16. 3_force_index.txt
          5 kB
        17. 2-1.txt
          47 kB
        18. 3-1.txt
          32 kB
        19. new.txt
          1.04 MB
        20. original.txt
          1.04 MB
        21. Untitled.png
          Untitled.png
          126 kB
        22. 2024_06_18.zip
          146 kB

        Activity

          People

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