explain.depesz.com

PostgreSQL's explain analyze made readable

Result: JcX8

Settings
# exclusive inclusive rows x rows loops node
1. 134.806 1,097.883 ↑ 1.9 54 1

Result (cost=90,159.41..90,336.60 rows=105 width=759) (actual time=967.612..1,097.883 rows=54 loops=1)

2.          

CTE with_veiculos_com_rastreamento

3. 7.043 23.720 ↑ 1.0 112 1

Unique (cost=0.29..1,946.14 rows=112 width=4) (actual time=0.074..23.720 rows=112 loops=1)

4. 16.677 16.677 ↓ 1.0 88,564 1

Index Only Scan using idx_veiculo_ficha_diaria_cd_veiculo on veiculo_ficha_diaria vfd (cost=0.29..1,724.73 rows=88,563 width=4) (actual time=0.073..16.677 rows=88,564 loops=1)

  • Heap Fetches: 268
5.          

CTE with_ultimos_documentos_veiculo

6. 0.435 70.071 ↓ 1.7 296 1

HashAggregate (cost=2,547.12..2,548.90 rows=178 width=44) (actual time=69.941..70.071 rows=296 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.039 69.636 ↓ 1.7 296 1

Append (cost=0.58..2,542.67 rows=178 width=44) (actual time=0.180..69.636 rows=296 loops=1)

8. 0.466 26.805 ↓ 2.9 112 1

Nested Loop (cost=0.58..292.65 rows=39 width=44) (actual time=0.179..26.805 rows=112 loops=1)

9. 0.219 24.547 ↑ 1.0 112 1

Nested Loop (cost=0.29..247.88 rows=112 width=8) (actual time=0.097..24.547 rows=112 loops=1)

10. 23.768 23.768 ↑ 1.0 112 1

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

11. 0.560 0.560 ↑ 1.0 1 112

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

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

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

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

Unique (cost=1,932.34..1,963.56 rows=112 width=44) (actual time=37.850..41.509 rows=111 loops=1)

14. 14.067 39.512 ↓ 2.0 12,633 1

Sort (cost=1,932.34..1,947.95 rows=6,244 width=44) (actual time=37.846..39.512 rows=12,633 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: 1371kB
15. 12.662 25.445 ↓ 2.0 12,633 1

Hash Join (cost=3.64..1,538.71 rows=6,244 width=44) (actual time=0.113..25.445 rows=12,633 loops=1)

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

Seq Scan on viagem_receita vr_1 (cost=0.00..1,323.92 rows=6,355 width=32) (actual time=0.032..12.739 rows=12,722 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: 16442
17. 0.025 0.044 ↑ 1.0 112 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 12kB
18. 0.019 0.019 ↑ 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.019 rows=112 loops=1)

19. 0.060 1.283 ↓ 2.7 73 1

Nested Loop (cost=0.58..284.67 rows=27 width=44) (actual time=0.111..1.283 rows=73 loops=1)

20. 0.081 0.439 ↑ 1.0 112 1

Nested Loop (cost=0.29..247.88 rows=112 width=8) (actual time=0.038..0.439 rows=112 loops=1)

21. 0.022 0.022 ↑ 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.022 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..2.19 rows=1 width=8) (actual time=0.003..0.003 rows=1 loops=112)

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

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

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

CTE with_ultimo_documento

25. 0.045 71.221 ↑ 1.6 112 1

Unique (cost=376.25..377.14 rows=178 width=48) (actual time=71.162..71.221 rows=112 loops=1)

26. 0.192 71.176 ↓ 1.7 296 1

Sort (cost=376.25..376.69 rows=178 width=48) (actual time=71.161..71.176 rows=296 loops=1)

  • Sort Key: wudv.cd_veiculo, wudv.dt_documento DESC, wudv.id_prioridade
  • Sort Method: quicksort Memory: 48kB
27. 0.160 70.984 ↓ 1.7 296 1

Nested Loop (cost=0.29..369.60 rows=178 width=48) (actual time=69.978..70.984 rows=296 loops=1)

28. 70.232 70.232 ↓ 1.7 296 1

CTE Scan on with_ultimos_documentos_veiculo wudv (cost=0.00..3.56 rows=178 width=44) (actual time=69.945..70.232 rows=296 loops=1)

29. 0.592 0.592 ↑ 1.0 1 296

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

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

CTE with_veiculo_ficha_diaria

31. 109.198 515.154 ↓ 1.8 76,144 1

WindowAgg (cost=67,753.08..69,056.70 rows=43,454 width=307) (actual time=377.865..515.154 rows=76,144 loops=1)

32. 139.740 405.956 ↓ 1.8 76,144 1

Sort (cost=67,753.08..67,861.71 rows=43,454 width=287) (actual time=377.843..405.956 rows=76,144 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: quicksort Memory: 40524kB
33. 27.002 266.216 ↓ 1.8 76,144 1

Hash Left Join (cost=191.69..64,405.55 rows=43,454 width=287) (actual time=73.593..266.216 rows=76,144 loops=1)

  • Hash Cond: (vfd_1.cd_cidade_posicao = ci.cd_cidade)
34. 97.535 236.996 ↓ 1.8 76,144 1

Hash Left Join (cost=5.79..64,105.49 rows=43,454 width=275) (actual time=71.335..236.996 rows=76,144 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: 12420
35. 68.169 68.169 ↓ 1.4 88,564 1

Seq Scan on veiculo_ficha_diaria vfd_1 (cost=0.00..24,140.86 rows=62,072 width=243) (actual time=0.020..68.169 rows=88,564 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.030 71.292 ↑ 1.6 112 1

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

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

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

38. 1.005 2.218 ↑ 1.0 5,729 1

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

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

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

40.          

CTE with_faturamento_ctrc

41. 26.779 310.271 ↓ 13.1 2,627 1

HashAggregate (cost=9,345.09..9,347.59 rows=200 width=36) (actual time=308.884..310.271 rows=2,627 loops=1)

  • Group Key: wvfd_1.cd_ficha
42. 6.351 283.492 ↑ 4.4 24,928 1

Hash Join (cost=3,701.83..6,355.15 rows=108,725 width=36) (actual time=265.570..283.492 rows=24,928 loops=1)

  • Hash Cond: (v_3.cd_viagem = vr_2.cd_viagem)
43. 11.974 235.104 ↑ 2.8 2,730 1

Hash Join (cost=1,412.26..2,397.15 rows=7,749 width=8) (actual time=223.327..235.104 rows=2,730 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: 73322
44. 0.619 0.619 ↑ 1.0 107 1

Seq Scan on viagem v_3 (cost=0.00..54.76 rows=107 width=12) (actual time=0.435..0.619 rows=107 loops=1)

  • Filter: (dt_chegada IS NULL)
  • Rows Removed by Filter: 1969
45. 19.017 222.511 ↓ 1.8 76,144 1

Hash (cost=869.08..869.08 rows=43,454 width=16) (actual time=222.511..222.511 rows=76,144 loops=1)

  • Buckets: 131072 (originally 65536) Batches: 1 (originally 1) Memory Usage: 4594kB
46. 203.494 203.494 ↓ 1.8 76,144 1

CTE Scan on with_veiculo_ficha_diaria wvfd_1 (cost=0.00..869.08 rows=43,454 width=16) (actual time=0.001..203.494 rows=76,144 loops=1)

47. 8.131 42.037 ↓ 1.0 29,164 1

Hash (cost=1,925.48..1,925.48 rows=29,128 width=36) (actual time=42.037..42.037 rows=29,164 loops=1)

  • Buckets: 32768 Batches: 1 Memory Usage: 2268kB
48. 17.497 33.906 ↓ 1.0 29,164 1

Hash Left Join (cost=670.73..1,925.48 rows=29,128 width=36) (actual time=10.865..33.906 rows=29,164 loops=1)

  • Hash Cond: (vr_2.cd_viagem_receita = vrs.cd_viagem_receita)
49. 5.765 5.765 ↓ 1.0 29,164 1

Seq Scan on viagem_receita vr_2 (cost=0.00..1,178.28 rows=29,128 width=32) (actual time=0.021..5.765 rows=29,164 loops=1)

50. 4.445 10.644 ↓ 1.0 19,828 1

Hash (cost=423.10..423.10 rows=19,810 width=12) (actual time=10.644..10.644 rows=19,828 loops=1)

  • Buckets: 32768 Batches: 1 Memory Usage: 1162kB
51. 6.199 6.199 ↓ 1.0 19,828 1

Seq Scan on viagem_receita_saldo vrs (cost=0.00..423.10 rows=19,810 width=12) (actual time=0.029..6.199 rows=19,828 loops=1)

52.          

CTE with_viagem_receita

53. 0.003 17.428 ↓ 0.0 0 1

GroupAggregate (cost=1,111.13..1,111.19 rows=1 width=8) (actual time=17.428..17.428 rows=0 loops=1)

  • Group Key: wvfd_2.cd_ficha
54. 0.011 17.425 ↓ 0.0 0 1

Sort (cost=1,111.13..1,111.14 rows=7 width=8) (actual time=17.425..17.425 rows=0 loops=1)

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

Nested Loop (cost=1.80..1,111.03 rows=7 width=8) (actual time=17.414..17.414 rows=0 loops=1)

56. 0.003 17.413 ↓ 0.0 0 1

Nested Loop (cost=1.52..886.42 rows=1 width=8) (actual time=17.413..17.413 rows=0 loops=1)

57. 17.410 17.410 ↓ 0.0 0 1

CTE Scan on with_veiculo_ficha_diaria wvfd_2 (cost=0.00..869.08 rows=1 width=16) (actual time=17.410..17.410 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: 76144
58. 0.000 0.000 ↓ 0.0 0

Bitmap Heap Scan on viagem vi_1 (cost=1.52..17.33 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..1.52 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..224.53 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.123 0.183 ↑ 3.7 56 1

Seq Scan on veiculo_proprio vp_1 (cost=6.54..16.75 rows=208 width=4) (actual time=0.108..0.183 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.003 0.016 ↑ 1.0 1 1

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

65. 0.013 0.013 ↑ 1.0 1 1

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

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

SubPlan (forSeq Scan)

67. 0.013 0.044 ↓ 1.2 56 1

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

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

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

  • Join Filter: (gv_.cd_grupo = gvp__1.cd_grupo)
  • Rows Removed by Join Filter: 1
69. 0.003 0.003 ↑ 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.003 rows=1 loops=1)

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

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

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

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

72.          

CTE with_veiculo_conjunto

73. 0.134 2.501 ↑ 1.2 214 1

WindowAgg (cost=318.54..324.81 rows=251 width=20) (actual time=2.368..2.501 rows=214 loops=1)

74. 0.109 2.367 ↑ 1.2 214 1

Sort (cost=318.54..319.16 rows=251 width=12) (actual time=2.355..2.367 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. 0.102 2.258 ↑ 1.2 214 1

Nested Loop (cost=0.29..308.53 rows=251 width=12) (actual time=0.187..2.258 rows=214 loops=1)

76. 0.071 0.071 ↑ 1.0 417 1

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

77. 2.085 2.085 ↑ 1.0 1 417

Index Scan using idx_veiculo_conjunto_cd_veiculo on veiculo_conjunto vc (cost=0.29..0.71 rows=1 width=10) (actual time=0.004..0.005 rows=1 loops=417)

  • Index Cond: (cd_veiculo = vp_2.cd_veiculo)
  • Filter: ((dt_alteracao <= CURRENT_DATE) AND (COALESCE(dt_alteracao_final, CURRENT_DATE) >= CURRENT_DATE))
  • Rows Removed by Filter: 2
78.          

CTE with_tipo_veiculo_conjunto

79. 4.080 20.428 ↑ 1.0 417 1

Nested Loop Left Join (cost=1.16..754.84 rows=417 width=20) (actual time=3.938..20.428 rows=417 loops=1)

  • Join Filter: (wvc1.cd_veiculo = vcav.cd_veiculo)
  • Rows Removed by Join Filter: 41184
80. 3.496 13.429 ↑ 1.0 417 1

Nested Loop Left Join (cost=0.87..740.42 rows=417 width=16) (actual time=3.532..13.429 rows=417 loops=1)

  • Join Filter: (wvc2.cd_veiculo = vcav.cd_veiculo)
  • Rows Removed by Join Filter: 36192
81. 1.087 7.014 ↑ 1.0 417 1

Nested Loop Left Join (cost=0.58..726.01 rows=417 width=12) (actual time=2.952..7.014 rows=417 loops=1)

  • Join Filter: (wvc3.cd_veiculo = vcav.cd_veiculo)
  • Rows Removed by Join Filter: 11648
82. 0.394 2.174 ↑ 1.0 417 1

Nested Loop (cost=0.29..711.60 rows=417 width=8) (actual time=0.068..2.174 rows=417 loops=1)

83. 0.112 0.112 ↑ 1.0 417 1

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

84. 1.668 1.668 ↑ 1.0 1 417

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

  • Index Cond: (cd_veiculo = vcavp.cd_veiculo)
85. 0.891 3.753 ↓ 28.0 28 417

Materialize (cost=0.29..8.16 rows=1 width=8) (actual time=0.006..0.009 rows=28 loops=417)

86. 0.015 2.862 ↓ 28.0 28 1

Nested Loop Left Join (cost=0.29..8.16 rows=1 width=8) (actual time=2.404..2.862 rows=28 loops=1)

87. 2.567 2.567 ↓ 28.0 28 1

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

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

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

  • Index Cond: (cd_veiculo = wvc3.cd_veiculo_conjunto)
89. 2.363 2.919 ↓ 87.0 87 417

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

90. 0.006 0.556 ↓ 87.0 87 1

Nested Loop Left Join (cost=0.29..8.16 rows=1 width=8) (actual time=0.023..0.556 rows=87 loops=1)

91. 0.028 0.028 ↓ 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.028 rows=87 loops=1)

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

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

  • Index Cond: (cd_veiculo = wvc2.cd_veiculo_conjunto)
93. 2.552 2.919 ↓ 99.0 99 417

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

94. 0.043 0.367 ↓ 99.0 99 1

Nested Loop Left Join (cost=0.29..8.16 rows=1 width=8) (actual time=0.011..0.367 rows=99 loops=1)

95. 0.027 0.027 ↓ 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.027 rows=99 loops=1)

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

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

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

CTE with_dias_viagem

98. 0.285 0.678 ↑ 1.1 536 1

WindowAgg (cost=41.22..53.34 rows=606 width=20) (actual time=0.359..0.678 rows=536 loops=1)

99. 0.234 0.393 ↑ 1.1 536 1

Sort (cost=41.22..42.73 rows=606 width=12) (actual time=0.346..0.393 rows=536 loops=1)

  • Sort Key: ff.cd_pessoa, ff.dt_final DESC
  • Sort Method: quicksort Memory: 50kB
100. 0.159 0.159 ↑ 1.1 536 1

Seq Scan on funcionario_folga ff (cost=0.00..13.21 rows=606 width=12) (actual time=0.027..0.159 rows=536 loops=1)

  • Filter: (dt_final IS NOT NULL)
  • Rows Removed by Filter: 10
101.          

CTE with_dias_folga

102. 0.015 0.133 ↑ 1.5 10 1

WindowAgg (cost=16.61..16.91 rows=15 width=20) (actual time=0.127..0.133 rows=10 loops=1)

103. 0.013 0.118 ↑ 1.5 10 1

Sort (cost=16.61..16.65 rows=15 width=12) (actual time=0.117..0.118 rows=10 loops=1)

  • Sort Key: ff_1.cd_pessoa, ff_1.dt_inicio DESC
  • Sort Method: quicksort Memory: 25kB
104. 0.105 0.105 ↑ 1.5 10 1

Seq Scan on funcionario_folga ff_1 (cost=0.00..16.31 rows=15 width=12) (actual time=0.100..0.105 rows=10 loops=1)

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

CTE with_ultima_abastecida_tc

106. 8.970 192.220 ↓ 927.6 15,770 1

WindowAgg (cost=1,540.20..1,540.58 rows=17 width=64) (actual time=181.977..192.220 rows=15,770 loops=1)

107. 8.227 183.250 ↓ 927.6 15,770 1

Sort (cost=1,540.20..1,540.24 rows=17 width=56) (actual time=181.958..183.250 rows=15,770 loops=1)

  • Sort Key: cvi.cd_viagem, (COALESCE(cve.dt_abastecimento, c_1.dt_documento)) DESC, cvi.cd_caixa
  • Sort Method: quicksort Memory: 1617kB
108. 9.352 175.023 ↓ 927.6 15,770 1

GroupAggregate (cost=1,539.38..1,539.85 rows=17 width=56) (actual time=164.295..175.023 rows=15,770 loops=1)

  • Group Key: cvi.cd_viagem, cvi.cd_caixa, cve.dt_abastecimento, c_1.cd_caixa
109. 11.276 165.671 ↓ 937.2 15,933 1

Sort (cost=1,539.38..1,539.43 rows=17 width=25) (actual time=164.274..165.671 rows=15,933 loops=1)

  • Sort Key: cvi.cd_viagem, cvi.cd_caixa, cve.dt_abastecimento
  • Sort Method: quicksort Memory: 1629kB
110. 5.225 154.395 ↓ 937.2 15,933 1

Nested Loop (cost=86.57..1,539.04 rows=17 width=25) (actual time=0.936..154.395 rows=15,933 loops=1)

111. 16.786 115.712 ↓ 380.2 16,729 1

Nested Loop (cost=86.28..1,525.02 rows=44 width=25) (actual time=0.886..115.712 rows=16,729 loops=1)

  • Join Filter: (cve.cd_caixa = c_1.cd_caixa)
112. 2.003 65.468 ↓ 288.4 16,729 1

Nested Loop (cost=85.99..1,503.47 rows=58 width=17) (actual time=0.855..65.468 rows=16,729 loops=1)

113. 10.348 21.011 ↓ 265.3 21,227 1

Hash Join (cost=85.70..1,477.90 rows=80 width=9) (actual time=0.806..21.011 rows=21,227 loops=1)

  • Hash Cond: (cp.cd_produto = pc.cd_produto)
114. 9.894 9.894 ↓ 1.0 57,262 1

Seq Scan on caixa_produto cp (cost=0.00..1,241.90 rows=57,190 width=13) (actual time=0.020..9.894 rows=57,262 loops=1)

115. 0.005 0.769 ↓ 1.6 8 1

Hash (cost=85.64..85.64 rows=5 width=4) (actual time=0.769..0.769 rows=8 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
116. 0.764 0.764 ↓ 1.6 8 1

Seq Scan on produto_consumo pc (cost=0.00..85.64 rows=5 width=4) (actual time=0.025..0.764 rows=8 loops=1)

  • Filter: (id_combustivel = 1)
  • Rows Removed by Filter: 3578
117. 42.454 42.454 ↑ 1.0 1 21,227

Index Scan using pk_caixa_veiculo on caixa_veiculo cve (cost=0.29..0.32 rows=1 width=8) (actual time=0.002..0.002 rows=1 loops=21,227)

  • Index Cond: (cd_caixa = cp.cd_caixa)
  • Filter: (id_tanque_cheio = 1)
  • Rows Removed by Filter: 0
118. 33.458 33.458 ↑ 1.0 1 16,729

Index Scan using pk_caixa on caixa c_1 (cost=0.29..0.36 rows=1 width=8) (actual time=0.002..0.002 rows=1 loops=16,729)

  • Index Cond: (cd_caixa = cp.cd_caixa)
119. 33.458 33.458 ↑ 1.0 1 16,729

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,729)

  • Index Cond: (cd_caixa = c_1.cd_caixa)
  • Heap Fetches: 15957
120. 0.295 962.267 ↑ 1.9 54 1

Sort (cost=3,064.54..3,064.80 rows=105 width=701) (actual time=962.220..962.267 rows=54 loops=1)

  • Sort Key: wvfd.dt_evento DESC
  • Sort Method: quicksort Memory: 71kB
121. 0.841 961.972 ↑ 1.9 54 1

Hash Left Join (cost=65.12..3,061.02 rows=105 width=701) (actual time=927.703..961.972 rows=54 loops=1)

  • Hash Cond: (vi.cd_viagem = wuat.cd_viagem)
122. 0.079 763.138 ↑ 1.9 54 1

Hash Left Join (cost=64.73..3,049.72 rows=105 width=424) (actual time=729.548..763.138 rows=54 loops=1)

  • Hash Cond: (wvfd.cd_pessoa_motorista = wdf.cd_pessoa)
123. 0.410 762.914 ↑ 1.9 54 1

Nested Loop Left Join (cost=64.38..3,048.96 rows=105 width=420) (actual time=729.377..762.914 rows=54 loops=1)

  • Join Filter: (wdv.cd_pessoa = wvfd.cd_pessoa_motorista)
  • Rows Removed by Join Filter: 5295
124. 0.086 758.886 ↑ 1.9 54 1

Nested Loop Left Join (cost=64.38..3,028.27 rows=105 width=412) (actual time=728.876..758.886 rows=54 loops=1)

125. 0.075 758.476 ↑ 1.9 54 1

Nested Loop Left Join (cost=64.10..2,996.87 rows=105 width=404) (actual time=728.840..758.476 rows=54 loops=1)

126. 5.210 758.077 ↑ 1.9 54 1

Nested Loop Left Join (cost=63.81..2,961.33 rows=105 width=383) (actual time=728.824..758.077 rows=54 loops=1)

127. 0.068 752.705 ↑ 1.9 54 1

Hash Left Join (cost=57.07..2,020.85 rows=105 width=374) (actual time=728.770..752.705 rows=54 loops=1)

  • Hash Cond: (wvfd.cd_ficha = wvr.cd_ficha)
128. 0.078 735.207 ↑ 1.9 54 1

Hash Left Join (cost=57.03..2,020.41 rows=105 width=370) (actual time=711.321..735.207 rows=54 loops=1)

  • Hash Cond: (COALESCE(ct.cd_pessoa_matriz, oc.cd_pessoa_matriz, ve.cd_pessoa_transportadora_doc) = weg.cd_pessoa)
129. 0.079 735.037 ↑ 1.9 54 1

Nested Loop Left Join (cost=48.38..2,011.34 rows=105 width=364) (actual time=711.212..735.037 rows=54 loops=1)

130. 0.082 734.904 ↑ 1.9 54 1

Nested Loop Left Join (cost=48.09..1,814.58 rows=105 width=360) (actual time=711.202..734.904 rows=54 loops=1)

131. 0.125 734.768 ↑ 1.9 54 1

Nested Loop Left Join (cost=47.95..1,798.02 rows=105 width=361) (actual time=711.191..734.768 rows=54 loops=1)

132. 0.087 734.427 ↑ 1.9 54 1

Nested Loop Left Join (cost=47.65..1,575.99 rows=105 width=342) (actual time=711.181..734.427 rows=54 loops=1)

133. 0.101 734.232 ↑ 1.9 54 1

Nested Loop Left Join (cost=47.51..1,559.42 rows=105 width=343) (actual time=711.163..734.232 rows=54 loops=1)

134. 0.070 733.915 ↑ 1.9 54 1

Nested Loop Left Join (cost=47.23..1,488.00 rows=105 width=331) (actual time=711.153..733.915 rows=54 loops=1)

135. 0.096 733.467 ↑ 1.9 54 1

Nested Loop Left Join (cost=46.95..1,416.58 rows=105 width=319) (actual time=711.130..733.467 rows=54 loops=1)

136. 0.077 732.561 ↑ 1.9 54 1

Hash Left Join (cost=46.66..1,221.96 rows=105 width=290) (actual time=711.092..732.561 rows=54 loops=1)

  • Hash Cond: ((wvfd.cd_pessoa_rastreadora = rv.cd_pessoa) AND (ve.cd_veiculo = rv.cd_veiculo))
137. 0.111 732.421 ↑ 1.9 54 1

Hash Left Join (cost=42.46..1,217.20 rows=105 width=288) (actual time=711.020..732.421 rows=54 loops=1)

  • Hash Cond: (wtvc.cd_tipo_veiculo_cavalo = tvc.cd_tipo_veiculo)
  • 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)))
  • Rows Removed by Join Filter: 108
138. 0.143 732.280 ↑ 1.9 54 1

Nested Loop (cost=41.32..1,215.36 rows=105 width=295) (actual time=710.973..732.280 rows=54 loops=1)

  • Join Filter: (vp.cd_veiculo = ve.cd_veiculo)
139. 0.101 731.651 ↑ 1.9 54 1

Hash Join (cost=41.03..1,037.18 rows=105 width=291) (actual time=710.934..731.651 rows=54 loops=1)

  • Hash Cond: (vp.cd_veiculo = wtvc.cd_veiculo_cavalo)
140. 0.090 710.765 ↑ 1.9 54 1

Hash Left Join (cost=27.48..1,016.80 rows=105 width=271) (actual time=690.126..710.765 rows=54 loops=1)

  • Hash Cond: (wvfd.cd_ficha = wfc.cd_ficha)
141. 0.123 398.927 ↑ 1.9 54 1

Hash Join (cost=20.98..1,006.36 rows=105 width=239) (actual time=378.368..398.927 rows=54 loops=1)

  • Hash Cond: (vp.cd_veiculo = wvu.cd_veiculo)
142. 0.146 398.594 ↑ 2.0 105 1

Hash Join (cost=14.22..992.52 rows=210 width=235) (actual time=378.127..398.594 rows=105 loops=1)

  • Hash Cond: (wvfd.cd_veiculo = vp.cd_veiculo)
143. 398.228 398.228 ↑ 2.0 110 1

CTE Scan on with_veiculo_ficha_diaria wvfd (cost=0.00..977.71 rows=217 width=198) (actual time=377.883..398.228 rows=110 loops=1)

  • Filter: (rank = 1)
  • Rows Removed by Filter: 76034
144. 0.068 0.220 ↑ 1.0 404 1

Hash (cost=9.17..9.17 rows=404 width=37) (actual time=0.220..0.220 rows=404 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 28kB
145. 0.152 0.152 ↑ 1.0 404 1

Seq Scan on veiculo_proprio vp (cost=0.00..9.17 rows=404 width=37) (actual time=0.028..0.152 rows=404 loops=1)

  • Filter: (dt_baixa IS NULL)
  • Rows Removed by Filter: 13
146. 0.010 0.210 ↑ 3.7 56 1

Hash (cost=4.16..4.16 rows=208 width=4) (actual time=0.210..0.210 rows=56 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 10kB
147. 0.200 0.200 ↑ 3.7 56 1

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

148. 0.603 311.748 ↓ 13.1 2,627 1

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

  • Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 155kB
149. 311.145 311.145 ↓ 13.1 2,627 1

CTE Scan on with_faturamento_ctrc wfc (cost=0.00..4.00 rows=200 width=36) (actual time=308.890..311.145 rows=2,627 loops=1)

150. 0.157 20.785 ↑ 1.0 417 1

Hash (cost=8.34..8.34 rows=417 width=20) (actual time=20.785..20.785 rows=417 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 26kB
151. 20.628 20.628 ↑ 1.0 417 1

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

152. 0.486 0.486 ↑ 1.0 1 54

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

  • Index Cond: (cd_veiculo = wtvc.cd_veiculo_cavalo)
153. 0.006 0.030 ↑ 1.0 6 1

Hash (cost=1.06..1.06 rows=6 width=25) (actual time=0.030..0.030 rows=6 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
154. 0.024 0.024 ↑ 1.0 6 1

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

155. 0.032 0.063 ↑ 1.0 128 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 14kB
156. 0.031 0.031 ↑ 1.0 128 1

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

157. 0.810 0.810 ↑ 1.0 1 54

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

  • Index Cond: (cd_pessoa = wvfd.cd_pessoa_motorista)
158. 0.378 0.378 ↑ 1.0 1 54

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

  • Index Cond: (cd_cidade = wvfd.cd_cidade_origem)
159. 0.216 0.216 ↑ 1.0 1 54

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

  • Index Cond: (cd_cidade = wvfd.cd_cidade_destino)
160. 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)
161. 0.216 0.216 ↑ 1.0 1 54

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

  • Index Cond: (cd_ctrc = wvfd.cd_ctrc)
162. 0.054 0.054 ↑ 1.0 1 54

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

  • Index Cond: (cd_uf = co.cd_uf)
163. 0.054 0.054 ↓ 0.0 0 54

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

  • Index Cond: (cd_ordem = wvfd.cd_ordem_carregamento)
164. 0.005 0.092 ↑ 1.0 3 1

Hash (cost=8.62..8.62 rows=3 width=22) (actual time=0.092..0.092 rows=3 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
165. 0.002 0.087 ↑ 1.0 3 1

Subquery Scan on weg (cost=8.58..8.62 rows=3 width=22) (actual time=0.086..0.087 rows=3 loops=1)

166. 0.026 0.085 ↑ 1.0 3 1

Sort (cost=8.58..8.59 rows=3 width=22) (actual time=0.084..0.085 rows=3 loops=1)

  • Sort Key: p.nm_fantasia
  • Sort Method: quicksort Memory: 25kB
167. 0.004 0.059 ↑ 1.0 3 1

Nested Loop (cost=0.29..8.56 rows=3 width=22) (actual time=0.045..0.059 rows=3 loops=1)

168. 0.007 0.007 ↑ 1.0 3 1

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

  • Filter: (id_ativo = 1)
169. 0.048 0.048 ↑ 1.0 1 3

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

  • Index Cond: (cd_pessoa = eg.cd_pessoa)
170. 0.001 17.430 ↓ 0.0 0 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 8kB
171. 17.429 17.429 ↓ 0.0 0 1

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

172. 0.000 0.162 ↑ 1.0 1 54

Index Scan using pk_viagem_receita on viagem_receita vr (cost=6.74..8.96 rows=1 width=17) (actual time=0.003..0.003 rows=1 loops=54)

  • Index Cond: (cd_viagem_receita = COALESCE(wvfd.cd_viagem_receita, wvr.cd_viagem_receita, (SubPlan 17)))
173.          

SubPlan (forIndex Scan)

174. 0.039 4.992 ↑ 1.0 1 39

Result (cost=6.44..6.45 rows=1 width=4) (actual time=0.128..0.128 rows=1 loops=39)

175.          

Initplan (forResult)

176. 0.039 4.953 ↑ 1.0 1 39

Limit (cost=0.29..6.44 rows=1 width=4) (actual time=0.127..0.127 rows=1 loops=39)

177. 4.914 4.914 ↑ 256.0 1 39

Index Scan Backward using pk_viagem_receita on viagem_receita vr_ (cost=0.29..1,575.83 rows=256 width=4) (actual time=0.126..0.126 rows=1 loops=39)

  • Index Cond: (cd_viagem_receita IS NOT NULL)
  • Filter: (cd_veiculo = ve.cd_veiculo)
  • Rows Removed by Filter: 185
178. 0.324 0.324 ↓ 0.0 0 54

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

  • Index Cond: (cd_pessoa = vr.cd_pessoa)
179. 0.324 0.324 ↑ 1.0 1 54

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

  • Index Cond: (cd_viagem = vr.cd_viagem)
180. 3.618 3.618 ↓ 33.0 99 54

CTE Scan on with_dias_viagem wdv (cost=0.00..13.63 rows=3 width=12) (actual time=0.007..0.067 rows=99 loops=54)

  • Filter: (rank = 1)
  • Rows Removed by Filter: 437
181. 0.006 0.145 ↓ 10.0 10 1

Hash (cost=0.34..0.34 rows=1 width=12) (actual time=0.145..0.145 rows=10 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
182. 0.139 0.139 ↓ 10.0 10 1

CTE Scan on with_dias_folga wdf (cost=0.00..0.34 rows=1 width=12) (actual time=0.129..0.139 rows=10 loops=1)

  • Filter: (rank = 1)
183. 0.385 197.993 ↓ 2,025.0 2,025 1

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

  • Buckets: 2048 (originally 1024) Batches: 1 (originally 1) Memory Usage: 111kB
184. 197.608 197.608 ↓ 2,025.0 2,025 1

CTE Scan on with_ultima_abastecida_tc wuat (cost=0.00..0.38 rows=1 width=40) (actual time=181.981..197.608 rows=2,025 loops=1)

  • Filter: (rank = 1)
  • Rows Removed by Filter: 13745
185.          

SubPlan (forResult)

186. 0.108 0.810 ↓ 0.0 0 54

Limit (cost=1.20..1.20 rows=1 width=37) (actual time=0.015..0.015 rows=0 loops=54)

187. 0.432 0.702 ↓ 0.0 0 54

Sort (cost=1.20..1.20 rows=1 width=37) (actual time=0.013..0.013 rows=0 loops=54)

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

Seq Scan on veiculo_observacao vo_ (cost=0.00..1.19 rows=1 width=37) (actual time=0.005..0.005 rows=0 loops=54)

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