The same SQL, tables with the same data volume, different execution plans on two clusters, the cluster with the lower TiDB version has a better execution plan

This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 同一个sql,数据量相同的表,两个集群执行计划不一样,tidb版本低的集群执行计划更好

| username: jiangh

SQL text:

line_code as lineCode,
sum(amount) as amount
join ext on =
join event on = event.rcv_header_id
left join line on
line.rcv_header_id =
ext.order_id = 8405253
and header.rcp_business_type in ('edrwcew')
and event.event_at >= 1669824000000
and event.event_at <= 1672502399999
group by

Execution plan for lower version (2.0):

Execution plan for higher version (5.1.2):

| username: jiangh | Original post link

After collecting some statistics in version 5.1.2, the execution plans on both sides are now the same.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.