Coder Social home page Coder Social logo

Comments (2)

laurynas-biveinis avatar laurynas-biveinis commented on April 27, 2024

Both EXPLAIN outputs seem identical, any chance this is the same thing pasted twice?

from mysql-5.6.

rockeet avatar rockeet commented on April 27, 2024

Both EXPLAIN outputs seem identical, any chance this is the same thing pasted twice?

It's my fault, I pasted wrong text for the second one.

Now I have re-run the two explain on a larger data set and updated the above result -- the second explain result is ok, the query plan using key_len 12 and estimated rows is 13482. the first one is wrong, it using key_len 8, which causing slow index range scan.

Also I have reproduced this issue on upstream(Oracle) mysql-8.0.30, it seems this issue was inroduced in some recent revision by upstream mysql. So I worked around this issue by rewrite the relavant tpcc subquery to:

explain SELECT ol_i_id FROM bmsql_order_line WHERE (ol_w_id, ol_d_id, ol_o_id) IN
 (WITH RECURSIVE nums AS (SELECT 1 AS value UNION ALL SELECT value + 1 AS value FROM nums WHERE nums.value < 20) 
   SELECT d_w_id, d_id, d_next_o_id - value
    FROM nums cross join bmsql_district where d_w_id = 1 AND d_id = 5);

The new query force query plan to use the full 3 columns of the index(key_len = 12):

+----+-------------+------------------+------------+-------+---------------+---------+---------+------------------+------+----------+----------------------------+
| id | select_type | table            | partitions | type  | possible_keys | key     | key_len | ref              | rows | filtered | Extra                      |
+----+-------------+------------------+------------+-------+---------------+---------+---------+------------------+------+----------+----------------------------+
|  1 | PRIMARY     | bmsql_district   | p0         | const | PRIMARY       | PRIMARY | 8       | const,const      |    1 |   100.00 | NULL                       |
|  1 | PRIMARY     | <derived3>       | NULL       | ALL   | NULL          | NULL    | NULL    | NULL             |    3 |   100.00 | Start temporary            |
|  1 | PRIMARY     | bmsql_order_line | p0         | ref   | PRIMARY       | PRIMARY | 12      | const,const,func |   10 |   100.00 | Using where; End temporary |
|  3 | DERIVED     | NULL             | NULL       | NULL  | NULL          | NULL    | NULL    | NULL             | NULL |     NULL | No tables used             |
|  4 | UNION       | nums             | NULL       | ALL   | NULL          | NULL    | NULL    | NULL             |    2 |    50.00 | Recursive; Using where     |
+----+-------------+------------------+------------+-------+---------------+---------+---------+------------------+------+----------+----------------------------+

Since this is an upstream issue, if myrocks team have no interest on tracking this issue, just close it.

from mysql-5.6.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.