重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 584|回复: 0
打印 上一主题 下一主题

如何 查看PG SQL语句执行计划

[复制链接]
跳转到指定楼层
楼主
发表于 2023-8-2 14:54:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 郑全 于 2023-8-2 14:56 编辑

explain
select * from mdc2_mz_cost_view where patientid='60963' and clinicno='2307190246_102840' and hiscode='0';
不执行,执行计划不详细   

explain (buffers true,analyze true,verbose true)
  select * from mdc2_mz_cost_view where patientid='60963' and clinicno='2307190246_102840' and hiscode='0';

实际执行,并产生实际执行的执行计划

下面看看具体的:

# explain
  select * from mdc2_mz_cost_view where patientid='60963' and clinicno='2307190246_102840' and hiscode='0';
QUERY PLAN                                                                                                                                                                                                                                                                     
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Unique  (cost=1250110426.46..1250113863.96 rows=62500 width=701)
   ->  Sort  (cost=1250110426.46..1250110582.71 rows=62500 width=701)
         Sort Key: b."BalanceNo", pb."BillId", pb."BillNo", (CASE a."ChargesCategoryCode" WHEN '5'::text THEN )
         ->  Hash Left Join  (cost=70268.47..1250086005.34 rows=62500 width=701)
               Hash Cond: (o."相关ID" = o2."ID")
               ->  Hash Left Join  (cost=50255.97..61039.72 rows=12500 width=732)
                     Hash Cond: (o."诊疗项目ID" = t."药名ID")
                     ->  Hash Right Join  (cost=30243.47..40583.47 rows=2500 width=694)
                           Hash Cond: ((cc."药品ID")::text = (o."收费细目ID")::text)
                           ->  Foreign Scan on drug_dict cc  (cost=10000.00..20000.00 rows=1000 width=238)
                                 Oracle query: SELECT /*1760ee84eeafd92f*/ r10."药品ID", r10."产地" FROM "ZLHIS"."药品目录" r10
                           ->  Hash  (cost=20237.22..20237.22 rows=500 width=496)
                                 ->  Nested Loop  (cost=10003.52..20237.22 rows=500 width=496)
                                       ->  Nested Loop  (cost=1.27..218.71 rows=1 width=859)
                                             ->  Nested Loop  (cost=0.85..218.11 rows=1 width=880)
                                                   ->  Index Scan using processedbill_patid_idx on "ProcessedBill" pb  (cost=0.42..209.65 rows=1 width=843)
                                                         Index Cond: ("PatId" = '60963'::text)
                                                         Filter: (("PatOriginCode" = '01'::text) AND ("OccurTime" > (now() + '-60 days'::interval))
                                                   ->  Index Scan using balancebill_billid_idx on "BalanceBill" bb  (cost=0.42..8.44 rows=1 width=74)
                                                         Index Cond: ("BillId" = pb."BillId")
                                             ->  Index Scan using "PK_Balanced" on "Balanced" b  (cost=0.42..0.61 rows=1 width=53)
                                                   Index Cond: ("BalanceId" = bb."BalanceId")
                                                   Filter: ("BalanceStatusCode" = '1'::text)
                                       ->  Hash Join  (cost=10002.25..20013.50 rows=500 width=376)
                                             Hash Cond: ((o."ID")::text = a."OrderId")
                                             ->  Foreign Scan on orders o  (cost=10000.00..20000.00 rows=1000 width=108)
                                                   Oracle query: SELECT /*5bdbf33d2da9cbf7*/ r7."ID", r7."相关ID", r7."序号", r7."诊疗类别" FROM "ZLHIS"."病人医嘱记录" r7
                                             ->  Hash  (cost=1.00..1.00 rows=100 width=288)
                                                   ->  Function Scan on json_to_recordset a  (cost=0.00..1.00 rows=100 width=288)
                                                         Filter: ("OrderId" IS NOT NULL)
                     ->  Hash  (cost=20000.00..20000.00 rows=1000 width=78)
                           ->  Foreign Scan on drug_characteristics t  (cost=10000.00..20000.00 rows=1000 width=78)
                                 Oracle query: SELECT /*69b41dd03b52e736*/ r8."药名ID", r8."药品剂型" FROM "ZLHIS"."药品特性" r8
               ->  Hash  (cost=20000.00..20000.00 rows=1000 width=536)
                     ->  Foreign Scan on orders o2  (cost=10000.00..20000.00 rows=1000 width=536)
                           Oracle query: SELECT /*5480e416df50af90*/ r12."ID", r12."医嘱内容" FROM "ZLHIS"."病人医嘱记录" r12
               SubPlan 1
                 ->  Foreign Scan on staff_dict t5  (cost=10000.00..20000.00 rows=1000 width=32)
                       Oracle query: SELECT /*c7dbdd5894bf799d*/ r1."ID", r1."编号" FROM "ZLHIS"."人员表" r1 WHERE (r1."ID" = to_number(:p1, 'fm999999'))
(39 rows)


zlcost=# explain (buffers true,analyze true,verbose true)
  select * from mdc2_mz_cost_view where patientid='60963' and clinicno='2307190246_102840' and hiscode='0';
-----------------------------------------------------------------------------------------
Unique  (cost=1250110426.46..1250113863.96 rows=62500 width=701) (actual time=33223.739..33223.764 rows=10 loops=1)
   Output: '0'::text, pb."PatId",  THEN '2'::text ELSE '1'::text END)
   Buffers: shared hit=50, temp read=11947 written=11947
   ->  Sort  (cost=1250110426.46..1250110582.71 rows=62500 width=701) (actual time=33223.738..33223.751 rows=10 loops=1)
         Output: '0'::text, pb."PatId", THEN '2'::text ELSE '1'::text END)
         Sort Key: b."BalanceNo", pb."BillId", pb."BillNo", THEN '2'::text ELSE '1'::text END)
         Sort Method: quicksort  Memory: 28kB
         Buffers: shared hit=50, temp read=11947 written=11947
         ->  Hash Left Join  (cost=70268.47..1250086005.34 rows=62500 width=701) (actual time=33064.997..33223.651 rows=10 loops=1)
               Output: '0'::text, pb."PatId", ((pb."IdentityNo" || '_'::text) || pb."PatOriginId"), b."BalanceNo", THEN '2'::text ELSE '1'::text END
               Hash Cond: (o."相关ID" = o2."ID")
               Buffers: shared hit=47, temp read=11947 written=11947
               ->  Hash Left Join  (cost=50255.97..61039.72 rows=12500 width=732) (actual time=28331.324..28333.619 rows=10 loops=1)
                     Output: pb."PatId", pb."IdentityNo", pb."PatOriginId", pb."BillId", pb."BillNo", pb."OccurTime", cc."产地"
                     Hash Cond: (o."诊疗项目ID" = t."药名ID")
                     Buffers: shared hit=47
                     ->  Hash Right Join  (cost=30243.47..40583.47 rows=2500 width=694) (actual time=28317.999..28320.283 rows=10 loops=1)
                           Output: pb."PatId", pb."IdentityNo", pb."PatOriginId", pb."BillId", pb."BillNo", pb."OccurT cc."产地"
                           Hash Cond: ((cc."药品ID")::text = (o."收费细目ID")::text)
                           Buffers: shared hit=47
                           ->  Foreign Scan on public.drug_dict cc  (cost=10000.00..20000.00 rows=1000 width=238) (actual time=24.989..37.544 rows=2674 loops=1)
                                 Output: cc."药品ID", cc."药名ID", cc."编码", cc."名称", cc."规格", cc."产地"
                                 Oracle query: SELECT /*1760ee84eeafd92f*/ r10."药品ID", r10."产地" FROM "ZLHIS"."药品目录" r10
                                 Oracle plan: SELECT STATEMENT
                                 Oracle plan:   NESTED LOOPS
                                 Oracle plan:     TABLE ACCESS FULL 收费项目目录  (filter ("I"."类别"='5' OR "I"."类别"='6' OR "I"."类别"='7'))
                                 Oracle plan:     INDEX UNIQUE SCAN 药品规格_PK (condition "I"."ID"="S"."药品ID")
                           ->  Hash  (cost=20237.22..20237.22 rows=500 width=496) (actual time=28282.205..28282.210 rows=10 loops=1)
                                 Output: pb."PatId", pb."IdentityNo", pb."PatOriginId", pb."BillId", pb."BillNo", o."收费细目ID", o."相关ID"
                                 Buckets: 1024  Batches: 1  Memory Usage: 11kB
                                 Buffers: shared hit=47
                                 ->  Nested Loop  (cost=10003.52..20237.22 rows=500 width=496) (actual time=5033.333..28282.180 rows=10 loops=1)
                                       Output: pb."PatId", pb."IdentityNo", pb."PatOriginId", pb."BillId", pb."BillNo", o."诊疗项目ID", o."收费细目ID", o."相关ID"
                                       Buffers: shared hit=47
                                       ->  Nested Loop  (cost=1.27..218.71 rows=1 width=859) (actual time=0.196..0.651 rows=5 loops=1)
                                             Output: pb."PatId", pb."IdentityNo", pb."PatOriginId", pb."BillId", pb."BillNo", pb."OccurTime", b."InsuranceBalanceStatusCode"
                                             Inner Unique: true
                                             Buffers: shared hit=47
                                             ->  Nested Loop  (cost=0.85..218.11 rows=1 width=880) (actual time=0.135..0.466 rows=5 loops=1)
                                                   Output: pb."PatId", pb."IdentityNo", pb."PatOriginId", pb."BillId", pb."BillNo", pb."OccurTime", bb."BalanceId"
                                                   Buffers: shared hit=27
                                                   ->  Index Scan using processedbill_patid_idx on public."ProcessedBill" pb  (cost=0.42..209.65 rows=1 width=843) (actual time=0.077..0.177 rows=5 loops=1)
                                                         Output: pb."BillId", pb."BillNo", pb."OccurTime", pb."OccurOrgId", pb."OccurOrg"
                                                         Index Cond: (pb."PatId" = '60963'::text)
                                                         Filter: ((pb."PatOriginCode" = '01'::text) AND (pb."OccurTime" > (now() + '-60 days'::interval))
                                                         Buffers: shared hit=7
                                                   ->  Index Scan using balancebill_billid_idx on public."BalanceBill" bb  (cost=0.42..8.44 rows=1 width=74) (actual time=0.050..0.054 rows=1 loops=5)
                                                         Output: bb."BalanceBillId", bb."BalanceId", bb."BillId", bb."BalanceBillStatus"
                                                         Index Cond: (bb."BillId" = pb."BillId")
                                                         Buffers: shared hit=20
                                             ->  Index Scan using "PK_Balanced" on public."Balanced" b  (cost=0.42..0.61 rows=1 width=53) (actual time=0.032..0.032 rows=1 loops=5)
                                                   Output: b."BalanceId", b."BalanceTime", b."BalanceDeptId", b."BusinessNote", b."ArrearsBalanceSign", b."IdentityNo"
                                                   Index Cond: (b."BalanceId" = bb."BalanceId")
                                                   Filter: (b."BalanceStatusCode" = '1'::text)
                                                   Buffers: shared hit=20
                                       ->  Hash Join  (cost=10002.25..20013.50 rows=500 width=376) (actual time=4312.882..5656.300 rows=2 loops=5)
                                             Output: a."ChargesCategoryCode", a."ChargesId", a."ChargesName", a."Spec", a."Unit", a."Quantity",o."相关ID"
                                             Hash Cond: ((o."ID")::text = a."OrderId")
                                             ->  Foreign Scan on public.orders o  (cost=10000.00..20000.00 rows=1000 width=108) (actual time=1.029..6835.855 rows=1241680 loops=4)
                                                   Output: o."ID", o."相关ID", o."前提ID", o."病人来源", o."病人ID", o."主页ID"
                                                   Oracle query: SELECT /*5bdbf33d2da9cbf7*/ r7."ID", r7."相关ID", r7."序号", r7."诊疗类别" FROM "ZLHIS"."病人医嘱记录" r7
                                                   Oracle plan: SELECT STATEMENT
                                                   Oracle plan:   TABLE ACCESS FULL 病人医嘱记录
                                             ->  Hash  (cost=1.00..1.00 rows=100 width=288) (actual time=0.044..0.044 rows=2 loops=5)
                                                   Output: a."ChargesCategoryCode", a."ChargesId", a."ChargesName", a."Spec", a."Unit"
                                                   Buckets: 1024  Batches: 1  Memory Usage: 9kB
                                                   ->  Function Scan on pg_catalog.json_to_recordset a  (cost=0.00..1.00 rows=100 width=288) (actual time=0.038..0.039 rows=2 loops=5)
                                                         Output: a."ChargesCategoryCode", a."ChargesId", a."ChargesName", a."Spec", a."Unit", a."Quantity", a."Received", a."Price", a."OrderId"
                                                         Function Call: json_to_recordset(pb."BillContent")
                                                         Filter: (a."OrderId" IS NOT NULL)
                                                         Rows Removed by Filter: 0
                     ->  Hash  (cost=20000.00..20000.00 rows=1000 width=78) (actual time=13.292..13.293 rows=2374 loops=1)
                           Output: t."药品剂型", t."药名ID"
                           Buckets: 4096 (originally 1024)  Batches: 1 (originally 1)  Memory Usage: 150kB
                           ->  Foreign Scan on public.drug_characteristics t  (cost=10000.00..20000.00 rows=1000 width=78) (actual time=4.226..12.726 rows=2374 loops=1)
                                 Output: t."药品剂型", t."药名ID"
                                 Oracle query: SELECT /*69b41dd03b52e736*/ r8."药名ID", r8."药品剂型" FROM "ZLHIS"."药品特性" r8
                                 Oracle plan: SELECT STATEMENT
                                 Oracle plan:   TABLE ACCESS FULL 药品特性
               ->  Hash  (cost=20000.00..20000.00 rows=1000 width=536) (actual time=4730.588..4730.589 rows=1241680 loops=1)
                     Output: o2."医嘱内容", o2."ID"
                     Buckets: 65536 (originally 1024)  Batches: 32 (originally 1)  Memory Usage: 3585kB
                     Buffers: temp written=8351
                     ->  Foreign Scan on public.orders o2  (cost=10000.00..20000.00 rows=1000 width=536) (actual time=0.697..4389.208 rows=1241680 loops=1)
                           Output: o2."医嘱内容", o2."ID"
                           Oracle query: SELECT /*5480e416df50af90*/ r12."ID", r12."医嘱内容" FROM "ZLHIS"."病人医嘱记录" r12
                           Oracle plan: SELECT STATEMENT
                           Oracle plan:   TABLE ACCESS FULL 病人医嘱记录
               SubPlan 1
                 ->  Foreign Scan on public.staff_dict t5  (cost=10000.00..20000.00 rows=1000 width=32) (actual time=0.373..0.379 rows=1 loops=10)
                       Output: (t5."编号")::text
                       Oracle query: SELECT /*c7dbdd5894bf799d*/ r1."ID", r1."编号" FROM "ZLHIS"."人员表" r1 WHERE (r1."ID" = to_number(:p1, 'fm999999'))
                       Oracle plan: SELECT STATEMENT
                       Oracle plan:   TABLE ACCESS BY INDEX ROWID 人员表
                       Oracle plan:     INDEX UNIQUE SCAN 人员表_PK (condition "R1"."ID"=TO_NUMBER(:P1,''))
Planning:
   Buffers: shared hit=49
Planning Time: 5.840 ms
Execution Time: 33224.037 ms
(99 rows)




分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-5-18 15:29 , Processed in 0.089083 second(s), 19 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表