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

IN predicate to IN subquery conversion causes performance regression

Details

    Description

      This issue affects Magento2 (leading eCommerce CRM): https://magento.com/
      Most likely related to MDEV-12176.

      Magento2 is using Entity-Attribute-Value model (EAV), also known as object-attribute-value.
      with 315 tables. Here is the diagram:
      https://anna.voelkl.at/magento-ce-2-1-3-database-diagram/

      As a result, there are multiple "IN " statements in queries. Here is one of the problematic queries:
      SELECT `main_table`.* FROM `url_rewrite` AS `main_table` WHERE (`redirect_type` = '0') AND (`entity_type` = 'product') AND (`entity_id` IN('448', '503', '532', '547 ........... <------ if the number of products here exceeds 1000, then "optimizer" creates subqueries.

      In MariaDB 10.1 and 10.2 and also MySQL 8 it's a SIMPLE execution plan that takes 6 seconds:

      • see screenshot 1

      95210 rows in set (5.58 sec)

      On MariaDB 10.3 and 10.4 on the same server with the same settings (including optimizer_switch) it's now 35 mins:

      • see screenshot 2

      However, there is no way to disable subqueries in MDEV-12176 (@@in_predicate_conversion_threshold doesn't work on production releases)

      The database is about 7GB and contains sensitive data. That's why I didn't attach it to this issue. It is available on request.

      Attachments

        Issue Links

          Activity

            babanski Alex Babanski created issue -
            babanski Alex Babanski made changes -
            Field Original Value New Value
            babanski Alex Babanski made changes -
            Description This issue affects Magento2 (leading eCommerce CRM): https://magento.com/
            Most likely related to MDEV-12176.

            Magento2 is using Entity-Attribute-Value model (EAV), also known as object-attribute-value.
            with 315 tables. Here is the diagram:
            https://anna.voelkl.at/magento-ce-2-1-3-database-diagram/

            As a result, there are multiple "IN " statements in queries. Here is one of the problematic queries:
            SELECT `main_table`.* FROM `url_rewrite` AS `main_table` WHERE (`redirect_type` = '0') AND (`entity_type` = 'product') AND (`entity_id` IN('448', '503', '532', '547 ........... <------ if the number of products here exceeds 1000, then "optimizer" creates subqueries.

            In *MariaDB 10.1* and *10.2* and also *MySQL 8* it's a SIMPLE execution plan that takes *6 seconds*:
            *************************** 1. row ***************************
            id: 1
            select_type: SIMPLE
            table: main_table
            partitions: NULL
            type: ALL
            possible_keys: NULL
            key: NULL
            key_len: NULL
            ref: NULL
            rows: 659999
            filtered: 0.50
            Extra: Using where

            95210 rows in set (5.58 sec)
                      
            On *MariaDB 10.3* and *10.4* on the same server with the same settings (including optimizer_switch) it's now *35 mins*:

            *************************** 1. row ***************************
                       id: 1
              select_type: PRIMARY
                    table: main_table
                     type: ALL
            possible_keys: NULL
                      key: NULL
                  key_len: NULL
                      ref: NULL
                     rows: 671326
                    Extra: Using where
            *************************** 2. row ***************************
                       id: 1
              select_type: PRIMARY
                    table: <derived3>
                     type: ALL
            possible_keys: NULL
                      key: NULL
                  key_len: NULL
                      ref: NULL
                     rows: 31001
                    Extra: Using where; FirstMatch(main_table)
            *************************** 3. row ***************************
                       id: 3
              select_type: DERIVED
                    table: NULL
                     type: NULL
            possible_keys: NULL
                      key: NULL
                  key_len: NULL
                      ref: NULL
                     rows: NULL
                    Extra: No tables used


            However, there is no way to disable subqueries in MDEV-12176 (@@in_predicate_conversion_threshold doesn't work on production releases)

            The database is about 7GB and contains sensitive data. That's why I didn't attach it to this issue. It is available on request.
            This issue affects Magento2 (leading eCommerce CRM): https://magento.com/
            Most likely related to MDEV-12176.

            Magento2 is using Entity-Attribute-Value model (EAV), also known as object-attribute-value.
            with 315 tables. Here is the diagram:
            https://anna.voelkl.at/magento-ce-2-1-3-database-diagram/

            As a result, there are multiple "IN " statements in queries. Here is one of the problematic queries:
            SELECT `main_table`.* FROM `url_rewrite` AS `main_table` WHERE (`redirect_type` = '0') AND (`entity_type` = 'product') AND (`entity_id` IN('448', '503', '532', '547 ........... <------ *if the number of products here exceeds 1000, then "optimizer" creates subqueries.*

            In *MariaDB 10.1* and *10.2* and also *MySQL 8* it's a SIMPLE execution plan that takes *6 seconds*:
            *************************** 1. row ***************************
            id: 1
            select_type: SIMPLE
            table: main_table
            partitions: NULL
            type: ALL
            possible_keys: NULL
            key: NULL
            key_len: NULL
            ref: NULL
            rows: 659999
            filtered: 0.50
            Extra: Using where

            95210 rows in set (5.58 sec)
                      
            On *MariaDB 10.3* and *10.4* on the same server with the same settings (including optimizer_switch) it's now *35 mins*:

            *************************** 1. row ***************************
                       id: 1
              select_type: PRIMARY
                    table: main_table
                     type: ALL
            possible_keys: NULL
                      key: NULL
                  key_len: NULL
                      ref: NULL
                     rows: 671326
                    Extra: Using where
            *************************** 2. row ***************************
                       id: 1
              select_type: PRIMARY
                    table: <derived3>
                     type: ALL
            possible_keys: NULL
                      key: NULL
                  key_len: NULL
                      ref: NULL
                     rows: 31001
                    Extra: Using where; FirstMatch(main_table)
            *************************** 3. row ***************************
                       id: 3
              select_type: DERIVED
                    table: NULL
                     type: NULL
            possible_keys: NULL
                      key: NULL
                  key_len: NULL
                      ref: NULL
                     rows: NULL
                    Extra: No tables used


            However, there is no way to disable subqueries in MDEV-12176 (@@in_predicate_conversion_threshold doesn't work on production releases)

            The database is about 7GB and contains sensitive data. That's why I didn't attach it to this issue. It is available on request.
            babanski Alex Babanski made changes -
            Description This issue affects Magento2 (leading eCommerce CRM): https://magento.com/
            Most likely related to MDEV-12176.

            Magento2 is using Entity-Attribute-Value model (EAV), also known as object-attribute-value.
            with 315 tables. Here is the diagram:
            https://anna.voelkl.at/magento-ce-2-1-3-database-diagram/

            As a result, there are multiple "IN " statements in queries. Here is one of the problematic queries:
            SELECT `main_table`.* FROM `url_rewrite` AS `main_table` WHERE (`redirect_type` = '0') AND (`entity_type` = 'product') AND (`entity_id` IN('448', '503', '532', '547 ........... <------ *if the number of products here exceeds 1000, then "optimizer" creates subqueries.*

            In *MariaDB 10.1* and *10.2* and also *MySQL 8* it's a SIMPLE execution plan that takes *6 seconds*:
            *************************** 1. row ***************************
            id: 1
            select_type: SIMPLE
            table: main_table
            partitions: NULL
            type: ALL
            possible_keys: NULL
            key: NULL
            key_len: NULL
            ref: NULL
            rows: 659999
            filtered: 0.50
            Extra: Using where

            95210 rows in set (5.58 sec)
                      
            On *MariaDB 10.3* and *10.4* on the same server with the same settings (including optimizer_switch) it's now *35 mins*:

            *************************** 1. row ***************************
                       id: 1
              select_type: PRIMARY
                    table: main_table
                     type: ALL
            possible_keys: NULL
                      key: NULL
                  key_len: NULL
                      ref: NULL
                     rows: 671326
                    Extra: Using where
            *************************** 2. row ***************************
                       id: 1
              select_type: PRIMARY
                    table: <derived3>
                     type: ALL
            possible_keys: NULL
                      key: NULL
                  key_len: NULL
                      ref: NULL
                     rows: 31001
                    Extra: Using where; FirstMatch(main_table)
            *************************** 3. row ***************************
                       id: 3
              select_type: DERIVED
                    table: NULL
                     type: NULL
            possible_keys: NULL
                      key: NULL
                  key_len: NULL
                      ref: NULL
                     rows: NULL
                    Extra: No tables used


            However, there is no way to disable subqueries in MDEV-12176 (@@in_predicate_conversion_threshold doesn't work on production releases)

            The database is about 7GB and contains sensitive data. That's why I didn't attach it to this issue. It is available on request.
            This issue affects Magento2 (leading eCommerce CRM): https://magento.com/
            Most likely related to MDEV-12176.

            Magento2 is using Entity-Attribute-Value model (EAV), also known as object-attribute-value.
            with 315 tables. Here is the diagram:
            https://anna.voelkl.at/magento-ce-2-1-3-database-diagram/

            As a result, there are multiple "IN " statements in queries. Here is one of the problematic queries:
            SELECT `main_table`.* FROM `url_rewrite` AS `main_table` WHERE (`redirect_type` = '0') AND (`entity_type` = 'product') AND (`entity_id` IN('448', '503', '532', '547 ........... <------ *if the number of products here exceeds 1000, then "optimizer" creates subqueries.*

            In *MariaDB 10.1* and *10.2* and also *MySQL 8* it's a SIMPLE execution plan that takes *6 seconds*:

            id: 1
            select_type: SIMPLE
            table: main_table
            partitions: NULL
            type: ALL
            possible_keys: NULL
            key: NULL
            key_len: NULL
            ref: NULL
            rows: 659999
            filtered: 0.50
            Extra: Using where

            95210 rows in set (5.58 sec)
                      
            On *MariaDB 10.3* and *10.4* on the same server with the same settings (including optimizer_switch) it's now *35 mins*:

            *************************** 1. row ***************************
                       id: 1
              select_type: PRIMARY
                    table: main_table
                     type: ALL
            possible_keys: NULL
                      key: NULL
                  key_len: NULL
                      ref: NULL
                     rows: 671326
                    Extra: Using where
            *************************** 2. row ***************************
                       id: 1
              select_type: PRIMARY
                    table: <derived3>
                     type: ALL
            possible_keys: NULL
                      key: NULL
                  key_len: NULL
                      ref: NULL
                     rows: 31001
                    Extra: Using where; FirstMatch(main_table)
            *************************** 3. row ***************************
                       id: 3
              select_type: DERIVED
                    table: NULL
                     type: NULL
            possible_keys: NULL
                      key: NULL
                  key_len: NULL
                      ref: NULL
                     rows: NULL
                    Extra: No tables used


            However, there is no way to disable subqueries in MDEV-12176 (@@in_predicate_conversion_threshold doesn't work on production releases)

            The database is about 7GB and contains sensitive data. That's why I didn't attach it to this issue. It is available on request.
            babanski Alex Babanski made changes -
            Description This issue affects Magento2 (leading eCommerce CRM): https://magento.com/
            Most likely related to MDEV-12176.

            Magento2 is using Entity-Attribute-Value model (EAV), also known as object-attribute-value.
            with 315 tables. Here is the diagram:
            https://anna.voelkl.at/magento-ce-2-1-3-database-diagram/

            As a result, there are multiple "IN " statements in queries. Here is one of the problematic queries:
            SELECT `main_table`.* FROM `url_rewrite` AS `main_table` WHERE (`redirect_type` = '0') AND (`entity_type` = 'product') AND (`entity_id` IN('448', '503', '532', '547 ........... <------ *if the number of products here exceeds 1000, then "optimizer" creates subqueries.*

            In *MariaDB 10.1* and *10.2* and also *MySQL 8* it's a SIMPLE execution plan that takes *6 seconds*:

            id: 1
            select_type: SIMPLE
            table: main_table
            partitions: NULL
            type: ALL
            possible_keys: NULL
            key: NULL
            key_len: NULL
            ref: NULL
            rows: 659999
            filtered: 0.50
            Extra: Using where

            95210 rows in set (5.58 sec)
                      
            On *MariaDB 10.3* and *10.4* on the same server with the same settings (including optimizer_switch) it's now *35 mins*:

            *************************** 1. row ***************************
                       id: 1
              select_type: PRIMARY
                    table: main_table
                     type: ALL
            possible_keys: NULL
                      key: NULL
                  key_len: NULL
                      ref: NULL
                     rows: 671326
                    Extra: Using where
            *************************** 2. row ***************************
                       id: 1
              select_type: PRIMARY
                    table: <derived3>
                     type: ALL
            possible_keys: NULL
                      key: NULL
                  key_len: NULL
                      ref: NULL
                     rows: 31001
                    Extra: Using where; FirstMatch(main_table)
            *************************** 3. row ***************************
                       id: 3
              select_type: DERIVED
                    table: NULL
                     type: NULL
            possible_keys: NULL
                      key: NULL
                  key_len: NULL
                      ref: NULL
                     rows: NULL
                    Extra: No tables used


            However, there is no way to disable subqueries in MDEV-12176 (@@in_predicate_conversion_threshold doesn't work on production releases)

            The database is about 7GB and contains sensitive data. That's why I didn't attach it to this issue. It is available on request.
            This issue affects Magento2 (leading eCommerce CRM): https://magento.com/
            Most likely related to MDEV-12176.

            Magento2 is using Entity-Attribute-Value model (EAV), also known as object-attribute-value.
            with 315 tables. Here is the diagram:
            https://anna.voelkl.at/magento-ce-2-1-3-database-diagram/

            As a result, there are multiple "IN " statements in queries. Here is one of the problematic queries:
            SELECT `main_table`.* FROM `url_rewrite` AS `main_table` WHERE (`redirect_type` = '0') AND (`entity_type` = 'product') AND (`entity_id` IN('448', '503', '532', '547 ........... <------ *if the number of products here exceeds 1000, then "optimizer" creates subqueries.*

            In *MariaDB 10.1* and *10.2* and also *MySQL 8* it's a SIMPLE execution plan that takes *6 seconds*:


            95210 rows in set (5.58 sec)
                      
            On *MariaDB 10.3* and *10.4* on the same server with the same settings (including optimizer_switch) it's now *35 mins*:

            *************************** 1. row ***************************
                       id: 1
              select_type: PRIMARY
                    table: main_table
                     type: ALL
            possible_keys: NULL
                      key: NULL
                  key_len: NULL
                      ref: NULL
                     rows: 671326
                    Extra: Using where
            *************************** 2. row ***************************
                       id: 1
              select_type: PRIMARY
                    table: <derived3>
                     type: ALL
            possible_keys: NULL
                      key: NULL
                  key_len: NULL
                      ref: NULL
                     rows: 31001
                    Extra: Using where; FirstMatch(main_table)
            *************************** 3. row ***************************
                       id: 3
              select_type: DERIVED
                    table: NULL
                     type: NULL
            possible_keys: NULL
                      key: NULL
                  key_len: NULL
                      ref: NULL
                     rows: NULL
                    Extra: No tables used


            However, there is no way to disable subqueries in MDEV-12176 (@@in_predicate_conversion_threshold doesn't work on production releases)

            The database is about 7GB and contains sensitive data. That's why I didn't attach it to this issue. It is available on request.
            babanski Alex Babanski made changes -
            Attachment Capture0.PNG [ 49307 ]
            babanski Alex Babanski made changes -
            Attachment Capture1.PNG [ 49308 ]
            babanski Alex Babanski made changes -
            Description This issue affects Magento2 (leading eCommerce CRM): https://magento.com/
            Most likely related to MDEV-12176.

            Magento2 is using Entity-Attribute-Value model (EAV), also known as object-attribute-value.
            with 315 tables. Here is the diagram:
            https://anna.voelkl.at/magento-ce-2-1-3-database-diagram/

            As a result, there are multiple "IN " statements in queries. Here is one of the problematic queries:
            SELECT `main_table`.* FROM `url_rewrite` AS `main_table` WHERE (`redirect_type` = '0') AND (`entity_type` = 'product') AND (`entity_id` IN('448', '503', '532', '547 ........... <------ *if the number of products here exceeds 1000, then "optimizer" creates subqueries.*

            In *MariaDB 10.1* and *10.2* and also *MySQL 8* it's a SIMPLE execution plan that takes *6 seconds*:


            95210 rows in set (5.58 sec)
                      
            On *MariaDB 10.3* and *10.4* on the same server with the same settings (including optimizer_switch) it's now *35 mins*:

            *************************** 1. row ***************************
                       id: 1
              select_type: PRIMARY
                    table: main_table
                     type: ALL
            possible_keys: NULL
                      key: NULL
                  key_len: NULL
                      ref: NULL
                     rows: 671326
                    Extra: Using where
            *************************** 2. row ***************************
                       id: 1
              select_type: PRIMARY
                    table: <derived3>
                     type: ALL
            possible_keys: NULL
                      key: NULL
                  key_len: NULL
                      ref: NULL
                     rows: 31001
                    Extra: Using where; FirstMatch(main_table)
            *************************** 3. row ***************************
                       id: 3
              select_type: DERIVED
                    table: NULL
                     type: NULL
            possible_keys: NULL
                      key: NULL
                  key_len: NULL
                      ref: NULL
                     rows: NULL
                    Extra: No tables used


            However, there is no way to disable subqueries in MDEV-12176 (@@in_predicate_conversion_threshold doesn't work on production releases)

            The database is about 7GB and contains sensitive data. That's why I didn't attach it to this issue. It is available on request.
            This issue affects Magento2 (leading eCommerce CRM): https://magento.com/
            Most likely related to MDEV-12176.

            Magento2 is using Entity-Attribute-Value model (EAV), also known as object-attribute-value.
            with 315 tables. Here is the diagram:
            https://anna.voelkl.at/magento-ce-2-1-3-database-diagram/

            As a result, there are multiple "IN " statements in queries. Here is one of the problematic queries:
            SELECT `main_table`.* FROM `url_rewrite` AS `main_table` WHERE (`redirect_type` = '0') AND (`entity_type` = 'product') AND (`entity_id` IN('448', '503', '532', '547 ........... <------ *if the number of products here exceeds 1000, then "optimizer" creates subqueries.*

            In *MariaDB 10.1* and *10.2* and also *MySQL 8* it's a SIMPLE execution plan that takes *6 seconds*:

            - see screenshot 1
             !Capture0.PNG|thumbnail!

            95210 rows in set (5.58 sec)
                      
            On *MariaDB 10.3* and *10.4* on the same server with the same settings (including optimizer_switch) it's now *35 mins*:

            - see screenshot 2
             !Capture1.PNG|thumbnail!

            However, there is no way to disable subqueries in MDEV-12176 (@@in_predicate_conversion_threshold doesn't work on production releases)

            The database is about 7GB and contains sensitive data. That's why I didn't attach it to this issue. It is available on request.
            varun Varun Gupta (Inactive) made changes -
            Assignee Varun Gupta [ varun ]
            varun Varun Gupta (Inactive) made changes -
            Summary MDEV-12176 affects execution plans IN predicate to IN subquery conversion causes performance regression
            varun Varun Gupta (Inactive) made changes -
            Fix Version/s 10.3 [ 22126 ]
            Fix Version/s 10.4 [ 22408 ]
            varun Varun Gupta (Inactive) made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            varun Varun Gupta (Inactive) made changes -
            Assignee Varun Gupta [ varun ] Sergei Petrunia [ psergey ]
            Status In Progress [ 3 ] In Review [ 10002 ]
            varun Varun Gupta (Inactive) made changes -
            Assignee Sergei Petrunia [ psergey ] Varun Gupta [ varun ]
            varun Varun Gupta (Inactive) made changes -
            Status In Review [ 10002 ] Stalled [ 10000 ]
            varun Varun Gupta (Inactive) made changes -
            Fix Version/s 10.3.21 [ 24014 ]
            Fix Version/s 10.4.11 [ 24013 ]
            Fix Version/s 10.5.1 [ 24029 ]
            Fix Version/s 10.3 [ 22126 ]
            Fix Version/s 10.4 [ 22408 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            varun Varun Gupta (Inactive) made changes -
            varun Varun Gupta (Inactive) made changes -
            varun Varun Gupta (Inactive) made changes -
            Fix Version/s 10.3.22 [ 24018 ]
            Fix Version/s 10.3.21 [ 24014 ]
            varun Varun Gupta (Inactive) made changes -
            Fix Version/s 10.4.12 [ 24019 ]
            Fix Version/s 10.4.11 [ 24013 ]
            psergei Sergei Petrunia made changes -
            valerii Valerii Kravchuk made changes -
            Comment [ A comment with security level 'Developers' was removed. ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 100606 ] MariaDB v4 [ 156902 ]
            mariadb-jira-automation Jira Automation (IT) made changes -
            Zendesk Related Tickets 184082

            People

              varun Varun Gupta (Inactive)
              babanski Alex Babanski
              Votes:
              1 Vote for this issue
              Watchers:
              6 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.