KingbaseES 如何查看应用执行的SQL的执行计划

通过explain ,我们可以获取特定SQL 的执行计划。但对于同一条SQL,不同的变量、不同的系统负荷,其执行计划可能不同。我们要如何取得SQL执行时间点的执行计划?KingbaseES 提供了 auto_explain 扩展插件,可以自动跟踪SQL执行计划。

1、设置参数

设置参数:

shared_preload_libraries = 'auto_explain'
auto_explain.log_min_duration = 1000

auto_explain.log_min_duration 是最短语句执行时间(以毫秒为单位),将此设置为0 将记录所有计划。-1(默认)禁用计划记录。

2、查看SQL 执行计划

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 : 

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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值