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 results executing streamAgg with order by #17325

Closed
SunRunAway opened this issue May 20, 2020 · 3 comments · Fixed by #17338
Closed

wrong results executing streamAgg with order by #17325

SunRunAway opened this issue May 20, 2020 · 3 comments · Fixed by #17338
Assignees
Labels
priority/P1 The issue has P1 priority. severity/critical sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Milestone

Comments

@SunRunAway
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

mysql> drop table t;
Query OK, 0 rows affected (0.19 sec)

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

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

mysql> select /*+ hash_agg() */ count(*) c from t group by a order by c  limit 1;
+---+
| c |
+---+
| 1 |
+---+
1 row in set (0.00 sec)

mysql> select /*+ stream_agg() */ count(*) c from t group by a order by c  limit 1;
+---+
| c |
+---+
| 2 |
+---+
1 row in set (0.00 sec)

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

mysql> select /*+ stream_agg() */ count(*) c from t group by a order by c  limit 1;
+---+
| c |
+---+
| 1 |
+---+
1 row in set (0.00 sec)

3. What did you see instead (Required)

mysql> select /*+ stream_agg() */ count(*) c from t group by a order by c  limit 1;
+---+
| c |
+---+
| 2 |
+---+
1 row in set (0.00 sec)

4. Affected version (Required)

master, do not know whether other versions are affected.

5. Root Cause Analysis

Shoud use TopN but not Limit here.

mysql> desc select /*+ stream_agg() */ count(*) c from t group by a order by c  limit 1;
+------------------------------+---------+-----------+---------------+---------------------------------------------+
| id                           | estRows | task      | access object | operator info                               |
+------------------------------+---------+-----------+---------------+---------------------------------------------+
| Limit_13                     | 1.00    | root      |               | offset:0, count:1                           |
| └─StreamAgg_26               | 1.00    | root      |               | group by:test.t.a, funcs:count(1)->Column#3 |
|   └─Sort_31                  | 1.25    | root      |               | test.t.a                                    |
|     └─TableReader_30         | 1.25    | root      |               | data:TableFullScan_29                       |
|       └─TableFullScan_29     | 1.25    | cop[tikv] | table:t       | keep order:false, stats:pseudo              |
+------------------------------+---------+-----------+---------------+---------------------------------------------+
5 rows in set (0.00 sec)
@SunRunAway SunRunAway added type/bug The issue is confirmed as a bug. sig/planner SIG: Planner labels May 20, 2020
@zz-jason zz-jason added priority/P1 The issue has P1 priority. severity/critical labels May 21, 2020
@SunRunAway
Copy link
Contributor Author

still get wrong results without LIMIT

mysql> select /*+ hash_agg() */ count(*) c from t group by a order by c;
+---+
| c |
+---+
| 1 |
| 2 |
+---+
2 rows in set (0.00 sec)

mysql> select /*+ stream_agg() */ count(*) c from t group by a order by c;
+---+
| c |
+---+
| 2 |
| 1 |
+---+
2 rows in set (0.00 sec)

@SunRunAway SunRunAway changed the title wrong results executing streamAgg with order by and limit wrong results executing streamAgg with order by May 21, 2020
@eurekaka
Copy link
Contributor

RC: getEnforcedStreamAggs didn't check the required order property from parent.

@ChenPeng2013
Copy link
Contributor

verified on
master: v4.0.0-beta.2-632-g6c305e2a4
release-4.0: v4.0.0-66-gcf781a347
release-3.1: v3.1.2-31-g11cff9007

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/P1 The issue has P1 priority. 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.

4 participants