pingcap / tiflash

The analytical engine for TiDB and TiDB Cloud. Try free: https://tidbcloud.com/free-trial
https://docs.pingcap.com/tidb/stable/tiflash-overview
Apache License 2.0
941 stars 409 forks source link

MPP dispatch tasks error with TopN #1929

Open leiysky opened 3 years ago

leiysky commented 3 years ago

Minimal reproduce:

create table t (a int); -- create any table
alter table t set tiflash replica 1;
set tidb_allow_mpp=2; -- enforce MPP

select cot(0) as field from t where a = 1 order by field limit 1;
ERROR 1105 (HY000): DB::TiFlashException: TopN executor without order by exprs

The perquisite of this issue:

  1. Projection has a constant expression that cannot be folded(may throw error during execution, e.g. cot(0))
  2. Query will be run in MPP mode
  3. Query has a TopN executor which will order by the expression mentioned in 1
fzhedu commented 3 years ago
mysql> desc select cot(0) as field from t where a = 1 order by field limit 1;
+--------------------------------+---------+--------------+---------------+--------------------------------+
| id                             | estRows | task         | access object | operator info                  |
+--------------------------------+---------+--------------+---------------+--------------------------------+
| Projection_7                   | 1.00    | root         |               | cot(0)->Column#3               |
| └─Limit_12                     | 1.00    | root         |               | offset:0, count:1              |
|   └─TableReader_30             | 1.00    | root         |               | data:Limit_29                  |
|     └─Limit_29                 | 1.00    | cop[tiflash] |               | offset:0, count:1              |
|       └─Selection_28           | 1.00    | cop[tiflash] |               | eq(topn.t.a, 1)                |
|         └─TableFullScan_27     | 1000.00 | cop[tiflash] | table:t       | keep order:false, stats:pseudo |
+--------------------------------+---------+--------------+---------------+--------------------------------+
6 rows in set (0.06 sec)

mysql>  select cot(0) as field from t where a = 1 order by field limit 1;
Empty set (0.11 sec)

cannot reproduce,may be fixed.

leiysky commented 3 years ago

image

@fzhedu I can still reproduce this with latest nightly.

leiysky commented 3 years ago
MySQL [test]> select cot(0) as field from t where a = 1 order by field limit 1;
ERROR 1105 (HY000): DB::TiFlashException: TopN executor without order by exprs
MySQL [test]> explain select cot(0) as field from t where a = 1 order by field limit 1;
+----------------------------------+----------+-------------------+---------------+--------------------------------+
| id                               | estRows  | task              | access object | operator info                  |
+----------------------------------+----------+-------------------+---------------+--------------------------------+
| Projection_7                     | 1.00     | root              |               | cot(0)->Column#3               |
| └─TopN_11                        | 1.00     | root              |               | , offset:0, count:1            |
|   └─TableReader_31               | 1.00     | root              |               | data:ExchangeSender_30         |
|     └─ExchangeSender_30          | 1.00     | batchCop[tiflash] |               | ExchangeType: PassThrough      |
|       └─TopN_29                  | 1.00     | batchCop[tiflash] |               | , offset:0, count:1            |
|         └─Selection_28           | 10.00    | batchCop[tiflash] |               | eq(test.t.a, 1)                |
|           └─TableFullScan_27     | 10000.00 | batchCop[tiflash] | table:t       | keep order:false, stats:pseudo |
+----------------------------------+----------+-------------------+---------------+--------------------------------+
7 rows in set (0.001 sec)

MySQL [test]> select tidb_version();
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                                            |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v5.2.0-alpha-179-ga0b97b0c9
Edition: Community
Git Commit Hash: a0b97b0c962de646f05f42f67ca7d53d630eb9ad
Git Branch: master
UTC Build Time: 2021-06-29 08:12:37
GoVersion: go1.16.4
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)

With the latest nightly, I get a different error message.