explain.depesz.com

PostgreSQL's explain analyze made readable

Result: 8oVl

Settings
# exclusive inclusive rows x rows loops node
1. 46.929 189,336.123 ↓ 1.1 7,700 1

Unique (cost=6,749,340.27..6,749,905.97 rows=6,857 width=722) (actual time=189,280.683..189,336.123 rows=7,700 loops=1)

2. 737.128 189,289.194 ↓ 5.9 40,119 1

Sort (cost=6,749,340.27..6,749,357.41 rows=6,857 width=722) (actual time=189,280.681..189,289.194 rows=40,119 loops=1)

  • Sort Key: (to_char(viagem.date, 'DD/MM/YYYY HH24:MI:SS'::text)), viagem.id, (CASE viagem.status WHEN 'A'::bpchar THEN 'Aprovada'::text WHEN 'I'::bpchar THEN 'Iniciada'::text WHEN 'F'::bpchar THEN 'Finalizada'::text WHEN 'S'::bpchar THEN 'Sinistrada'::text WHEN 'I'::bpchar THEN 'Iniciada'::text WHEN 'P'::bpchar THEN 'Pendente'::text WHEN 'O'::bpchar THEN 'Solicitada'::text WHEN 'C'::bpchar THEN 'Cancelada'::text WHEN 'R'::bpchar THEN 'Reencaminhada'::text WHEN 'N'::bpchar THEN 'Nao Aprovada'::text WHEN 'V'::bpchar THEN 'Parado'::text ELSE 'Desconhecido'::text END), base.nome, base.software, usuario_cadastrador.*, (to_char(usuario_cadastrador.data, 'DD/MM/YYYY HH24:MI:SS'::text)), u_2.nome, (to_char((max(h_1.data)), 'DD/MM/YYYY HH24:MI:SS'::text)), u.nome, (to_char((max(av.data)), 'DD/MM/YYYY HH24:MI:SS'::text)), empresa.nome, localidade.nome, pontoorigem2.nome, enderecoorigem.cidade, enderecoorigem.estado, pontodestino.nome, enderecodestino.cidade, enderecodestino.estado, (to_char(f.datasaidaprevista, 'DD/MM/YYYY HH24:MI:SS'::text)), (to_char(f.datasaidarealizada, 'DD/MM/YYYY HH24:MI:SS'::text)), (to_char(f_1.datachegadaprevista, 'DD/MM/YYYY HH24:MI:SS'::text)), (to_char(f_1.datachegadarealizada, 'DD/MM/YYYY HH24:MI:SS'::text)), (to_char((f_1.datachegadarealizada - f.datasaidarealizada), 'HH24:MI:SS'::text)), viagem.manifesto, automovel.placa, (CASE pesquisaauto.vinculo WHEN 'F'::bpchar THEN 'Frota'::text WHEN 'A'::bpchar THEN 'Agregado'::text WHEN 'G'::bpchar THEN 'Agregado_motorista'::text WHEN 'T'::bpchar THEN 'Terceiro'::text ELSE 'Desconhecido'::text END), pessoa.nome, pessoa.cpfcnpj, (CASE pesquisamot.vinculo WHEN 'F'::bpchar THEN 'Frota'::text WHEN 'A'::bpchar THEN 'Agregado'::text WHEN 'T'::bpchar THEN 'Terceiro'::text WHEN 'J'::bpchar THEN 'Ajudante'::text WHEN 'G'::bpchar THEN 'Agregado_motorista'::text WHEN 'U'::bpchar THEN 'Funcionario'::text ELSE 'Desconhecido'::text END), (concattipoproduto(viagem.id)), (somadocumentos(viagem.id))
  • Sort Method: external sort Disk: 17368kB
3. 7,464.459 188,552.066 ↓ 5.9 40,119 1

Merge Right Join (cost=6,637,854.58..6,746,698.36 rows=6,857 width=722) (actual time=181,115.822..188,552.066 rows=40,119 loops=1)

  • Merge Cond: (va.viagem_id = viagem.id)
4. 330.394 10,933.001 ↑ 1.0 902,073 1

GroupAggregate (cost=308,082.79..326,815.43 rows=936,632 width=31) (actual time=6,472.473..10,933.001 rows=902,073 loops=1)

  • Group Key: va.viagem_id, u.nome
5. 4,626.658 10,602.607 ↑ 1.0 904,268 1

Sort (cost=308,082.79..310,424.37 rows=936,632 width=31) (actual time=6,472.464..10,602.607 rows=904,268 loops=1)

  • Sort Key: va.viagem_id, u.nome
  • Sort Method: external merge Disk: 43080kB
6. 176.612 5,975.949 ↓ 1.0 937,286 1

Hash Join (cost=85,849.54..192,771.87 rows=936,632 width=31) (actual time=4,058.755..5,975.949 rows=937,286 loops=1)

  • Hash Cond: (av.usuario_id = u.id)
7. 1,019.060 5,796.543 ↓ 1.0 937,304 1

Hash Right Join (cost=85,664.85..179,708.80 rows=936,632 width=24) (actual time=4,055.948..5,796.543 rows=937,304 loops=1)

  • Hash Cond: (va.acoes_id = av.id)
8. 721.843 721.843 ↑ 1.0 2,747,601 1

Seq Scan on viagem_acaoviagemselecionada va (cost=0.00..42,330.79 rows=2,747,779 width=16) (actual time=0.009..721.843 rows=2,747,601 loops=1)

9. 303.573 4,055.640 ↓ 1.0 937,304 1

Hash (cost=68,467.95..68,467.95 rows=936,632 width=24) (actual time=4,055.640..4,055.640 rows=937,304 loops=1)

  • Buckets: 65536 Batches: 16 Memory Usage: 3728kB
10. 3,752.067 3,752.067 ↓ 1.0 937,304 1

Seq Scan on acaoviagemselecionada av (cost=0.00..68,467.95 rows=936,632 width=24) (actual time=0.016..3,752.067 rows=937,304 loops=1)

  • Filter: (acao_id = 5)
  • Rows Removed by Filter: 1895259
11. 1.235 2.794 ↑ 1.0 4,564 1

Hash (cost=127.64..127.64 rows=4,564 width=23) (actual time=2.794..2.794 rows=4,564 loops=1)

  • Buckets: 8192 Batches: 1 Memory Usage: 324kB
12. 1.559 1.559 ↑ 1.0 4,564 1

Seq Scan on usuario u (cost=0.00..127.64 rows=4,564 width=23) (actual time=0.029..1.559 rows=4,564 loops=1)

13. 24.997 170,154.606 ↓ 5.9 40,119 1

Materialize (cost=6,329,771.79..6,404,146.24 rows=6,857 width=321) (actual time=170,035.330..170,154.606 rows=40,119 loops=1)

14. 75.863 170,129.609 ↓ 5.8 40,105 1

Merge Left Join (cost=6,329,771.79..6,404,129.10 rows=6,857 width=321) (actual time=170,035.326..170,129.609 rows=40,105 loops=1)

  • Merge Cond: (viagem.id = h_1.viagem_id)
15. 122.188 166,532.783 ↓ 5.8 40,012 1

Merge Left Join (cost=6,126,807.03..6,170,893.52 rows=6,857 width=298) (actual time=166,464.613..166,532.783 rows=40,012 loops=1)

  • Merge Cond: (viagem.id = usuario_cadastrador.viagem_id)
16. 51.268 160,463.838 ↓ 5.9 40,012 1

Sort (cost=5,824,463.45..5,824,480.38 rows=6,774 width=235) (actual time=160,445.227..160,463.838 rows=40,012 loops=1)

  • Sort Key: viagem.id
  • Sort Method: external merge Disk: 9616kB
17. 7.224 160,412.570 ↓ 5.9 40,012 1

Hash Left Join (cost=4,841,925.18..5,824,032.42 rows=6,774 width=235) (actual time=159,165.020..160,412.570 rows=40,012 loops=1)

  • Hash Cond: (viagem.base_id = base.id)
18. 38.763 160,392.777 ↓ 5.9 40,012 1

Hash Left Join (cost=4,841,921.81..5,823,956.11 rows=6,774 width=220) (actual time=159,152.440..160,392.777 rows=40,012 loops=1)

  • Hash Cond: (f.ponto_id = pontoorigem2.id)
19. 90.165 160,084.956 ↓ 5.9 40,012 1

Hash Left Join (cost=4,832,375.84..5,812,319.00 rows=6,774 width=201) (actual time=158,883.332..160,084.956 rows=40,012 loops=1)

  • Hash Cond: (viagem.id = viagem_documento.viagem_id)
20. 258.337 159,681.048 ↓ 5.9 39,993 1

Hash Right Join (cost=4,809,549.80..5,782,202.40 rows=6,774 width=201) (actual time=158,378.126..159,681.048 rows=39,993 loops=1)

  • Hash Cond: (f_2.viagem_id = viagem.id)
21. 1,228.144 5,844.151 ↓ 45.8 1,241,486 1

Hash Join (cost=241,067.23..1,213,616.72 rows=27,108 width=8) (actual time=2,092.370..5,844.151 rows=1,241,486 loops=1)

  • Hash Cond: ((x_2.min = f_2.ordem) AND (x_2.viagem_id = f_2.viagem_id))
22. 119.159 2,525.082 ↓ 6.1 1,241,458 1

Subquery Scan on x_2 (cost=0.43..378,700.19 rows=203,729 width=12) (actual time=0.060..2,525.082 rows=1,241,458 loops=1)

23. 739.381 2,405.923 ↓ 6.1 1,241,458 1

GroupAggregate (cost=0.43..376,662.90 rows=203,729 width=12) (actual time=0.058..2,405.923 rows=1,241,458 loops=1)

  • Group Key: elementoviagem.viagem_id
24. 1,666.542 1,666.542 ↑ 1.0 5,478,352 1

Index Only Scan using idx_elementoviagem_viagem_id_ordem on elementoviagem (cost=0.43..347,233.85 rows=5,478,352 width=12) (actual time=0.051..1,666.542 rows=5,478,352 loops=1)

  • Heap Fetches: 5478352
25. 1,041.311 2,090.925 ↑ 1.0 5,424,106 1

Hash (cost=132,141.52..132,141.52 rows=5,478,352 width=12) (actual time=2,090.925..2,090.925 rows=5,424,106 loops=1)

  • Buckets: 131072 Batches: 128 Memory Usage: 2999kB
26. 1,049.614 1,049.614 ↑ 1.0 5,478,352 1

Seq Scan on elementoviagem f_2 (cost=0.00..132,141.52 rows=5,478,352 width=12) (actual time=0.015..1,049.614 rows=5,478,352 loops=1)

27. 20.034 153,578.560 ↓ 5.9 39,987 1

Hash (cost=4,568,397.89..4,568,397.89 rows=6,774 width=201) (actual time=153,578.560..153,578.560 rows=39,987 loops=1)

  • Buckets: 32768 (originally 8192) Batches: 4 (originally 1) Memory Usage: 3841kB
28. 248.967 153,558.526 ↓ 5.9 39,987 1

Hash Right Join (cost=3,595,745.29..4,568,397.89 rows=6,774 width=201) (actual time=152,358.638..153,558.526 rows=39,987 loops=1)

  • Hash Cond: (f_3.viagem_id = viagem.id)
29. 1,148.984 5,709.697 ↓ 45.8 1,241,488 1

Hash Join (cost=241,067.23..1,213,616.72 rows=27,108 width=8) (actual time=1,962.824..5,709.697 rows=1,241,488 loops=1)

  • Hash Cond: ((x_3.max = f_3.ordem) AND (x_3.viagem_id = f_3.viagem_id))
30. 117.521 2,598.305 ↓ 6.1 1,241,458 1

Subquery Scan on x_3 (cost=0.43..378,700.19 rows=203,729 width=12) (actual time=0.026..2,598.305 rows=1,241,458 loops=1)

31. 760.101 2,480.784 ↓ 6.1 1,241,458 1

GroupAggregate (cost=0.43..376,662.90 rows=203,729 width=12) (actual time=0.025..2,480.784 rows=1,241,458 loops=1)

  • Group Key: elementoviagem_1.viagem_id
32. 1,720.683 1,720.683 ↑ 1.0 5,478,352 1

Index Only Scan using idx_elementoviagem_viagem_id_ordem on elementoviagem elementoviagem_1 (cost=0.43..347,233.85 rows=5,478,352 width=12) (actual time=0.020..1,720.683 rows=5,478,352 loops=1)

  • Heap Fetches: 5478352
33. 973.145 1,962.408 ↑ 1.0 5,424,106 1

Hash (cost=132,141.52..132,141.52 rows=5,478,352 width=12) (actual time=1,962.408..1,962.408 rows=5,424,106 loops=1)

  • Buckets: 131072 Batches: 128 Memory Usage: 2999kB
34. 989.263 989.263 ↑ 1.0 5,478,352 1

Seq Scan on elementoviagem f_3 (cost=0.00..132,141.52 rows=5,478,352 width=12) (actual time=0.011..989.263 rows=5,478,352 loops=1)

35. 25.279 147,599.862 ↓ 5.9 39,987 1

Hash (cost=3,354,593.38..3,354,593.38 rows=6,774 width=201) (actual time=147,599.862..147,599.862 rows=39,987 loops=1)

  • Buckets: 32768 (originally 8192) Batches: 4 (originally 1) Memory Usage: 3841kB
36. 14.883 147,574.583 ↓ 5.9 39,987 1

Hash Left Join (cost=3,206,414.19..3,354,593.38 rows=6,774 width=201) (actual time=146,529.973..147,574.583 rows=39,987 loops=1)

  • Hash Cond: (viagem.localidade_id = localidade.id)
37. 7.582 147,541.861 ↓ 5.9 39,987 1

Nested Loop Left Join (cost=3,206,353.41..3,354,439.49 rows=6,774 width=189) (actual time=146,512.116..147,541.861 rows=39,987 loops=1)

38. 33.496 147,414.318 ↓ 5.9 39,987 1

Nested Loop Left Join (cost=3,206,352.98..3,311,622.82 rows=6,774 width=195) (actual time=146,508.072..147,414.318 rows=39,987 loops=1)

39. 7.068 147,140.900 ↓ 5.9 39,987 1

Nested Loop Left Join (cost=3,206,352.56..3,268,806.15 rows=6,774 width=201) (actual time=146,483.930..147,140.900 rows=39,987 loops=1)

40. 51.472 146,791.688 ↓ 5.6 38,016 1

Hash Right Join (cost=3,206,352.13..3,219,607.14 rows=6,774 width=209) (actual time=146,454.953..146,791.688 rows=38,016 loops=1)

  • Hash Cond: ((pesquisa.veiculo_id = automovel.id) AND (pesquisa.empresa_id = viagem.empresa_id))
41. 137.297 1,049.585 ↓ 1.0 106,084 1

GroupAggregate (cost=154,502.36..165,937.85 rows=103,959 width=24) (actual time=696.483..1,049.585 rows=106,084 loops=1)

  • Group Key: pesquisa.empresa_id, pesquisa.veiculo_id
42. 710.803 912.288 ↑ 1.0 1,039,590 1

Sort (cost=154,502.36..157,101.33 rows=1,039,590 width=24) (actual time=696.476..912.288 rows=1,039,590 loops=1)

  • Sort Key: pesquisa.empresa_id, pesquisa.veiculo_id
  • Sort Method: external merge Disk: 28752kB
43. 201.485 201.485 ↑ 1.0 1,039,590 1

Seq Scan on pesquisa (cost=0.00..29,285.90 rows=1,039,590 width=24) (actual time=0.028..201.485 rows=1,039,590 loops=1)

44. 20.171 145,690.631 ↓ 5.6 38,016 1

Hash (cost=3,051,748.16..3,051,748.16 rows=6,774 width=217) (actual time=145,690.631..145,690.631 rows=38,016 loops=1)

  • Buckets: 16384 (originally 8192) Batches: 4 (originally 1) Memory Usage: 3969kB
45. 32.869 145,670.460 ↓ 5.6 38,016 1

Merge Left Join (cost=3,038,442.38..3,051,748.16 rows=6,774 width=217) (actual time=145,201.240..145,670.460 rows=38,016 loops=1)

  • Merge Cond: ((viagem.empresa_id = pesquisa_1.empresa_id) AND (motorista.id = pesquisa_1.motorista_id))
46. 207.275 143,515.640 ↓ 5.6 38,016 1

Sort (cost=2,883,940.02..2,883,956.96 rows=6,774 width=217) (actual time=143,495.188..143,515.640 rows=38,016 loops=1)

  • Sort Key: viagem.empresa_id, motorista.id
  • Sort Method: external merge Disk: 9048kB
47. 17.277 143,308.365 ↓ 5.6 38,016 1

Nested Loop Left Join (cost=1,759,148.62..2,883,509.00 rows=6,774 width=217) (actual time=64,833.087..143,308.365 rows=38,016 loops=1)

48. 9.915 143,191.378 ↓ 5.0 7,670 1

Nested Loop Left Join (cost=1,759,148.19..2,818,348.45 rows=1,535 width=209) (actual time=64,817.878..143,191.378 rows=7,670 loops=1)

49. 7.616 105,299.333 ↓ 5.0 7,670 1

Nested Loop Left Join (cost=1,759,147.63..2,807,463.35 rows=1,535 width=204) (actual time=64,730.218..105,299.333 rows=7,670 loops=1)

50. 7.063 90,197.157 ↓ 5.0 7,670 1

Nested Loop Left Join (cost=1,759,147.21..2,797,834.21 rows=1,535 width=177) (actual time=64,720.439..90,197.157 rows=7,670 loops=1)

51. 7.402 81,538.334 ↓ 5.0 7,670 1

Nested Loop Left Join (cost=1,759,146.64..2,786,949.11 rows=1,535 width=172) (actual time=64,655.886..81,538.334 rows=7,670 loops=1)

52. 2,092.443 77,611.562 ↓ 5.0 7,670 1

Hash Left Join (cost=1,759,146.22..2,777,319.97 rows=1,535 width=164) (actual time=64,540.188..77,611.562 rows=7,670 loops=1)

  • Hash Cond: (viagem.id = f_1.viagem_id)
53. 10.666 69,047.952 ↓ 5.0 7,670 1

Nested Loop Left Join (cost=513,090.65..1,531,194.99 rows=1,535 width=140) (actual time=23,452.753..69,047.952 rows=7,670 loops=1)

54. 7.126 58,736.476 ↓ 5.0 7,670 1

Nested Loop Left Join (cost=513,090.23..1,521,563.21 rows=1,535 width=112) (actual time=23,443.705..58,736.476 rows=7,670 loops=1)

55. 7.128 42,921.480 ↓ 5.0 7,670 1

Nested Loop (cost=513,089.81..1,511,930.75 rows=1,535 width=104) (actual time=23,419.917..42,921.480 rows=7,670 loops=1)

56. 194.815 24,920.532 ↓ 5.0 7,670 1

Hash Right Join (cost=513,089.39..1,501,790.86 rows=1,535 width=96) (actual time=23,401.540..24,920.532 rows=7,670 loops=1)

  • Hash Cond: (f.viagem_id = viagem.id)
57. 1,510.759 9,615.422 ↓ 45.8 1,241,486 1

Hash Join (cost=257,117.23..1,245,716.72 rows=27,108 width=32) (actual time=3,852.790..9,615.422 rows=1,241,486 loops=1)

  • Hash Cond: ((x.min = f.ordem) AND (x.viagem_id = f.viagem_id))
58. 118.653 4,252.588 ↓ 6.1 1,241,458 1

Subquery Scan on x (cost=0.43..378,700.19 rows=203,729 width=12) (actual time=0.017..4,252.588 rows=1,241,458 loops=1)

59. 765.998 4,133.935 ↓ 6.1 1,241,458 1

GroupAggregate (cost=0.43..376,662.90 rows=203,729 width=12) (actual time=0.016..4,133.935 rows=1,241,458 loops=1)

  • Group Key: elementoviagem_2.viagem_id
60. 3,367.937 3,367.937 ↑ 1.0 5,478,352 1

Index Only Scan using idx_elementoviagem_viagem_id_ordem on elementoviagem elementoviagem_2 (cost=0.43..347,233.85 rows=5,478,352 width=12) (actual time=0.013..3,367.937 rows=5,478,352 loops=1)

  • Heap Fetches: 5478352
61. 1,212.663 3,852.075 ↑ 1.0 5,424,106 1

Hash (cost=132,141.52..132,141.52 rows=5,478,352 width=36) (actual time=3,852.075..3,852.075 rows=5,424,106 loops=1)

  • Buckets: 65536 Batches: 128 Memory Usage: 3094kB
62. 2,639.412 2,639.412 ↑ 1.0 5,478,352 1

Seq Scan on elementoviagem f (cost=0.00..132,141.52 rows=5,478,352 width=36) (actual time=0.015..2,639.412 rows=5,478,352 loops=1)

63. 1.727 15,110.295 ↓ 5.0 7,669 1

Hash (cost=255,952.97..255,952.97 rows=1,535 width=72) (actual time=15,110.295..15,110.295 rows=7,669 loops=1)

  • Buckets: 8192 (originally 2048) Batches: 1 (originally 1) Memory Usage: 891kB
64. 80.051 15,108.568 ↓ 5.0 7,669 1

Merge Right Join (cost=180,071.22..255,952.97 rows=1,535 width=72) (actual time=15,087.853..15,108.568 rows=7,669 loops=1)

  • Merge Cond: (viagem_motorista.viagem_id = viagem.id)
65. 404.936 2,794.725 ↓ 1.0 1,240,797 1

GroupAggregate (cost=0.43..60,691.69 rows=1,213,425 width=16) (actual time=36.062..2,794.725 rows=1,240,797 loops=1)

  • Group Key: viagem_motorista.viagem_id
66. 2,389.789 2,389.789 ↑ 1.0 1,246,647 1

Index Scan using idx_viagem_motorista_viagem_id on viagem_motorista (cost=0.43..42,324.21 rows=1,246,647 width=16) (actual time=36.054..2,389.789 rows=1,246,647 loops=1)

67. 5.672 12,233.792 ↓ 5.0 7,669 1

Sort (cost=180,070.79..180,074.63 rows=1,535 width=64) (actual time=12,233.148..12,233.792 rows=7,669 loops=1)

  • Sort Key: viagem.id
  • Sort Method: quicksort Memory: 1271kB
68. 7.247 12,228.120 ↓ 5.0 7,669 1

Hash Join (cost=28.75..179,989.56 rows=1,535 width=64) (actual time=1,997.686..12,228.120 rows=7,669 loops=1)

  • Hash Cond: (viagem.empresa_id = empresa.id)
69. 12,204.540 12,204.540 ↑ 1.1 7,669 1

Seq Scan on viagem (cost=0.00..179,913.01 rows=8,655 width=55) (actual time=1,981.334..12,204.540 rows=7,669 loops=1)

  • Filter: ((date >= '2019-04-01 00:00:00'::timestamp without time zone) AND (date <= '2019-04-30 23:59:59'::timestamp without time zone))
  • Rows Removed by Filter: 1233798
70. 0.048 16.333 ↑ 1.0 127 1

Hash (cost=27.16..27.16 rows=127 width=17) (actual time=16.333..16.333 rows=127 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 15kB
71. 16.285 16.285 ↑ 1.0 127 1

Seq Scan on empresa (cost=0.00..27.16 rows=127 width=17) (actual time=14.109..16.285 rows=127 loops=1)

  • Filter: ativado
  • Rows Removed by Filter: 589
72. 17,993.820 17,993.820 ↑ 1.0 1 7,670

Index Scan using automovel_pkey on automovel (cost=0.42..6.60 rows=1 width=16) (actual time=2.346..2.346 rows=1 loops=7,670)

  • Index Cond: (id = viagem.veiculo_id)
73. 15,807.870 15,807.870 ↑ 1.0 1 7,670

Index Scan using motorista_pkey on motorista (cost=0.42..6.27 rows=1 width=16) (actual time=2.060..2.061 rows=1 loops=7,670)

  • Index Cond: (id = (min(viagem_motorista.motoristas_id)))
74. 10,300.810 10,300.810 ↑ 1.0 1 7,670

Index Scan using pessoa_pkey on pessoa (cost=0.42..6.26 rows=1 width=44) (actual time=1.343..1.343 rows=1 loops=7,670)

  • Index Cond: (id = motorista.pessoa_id)
75. 230.747 6,471.167 ↓ 45.8 1,241,488 1

Hash (cost=1,245,716.72..1,245,716.72 rows=27,108 width=32) (actual time=6,471.167..6,471.167 rows=1,241,488 loops=1)

  • Buckets: 65536 (originally 32768) Batches: 32 (originally 1) Memory Usage: 3585kB
76. 1,236.844 6,240.420 ↓ 45.8 1,241,488 1

Hash Join (cost=257,117.23..1,245,716.72 rows=27,108 width=32) (actual time=2,386.237..6,240.420 rows=1,241,488 loops=1)

  • Hash Cond: ((x_1.max = f_1.ordem) AND (x_1.viagem_id = f_1.viagem_id))
77. 120.576 2,619.045 ↓ 6.1 1,241,458 1

Subquery Scan on x_1 (cost=0.43..378,700.19 rows=203,729 width=12) (actual time=0.033..2,619.045 rows=1,241,458 loops=1)

78. 755.877 2,498.469 ↓ 6.1 1,241,458 1

GroupAggregate (cost=0.43..376,662.90 rows=203,729 width=12) (actual time=0.032..2,498.469 rows=1,241,458 loops=1)

  • Group Key: elementoviagem_3.viagem_id
79. 1,742.592 1,742.592 ↑ 1.0 5,478,352 1

Index Only Scan using idx_elementoviagem_viagem_id_ordem on elementoviagem elementoviagem_3 (cost=0.43..347,233.85 rows=5,478,352 width=12) (actual time=0.027..1,742.592 rows=5,478,352 loops=1)

  • Heap Fetches: 5478352
80. 1,174.805 2,384.531 ↑ 1.0 5,424,106 1

Hash (cost=132,141.52..132,141.52 rows=5,478,352 width=36) (actual time=2,384.531..2,384.531 rows=5,424,106 loops=1)

  • Buckets: 65536 Batches: 128 Memory Usage: 3106kB
81. 1,209.726 1,209.726 ↑ 1.0 5,478,352 1

Seq Scan on elementoviagem f_1 (cost=0.00..132,141.52 rows=5,478,352 width=36) (actual time=0.010..1,209.726 rows=5,478,352 loops=1)

82. 3,919.370 3,919.370 ↑ 1.0 1 7,670

Index Scan using pontoviagem_pkey on pontoviagem pontoorigem (cost=0.42..6.26 rows=1 width=16) (actual time=0.510..0.511 rows=1 loops=7,670)

  • Index Cond: (id = f.ponto_id)
83. 8,651.760 8,651.760 ↑ 1.0 1 7,670

Index Scan using endereco_pkey on endereco enderecoorigem (cost=0.56..7.08 rows=1 width=21) (actual time=1.128..1.128 rows=1 loops=7,670)

  • Index Cond: (id = pontoorigem.endereco_id)
84. 15,094.560 15,094.560 ↑ 1.0 1 7,670

Index Scan using pontoviagem_pkey on pontoviagem pontodestino (cost=0.42..6.26 rows=1 width=43) (actual time=1.967..1.968 rows=1 loops=7,670)

  • Index Cond: (id = f_1.ponto_id)
85. 37,882.130 37,882.130 ↑ 1.0 1 7,670

Index Scan using endereco_pkey on endereco enderecodestino (cost=0.56..7.08 rows=1 width=21) (actual time=4.938..4.939 rows=1 loops=7,670)

  • Index Cond: (id = pontodestino.endereco_id)
86. 99.710 99.710 ↑ 5.4 5 7,670

Index Scan using idx_elementoviagem_viagem_id_ordem on elementoviagem ev (cost=0.43..42.18 rows=27 width=16) (actual time=0.010..0.013 rows=5 loops=7,670)

  • Index Cond: (viagem_id = viagem.id)
87. 28.450 2,121.951 ↓ 2.4 250,814 1

Materialize (cost=154,502.36..167,237.34 rows=103,959 width=24) (actual time=1,706.004..2,121.951 rows=250,814 loops=1)

88. 156.523 2,093.501 ↓ 2.1 213,727 1

GroupAggregate (cost=154,502.36..165,937.85 rows=103,959 width=24) (actual time=1,705.998..2,093.501 rows=213,727 loops=1)

  • Group Key: pesquisa_1.empresa_id, pesquisa_1.motorista_id
89. 870.839 1,936.978 ↑ 1.0 1,039,111 1

Sort (cost=154,502.36..157,101.33 rows=1,039,590 width=24) (actual time=1,705.990..1,936.978 rows=1,039,111 loops=1)

  • Sort Key: pesquisa_1.empresa_id, pesquisa_1.motorista_id
  • Sort Method: external merge Disk: 30904kB
90. 1,066.139 1,066.139 ↑ 1.0 1,039,590 1

Seq Scan on pesquisa pesquisa_1 (cost=0.00..29,285.90 rows=1,039,590 width=24) (actual time=27.131..1,066.139 rows=1,039,590 loops=1)

91. 342.144 342.144 ↓ 0.0 0 38,016

Index Only Scan using idx_documento_elementoviagem_id on documento (cost=0.43..7.14 rows=12 width=8) (actual time=0.009..0.009 rows=0 loops=38,016)

  • Index Cond: (elementoviagem_id = ev.id)
  • Heap Fetches: 15390
92. 239.922 239.922 ↑ 1.0 1 39,987

Index Scan using pesquisa_pkey on pesquisa pesquisamot (cost=0.42..6.31 rows=1 width=10) (actual time=0.006..0.006 rows=1 loops=39,987)

  • Index Cond: (id = (max(pesquisa_1.id)))
93. 119.961 119.961 ↑ 1.0 1 39,987

Index Scan using pesquisa_pkey on pesquisa pesquisaauto (cost=0.42..6.31 rows=1 width=10) (actual time=0.003..0.003 rows=1 loops=39,987)

  • Index Cond: (id = (max(pesquisa.id)))
94. 0.237 17.839 ↑ 1.0 1,768 1

Hash (cost=38.68..38.68 rows=1,768 width=28) (actual time=17.839..17.839 rows=1,768 loops=1)

  • Buckets: 2048 Batches: 1 Memory Usage: 127kB
95. 17.602 17.602 ↑ 1.0 1,768 1

Seq Scan on localidade (cost=0.00..38.68 rows=1,768 width=28) (actual time=16.598..17.602 rows=1,768 loops=1)

96. 97.414 313.743 ↑ 1.0 717,513 1

Hash (cost=11,054.13..11,054.13 rows=717,513 width=8) (actual time=313.743..313.743 rows=717,513 loops=1)

  • Buckets: 131072 Batches: 16 Memory Usage: 2783kB
97. 216.329 216.329 ↑ 1.0 717,513 1

Seq Scan on viagem_documento (cost=0.00..11,054.13 rows=717,513 width=8) (actual time=15.586..216.329 rows=717,513 loops=1)

98. 44.620 269.058 ↑ 1.0 206,532 1

Hash (cost=5,350.32..5,350.32 rows=206,532 width=35) (actual time=269.058..269.058 rows=206,532 loops=1)

  • Buckets: 65536 Batches: 8 Memory Usage: 2314kB
99. 224.438 224.438 ↑ 1.0 206,532 1

Seq Scan on pontoviagem pontoorigem2 (cost=0.00..5,350.32 rows=206,532 width=35) (actual time=11.156..224.438 rows=206,532 loops=1)

100. 0.035 12.569 ↑ 1.0 105 1

Hash (cost=2.05..2.05 rows=105 width=31) (actual time=12.569..12.569 rows=105 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 15kB
101. 12.534 12.534 ↑ 1.0 105 1

Seq Scan on base (cost=0.00..2.05 rows=105 width=31) (actual time=12.518..12.534 rows=105 loops=1)

102. 167.970 5,946.757 ↓ 1.0 1,273,799 1

Materialize (cost=302,343.59..343,185.91 rows=1,256,687 width=71) (actual time=4,985.721..5,946.757 rows=1,273,799 loops=1)

103. 235.969 5,778.787 ↑ 1.0 1,241,457 1

Subquery Scan on usuario_cadastrador (cost=302,343.59..340,044.20 rows=1,256,687 width=71) (actual time=4,985.717..5,778.787 rows=1,241,457 loops=1)

104. 332.573 5,542.818 ↑ 1.0 1,241,457 1

GroupAggregate (cost=302,343.59..327,477.33 rows=1,256,687 width=31) (actual time=4,985.705..5,542.818 rows=1,241,457 loops=1)

  • Group Key: h.viagem_id, u_1.nome
105. 838.709 5,210.245 ↑ 1.0 1,241,457 1

Sort (cost=302,343.59..305,485.30 rows=1,256,687 width=31) (actual time=4,985.694..5,210.245 rows=1,241,457 loops=1)

  • Sort Key: h.viagem_id, u_1.nome
  • Sort Method: external merge Disk: 58328kB
106. 342.255 4,371.536 ↑ 1.0 1,241,457 1

Hash Join (cost=23,712.45..114,896.69 rows=1,256,687 width=31) (actual time=346.184..4,371.536 rows=1,241,457 loops=1)

  • Hash Cond: (h.usuario_id = u_1.id)
107. 3,716.077 4,013.168 ↑ 1.0 1,241,457 1

Bitmap Heap Scan on historicoviagem h (cost=23,527.76..97,534.34 rows=1,256,687 width=24) (actual time=330.048..4,013.168 rows=1,241,457 loops=1)

  • Recheck Cond: (acao = 'C'::bpchar)
  • Rows Removed by Index Recheck: 2540868
  • Heap Blocks: exact=30784 lossy=26424
108. 297.091 297.091 ↑ 1.0 1,241,457 1

Bitmap Index Scan on idx_historicoviagem_acao (cost=0.00..23,213.58 rows=1,256,687 width=0) (actual time=297.091..297.091 rows=1,241,457 loops=1)

  • Index Cond: (acao = 'C'::bpchar)
109. 0.831 16.113 ↑ 1.0 4,564 1

Hash (cost=127.64..127.64 rows=4,564 width=23) (actual time=16.113..16.113 rows=4,564 loops=1)

  • Buckets: 8192 Batches: 1 Memory Usage: 324kB
110. 15.282 15.282 ↑ 1.0 4,564 1

Seq Scan on usuario u_1 (cost=0.00..127.64 rows=4,564 width=23) (actual time=10.829..15.282 rows=4,564 loops=1)

111. 112.941 3,520.963 ↓ 1.0 879,138 1

Materialize (cost=202,964.76..231,013.20 rows=863,029 width=31) (actual time=3,020.036..3,520.963 rows=879,138 loops=1)

112. 235.957 3,408.022 ↓ 1.0 865,592 1

GroupAggregate (cost=202,964.76..220,225.34 rows=863,029 width=31) (actual time=3,020.031..3,408.022 rows=865,592 loops=1)

  • Group Key: h_1.viagem_id, u_2.nome
113. 609.381 3,172.065 ↓ 1.0 874,413 1

Sort (cost=202,964.76..205,122.33 rows=863,029 width=31) (actual time=3,020.024..3,172.065 rows=874,413 loops=1)

  • Sort Key: h_1.viagem_id, u_2.nome
  • Sort Method: external merge Disk: 41640kB
114. 215.864 2,562.684 ↓ 1.0 874,413 1

Hash Join (cost=16,341.60..97,224.20 rows=863,029 width=31) (actual time=217.882..2,562.684 rows=874,413 loops=1)

  • Hash Cond: (h_1.usuario_id = u_2.id)
115. 2,135.376 2,345.504 ↓ 1.0 874,413 1

Bitmap Heap Scan on historicoviagem h_1 (cost=16,156.91..85,242.77 rows=863,029 width=24) (actual time=216.554..2,345.504 rows=874,413 loops=1)

  • Recheck Cond: (acao = 'A'::bpchar)
  • Rows Removed by Index Recheck: 2702855
  • Heap Blocks: exact=30522 lossy=26426
116. 210.128 210.128 ↓ 1.0 874,413 1

Bitmap Index Scan on idx_historicoviagem_acao (cost=0.00..15,941.15 rows=863,029 width=0) (actual time=210.128..210.128 rows=874,413 loops=1)

  • Index Cond: (acao = 'A'::bpchar)
117. 0.571 1.316 ↑ 1.0 4,564 1

Hash (cost=127.64..127.64 rows=4,564 width=23) (actual time=1.316..1.316 rows=4,564 loops=1)

  • Buckets: 8192 Batches: 1 Memory Usage: 324kB
118. 0.745 0.745 ↑ 1.0 4,564 1

Seq Scan on usuario u_2 (cost=0.00..127.64 rows=4,564 width=23) (actual time=0.018..0.745 rows=4,564 loops=1)