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

Identity server Db Select Statement order by issue.

Details

    Description

      Please have a look at the attached screenshots, it will be easy to reproduce.

      when i run this Query, it return wrong results when i run this query on 10.2.7

      but return right results when i run on 10.1.x.

      SELECT `api`.`Id`, `api`.`Description`, `api`.`DisplayName`, `api`.`Enabled`, `api`.`Name`
      FROM `ApiResources` AS `api`
      WHERE EXISTS (
          SELECT 1
          FROM `ApiScopes` AS `x`
          WHERE `x`.`Name` IN ('openid', 'profile', 'ccx2api', 'ccx2lmapi') AND (`api`.`Id` = `x`.`ApiResourceId`))
      ORDER BY `api`.`Id`
      

      Attachments

        1. 10.1.png
          10.1.png
          364 kB
        2. 10.2.png
          10.2.png
          289 kB
        3. 2017-07-27 (1).png
          2017-07-27 (1).png
          346 kB
        4. 2017-07-27 (2).png
          2017-07-27 (2).png
          332 kB
        5. ccx-id_apiresources.sql
          2 kB
        6. ccx-id_apiscopes.sql
          3 kB

        Issue Links

          Activity

            ajaygoel555 Ajay Kumar added a comment - - edited

            Tried set optimizer_switch='materialization=off';

            working Thanks

            ajaygoel555 Ajay Kumar added a comment - - edited Tried set optimizer_switch='materialization=off'; working Thanks

            ANALYZE: {
              "query_block": {
                "select_id": 1,
                "r_loops": 1,
                "r_total_time_ms": 1.1786,
                "read_sorted_file": {
                  "r_rows": 2,
                  "filesort": {
                    "sort_key": "t1.`Id`",
                    "r_loops": 1,
                    "r_total_time_ms": 0.1815,
                    "r_used_priority_queue": false,
                    "r_output_rows": 2,
                    "r_buffer_size": "240",
                    "table": {
                      "table_name": "<subquery2>",
                      "access_type": "ALL",
                      "possible_keys": ["distinct_key"],
                      "r_loops": 1,
                      "rows": 2,
                      "r_rows": 2,
                      "r_total_time_ms": 0.2101,
                      "filtered": 100,
                      "r_filtered": 1,
                      "materialized": {
                        "unique": 1,
                        "query_block": {
                          "select_id": 2,
                          "table": {
                            "table_name": "t2",
                            "access_type": "range",
                            "possible_keys": ["Name", "id_t2"],
                            "key": "Name",
                            "key_length": "202",
                            "used_key_parts": ["Name"],
                            "r_loops": 1,
                            "rows": 2,
                            "r_rows": 2,
                            "r_total_time_ms": 0.4923,
                            "filtered": 100,
                            "r_filtered": 100,
                            "index_condition": "t2.`Name` in ('aa','bb')"
                          }
                        }
                      }
                    }
                  }
                },
                "table": {
                  "table_name": "t1",
                  "access_type": "eq_ref",
                  "possible_keys": ["PRIMARY"],
                  "key": "PRIMARY",
                  "key_length": "4",
                  "used_key_parts": ["Id"],
                  "ref": ["test.t2.id_t2"],
                  "r_loops": 2,
                  "rows": 1,
                  "r_rows": 1,
                  "r_total_time_ms": 0.0924,
                  "filtered": 100,
                  "r_filtered": 100
                }
              }
            }
            

            psergei Sergei Petrunia added a comment - ANALYZE: { "query_block": { "select_id": 1, "r_loops": 1, "r_total_time_ms": 1.1786, "read_sorted_file": { "r_rows": 2, "filesort": { "sort_key": "t1.`Id`", "r_loops": 1, "r_total_time_ms": 0.1815, "r_used_priority_queue": false, "r_output_rows": 2, "r_buffer_size": "240", "table": { "table_name": "<subquery2>", "access_type": "ALL", "possible_keys": ["distinct_key"], "r_loops": 1, "rows": 2, "r_rows": 2, "r_total_time_ms": 0.2101, "filtered": 100, "r_filtered": 1, "materialized": { "unique": 1, "query_block": { "select_id": 2, "table": { "table_name": "t2", "access_type": "range", "possible_keys": ["Name", "id_t2"], "key": "Name", "key_length": "202", "used_key_parts": ["Name"], "r_loops": 1, "rows": 2, "r_rows": 2, "r_total_time_ms": 0.4923, "filtered": 100, "r_filtered": 100, "index_condition": "t2.`Name` in ('aa','bb')" } } } } } }, "table": { "table_name": "t1", "access_type": "eq_ref", "possible_keys": ["PRIMARY"], "key": "PRIMARY", "key_length": "4", "used_key_parts": ["Id"], "ref": ["test.t2.id_t2"], "r_loops": 2, "rows": 1, "r_rows": 1, "r_total_time_ms": 0.0924, "filtered": 100, "r_filtered": 100 } } }

            Peculiar things about this query plan:

            • first, we do the subquery materialization (this reads data from table t2)
            • then, materialized subquery is used as a source data for filesort().
            • filesort has "sort_key": "t1.`Id`". That is, sort criteria uses table t1.

            This is valid since the query has

            WHERE (api.Id = x.ApiResourceId))  -- this is in the subquery
            ...
            ORDER BY api.Id
            

            however, this is where the bug most likely is.
            SJ-Materialization-scan strategy unpacks in-equality columns to the outer select' columns.
            I mean, join execution does that but does this happen when the filesort() is employed?

            The guess agrees with the observation that the error started to occur after commit a95e384d54702 (which made such query plans possible).

            psergei Sergei Petrunia added a comment - Peculiar things about this query plan: first, we do the subquery materialization (this reads data from table t2) then, materialized subquery is used as a source data for filesort(). filesort has "sort_key": "t1.`Id`" . That is, sort criteria uses table t1. This is valid since the query has WHERE (api.Id = x.ApiResourceId)) -- this is in the subquery ... ORDER BY api.Id however, this is where the bug most likely is. SJ-Materialization-scan strategy unpacks in-equality columns to the outer select' columns. I mean, join execution does that but does this happen when the filesort() is employed? The guess agrees with the observation that the error started to occur after commit a95e384d54702 (which made such query plans possible).
            alice Alice Sherepa added a comment -

            Sergei Petrunia, after fixing please check if initially reported problem and one from mdev-12959 are fixed

            alice Alice Sherepa added a comment - Sergei Petrunia, after fixing please check if initially reported problem and one from mdev-12959 are fixed
            varun Varun Gupta (Inactive) added a comment - Fixed by MDEV-13994

            People

              psergei Sergei Petrunia
              ajaygoel555 Ajay Kumar
              Votes:
              0 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.