explain.depesz.com

PostgreSQL's explain analyze made readable

Result: RQrH

Settings
# exclusive inclusive rows x rows loops node
1. 82.922 91,276.310 ↓ 0.0 0 1

Insert on billing_mv (cost=168,427.90..168,427.92 rows=1 width=4,250) (actual time=91,276.310..91,276.310 rows=0 loops=1)

2.          

CTE teste

3. 12.734 91,190.823 ↓ 245.0 245 1

Nested Loop Left Join (cost=80,455.24..168,427.89 rows=1 width=1,856) (actual time=2,858.902..91,190.823 rows=245 loops=1)

4. 1.330 91,178.089 ↓ 245.0 245 1

Nested Loop Left Join (cost=80,454.82..168,421.25 rows=1 width=1,528) (actual time=2,858.849..91,178.089 rows=245 loops=1)

5. 2,791.546 91,176.269 ↓ 245.0 245 1

Nested Loop Left Join (cost=80,454.55..168,420.94 rows=1 width=1,528) (actual time=2,858.840..91,176.269 rows=245 loops=1)

  • Join Filter: (thhp.treatment_id = t.treatment_id)
  • Rows Removed by Join Filter: 35061415
6. 0.856 2,530.598 ↓ 245.0 245 1

Nested Loop Left Join (cost=51,951.98..129,300.46 rows=1 width=1,423) (actual time=2,325.175..2,530.598 rows=245 loops=1)

7. 0.853 2,528.517 ↓ 245.0 245 1

Nested Loop Left Join (cost=51,951.70..129,298.09 rows=1 width=1,418) (actual time=2,325.168..2,528.517 rows=245 loops=1)

8. 0.875 2,526.684 ↓ 245.0 245 1

Nested Loop Left Join (cost=51,951.28..129,294.73 rows=1 width=1,396) (actual time=2,325.161..2,526.684 rows=245 loops=1)

9. 0.760 2,524.584 ↓ 245.0 245 1

Nested Loop Left Join (cost=51,951.00..129,293.52 rows=1 width=1,392) (actual time=2,325.153..2,524.584 rows=245 loops=1)

10. 1.035 2,522.844 ↓ 245.0 245 1

Nested Loop Left Join (cost=51,950.86..129,293.10 rows=1 width=1,360) (actual time=2,325.145..2,522.844 rows=245 loops=1)

11. 1.049 2,520.094 ↓ 245.0 245 1

Nested Loop Left Join (cost=51,950.44..129,285.31 rows=1 width=1,348) (actual time=2,325.135..2,520.094 rows=245 loops=1)

12. 0.867 2,518.310 ↓ 245.0 245 1

Nested Loop Left Join (cost=51,950.29..129,285.00 rows=1 width=1,329) (actual time=2,325.128..2,518.310 rows=245 loops=1)

13. 0.949 2,516.463 ↓ 245.0 245 1

Nested Loop Left Join (cost=51,950.15..129,284.73 rows=1 width=1,310) (actual time=2,325.121..2,516.463 rows=245 loops=1)

14. 1.008 2,514.534 ↓ 245.0 245 1

Nested Loop Left Join (cost=51,949.74..129,278.24 rows=1 width=1,288) (actual time=2,325.115..2,514.534 rows=245 loops=1)

15. 0.908 2,512.301 ↓ 245.0 245 1

Nested Loop Left Join (cost=51,949.46..129,277.44 rows=1 width=1,284) (actual time=2,325.106..2,512.301 rows=245 loops=1)

16. 0.871 2,509.678 ↓ 245.0 245 1

Nested Loop Left Join (cost=51,949.05..129,276.93 rows=1 width=1,262) (actual time=2,325.095..2,509.678 rows=245 loops=1)

17. 0.911 2,507.092 ↓ 245.0 245 1

Nested Loop Left Join (cost=51,948.63..129,269.36 rows=1 width=1,258) (actual time=2,325.085..2,507.092 rows=245 loops=1)

18. 1.049 2,499.321 ↓ 245.0 245 1

Nested Loop Left Join (cost=51,947.65..129,268.14 rows=1 width=1,128) (actual time=2,325.057..2,499.321 rows=245 loops=1)

19. 1.731 2,496.557 ↓ 245.0 245 1

Nested Loop (cost=51,947.37..129,267.67 rows=1 width=1,073) (actual time=2,325.033..2,496.557 rows=245 loops=1)

20. 1.075 2,491.151 ↓ 245.0 245 1

Nested Loop Left Join (cost=51,947.37..129,264.70 rows=1 width=1,077) (actual time=2,325.010..2,491.151 rows=245 loops=1)

21. 19.583 2,488.116 ↓ 245.0 245 1

Nested Loop (cost=51,947.09..129,256.40 rows=1 width=1,065) (actual time=2,324.983..2,488.116 rows=245 loops=1)

  • Join Filter: (pp.procedure_performed_id = rhpp.procedure_performed_id)
  • Rows Removed by Join Filter: 173705
22. 0.893 0.893 ↑ 1.0 245 1

Index Scan using recourse_has_procedure_performed_pkey on recourse_has_procedure_performed rhpp (cost=0.28..301.42 rows=245 width=111) (actual time=0.010..0.893 rows=245 loops=1)

  • Index Cond: (recourse_id = 94)
23. 20.997 2,467.640 ↓ 39.4 710 245

Materialize (cost=51,946.81..128,888.87 rows=18 width=958) (actual time=6.400..10.072 rows=710 loops=245)

24. 17.608 2,446.643 ↓ 39.4 710 1

Hash Join (cost=51,946.81..128,888.78 rows=18 width=958) (actual time=1,567.827..2,446.643 rows=710 loops=1)

  • Hash Cond: (s.sadt_lot_id = lot_map_aux.sadt_lot_id)
25. 63.288 2,428.946 ↓ 1.0 141,397 1

Hash Left Join (cost=51,929.95..128,345.27 rows=140,395 width=950) (actual time=1,061.362..2,428.946 rows=141,397 loops=1)

  • Hash Cond: (t.treatment_status_id = ts.treatment_status_id)
26. 53.995 2,365.649 ↓ 1.0 141,397 1

Hash Left Join (cost=51,928.86..126,883.20 rows=140,395 width=832) (actual time=1,061.346..2,365.649 rows=141,397 loops=1)

  • Hash Cond: (treatment_wait_list.wait_list_created_by = utwlr.user_id)
27. 65.486 2,310.687 ↓ 1.0 141,397 1

Hash Left Join (cost=49,406.27..122,430.17 rows=140,395 width=806) (actual time=1,060.374..2,310.687 rows=141,397 loops=1)

  • Hash Cond: (t.treatment_model_id = tm.treatment_model_id)
28. 362.869 2,245.174 ↓ 1.0 141,397 1

Hash Join (cost=49,403.78..120,497.25 rows=140,395 width=664) (actual time=1,060.339..2,245.174 rows=141,397 loops=1)

  • Hash Cond: (pp.procedure_auth_id = pa.procedure_auth_id)
29. 72.717 1,559.377 ↑ 1.0 169,953 1

Hash Left Join (cost=29,906.23..70,358.03 rows=169,953 width=638) (actual time=736.773..1,559.377 rows=169,953 loops=1)

  • Hash Cond: (pp.procedure_status_id = ps.procedure_status_id)
30. 60.007 1,486.652 ↑ 1.0 169,953 1

Hash Left Join (cost=29,905.07..68,426.69 rows=169,953 width=550) (actual time=736.759..1,486.652 rows=169,953 loops=1)

  • Hash Cond: (pp.procedure_performed_amb_id = ppamb.procedure_performed_amb_id)
31. 89.071 1,426.642 ↑ 1.0 169,953 1

Hash Left Join (cost=29,880.45..66,256.41 rows=169,953 width=470) (actual time=736.750..1,426.642 rows=169,953 loops=1)

  • Hash Cond: ((pp.procedure_code)::text = (proc.procedure_code)::text)
32. 288.150 1,337.496 ↑ 1.0 169,953 1

Hash Left Join (cost=29,874.76..63,913.86 rows=169,953 width=292) (actual time=736.665..1,337.496 rows=169,953 loops=1)

  • Hash Cond: (pp.procedure_performed_id = ppp.procedure_performed_id)
33. 113.091 312.910 ↑ 1.0 169,953 1

Merge Right Join (cost=40.39..22,287.84 rows=169,953 width=159) (actual time=0.072..312.910 rows=169,953 loops=1)

  • Merge Cond: (t.treatment_id = pp.treatment_id)
34. 51.303 111.664 ↓ 1.0 152,022 1

Merge Left Join (cost=39.70..9,675.66 rows=152,021 width=91) (actual time=0.055..111.664 rows=152,022 loops=1)

  • Merge Cond: (t.treatment_id = treatment_wait_list.treatment_id)
35. 60.332 60.332 ↓ 1.0 152,022 1

Index Scan using treatment_pkey on treatment t (cost=0.42..9,249.18 rows=152,021 width=87) (actual time=0.022..60.332 rows=152,022 loops=1)

36. 0.000 0.029 ↓ 0.0 0 1

Unique (cost=39.28..41.93 rows=200 width=12) (actual time=0.029..0.029 rows=0 loops=1)

37. 0.022 0.029 ↓ 0.0 0 1

Sort (cost=39.28..40.61 rows=530 width=12) (actual time=0.029..0.029 rows=0 loops=1)

  • Sort Key: treatment_wait_list.treatment_id, treatment_wait_list.wait_list_patient_arrival
  • Sort Method: quicksort Memory: 25kB
38. 0.007 0.007 ↓ 0.0 0 1

Seq Scan on treatment_wait_list (cost=0.00..15.30 rows=530 width=12) (actual time=0.007..0.007 rows=0 loops=1)

39. 88.155 88.155 ↑ 1.0 169,953 1

Index Scan using procedure_performed_treatment_id_idx on procedure_performed pp (cost=0.42..10,108.05 rows=169,953 width=72) (actual time=0.012..88.155 rows=169,953 loops=1)

40. 62.849 736.436 ↑ 1.0 97,977 1

Hash (cost=26,599.66..26,599.66 rows=97,977 width=137) (actual time=736.436..736.436 rows=97,977 loops=1)

  • Buckets: 32768 Batches: 8 Memory Usage: 1473kB
41. 14.053 673.587 ↑ 1.0 97,977 1

Subquery Scan on ppp (cost=21,700.81..26,599.66 rows=97,977 width=137) (actual time=139.117..673.587 rows=97,977 loops=1)

42. 505.439 659.534 ↑ 1.0 97,977 1

GroupAggregate (cost=21,700.81..25,619.89 rows=97,977 width=137) (actual time=139.115..659.534 rows=97,977 loops=1)

  • Group Key: ppp_1.procedure_performed_id
43. 94.334 154.095 ↓ 1.0 97,978 1

Sort (cost=21,700.81..21,945.75 rows=97,977 width=133) (actual time=139.063..154.095 rows=97,978 loops=1)

  • Sort Key: ppp_1.procedure_performed_id
  • Sort Method: external sort Disk: 5448kB
44. 20.243 59.761 ↓ 1.0 97,978 1

Hash Left Join (cost=2,523.75..6,879.44 rows=97,977 width=133) (actual time=1.027..59.761 rows=97,978 loops=1)

  • Hash Cond: (ppp_1.procedure_payment_type_id = ppt.procedure_payment_type_id)
45. 28.836 39.507 ↓ 1.0 97,978 1

Hash Left Join (cost=2,522.60..5,765.55 rows=97,977 width=45) (actual time=1.009..39.507 rows=97,978 loops=1)

  • Hash Cond: (ppp_1.created_by = u.user_id)
46. 9.679 9.679 ↓ 1.0 97,978 1

Seq Scan on procedure_performed_payment ppp_1 (cost=0.00..1,895.77 rows=97,977 width=23) (actual time=0.010..9.679 rows=97,978 loops=1)

47. 0.078 0.992 ↑ 1.0 386 1

Hash (cost=2,517.77..2,517.77 rows=386 width=30) (actual time=0.992..0.992 rows=386 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 30kB
48. 0.084 0.914 ↑ 1.0 386 1

Nested Loop Left Join (cost=0.42..2,517.77 rows=386 width=30) (actual time=0.020..0.914 rows=386 loops=1)

49. 0.058 0.058 ↑ 1.0 386 1

Seq Scan on "user" u (cost=0.00..13.86 rows=386 width=8) (actual time=0.006..0.058 rows=386 loops=1)

50. 0.772 0.772 ↑ 1.0 1 386

Index Scan using person_pkey on person p_1 (cost=0.42..6.49 rows=1 width=30) (actual time=0.002..0.002 rows=1 loops=386)

  • Index Cond: (person_id = u.person_id)
51. 0.003 0.011 ↑ 1.0 7 1

Hash (cost=1.07..1.07 rows=7 width=92) (actual time=0.011..0.011 rows=7 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
52. 0.008 0.008 ↑ 1.0 7 1

Seq Scan on procedure_payment_type ppt (cost=0.00..1.07 rows=7 width=92) (actual time=0.007..0.008 rows=7 loops=1)

53. 0.021 0.075 ↑ 1.0 79 1

Hash (cost=4.70..4.70 rows=79 width=187) (actual time=0.075..0.075 rows=79 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 18kB
54. 0.029 0.054 ↑ 1.0 79 1

Hash Left Join (cost=1.09..4.70 rows=79 width=187) (actual time=0.025..0.054 rows=79 loops=1)

  • Hash Cond: (proc.procedure_type_id = pt.procedure_type_id)
55. 0.016 0.016 ↑ 1.0 79 1

Seq Scan on procedure proc (cost=0.00..2.79 rows=79 width=69) (actual time=0.010..0.016 rows=79 loops=1)

56. 0.002 0.009 ↑ 1.0 4 1

Hash (cost=1.04..1.04 rows=4 width=122) (actual time=0.009..0.009 rows=4 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
57. 0.007 0.007 ↑ 1.0 4 1

Seq Scan on procedure_type pt (cost=0.00..1.04 rows=4 width=122) (actual time=0.006..0.007 rows=4 loops=1)

58. 0.000 0.003 ↓ 0.0 0 1

Hash (cost=16.50..16.50 rows=650 width=88) (actual time=0.003..0.003 rows=0 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 8kB
59. 0.003 0.003 ↓ 0.0 0 1

Seq Scan on procedure_performed_amb ppamb (cost=0.00..16.50 rows=650 width=88) (actual time=0.003..0.003 rows=0 loops=1)

60. 0.002 0.008 ↑ 1.0 7 1

Hash (cost=1.07..1.07 rows=7 width=92) (actual time=0.008..0.008 rows=7 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
61. 0.006 0.006 ↑ 1.0 7 1

Seq Scan on procedure_status ps (cost=0.00..1.07 rows=7 width=92) (actual time=0.005..0.006 rows=7 loops=1)

62. 50.029 322.928 ↑ 1.0 134,562 1

Hash (cost=16,763.53..16,763.53 rows=134,562 width=34) (actual time=322.928..322.928 rows=134,562 loops=1)

  • Buckets: 65536 Batches: 4 Memory Usage: 2675kB
63. 103.341 272.899 ↑ 1.0 134,562 1

Hash Join (cost=6,018.07..16,763.53 rows=134,562 width=34) (actual time=87.135..272.899 rows=134,562 loops=1)

  • Hash Cond: (s.procedure_auth_id = pa.procedure_auth_id)
64. 82.678 82.678 ↑ 1.0 134,562 1

Seq Scan on sadt s (cost=0.00..6,775.62 rows=134,562 width=12) (actual time=0.013..82.678 rows=134,562 loops=1)

65. 48.812 86.880 ↑ 1.0 162,892 1

Hash (cost=3,026.92..3,026.92 rows=162,892 width=22) (actual time=86.880..86.880 rows=162,892 loops=1)

  • Buckets: 65536 Batches: 4 Memory Usage: 2420kB
66. 38.068 38.068 ↑ 1.0 162,892 1

Seq Scan on procedure_auth pa (cost=0.00..3,026.92 rows=162,892 width=22) (actual time=0.009..38.068 rows=162,892 loops=1)

67. 0.003 0.027 ↑ 1.0 9 1

Hash (cost=2.37..2.37 rows=9 width=146) (actual time=0.027..0.027 rows=9 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
68. 0.007 0.024 ↑ 1.0 9 1

Hash Left Join (cost=1.18..2.37 rows=9 width=146) (actual time=0.021..0.024 rows=9 loops=1)

  • Hash Cond: (tm.treatment_seq_id = tseq.treatment_seq_id)
69. 0.007 0.007 ↑ 1.0 9 1

Seq Scan on treatment_model tm (cost=0.00..1.09 rows=9 width=126) (actual time=0.006..0.007 rows=9 loops=1)

70. 0.003 0.010 ↑ 1.0 8 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
71. 0.007 0.007 ↑ 1.0 8 1

Seq Scan on treatment_seq tseq (cost=0.00..1.08 rows=8 width=28) (actual time=0.005..0.007 rows=8 loops=1)

72. 0.067 0.967 ↑ 1.0 386 1

Hash (cost=2,517.77..2,517.77 rows=386 width=30) (actual time=0.967..0.967 rows=386 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 30kB
73. 0.079 0.900 ↑ 1.0 386 1

Nested Loop Left Join (cost=0.42..2,517.77 rows=386 width=30) (actual time=0.021..0.900 rows=386 loops=1)

74. 0.049 0.049 ↑ 1.0 386 1

Seq Scan on "user" utwlr (cost=0.00..13.86 rows=386 width=8) (actual time=0.006..0.049 rows=386 loops=1)

75. 0.772 0.772 ↑ 1.0 1 386

Index Scan using person_pkey on person petwlr (cost=0.42..6.49 rows=1 width=30) (actual time=0.002..0.002 rows=1 loops=386)

  • Index Cond: (person_id = utwlr.person_id)
76. 0.002 0.009 ↑ 1.0 4 1

Hash (cost=1.04..1.04 rows=4 width=122) (actual time=0.009..0.009 rows=4 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
77. 0.007 0.007 ↑ 1.0 4 1

Seq Scan on treatment_status ts (cost=0.00..1.04 rows=4 width=122) (actual time=0.006..0.007 rows=4 loops=1)

78. 0.017 0.089 ↓ 105.0 105 1

Hash (cost=16.84..16.84 rows=1 width=16) (actual time=0.089..0.089 rows=105 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 13kB
79. 0.016 0.072 ↓ 105.0 105 1

Nested Loop (cost=0.56..16.84 rows=1 width=16) (actual time=0.023..0.072 rows=105 loops=1)

80. 0.016 0.016 ↑ 1.0 1 1

Index Scan using sadt_lot_map_mv_recourse_id on sadt_lot_map_mv lot_map (cost=0.28..8.30 rows=1 width=12) (actual time=0.015..0.016 rows=1 loops=1)

  • Index Cond: (recourse_id = 94)
81. 0.040 0.040 ↓ 21.0 105 1

Index Scan using sadt_lot_map_mv_root_id on sadt_lot_map_mv lot_map_aux (cost=0.28..8.49 rows=5 width=8) (actual time=0.006..0.040 rows=105 loops=1)

  • Index Cond: (root_id = lot_map.sadt_lot_id)
82. 1.960 1.960 ↑ 1.0 1 245

Index Scan using sadt_lot_pkey on sadt_lot sl (cost=0.28..8.30 rows=1 width=12) (actual time=0.008..0.008 rows=1 loops=245)

  • Index Cond: (sadt_lot_id = lot_map.sadt_lot_id)
83. 3.675 3.675 ↑ 1.0 1 245

Seq Scan on recourse rec (cost=0.00..2.96 rows=1 width=4) (actual time=0.013..0.015 rows=1 loops=245)

  • Filter: (recourse_id = 94)
  • Rows Removed by Filter: 76
84. 1.715 1.715 ↓ 0.0 0 245

Index Scan using import_tuss_38_pkey on import_tuss_38 it38 (cost=0.28..0.47 rows=1 width=60) (actual time=0.007..0.007 rows=0 loops=245)

  • Index Cond: ((code)::text = (rhpp.gloss_over_code)::text)
85. 0.980 6.860 ↑ 1.0 1 245

Nested Loop Left Join (cost=0.98..1.21 rows=1 width=134) (actual time=0.024..0.028 rows=1 loops=245)

86. 1.225 5.880 ↑ 1.0 1 245

Nested Loop Left Join (cost=0.84..1.03 rows=1 width=91) (actual time=0.020..0.024 rows=1 loops=245)

87. 2.940 2.940 ↑ 1.0 1 245

Index Scan using treatment_pkey on treatment t_aux (cost=0.42..0.50 rows=1 width=48) (actual time=0.009..0.012 rows=1 loops=245)

  • Index Cond: (treatment_id = t.treatment_id)
88. 1.715 1.715 ↑ 1.0 1 245

Index Scan using request_pkey on request r (cost=0.42..0.53 rows=1 width=43) (actual time=0.007..0.007 rows=1 loops=245)

  • Index Cond: (request_id = t_aux.request_id)
89. 0.000 0.000 ↓ 0.0 0 245

Index Scan using schedule_pkey on schedule s_1 (cost=0.14..0.16 rows=1 width=98) (actual time=0.000..0.000 rows=0 loops=245)

  • Index Cond: (schedule_id = t_aux.schedule_id)
90. 1.715 1.715 ↑ 1.0 1 245

Index Scan using patient_pkey on patient p (cost=0.42..7.56 rows=1 width=8) (actual time=0.007..0.007 rows=1 loops=245)

  • Index Cond: (patient_id = (CASE WHEN (t_aux.request_id IS NOT NULL) THEN r.patient_id ELSE s_1.patient_id END))
91. 1.715 1.715 ↑ 1.0 1 245

Index Scan using person_pkey on person ppe (cost=0.42..0.51 rows=1 width=30) (actual time=0.007..0.007 rows=1 loops=245)

  • Index Cond: (person_id = p.person_id)
92. 1.225 1.225 ↑ 1.0 1 245

Index Scan using user_pkey on "user" ttu (cost=0.27..0.80 rows=1 width=8) (actual time=0.005..0.005 rows=1 loops=245)

  • Index Cond: (user_id = (CASE WHEN (t_aux.request_id IS NOT NULL) THEN r.created_by ELSE s_1.created_by END))
93. 0.980 0.980 ↑ 1.0 1 245

Index Scan using person_pkey on person ttpe (cost=0.42..6.49 rows=1 width=30) (actual time=0.004..0.004 rows=1 loops=245)

  • Index Cond: (person_id = ttu.person_id)
94. 0.980 0.980 ↑ 1.0 1 245

Index Scan using health_insurance_company_pkey on health_insurance_company hic (cost=0.14..0.27 rows=1 width=23) (actual time=0.004..0.004 rows=1 loops=245)

  • Index Cond: (health_insurance_company_id = (CASE WHEN (t_aux.request_id IS NOT NULL) THEN r.health_insurance_company_id ELSE s_1.health_insurance_company_id END))
95. 0.735 0.735 ↑ 1.0 1 245

Index Scan using health_insurance_company_plan_pkey on health_insurance_company_plan hicp (cost=0.14..0.31 rows=1 width=27) (actual time=0.003..0.003 rows=1 loops=245)

  • Index Cond: ((health_insurance_company_plan_id = (CASE WHEN (t_aux.request_id IS NOT NULL) THEN r.health_insurance_company_plan_id ELSE s_1.health_insurance_company_plan_id END)) AND (health_insurance_company_id = (CASE WHEN (t_aux.request_id IS NOT NULL) THEN r.health_insurance_company_id ELSE s_1.health_insurance_company_id END)))
96. 1.715 1.715 ↑ 1.0 1 245

Index Scan using patient_has_health_insurance_company_plan_pkey on patient_has_health_insurance_company_plan phhicp (cost=0.42..7.79 rows=1 width=24) (actual time=0.007..0.007 rows=1 loops=245)

  • Index Cond: ((patient_id = (CASE WHEN (t_aux.request_id IS NOT NULL) THEN r.patient_id ELSE s_1.patient_id END)) AND (health_insurance_company_id = (CASE WHEN (t_aux.request_id IS NOT NULL) THEN r.health_insurance_company_id ELSE s_1.health_insurance_company_id END)) AND (health_insurance_company_plan_id = (CASE WHEN (t_aux.request_id IS NOT NULL) THEN r.health_insurance_company_plan_id ELSE s_1.health_insurance_company_plan_id END)))
97. 0.980 0.980 ↑ 1.0 1 245

Index Scan using health_facility_pkey on health_facility rhf (cost=0.14..0.42 rows=1 width=36) (actual time=0.004..0.004 rows=1 loops=245)

  • Index Cond: (health_facility_id = (CASE WHEN (t_aux.request_id IS NOT NULL) THEN r.health_facility_id ELSE s_1.health_facility_id END))
98. 1.225 1.225 ↑ 1.0 1 245

Index Scan using health_professional_pkey on health_professional rhp (cost=0.28..1.21 rows=1 width=8) (actual time=0.005..0.005 rows=1 loops=245)

  • Index Cond: (health_professional_id = (CASE WHEN (t_aux.request_id IS NOT NULL) THEN r.health_professional_id ELSE s_1.health_professional_id END))
99. 0.980 0.980 ↑ 1.0 1 245

Index Scan using person_pkey on person rhppe (cost=0.42..3.36 rows=1 width=30) (actual time=0.004..0.004 rows=1 loops=245)

  • Index Cond: (person_id = rhp.person_id)
100. 1.225 1.225 ↑ 1.0 1 245

Index Scan using profession_pkey on profession rhpprof (cost=0.28..2.37 rows=1 width=13) (actual time=0.005..0.005 rows=1 loops=245)

  • Index Cond: (profession_id = (CASE WHEN (t_aux.request_id IS NOT NULL) THEN r.profession_id ELSE s_1.profession_id END))
101. 79,516.465 85,854.125 ↓ 1.0 143,109 245

GroupAggregate (cost=28,502.56..35,942.54 rows=141,242 width=109) (actual time=0.819..350.425 rows=143,109 loops=245)

  • Group Key: thhp.treatment_id
102. 6,254.836 6,337.660 ↑ 1.1 158,925 245

Sort (cost=28,502.56..28,922.12 rows=167,823 width=42) (actual time=0.808..25.868 rows=158,925 loops=245)

  • Sort Key: thhp.treatment_id
  • Sort Method: external sort Disk: 8552kB
103. 44.877 82.824 ↑ 1.0 167,823 1

Hash Left Join (cost=3,387.60..8,772.40 rows=167,823 width=42) (actual time=22.594..82.824 rows=167,823 loops=1)

  • Hash Cond: (thhp.health_professional_id = php.health_professional_id)
104. 15.374 15.374 ↑ 1.0 167,823 1

Seq Scan on treatment_has_health_professional thhp (cost=0.00..3,077.23 rows=167,823 width=16) (actual time=0.009..15.374 rows=167,823 loops=1)

105. 0.406 22.573 ↓ 1.0 2,349 1

Hash (cost=3,358.26..3,358.26 rows=2,347 width=30) (actual time=22.573..22.573 rows=2,349 loops=1)

  • Buckets: 4096 Batches: 1 Memory Usage: 172kB
106. 11.005 22.167 ↓ 1.0 2,349 1

Hash Right Join (cost=68.81..3,358.26 rows=2,347 width=30) (actual time=0.579..22.167 rows=2,349 loops=1)

  • Hash Cond: (phppe.person_id = php.person_id)
107. 10.597 10.597 ↓ 1.0 107,710 1

Seq Scan on person phppe (cost=0.00..2,862.08 rows=107,708 width=30) (actual time=0.007..10.597 rows=107,710 loops=1)

108. 0.285 0.565 ↓ 1.0 2,349 1

Hash (cost=39.47..39.47 rows=2,347 width=8) (actual time=0.565..0.565 rows=2,349 loops=1)

  • Buckets: 4096 Batches: 1 Memory Usage: 124kB
109. 0.280 0.280 ↓ 1.0 2,349 1

Seq Scan on health_professional php (cost=0.00..39.47 rows=2,347 width=8) (actual time=0.008..0.280 rows=2,349 loops=1)

110. 0.490 0.490 ↓ 0.0 0 245

Index Scan using user_pkey on "user" rep_u (cost=0.27..0.29 rows=1 width=8) (actual time=0.002..0.002 rows=0 loops=245)

  • Index Cond: (user_id = pp.repassed_by)
111. 0.000 0.000 ↓ 0.0 0 245

Index Scan using person_pkey on person rep_p (cost=0.42..6.49 rows=1 width=30) (actual time=0.000..0.000 rows=0 loops=245)

  • Index Cond: (person_id = rep_u.person_id)
112. 91,193.388 91,193.388 ↓ 245.0 245 1

CTE Scan on teste (cost=0.00..0.02 rows=1 width=4,250) (actual time=2,858.911..91,193.388 rows=245 loops=1)

Planning time : 20.617 ms
Execution time : 91,281.961 ms