TopN 转换成 Limit 后慢很多

【 TiDB 使用环境】

【概述】 场景 + 问题概述
同样的两条sql,查了一张分区表,有分页和排序操作,一条sql:select * from laiye_3rd_info.tbl_checkin_followers_partion where follower_id = 23129203 and event_id = 1 and stop = 0 and id > 0 order by id limit 2001;
执行结果如下:
image
image
image

另一条sql:select * from laiye_3rd_info.tbl_checkin_followers_partion where follower_id = 20775243 and event_id = 1 and stop = 0 and id > 0 order by id limit 2001;
执行计划如下:
image
image
image

[图片太宽没法截完整的图,见谅]
三个问题:
1、两条sql查到的结果都是几十条,为啥sql1里的TopN下还套着一个TopN
2、sql1里其他分区都是TopN,为啥有一个分区是Limit(主要耗时)
3、sql1里estRows和actRows相差太大是怎么回事

【背景】 做过哪些操作

【现象】 业务和数据库现象

【问题】 当前遇到的问题

【业务影响】
业务查询慢
【TiDB 版本】
v4.0.14
【应用软件及版本】

【附件】 相关日志及配置信息

  • TiUP Cluster Display 信息
  • TiUP CLuster Edit config 信息

监控(https://metricstool.pingcap.com/)

  • TiDB-Overview Grafana监控
  • TiDB Grafana 监控
  • TiKV Grafana 监控
  • PD Grafana 监控
  • 对应模块日志(包含问题前后 1 小时日志)

手动收集统计信息后再试试

1 个赞

对比起来是多了个Projection,这些数据跨Region了吗?

1 个赞

该主题在最后一个回复创建后60天后自动关闭。不再允许新的回复。