Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong index join range display when executing the cached plan #38269

Closed
xuyifangreeneyes opened this issue Sep 30, 2022 · 0 comments · Fixed by #38284
Closed

wrong index join range display when executing the cached plan #38269

xuyifangreeneyes opened this issue Sep 30, 2022 · 0 comments · Fixed by #38284
Assignees

Comments

@xuyifangreeneyes
Copy link
Contributor

Enhancement

mysql> create table t1(a int);
Query OK, 0 rows affected (0.02 sec)

mysql> create table t2(a int, b int, c int, index idx(a, b));
Query OK, 0 rows affected (0.02 sec)

mysql> set @@tidb_enable_prepared_plan_cache=1;
Query OK, 0 rows affected (0.00 sec)

mysql> set @@tidb_enable_collect_execution_info=0;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> show processlist;
+---------------+------+-----------------+------+---------+------+------------+------------------+
| Id            | User | Host            | db   | Command | Time | State      | Info             |
+---------------+------+-----------------+------+---------+------+------------+------------------+
| 2199023255961 | root | 127.0.0.1:53931 | test | Query   |    0 | autocommit | show processlist |
+---------------+------+-----------------+------+---------+------+------------+------------------+
1 row in set (0.00 sec)

mysql> prepare stmt1 from 'select /*+ inl_join(t2) */ * from t1 join t2 on t1.a = t2.a where t2.b in (?, ?, ?)';
Query OK, 0 rows affected (0.00 sec)

mysql> set @a = 10, @b = 20, @c = 30, @d = 40, @e = 50, @f = 60;
Query OK, 0 rows affected (0.00 sec)

mysql> execute stmt1 using @a, @b, @c;
Empty set (0.01 sec)

mysql> explain for connection  2199023255961;
+---------------------------------+----------+-----------+---------------------------+-----------------------------------------------------------------------------------------------------------------+
| id                              | estRows  | task      | access object             | operator info                                                                                                   |
+---------------------------------+----------+-----------+---------------------------+-----------------------------------------------------------------------------------------------------------------+
| IndexJoin_12                    | 37.46    | root      |                           | inner join, inner:IndexLookUp_11, outer key:test.t1.a, inner key:test.t2.a, equal cond:eq(test.t1.a, test.t2.a) |
| ├─TableReader_24(Build)         | 9990.00  | root      |                           | data:Selection_23                                                                                               |
| │ └─Selection_23                | 9990.00  | cop[tikv] |                           | not(isnull(test.t1.a))                                                                                          |
| │   └─TableFullScan_22          | 10000.00 | cop[tikv] | table:t1                  | keep order:false, stats:pseudo                                                                                  |
| └─IndexLookUp_11(Probe)         | 0.00     | root      |                           |                                                                                                                 |
|   ├─Selection_10(Build)         | 0.00     | cop[tikv] |                           | not(isnull(test.t2.a))                                                                                          |
|   │ └─IndexRangeScan_8          | 0.00     | cop[tikv] | table:t2, index:idx(a, b) | range: decided by [eq(test.t2.a, test.t1.a) in(test.t2.b, 10, 20, 30)], keep order:false, stats:pseudo          |
|   └─TableRowIDScan_9(Probe)     | 0.00     | cop[tikv] | table:t2                  | keep order:false, stats:pseudo                                                                                  |
+---------------------------------+----------+-----------+---------------------------+-----------------------------------------------------------------------------------------------------------------+
8 rows in set (0.00 sec)

mysql> execute stmt1 using @d, @e, @f;
Empty set (0.00 sec)

mysql> explain for connection  2199023255961;
+---------------------------------+----------+-----------+---------------------------+-----------------------------------------------------------------------------------------------------------------+
| id                              | estRows  | task      | access object             | operator info                                                                                                   |
+---------------------------------+----------+-----------+---------------------------+-----------------------------------------------------------------------------------------------------------------+
| IndexJoin_12                    | 37.46    | root      |                           | inner join, inner:IndexLookUp_11, outer key:test.t1.a, inner key:test.t2.a, equal cond:eq(test.t1.a, test.t2.a) |
| ├─TableReader_24(Build)         | 9990.00  | root      |                           | data:Selection_23                                                                                               |
| │ └─Selection_23                | 9990.00  | cop[tikv] |                           | not(isnull(test.t1.a))                                                                                          |
| │   └─TableFullScan_22          | 10000.00 | cop[tikv] | table:t1                  | keep order:false, stats:pseudo                                                                                  |
| └─IndexLookUp_11(Probe)         | 0.00     | root      |                           |                                                                                                                 |
|   ├─Selection_10(Build)         | 0.00     | cop[tikv] |                           | not(isnull(test.t2.a))                                                                                          |
|   │ └─IndexRangeScan_8          | 0.00     | cop[tikv] | table:t2, index:idx(a, b) | range: decided by [eq(test.t2.a, test.t1.a) in(test.t2.b, 10, 20, 30)], keep order:false, stats:pseudo          |
|   └─TableRowIDScan_9(Probe)     | 0.00     | cop[tikv] | table:t2                  | keep order:false, stats:pseudo                                                                                  |
+---------------------------------+----------+-----------+---------------------------+-----------------------------------------------------------------------------------------------------------------+
8 rows in set (0.00 sec)

When execute stmt1 using @d, @e, @f, the right index inner range should be range: decided by [eq(test.t2.a, test.t1.a) in(test.t2.b, 40, 50, 60)] rather than range: decided by [eq(test.t2.a, test.t1.a) in(test.t2.b, 10, 20, 30)].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant