【 TiDB 使用环境】生产环境
【 TiDB 版本】v5.0.4, 相关表已开启TiFlash并启用MPP模式
【遇到的问题】
执行SQL:
explain select DATE_FORMAT(CREATED_AT,'%Y-%m') as ORDER_MONTH, count(1) FROM tbl_order GROUP BY ORDER_MONTH;
得到的执行计划如下:
Projection_4, 66101793.52, root, , date_format(tbl_order.created_at, %Y-%m)->Column#54, Column#53
└─TableReader_27, 66101793.52, root, , data:ExchangeSender_26
└─ExchangeSender_26, 66101793.52, batchCop[tiflash], , ExchangeType: PassThrough
└─Projection_22, 66101793.52, batchCop[tiflash], , Column#53, tbl_order.created_at
└─HashAgg_23, 66101793.52, batchCop[tiflash], , group by:Column#59, funcs:sum(Column#60)->Column#53, funcs:firstrow(Column#61)->tbl_order.created_at
└─ExchangeReceiver_25, 66101793.52, batchCop[tiflash], ,
└─ExchangeSender_24, 66101793.52, batchCop[tiflash], , ExchangeType: HashPartition, Hash Cols: Column#59
└─HashAgg_8, 66101793.52, batchCop[tiflash], , group by:Column#66, funcs:count(1)->Column#60, funcs:firstrow(Column#65)->Column#61
└─Projection_31, 177472581.00, batchCop[tiflash], , tbl_order.created_at, date_format(tbl_order.created_at, %Y-%m)->Column#66
└─TableFullScan_21, 177472581.00, batchCop[tiflash], table:tbl_order, keep order:false
只统计一两年的每月汇总数据, 返回TiDB Server结果集行数应该在几十行, 但现在在TiDB Server上还会处理66101793.52行.
【复现路径】
【问题现象及影响】 TiDB Server处理行数较多, 与预期不符.
若提问为性能优化、故障排查类问题,请下载脚本运行。终端输出的打印结果,请务必全选并复制粘贴上传。