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

LP:806894 - SJ-Materialization picks scan-strategy which is 2x slower than SJ-Materialization lookup

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 5.3.12, 5.5
    • Fix Version/s: 5.5
    • Component/s: None
    • Labels:

      Description

      See testcase and details in MDEV-2608

      I'm not sure if this is actually a bug (i.e. here we have a situation where the optimizer had sufficient info to make the right decision but didn't make it). This needs to be investigated.

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            psergey Sergei Petrunia added a comment -

            Re: SJ-Materialization picks scan-strategy which is 2x slower than SJ-Materialization lookup
            == Semi-join plan analysis ==

            MariaDB [bug806894]> show table_statistics;
            ---------------------------------

            Table_schema Table_name Rows_read

            ---------------------------------

            bug806894 City 1676
            bug806894 Country 114

            ---------------------------------

            MariaDB [bug806894]> show index_statistics;;
            -------------------------------------------+

            Table_schema Table_name Index_name Rows_read

            -------------------------------------------+

            bug806894 City Country 1676
            bug806894 Country PRIMARY 114

            -------------------------------------------+

            This means that
            Country: 114 rows expected, 114 rows read
            City: 18*114=2052 rows expected, 1676 rows read
            CountryLanguage: 18*114*1=2052 rows expected, 0 rows actually read

            Per-table counters count sucessful read ops. Key lookups that found nothing are
            not counted. Let's also check status increments:

            ---------------------------------+

            Handler_read_key 1791
            Handler_read_next 1790
            Handler_tmp_update 0
            Handler_tmp_write 0

            ---------------------------------+

            .. which are caused by:

            table | Handler_read_key | Handler_read_next
            Country | 1 | 113
            City | 114 lookups | min. 1676
            CountryLanguage | =1790-115=1676 | 0, its eq_ref

            Show
            psergey Sergei Petrunia added a comment - Re: SJ-Materialization picks scan-strategy which is 2x slower than SJ-Materialization lookup == Semi-join plan analysis == MariaDB [bug806894] > show table_statistics; ------------- ---------- ---------- Table_schema Table_name Rows_read ------------- ---------- ---------- bug806894 City 1676 bug806894 Country 114 ------------- ---------- ---------- MariaDB [bug806894] > show index_statistics;; ------------- ---------- ---------- ----------+ Table_schema Table_name Index_name Rows_read ------------- ---------- ---------- ----------+ bug806894 City Country 1676 bug806894 Country PRIMARY 114 ------------- ---------- ---------- ----------+ This means that Country: 114 rows expected, 114 rows read City: 18*114=2052 rows expected, 1676 rows read CountryLanguage: 18*114*1=2052 rows expected, 0 rows actually read Per-table counters count sucessful read ops. Key lookups that found nothing are not counted. Let's also check status increments: --------------------------- ------+ Handler_read_key 1791 Handler_read_next 1790 Handler_tmp_update 0 Handler_tmp_write 0 --------------------------- ------+ .. which are caused by: table | Handler_read_key | Handler_read_next Country | 1 | 113 City | 114 lookups | min. 1676 CountryLanguage | =1790-115=1676 | 0, its eq_ref
            Hide
            psergey Sergei Petrunia added a comment -

            Re: SJ-Materialization picks scan-strategy which is 2x slower than SJ-Materialization lookup
            Indeed, let's take another look at the query:

            select *
            from
            CountryLanguage
            where (Language, Country) IN (SELECT City.Name, Country.Code FROM ...)

            Apparently, one will never get matches when they look for City.Name= CountryLanguage.Language.

            On the other hand, in the subquery's join

            SELECT City.Name, Country.Code FROM City, Country WHERE Country = Code and Code > 'LLL'

            either table will have matches. Condition "City.Country=Country.Code" is the join intended by the dataset, each city lies within some existing country, and each country has some cities.

            Show
            psergey Sergei Petrunia added a comment - Re: SJ-Materialization picks scan-strategy which is 2x slower than SJ-Materialization lookup Indeed, let's take another look at the query: select * from CountryLanguage where (Language, Country) IN (SELECT City.Name, Country.Code FROM ...) Apparently, one will never get matches when they look for City.Name= CountryLanguage.Language. On the other hand, in the subquery's join SELECT City.Name, Country.Code FROM City, Country WHERE Country = Code and Code > 'LLL' either table will have matches. Condition "City.Country=Country.Code" is the join intended by the dataset, each city lies within some existing country, and each country has some cities.
            Hide
            psergey Sergei Petrunia added a comment -

            Re: SJ-Materialization picks scan-strategy which is 2x slower than SJ-Materialization lookup
            Due to the above, I'm making the conclusion:
            this particular slowdown is expected. The fact that it worked before is pure luck, because previous plan has put table that has no matches in other tables into the front of the query plan, while now it is at the end of it.

            Show
            psergey Sergei Petrunia added a comment - Re: SJ-Materialization picks scan-strategy which is 2x slower than SJ-Materialization lookup Due to the above, I'm making the conclusion: this particular slowdown is expected. The fact that it worked before is pure luck, because previous plan has put table that has no matches in other tables into the front of the query plan, while now it is at the end of it.
            Hide
            elenst Elena Stepanova added a comment -

            Re: SJ-Materialization picks scan-strategy which is 2x slower than SJ-Materialization lookup
            Also filed in JIRA as MDEV-194

            Show
            elenst Elena Stepanova added a comment - Re: SJ-Materialization picks scan-strategy which is 2x slower than SJ-Materialization lookup Also filed in JIRA as MDEV-194
            Hide
            ratzpo Rasmus Johansson added a comment -

            Launchpad bug id: 806894

            Show
            ratzpo Rasmus Johansson added a comment - Launchpad bug id: 806894

              People

              • Assignee:
                psergey Sergei Petrunia
                Reporter:
                psergey Sergei Petrunia
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: