explain.depesz.com

PostgreSQL's explain analyze made readable

Result: 8HkN

Settings
# exclusive inclusive rows x rows loops node
1. 122.878 908.026 ↑ 2.8 54 1

Result (cost=85,846.45..86,099.75 rows=149 width=760) (actual time=788.935..908.026 rows=54 loops=1)

2.          

CTE with_veiculo_ficha_diaria

3. 148.333 148.333 ↓ 1.1 65,567 1

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

CTE with_faturamento_ctrc

5. 29.431 368.779 ↓ 10.3 2,055 1

HashAggregate (cost=12,405.72..12,408.22 rows=200 width=36) (actual time=367.662..368.779 rows=2,055 loops=1)

  • Group Key: wvfd_1.cd_ficha
6. 8.020 339.348 ↑ 8.1 18,996 1

Hash Join (cost=4,396.14..8,148.66 rows=154,802 width=36) (actual time=302.094..339.348 rows=18,996 loops=1)

  • Hash Cond: (v.cd_viagem = vr_1.cd_viagem)
7. 29.353 277.238 ↑ 5.2 2,136 1

Hash Join (cost=2,010.71..3,387.73 rows=11,033 width=8) (actual time=247.973..277.238 rows=2,136 loops=1)

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

Seq Scan on viagem v (cost=0.00..52.76 rows=107 width=12) (actual time=0.402..0.487 rows=107 loops=1)

  • Filter: (dt_chegada IS NULL)
  • Rows Removed by Filter: 1969
9. 28.385 247.398 ↓ 1.1 65,567 1

Hash (cost=1,237.36..1,237.36 rows=61,868 width=16) (actual time=247.398..247.398 rows=65,567 loops=1)

  • Buckets: 131072 (originally 65536) Batches: 2 (originally 1) Memory Usage: 3073kB
10. 219.013 219.013 ↓ 1.1 65,567 1

CTE Scan on with_veiculo_ficha_diaria wvfd_1 (cost=0.00..1,237.36 rows=61,868 width=16) (actual time=0.002..219.013 rows=65,567 loops=1)

11. 10.159 54.090 ↑ 1.0 29,128 1

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

  • Buckets: 32768 Batches: 1 Memory Usage: 2265kB
12. 23.511 43.931 ↑ 1.0 29,128 1

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

  • Hash Cond: (vr_1.cd_viagem_receita = vrs.cd_viagem_receita)
13. 7.583 7.583 ↑ 1.0 29,128 1

Seq Scan on viagem_receita vr_1 (cost=0.00..986.28 rows=29,128 width=32) (actual time=0.012..7.583 rows=29,128 loops=1)

14. 4.910 12.837 ↑ 1.0 19,792 1

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

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

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

16.          

CTE with_viagem_receita

17. 0.003 22.054 ↓ 0.0 0 1

GroupAggregate (cost=1,508.23..1,508.29 rows=1 width=8) (actual time=22.054..22.054 rows=0 loops=1)

  • Group Key: wvfd_2.cd_ficha
18. 0.006 22.051 ↓ 0.0 0 1

Sort (cost=1,508.23..1,508.25 rows=7 width=8) (actual time=22.051..22.051 rows=0 loops=1)

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

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

20. 0.001 22.044 ↓ 0.0 0 1

Nested Loop (cost=4.42..1,271.29 rows=1 width=8) (actual time=22.044..22.044 rows=0 loops=1)

21. 22.043 22.043 ↓ 0.0 0 1

CTE Scan on with_veiculo_ficha_diaria wvfd_2 (cost=0.00..1,237.36 rows=1 width=16) (actual time=22.043..22.043 rows=0 loops=1)

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

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

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

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

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

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

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

CTE with_veiculo_usuario

26. 0.132 0.189 ↑ 3.7 56 1

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

  • Filter: CASE WHEN ($6 IS NOT NULL) THEN (hashed SubPlan 5) ELSE true END
  • Rows Removed by Filter: 361
27.          

Initplan (forSeq Scan)

28. 0.001 0.009 ↑ 1.0 1 1

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

29. 0.008 0.008 ↑ 1.0 1 1

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

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

SubPlan (forSeq Scan)

31. 0.021 0.048 ↓ 1.2 56 1

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

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

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

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

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

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

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

  • Filter: (id_ativo = 1)
35. 0.020 0.020 ↑ 1.0 91 1

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

36.          

CTE with_veiculo_conjunto

37. 0.195 14.578 ↑ 1.2 214 1

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

38. 0.147 14.383 ↑ 1.2 214 1

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

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

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

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

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

  • Filter: ((dt_alteracao <= CURRENT_DATE) AND (COALESCE(dt_alteracao_final, CURRENT_DATE) >= CURRENT_DATE))
  • Rows Removed by Filter: 2127
41. 0.089 0.178 ↑ 1.0 417 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 23kB
42. 0.089 0.089 ↑ 1.0 417 1

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

43.          

CTE with_tipo_veiculo_conjunto

44. 5.656 39.184 ↑ 1.0 417 1

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

  • Join Filter: (wvc1.cd_veiculo = vcav.cd_veiculo)
  • Rows Removed by Join Filter: 41184
45. 5.012 28.941 ↑ 1.0 417 1

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

  • Join Filter: (wvc2.cd_veiculo = vcav.cd_veiculo)
  • Rows Removed by Join Filter: 36192
46. 1.602 19.759 ↑ 1.0 417 1

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

  • Join Filter: (wvc3.cd_veiculo = vcav.cd_veiculo)
  • Rows Removed by Join Filter: 11648
47. 0.540 1.894 ↑ 1.0 417 1

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

48. 0.103 0.103 ↑ 1.0 417 1

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

49. 1.251 1.251 ↑ 1.0 1 417

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

  • Index Cond: (cd_veiculo = vcavp.cd_veiculo)
50. 1.356 16.263 ↓ 28.0 28 417

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

51. 0.041 14.907 ↓ 28.0 28 1

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

52. 14.670 14.670 ↓ 28.0 28 1

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

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

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

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

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

55. 0.064 0.546 ↓ 87.0 87 1

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

56. 0.047 0.047 ↓ 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.047 rows=87 loops=1)

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

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

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

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

59. 0.040 0.484 ↓ 99.0 99 1

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

60. 0.048 0.048 ↓ 99.0 99 1

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

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

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

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

CTE with_dias_viagem

63. 0.442 1.005 ↑ 1.0 536 1

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

64. 0.361 0.563 ↑ 1.0 536 1

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

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

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

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

CTE with_dias_folga

67. 0.013 0.202 ↑ 1.0 8 1

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

68. 0.017 0.189 ↑ 1.0 8 1

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

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

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

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

CTE with_ultima_abastecida_tc

71. 13.259 281.168 ↓ 925.8 15,739 1

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

72. 13.295 267.909 ↓ 925.8 15,739 1

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

  • Sort Key: cvi.cd_viagem, (COALESCE(cve.dt_abastecimento, c.dt_documento)) DESC, cvi.cd_caixa
  • Sort Method: quicksort Memory: 1614kB
73. 18.223 254.614 ↓ 925.8 15,739 1

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

  • Group Key: cvi.cd_viagem, cvi.cd_caixa, cve.dt_abastecimento, c.cd_caixa
74. 16.589 236.391 ↓ 935.4 15,901 1

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

  • Sort Key: cvi.cd_viagem, cvi.cd_caixa, cve.dt_abastecimento
  • Sort Method: quicksort Memory: 1627kB
75. 14.927 219.802 ↓ 935.4 15,901 1

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

76. 16.723 171.483 ↓ 388.3 16,696 1

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

  • Join Filter: (cve.cd_caixa = c.cd_caixa)
77. 8.063 104.672 ↓ 287.9 16,696 1

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

78. 18.630 33.057 ↓ 264.8 21,184 1

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

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

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

80. 0.006 0.731 ↓ 1.6 8 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
81. 0.725 0.725 ↓ 1.6 8 1

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

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

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

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

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

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

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

  • Index Cond: (cd_caixa = c.cd_caixa)
  • Heap Fetches: 0
85. 0.232 784.554 ↑ 2.8 54 1

Sort (cost=6,780.50..6,780.88 rows=149 width=702) (actual time=784.524..784.554 rows=54 loops=1)

  • Sort Key: wvfd.dt_evento DESC
  • Sort Method: quicksort Memory: 73kB
86. 0.888 784.322 ↑ 2.8 54 1

Hash Left Join (cost=1,440.41..6,775.13 rows=149 width=702) (actual time=744.480..784.322 rows=54 loops=1)

  • Hash Cond: (vi.cd_viagem = wuat.cd_viagem)
87. 0.071 493.902 ↑ 2.8 54 1

Hash Left Join (cost=1,440.02..6,759.26 rows=149 width=425) (actual time=454.897..493.902 rows=54 loops=1)

  • Hash Cond: (wvfd.cd_pessoa_motorista = wdf.cd_pessoa)
88. 0.089 493.619 ↑ 2.8 54 1

Hash Left Join (cost=1,439.83..6,758.50 rows=149 width=421) (actual time=454.670..493.619 rows=54 loops=1)

  • Hash Cond: (wvfd.cd_pessoa_motorista = wdv.cd_pessoa)
89. 0.134 492.281 ↑ 2.8 54 1

Nested Loop Left Join (cost=1,427.73..6,745.82 rows=149 width=413) (actual time=453.405..492.281 rows=54 loops=1)

90. 0.111 491.985 ↑ 2.8 54 1

Nested Loop Left Join (cost=1,427.45..6,700.68 rows=149 width=405) (actual time=453.391..491.985 rows=54 loops=1)

91. 0.341 491.604 ↑ 2.8 54 1

Hash Left Join (cost=1,427.16..6,638.33 rows=149 width=384) (actual time=453.383..491.604 rows=54 loops=1)

  • Hash Cond: (COALESCE(wvfd.cd_viagem_receita, wvr.cd_viagem_receita, (SubPlan 14)) = vr.cd_viagem_receita)
92. 0.066 464.117 ↑ 2.8 54 1

Hash Left Join (cost=76.78..5,230.83 rows=149 width=375) (actual time=432.962..464.117 rows=54 loops=1)

  • Hash Cond: (wvfd.cd_ficha = wvr.cd_ficha)
93. 0.086 441.995 ↑ 2.8 54 1

Hash Left Join (cost=76.75..5,230.23 rows=149 width=371) (actual time=410.895..441.995 rows=54 loops=1)

  • Hash Cond: (COALESCE(ct.cd_pessoa_matriz, oc.cd_pessoa_matriz, ve.cd_pessoa_transportadora_doc) = weg.cd_pessoa)
94. 0.097 441.844 ↑ 2.8 54 1

Nested Loop Left Join (cost=50.69..5,203.59 rows=149 width=365) (actual time=410.822..441.844 rows=54 loops=1)

95. 0.098 441.693 ↑ 2.8 54 1

Nested Loop Left Join (cost=50.40..4,420.97 rows=149 width=361) (actual time=410.817..441.693 rows=54 loops=1)

96. 0.105 441.325 ↑ 2.8 54 1

Nested Loop Left Join (cost=50.10..3,462.46 rows=149 width=342) (actual time=410.791..441.325 rows=54 loops=1)

97. 0.058 441.166 ↑ 2.8 54 1

Nested Loop Left Join (cost=49.96..3,438.73 rows=149 width=343) (actual time=410.785..441.166 rows=54 loops=1)

98. 0.095 440.892 ↑ 2.8 54 1

Nested Loop Left Join (cost=49.68..3,249.37 rows=149 width=331) (actual time=410.767..440.892 rows=54 loops=1)

99. 0.085 440.689 ↑ 2.8 54 1

Nested Loop Left Join (cost=49.54..3,225.65 rows=149 width=332) (actual time=410.759..440.689 rows=54 loops=1)

100. 0.118 440.334 ↑ 2.8 54 1

Nested Loop Left Join (cost=49.26..3,036.29 rows=149 width=320) (actual time=410.739..440.334 rows=54 loops=1)

101. 0.089 439.730 ↑ 2.8 54 1

Hash Left Join (cost=48.97..2,263.31 rows=149 width=291) (actual time=410.708..439.730 rows=54 loops=1)

  • Hash Cond: ((wvfd.cd_pessoa_rastreadora = rv.cd_pessoa) AND (ve.cd_veiculo = rv.cd_veiculo))
102. 0.083 439.561 ↑ 2.8 54 1

Hash Left Join (cost=44.77..2,256.84 rows=149 width=289) (actual time=410.613..439.561 rows=54 loops=1)

  • Hash Cond: (wvfd.cd_ficha = wfc.cd_ficha)
103. 0.140 69.119 ↑ 2.8 54 1

Nested Loop Left Join (cost=38.27..2,244.75 rows=149 width=257) (actual time=40.243..69.119 rows=54 loops=1)

  • Join Filter: (((tvc.cd_tipo_veiculo_1 = wtvc.cd_tipo_veiculo_carreta_1) OR (tvc.cd_tipo_veiculo_1 IS NULL)) AND ((tvc.cd_tipo_veiculo_2 = wtvc.cd_tipo_veiculo_carreta_2) OR (tvc.cd_tipo_veiculo_2 IS NULL)) AND ((tvc.cd_tipo_veiculo_3 = wtvc.cd_tipo_veiculo_carreta_3) OR (tvc.cd_tipo_veiculo_3 IS NULL)) AND (tvc.cd_tipo_veiculo = wtvc.cd_tipo_veiculo_cavalo))
  • Rows Removed by Join Filter: 270
104. 0.183 68.871 ↑ 2.8 54 1

Nested Loop (cost=38.27..2,223.56 rows=149 width=264) (actual time=40.226..68.871 rows=54 loops=1)

  • Join Filter: (vp.cd_veiculo = ve.cd_veiculo)
105. 0.121 68.310 ↑ 2.8 54 1

Hash Join (cost=37.98..1,432.67 rows=149 width=260) (actual time=40.219..68.310 rows=54 loops=1)

  • Hash Cond: (wvfd.cd_veiculo = vp.cd_veiculo)
106. 28.001 28.001 ↑ 2.8 110 1

CTE Scan on with_veiculo_ficha_diaria wvfd (cost=0.00..1,392.03 rows=309 width=198) (actual time=0.023..28.001 rows=110 loops=1)

  • Filter: (rank = 1)
  • Rows Removed by Filter: 65457
107. 0.038 40.188 ↑ 3.6 56 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 14kB
108. 0.156 40.150 ↑ 3.6 56 1

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

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

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

110. 0.020 0.552 ↑ 3.6 56 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 12kB
111. 0.035 0.532 ↑ 3.6 56 1

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

  • Hash Cond: (wvu.cd_veiculo = vp.cd_veiculo)
112. 0.212 0.212 ↑ 3.7 56 1

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

113. 0.110 0.285 ↑ 1.0 404 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 28kB
114. 0.175 0.175 ↑ 1.0 404 1

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

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

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

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

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

117. 0.015 0.015 ↑ 1.0 6 1

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

118. 0.583 370.359 ↓ 10.3 2,055 1

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

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

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

120. 0.034 0.080 ↑ 1.0 128 1

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

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

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

122. 0.486 0.486 ↑ 1.0 1 54

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

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

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

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

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

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

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

  • Index Cond: (cd_cidade = wvfd.cd_cidade_destino)
126. 0.054 0.054 ↑ 1.0 1 54

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

  • Index Cond: (cd_uf = cd.cd_uf)
127. 0.270 0.270 ↑ 1.0 1 54

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

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

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

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

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

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

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

131. 0.015 0.059 ↑ 1.0 3 1

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

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

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

133. 0.006 0.006 ↑ 1.0 3 1

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

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

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

  • Index Cond: (cd_pessoa = eg.cd_pessoa)
135. 0.001 22.056 ↓ 0.0 0 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 8kB
136. 22.055 22.055 ↓ 0.0 0 1

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

137. 8.151 20.126 ↑ 1.0 29,128 1

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

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

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

139.          

SubPlan (forHash Left Join)

140. 0.090 7.020 ↑ 1.0 1 90

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

141.          

Initplan (forResult)

142. 0.090 6.930 ↑ 1.0 1 90

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

143. 6.840 6.840 ↑ 256.0 1 90

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

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

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

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

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

  • Index Cond: (cd_viagem = vr.cd_viagem)
146. 0.032 1.249 ↓ 33.0 99 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 13kB
147. 1.217 1.217 ↓ 33.0 99 1

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

  • Filter: (rank = 1)
  • Rows Removed by Filter: 437
148. 0.004 0.212 ↓ 8.0 8 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
149. 0.208 0.208 ↓ 8.0 8 1

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

  • Filter: (rank = 1)
150. 0.566 289.532 ↓ 2,023.0 2,023 1

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

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

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

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

SubPlan (forResult)

153. 0.054 0.594 ↓ 0.0 0 54

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

154. 0.324 0.540 ↓ 0.0 0 54

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

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

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

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