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

MPP plan is not correct #30980

Closed
windtalker opened this issue Dec 23, 2021 · 2 comments · Fixed by #28067
Closed

MPP plan is not correct #30980

windtalker opened this issue Dec 23, 2021 · 2 comments · Fixed by #28067
Labels
affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. fixes-5.3.0 This bug is fixed at 5.3.0 type/bug The issue is confirmed as a bug.

Comments

@windtalker
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

mysql> create table t1(id int, v1 decimal(20,2), v2 decimal(20,2));
Query OK, 0 rows affected (0.14 sec)
mysql> create table t2(id int, v1 decimal(10,2), v2 decimal(10,2));                                                                                                                                
Query OK, 0 rows affected (0.07 sec)

mysql> create table t3(id int, v1 decimal(10,2), v2 decimal(10,2))
    -> ;
Query OK, 0 rows affected (0.09 sec)

mysql> insert into t1 values(1,1,1),(2,2,2);
Query OK, 2 rows affected (0.02 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> insert into t2 values(1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5),(6,6,6),(7,7,7),(8,8,8);
Query OK, 8 rows affected (0.02 sec)
Records: 8  Duplicates: 0  Warnings: 0

mysql> insert into t3 values(1,1,1);
Query OK, 1 row affected (0.01 sec)

mysql> analyze table t1;
Query OK, 0 rows affected (0.14 sec)

mysql> analyze table t2;
Query OK, 0 rows affected (0.14 sec)

mysql> analyze table t3;
Query OK, 0 rows affected (0.05 sec)
mysql> alter table t1 set tiflash replica 1;
Query OK, 0 rows affected (0.12 sec)

mysql> alter table t2 set tiflash replica 1;                                                                                                                                                       
Query OK, 0 rows affected (0.11 sec)

mysql> alter table t3 set tiflash replica 1;                                                                                                                                                       
Query OK, 0 rows affected (0.08 sec)

mysql> set @@session.tidb_broadcast_join_threshold_size = 0;
Query OK, 0 rows affected (0.02 sec)

mysql> explain format = 'brief' select count(*), t2.v1, t2.v2 from t1 left join t2 on t1.v1 = t2.v1 and t1.v2 = t2.v2 group by t2.v1, t2.v2;
+---------------------------------------+---------+-------------------+---------------+------------------------------------------------------------------------------------------------------------
-------------------------------+
| id                                    | estRows | task              | access object | operator info                                                                                              
                               |
+---------------------------------------+---------+-------------------+---------------+------------------------------------------------------------------------------------------------------------
-------------------------------+
| TableReader                           | 2.00    | root              |               | data:ExchangeSender                                                                                        
                               |
| └─ExchangeSender                      | 2.00    | batchCop[tiflash] |               | ExchangeType: PassThrough                                                                                  
                               |
|   └─Projection                        | 2.00    | batchCop[tiflash] |               | Column#9, test.t2.v1, test.t2.v2                                                                           
                               |
|     └─HashAgg                         | 2.00    | batchCop[tiflash] |               | group by:test.t2.v1, test.t2.v2, funcs:count(1)->Column#9, funcs:firstrow(test.t2.v1)->test.t2.v1, funcs:fi
rstrow(test.t2.v2)->test.t2.v2 |
|       └─HashJoin                      | 2.00    | batchCop[tiflash] |               | left outer join, equal:[eq(test.t1.v1, test.t2.v1) eq(test.t1.v2, test.t2.v2)]                             
                               |
|         ├─ExchangeReceiver(Build)     | 8.00    | batchCop[tiflash] |               |                                                                                                            
                               |
|         │ └─ExchangeSender            | 8.00    | batchCop[tiflash] |               | ExchangeType: HashPartition, Hash Cols: Column#12, Column#13                                               
                               |
|         │   └─Projection              | 8.00    | batchCop[tiflash] |               | test.t2.v1, test.t2.v2, cast(test.t2.v1, decimal(20,2))->Column#12, cast(test.t2.v2, decimal(20,2))->Column
#13                            |
|         │     └─Selection             | 8.00    | batchCop[tiflash] |               | not(isnull(test.t2.v1)), not(isnull(test.t2.v2))                                                           
                               |
|         │       └─TableFullScan       | 8.00    | batchCop[tiflash] | table:t2      | keep order:false                                                                                           
                               |
|         └─ExchangeReceiver(Probe)     | 2.00    | batchCop[tiflash] |               |                                                                                                            
                               |
|           └─ExchangeSender            | 2.00    | batchCop[tiflash] |               | ExchangeType: HashPartition, Hash Cols: test.t1.v1, test.t1.v2                                             
                               |
|             └─TableFullScan           | 2.00    | batchCop[tiflash] | table:t1      | keep order:false                                                                                           
                               |
+---------------------------------------+---------+-------------------+---------------+------------------------------------------------------------------------------------------------------------
-------------------------------+
13 rows in set (0.01 sec)

2. What did you expect to see? (Required)

Here is a ExchangeSender/ExchangeReceiver after HashJoin. Because group by column comes from the inner table of a outer join, and it will generate null values if join not matched.

3. What did you see instead (Required)

No ExchangeSender/ExchangeReceiver after HashJoin

4. What is your TiDB version? (Required)

[email protected]

@windtalker windtalker added the type/bug The issue is confirmed as a bug. label Dec 23, 2021
@XuHuaiyu
Copy link
Contributor

Fixed by #28067

@github-actions
Copy link

Please check whether the issue should be labeled with 'affects-x.y' or 'fixes-x.y.z', and then remove 'needs-more-info' label.

@windtalker windtalker added affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. fixes-5.3.0 This bug is fixed at 5.3.0 and removed needs-more-info labels Dec 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. fixes-5.3.0 This bug is fixed at 5.3.0 type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants