explain.depesz.com

PostgreSQL's explain analyze made readable

Result: 7fni

Settings

Optimization(s) for this plan:

# exclusive inclusive rows x rows loops node
1. 274.018 54,188.455 ↓ 1,805.0 1,805 1

Merge Join (cost=38,159.14..42,792.80 rows=1 width=1,822) (actual time=1,693.342..54,188.455 rows=1,805 loops=1)

  • Merge Cond: (((t1.org_code_oms)::text = (b.fc_mo)::text) AND ((t1.payment_method_code)::text = (b.fc_opl)::text) AND (t1.det = (b.det)::text) AND (t1.care_regimen_code = (b.usl_ok)::text))
  • Join Filter: ((daterange(b.date_b, b.date_e, '[]'::text) @> t1.case_close_date) AND CASE t1.init_goal_id WHEN 19 THEN ((b.c_serv)::text = '1021'::text) ELSE ((b.c_serv)::text = (t1.service_code)::text) END)
  • Rows Removed by Join Filter: 147107
2.          

CTE t1

3. 1.215 9.287 ↑ 6.3 1,805 1

Hash Join (cost=10,354.96..11,150.06 rows=11,305 width=130) (actual time=5.874..9.287 rows=1,805 loops=1)

  • Hash Cond: (g.init_goal_id = i.id)
4. 0.502 8.048 ↑ 6.3 1,805 1

Hash Left Join (cost=10,353.51..10,724.67 rows=11,305 width=126) (actual time=5.837..8.048 rows=1,805 loops=1)

  • Hash Cond: (g.care_regimen_id = c.id)
5. 0.563 7.541 ↑ 6.3 1,805 1

Hash Left Join (cost=10,352.33..10,568.05 rows=11,305 width=126) (actual time=5.828..7.541 rows=1,805 loops=1)

  • Hash Cond: (g.payment_method_id = p.id)
6. 0.782 6.960 ↑ 6.3 1,805 1

Merge Left Join (cost=10,349.36..10,409.64 rows=11,305 width=128) (actual time=5.802..6.960 rows=1,805 loops=1)

  • Merge Cond: (g.org_id = o.org_id)
7. 0.780 5.643 ↑ 6.3 1,805 1

Sort (cost=10,173.33..10,201.60 rows=11,305 width=116) (actual time=5.418..5.643 rows=1,805 loops=1)

  • Sort Key: g.org_id
  • Sort Method: quicksort Memory: 528kB
8. 4.863 4.863 ↑ 6.3 1,805 1

Index Scan using fin_bill_generate_bill_id_idx on fin_bill_generate g (cost=0.43..9,412.24 rows=11,305 width=116) (actual time=0.252..4.863 rows=1,805 loops=1)

  • Index Cond: (bill_id = 791)
  • Filter: ((NOT is_sifted) AND ((region_data ->> 'is_tariff_service'::text))::boolean)
  • Rows Removed by Filter: 2344
9. 0.262 0.535 ↓ 4.7 1,807 1

Sort (cost=176.03..176.98 rows=382 width=16) (actual time=0.378..0.535 rows=1,807 loops=1)

  • Sort Key: o.org_id
  • Sort Method: quicksort Memory: 57kB
10. 0.273 0.273 ↓ 1.8 688 1

Index Scan using fkc6856cb3ec5d17fa on pim_org_code o (cost=0.42..159.64 rows=382 width=16) (actual time=0.013..0.273 rows=688 loops=1)

  • Index Cond: (type_id = 7)
11. 0.010 0.018 ↑ 1.0 43 1

Hash (cost=2.43..2.43 rows=43 width=6) (actual time=0.018..0.018 rows=43 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 10kB
12. 0.008 0.008 ↑ 1.0 43 1

Seq Scan on mc_payment_method p (cost=0.00..2.43 rows=43 width=6) (actual time=0.002..0.008 rows=43 loops=1)

13. 0.003 0.005 ↑ 1.0 8 1

Hash (cost=1.08..1.08 rows=8 width=8) (actual time=0.005..0.005 rows=8 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
14. 0.002 0.002 ↑ 1.0 8 1

Seq Scan on mc_care_regimen c (cost=0.00..1.08 rows=8 width=8) (actual time=0.002..0.002 rows=8 loops=1)

15. 0.011 0.024 ↑ 1.0 20 1

Hash (cost=1.20..1.20 rows=20 width=8) (actual time=0.024..0.024 rows=20 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
16. 0.013 0.013 ↑ 1.0 20 1

Seq Scan on mc_case_init_goal i (cost=0.00..1.20 rows=20 width=8) (actual time=0.006..0.013 rows=20 loops=1)

17. 3.152 13.739 ↑ 6.3 1,805 1

Sort (cost=10,146.69..10,174.95 rows=11,305 width=1,867) (actual time=12.165..13.739 rows=1,805 loops=1)

  • Sort Key: t1.org_code_oms, t1.payment_method_code, t1.det, t1.care_regimen_code
  • Sort Method: quicksort Memory: 302kB
18. 10.587 10.587 ↑ 6.3 1,805 1

CTE Scan on t1 (cost=0.00..226.10 rows=11,305 width=1,867) (actual time=5.878..10.587 rows=1,805 loops=1)

19. 1,487.360 1,640.893 ↓ 1.6 243,175 1

Sort (cost=16,862.39..17,231.51 rows=147,648 width=48) (actual time=1,586.302..1,640.893 rows=243,175 loops=1)

  • Sort Key: b.fc_mo, b.fc_opl, b.det, b.usl_ok
  • Sort Method: external sort Disk: 10136kB
20. 153.533 153.533 ↓ 1.0 147,665 1

Seq Scan on billing_tariff_services b (cost=0.00..4,185.48 rows=147,648 width=48) (actual time=0.004..153.533 rows=147,665 loops=1)

21.          

SubPlan (for Merge Join)

22. 52,259.805 52,259.805 ↓ 3.4 725 1,707

Seq Scan on billing_tariff_services (cost=0.00..5,292.84 rows=215 width=4) (actual time=14.529..30.615 rows=725 loops=1,707)

  • Filter: ((t1.case_open_date >= COALESCE(date_b, '-infinity'::date)) AND (t1.case_open_date <= COALESCE(date_e, '-infinity'::date)) AND ((fc_opl)::text = '28'::text))
  • Rows Removed by Filter: 146940
Planning time : 4.507 ms
Execution time : 54,198.832 ms