explain.depesz.com

PostgreSQL's explain analyze made readable

Result: uO1O

Settings
# exclusive inclusive rows x rows loops node
1. 106.293 850.976 ↑ 2.0 52 1

Result (cost=110,429.73..110,605.23 rows=104 width=757) (actual time=747.505..850.976 rows=52 loops=1)

2.          

CTE with_veiculos_com_rastreamento

3. 29.374 43.239 ↑ 1.0 112 1

HashAggregate (cost=5,756.62..5,757.74 rows=112 width=4) (actual time=43.217..43.239 rows=112 loops=1)

  • Group Key: vfd.cd_veiculo
4. 13.865 13.865 ↓ 1.0 88,046 1

Seq Scan on veiculo_ficha_diaria vfd (cost=0.00..5,536.70 rows=87,970 width=4) (actual time=0.003..13.865 rows=88,046 loops=1)

5.          

CTE with_ultimos_documentos_veiculo

6. 0.302 81.290 ↓ 1.7 297 1

HashAggregate (cost=2,538.06..2,539.84 rows=178 width=44) (actual time=81.195..81.290 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.032 80.988 ↓ 1.7 297 1

Append (cost=0.58..2,533.61 rows=178 width=44) (actual time=43.290..80.988 rows=297 loops=1)

8. 0.220 44.205 ↓ 2.9 112 1

Nested Loop (cost=0.58..291.27 rows=39 width=44) (actual time=43.288..44.205 rows=112 loops=1)

9. 0.042 43.649 ↑ 1.0 112 1

Nested Loop (cost=0.29..246.78 rows=112 width=8) (actual time=43.251..43.649 rows=112 loops=1)

10. 43.271 43.271 ↑ 1.0 112 1

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

11. 0.336 0.336 ↑ 1.0 1 112

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

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

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

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

Unique (cost=1,925.97..1,957.01 rows=112 width=44) (actual time=33.129..35.992 rows=111 loops=1)

14. 11.834 34.519 ↓ 2.0 12,559 1

Sort (cost=1,925.97..1,941.49 rows=6,208 width=44) (actual time=33.126..34.519 rows=12,559 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: 1366kB
15. 11.510 22.685 ↓ 2.0 12,559 1

Hash Join (cost=3.64..1,534.87 rows=6,208 width=44) (actual time=0.051..22.685 rows=12,559 loops=1)

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

Seq Scan on viagem_receita vr_1 (cost=0.00..1,321.30 rows=6,319 width=32) (actual time=0.013..11.153 rows=12,647 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: 16339
17. 0.012 0.022 ↑ 1.0 112 1

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

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

19. 0.019 0.759 ↓ 2.7 74 1

Nested Loop (cost=0.58..283.55 rows=27 width=44) (actual time=0.059..0.759 rows=74 loops=1)

20. 0.046 0.404 ↑ 1.0 112 1

Nested Loop (cost=0.29..246.78 rows=112 width=8) (actual time=0.039..0.404 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.18 rows=1 width=8) (actual time=0.003..0.003 rows=1 loops=112)

  • Index Cond: (cd_veiculo = wvcr_2.cd_veiculo)
23. 0.336 0.336 ↑ 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.003..0.003 rows=1 loops=112)

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

CTE with_ultimo_documento

25. 0.046 82.100 ↑ 1.6 112 1

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

26. 0.154 82.054 ↓ 1.7 297 1

Sort (cost=376.25..376.69 rows=178 width=48) (actual time=82.031..82.054 rows=297 loops=1)

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

Nested Loop (cost=0.29..369.60 rows=178 width=48) (actual time=81.208..81.900 rows=297 loops=1)

28. 81.396 81.396 ↓ 1.7 297 1

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

29. 0.297 0.297 ↑ 1.0 1 297

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

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

CTE with_veiculo_ficha_diaria

31. 61.789 408.807 ↓ 1.1 45,538 1

WindowAgg (cost=84,610.92..85,906.50 rows=43,186 width=307) (actual time=329.034..408.807 rows=45,538 loops=1)

32. 86.036 347.018 ↓ 1.1 45,538 1

Sort (cost=84,610.92..84,718.89 rows=43,186 width=287) (actual time=329.017..347.018 rows=45,538 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: 24436kB
33. 15.266 260.982 ↓ 1.1 45,538 1

Hash Left Join (cost=191.69..81,285.97 rows=43,186 width=287) (actual time=84.165..260.982 rows=45,538 loops=1)

  • Hash Cond: (vfd_1.cd_cidade_posicao = ci.cd_cidade)
34. 105.435 243.777 ↓ 1.1 45,538 1

Hash Left Join (cost=5.79..80,986.62 rows=43,186 width=275) (actual time=82.194..243.777 rows=45,538 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)::text <> '30784'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:22:01'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 11:03:47'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 422) AND (((wud.cd_ultimo_documento)::text <> '43859'::text) OR (vfd_1.dt_posicao > '2019-07-08 09:33:30'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-07 16:43:45'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45658) AND (((wud.cd_ultimo_documento)::text <> '72442'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:14:33'::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)::text <> '72429'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:14:52'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 10:14:13'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45671) AND (((wud.cd_ultimo_documento)::text <> '72489'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:17:35'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 09:19:03'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45673) AND (((wud.cd_ultimo_documento)::text <> '30781'::text) OR (vfd_1.dt_posicao > '2019-07-08 10:17:37'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 07:46:14'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45675) AND (((wud.cd_ultimo_documento)::text <> '72080'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:02:24'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-07 21:30:45'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45678) AND (((wud.cd_ultimo_documento)::text <> '30778'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:22:46'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-07 13:54:37'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45685) AND (((wud.cd_ultimo_documento)::text <> '72430'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:22:56'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 07:34:30'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45689) AND (((wud.cd_ultimo_documento)::text <> '72127'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:19:30'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 11:19:30'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45692) AND (((wud.cd_ultimo_documento)::text <> '30790'::text) OR (vfd_1.dt_posicao > '2019-07-08 07:48:56'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-07 19:49:08'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45693) AND (((wud.cd_ultimo_documento)::text <> '72437'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:19:08'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 10:54:49'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45696) AND (((wud.cd_ultimo_documento)::text <> '43847'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:22:01'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 11:03:56'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45697) AND (((wud.cd_ultimo_documento)::text <> '43820'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:22:32'::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)::text <> '72375'::text) OR (vfd_1.dt_posicao > '2019-07-07 22:18:31'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-07 10:55:48'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45701) AND (((wud.cd_ultimo_documento)::text <> '72404'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:19:32'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 10:00:00'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45702) AND (((wud.cd_ultimo_documento)::text <> '72422'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:23:09'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-07 11:16:19'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45703) AND (((wud.cd_ultimo_documento)::text <> '72402'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:22:50'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 09:47:24'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45704) AND (((wud.cd_ultimo_documento)::text <> '28330'::text) OR (vfd_1.dt_posicao > '2019-07-04 17:04:07'::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)::text <> '43870'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:23:21'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 10:30:49'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45713) AND (((wud.cd_ultimo_documento)::text <> '71960'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:13:54'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-07 09:04:12'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45714) AND (((wud.cd_ultimo_documento)::text <> '72100'::text) OR (vfd_1.dt_posicao > '2019-07-06 21:23:59'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-06-25 19:35:21'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45715) AND (((wud.cd_ultimo_documento)::text <> '72440'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:22:11'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 08:30:38'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45719) AND (((wud.cd_ultimo_documento)::text <> '72353'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:22:34'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 08:35:31'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45722) AND (((wud.cd_ultimo_documento)::text <> '72435'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:23:40'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 08:19:55'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45740) AND (((wud.cd_ultimo_documento)::text <> '29892'::text) 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)::text <> '43852'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:19:33'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 09:05:10'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45933) AND (((wud.cd_ultimo_documento)::text <> '43860'::text) OR (vfd_1.dt_posicao > '2019-07-08 10:05:05'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 09:44:28'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45940) AND (((wud.cd_ultimo_documento)::text <> '43829'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:22:36'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 09:41:04'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45941) AND (((wud.cd_ultimo_documento)::text <> '72450'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:20:31'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 10:42:52'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45942) AND (((wud.cd_ultimo_documento)::text <> '71499'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:22:59'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-02 18:57:03'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45943) AND (((wud.cd_ultimo_documento)::text <> '30771'::text) 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)::text <> '30552'::text) OR (vfd_1.dt_posicao > '2019-07-08 10:43:02'::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)::text <> '71916'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:19:27'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-06 08:19:03'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45970) AND (((wud.cd_ultimo_documento)::text <> '30754'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:20:12'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-06 23:54:10'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45971) AND (((wud.cd_ultimo_documento)::text <> '72458'::text) OR (vfd_1.dt_posicao > '2019-07-08 10:20:31'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 06:19:46'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45973) AND (((wud.cd_ultimo_documento)::text <> '43871'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:19:40'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-07 10:50:16'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45974) AND (((wud.cd_ultimo_documento)::text <> '30795'::text) OR (vfd_1.dt_posicao > '2019-07-08 10:27:53'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-07 19:53:52'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45991) AND (((wud.cd_ultimo_documento)::text <> '72451'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:22:30'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 01:06:56'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 45992) AND (((wud.cd_ultimo_documento)::text <> '72128'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:22:59'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-07 16:23:07'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 46746) AND (((wud.cd_ultimo_documento)::text <> '72403'::text) OR (vfd_1.dt_posicao > '2019-07-08 10:51:51'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 10:43:27'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 46747) AND (((wud.cd_ultimo_documento)::text <> '30755'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:12:46'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 11:12:46'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 48074) AND (((wud.cd_ultimo_documento)::text <> '30630'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:20:18'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 10:26:28'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 48150) AND (((wud.cd_ultimo_documento)::text <> '72376'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:19:38'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-06 16:44:29'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 48664) AND (((wud.cd_ultimo_documento)::text <> '30631'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:19:55'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 10:30:18'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 48665) AND (((wud.cd_ultimo_documento)::text <> '30756'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:20:38'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 11:11:51'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 49687) AND (((wud.cd_ultimo_documento)::text <> '72159'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:12:33'::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)::text <> '43832'::text) OR (vfd_1.dt_posicao > '2019-07-08 10:51:52'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 09:41:45'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 50922) AND (((wud.cd_ultimo_documento)::text <> '30775'::text) OR (vfd_1.dt_posicao > '2019-07-08 07:24:51'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-07 11:18:42'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 50923) AND (((wud.cd_ultimo_documento)::text <> '30776'::text) OR (vfd_1.dt_posicao > '2019-07-08 08:45:59'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-07 11:14:09'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 52099) AND (((wud.cd_ultimo_documento)::text <> '71232'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:22:56'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 00:55:37'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 52100) AND (((wud.cd_ultimo_documento)::text <> '30632'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:22:22'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-05 20:19:13'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 52101) AND (((wud.cd_ultimo_documento)::text <> '72388'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:17:38'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-07 16:30:55'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 53289) AND (((wud.cd_ultimo_documento)::text <> '43875'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:22:19'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 06:09:28'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 53836) AND (((wud.cd_ultimo_documento)::text <> '72401'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:23:12'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-07 20:01:46'::timestamp without time zone))) OR ((vfd_1.cd_veiculo = 53837) AND (((wud.cd_ultimo_documento)::text <> '30633'::text) OR (vfd_1.dt_posicao > '2019-07-08 11:22:32'::timestamp without time zone) OR (vfd_1.dt_evento > '2019-07-08 10:38:11'::timestamp without time zone))))
  • Rows Removed by Filter: 42508
35. 56.174 56.174 ↓ 1.4 88,046 1

Seq Scan on veiculo_ficha_diaria vfd_1 (cost=0.00..24,010.40 rows=61,673 width=243) (actual time=0.010..56.174 rows=88,046 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.029 82.168 ↑ 1.6 112 1

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

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

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

38. 0.829 1.939 ↑ 1.0 5,729 1

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

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

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

40.          

CTE with_faturamento_ctrc

41. 8.598 188.629 ↓ 5.3 1,052 1

HashAggregate (cost=9,024.22..9,026.72 rows=200 width=36) (actual time=188.141..188.629 rows=1,052 loops=1)

  • Group Key: wvfd_1.cd_ficha
42. 2.202 180.031 ↑ 13.2 7,785 1

Hash Join (cost=3,686.61..6,200.19 rows=102,692 width=37) (actual time=172.284..180.031 rows=7,785 loops=1)

  • Hash Cond: (v_3.cd_viagem = vr_2.cd_viagem)
43. 5.800 129.603 ↑ 6.8 1,073 1

Hash Join (cost=1,403.55..2,339.55 rows=7,342 width=8) (actual time=123.831..129.603 rows=1,073 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: 39798
44. 0.456 0.456 ↓ 1.0 103 1

Seq Scan on viagem v_3 (cost=0.00..54.70 rows=102 width=12) (actual time=0.354..0.456 rows=103 loops=1)

  • Filter: (dt_chegada IS NULL)
  • Rows Removed by Filter: 1969
45. 8.025 123.347 ↓ 1.1 45,538 1

Hash (cost=863.72..863.72 rows=43,186 width=16) (actual time=123.347..123.347 rows=45,538 loops=1)

  • Buckets: 65536 Batches: 1 Memory Usage: 2647kB
46. 115.322 115.322 ↓ 1.1 45,538 1

CTE Scan on with_veiculo_ficha_diaria wvfd_1 (cost=0.00..863.72 rows=43,186 width=16) (actual time=0.001..115.322 rows=45,538 loops=1)

47. 10.003 48.226 ↓ 1.0 28,986 1

Hash (cost=1,921.16..1,921.16 rows=28,953 width=37) (actual time=48.226..48.226 rows=28,986 loops=1)

  • Buckets: 32768 Batches: 1 Memory Usage: 2255kB
48. 23.276 38.223 ↓ 1.0 28,986 1

Hash Left Join (cost=668.61..1,921.16 rows=28,953 width=37) (actual time=8.929..38.223 rows=28,986 loops=1)

  • Hash Cond: (vr_2.cd_viagem_receita = vrs.cd_viagem_receita)
49. 6.241 6.241 ↓ 1.0 28,986 1

Seq Scan on viagem_receita vr_2 (cost=0.00..1,176.53 rows=28,953 width=32) (actual time=0.016..6.241 rows=28,986 loops=1)

50. 3.810 8.706 ↑ 1.0 19,650 1

Hash (cost=421.05..421.05 rows=19,805 width=13) (actual time=8.706..8.706 rows=19,650 loops=1)

  • Buckets: 32768 Batches: 1 Memory Usage: 1154kB
51. 4.896 4.896 ↑ 1.0 19,650 1

Seq Scan on viagem_receita_saldo vrs (cost=0.00..421.05 rows=19,805 width=13) (actual time=0.013..4.896 rows=19,650 loops=1)

52.          

CTE with_viagem_receita

53. 0.002 11.686 ↓ 0.0 0 1

GroupAggregate (cost=1,104.61..1,104.67 rows=1 width=8) (actual time=11.686..11.686 rows=0 loops=1)

  • Group Key: wvfd_2.cd_ficha
54. 0.013 11.684 ↓ 0.0 0 1

Sort (cost=1,104.61..1,104.63 rows=7 width=8) (actual time=11.684..11.684 rows=0 loops=1)

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

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

56. 0.002 11.670 ↓ 0.0 0 1

Nested Loop (cost=1.52..881.06 rows=1 width=8) (actual time=11.669..11.670 rows=0 loops=1)

57. 11.668 11.668 ↓ 0.0 0 1

CTE Scan on with_veiculo_ficha_diaria wvfd_2 (cost=0.00..863.72 rows=1 width=16) (actual time=11.668..11.668 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: 45538
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..223.38 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.105 0.155 ↑ 3.7 56 1

Seq Scan on veiculo_proprio vp_1 (cost=6.54..16.74 rows=208 width=4) (actual time=0.089..0.155 rows=56 loops=1)

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

Initplan (forSeq Scan)

64. 0.002 0.012 ↑ 1.0 1 1

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

65. 0.010 0.010 ↑ 1.0 1 1

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

  • Filter: (cd_pessoa = 452)
  • Rows Removed by Filter: 3
66.          

SubPlan (forSeq Scan)

67. 0.012 0.038 ↓ 1.2 56 1

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

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

Nested Loop (cost=0.00..2.21 rows=1 width=8) (actual time=0.011..0.012 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.003..0.003 rows=1 loops=1)

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

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

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

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

72.          

CTE with_veiculo_conjunto

73. 0.131 1.824 ↑ 1.2 216 1

WindowAgg (cost=317.02..323.27 rows=250 width=20) (actual time=1.694..1.824 rows=216 loops=1)

74. 0.089 1.693 ↑ 1.2 216 1

Sort (cost=317.02..317.65 rows=250 width=12) (actual time=1.676..1.693 rows=216 loops=1)

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

Nested Loop (cost=0.29..307.07 rows=250 width=12) (actual time=0.080..1.604 rows=216 loops=1)

76. 0.061 0.061 ↑ 1.0 416 1

Seq Scan on veiculo_proprio vp_2 (cost=0.00..9.16 rows=416 width=4) (actual time=0.003..0.061 rows=416 loops=1)

77. 1.248 1.248 ↑ 1.0 1 416

Index Scan using idx_veiculo_conjunto_cd_veiculo on veiculo_conjunto vc (cost=0.29..0.70 rows=1 width=10) (actual time=0.003..0.003 rows=1 loops=416)

  • 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. 3.044 15.077 ↑ 1.0 416 1

Nested Loop Left Join (cost=1.16..752.21 rows=416 width=20) (actual time=2.640..15.077 rows=416 loops=1)

  • Join Filter: (wvc1.cd_veiculo = vcav.cd_veiculo)
  • Rows Removed by Join Filter: 41915
80. 2.776 9.537 ↑ 1.0 416 1

Nested Loop Left Join (cost=0.87..737.83 rows=416 width=16) (actual time=2.350..9.537 rows=416 loops=1)

  • Join Filter: (wvc2.cd_veiculo = vcav.cd_veiculo)
  • Rows Removed by Join Filter: 36105
81. 1.089 4.681 ↑ 1.0 416 1

Nested Loop Left Join (cost=0.58..723.46 rows=416 width=12) (actual time=2.049..4.681 rows=416 loops=1)

  • Join Filter: (wvc3.cd_veiculo = vcav.cd_veiculo)
  • Rows Removed by Join Filter: 11620
82. 0.194 1.096 ↑ 1.0 416 1

Nested Loop (cost=0.29..709.08 rows=416 width=8) (actual time=0.033..1.096 rows=416 loops=1)

83. 0.070 0.070 ↑ 1.0 416 1

Seq Scan on veiculo_proprio vcavp (cost=0.00..9.16 rows=416 width=4) (actual time=0.015..0.070 rows=416 loops=1)

84. 0.832 0.832 ↑ 1.0 1 416

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

  • Index Cond: (cd_veiculo = vcavp.cd_veiculo)
85. 0.492 2.496 ↓ 28.0 28 416

Materialize (cost=0.29..8.14 rows=1 width=8) (actual time=0.004..0.006 rows=28 loops=416)

86. 0.008 2.004 ↓ 28.0 28 1

Nested Loop Left Join (cost=0.29..8.13 rows=1 width=8) (actual time=1.718..2.004 rows=28 loops=1)

87. 1.884 1.884 ↓ 28.0 28 1

CTE Scan on with_veiculo_conjunto wvc3 (cost=0.00..5.62 rows=1 width=8) (actual time=1.704..1.884 rows=28 loops=1)

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

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

  • Index Cond: (cd_veiculo = wvc3.cd_veiculo_conjunto)
89. 1.803 2.080 ↓ 87.0 87 416

Materialize (cost=0.29..8.14 rows=1 width=8) (actual time=0.000..0.005 rows=87 loops=416)

90. 0.076 0.277 ↓ 87.0 87 1

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

91. 0.027 0.027 ↓ 87.0 87 1

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

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

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

  • Index Cond: (cd_veiculo = wvc2.cd_veiculo_conjunto)
93. 2.232 2.496 ↓ 101.0 101 416

Materialize (cost=0.29..8.14 rows=1 width=8) (actual time=0.000..0.006 rows=101 loops=416)

94. 0.034 0.264 ↓ 101.0 101 1

Nested Loop Left Join (cost=0.29..8.13 rows=1 width=8) (actual time=0.006..0.264 rows=101 loops=1)

95. 0.028 0.028 ↓ 101.0 101 1

CTE Scan on with_veiculo_conjunto wvc1 (cost=0.00..5.62 rows=1 width=8) (actual time=0.001..0.028 rows=101 loops=1)

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

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

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

CTE with_dias_viagem

98. 0.329 0.709 ↓ 1.0 533 1

WindowAgg (cost=34.73..45.11 rows=519 width=20) (actual time=0.324..0.709 rows=533 loops=1)

99. 0.268 0.380 ↓ 1.0 533 1

Sort (cost=34.73..36.02 rows=519 width=12) (actual time=0.313..0.380 rows=533 loops=1)

  • Sort Key: ff.cd_pessoa, ff.dt_final DESC
  • Sort Method: quicksort Memory: 49kB
100. 0.112 0.112 ↓ 1.0 533 1

Seq Scan on funcionario_folga ff (cost=0.00..11.32 rows=519 width=12) (actual time=0.015..0.112 rows=533 loops=1)

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

CTE with_dias_folga

102. 0.016 0.129 ↑ 3.2 4 1

WindowAgg (cost=14.22..14.48 rows=13 width=20) (actual time=0.126..0.129 rows=4 loops=1)

103. 0.011 0.113 ↑ 3.2 4 1

Sort (cost=14.22..14.25 rows=13 width=12) (actual time=0.113..0.113 rows=4 loops=1)

  • Sort Key: ff_1.cd_pessoa, ff_1.dt_inicio DESC
  • Sort Method: quicksort Memory: 25kB
104. 0.102 0.102 ↑ 3.2 4 1

Seq Scan on funcionario_folga ff_1 (cost=0.00..13.98 rows=13 width=12) (actual time=0.099..0.102 rows=4 loops=1)

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

CTE with_ultima_abastecida_tc

106. 8.840 169.001 ↓ 979.3 15,669 1

WindowAgg (cost=1,524.61..1,524.97 rows=16 width=64) (actual time=158.545..169.001 rows=15,669 loops=1)

107. 9.009 160.161 ↓ 979.3 15,669 1

Sort (cost=1,524.61..1,524.65 rows=16 width=56) (actual time=158.532..160.161 rows=15,669 loops=1)

  • Sort Key: cvi.cd_viagem, (COALESCE(cve.dt_abastecimento, c_1.dt_documento)) DESC, cvi.cd_caixa
  • Sort Method: quicksort Memory: 1609kB
108. 10.178 151.152 ↓ 979.3 15,669 1

GroupAggregate (cost=1,523.85..1,524.29 rows=16 width=56) (actual time=139.016..151.152 rows=15,669 loops=1)

  • Group Key: cvi.cd_viagem, cvi.cd_caixa, cve.dt_abastecimento, c_1.cd_caixa
109. 11.254 140.974 ↓ 989.3 15,829 1

Sort (cost=1,523.85..1,523.89 rows=16 width=25) (actual time=139.000..140.974 rows=15,829 loops=1)

  • Sort Key: cvi.cd_viagem, cvi.cd_caixa, cve.dt_abastecimento
  • Sort Method: quicksort Memory: 1621kB
110. 0.000 129.720 ↓ 989.3 15,829 1

Nested Loop (cost=86.57..1,523.53 rows=16 width=25) (actual time=0.678..129.720 rows=15,829 loops=1)

111. 5.971 97.371 ↓ 395.4 16,607 1

Nested Loop (cost=86.28..1,510.16 rows=42 width=25) (actual time=0.653..97.371 rows=16,607 loops=1)

  • Join Filter: (cve.cd_caixa = c_1.cd_caixa)
112. 0.000 58.186 ↓ 286.3 16,607 1

Nested Loop (cost=85.99..1,488.61 rows=58 width=17) (actual time=0.630..58.186 rows=16,607 loops=1)

113. 9.382 17.538 ↓ 266.8 21,076 1

Hash Join (cost=85.70..1,463.36 rows=79 width=9) (actual time=0.589..17.538 rows=21,076 loops=1)

  • Hash Cond: (cp.cd_produto = pc.cd_produto)
114. 7.594 7.594 ↓ 1.0 56,627 1

Seq Scan on caixa_produto cp (cost=0.00..1,228.93 rows=56,593 width=13) (actual time=0.011..7.594 rows=56,627 loops=1)

115. 0.006 0.562 ↓ 1.6 8 1

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

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

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

  • Filter: (id_combustivel = 1)
  • Rows Removed by Filter: 3561
117. 42.152 42.152 ↑ 1.0 1 21,076

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

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

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

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

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

  • Index Cond: (cd_caixa = c_1.cd_caixa)
  • Heap Fetches: 15829
120. 0.189 744.111 ↑ 2.0 52 1

Sort (cost=3,040.34..3,040.60 rows=104 width=699) (actual time=744.078..744.111 rows=52 loops=1)

  • Sort Key: wvfd.dt_evento DESC
  • Sort Method: quicksort Memory: 72kB
121. 0.521 743.922 ↑ 2.0 52 1

Hash Left Join (cost=65.03..3,036.86 rows=104 width=699) (actual time=721.282..743.922 rows=52 loops=1)

  • Hash Cond: (vi.cd_viagem = wuat.cd_viagem)
122. 0.081 568.928 ↑ 2.0 52 1

Hash Left Join (cost=64.66..3,025.69 rows=104 width=422) (actual time=546.750..568.928 rows=52 loops=1)

  • Hash Cond: (wvfd.cd_pessoa_motorista = wdf.cd_pessoa)
123. 0.398 568.707 ↑ 2.0 52 1

Nested Loop Left Join (cost=64.36..3,024.98 rows=104 width=418) (actual time=546.588..568.707 rows=52 loops=1)

  • Join Filter: (wdv.cd_pessoa = wvfd.cd_pessoa_motorista)
  • Rows Removed by Join Filter: 5099
124. 0.051 565.033 ↑ 2.0 52 1

Nested Loop Left Join (cost=64.36..3,006.31 rows=104 width=410) (actual time=546.119..565.033 rows=52 loops=1)

125. 0.056 564.774 ↑ 2.0 52 1

Nested Loop Left Join (cost=64.08..2,975.21 rows=104 width=402) (actual time=546.096..564.774 rows=52 loops=1)

126. 3.848 564.562 ↑ 2.0 52 1

Nested Loop Left Join (cost=63.79..2,940.00 rows=104 width=381) (actual time=546.085..564.562 rows=52 loops=1)

127. 0.070 560.610 ↑ 2.0 52 1

Hash Left Join (cost=57.01..2,004.73 rows=104 width=372) (actual time=546.034..560.610 rows=52 loops=1)

  • Hash Cond: (wvfd.cd_ficha = wvr.cd_ficha)
128. 0.058 548.851 ↑ 2.0 52 1

Hash Left Join (cost=56.98..2,004.30 rows=104 width=368) (actual time=534.317..548.851 rows=52 loops=1)

  • Hash Cond: (COALESCE(ct.cd_pessoa_matriz, oc.cd_pessoa_matriz, ve.cd_pessoa_transportadora_doc) = weg.cd_pessoa)
129. 0.068 548.728 ↑ 2.0 52 1

Nested Loop Left Join (cost=48.32..1,995.23 rows=104 width=362) (actual time=534.241..548.728 rows=52 loops=1)

130. 0.073 548.608 ↑ 2.0 52 1

Nested Loop Left Join (cost=48.03..1,800.66 rows=104 width=358) (actual time=534.235..548.608 rows=52 loops=1)

131. 0.086 548.483 ↑ 2.0 52 1

Nested Loop Left Join (cost=47.89..1,784.25 rows=104 width=359) (actual time=534.228..548.483 rows=52 loops=1)

132. 0.041 548.241 ↑ 2.0 52 1

Nested Loop Left Join (cost=47.60..1,564.52 rows=104 width=340) (actual time=534.220..548.241 rows=52 loops=1)

133. 0.071 548.096 ↑ 2.0 52 1

Nested Loop Left Join (cost=47.46..1,548.12 rows=104 width=341) (actual time=534.204..548.096 rows=52 loops=1)

134. 0.050 547.869 ↑ 2.0 52 1

Nested Loop Left Join (cost=47.18..1,477.19 rows=104 width=329) (actual time=534.187..547.869 rows=52 loops=1)

135. 0.066 547.611 ↑ 2.0 52 1

Nested Loop Left Join (cost=46.89..1,406.27 rows=104 width=317) (actual time=534.169..547.611 rows=52 loops=1)

136. 0.063 547.233 ↑ 2.0 52 1

Hash Left Join (cost=46.60..1,213.81 rows=104 width=288) (actual time=534.149..547.233 rows=52 loops=1)

  • Hash Cond: ((wvfd.cd_pessoa_rastreadora = rv.cd_pessoa) AND (ve.cd_veiculo = rv.cd_veiculo))
137. 0.100 547.113 ↑ 2.0 52 1

Hash Left Join (cost=42.40..1,209.07 rows=104 width=286) (actual time=534.081..547.113 rows=52 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: 104
138. 0.093 546.986 ↑ 2.0 52 1

Nested Loop (cost=41.27..1,207.23 rows=104 width=293) (actual time=534.033..546.986 rows=52 loops=1)

  • Join Filter: (vp.cd_veiculo = ve.cd_veiculo)
139. 0.069 546.581 ↑ 2.0 52 1

Hash Join (cost=40.98..1,030.95 rows=104 width=289) (actual time=533.999..546.581 rows=52 loops=1)

  • Hash Cond: (vp.cd_veiculo = wtvc.cd_veiculo_cavalo)
140. 0.070 531.200 ↑ 2.0 52 1

Hash Left Join (cost=27.46..1,010.67 rows=104 width=269) (actual time=518.676..531.200 rows=52 loops=1)

  • Hash Cond: (wvfd.cd_ficha = wfc.cd_ficha)
141. 0.071 341.935 ↑ 2.0 52 1

Hash Join (cost=20.96..1,000.27 rows=104 width=237) (actual time=329.470..341.935 rows=52 loops=1)

  • Hash Cond: (vp.cd_veiculo = wvu.cd_veiculo)
142. 0.125 341.684 ↑ 2.0 103 1

Hash Join (cost=14.20..986.46 rows=209 width=233) (actual time=329.273..341.684 rows=103 loops=1)

  • Hash Cond: (wvfd.cd_veiculo = vp.cd_veiculo)
143. 341.349 341.349 ↑ 2.0 108 1

CTE Scan on with_veiculo_ficha_diaria wvfd (cost=0.00..971.68 rows=216 width=198) (actual time=329.041..341.349 rows=108 loops=1)

  • Filter: (rank = 1)
  • Rows Removed by Filter: 45430
144. 0.069 0.210 ↑ 1.0 403 1

Hash (cost=9.16..9.16 rows=403 width=35) (actual time=0.210..0.210 rows=403 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 28kB
145. 0.141 0.141 ↑ 1.0 403 1

Seq Scan on veiculo_proprio vp (cost=0.00..9.16 rows=403 width=35) (actual time=0.020..0.141 rows=403 loops=1)

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

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

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

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

148. 0.235 189.195 ↓ 5.3 1,052 1

Hash (cost=4.00..4.00 rows=200 width=36) (actual time=189.195..189.195 rows=1,052 loops=1)

  • Buckets: 2048 (originally 1024) Batches: 1 (originally 1) Memory Usage: 65kB
149. 188.960 188.960 ↓ 5.3 1,052 1

CTE Scan on with_faturamento_ctrc wfc (cost=0.00..4.00 rows=200 width=36) (actual time=188.146..188.960 rows=1,052 loops=1)

150. 0.088 15.312 ↑ 1.0 416 1

Hash (cost=8.32..8.32 rows=416 width=20) (actual time=15.312..15.312 rows=416 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 26kB
151. 15.224 15.224 ↑ 1.0 416 1

CTE Scan on with_tipo_veiculo_conjunto wtvc (cost=0.00..8.32 rows=416 width=20) (actual time=2.642..15.224 rows=416 loops=1)

152. 0.312 0.312 ↑ 1.0 1 52

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

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

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

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

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

155. 0.027 0.057 ↑ 1.0 128 1

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

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

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

157. 0.312 0.312 ↑ 1.0 1 52

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

  • Index Cond: (cd_pessoa = wvfd.cd_pessoa_motorista)
158. 0.208 0.208 ↑ 1.0 1 52

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

  • Index Cond: (cd_cidade = wvfd.cd_cidade_origem)
159. 0.156 0.156 ↑ 1.0 1 52

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

  • Index Cond: (cd_cidade = wvfd.cd_cidade_destino)
160. 0.104 0.104 ↑ 1.0 1 52

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=52)

  • Index Cond: (cd_uf = cd.cd_uf)
161. 0.156 0.156 ↑ 1.0 1 52

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

  • Index Cond: (cd_ctrc = wvfd.cd_ctrc)
162. 0.052 0.052 ↑ 1.0 1 52

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=52)

  • Index Cond: (cd_uf = co.cd_uf)
163. 0.052 0.052 ↓ 0.0 0 52

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=52)

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

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

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

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

166. 0.022 0.058 ↑ 1.0 3 1

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

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

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

168. 0.008 0.008 ↑ 1.0 3 1

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

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

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

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

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

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

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

172. 0.000 0.104 ↑ 1.0 1 52

Index Scan using pk_viagem_receita on viagem_receita vr (cost=6.78..8.99 rows=1 width=17) (actual time=0.002..0.002 rows=1 loops=52)

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

SubPlan (forIndex Scan)

174. 0.038 3.686 ↑ 1.0 1 38

Result (cost=6.48..6.49 rows=1 width=4) (actual time=0.097..0.097 rows=1 loops=38)

175.          

Initplan (forResult)

176. 0.038 3.648 ↑ 1.0 1 38

Limit (cost=0.29..6.48 rows=1 width=4) (actual time=0.096..0.096 rows=1 loops=38)

177. 3.610 3.610 ↑ 254.0 1 38

Index Scan Backward using pk_viagem_receita on viagem_receita vr_ (cost=0.29..1,572.66 rows=254 width=4) (actual time=0.095..0.095 rows=1 loops=38)

  • Index Cond: (cd_viagem_receita IS NOT NULL)
  • Filter: (cd_veiculo = ve.cd_veiculo)
  • Rows Removed by Filter: 139
178. 0.156 0.156 ↑ 1.0 1 52

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

  • Index Cond: (cd_pessoa = vr.cd_pessoa)
179. 0.208 0.208 ↑ 1.0 1 52

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

  • Index Cond: (cd_viagem = vr.cd_viagem)
180. 3.276 3.276 ↓ 33.0 99 52

CTE Scan on with_dias_viagem wdv (cost=0.00..11.68 rows=3 width=12) (actual time=0.007..0.063 rows=99 loops=52)

  • Filter: (rank = 1)
  • Rows Removed by Filter: 434
181. 0.006 0.140 ↓ 4.0 4 1

Hash (cost=0.29..0.29 rows=1 width=12) (actual time=0.140..0.140 rows=4 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
182. 0.134 0.134 ↓ 4.0 4 1

CTE Scan on with_dias_folga wdf (cost=0.00..0.29 rows=1 width=12) (actual time=0.129..0.134 rows=4 loops=1)

  • Filter: (rank = 1)
183. 0.357 174.473 ↓ 2,020.0 2,020 1

Hash (cost=0.36..0.36 rows=1 width=40) (actual time=174.473..174.473 rows=2,020 loops=1)

  • Buckets: 2048 (originally 1024) Batches: 1 (originally 1) Memory Usage: 111kB
184. 174.116 174.116 ↓ 2,020.0 2,020 1

CTE Scan on with_ultima_abastecida_tc wuat (cost=0.00..0.36 rows=1 width=40) (actual time=158.550..174.116 rows=2,020 loops=1)

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

SubPlan (forResult)

186. 0.104 0.572 ↓ 0.0 0 52

Limit (cost=1.20..1.20 rows=1 width=37) (actual time=0.011..0.011 rows=0 loops=52)

187. 0.260 0.468 ↓ 0.0 0 52

Sort (cost=1.20..1.20 rows=1 width=37) (actual time=0.009..0.009 rows=0 loops=52)

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

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

  • Filter: (cd_veiculo = vp.cd_veiculo)
  • Rows Removed by Filter: 16
Planning time : 14.816 ms
Execution time : 857.656 ms