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

Planner generates wrong 2 phase aggregate plan for TiFlash #34682

Closed
fixdb opened this issue May 16, 2022 · 3 comments · Fixed by #34779
Closed

Planner generates wrong 2 phase aggregate plan for TiFlash #34682

fixdb opened this issue May 16, 2022 · 3 comments · Fixed by #34779
Assignees
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. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 severity/critical sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@fixdb
Copy link
Contributor

fixdb commented May 16, 2022

Bug Report

1. Minimal reproduce step (Required)

create table customer2(c_id bigint primary key);
create table orders2(o_id bigint primary key, c_id bigint);
insert into customer2 values(1),(2),(3),(4),(5);
insert into orders2 values(1,1),(2,1),(3,2),(4,2),(5,2);
alter table customer2 set tiflash replica 1;
alter table orders2 set tiflash replica 1;
set @@tidb_enforce_mpp=1;
set @@tidb_opt_agg_push_down=1;
select count(*) from customer2 c, orders2 o where c.c_id=o.c_id;

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

tidb> select count(*) from customer2 c, orders2 o where c.c_id=o.c_id;
+----------+
| count(*) |
+----------+
|        5 |
+----------+
1 row in set (0.00 sec)

3. What did you see instead (Required)

mysql> select count(*) from customer2 c, orders2 o where c.c_id=o.c_id;
+----------+
| count(*) |
+----------+
|        2 |
+----------+
1 row in set (0.19 sec)

mysql> explain select count(*) from customer2 c, orders2 o where c.c_id=o.c_id;
+--------------------------------------------------+---------+--------------+---------------+-----------------------------------------------------------------------------------------------------------------+
| id                                               | estRows | task         | access object | operator info                                                                                                   |
+--------------------------------------------------+---------+--------------+---------------+-----------------------------------------------------------------------------------------------------------------+
| HashAgg_81                                       | 1.00    | root         |               | funcs:count(Column#14)->Column#4                                                                                |
| └─TableReader_83                                 | 1.00    | root         |               | data:ExchangeSender_82                                                                                          |
|   └─ExchangeSender_82                            | 1.00    | mpp[tiflash] |               | ExchangeType: PassThrough                                                                                       |
|     └─HashAgg_13                                 | 1.00    | mpp[tiflash] |               | funcs:count(Column#5)->Column#14                                                                                |
|       └─HashJoin_80                              | 5.00    | mpp[tiflash] |               | inner join, equal:[eq(test.customer2.c_id, test.orders2.c_id)]                                                  |
|         ├─ExchangeReceiver_43(Build)             | 4.00    | mpp[tiflash] |               |                                                                                                                 |
|         │ └─ExchangeSender_42                    | 4.00    | mpp[tiflash] |               | ExchangeType: Broadcast                                                                                         |
|         │   └─Projection_38                      | 4.00    | mpp[tiflash] |               | Column#5, test.orders2.c_id                                                                                     |
|         │     └─HashAgg_39                       | 4.00    | mpp[tiflash] |               | group by:test.orders2.c_id, funcs:sum(Column#6)->Column#5, funcs:firstrow(test.orders2.c_id)->test.orders2.c_id |
|         │       └─ExchangeReceiver_41            | 4.00    | mpp[tiflash] |               |                                                                                                                 |
|         │         └─ExchangeSender_40            | 4.00    | mpp[tiflash] |               | ExchangeType: HashPartition, Hash Cols: [name: test.orders2.c_id, collate: N/A]                                 |
|         │           └─HashAgg_28                 | 4.00    | mpp[tiflash] |               | group by:test.orders2.c_id, funcs:count(1)->Column#6                                                            |
|         │             └─Selection_37             | 5.00    | mpp[tiflash] |               | not(isnull(test.orders2.c_id))                                                                                  |
|         │               └─TableFullScan_36       | 5.00    | mpp[tiflash] | table:o       | keep order:false, stats:pseudo                                                                                  |
|         └─TableFullScan_26(Probe)                | 5.00    | mpp[tiflash] | table:c       | keep order:false, stats:pseudo                                                                                  |
+--------------------------------------------------+---------+--------------+---------------+-----------------------------------------------------------------------------------------------------------------+
15 rows in set (0.18 sec)

4. What is your TiDB version? (Required)

mysql> select version();
+--------------------------+
| version()                |
+--------------------------+
| 5.7.25-TiDB-v6.1.0-alpha |
+--------------------------+
1 row in set (0.17 sec)
@fixdb fixdb added the type/bug The issue is confirmed as a bug. label May 16, 2022
@seiya-annie seiya-annie added the sig/planner SIG: Planner label May 16, 2022
@ti-chi-bot ti-chi-bot added may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.0 may-affects-6.1 labels May 23, 2022
@jebter jebter added affects-6.1 and removed may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-6.0 may-affects-6.1 labels May 23, 2022
@zanmato1984
Copy link
Contributor

Why is planner bug assigned to me? @jebter

@jebter jebter assigned chrysan and unassigned zanmato1984 May 23, 2022
fixdb added a commit to fixdb/tidb that referenced this issue May 24, 2022
…for TiFlash

When pushing down aggregate past join operator, the planner updates the top
aggregate from CompleteMode to FinalMode. But in MPP, the planner again tries
to split the top aggregate into 2 stage aggregate: 1 partial aggregate on
TiFlash, 1 Final aggregate on TiDB. The newly created partial aggregate will
ignore the partial aggregate result that comes under the join and treats the
data as standard input data, hence causes wrong result. In this patch, we
disable splitting aggregate into multiple stages if the aggregate is in final
mode.

Close pingcap#34682
@jebter jebter 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. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 labels May 26, 2022
@chrysan chrysan removed 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. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. labels Jun 14, 2022
@chrysan chrysan assigned fixdb and unassigned chrysan Jun 14, 2022
@chrysan chrysan 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. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. labels Jun 14, 2022
@chrysan
Copy link
Contributor

chrysan commented Jun 14, 2022

Needs triage and cherry-pick to old versions from v5.0...

fixdb added a commit to fixdb/tidb that referenced this issue Jun 16, 2022
…for TiFlash

When pushing down aggregate past join operator, the planner updates the top
aggregate from CompleteMode to FinalMode. But in MPP, the planner again tries
to split the top aggregate into 2 stage aggregate: 1 partial aggregate on
TiFlash, 1 Final aggregate on TiDB. The newly created partial aggregate will
ignore the partial aggregate result that comes under the join and treats the
data as standard input data, hence causes wrong result. In this patch, we
disable splitting aggregate into multiple stages if the aggregate is in final
mode.

Close pingcap#34682
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. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 severity/critical sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants