explain.depesz.com

PostgreSQL's explain analyze made readable

Result: HKIr

Settings
# exclusive inclusive rows x rows loops node
1. 153.935 903.327 ↑ 2.8 54 1

Result (cost=85,897.95..86,152.95 rows=150 width=760) (actual time=752.278..903.327 rows=54 loops=1)

2.          

CTE with_veiculo_ficha_diaria

3. 147.842 147.842 ↓ 1.1 65,567 1

Seq Scan on mv_veiculo_ficha_diaria vfd (cost=0.00..60,130.12 rows=61,994 width=281) (actual time=0.018..147.842 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. 28.550 345.169 ↓ 10.3 2,055 1

HashAggregate (cost=12,426.27..12,428.77 rows=200 width=36) (actual time=344.001..345.169 rows=2,055 loops=1)

  • Group Key: wvfd_1.cd_ficha
6. 7.835 316.619 ↑ 8.2 18,996 1

Hash Join (cost=4,400.24..8,160.34 rows=155,125 width=36) (actual time=290.630..316.619 rows=18,996 loops=1)

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

Hash Join (cost=2,014.81..3,394.45 rows=11,056 width=8) (actual time=237.854..256.041 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.483 0.483 ↑ 1.0 107 1

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

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

Hash (cost=1,239.88..1,239.88 rows=61,994 width=16) (actual time=237.304..237.304 rows=65,567 loops=1)

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

CTE Scan on with_veiculo_ficha_diaria wvfd_1 (cost=0.00..1,239.88 rows=61,994 width=16) (actual time=0.001..214.787 rows=65,567 loops=1)

11. 9.966 52.743 ↑ 1.0 29,128 1

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

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

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

  • Hash Cond: (vr_1.cd_viagem_receita = vrs.cd_viagem_receita)
13. 5.436 5.436 ↑ 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.013..5.436 rows=29,128 loops=1)

14. 4.916 12.820 ↑ 1.0 19,792 1

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

  • Buckets: 32768 Batches: 1 Memory Usage: 1161kB
15. 7.904 7.904 ↑ 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.904 rows=19,792 loops=1)

16.          

CTE with_viagem_receita

17. 0.002 28.470 ↓ 0.0 0 1

GroupAggregate (cost=1,510.75..1,510.81 rows=1 width=8) (actual time=28.470..28.470 rows=0 loops=1)

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

Sort (cost=1,510.75..1,510.77 rows=7 width=8) (actual time=28.468..28.468 rows=0 loops=1)

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

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

20. 0.001 28.461 ↓ 0.0 0 1

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

21. 28.460 28.460 ↓ 0.0 0 1

CTE Scan on with_veiculo_ficha_diaria wvfd_2 (cost=0.00..1,239.88 rows=1 width=16) (actual time=28.460..28.460 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.183 ↑ 3.7 56 1

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

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

29. 0.003 0.003 ↑ 1.0 1 1

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

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

SubPlan (forSeq Scan)

31. 0.020 0.047 ↓ 1.2 56 1

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

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

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

  • Join Filter: (gv_.cd_grupo = gvp__1.cd_grupo)
  • Rows Removed by Join Filter: 1
33. 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
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.189 14.559 ↑ 1.2 214 1

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

38. 0.144 14.370 ↑ 1.2 214 1

Sort (cost=543.51..544.14 rows=251 width=12) (actual time=14.345..14.370 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.210 14.226 ↑ 1.2 214 1

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

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

Seq Scan on veiculo_conjunto vc (cost=0.00..450.99 rows=5,348 width=10) (actual time=0.014..11.840 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.176 ↑ 1.0 417 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 23kB
42. 0.087 0.087 ↑ 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.087 rows=417 loops=1)

43.          

CTE with_tipo_veiculo_conjunto

44. 5.670 38.715 ↑ 1.0 417 1

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

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

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

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

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

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

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

48. 0.086 0.086 ↑ 1.0 417 1

Seq Scan on veiculo_proprio vcavp (cost=0.00..9.17 rows=417 width=4) (actual time=0.004..0.086 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.044 15.846 ↓ 28.0 28 417

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

51. 0.040 14.802 ↓ 28.0 28 1

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

52. 14.650 14.650 ↓ 28.0 28 1

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

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

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

  • Index Cond: (cd_veiculo = wvc3.cd_veiculo_conjunto)
54. 3.784 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.081 0.386 ↓ 87.0 87 1

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

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

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

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

  • Index Cond: (cd_veiculo = wvc2.cd_veiculo_conjunto)
58. 4.128 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.104 0.459 ↓ 99.0 99 1

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

60. 0.058 0.058 ↓ 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.058 rows=99 loops=1)

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

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

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

CTE with_dias_viagem

63. 0.426 1.052 ↑ 1.0 536 1

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

64. 0.441 0.626 ↑ 1.0 536 1

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

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

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

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

CTE with_dias_folga

67. 0.010 0.186 ↑ 1.0 8 1

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

68. 0.009 0.176 ↑ 1.0 8 1

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

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

Seq Scan on funcionario_folga ff_1 (cost=0.00..14.16 rows=8 width=12) (actual time=0.159..0.167 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.407 264.307 ↓ 925.8 15,739 1

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

72. 12.668 250.900 ↓ 925.8 15,739 1

Sort (cost=2,113.46..2,113.50 rows=17 width=56) (actual time=248.883..250.900 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.138 238.232 ↓ 925.8 15,739 1

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

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

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

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

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

76. 24.446 156.922 ↓ 388.3 16,696 1

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

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

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

78. 18.247 30.580 ↓ 264.8 21,184 1

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

  • Hash Cond: (cp.cd_produto = pc.cd_produto)
79. 11.580 11.580 ↑ 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.007..11.580 rows=57,083 loops=1)

80. 0.006 0.753 ↓ 1.6 8 1

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

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

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

  • Filter: (id_combustivel = 1)
  • Rows Removed by Filter: 3573
82. 42.368 42.368 ↑ 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.002..0.002 rows=1 loops=21,184)

  • Index Cond: (cd_caixa = cp.cd_caixa)
  • Filter: (id_tanque_cheio = 1)
  • Rows Removed by Filter: 0
83. 33.392 33.392 ↑ 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.002..0.002 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.224 748.636 ↑ 2.8 54 1

Sort (cost=6,808.93..6,809.30 rows=150 width=702) (actual time=748.608..748.636 rows=54 loops=1)

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

Hash Left Join (cost=1,440.41..6,803.50 rows=150 width=702) (actual time=709.897..748.412 rows=54 loops=1)

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

Hash Left Join (cost=1,440.02..6,787.54 rows=150 width=425) (actual time=436.967..474.629 rows=54 loops=1)

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

Hash Left Join (cost=1,439.83..6,786.77 rows=150 width=421) (actual time=436.763..474.372 rows=54 loops=1)

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

Nested Loop Left Join (cost=1,427.73..6,774.09 rows=150 width=413) (actual time=435.461..472.998 rows=54 loops=1)

90. 0.070 472.725 ↑ 2.8 54 1

Nested Loop Left Join (cost=1,427.45..6,728.64 rows=150 width=405) (actual time=435.449..472.725 rows=54 loops=1)

91. 0.260 472.439 ↑ 2.8 54 1

Hash Left Join (cost=1,427.16..6,665.87 rows=150 width=384) (actual time=435.443..472.439 rows=54 loops=1)

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

Hash Left Join (cost=76.78..5,257.99 rows=150 width=375) (actual time=415.233..445.350 rows=54 loops=1)

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

Hash Left Join (cost=76.75..5,257.39 rows=150 width=371) (actual time=386.750..416.812 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.080 416.671 ↑ 2.8 54 1

Nested Loop Left Join (cost=50.69..5,230.75 rows=150 width=365) (actual time=386.683..416.671 rows=54 loops=1)

95. 0.121 416.537 ↑ 2.8 54 1

Nested Loop Left Join (cost=50.40..4,443.33 rows=150 width=361) (actual time=386.678..416.537 rows=54 loops=1)

96. 0.109 416.200 ↑ 2.8 54 1

Nested Loop Left Join (cost=50.10..3,477.47 rows=150 width=342) (actual time=386.660..416.200 rows=54 loops=1)

97. 0.096 416.037 ↑ 2.8 54 1

Nested Loop Left Join (cost=49.96..3,453.59 rows=150 width=343) (actual time=386.654..416.037 rows=54 loops=1)

98. 0.081 415.779 ↑ 2.8 54 1

Nested Loop Left Join (cost=49.68..3,263.43 rows=150 width=331) (actual time=386.645..415.779 rows=54 loops=1)

99. 0.074 415.590 ↑ 2.8 54 1

Nested Loop Left Join (cost=49.54..3,239.55 rows=150 width=332) (actual time=386.638..415.590 rows=54 loops=1)

100. 0.090 415.300 ↑ 2.8 54 1

Nested Loop Left Join (cost=49.26..3,049.38 rows=150 width=320) (actual time=386.626..415.300 rows=54 loops=1)

101. 0.093 414.778 ↑ 2.8 54 1

Hash Left Join (cost=48.97..2,271.65 rows=150 width=291) (actual time=386.602..414.778 rows=54 loops=1)

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

Hash Left Join (cost=44.77..2,265.16 rows=150 width=289) (actual time=386.499..414.599 rows=54 loops=1)

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

Nested Loop Left Join (cost=38.27..2,253.03 rows=150 width=257) (actual time=39.749..67.773 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.166 67.530 ↑ 2.8 54 1

Nested Loop (cost=38.27..2,231.71 rows=150 width=264) (actual time=39.737..67.530 rows=54 loops=1)

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

Hash Join (cost=37.98..1,435.51 rows=150 width=260) (actual time=39.730..66.986 rows=54 loops=1)

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

CTE Scan on with_veiculo_ficha_diaria wvfd (cost=0.00..1,394.87 rows=310 width=198) (actual time=0.022..27.164 rows=110 loops=1)

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

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

  • Buckets: 1024 Batches: 1 Memory Usage: 14kB
108. 0.149 39.664 ↑ 3.6 56 1

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

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

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

110. 0.020 0.545 ↑ 3.6 56 1

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

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

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

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

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

113. 0.110 0.284 ↑ 1.0 404 1

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

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

Seq Scan on veiculo_proprio vp (cost=0.00..9.17 rows=404 width=38) (actual time=0.004..0.174 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.043 0.054 ↑ 1.0 6 54

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

117. 0.011 0.011 ↑ 1.0 6 1

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

118. 0.560 346.740 ↓ 10.3 2,055 1

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

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

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

120. 0.034 0.086 ↑ 1.0 128 1

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

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

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

122. 0.432 0.432 ↑ 1.0 1 54

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

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

Index Scan using pk_cidade on cidade co (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_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.162 0.162 ↑ 1.0 1 54

Index Scan using pk_cidade on cidade cd (cost=0.28..1.27 rows=1 width=20) (actual time=0.003..0.003 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.216 0.216 ↑ 1.0 1 54

Index Scan using pk_ctrc on ctrc ct (cost=0.29..6.44 rows=1 width=23) (actual time=0.004..0.004 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.002 0.059 ↑ 1.0 3 1

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

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

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

131. 0.014 0.054 ↑ 1.0 3 1

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

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

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

133. 0.007 0.007 ↑ 1.0 3 1

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

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

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

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

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

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

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

137. 7.906 19.989 ↑ 1.0 29,128 1

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

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

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

139.          

SubPlan (forHash Left Join)

140. 0.090 6.840 ↑ 1.0 1 90

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

141.          

Initplan (forResult)

142. 0.090 6.750 ↑ 1.0 1 90

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

143. 6.660 6.660 ↑ 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.074..0.074 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.216 0.216 ↑ 1.0 1 54

Index Scan using pk_pessoa on pessoa pp (cost=0.29..0.42 rows=1 width=29) (actual time=0.004..0.004 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.026 1.288 ↓ 33.0 99 1

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

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

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

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

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

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

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

  • Filter: (rank = 1)
150. 0.562 272.886 ↓ 2,023.0 2,023 1

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

  • Buckets: 2048 (originally 1024) Batches: 1 (originally 1) Memory Usage: 111kB
151. 272.324 272.324 ↓ 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=248.895..272.324 rows=2,023 loops=1)

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

SubPlan (forResult)

153. 0.108 0.756 ↓ 0.0 0 54

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

154. 0.324 0.648 ↓ 0.0 0 54

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

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

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

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