V4.0.13
我们有个sql需要全局排序,但是局部先排序下推不到tikv/tiflash,于是我们改了sql,发现疑似是个bug:
原先sql,直接把tidb 跑崩了:
SELECT doc_id,pub_code,MAX(pub_time) AS pub_time, MAX(IF(like_cnt IS NULL, 0, like_cnt) + IF(collect_cnt IS NULL, 0, collect_cnt)
- IF(forward_cnt IS NULL, 0, forward_cnt) + IF(reply_cnt IS NULL, 0, reply_cnt)) AS engagement FROM bdp.fact_1218
WHERE pub_code = ‘bg_m_sinacn’
GROUP BY doc_id, pub_code
ORDER BY DESC
修改后,先取top 1w,因为这个可以下推,很快:
SELECT doc_id,pub_code, pub_time, (IF(like_cnt IS NULL, 0, like_cnt) + IF(collect_cnt IS NULL, 0, collect_cnt)
- IF(forward_cnt IS NULL, 0, forward_cnt) + IF(reply_cnt IS NULL, 0, reply_cnt)) AS engagement
FROM bdp.fact_1218 WHERE pub_code = ‘bg_m_sinacn’ ORDER BY engagement DESC LIMIT 10000
然后我们对这个结果再group by order by limit就有问题了: