explain.depesz.com

PostgreSQL's explain analyze made readable

Result: bijp

Settings
# exclusive inclusive rows x rows loops node
1. 144.155 1,117.269 ↑ 1.9 54 1

Result (cost=107,506.44..107,683.62 rows=105 width=759) (actual time=975.967..1,117.269 rows=54 loops=1)

2.          

CTE with_veiculos_com_rastreamento

3. 5.388 25.819 ↑ 1.0 112 1

Unique (cost=0.29..1,939.87 rows=112 width=4) (actual time=0.024..25.819 rows=112 loops=1)

4. 20.431 20.431 ↓ 1.0 88,559 1

Index Only Scan using idx_veiculo_ficha_diaria_cd_veiculo on veiculo_ficha_diaria vfd (cost=0.29..1,718.73 rows=88,456 width=4) (actual time=0.023..20.431 rows=88,559 loops=1)

  • Heap Fetches: 14874
5.          

CTE with_ultimos_documentos_veiculo

6. 0.375 65.838 ↓ 1.7 296 1

HashAggregate (cost=2,547.12..2,548.90 rows=178 width=44) (actual time=65.707..65.838 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.036 65.463 ↓ 1.7 296 1

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

8. 0.263 27.175 ↓ 2.9 112 1

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

9. 0.163 26.352 ↑ 1.0 112 1

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

10. 25.853 25.853 ↑ 1.0 112 1

CTE Scan on with_veiculos_com_rastreamento wvcr (cost=0.00..2.24 rows=112 width=4) (actual time=0.025..25.853 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.19 rows=1 width=8) (actual time=0.003..0.003 rows=1 loops=112)

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

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

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

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

14. 11.891 35.556 ↓ 2.0 12,632 1

Sort (cost=1,932.34..1,947.95 rows=6,244 width=44) (actual time=34.126..35.556 rows=12,632 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.325 23.665 ↓ 2.0 12,632 1

Hash Join (cost=3.64..1,538.71 rows=6,244 width=44) (actual time=0.064..23.665 rows=12,632 loops=1)

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

Seq Scan on viagem_receita vr_1 (cost=0.00..1,323.92 rows=6,355 width=32) (actual time=0.020..11.313 rows=12,721 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.011 0.027 ↑ 1.0 112 1

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

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

19. 0.216 1.045 ↓ 2.7 73 1

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

20. 0.128 0.493 ↑ 1.0 112 1

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

21. 0.029 0.029 ↑ 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.003..0.029 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.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.045 66.685 ↑ 1.6 112 1

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

26. 0.145 66.640 ↓ 1.7 296 1

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

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

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

28. 65.948 65.948 ↓ 1.7 296 1

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

29. 0.296 0.296 ↑ 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.001..0.001 rows=1 loops=296)

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

CTE with_veiculo_ficha_diaria

31. 107.869 537.378 ↓ 1.7 75,316 1

WindowAgg (cost=85,098.62..86,403.20 rows=43,486 width=307) (actual time=392.591..537.378 rows=75,316 loops=1)

32. 165.466 429.509 ↓ 1.7 75,316 1

Sort (cost=85,098.62..85,207.33 rows=43,486 width=287) (actual time=392.569..429.509 rows=75,316 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: 40105kB
33. 28.705 264.043 ↓ 1.7 75,316 1

Hash Left Join (cost=191.69..81,748.40 rows=43,486 width=287) (actual time=68.884..264.043 rows=75,316 loops=1)

  • Hash Cond: (vfd_1.cd_cidade_posicao = ci.cd_cidade)
34. 104.392 233.280 ↓ 1.7 75,316 1

Hash Left Join (cost=5.79..81,448.26 rows=43,486 width=275) (actual time=66.785..233.280 rows=75,316 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 <> '72637'::text) 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)::text <> '72665'::text) 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)::text <> '72442'::text) 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)::text <> '72715'::text) 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)::text <> '72489'::text) 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)::text <> '72628'::text) 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)::text <> '72779'::text) 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)::text <> '30778'::text) 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)::text <> '72430'::text) 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)::text <> '72648'::text) 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)::text <> '72524'::text) 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)::text <> '72790'::text) 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)::text <> '72646'::text) 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)::text <> '72590'::text) 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)::text <> '72542'::text) 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)::text <> '72596'::text) 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)::text <> '72422'::text) 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)::text <> '72711'::text) 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)::text <> '28330'::text) 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)::text <> '43870'::text) 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)::text <> '30809'::text) 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)::text <> '72454'::text) 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)::text <> '72440'::text) 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)::text <> '72353'::text) 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)::text <> '72435'::text) 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)::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 <> '72746'::text) 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)::text <> '72666'::text) 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)::text <> '72618'::text) 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)::text <> '30880'::text) 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)::text <> '71499'::text) 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)::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-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)::text <> '71916'::text) 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)::text <> '30754'::text) 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)::text <> '30888'::text) 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)::text <> '43871'::text) 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)::text <> '72781'::text) 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)::text <> '72451'::text) 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)::text <> '72566'::text) 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)::text <> '72707'::text) 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)::text <> '30886'::text) 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)::text <> '72768'::text) 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)::text <> '43935'::text) 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)::text <> '72776'::text) 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)::text <> '30887'::text) 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)::text <> '72159'::text) 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)::text <> '72647'::text) 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)::text <> '30775'::text) 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)::text <> '30776'::text) 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)::text <> '72657'::text) 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)::text <> '72775'::text) 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)::text <> '72388'::text) 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)::text <> '43875'::text) 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)::text <> '72703'::text) 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)::text <> '72783'::text) 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: 13243
35. 62.131 62.131 ↓ 1.4 88,559 1

Seq Scan on veiculo_ficha_diaria vfd_1 (cost=0.00..24,117.32 rows=62,057 width=243) (actual time=0.011..62.131 rows=88,559 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.035 66.757 ↑ 1.6 112 1

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

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

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

38. 0.831 2.058 ↑ 1.0 5,729 1

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

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

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

40.          

CTE with_faturamento_ctrc

41. 24.430 308.399 ↓ 13.0 2,591 1

HashAggregate (cost=9,350.52..9,353.02 rows=200 width=36) (actual time=306.947..308.399 rows=2,591 loops=1)

  • Group Key: wvfd_1.cd_ficha
42. 5.758 283.969 ↑ 4.4 24,576 1

Hash Join (cost=3,702.87..6,358.27 rows=108,809 width=36) (actual time=268.038..283.969 rows=24,576 loops=1)

  • Hash Cond: (v_3.cd_viagem = vr_2.cd_viagem)
43. 10.336 232.684 ↑ 2.9 2,694 1

Hash Join (cost=1,413.30..2,398.98 rows=7,755 width=8) (actual time=222.402..232.684 rows=2,694 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: 72530
44. 0.506 0.506 ↑ 1.0 107 1

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

  • Filter: (dt_chegada IS NULL)
  • Rows Removed by Filter: 1969
45. 16.474 221.842 ↓ 1.7 75,316 1

Hash (cost=869.72..869.72 rows=43,486 width=16) (actual time=221.842..221.842 rows=75,316 loops=1)

  • Buckets: 131072 (originally 65536) Batches: 1 (originally 1) Memory Usage: 4555kB
46. 205.368 205.368 ↓ 1.7 75,316 1

CTE Scan on with_veiculo_ficha_diaria wvfd_1 (cost=0.00..869.72 rows=43,486 width=16) (actual time=0.001..205.368 rows=75,316 loops=1)

47. 9.445 45.527 ↓ 1.0 29,163 1

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

  • Buckets: 32768 Batches: 1 Memory Usage: 2267kB
48. 19.939 36.082 ↓ 1.0 29,163 1

Hash Left Join (cost=670.73..1,925.48 rows=29,128 width=36) (actual time=9.881..36.082 rows=29,163 loops=1)

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

Seq Scan on viagem_receita vr_2 (cost=0.00..1,178.28 rows=29,128 width=32) (actual time=0.023..6.521 rows=29,163 loops=1)

50. 4.101 9.622 ↓ 1.0 19,827 1

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

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

Seq Scan on viagem_receita_saldo vrs (cost=0.00..423.10 rows=19,810 width=12) (actual time=0.016..5.521 rows=19,827 loops=1)

52.          

CTE with_viagem_receita

53. 0.003 18.067 ↓ 0.0 0 1

GroupAggregate (cost=1,111.77..1,111.83 rows=1 width=8) (actual time=18.066..18.067 rows=0 loops=1)

  • Group Key: wvfd_2.cd_ficha
54. 0.012 18.064 ↓ 0.0 0 1

Sort (cost=1,111.77..1,111.78 rows=7 width=8) (actual time=18.064..18.064 rows=0 loops=1)

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

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

56. 0.002 18.052 ↓ 0.0 0 1

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

57. 18.050 18.050 ↓ 0.0 0 1

CTE Scan on with_veiculo_ficha_diaria wvfd_2 (cost=0.00..869.72 rows=1 width=16) (actual time=18.049..18.050 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: 75316
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.103 0.153 ↑ 3.7 56 1

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

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

Initplan (forSeq Scan)

64. 0.002 0.013 ↑ 1.0 1 1

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

65. 0.011 0.011 ↑ 1.0 1 1

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

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

SubPlan (forSeq Scan)

67. 0.012 0.037 ↓ 1.2 56 1

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

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

Nested Loop (cost=0.00..2.21 rows=1 width=8) (actual time=0.010..0.011 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.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.005..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.121 1.789 ↑ 1.2 214 1

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

74. 0.087 1.668 ↑ 1.2 214 1

Sort (cost=318.54..319.16 rows=251 width=12) (actual time=1.655..1.668 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.270 1.581 ↑ 1.2 214 1

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

76. 0.060 0.060 ↑ 1.0 417 1

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

77. 1.251 1.251 ↑ 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.003..0.003 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. 2.975 15.137 ↑ 1.0 417 1

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

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

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

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

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

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

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

83. 0.071 0.071 ↑ 1.0 417 1

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

84. 0.834 0.834 ↑ 1.0 1 417

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

  • Index Cond: (cd_veiculo = vcavp.cd_veiculo)
85. 0.535 2.502 ↓ 28.0 28 417

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

86. 0.006 1.967 ↓ 28.0 28 1

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

87. 1.849 1.849 ↓ 28.0 28 1

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

  • Filter: (rank = 3)
  • Rows Removed by Filter: 186
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.802 2.085 ↓ 87.0 87 417

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

90. 0.083 0.283 ↓ 87.0 87 1

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

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

  • Filter: (rank = 2)
  • Rows Removed by Filter: 127
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.236 2.502 ↓ 99.0 99 417

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

94. 0.040 0.266 ↓ 99.0 99 1

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

95. 0.028 0.028 ↓ 99.0 99 1

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

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

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

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

CTE with_dias_viagem

98. 0.267 0.618 ↑ 1.1 536 1

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

99. 0.235 0.351 ↑ 1.1 536 1

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

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

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

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

CTE with_dias_folga

102. 0.014 0.140 ↑ 1.7 9 1

WindowAgg (cost=16.61..16.91 rows=15 width=20) (actual time=0.134..0.140 rows=9 loops=1)

103. 0.015 0.126 ↑ 1.7 9 1

Sort (cost=16.61..16.65 rows=15 width=12) (actual time=0.126..0.126 rows=9 loops=1)

  • Sort Key: ff_1.cd_pessoa, ff_1.dt_inicio DESC
  • Sort Method: quicksort Memory: 25kB
104. 0.111 0.111 ↑ 1.7 9 1

Seq Scan on funcionario_folga ff_1 (cost=0.00..16.31 rows=15 width=12) (actual time=0.106..0.111 rows=9 loops=1)

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

CTE with_ultima_abastecida_tc

106. 11.677 195.691 ↓ 927.6 15,770 1

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

107. 11.372 184.014 ↓ 927.6 15,770 1

Sort (cost=1,540.20..1,540.24 rows=17 width=56) (actual time=182.085..184.014 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. 11.835 172.642 ↓ 927.6 15,770 1

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

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

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

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

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

111. 12.539 111.827 ↓ 380.2 16,729 1

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

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

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

113. 11.103 20.354 ↓ 265.3 21,227 1

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

  • Hash Cond: (cp.cd_produto = pc.cd_produto)
114. 8.710 8.710 ↓ 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.009..8.710 rows=57,262 loops=1)

115. 0.005 0.541 ↓ 1.6 8 1

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

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

Seq Scan on produto_consumo pc (cost=0.00..85.64 rows=5 width=4) (actual time=0.017..0.536 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.210 972.250 ↑ 1.9 54 1

Sort (cost=3,065.26..3,065.52 rows=105 width=701) (actual time=972.202..972.250 rows=54 loops=1)

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

Hash Left Join (cost=65.12..3,061.74 rows=105 width=701) (actual time=940.465..972.040 rows=54 loops=1)

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

Hash Left Join (cost=64.73..3,050.44 rows=105 width=424) (actual time=737.418..768.444 rows=54 loops=1)

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

Nested Loop Left Join (cost=64.38..3,049.68 rows=105 width=420) (actual time=737.245..768.222 rows=54 loops=1)

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

Nested Loop Left Join (cost=64.38..3,028.99 rows=105 width=412) (actual time=736.797..764.566 rows=54 loops=1)

125. 0.055 764.239 ↑ 1.9 54 1

Nested Loop Left Join (cost=64.10..2,997.59 rows=105 width=404) (actual time=736.749..764.239 rows=54 loops=1)

126. 4.762 763.914 ↑ 1.9 54 1

Nested Loop Left Join (cost=63.81..2,962.05 rows=105 width=383) (actual time=736.734..763.914 rows=54 loops=1)

127. 0.068 758.990 ↑ 1.9 54 1

Hash Left Join (cost=57.07..2,021.57 rows=105 width=374) (actual time=736.689..758.990 rows=54 loops=1)

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

Hash Left Join (cost=57.03..2,021.13 rows=105 width=370) (actual time=718.600..740.853 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.066 740.742 ↑ 1.9 54 1

Nested Loop Left Join (cost=48.38..2,012.06 rows=105 width=364) (actual time=718.541..740.742 rows=54 loops=1)

130. 0.058 740.622 ↑ 1.9 54 1

Nested Loop Left Join (cost=48.09..1,815.30 rows=105 width=360) (actual time=718.532..740.622 rows=54 loops=1)

131. 0.092 740.510 ↑ 1.9 54 1

Nested Loop Left Join (cost=47.95..1,798.74 rows=105 width=361) (actual time=718.527..740.510 rows=54 loops=1)

132. 0.059 740.202 ↑ 1.9 54 1

Nested Loop Left Join (cost=47.65..1,576.71 rows=105 width=342) (actual time=718.521..740.202 rows=54 loops=1)

133. 0.088 740.035 ↑ 1.9 54 1

Nested Loop Left Join (cost=47.51..1,560.14 rows=105 width=343) (actual time=718.507..740.035 rows=54 loops=1)

134. 0.065 739.785 ↑ 1.9 54 1

Nested Loop Left Join (cost=47.23..1,488.72 rows=105 width=331) (actual time=718.501..739.785 rows=54 loops=1)

135. 0.103 739.450 ↑ 1.9 54 1

Nested Loop Left Join (cost=46.95..1,417.30 rows=105 width=319) (actual time=718.481..739.450 rows=54 loops=1)

136. 0.070 739.023 ↑ 1.9 54 1

Hash Left Join (cost=46.66..1,222.68 rows=105 width=290) (actual time=718.462..739.023 rows=54 loops=1)

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

Hash Left Join (cost=42.46..1,217.92 rows=105 width=288) (actual time=718.391..738.894 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.105 738.760 ↑ 1.9 54 1

Nested Loop (cost=41.32..1,216.08 rows=105 width=295) (actual time=718.337..738.760 rows=54 loops=1)

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

Hash Join (cost=41.03..1,037.90 rows=105 width=291) (actual time=718.298..738.223 rows=54 loops=1)

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

Hash Left Join (cost=27.48..1,017.52 rows=105 width=271) (actual time=702.896..722.758 rows=54 loops=1)

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

Hash Join (cost=20.98..1,007.08 rows=105 width=239) (actual time=393.088..412.878 rows=54 loops=1)

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

Hash Join (cost=14.22..993.24 rows=210 width=235) (actual time=392.892..412.617 rows=105 loops=1)

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

CTE Scan on with_veiculo_ficha_diaria wvfd (cost=0.00..978.43 rows=217 width=198) (actual time=392.598..412.219 rows=110 loops=1)

  • Filter: (rank = 1)
  • Rows Removed by Filter: 75206
144. 0.071 0.265 ↑ 1.0 404 1

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

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

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

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

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

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

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

148. 0.543 309.797 ↓ 13.0 2,591 1

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

  • Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 153kB
149. 309.254 309.254 ↓ 13.0 2,591 1

CTE Scan on with_faturamento_ctrc wfc (cost=0.00..4.00 rows=200 width=36) (actual time=306.953..309.254 rows=2,591 loops=1)

150. 0.104 15.391 ↑ 1.0 417 1

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

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

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

152. 0.432 0.432 ↑ 1.0 1 54

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

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

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

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

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

155. 0.030 0.059 ↑ 1.0 128 1

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

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

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

157. 0.324 0.324 ↑ 1.0 1 54

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

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

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

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

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=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.051 ↑ 1.0 3 1

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

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

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

166. 0.016 0.044 ↑ 1.0 3 1

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

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

Nested Loop (cost=0.29..8.56 rows=3 width=22) (actual time=0.019..0.028 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.007..0.008 rows=3 loops=1)

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

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

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

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

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

CTE Scan on with_viagem_receita wvr (cost=0.00..0.02 rows=1 width=8) (actual time=18.068..18.068 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.040 4.640 ↑ 1.0 1 40

Result (cost=6.44..6.45 rows=1 width=4) (actual time=0.116..0.116 rows=1 loops=40)

175.          

Initplan (forResult)

176. 0.040 4.600 ↑ 1.0 1 40

Limit (cost=0.29..6.44 rows=1 width=4) (actual time=0.114..0.115 rows=1 loops=40)

177. 4.560 4.560 ↑ 256.0 1 40

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

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

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

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

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

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

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

  • Filter: (rank = 1)
  • Rows Removed by Filter: 437
181. 0.009 0.154 ↓ 9.0 9 1

Hash (cost=0.34..0.34 rows=1 width=12) (actual time=0.154..0.154 rows=9 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
182. 0.145 0.145 ↓ 9.0 9 1

CTE Scan on with_dias_folga wdf (cost=0.00..0.34 rows=1 width=12) (actual time=0.136..0.145 rows=9 loops=1)

  • Filter: (rank = 1)
183. 0.529 202.981 ↓ 2,025.0 2,025 1

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

  • Buckets: 2048 (originally 1024) Batches: 1 (originally 1) Memory Usage: 111kB
184. 202.452 202.452 ↓ 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=182.106..202.452 rows=2,025 loops=1)

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

SubPlan (forResult)

186. 0.108 0.864 ↓ 0.0 0 54

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

187. 0.432 0.756 ↓ 0.0 0 54

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

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

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

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