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
945 stars 409 forks source link

CastDecimalAsReal blocks pushing down agg #3086

Open fzhedu opened 3 years ago

fzhedu commented 3 years ago
mysql> desc select max(a) from (select id, zxjq * (sum(fzsl)-zqsl) a from t group by id, zqsl,zxjq)tb group by id;
+------------------------------------------+----------+-------------------+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id                                       | estRows  | task              | access object | operator info                                                                                                                                                                        |
+------------------------------------------+----------+-------------------+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| HashAgg_8                                | 8000.00  | root              |               | group by:Column#31, funcs:max(Column#30)->Column#8                                                                                                                                   |
| └─Projection_40                          | 8000.00  | root              |               | mul(zq.t.zxjq, cast(minus(Column#6, cast(zq.t.zqsl, decimal(20,0) BINARY)), double BINARY))->Column#30, zq.t.id                                                                      |
|   └─TableReader_32                       | 8000.00  | root              |               | data:ExchangeSender_31                                                                                                                                                               |
|     └─ExchangeSender_31                  | 8000.00  | batchCop[tiflash] |               | ExchangeType: PassThrough                                                                                                                                                            |
|       └─Projection_27                    | 8000.00  | batchCop[tiflash] |               | Column#6, zq.t.zqsl, zq.t.zxjq, zq.t.id                                                                                                                                              |
|         └─HashAgg_28                     | 8000.00  | batchCop[tiflash] |               | group by:zq.t.id, zq.t.zqsl, zq.t.zxjq, funcs:sum(Column#14)->Column#6, funcs:firstrow(zq.t.zqsl)->zq.t.zqsl, funcs:firstrow(zq.t.zxjq)->zq.t.zxjq, funcs:firstrow(zq.t.id)->zq.t.id |
|           └─ExchangeReceiver_30          | 8000.00  | batchCop[tiflash] |               |                                                                                                                                                                                      |
|             └─ExchangeSender_29          | 8000.00  | batchCop[tiflash] |               | ExchangeType: HashPartition, Hash Cols: [name: zq.t.id, collate: N/A], [name: zq.t.zqsl, collate: N/A], [name: zq.t.zxjq, collate: N/A]                                              |
|               └─HashAgg_13               | 8000.00  | batchCop[tiflash] |               | group by:Column#27, Column#28, Column#29, funcs:sum(Column#26)->Column#14                                                                                                            |
|                 └─Projection_39          | 10000.00 | batchCop[tiflash] |               | cast(zq.t.fzsl, decimal(32,0) BINARY)->Column#26, zq.t.id, zq.t.zqsl, zq.t.zxjq                                                                                                      |
|                   └─TableFullScan_26     | 10000.00 | batchCop[tiflash] | table:t       | keep order:false, stats:pseudo                                                                                                                                                       |
+------------------------------------------+----------+-------------------+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
11 rows in set, 4 warnings (0.00 sec)

mysql> show warnings;
+---------+------+--------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                |
+---------+------+--------------------------------------------------------------------------------------------------------+
| Warning | 1105 | Scalar function 'cast'(signature: CastDecimalAsReal) can not be pushed to tiflash                      |
| Warning | 1105 | Aggregation can not be pushed to tiflash because arguments of AggFunc `max` contains unsupported exprs |
| Warning | 1105 | Scalar function 'cast'(signature: CastDecimalAsReal) can not be pushed to tiflash                      |
| Warning | 1105 | Aggregation can not be pushed to tiflash because arguments of AggFunc `max` contains unsupported exprs |
+---------+------+--------------------------------------------------------------------------------------------------------+
4 rows in set (0.00 sec)

mysql> desc t;
+-------+---------+------+------+---------+-------+
| Field | Type    | Null | Key  | Default | Extra |
+-------+---------+------+------+---------+-------+
| fzsl  | int(11) | YES  |      | NULL    |       |
| zqsl  | int(11) | YES  |      | NULL    |       |
| zxjq  | double  | YES  |      | NULL    |       |
| id    | int(11) | YES  |      | NULL    |       |
+-------+---------+------+------+---------+-------+
4 rows in set (0.00 sec)
CREATE TABLE `t` (
  `fzsl` int(11) DEFAULT NULL,
  `zqsl` int(11) DEFAULT NULL,
  `zxjq` double DEFAULT NULL,
  `id` int(11) DEFAULT NULL
)
alter table t set tiflash replica 1;
fzhedu commented 3 years ago

from oncall-3710