explain.depesz.com

PostgreSQL's explain analyze made readable

Result: 3pRf

Settings
# exclusive inclusive rows x rows loops node
1. 125.405 1,514.900 ↑ 1.9 54 1

Result (cost=102,220.58..102,399.08 rows=105 width=760) (actual time=1,392.814..1,514.900 rows=54 loops=1)

2.          

CTE with_veiculos_com_rastreamento

3. 10.932 27.706 ↑ 1.0 112 1

Unique (cost=0.29..2,523.87 rows=112 width=4) (actual time=0.037..27.706 rows=112 loops=1)

4. 16.774 16.774 ↑ 1.0 88,433 1

Index Only Scan using idx_veiculo_ficha_diaria_cd_veiculo on veiculo_ficha_diaria vfd (cost=0.29..2,302.79 rows=88,433 width=4) (actual time=0.036..16.774 rows=88,433 loops=1)

  • Heap Fetches: 0
5.          

CTE with_ultimos_documentos_veiculo

6. 0.500 96.164 ↓ 1.7 297 1

HashAggregate (cost=3,496.34..3,498.12 rows=178 width=44) (actual time=95.984..96.164 rows=297 loops=1)

  • Group Key: c.cd_ctrc, (NULL::integer), (NULL::integer), (((((c.dt_emissao)::text || ' '::text) || (c.hr_emissao)::text))::timestamp without time zone), (0), wvcr.cd_veiculo, c.cd_cidade_origem, c.cd_cidade_destino, c.cd_pessoa_motorista, c.dt_emissao
7. 0.067 95.664 ↓ 1.7 297 1

Append (cost=0.58..3,491.89 rows=178 width=44) (actual time=0.095..95.664 rows=297 loops=1)

8. 0.516 29.783 ↓ 2.9 112 1

Nested Loop (cost=0.58..871.11 rows=39 width=44) (actual time=0.094..29.783 rows=112 loops=1)

9. 0.160 28.595 ↑ 1.0 112 1

Nested Loop (cost=0.29..804.68 rows=112 width=8) (actual time=0.063..28.595 rows=112 loops=1)

10. 27.763 27.763 ↑ 1.0 112 1

CTE Scan on with_veiculos_com_rastreamento wvcr (cost=0.00..2.24 rows=112 width=4) (actual time=0.038..27.763 rows=112 loops=1)

11. 0.672 0.672 ↑ 1.0 1 112

Index Scan using pk_veiculo on veiculo v (cost=0.29..7.16 rows=1 width=8) (actual time=0.006..0.006 rows=1 loops=112)

  • Index Cond: (cd_veiculo = wvcr.cd_veiculo)
12. 0.672 0.672 ↑ 1.0 1 112

Index Scan using pk_ctrc on ctrc c (cost=0.29..0.59 rows=1 width=28) (actual time=0.006..0.006 rows=1 loops=112)

  • Index Cond: (cd_ctrc = v.cd_ultimo_ctrc)
13. 2.192 64.687 ↑ 1.0 111 1

Unique (cost=1,740.34..1,771.56 rows=112 width=44) (actual time=61.016..64.687 rows=111 loops=1)

14. 17.624 62.495 ↓ 2.0 12,614 1

Sort (cost=1,740.34..1,755.95 rows=6,244 width=44) (actual time=61.014..62.495 rows=12,614 loops=1)

  • Sort Key: wvcr_1.cd_veiculo, (((((vr_1.dt_embarque)::text || ' '::text) || (COALESCE(vr_1.hr_embarque, '00:00:00'::time without time zone))::text))::timestamp without time zone) DESC
  • Sort Method: quicksort Memory: 1370kB
15. 22.718 44.871 ↓ 2.0 12,614 1

Hash Join (cost=3.64..1,346.71 rows=6,244 width=44) (actual time=0.065..44.871 rows=12,614 loops=1)

  • Hash Cond: (vr_1.cd_veiculo = wvcr_1.cd_veiculo)
16. 22.116 22.116 ↓ 2.0 12,703 1

Seq Scan on viagem_receita vr_1 (cost=0.00..1,131.92 rows=6,355 width=32) (actual time=0.014..22.116 rows=12,703 loops=1)

  • Filter: ((cd_ctrc IS NULL) AND CASE WHEN ((COALESCE(vl_diaria, '0'::numeric) > '0'::numeric) AND (COALESCE(vl_frete, '0'::numeric) = '0'::numeric)) THEN false ELSE true END)
  • Rows Removed by Filter: 16425
17. 0.020 0.037 ↑ 1.0 112 1

Hash (cost=2.24..2.24 rows=112 width=4) (actual time=0.037..0.037 rows=112 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 12kB
18. 0.017 0.017 ↑ 1.0 112 1

CTE Scan on with_veiculos_com_rastreamento wvcr_1 (cost=0.00..2.24 rows=112 width=4) (actual time=0.001..0.017 rows=112 loops=1)

19. 0.087 1.127 ↓ 2.7 74 1

Nested Loop (cost=0.58..847.44 rows=27 width=44) (actual time=0.055..1.127 rows=74 loops=1)

20. 0.108 0.480 ↑ 1.0 112 1

Nested Loop (cost=0.29..804.68 rows=112 width=8) (actual time=0.029..0.480 rows=112 loops=1)

21. 0.036 0.036 ↑ 1.0 112 1

CTE Scan on with_veiculos_com_rastreamento wvcr_2 (cost=0.00..2.24 rows=112 width=4) (actual time=0.002..0.036 rows=112 loops=1)

22. 0.336 0.336 ↑ 1.0 1 112

Index Scan using pk_veiculo on veiculo v_1 (cost=0.29..7.16 rows=1 width=8) (actual time=0.003..0.003 rows=1 loops=112)

  • Index Cond: (cd_veiculo = wvcr_2.cd_veiculo)
23. 0.560 0.560 ↑ 1.0 1 112

Index Scan using pk_ordem_carregamento on ordem_carregamento oc_1 (cost=0.29..0.38 rows=1 width=32) (actual time=0.005..0.005 rows=1 loops=112)

  • Index Cond: (cd_ordem = v_1.cd_ultima_ordem)
24.          

CTE with_ultimo_documento

25. 0.079 97.485 ↑ 1.6 112 1

Unique (cost=532.95..533.84 rows=178 width=48) (actual time=97.377..97.485 rows=112 loops=1)

26. 0.257 97.406 ↓ 1.7 297 1

Sort (cost=532.95..533.39 rows=178 width=48) (actual time=97.376..97.406 rows=297 loops=1)

  • Sort Key: wudv.cd_veiculo, wudv.dt_documento DESC, wudv.id_prioridade
  • Sort Method: quicksort Memory: 48kB
27. 0.201 97.149 ↓ 1.7 297 1

Nested Loop (cost=0.29..526.30 rows=178 width=48) (actual time=96.003..97.149 rows=297 loops=1)

28. 96.354 96.354 ↓ 1.7 297 1

CTE Scan on with_ultimos_documentos_veiculo wudv (cost=0.00..3.56 rows=178 width=44) (actual time=95.987..96.354 rows=297 loops=1)

29. 0.594 0.594 ↑ 1.0 1 297

Index Only Scan using pk_veiculo on veiculo v_2 (cost=0.29..2.94 rows=1 width=4) (actual time=0.002..0.002 rows=1 loops=297)

  • Index Cond: (cd_veiculo = wudv.cd_veiculo)
  • Heap Fetches: 0
30.          

CTE with_veiculo_ficha_diaria

31. 97.015 723.301 ↓ 1.5 65,567 1

WindowAgg (cost=73,261.24..74,567.65 rows=43,547 width=307) (actual time=586.654..723.301 rows=65,567 loops=1)

32. 176.719 626.286 ↓ 1.5 65,567 1

Sort (cost=73,261.24..73,370.11 rows=43,547 width=287) (actual time=586.640..626.286 rows=65,567 loops=1)

  • Sort Key: vfd_1.cd_veiculo, (COALESCE(vfd_1.dt_evento, vfd_1.dt_posicao)) DESC, vfd_1.cd_ficha DESC
  • Sort Method: external merge Disk: 19312kB
33. 44.068 449.567 ↓ 1.5 65,567 1

Hash Left Join (cost=191.69..64,099.38 rows=43,547 width=287) (actual time=100.740..449.567 rows=65,567 loops=1)

  • Hash Cond: (vfd_1.cd_cidade_posicao = ci.cd_cidade)
34. 190.543 402.408 ↓ 1.5 65,567 1

Hash Left Join (cost=5.79..63,363.77 rows=43,547 width=275) (actual time=97.627..402.408 rows=65,567 loops=1)

  • Hash Cond: (vfd_1.cd_veiculo = wud.cd_veiculo)
  • Filter: ((vfd_1.cd_veiculo <> ALL ('{420,422,45658,45665,45671,45673,45675,45678,45685,45689,45692,45693,45696,45697,45700,45701,45702,45703,45704,45705,45713,45714,45715,45719,45722,45740,45932,45933,45940,45941,45942,45943,45944,45945,45970,45971,45973,45974,45991,45992,46746,46747,48074,48150,48664,48665,49687,49688,50922,50923,52099,52100,52101,53289,53836,53837}'::integer[])) OR ((vfd_1.cd_veiculo = 420) AND ((wud.cd_ultimo_documento <> 72637) OR (vfd_1.dt_posicao > '2019-07-09 08:33:51'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 16:49:10'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 422) AND ((wud.cd_ultimo_documento <> 72665) OR (vfd_1.dt_posicao > '2019-07-09 10:12:29'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 18:45:05'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45658) AND ((wud.cd_ultimo_documento <> 72442) OR (vfd_1.dt_posicao > '2019-07-09 10:11:59'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 07:42:37'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45665) AND ((wud.cd_ultimo_documento <> 72715) OR (vfd_1.dt_posicao > '2019-07-09 10:15:19'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 18:50:00'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45671) AND ((wud.cd_ultimo_documento <> 72489) OR (vfd_1.dt_posicao > '2019-07-09 10:19:23'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 09:43:11'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45673) AND ((wud.cd_ultimo_documento <> 72628) OR (vfd_1.dt_posicao > '2019-07-09 10:15:12'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 16:42:04'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45675) AND ((wud.cd_ultimo_documento <> 72779) OR (vfd_1.dt_posicao > '2019-07-09 09:58:58'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 09:12:02'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45678) AND ((wud.cd_ultimo_documento <> 30778) OR (vfd_1.dt_posicao > '2019-07-09 10:20:14'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 17:12:47'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45685) AND ((wud.cd_ultimo_documento <> 72430) OR (vfd_1.dt_posicao > '2019-07-08 22:07:48'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 16:10:36'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45689) AND ((wud.cd_ultimo_documento <> 72648) OR (vfd_1.dt_posicao > '2019-07-09 10:18:52'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 21:55:50'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45692) AND ((wud.cd_ultimo_documento <> 72524) OR (vfd_1.dt_posicao > '2019-07-09 10:19:21'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 09:20:06'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45693) AND ((wud.cd_ultimo_documento <> 72790) OR (vfd_1.dt_posicao > '2019-07-09 09:34:28'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 23:14:19'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45696) AND ((wud.cd_ultimo_documento <> 72646) OR (vfd_1.dt_posicao > '2019-07-09 08:02:33'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 21:29:36'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45697) AND ((wud.cd_ultimo_documento <> 72590) OR (vfd_1.dt_posicao > '2019-07-08 18:36:11'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-06 19:02:00'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45700) AND ((wud.cd_ultimo_documento <> 72542) OR (vfd_1.dt_posicao > '2019-07-09 10:19:41'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 21:54:40'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45701) AND ((wud.cd_ultimo_documento <> 72596) OR (vfd_1.dt_posicao > '2019-07-09 10:20:07'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 08:28:58'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45702) AND ((wud.cd_ultimo_documento <> 72422) OR (vfd_1.dt_posicao > '2019-07-09 10:18:54'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 19:44:13'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45703) AND ((wud.cd_ultimo_documento <> 72711) OR (vfd_1.dt_posicao > '2019-07-09 10:18:56'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 12:12:47'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45704) AND ((wud.cd_ultimo_documento <> 28330) OR (vfd_1.dt_posicao > '2019-07-09 09:16:52'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-05-29 08:40:20'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45705) AND ((wud.cd_ultimo_documento <> 43870) OR (vfd_1.dt_posicao > '2019-07-09 10:05:43'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 18:04:29'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45713) AND ((wud.cd_ultimo_documento <> 30809) OR (vfd_1.dt_posicao > '2019-07-09 10:13:23'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 06:56:52'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45714) AND ((wud.cd_ultimo_documento <> 72454) OR (vfd_1.dt_posicao > '2019-07-09 10:14:41'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 07:48:34'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45715) AND ((wud.cd_ultimo_documento <> 72440) OR (vfd_1.dt_posicao > '2019-07-09 10:18:17'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 07:52:15'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45719) AND ((wud.cd_ultimo_documento <> 72353) OR (vfd_1.dt_posicao > '2019-07-09 08:56:32'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 13:22:16'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45722) AND ((wud.cd_ultimo_documento <> 72435) OR (vfd_1.dt_posicao > '2019-07-09 09:20:40'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 17:49:15'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45740) AND ((wud.cd_ultimo_documento <> 29892) OR (vfd_1.dt_posicao > '2019-07-01 18:41:31'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-06-18 11:37:52'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45932) AND ((wud.cd_ultimo_documento <> 72746) OR (vfd_1.dt_posicao > '2019-07-09 09:59:32'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 07:44:28'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45933) AND ((wud.cd_ultimo_documento <> 72666) OR (vfd_1.dt_posicao > '2019-07-09 10:15:02'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 18:46:18'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45940) AND ((wud.cd_ultimo_documento <> 72618) OR (vfd_1.dt_posicao > '2019-07-09 10:19:27'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 10:02:26'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45941) AND ((wud.cd_ultimo_documento <> 30880) OR (vfd_1.dt_posicao > '2019-07-09 09:55:01'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 05:54:20'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45942) AND ((wud.cd_ultimo_documento <> 71499) OR (vfd_1.dt_posicao > '2019-07-09 10:18:50'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 14:42:41'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45943) AND ((wud.cd_ultimo_documento <> 30771) OR (vfd_1.dt_posicao > '2019-07-08 10:06:14'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-05 19:14:57'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45944) AND ((wud.cd_ultimo_documento <> 30552) OR (vfd_1.dt_posicao > '2019-07-09 10:07:22'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-04 19:51:33'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45945) AND ((wud.cd_ultimo_documento <> 71916) OR (vfd_1.dt_posicao > '2019-07-09 10:14:05'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 07:04:06'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45970) AND ((wud.cd_ultimo_documento <> 30754) OR (vfd_1.dt_posicao > '2019-07-09 10:15:17'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 08:49:26'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45971) AND ((wud.cd_ultimo_documento <> 30888) OR (vfd_1.dt_posicao > '2019-07-09 10:01:12'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 07:47:09'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45973) AND ((wud.cd_ultimo_documento <> 43871) OR (vfd_1.dt_posicao > '2019-07-09 09:56:24'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 13:37:45'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45974) AND ((wud.cd_ultimo_documento <> 72781) OR (vfd_1.dt_posicao > '2019-07-09 10:14:38'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 09:29:17'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45991) AND ((wud.cd_ultimo_documento <> 72451) OR (vfd_1.dt_posicao > '2019-07-09 10:07:41'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 17:10:34'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45992) AND ((wud.cd_ultimo_documento <> 72566) OR (vfd_1.dt_posicao > '2019-07-09 10:19:41'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 07:53:15'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 46746) AND ((wud.cd_ultimo_documento <> 72707) OR (vfd_1.dt_posicao > '2019-07-09 10:14:39'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 17:35:38'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 46747) AND ((wud.cd_ultimo_documento <> 30886) OR (vfd_1.dt_posicao > '2019-07-09 10:03:20'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 16:04:36'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 48074) AND ((wud.cd_ultimo_documento <> 72768) OR (vfd_1.dt_posicao > '2019-07-09 10:06:33'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 05:09:20'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 48150) AND ((wud.cd_ultimo_documento <> 43935) OR (vfd_1.dt_posicao > '2019-07-09 09:48:54'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 00:01:41'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 48664) AND ((wud.cd_ultimo_documento <> 72776) OR (vfd_1.dt_posicao > '2019-07-09 09:59:59'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 05:05:07'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 48665) AND ((wud.cd_ultimo_documento <> 30887) OR (vfd_1.dt_posicao > '2019-07-09 09:50:18'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 16:06:55'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 49687) AND ((wud.cd_ultimo_documento <> 72159) OR (vfd_1.dt_posicao > '2019-07-09 09:59:31'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-06-19 11:47:08'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 49688) AND ((wud.cd_ultimo_documento <> 72647) OR (vfd_1.dt_posicao > '2019-07-09 10:14:55'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 06:10:11'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 50922) AND ((wud.cd_ultimo_documento <> 30775) OR (vfd_1.dt_posicao > '2019-07-09 10:13:12'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 07:00:14'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 50923) AND ((wud.cd_ultimo_documento <> 30776) OR (vfd_1.dt_posicao > '2019-07-09 09:54:11'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 06:58:24'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 52099) AND ((wud.cd_ultimo_documento <> 72657) OR (vfd_1.dt_posicao > '2019-07-09 10:17:32'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 22:08:20'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 52100) AND ((wud.cd_ultimo_documento <> 72775) OR (vfd_1.dt_posicao > '2019-07-09 09:45:49'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 03:03:18'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 52101) AND ((wud.cd_ultimo_documento <> 72388) OR (vfd_1.dt_posicao > '2019-07-09 10:19:47'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 06:51:57'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 53289) AND ((wud.cd_ultimo_documento <> 43875) OR (vfd_1.dt_posicao > '2019-07-09 10:18:26'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 09:52:03'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 53836) AND ((wud.cd_ultimo_documento <> 72703) OR (vfd_1.dt_posicao > '2019-07-09 10:18:30'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 17:35:55'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 53837) AND ((wud.cd_ultimo_documento <> 72783) OR (vfd_1.dt_posicao > '2019-07-09 10:18:26'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-09 10:18:26'::timestamp without time zone))))
  • Rows Removed by Filter: 22866
35. 114.276 114.276 ↓ 1.4 88,433 1

Seq Scan on veiculo_ficha_diaria vfd_1 (cost=0.00..23,386.26 rows=62,092 width=243) (actual time=0.021..114.276 rows=88,433 loops=1)

  • Filter: ((cd_veiculo <> ALL ('{420,422,45658,45665,45671,45673,45675,45678,45685,45689,45692,45693,45696,45697,45700,45701,45702,45703,45704,45705,45713,45714,45715,45719,45722,45740,45932,45933,45940,45941,45942,45943,45944,45945,45970,45971,45973,45974,45991,45992,46746,46747,48074,48150,48664,48665,49687,49688,50922,50923,52099,52100,52101,53289,53836,53837}'::integer[])) OR (cd_veiculo = 420) OR (cd_veiculo = 422) OR (cd_veiculo = 45658) OR (cd_veiculo = 45665) OR (cd_veiculo = 45671) OR (cd_veiculo = 45673) OR (cd_veiculo = 45675) OR (cd_veiculo = 45678) OR (cd_veiculo = 45685) OR (cd_veiculo = 45689) OR (cd_veiculo = 45692) OR (cd_veiculo = 45693) OR (cd_veiculo = 45696) OR (cd_veiculo = 45697) OR (cd_veiculo = 45700) OR (cd_veiculo = 45701) OR (cd_veiculo = 45702) OR (cd_veiculo = 45703) OR (cd_veiculo = 45704) OR (cd_veiculo = 45705) OR (cd_veiculo = 45713) OR (cd_veiculo = 45714) OR (cd_veiculo = 45715) OR (cd_veiculo = 45719) OR (cd_veiculo = 45722) OR (cd_veiculo = 45740) OR (cd_veiculo = 45932) OR (cd_veiculo = 45933) OR (cd_veiculo = 45940) OR (cd_veiculo = 45941) OR (cd_veiculo = 45942) OR (cd_veiculo = 45943) OR (cd_veiculo = 45944) OR (cd_veiculo = 45945) OR (cd_veiculo = 45970) OR (cd_veiculo = 45971) OR (cd_veiculo = 45973) OR (cd_veiculo = 45974) OR (cd_veiculo = 45991) OR (cd_veiculo = 45992) OR (cd_veiculo = 46746) OR (cd_veiculo = 46747) OR (cd_veiculo = 48074) OR (cd_veiculo = 48150) OR (cd_veiculo = 48664) OR (cd_veiculo = 48665) OR (cd_veiculo = 49687) OR (cd_veiculo = 49688) OR (cd_veiculo = 50922) OR (cd_veiculo = 50923) OR (cd_veiculo = 52099) OR (cd_veiculo = 52100) OR (cd_veiculo = 52101) OR (cd_veiculo = 53289) OR (cd_veiculo = 53836) OR (cd_veiculo = 53837))
36. 0.045 97.589 ↑ 1.6 112 1

Hash (cost=3.56..3.56 rows=178 width=36) (actual time=97.589..97.589 rows=112 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 16kB
37. 97.544 97.544 ↑ 1.6 112 1

CTE Scan on with_ultimo_documento wud (cost=0.00..3.56 rows=178 width=36) (actual time=97.379..97.544 rows=112 loops=1)

38. 1.324 3.091 ↑ 1.0 5,729 1

Hash (cost=114.29..114.29 rows=5,729 width=20) (actual time=3.091..3.091 rows=5,729 loops=1)

  • Buckets: 8192 Batches: 1 Memory Usage: 353kB
39. 1.767 1.767 ↑ 1.0 5,729 1

Seq Scan on cidade ci (cost=0.00..114.29 rows=5,729 width=20) (actual time=0.013..1.767 rows=5,729 loops=1)

40.          

CTE with_faturamento_ctrc

41. 28.090 383.263 ↓ 10.3 2,055 1

HashAggregate (cost=9,454.25..9,456.75 rows=200 width=36) (actual time=382.114..383.263 rows=2,055 loops=1)

  • Group Key: wvfd_1.cd_ficha
42. 7.718 355.173 ↑ 5.7 18,996 1

Hash Join (cost=3,800.71..6,457.77 rows=108,963 width=36) (actual time=330.429..355.173 rows=18,996 loops=1)

  • Hash Cond: (v_3.cd_viagem = vr_2.cd_viagem)
43. 17.141 295.636 ↑ 3.6 2,136 1

Hash Join (cost=1,415.28..2,400.26 rows=7,766 width=8) (actual time=278.579..295.636 rows=2,136 loops=1)

  • Hash Cond: (v_3.cd_veiculo = wvfd_1.cd_veiculo)
  • Join Filter: (v_3.dt_saida < (wvfd_1.dt_evento)::date)
  • Rows Removed by Join Filter: 62552
44. 0.583 0.583 ↑ 1.0 107 1

Seq Scan on viagem v_3 (cost=0.00..52.76 rows=107 width=12) (actual time=0.499..0.583 rows=107 loops=1)

  • Filter: (dt_chegada IS NULL)
  • Rows Removed by Filter: 1969
45. 23.995 277.912 ↓ 1.5 65,567 1

Hash (cost=870.94..870.94 rows=43,547 width=16) (actual time=277.912..277.912 rows=65,567 loops=1)

  • Buckets: 131072 (originally 65536) Batches: 2 (originally 1) Memory Usage: 3073kB
46. 253.917 253.917 ↓ 1.5 65,567 1

CTE Scan on with_veiculo_ficha_diaria wvfd_1 (cost=0.00..870.94 rows=43,547 width=16) (actual time=0.002..253.917 rows=65,567 loops=1)

47. 10.095 51.819 ↑ 1.0 29,128 1

Hash (cost=2,021.33..2,021.33 rows=29,128 width=36) (actual time=51.819..51.819 rows=29,128 loops=1)

  • Buckets: 32768 Batches: 1 Memory Usage: 2265kB
48. 24.008 41.724 ↑ 1.0 29,128 1

Hash Left Join (cost=667.32..2,021.33 rows=29,128 width=36) (actual time=12.928..41.724 rows=29,128 loops=1)

  • Hash Cond: (vr_2.cd_viagem_receita = vrs.cd_viagem_receita)
49. 4.855 4.855 ↑ 1.0 29,128 1

Seq Scan on viagem_receita vr_2 (cost=0.00..986.28 rows=29,128 width=32) (actual time=0.016..4.855 rows=29,128 loops=1)

50. 4.867 12.861 ↑ 1.0 19,792 1

Hash (cost=419.92..419.92 rows=19,792 width=12) (actual time=12.861..12.861 rows=19,792 loops=1)

  • Buckets: 32768 Batches: 1 Memory Usage: 1161kB
51. 7.994 7.994 ↑ 1.0 19,792 1

Seq Scan on viagem_receita_saldo vrs (cost=0.00..419.92 rows=19,792 width=12) (actual time=0.025..7.994 rows=19,792 loops=1)

52.          

CTE with_viagem_receita

53. 0.002 22.471 ↓ 0.0 0 1

GroupAggregate (cost=1,141.81..1,141.87 rows=1 width=8) (actual time=22.471..22.471 rows=0 loops=1)

  • Group Key: wvfd_2.cd_ficha
54. 0.005 22.469 ↓ 0.0 0 1

Sort (cost=1,141.81..1,141.83 rows=7 width=8) (actual time=22.469..22.469 rows=0 loops=1)

  • Sort Key: wvfd_2.cd_ficha
  • Sort Method: quicksort Memory: 25kB
55. 0.000 22.464 ↓ 0.0 0 1

Nested Loop (cost=4.70..1,141.71 rows=7 width=8) (actual time=22.464..22.464 rows=0 loops=1)

56. 0.001 22.464 ↓ 0.0 0 1

Nested Loop (cost=4.42..904.87 rows=1 width=8) (actual time=22.464..22.464 rows=0 loops=1)

57. 22.463 22.463 ↓ 0.0 0 1

CTE Scan on with_veiculo_ficha_diaria wvfd_2 (cost=0.00..870.94 rows=1 width=16) (actual time=22.463..22.463 rows=0 loops=1)

  • Filter: ((cd_ctrc IS NULL) AND (cd_ordem_carregamento IS NULL) AND (cd_viagem_receita IS NULL))
  • Rows Removed by Filter: 65567
58. 0.000 0.000 ↓ 0.0 0

Bitmap Heap Scan on viagem vi_1 (cost=4.42..33.92 rows=1 width=12) (never executed)

  • Recheck Cond: (cd_veiculo = wvfd_2.cd_veiculo)
  • Filter: ((dt_chegada IS NULL) AND (dt_saida <= (wvfd_2.dt_evento)::date))
59. 0.000 0.000 ↓ 0.0 0

Bitmap Index Scan on idx_viagem_cd_veiculo (cost=0.00..4.42 rows=18 width=0) (never executed)

  • Index Cond: (cd_veiculo = wvfd_2.cd_veiculo)
60. 0.000 0.000 ↓ 0.0 0

Index Scan using idx_viagem_receita_dt_embarque_cd_viagem on viagem_receita vr_3 (cost=0.29..236.77 rows=7 width=8) (never executed)

  • Index Cond: (cd_viagem = vi_1.cd_viagem)
  • Filter: CASE WHEN ((COALESCE(vl_diaria, '0'::numeric) > '0'::numeric) AND (COALESCE(vl_frete, '0'::numeric) = '0'::numeric)) THEN false ELSE true END
61.          

CTE with_veiculo_usuario

62. 0.140 0.203 ↑ 3.7 56 1

Seq Scan on veiculo_proprio vp_1 (cost=6.54..16.75 rows=208 width=4) (actual time=0.112..0.203 rows=56 loops=1)

  • Filter: CASE WHEN ($14 IS NOT NULL) THEN (hashed SubPlan 8) ELSE true END
  • Rows Removed by Filter: 361
63.          

Initplan (forSeq Scan)

64. 0.002 0.013 ↑ 1.0 1 1

Limit (cost=0.00..1.16 rows=1 width=4) (actual time=0.013..0.013 rows=1 loops=1)

65. 0.011 0.011 ↑ 1.0 1 1

Seq Scan on grupo_veiculo_pessoa gvp_ (cost=0.00..1.16 rows=1 width=4) (actual time=0.011..0.011 rows=1 loops=1)

  • Filter: (cd_pessoa = 419)
  • Rows Removed by Filter: 4
66.          

SubPlan (forSeq Scan)

67. 0.020 0.050 ↓ 1.2 56 1

Nested Loop (cost=0.00..5.26 rows=46 width=4) (actual time=0.025..0.050 rows=56 loops=1)

  • Join Filter: (gv_.cd_grupo = gvv_.cd_grupo)
  • Rows Removed by Join Filter: 35
68. 0.001 0.009 ↑ 1.0 1 1

Nested Loop (cost=0.00..2.21 rows=1 width=8) (actual time=0.008..0.009 rows=1 loops=1)

  • Join Filter: (gv_.cd_grupo = gvp__1.cd_grupo)
  • Rows Removed by Join Filter: 1
69. 0.004 0.004 ↑ 1.0 1 1

Seq Scan on grupo_veiculo_pessoa gvp__1 (cost=0.00..1.16 rows=1 width=4) (actual time=0.002..0.004 rows=1 loops=1)

  • Filter: (cd_pessoa = 419)
  • Rows Removed by Filter: 12
70. 0.004 0.004 ↑ 1.0 2 1

Seq Scan on grupo_veiculo gv_ (cost=0.00..1.02 rows=2 width=4) (actual time=0.004..0.004 rows=2 loops=1)

  • Filter: (id_ativo = 1)
71. 0.021 0.021 ↑ 1.0 91 1

Seq Scan on grupo_veiculo_veiculo gvv_ (cost=0.00..1.91 rows=91 width=8) (actual time=0.010..0.021 rows=91 loops=1)

72.          

CTE with_veiculo_conjunto

73. 0.202 16.921 ↑ 1.2 214 1

WindowAgg (cost=543.51..549.79 rows=251 width=20) (actual time=16.700..16.921 rows=214 loops=1)

74. 0.152 16.719 ↑ 1.2 214 1

Sort (cost=543.51..544.14 rows=251 width=12) (actual time=16.693..16.719 rows=214 loops=1)

  • Sort Key: vc.cd_veiculo, (COALESCE((vc.nr_ordem)::integer, 0)), vc.cd_veiculo_conjunto
  • Sort Method: quicksort Memory: 35kB
75. 2.205 16.567 ↑ 1.2 214 1

Hash Join (cost=14.38..533.51 rows=251 width=12) (actual time=0.410..16.567 rows=214 loops=1)

  • Hash Cond: (vc.cd_veiculo = vp_2.cd_veiculo)
76. 14.177 14.177 ↓ 2.6 13,917 1

Seq Scan on veiculo_conjunto vc (cost=0.00..450.99 rows=5,348 width=10) (actual time=0.026..14.177 rows=13,917 loops=1)

  • Filter: ((dt_alteracao <= CURRENT_DATE) AND (COALESCE(dt_alteracao_final, CURRENT_DATE) >= CURRENT_DATE))
  • Rows Removed by Filter: 2127
77. 0.090 0.185 ↑ 1.0 417 1

Hash (cost=9.17..9.17 rows=417 width=4) (actual time=0.185..0.185 rows=417 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 23kB
78. 0.095 0.095 ↑ 1.0 417 1

Seq Scan on veiculo_proprio vp_2 (cost=0.00..9.17 rows=417 width=4) (actual time=0.004..0.095 rows=417 loops=1)

79.          

CTE with_tipo_veiculo_conjunto

80. 5.932 44.205 ↑ 1.0 417 1

Nested Loop Left Join (cost=1.16..2,278.04 rows=417 width=20) (actual time=18.598..44.205 rows=417 loops=1)

  • Join Filter: (wvc1.cd_veiculo = vcav.cd_veiculo)
  • Rows Removed by Join Filter: 41184
81. 7.074 33.686 ↑ 1.0 417 1

Nested Loop Left Join (cost=0.87..2,257.82 rows=417 width=16) (actual time=18.019..33.686 rows=417 loops=1)

  • Join Filter: (wvc2.cd_veiculo = vcav.cd_veiculo)
  • Rows Removed by Join Filter: 36192
82. 2.049 22.442 ↑ 1.0 417 1

Nested Loop Left Join (cost=0.58..2,237.61 rows=417 width=12) (actual time=17.344..22.442 rows=417 loops=1)

  • Join Filter: (wvc3.cd_veiculo = vcav.cd_veiculo)
  • Rows Removed by Join Filter: 11648
83. 0.255 2.045 ↑ 1.0 417 1

Nested Loop (cost=0.29..2,217.40 rows=417 width=8) (actual time=0.054..2.045 rows=417 loops=1)

84. 0.122 0.122 ↑ 1.0 417 1

Seq Scan on veiculo_proprio vcavp (cost=0.00..9.17 rows=417 width=4) (actual time=0.023..0.122 rows=417 loops=1)

85. 1.668 1.668 ↑ 1.0 1 417

Index Scan using pk_veiculo on veiculo vcav (cost=0.29..5.30 rows=1 width=8) (actual time=0.004..0.004 rows=1 loops=417)

  • Index Cond: (cd_veiculo = vcavp.cd_veiculo)
86. 1.082 18.348 ↓ 28.0 28 417

Materialize (cost=0.29..13.96 rows=1 width=8) (actual time=0.040..0.044 rows=28 loops=417)

87. 0.027 17.266 ↓ 28.0 28 1

Nested Loop Left Join (cost=0.29..13.96 rows=1 width=8) (actual time=16.732..17.266 rows=28 loops=1)

88. 17.015 17.015 ↓ 28.0 28 1

CTE Scan on with_veiculo_conjunto wvc3 (cost=0.00..5.65 rows=1 width=8) (actual time=16.713..17.015 rows=28 loops=1)

  • Filter: (rank = 3)
  • Rows Removed by Filter: 186
89. 0.224 0.224 ↑ 1.0 1 28

Index Scan using pk_veiculo on veiculo vcar3 (cost=0.29..8.31 rows=1 width=8) (actual time=0.008..0.008 rows=1 loops=28)

  • Index Cond: (cd_veiculo = wvc3.cd_veiculo_conjunto)
90. 3.548 4.170 ↓ 87.0 87 417

Materialize (cost=0.29..13.96 rows=1 width=8) (actual time=0.000..0.010 rows=87 loops=417)

91. 0.137 0.622 ↓ 87.0 87 1

Nested Loop Left Join (cost=0.29..13.96 rows=1 width=8) (actual time=0.009..0.622 rows=87 loops=1)

92. 0.050 0.050 ↓ 87.0 87 1

CTE Scan on with_veiculo_conjunto wvc2 (cost=0.00..5.65 rows=1 width=8) (actual time=0.001..0.050 rows=87 loops=1)

  • Filter: (rank = 2)
  • Rows Removed by Filter: 127
93. 0.435 0.435 ↑ 1.0 1 87

Index Scan using pk_veiculo on veiculo vcar2 (cost=0.29..8.31 rows=1 width=8) (actual time=0.005..0.005 rows=1 loops=87)

  • Index Cond: (cd_veiculo = wvc2.cd_veiculo_conjunto)
94. 4.067 4.587 ↓ 99.0 99 417

Materialize (cost=0.29..13.96 rows=1 width=8) (actual time=0.000..0.011 rows=99 loops=417)

95. 0.075 0.520 ↓ 99.0 99 1

Nested Loop Left Join (cost=0.29..13.96 rows=1 width=8) (actual time=0.008..0.520 rows=99 loops=1)

96. 0.049 0.049 ↓ 99.0 99 1

CTE Scan on with_veiculo_conjunto wvc1 (cost=0.00..5.65 rows=1 width=8) (actual time=0.001..0.049 rows=99 loops=1)

  • Filter: (rank = 1)
  • Rows Removed by Filter: 115
97. 0.396 0.396 ↑ 1.0 1 99

Index Scan using pk_veiculo on veiculo vcar1 (cost=0.29..8.31 rows=1 width=8) (actual time=0.004..0.004 rows=1 loops=99)

  • Index Cond: (cd_veiculo = wvc1.cd_veiculo_conjunto)
98.          

CTE with_dias_viagem

99. 0.447 0.988 ↑ 1.0 536 1

WindowAgg (cost=35.74..46.46 rows=536 width=20) (actual time=0.490..0.988 rows=536 loops=1)

100. 0.347 0.541 ↑ 1.0 536 1

Sort (cost=35.74..37.08 rows=536 width=12) (actual time=0.481..0.541 rows=536 loops=1)

  • Sort Key: ff.cd_pessoa, ff.dt_final DESC
  • Sort Method: quicksort Memory: 50kB
101. 0.194 0.194 ↑ 1.0 536 1

Seq Scan on funcionario_folga ff (cost=0.00..11.44 rows=536 width=12) (actual time=0.018..0.194 rows=536 loops=1)

  • Filter: (dt_final IS NOT NULL)
  • Rows Removed by Filter: 8
102.          

CTE with_dias_folga

103. 0.013 0.199 ↑ 1.0 8 1

WindowAgg (cost=14.28..14.44 rows=8 width=20) (actual time=0.190..0.199 rows=8 loops=1)

104. 0.015 0.186 ↑ 1.0 8 1

Sort (cost=14.28..14.30 rows=8 width=12) (actual time=0.185..0.186 rows=8 loops=1)

  • Sort Key: ff_1.cd_pessoa, ff_1.dt_inicio DESC
  • Sort Method: quicksort Memory: 25kB
105. 0.171 0.171 ↑ 1.0 8 1

Seq Scan on funcionario_folga ff_1 (cost=0.00..14.16 rows=8 width=12) (actual time=0.164..0.171 rows=8 loops=1)

  • Filter: ((dt_final IS NULL) OR (dt_final > CURRENT_TIMESTAMP))
  • Rows Removed by Filter: 536
106.          

CTE with_ultima_abastecida_tc

107. 14.117 279.837 ↓ 925.8 15,739 1

WindowAgg (cost=2,113.46..2,113.84 rows=17 width=64) (actual time=263.923..279.837 rows=15,739 loops=1)

108. 13.414 265.720 ↓ 925.8 15,739 1

Sort (cost=2,113.46..2,113.50 rows=17 width=56) (actual time=263.913..265.720 rows=15,739 loops=1)

  • Sort Key: cvi.cd_viagem, (COALESCE(cve.dt_abastecimento, c_1.dt_documento)) DESC, cvi.cd_caixa
  • Sort Method: quicksort Memory: 1614kB
109. 18.049 252.306 ↓ 925.8 15,739 1

GroupAggregate (cost=2,112.65..2,113.11 rows=17 width=56) (actual time=232.188..252.306 rows=15,739 loops=1)

  • Group Key: cvi.cd_viagem, cvi.cd_caixa, cve.dt_abastecimento, c_1.cd_caixa
110. 16.645 234.257 ↓ 935.4 15,901 1

Sort (cost=2,112.65..2,112.69 rows=17 width=25) (actual time=232.172..234.257 rows=15,901 loops=1)

  • Sort Key: cvi.cd_viagem, cvi.cd_caixa, cve.dt_abastecimento
  • Sort Method: quicksort Memory: 1627kB
111. 13.378 217.612 ↓ 935.4 15,901 1

Nested Loop (cost=84.70..2,112.30 rows=17 width=25) (actual time=0.863..217.612 rows=15,901 loops=1)

112. 17.291 170.842 ↓ 388.3 16,696 1

Nested Loop (cost=84.41..2,098.57 rows=43 width=25) (actual time=0.837..170.842 rows=16,696 loops=1)

  • Join Filter: (cve.cd_caixa = c_1.cd_caixa)
113. 7.435 103.463 ↓ 287.9 16,696 1

Nested Loop (cost=84.12..2,069.76 rows=58 width=17) (actual time=0.815..103.463 rows=16,696 loops=1)

114. 18.478 32.476 ↓ 264.8 21,184 1

Hash Join (cost=83.83..2,042.19 rows=80 width=9) (actual time=0.769..32.476 rows=21,184 loops=1)

  • Hash Cond: (cp.cd_produto = pc.cd_produto)
115. 13.252 13.252 ↑ 1.0 57,083 1

Seq Scan on caixa_produto cp (cost=0.00..1,237.83 rows=57,083 width=13) (actual time=0.012..13.252 rows=57,083 loops=1)

116. 0.007 0.746 ↓ 1.6 8 1

Hash (cost=83.76..83.76 rows=5 width=4) (actual time=0.746..0.746 rows=8 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
117. 0.739 0.739 ↓ 1.6 8 1

Seq Scan on produto_consumo pc (cost=0.00..83.76 rows=5 width=4) (actual time=0.022..0.739 rows=8 loops=1)

  • Filter: (id_combustivel = 1)
  • Rows Removed by Filter: 3573
118. 63.552 63.552 ↑ 1.0 1 21,184

Index Scan using pk_caixa_veiculo on caixa_veiculo cve (cost=0.29..0.34 rows=1 width=8) (actual time=0.003..0.003 rows=1 loops=21,184)

  • Index Cond: (cd_caixa = cp.cd_caixa)
  • Filter: (id_tanque_cheio = 1)
  • Rows Removed by Filter: 0
119. 50.088 50.088 ↑ 1.0 1 16,696

Index Scan using pk_caixa on caixa c_1 (cost=0.29..0.48 rows=1 width=8) (actual time=0.003..0.003 rows=1 loops=16,696)

  • Index Cond: (cd_caixa = cp.cd_caixa)
120. 33.392 33.392 ↑ 1.0 1 16,696

Index Only Scan using pk_caixa_viagem on caixa_viagem cvi (cost=0.29..0.31 rows=1 width=8) (actual time=0.002..0.002 rows=1 loops=16,696)

  • Index Cond: (cd_caixa = c_1.cd_caixa)
  • Heap Fetches: 0
121. 0.225 1,388.901 ↑ 1.9 54 1

Sort (cost=5,479.16..5,479.42 rows=105 width=702) (actual time=1,388.874..1,388.901 rows=54 loops=1)

  • Sort Key: wvfd.dt_evento DESC
  • Sort Method: quicksort Memory: 73kB
122. 0.898 1,388.676 ↑ 1.9 54 1

Hash Left Join (cost=1,440.41..5,475.63 rows=105 width=702) (actual time=1,349.343..1,388.676 rows=54 loops=1)

  • Hash Cond: (vi.cd_viagem = wuat.cd_viagem)
123. 0.069 1,099.260 ↑ 1.9 54 1

Hash Left Join (cost=1,440.02..5,464.33 rows=105 width=425) (actual time=1,060.777..1,099.260 rows=54 loops=1)

  • Hash Cond: (wvfd.cd_pessoa_motorista = wdf.cd_pessoa)
124. 0.085 1,098.981 ↑ 1.9 54 1

Hash Left Join (cost=1,439.83..5,463.74 rows=105 width=421) (actual time=1,060.554..1,098.981 rows=54 loops=1)

  • Hash Cond: (wvfd.cd_pessoa_motorista = wdv.cd_pessoa)
125. 0.129 1,097.651 ↑ 1.9 54 1

Nested Loop Left Join (cost=1,427.73..5,451.23 rows=105 width=413) (actual time=1,059.294..1,097.651 rows=54 loops=1)

126. 0.083 1,097.360 ↑ 1.9 54 1

Nested Loop Left Join (cost=1,427.45..5,419.41 rows=105 width=405) (actual time=1,059.280..1,097.360 rows=54 loops=1)

127. 0.235 1,097.007 ↑ 1.9 54 1

Hash Left Join (cost=1,427.16..5,375.47 rows=105 width=384) (actual time=1,059.272..1,097.007 rows=54 loops=1)

  • Hash Cond: (COALESCE(wvfd.cd_viagem_receita, wvr.cd_viagem_receita, (SubPlan 17)) = vr.cd_viagem_receita)
128. 0.068 1,070.217 ↑ 1.9 54 1

Hash Left Join (cost=76.78..3,984.84 rows=105 width=375) (actual time=1,039.703..1,070.217 rows=54 loops=1)

  • Hash Cond: (wvfd.cd_ficha = wvr.cd_ficha)
129. 0.083 1,047.676 ↑ 1.9 54 1

Hash Left Join (cost=76.75..3,984.41 rows=105 width=371) (actual time=1,017.217..1,047.676 rows=54 loops=1)

  • Hash Cond: (COALESCE(ct.cd_pessoa_matriz, oc.cd_pessoa_matriz, ve.cd_pessoa_transportadora_doc) = weg.cd_pessoa)
130. 0.064 1,047.529 ↑ 1.9 54 1

Nested Loop Left Join (cost=50.69..3,957.93 rows=105 width=365) (actual time=1,017.144..1,047.529 rows=54 loops=1)

131. 0.123 1,047.411 ↑ 1.9 54 1

Nested Loop Left Join (cost=50.40..3,330.32 rows=105 width=361) (actual time=1,017.140..1,047.411 rows=54 loops=1)

132. 0.049 1,047.126 ↑ 1.9 54 1

Nested Loop Left Join (cost=50.10..2,613.83 rows=105 width=342) (actual time=1,017.128..1,047.126 rows=54 loops=1)

133. 0.061 1,046.969 ↑ 1.9 54 1

Nested Loop Left Join (cost=49.96..2,597.11 rows=105 width=343) (actual time=1,017.123..1,046.969 rows=54 loops=1)

134. 0.094 1,046.692 ↑ 1.9 54 1

Nested Loop Left Join (cost=49.68..2,421.11 rows=105 width=331) (actual time=1,017.111..1,046.692 rows=54 loops=1)

135. 0.095 1,046.490 ↑ 1.9 54 1

Nested Loop Left Join (cost=49.54..2,404.39 rows=105 width=332) (actual time=1,017.102..1,046.490 rows=54 loops=1)

136. 0.096 1,046.071 ↑ 1.9 54 1

Nested Loop Left Join (cost=49.26..2,228.40 rows=105 width=320) (actual time=1,017.086..1,046.071 rows=54 loops=1)

137. 0.098 1,045.435 ↑ 1.9 54 1

Hash Left Join (cost=48.97..1,608.49 rows=105 width=291) (actual time=1,017.053..1,045.435 rows=54 loops=1)

  • Hash Cond: ((wvfd.cd_pessoa_rastreadora = rv.cd_pessoa) AND (ve.cd_veiculo = rv.cd_veiculo))
138. 0.096 1,045.257 ↑ 1.9 54 1

Hash Left Join (cost=44.77..1,602.69 rows=105 width=289) (actual time=1,016.958..1,045.257 rows=54 loops=1)

  • Hash Cond: (wvfd.cd_ficha = wfc.cd_ficha)
139. 0.154 660.258 ↑ 1.9 54 1

Nested Loop Left Join (cost=38.27..1,592.26 rows=105 width=257) (actual time=632.032..660.258 rows=54 loops=1)

  • Join Filter: (((tvc.cd_tipo_veiculo_1 = wtvc.cd_tipo_veiculo_carreta_1) OR (tvc.cd_tipo_veiculo_1 IS NULL)) AND ((tvc.cd_tipo_veiculo_2 = wtvc.cd_tipo_veiculo_carreta_2) OR (tvc.cd_tipo_veiculo_2 IS NULL)) AND ((tvc.cd_tipo_veiculo_3 = wtvc.cd_tipo_veiculo_carreta_3) OR (tvc.cd_tipo_veiculo_3 IS NULL)) AND (tvc.cd_tipo_veiculo = wtvc.cd_tipo_veiculo_cavalo))
  • Rows Removed by Join Filter: 270
140. 0.209 659.996 ↑ 1.9 54 1

Nested Loop (cost=38.27..1,577.01 rows=105 width=264) (actual time=632.000..659.996 rows=54 loops=1)

  • Join Filter: (vp.cd_veiculo = ve.cd_veiculo)
141. 0.154 659.409 ↑ 1.9 54 1

Hash Join (cost=37.98..1,019.66 rows=105 width=260) (actual time=631.988..659.409 rows=54 loops=1)

  • Hash Cond: (wvfd.cd_veiculo = vp.cd_veiculo)
142. 613.949 613.949 ↑ 2.0 110 1

CTE Scan on with_veiculo_ficha_diaria wvfd (cost=0.00..979.81 rows=218 width=198) (actual time=586.660..613.949 rows=110 loops=1)

  • Filter: (rank = 1)
  • Rows Removed by Filter: 65457
143. 0.042 45.306 ↑ 3.6 56 1

Hash (cost=35.45..35.45 rows=202 width=62) (actual time=45.306..45.306 rows=56 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 14kB
144. 0.169 45.264 ↑ 3.6 56 1

Hash Join (cost=23.53..35.45 rows=202 width=62) (actual time=23.305..45.264 rows=56 loops=1)

  • Hash Cond: (wtvc.cd_veiculo_cavalo = vp.cd_veiculo)
145. 44.519 44.519 ↑ 1.0 417 1

CTE Scan on with_tipo_veiculo_conjunto wtvc (cost=0.00..8.34 rows=417 width=20) (actual time=18.600..44.519 rows=417 loops=1)

146. 0.021 0.576 ↑ 3.6 56 1

Hash (cost=21.01..21.01 rows=202 width=42) (actual time=0.576..0.576 rows=56 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 12kB
147. 0.036 0.555 ↑ 3.6 56 1

Hash Join (cost=14.22..21.01 rows=202 width=42) (actual time=0.414..0.555 rows=56 loops=1)

  • Hash Cond: (wvu.cd_veiculo = vp.cd_veiculo)
148. 0.227 0.227 ↑ 3.7 56 1

CTE Scan on with_veiculo_usuario wvu (cost=0.00..4.16 rows=208 width=4) (actual time=0.114..0.227 rows=56 loops=1)

149. 0.109 0.292 ↑ 1.0 404 1

Hash (cost=9.17..9.17 rows=404 width=38) (actual time=0.292..0.292 rows=404 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 28kB
150. 0.183 0.183 ↑ 1.0 404 1

Seq Scan on veiculo_proprio vp (cost=0.00..9.17 rows=404 width=38) (actual time=0.005..0.183 rows=404 loops=1)

  • Filter: (dt_baixa IS NULL)
  • Rows Removed by Filter: 13
151. 0.378 0.378 ↑ 1.0 1 54

Index Scan using pk_veiculo on veiculo ve (cost=0.29..5.30 rows=1 width=16) (actual time=0.007..0.007 rows=1 loops=54)

  • Index Cond: (cd_veiculo = wtvc.cd_veiculo_cavalo)
152. 0.078 0.108 ↑ 1.0 6 54

Materialize (cost=0.00..1.09 rows=6 width=25) (actual time=0.001..0.002 rows=6 loops=54)

153. 0.030 0.030 ↑ 1.0 6 1

Seq Scan on tipo_veiculo_conjunto tvc (cost=0.00..1.06 rows=6 width=25) (actual time=0.022..0.030 rows=6 loops=1)

154. 0.586 384.903 ↓ 10.3 2,055 1

Hash (cost=4.00..4.00 rows=200 width=36) (actual time=384.903..384.903 rows=2,055 loops=1)

  • Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 128kB
155. 384.317 384.317 ↓ 10.3 2,055 1

CTE Scan on with_faturamento_ctrc wfc (cost=0.00..4.00 rows=200 width=36) (actual time=382.118..384.317 rows=2,055 loops=1)

156. 0.034 0.080 ↑ 1.0 128 1

Hash (cost=2.28..2.28 rows=128 width=10) (actual time=0.080..0.080 rows=128 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 14kB
157. 0.046 0.046 ↑ 1.0 128 1

Seq Scan on rastreadora_veiculo rv (cost=0.00..2.28 rows=128 width=10) (actual time=0.017..0.046 rows=128 loops=1)

158. 0.540 0.540 ↑ 1.0 1 54

Index Scan using pk_pessoa on pessoa pm (cost=0.29..5.90 rows=1 width=29) (actual time=0.010..0.010 rows=1 loops=54)

  • Index Cond: (cd_pessoa = wvfd.cd_pessoa_motorista)
159. 0.324 0.324 ↑ 1.0 1 54

Index Scan using pk_cidade on cidade co (cost=0.28..1.68 rows=1 width=20) (actual time=0.006..0.006 rows=1 loops=54)

  • Index Cond: (cd_cidade = wvfd.cd_cidade_origem)
160. 0.108 0.108 ↑ 1.0 1 54

Index Scan using pk_uf on uf uo (cost=0.14..0.16 rows=1 width=7) (actual time=0.002..0.002 rows=1 loops=54)

  • Index Cond: (cd_uf = co.cd_uf)
161. 0.216 0.216 ↑ 1.0 1 54

Index Scan using pk_cidade on cidade cd (cost=0.28..1.68 rows=1 width=20) (actual time=0.004..0.004 rows=1 loops=54)

  • Index Cond: (cd_cidade = wvfd.cd_cidade_destino)
162. 0.108 0.108 ↑ 1.0 1 54

Index Scan using pk_uf on uf ud (cost=0.14..0.16 rows=1 width=7) (actual time=0.002..0.002 rows=1 loops=54)

  • Index Cond: (cd_uf = cd.cd_uf)
163. 0.162 0.162 ↑ 1.0 1 54

Index Scan using pk_ctrc on ctrc ct (cost=0.29..6.82 rows=1 width=23) (actual time=0.003..0.003 rows=1 loops=54)

  • Index Cond: (cd_ctrc = wvfd.cd_ctrc)
164. 0.054 0.054 ↓ 0.0 0 54

Index Scan using pk_ordem_carregamento on ordem_carregamento oc (cost=0.29..5.98 rows=1 width=8) (actual time=0.001..0.001 rows=0 loops=54)

  • Index Cond: (cd_ordem = wvfd.cd_ordem_carregamento)
165. 0.002 0.064 ↑ 1.0 3 1

Hash (cost=26.02..26.02 rows=3 width=22) (actual time=0.064..0.064 rows=3 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
166. 0.003 0.062 ↑ 1.0 3 1

Subquery Scan on weg (cost=25.98..26.02 rows=3 width=22) (actual time=0.060..0.062 rows=3 loops=1)

167. 0.015 0.059 ↑ 1.0 3 1

Sort (cost=25.98..25.99 rows=3 width=22) (actual time=0.059..0.059 rows=3 loops=1)

  • Sort Key: p.nm_fantasia
  • Sort Method: quicksort Memory: 25kB
168. 0.005 0.044 ↑ 1.0 3 1

Nested Loop (cost=0.29..25.96 rows=3 width=22) (actual time=0.021..0.044 rows=3 loops=1)

169. 0.006 0.006 ↑ 1.0 3 1

Seq Scan on empresa_grupo eg (cost=0.00..1.04 rows=3 width=4) (actual time=0.005..0.006 rows=3 loops=1)

  • Filter: (id_ativo = 1)
170. 0.033 0.033 ↑ 1.0 1 3

Index Scan using pk_pessoa on pessoa p (cost=0.29..8.31 rows=1 width=22) (actual time=0.011..0.011 rows=1 loops=3)

  • Index Cond: (cd_pessoa = eg.cd_pessoa)
171. 0.000 22.473 ↓ 0.0 0 1

Hash (cost=0.02..0.02 rows=1 width=8) (actual time=22.473..22.473 rows=0 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 8kB
172. 22.473 22.473 ↓ 0.0 0 1

CTE Scan on with_viagem_receita wvr (cost=0.00..0.02 rows=1 width=8) (actual time=22.473..22.473 rows=0 loops=1)

173. 7.647 19.355 ↑ 1.0 29,128 1

Hash (cost=986.28..986.28 rows=29,128 width=17) (actual time=19.355..19.355 rows=29,128 loops=1)

  • Buckets: 32768 Batches: 1 Memory Usage: 1660kB
174. 11.708 11.708 ↑ 1.0 29,128 1

Seq Scan on viagem_receita vr (cost=0.00..986.28 rows=29,128 width=17) (actual time=0.020..11.708 rows=29,128 loops=1)

175.          

SubPlan (forHash Left Join)

176. 0.180 7.200 ↑ 1.0 1 90

Result (cost=7.40..7.41 rows=1 width=4) (actual time=0.079..0.080 rows=1 loops=90)

177.          

Initplan (forResult)

178. 0.090 7.020 ↑ 1.0 1 90

Limit (cost=0.29..7.40 rows=1 width=4) (actual time=0.078..0.078 rows=1 loops=90)

179. 6.930 6.930 ↑ 256.0 1 90

Index Scan Backward using pk_viagem_receita on viagem_receita vr_ (cost=0.29..1,822.19 rows=256 width=4) (actual time=0.077..0.077 rows=1 loops=90)

  • Index Cond: (cd_viagem_receita IS NOT NULL)
  • Filter: (cd_veiculo = ve.cd_veiculo)
  • Rows Removed by Filter: 183
180. 0.270 0.270 ↑ 1.0 1 54

Index Scan using pk_pessoa on pessoa pp (cost=0.29..0.42 rows=1 width=29) (actual time=0.005..0.005 rows=1 loops=54)

  • Index Cond: (cd_pessoa = vr.cd_pessoa)
181. 0.162 0.162 ↑ 1.0 1 54

Index Scan using pk_viagem on viagem vi (cost=0.28..0.30 rows=1 width=12) (actual time=0.003..0.003 rows=1 loops=54)

  • Index Cond: (cd_viagem = vr.cd_viagem)
182. 0.030 1.245 ↓ 33.0 99 1

Hash (cost=12.06..12.06 rows=3 width=12) (actual time=1.245..1.245 rows=99 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 13kB
183. 1.215 1.215 ↓ 33.0 99 1

CTE Scan on with_dias_viagem wdv (cost=0.00..12.06 rows=3 width=12) (actual time=0.493..1.215 rows=99 loops=1)

  • Filter: (rank = 1)
  • Rows Removed by Filter: 437
184. 0.006 0.210 ↓ 8.0 8 1

Hash (cost=0.18..0.18 rows=1 width=12) (actual time=0.210..0.210 rows=8 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
185. 0.204 0.204 ↓ 8.0 8 1

CTE Scan on with_dias_folga wdf (cost=0.00..0.18 rows=1 width=12) (actual time=0.192..0.204 rows=8 loops=1)

  • Filter: (rank = 1)
186. 0.641 288.518 ↓ 2,023.0 2,023 1

Hash (cost=0.38..0.38 rows=1 width=40) (actual time=288.518..288.518 rows=2,023 loops=1)

  • Buckets: 2048 (originally 1024) Batches: 1 (originally 1) Memory Usage: 111kB
187. 287.877 287.877 ↓ 2,023.0 2,023 1

CTE Scan on with_ultima_abastecida_tc wuat (cost=0.00..0.38 rows=1 width=40) (actual time=263.926..287.877 rows=2,023 loops=1)

  • Filter: (rank = 1)
  • Rows Removed by Filter: 13716
188.          

SubPlan (forResult)

189. 0.054 0.594 ↓ 0.0 0 54

Limit (cost=1.21..1.21 rows=1 width=43) (actual time=0.011..0.011 rows=0 loops=54)

190. 0.324 0.540 ↓ 0.0 0 54

Sort (cost=1.21..1.21 rows=1 width=43) (actual time=0.010..0.010 rows=0 loops=54)

  • Sort Key: vo_.dt_observacao DESC
  • Sort Method: quicksort Memory: 25kB
191. 0.216 0.216 ↓ 0.0 0 54

Seq Scan on veiculo_observacao vo_ (cost=0.00..1.20 rows=1 width=43) (actual time=0.004..0.004 rows=0 loops=54)

  • Filter: (cd_veiculo = vp.cd_veiculo)
  • Rows Removed by Filter: 16
Planning time : 23.176 ms
Execution time : 1,525.175 ms