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

actual plan of a running stmt is not the same as the result of explain stmt #11124

Closed
XuHuaiyu opened this issue Jul 8, 2019 · 2 comments · Fixed by #11186
Closed

actual plan of a running stmt is not the same as the result of explain stmt #11124

XuHuaiyu opened this issue Jul 8, 2019 · 2 comments · Fixed by #11186
Assignees
Labels
type/bug The issue is confirmed as a bug.

Comments

@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Jul 8, 2019

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
create table kankan1(id int, name text);

insert into kankan1 values(1, 'a');

insert into kankan1 values(2, 'a');

create table kankan2(id int, h1 text);

insert into kankan2 values(2, 'z');

In session1:

tidb> explain select t1.id,sleep(20) from kankan1 t1 left join kankan2 t2 on t1.id = t2.id where (case  when t1.name='b' then 'case2' when t1.name='a' then 'case1' else NULL
+---------------------------+-------+------+-----------------------------------------------------------------------------------------+
| id                        | count | task | operator info                                                                           |
+---------------------------+-------+------+-----------------------------------------------------------------------------------------+
| Projection_6              | 1.60  | root | test.t1.id, sleep(20)                                                                   |
| └─HashLeftJoin_7          | 1.60  | root | left outer join, inner:TableReader_13, equal:[eq(test.t1.id, test.t2.id)]    -- left outer join           |
|   ├─TableReader_10        | 1.60  | root | data:Selection_9                                                                        |
|   │ └─Selection_9         | 1.60  | cop  | eq(case(eq(test.t1.name, "b"), "case2", eq(test.t1.name, "a"), "case1", NULL), "case1") |
|   │   └─TableScan_8       | 2.00  | cop  | table:t1, range:[-inf,+inf], keep order:false, stats:pseudo                             |
|   └─TableReader_13        | 1.00  | root | data:Selection_12                                                                       |
|     └─Selection_12        | 1.00  | cop  | not(isnull(test.t2.id))                                                                 |
|       └─TableScan_11      | 1.00  | cop  | table:t2, range:[-inf,+inf], keep order:false, stats:pseudo                             |
+---------------------------+-------+------+-----------------------------------------------------------------------------------------+
8 rows in set (0.00 sec)

tidb> select t1.id,sleep(20) from kankan1 t1 left join kankan2 t2 on t1.id = t2.id where (case  when t1.name='b' then 'case2' when t1.name='a' then 'case1' else NULL end) = 'case1';

In session2:

tidb> show processlist; 
+------+------+-----------+------+---------+------+-------+------------------------------------------------------------------------------------------------------+
| Id   | User | Host      | db   | Command | Time | State | Info                                                                                                 |
+------+------+-----------+------+---------+------+-------+------------------------------------------------------------------------------------------------------+
|    1 | root | 127.0.0.1 | test | Query   |   10 | 2     | select t1.id,sleep(20) from kankan1 t1 left join kankan2 t2 on t1.id = t2.id where (case  when t1.na |
|    2 | root | 127.0.0.1 | test | Query   |    0 | 2     | show processlist                                                                                     |
+------+------+-----------+------+---------+------+-------+------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

tidb> explain for connection 1;
+---------------------------+-------+------+------------------------------------------------------------------------------------------------------------------+
| id                        | count | task | operator info                                                                                                    |
+---------------------------+-------+------+------------------------------------------------------------------------------------------------------------------+
| Projection_6              | 1.25  | root | test.t1.id, sleep(20)                                                                                            |
| └─HashLeftJoin_7          | 1.25  | root | inner join, inner:TableReader_14, equal:[eq(test.t1.id, test.t2.id)]      -- inner join                                       |
|   ├─TableReader_11        | 1.60  | root | data:Selection_10                                                                                                |
|   │ └─Selection_10        | 1.60  | cop  | eq(case(eq(test.t1.name, "b"), "case2", eq(test.t1.name, "a"), "case1", NULL), "case1"), not(isnull(test.t1.id)) |
|   │   └─TableScan_9       | 2.00  | cop  | table:t1, range:[-inf,+inf], keep order:false, stats:pseudo                                                      |
|   └─TableReader_14        | 1.00  | root | data:Selection_13                                                                                                |
|     └─Selection_13        | 1.00  | cop  | not(isnull(test.t2.id))                                                                                          |
|       └─TableScan_12      | 1.00  | cop  | table:t2, range:[-inf,+inf], keep order:false, stats:pseudo                                                      |
+---------------------------+-------+------+------------------------------------------------------------------------------------------------------------------+
8 rows in set (0.00 sec)
  1. What did you expect to see?
    The same explain result.

  2. What did you see instead?
    N/A

  3. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
    21d2590ac37bf53e5e687b8a341d50105ddbffe8 in master branch

@XuHuaiyu XuHuaiyu added the type/bug The issue is confirmed as a bug. label Jul 8, 2019
@XuHuaiyu XuHuaiyu self-assigned this Jul 8, 2019
@XuHuaiyu
Copy link
Contributor Author

XuHuaiyu commented Jul 8, 2019

The root cause is that StmtCtx of explain is not set correctly.

@XuHuaiyu
Copy link
Contributor Author

XuHuaiyu commented Jul 8, 2019

related issue:
#11102

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant