explain.depesz.com

PostgreSQL's explain analyze made readable

Result: SknW

Settings
# exclusive inclusive rows x rows loops node
1. 0.106 565.054 ↓ 24.0 24 1

Sort (cost=160,430.96..160,430.97 rows=1 width=397) (actual time=565.053..565.054 rows=24 loops=1)

  • Sort Key: dispensaca0_.dt_prox_dispensacao DESC, dispensaca1_.dt_dispensacao DESC, dispensaca1_.nr_dispensacao, dispensaca1_.empresa, dispensaca0_.item
  • Sort Method: quicksort Memory: 37kB
2. 0.030 564.948 ↓ 24.0 24 1

Nested Loop Left Join (cost=130.09..160,430.95 rows=1 width=397) (actual time=107.241..564.948 rows=24 loops=1)

3. 0.038 564.846 ↓ 24.0 24 1

Nested Loop Left Join (cost=129.82..160,430.64 rows=1 width=397) (actual time=107.235..564.846 rows=24 loops=1)

4. 0.020 564.760 ↓ 24.0 24 1

Nested Loop Left Join (cost=129.68..160,430.47 rows=1 width=362) (actual time=107.229..564.760 rows=24 loops=1)

5. 0.027 564.668 ↓ 24.0 24 1

Nested Loop Left Join (cost=129.39..160,423.57 rows=1 width=336) (actual time=107.225..564.668 rows=24 loops=1)

6. 0.025 564.593 ↓ 24.0 24 1

Nested Loop Left Join (cost=129.11..160,417.97 rows=1 width=307) (actual time=107.222..564.593 rows=24 loops=1)

7. 0.021 564.496 ↓ 24.0 24 1

Nested Loop Left Join (cost=128.84..160,412.37 rows=1 width=282) (actual time=107.217..564.496 rows=24 loops=1)

8. 0.040 564.355 ↓ 24.0 24 1

Nested Loop Left Join (cost=128.56..160,407.95 rows=1 width=258) (actual time=107.212..564.355 rows=24 loops=1)

9. 0.601 564.267 ↓ 24.0 24 1

Nested Loop Left Join (cost=128.43..160,407.44 rows=1 width=140) (actual time=107.208..564.267 rows=24 loops=1)

  • Filter: (dispensaca0_.cd_dis_med_item = (SubPlan 2))
  • Rows Removed by Filter: 259
10. 11.947 53.983 ↓ 5.4 283 1

Hash Join (cost=128.15..6,364.15 rows=52 width=97) (actual time=45.655..53.983 rows=283 loops=1)

  • Hash Cond: (dispensaca0_.nr_dispensacao = dispensaca1_.nr_dispensacao)
11. 41.961 41.961 ↓ 1.0 164,870 1

Seq Scan on dispensacao_medicamento_item dispensaca0_ (cost=0.00..5,642.50 rows=158,128 width=44) (actual time=0.016..41.961 rows=164,870 loops=1)

  • Filter: ((quantidade_dispensada > '0'::numeric) AND (status <> 1))
  • Rows Removed by Filter: 6830
12. 0.021 0.075 ↑ 1.1 30 1

Hash (cost=127.72..127.72 rows=34 width=61) (actual time=0.075..0.075 rows=30 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 12kB
13. 0.054 0.054 ↑ 1.1 30 1

Index Scan using idx_disp_med_1 on dispensacao_medicamento dispensaca1_ (cost=0.29..127.72 rows=34 width=61) (actual time=0.018..0.054 rows=30 loops=1)

  • Index Cond: (cd_usu_cadsus_destino = '211475'::numeric)
14. 1.415 1.415 ↑ 1.0 1 283

Index Scan using pk_produtos on produtos produto6_ (cost=0.28..0.30 rows=1 width=53) (actual time=0.005..0.005 rows=1 loops=283)

  • Index Cond: ((dispensaca0_.cod_pro)::text = (cod_pro)::text)
15.          

SubPlan (forNested Loop Left Join)

16. 0.000 508.268 ↑ 1.0 1 283

Aggregate (cost=2,962.05..2,962.06 rows=1 width=8) (actual time=1.796..1.796 rows=1 loops=283)

17.          

Initplan (forAggregate)

18. 0.566 262.058 ↑ 1.0 1 283

Aggregate (cost=1,480.34..1,480.35 rows=1 width=8) (actual time=0.926..0.926 rows=1 loops=283)

19. 32.828 261.492 ↓ 19.0 19 283

Hash Join (cost=24.81..1,480.34 rows=1 width=8) (actual time=0.744..0.924 rows=19 loops=283)

  • Hash Cond: (dispensaca12_.nr_dispensacao = dispensaca13_.nr_dispensacao)
20. 184.516 221.589 ↓ 2.4 1,351 283

Bitmap Heap Scan on dispensacao_medicamento_item dispensaca12_ (cost=12.85..1,466.23 rows=572 width=8) (actual time=0.213..0.783 rows=1,351 loops=283)

  • Recheck Cond: ((cod_pro)::text = (produto6_.cod_pro)::text)
  • Heap Blocks: exact=201589
21. 37.073 37.073 ↓ 2.4 1,351 283

Bitmap Index Scan on idx_disp_med_item_1 (cost=0.00..12.71 rows=572 width=0) (actual time=0.131..0.131 rows=1,351 loops=283)

  • Index Cond: ((cod_pro)::text = (produto6_.cod_pro)::text)
22. 1.132 7.075 ↓ 15.0 30 283

Hash (cost=11.93..11.93 rows=2 width=16) (actual time=0.025..0.025 rows=30 loops=283)

  • Buckets: 1024 Batches: 1 Memory Usage: 10kB
23. 5.943 5.943 ↓ 15.0 30 283

Index Scan using idx_disp_med_1 on dispensacao_medicamento dispensaca13_ (cost=0.29..11.93 rows=2 width=16) (actual time=0.005..0.021 rows=30 loops=283)

  • Index Cond: (cd_usu_cadsus_destino = dispensaca1_.cd_usu_cadsus_destino)
24. 293.471 507.985 ↑ 1.0 1 283

Nested Loop (cost=13.15..1,481.69 rows=1 width=8) (actual time=1.778..1.795 rows=1 loops=283)

  • Join Filter: (dispensaca10_.nr_dispensacao = dispensaca11_.nr_dispensacao)
  • Rows Removed by Join Filter: 1350
25. 1.132 1.132 ↑ 1.0 1 283

Index Scan using idx_disp_med_2 on dispensacao_medicamento dispensaca11_ (cost=0.29..8.31 rows=1 width=8) (actual time=0.004..0.004 rows=1 loops=283)

  • Index Cond: (dt_dispensacao = $2)
  • Filter: (cd_usu_cadsus_destino = dispensaca1_.cd_usu_cadsus_destino)
26. 176.309 213.382 ↓ 2.4 1,351 283

Bitmap Heap Scan on dispensacao_medicamento_item dispensaca10_ (cost=12.85..1,466.23 rows=572 width=16) (actual time=0.211..0.754 rows=1,351 loops=283)

  • Recheck Cond: ((cod_pro)::text = (produto6_.cod_pro)::text)
  • Heap Blocks: exact=201589
27. 37.073 37.073 ↓ 2.4 1,351 283

Bitmap Index Scan on idx_disp_med_item_1 (cost=0.00..12.71 rows=572 width=0) (actual time=0.131..0.131 rows=1,351 loops=283)

  • Index Cond: ((cod_pro)::text = (produto6_.cod_pro)::text)
28. 0.048 0.048 ↑ 1.0 1 24

Index Scan using pk_tipo_receita on tipo_receita tiporeceit2_ (cost=0.13..0.50 rows=1 width=126) (actual time=0.002..0.002 rows=1 loops=24)

  • Index Cond: (dispensaca1_.cd_receita = cd_receita)
29. 0.120 0.120 ↑ 1.0 1 24

Index Scan using pk_usuarios on usuarios usuario3_ (cost=0.28..4.41 rows=1 width=29) (actual time=0.004..0.005 rows=1 loops=24)

  • Index Cond: (dispensaca1_.cd_usuario = cd_usuario)
30. 0.072 0.072 ↑ 1.0 1 24

Index Scan using pk_empresa on empresa empresa4_ (cost=0.28..5.59 rows=1 width=29) (actual time=0.003..0.003 rows=1 loops=24)

  • Index Cond: (dispensaca1_.empresa_origem = empresa)
31. 0.048 0.048 ↑ 1.0 1 24

Index Scan using pk_empresa on empresa empresa5_ (cost=0.28..5.59 rows=1 width=29) (actual time=0.002..0.002 rows=1 loops=24)

  • Index Cond: (dispensaca1_.empresa = empresa)
32. 0.072 0.072 ↑ 1.0 1 24

Index Scan using pk_profissional on profissional profission9_ (cost=0.29..6.89 rows=1 width=30) (actual time=0.003..0.003 rows=1 loops=24)

  • Index Cond: (dispensaca1_.cd_profissional = cd_profissional)
33. 0.048 0.048 ↑ 1.0 1 24

Index Scan using pk_unidade on unidade unidade7_ (cost=0.14..0.16 rows=1 width=40) (actual time=0.002..0.002 rows=1 loops=24)

  • Index Cond: (produto6_.cod_uni = cod_uni)
34. 0.072 0.072 ↑ 1.0 1 24

Index Only Scan using pk_subgrupo on subgrupo subgrupo8_ (cost=0.27..0.30 rows=1 width=8) (actual time=0.003..0.003 rows=1 loops=24)

  • Index Cond: ((cod_gru = produto6_.cod_gru) AND (cod_sub = produto6_.cod_sub))
  • Heap Fetches: 0
Planning time : 5.298 ms
Execution time : 565.400 ms