[未完待续]explain sql解析器

7 篇文章 0 订阅
4 篇文章 0 订阅

是否使用索引:

gp=# explain select cjbh, jjbh, sfxq, sfsjsx, bccljg, cljgnr, spsj, zbld, ldclsj from jcj_cjxx_r where jjbh='20010015';
                                         QUERY PLAN                                         
--------------------------------------------------------------------------------------------
 Gather Motion 1:1  (slice1; segments: 1)  (cost=0.00..285.60 rows=1 width=122)
   ->  Index Scan using jcj_cjxx_r_pkey on jcj_cjxx_r  (cost=0.00..285.60 rows=1 width=122)
         Index Cond: jjbh::text = '20010015'::text
 Optimizer status: legacy query optimizer
(4 rows)

Time: 0.981 ms
gp=# explain select cjbh, jjbh, sfxq, sfsjsx, bccljg, cljgnr, spsj, zbld, ldclsj from jcj_cjxx_r where zbld='20010015';
                                      QUERY PLAN                                      
--------------------------------------------------------------------------------------
 Gather Motion 2:1  (slice1; segments: 2)  (cost=0.00..3918480.50 rows=197 width=122)
   ->  Seq Scan on jcj_cjxx_r  (cost=0.00..3918480.50 rows=99 width=122)
         Filter: zbld = '20010015'::bpchar
 Optimizer status: legacy query optimizer
(4 rows)

Time: 0.641 ms

下面这两个查询计划,一个是PQO打开,使用了全表扫描,一个是PQO关闭,使用了seq scan

                                                      QUERY PLAN                                                      
----------------------------------------------------------------------------------------------------------------------
 Limit  (cost=0.00..431.00 rows=1 width=274)
   ->  Gather Motion 2:1  (slice1; segments: 2)  (cost=0.00..431.00 rows=1 width=274)
         ->  Result  (cost=0.00..431.00 rows=1 width=274)
               ->  Table Scan on dma_i3_czrk_jbxx_a  (cost=0.00..431.00 rows=1 width=274)
                     Filter: gmsfzhm::text = '150424196710262754'::text OR gmsfzhm::text = '610623193712283251'::text
 Settings:  optimizer=on
 Optimizer status: PQO version 1.625
(7 rows)

                                                      QUERY PLAN                                                      
----------------------------------------------------------------------------------------------------------------------
 Limit  (cost=0.00..1.03 rows=1 width=274)
   ->  Gather Motion 2:1  (slice1; segments: 2)  (cost=0.00..1.03 rows=1 width=274)
         ->  Limit  (cost=0.00..1.01 rows=1 width=274)
               ->  Seq Scan on dma_i3_czrk_jbxx_a  (cost=0.00..1.01 rows=1 width=274)
                     Filter: gmsfzhm::text = '150424196710262754'::text OR gmsfzhm::text = '610623193712283251'::text
 Settings:  optimizer=off
 Optimizer status: legacy query optimizer
(7 rows)

下面是用用了index scan

                                              QUERY PLAN                                              
------------------------------------------------------------------------------------------------------
 Limit  (cost=0.00..3.00 rows=1 width=274)
   ->  Gather Motion 2:1  (slice1; segments: 2)  (cost=0.00..3.00 rows=1 width=274)
         ->  Index Scan using index_gmsfzhm on dma_i3_czrk_jbxx_a  (cost=0.00..3.00 rows=1 width=274)
               Index Cond: gmsfzhm::text = '150424196710262754'::text
 Settings:  optimizer=on
 Optimizer status: PQO version 1.625
(6 rows)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值