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

Query with selectall is slower than select a specific column as it does not use the index

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Not a Bug
    • None
    • N/A
    • Optimizer
    • None
    • Mariadb 11.0.2

    Description

      Adding below both explain queries with results.
      The selectAll query is not using the index.

      EXPLAIN SELECT
          *
      FROM
          `orders`
      WHERE
          amazon_order_id IN (
              SELECT
                  j.azid
              FROM
                  marketplace_order_data m,
                  JSON_TABLE(
                      m.shipment_order_ids,
                      '$[*]' COLUMNS(azid varchar(20) PATH '$')
                  ) AS j
              WHERE
                  shipment_id IN ('XXX')
          );
      

      +------+-------------+------------+-------+---------------+------------+---------+-------+--------+-----------------------------------------------------------------------------------------------------+
      | id   | select_type | table      | type  | possible_keys | key        | key_len | ref   | rows   | Extra                                                                                               |
      +------+-------------+------------+-------+---------------+------------+---------+-------+--------+-----------------------------------------------------------------------------------------------------+
      |    1 | PRIMARY     | m          | const | shipmentId    | shipmentId | 98      | const | 1      |                                                                                                     |
      |    1 | PRIMARY     | orders | ALL   | NULL          | NULL       | NULL    | NULL  | 599922 |                                                                                                     |
      |    1 | PRIMARY     | j          | ALL   | NULL          | NULL       | NULL    | NULL  | 40     | Table function: json_table; Using where; FirstMatch(orders); Using join buffer (flat, BNL join) |
      +------+-------------+------------+-------+---------------+------------+---------+-------+--------+-----------------------------------------------------------------------------------------------------+
      

      EXPLAIN SELECT
          amazon_order_id
      FROM
          `orders`
      WHERE
          amazon_order_id IN (
              SELECT
                  j.azid
              FROM
                  marketplace_order_data,
                  JSON_TABLE(
                      shipment_order_ids,
                      '$[*]' COLUMNS(azid varchar(20) PATH '$')
                  ) AS j
              WHERE
                  shipment_id IN ('XXX')
          );
      

      +------+-------------+----------------------------+-------+---------------+-----------------+---------+-------+--------+-----------------------------------------------------------------------------------------------------+
      | id   | select_type | table                      | type  | possible_keys | key             | key_len | ref   | rows   | Extra                                                                                               |
      +------+-------------+----------------------------+-------+---------------+-----------------+---------+-------+--------+-----------------------------------------------------------------------------------------------------+
      |    1 | PRIMARY     | marketplace_order_data | const | shipmentId    | shipmentId      | 98      | const | 1      |                                                                                                     |
      |    1 | PRIMARY     | orders                 | index | NULL          | amazon_order_id | 188     | NULL  | 599930 | Using index                                                                                         |
      |    1 | PRIMARY     | j                          | ALL   | NULL          | NULL            | NULL    | NULL  | 40     | Table function: json_table; Using where; FirstMatch(orders); Using join buffer (flat, BNL join) |
      +------+-------------+----------------------------+-------+---------------+-----------------+---------+-------+--------+-----------------------------------------------------------------------------------------------------+
      

      Attachments

        Activity

          People

            serg Sergei Golubchik
            lemnisk8 Chintan Thakkar
            Votes:
            0 Vote for this issue
            Watchers:
            2 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.