pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://www.pingcap.com/tidb-serverless/
https://pingcap.com
Apache License 2.0
36.89k stars 5.81k forks source link

final mode scalar agg function does not push down tiflash, and without warnings #50583

Open SeaRise opened 8 months ago

SeaRise commented 8 months ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

DROP TABLE IF EXISTS c_t2;
CREATE TABLE `c_t2` (
  `c1` int(11) DEFAULT NULL,
  `c2` varchar(50) DEFAULT NULL,
  `c3` varchar(1) NOT NULL DEFAULT 'N',
  `c4` varchar(32) NOT NULL DEFAULT 'sys',
  `c5` varchar(32) NOT NULL DEFAULT 'sys',
  `c6` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `c7` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `c8` bigint(20) NOT NULL DEFAULT '0',
  `c9` varchar(50) DEFAULT NULL
);
ALTER TABLE c_t2 SET TIFLASH REPLICA 1;

set tidb_allow_mpp=1;set tidb_enforce_mpp=1; set tidb_isolation_read_engines='tiflash';
explain
select
    GROUP_CONCAT(
      '"',
      replace(c9, '*', '_'),
      '":',
      c1,
      ''
    )
from
  c_t2;

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

final mode group_concat push down tiflash

3. What did you see instead (Required)

+--------------------------------+----------+--------------+---------------+---------------------------------------------------------------------------------------+
| id                             | estRows  | task         | access object | operator info                                                                         |
+--------------------------------+----------+--------------+---------------+---------------------------------------------------------------------------------------+
| HashAgg_17                     | 1.00     | root         |               | funcs:group_concat(Column#12 separator ",")->Column#11                                |
| └─TableReader_19               | 1.00     | root         |               | MppVersion: 2, data:ExchangeSender_18                                                 |
|   └─ExchangeSender_18          | 1.00     | mpp[tiflash] |               | ExchangeType: PassThrough                                                             |
|     └─HashAgg_9                | 1.00     | mpp[tiflash] |               | funcs:group_concat(""", Column#14, "":", Column#15, "" separator ",")->Column#12      |
|       └─Projection_28          | 10000.00 | mpp[tiflash] |               | replace(test.c_t2.c9, *, _)->Column#14, cast(test.c_t2.c1, var_string(20))->Column#15 |
|         └─TableFullScan_16     | 10000.00 | mpp[tiflash] | table:c_t2    | keep order:false, stats:pseudo                                                        |
+--------------------------------+----------+--------------+---------------+---------------------------------------------------------------------------------------+

4. What is your TiDB version? (Required)

Git Commit Hash: 7ba2330394bcfa1dcd321293c2656604c3a664ab

SeaRise commented 8 months ago

/sig planner

AilinKid commented 7 months ago

old code logic as said here by @Fangzhuhe

image
tidb> explain select sum(c9) from   c_t2;
+--------------------------------+----------+--------------+---------------+----------------------------------------------+
| id                             | estRows  | task         | access object | operator info                                |
+--------------------------------+----------+--------------+---------------+----------------------------------------------+
| HashAgg_22                     | 1.00     | root         |               | funcs:sum(Column#13)->Column#11              |
| └─TableReader_24               | 1.00     | root         |               | MppVersion: 2, data:ExchangeSender_23        |
|   └─ExchangeSender_23          | 1.00     | mpp[tiflash] |               | ExchangeType: PassThrough                    |
|     └─HashAgg_9                | 1.00     | mpp[tiflash] |               | funcs:sum(Column#16)->Column#13              |
|       └─Projection_38          | 10000.00 | mpp[tiflash] |               | cast(test.c_t2.c9, double BINARY)->Column#16 |
|         └─TableFullScan_21     | 10000.00 | mpp[tiflash] | table:c_t2    | keep order:false, stats:pseudo               |
+--------------------------------+----------+--------------+---------------+----------------------------------------------+
6 rows in set (0.00 sec)

Other case is the same, so I want to ask that the support of scalar agg in MPP mode is already done? if so we can lift it here. @SeaRise

AilinKid commented 7 months ago
image
SeaRise commented 7 months ago

ok, maybe it is a feature request instead of a bug...