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

Shouldn't push down the topN when the result for the order by item is uncertain #37986

Closed
Reminiscent opened this issue Sep 20, 2022 · 1 comment · Fixed by #53362 · May be fixed by #37996
Closed

Shouldn't push down the topN when the result for the order by item is uncertain #37986

Reminiscent opened this issue Sep 20, 2022 · 1 comment · Fixed by #53362 · May be fixed by #37996

Comments

@Reminiscent
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

drop table if exists t3;
CREATE TABLE t3(c0 INT, primary key(c0));
insert into t3 values(1), (2), (3), (4), (5);
SELECT v2.c0 FROM (select rand() as c0 from t3) v2 order by v2.c0 limit 100;

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

The result should be ordered.

mysql> SELECT v2.c0 FROM (select rand() as c0 from t3) v2 order by v2.c0 limit 100;
+---------------------+
| c0                  |
+---------------------+
| 0.10052517065827285 |
|  0.7717371729870673 |
|  0.8531838886935114 |
|   0.883147331777166 |
|  0.9643439622263833 |
+---------------------+
5 rows in set (0.00 sec)

3. What did you see instead (Required)

The result is not ordered.

mysql> SELECT v2.c0 FROM (select rand() as c0 from t3) v2 order by v2.c0 limit 100;
+--------------------+
| c0                 |
+--------------------+
| 0.3638526968321322 |
| 0.3650706674578326 |
| 0.7337952775264115 |
| 0.5737644159922045 |
| 0.6674362781154329 |
+--------------------+
5 rows in set (0.00 sec)
mysql> explain SELECT v2.c0 FROM (select rand() as c0 from t3) v2 order by v2.c0 limit 2;
+--------------------------------+----------+-----------+---------------+--------------------------------+
| id                             | estRows  | task      | access object | operator info                  |
+--------------------------------+----------+-----------+---------------+--------------------------------+
| Projection_7                   | 2.00     | root      |               | rand()->Column#2               |
| └─Projection_13                | 2.00     | root      |               | test.t3.c0                     |
|   └─TopN_8                     | 2.00     | root      |               | Column#3, offset:0, count:2    |
|     └─Projection_14            | 10000.00 | root      |               | test.t3.c0, rand()->Column#3   |
|       └─TableReader_12         | 10000.00 | root      |               | data:TableFullScan_11          |
|         └─TableFullScan_11     | 10000.00 | cop[tikv] | table:t3      | keep order:false, stats:pseudo |
+--------------------------------+----------+-----------+---------------+--------------------------------+
6 rows in set (0.00 sec)

4. What is your TiDB version? (Required)

latest master

@Reminiscent Reminiscent added type/bug The issue is confirmed as a bug. sig/planner SIG: Planner labels Sep 20, 2022
@Reminiscent Reminiscent self-assigned this Sep 20, 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 may-affects-6.2 may-affects-6.3 labels Sep 21, 2022
@Reminiscent Reminiscent 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. 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 may-affects-6.2 may-affects-6.3 labels Sep 21, 2022
@qw4990 qw4990 assigned qw4990 and unassigned Reminiscent May 8, 2024
@qw4990 qw4990 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. affects-6.0 affects-6.1 affects-6.2 affects-6.3 affects-6.4 affects-6.6 affects-7.0 labels May 17, 2024
ti-chi-bot bot pushed a commit that referenced this issue May 20, 2024
terry1purcell pushed a commit to terry1purcell/tidb that referenced this issue May 20, 2024
ti-chi-bot bot pushed a commit that referenced this issue May 21, 2024
RidRisR pushed a commit to RidRisR/tidb that referenced this issue May 23, 2024
ti-chi-bot bot pushed a commit that referenced this issue Jun 10, 2024
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this issue Jul 31, 2024
ti-chi-bot bot pushed a commit that referenced this issue Jul 31, 2024
ti-chi-bot bot pushed a commit that referenced this issue Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment