KingbaseES 如何查看应用执行的SQL的执行计划
通过explain ,我们可以获取特定SQL 的执行计划。但对于同一条SQL,不同的变量、不同的系统负荷,其执行计划可能不同。我们要如何取得SQL执行时间点的执行计划?KingbaseES 提供了 auto_explain 扩展插件,可以自动跟踪SQL执行计划。
1、设置参数
设置参数:
1 | shared_preload_libraries = 'auto_explain' <br>auto_explain.log_min_duration = 1000 |
auto_explain.log_min_duration 是最短语句执行时间(以毫秒为单位),将此设置为0 将记录所有计划。-1(默认)禁用计划记录。
2、查看SQL 执行计划
1 2 3 4 5 6 7 8 9 10 | 2021 - 08 - 30 17 : 35 : 06.797 CST [ 113562 ] LOG: duration: 0.010 ms plan: Query Text: select * from t1,t2 where t1.id1=t2.id2; Merge Join (cost= 166.75 .. 280.75 rows= 7200 width= 80 ) Merge Cond: (t1.id1 = t2.id2) -> Sort (cost= 83.37 .. 86.37 rows= 1200 width= 40 ) Sort Key: t1.id1 -> Seq Scan on t1 (cost= 0.00 .. 22.00 rows= 1200 width= 40 ) -> Sort (cost= 83.37 .. 86.37 rows= 1200 width= 40 ) Sort Key: t2.id2 -> Seq Scan on t2 (cost= 0.00 .. 22.00 rows= 1200 width= 40 ) |
3、explain analyze
设置参数 auto_explain.log_analyze=on , 相当于 explain analyze :
1 2 3 4 5 6 7 8 9 10 11 | 2021 - 08 - 30 19 : 55 : 09.506 CST [ 121850 ] LOG: duration: 0.041 ms plan: Query Text: select * from t1,t2 where t1.id1=t2.id2; Merge Join (cost= 166.75 .. 280.75 rows= 7200 width= 80 ) (actual time= 0.037 .. 0.038 rows= 0 loops= 1 ) Merge Cond: (t1.id1 = t2.id2) -> Sort (cost= 83.37 .. 86.37 rows= 1200 width= 40 ) (actual time= 0.035 .. 0.036 rows= 0 loops= 1 ) Sort Key: t1.id1 Sort Method: quicksort Memory: 25kB -> Seq Scan on t1 (cost= 0.00 .. 22.00 rows= 1200 width= 40 ) (actual time= 0.002 .. 0.002 rows= 0 loops= 1 ) -> Sort (cost= 83.37 .. 86.37 rows= 1200 width= 40 ) (never executed) Sort Key: t2.id2 -> Seq Scan on t2 (cost= 0.00 .. 22.00 rows= 1200 width= 40 ) (never executed) |
KINGBASE研究院
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!