explain.depesz.com

PostgreSQL's explain analyze made readable

Result: iU46

Settings
# exclusive inclusive rows x rows loops node
1. 0.057 10,748.656 ↓ 23.0 23 1

Nested Loop Left Join (cost=261,990.14..431,771.52 rows=1 width=16) (actual time=7,544.179..10,748.656 rows=23 loops=1)

2.          

CTE agendados

3. 0.023 0.475 ↑ 38.2 70 1

Unique (cost=455.07..468.49 rows=2,673 width=22) (actual time=0.433..0.475 rows=70 loops=1)

4. 0.091 0.452 ↑ 37.8 71 1

Sort (cost=455.07..461.78 rows=2,684 width=22) (actual time=0.432..0.452 rows=71 loops=1)

  • Sort Key: agenda.cod_pac, agenda.ini_agen
  • Sort Method: quicksort Memory: 30kB
5. 0.361 0.361 ↑ 37.8 71 1

Index Scan using agenda_idx on agenda (cost=0.44..302.22 rows=2,684 width=22) (actual time=0.050..0.361 rows=71 loops=1)

  • Index Cond: (fec_agen = ('now'::cstring)::date)
  • Filter: (cod_pac <> '0'::double precision)
  • Rows Removed by Filter: 13
6. 0.133 10,743.219 ↓ 20.0 20 1

Nested Loop Anti Join (cost=261,520.35..431,294.37 rows=1 width=16) (actual time=7,543.928..10,743.219 rows=20 loops=1)

7. 0.166 10,737.826 ↓ 20.0 20 1

Nested Loop Anti Join (cost=261,519.92..431,288.59 rows=1 width=16) (actual time=7,543.776..10,737.826 rows=20 loops=1)

8. 2,160.401 10,730.260 ↓ 40.0 40 1

Hash Join (cost=261,519.48..431,286.02 rows=1 width=16) (actual time=7,388.554..10,730.260 rows=40 loops=1)

  • Hash Cond: (((pac.cod_pac)::numeric)::double precision = ag.cod_pac)
9. 1,671.161 8,569.311 ↓ 1,140,143.0 1,140,143 1

Hash Right Join (cost=261,432.61..431,198.01 rows=1 width=8) (actual time=7,367.679..8,569.311 rows=1,140,143 loops=1)

  • Hash Cond: (cp.cod_pac = (pac.cod_pac)::numeric)
  • Filter: ((cp.cod_pac IS NULL) OR (cd.folio_diag IS NULL))
  • Rows Removed by Filter: 383,865
10. 1,605.791 3,946.381 ↑ 1.0 389,447 1

Hash Right Join (cost=168,747.69..323,459.33 rows=404,184 width=14) (actual time=3,314.609..3,946.381 rows=389,447 loops=1)

  • Hash Cond: (cd.folio_diag = cp.folio_diag)
11. 1,710.605 1,710.605 ↑ 1.0 5,006,911 1

Seq Scan on cabe_diag cd (cost=0.00..131,379.03 rows=5,167,559 width=8) (actual time=27.560..1,710.605 rows=5,006,911 loops=1)

  • Filter: (cod_esp <> '23'::numeric)
  • Rows Removed by Filter: 275,115
12. 175.280 629.985 ↑ 1.0 389,447 1

Hash (cost=163,695.39..163,695.39 rows=404,184 width=14) (actual time=629.985..629.985 rows=389,447 loops=1)

  • Buckets: 524,288 Batches: 1 Memory Usage: 22,352kB
13. 281.193 454.705 ↑ 1.0 389,447 1

Bitmap Heap Scan on cabe_presu cp (cost=16,943.33..163,695.39 rows=404,184 width=14) (actual time=180.083..454.705 rows=389,447 loops=1)

  • Recheck Cond: ((fecha_presu > date_trunc('day'::text, (now() - '6 mons'::interval))) AND (fecha_presu < ('now'::cstring)::date))
  • Heap Blocks: exact=16,270
14. 173.512 173.512 ↓ 1.0 409,186 1

Bitmap Index Scan on cabe_presu_idx (cost=0.00..16,842.28 rows=404,184 width=0) (actual time=173.512..173.512 rows=409,186 loops=1)

  • Index Cond: ((fecha_presu > date_trunc('day'::text, (now() - '6 mons'::interval))) AND (fecha_presu < ('now'::cstring)::date))
15. 2,317.238 2,951.769 ↑ 1.0 1,254,293 1

Hash (cost=71,506.70..71,506.70 rows=1,290,818 width=8) (actual time=2,951.769..2,951.769 rows=1,254,293 loops=1)

  • Buckets: 2,097,152 Batches: 2 Memory Usage: 40,871kB
16. 634.531 634.531 ↑ 1.0 1,254,293 1

Index Only Scan using paciente_pkey on paciente pac (cost=0.43..71,506.70 rows=1,290,818 width=8) (actual time=0.029..634.531 rows=1,254,293 loops=1)

  • Heap Fetches: 362
17. 0.036 0.548 ↑ 38.2 70 1

Hash (cost=53.46..53.46 rows=2,673 width=16) (actual time=0.548..0.548 rows=70 loops=1)

  • Buckets: 4,096 Batches: 1 Memory Usage: 36kB
18. 0.512 0.512 ↑ 38.2 70 1

CTE Scan on agendados ag (cost=0.00..53.46 rows=2,673 width=16) (actual time=0.436..0.512 rows=70 loops=1)

19. 7.400 7.400 ↓ 0.0 0 40

Index Scan using agenda_idx3 on agenda a (cost=0.43..2.12 rows=2 width=8) (actual time=0.185..0.185 rows=0 loops=40)

  • Index Cond: (cod_pac = pac.cod_pac)
  • Filter: ((cod_serv = '3'::double precision) AND (fec_agen < ('now'::cstring)::date) AND (fec_agen > date_trunc('day'::text, (now() - '6 mons'::interval))))
  • Rows Removed by Filter: 59
20. 5.260 5.260 ↓ 0.0 0 20

Index Scan using c_maestro_mov_idx1 on c_maestro_mov mov (cost=0.44..3.11 rows=1 width=6) (actual time=0.263..0.263 rows=0 loops=20)

  • Index Cond: (cod_pac = (pac.cod_pac)::numeric)
  • Filter: (((tipo_mov)::text = 'AC'::text) AND (activo = '1'::double precision) AND ((fecha_tra)::double precision < date_part('epoch'::text, (('now'::cstring)::date)::timestamp without time zone)) AND ((fecha_tra)::double precision > date_part('epoch'::text, date_trunc('day'::text, ((now())::date - '6 mons'::interval)))))
  • Rows Removed by Filter: 62
21. 0.072 5.380 ↓ 0.0 0 20

Nested Loop (cost=1.29..8.64 rows=1 width=6) (actual time=0.240..0.269 rows=0 loops=20)

22. 0.207 2.060 ↓ 2.0 6 20

Nested Loop (cost=0.86..4.87 rows=3 width=14) (actual time=0.038..0.103 rows=6 loops=20)

23. 0.620 0.620 ↑ 1.1 7 20

Index Scan using cabe_presu_idx1 on cabe_presu cp_1 (cost=0.43..1.08 rows=8 width=14) (actual time=0.018..0.031 rows=7 loops=20)

  • Index Cond: (cod_pac = (pac.cod_pac)::numeric)
24. 1.233 1.233 ↑ 1.0 1 137

Index Scan using cabe_tratamiento_folio_presu_key on cabe_tratamiento ct (cost=0.43..0.46 rows=1 width=16) (actual time=0.008..0.009 rows=1 loops=137)

  • Index Cond: (folio_presu = cp_1.folio_presu)
25. 3.248 3.248 ↓ 0.0 0 112

Index Scan using deta_tratamiento_folio_trata_idx on deta_tratamiento dt (cost=0.43..1.25 rows=1 width=8) (actual time=0.029..0.029 rows=0 loops=112)

  • Index Cond: (folio_trata = ct.folio_trata)
  • Filter: ((cod_sucursal > date_part('epoch'::text, date_trunc('day'::text, (now() - '6 mons'::interval)))) AND (cod_sucursal < date_part('epoch'::text, (('now'::cstring)::date)::timestamp without time zone)))
  • Rows Removed by Filter: 6