explain.depesz.com

PostgreSQL's explain analyze made readable

Result: SgVO

Settings
# exclusive inclusive rows x rows loops node
1. 47.107 180,269.128 ↓ 1.1 7,700 1

Unique (cost=6,749,340.27..6,749,905.97 rows=6,857 width=722) (actual time=180,213.161..180,269.128 rows=7,700 loops=1)

2. 826.638 180,222.021 ↓ 5.9 40,119 1

Sort (cost=6,749,340.27..6,749,357.41 rows=6,857 width=722) (actual time=180,213.160..180,222.021 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. 8,635.413 179,395.383 ↓ 5.9 40,119 1

Merge Right Join (cost=6,637,854.58..6,746,698.36 rows=6,857 width=722) (actual time=171,481.422..179,395.383 rows=40,119 loops=1)

  • Merge Cond: (va.viagem_id = viagem.id)
4. 239.449 8,600.394 ↑ 1.0 902,073 1

GroupAggregate (cost=308,082.79..326,815.43 rows=936,632 width=31) (actual time=6,987.968..8,600.394 rows=902,073 loops=1)

  • Group Key: va.viagem_id, u.nome
5. 1,879.263 8,360.945 ↑ 1.0 904,268 1

Sort (cost=308,082.79..310,424.37 rows=936,632 width=31) (actual time=6,987.959..8,360.945 rows=904,268 loops=1)

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

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

  • Hash Cond: (av.usuario_id = u.id)
7. 1,061.641 6,287.613 ↓ 1.0 937,304 1

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

  • Hash Cond: (va.acoes_id = av.id)
8. 644.801 644.801 ↑ 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.011..644.801 rows=2,747,601 loops=1)

9. 304.167 4,581.171 ↓ 1.0 937,304 1

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

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

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

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

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

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

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

13. 26.287 162,159.576 ↓ 5.9 40,119 1

Materialize (cost=6,329,771.79..6,404,146.24 rows=6,857 width=321) (actual time=162,036.803..162,159.576 rows=40,119 loops=1)

14. 77.671 162,133.289 ↓ 5.8 40,105 1

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

  • Merge Cond: (viagem.id = h_1.viagem_id)
15. 118.709 158,331.306 ↓ 5.8 40,012 1

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

  • Merge Cond: (viagem.id = usuario_cadastrador.viagem_id)
16. 54.351 152,268.489 ↓ 5.9 40,012 1

Sort (cost=5,824,463.45..5,824,480.38 rows=6,774 width=235) (actual time=152,248.126..152,268.489 rows=40,012 loops=1)

  • Sort Key: viagem.id
  • Sort Method: external merge Disk: 9616kB
17. 7.310 152,214.138 ↓ 5.9 40,012 1

Hash Left Join (cost=4,841,925.18..5,824,032.42 rows=6,774 width=235) (actual time=151,055.911..152,214.138 rows=40,012 loops=1)

  • Hash Cond: (viagem.base_id = base.id)
18. 41.403 152,194.300 ↓ 5.9 40,012 1

Hash Left Join (cost=4,841,921.81..5,823,956.11 rows=6,774 width=220) (actual time=151,043.370..152,194.300 rows=40,012 loops=1)

  • Hash Cond: (f.ponto_id = pontoorigem2.id)
19. 94.576 151,873.952 ↓ 5.9 40,012 1

Hash Left Join (cost=4,832,375.84..5,812,319.00 rows=6,774 width=201) (actual time=150,764.237..151,873.952 rows=40,012 loops=1)

  • Hash Cond: (viagem.id = viagem_documento.viagem_id)
20. 246.096 151,461.842 ↓ 5.9 39,993 1

Hash Right Join (cost=4,809,549.80..5,782,202.40 rows=6,774 width=201) (actual time=150,248.367..151,461.842 rows=39,993 loops=1)

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

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

  • Hash Cond: ((x_2.min = f_2.ordem) AND (x_2.viagem_id = f_2.viagem_id))
22. 116.451 2,561.517 ↓ 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.070..2,561.517 rows=1,241,458 loops=1)

23. 751.283 2,445.066 ↓ 6.1 1,241,458 1

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

  • Group Key: elementoviagem.viagem_id
24. 1,693.783 1,693.783 ↑ 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.061..1,693.783 rows=5,478,352 loops=1)

  • Heap Fetches: 5478352
25. 976.374 1,957.316 ↑ 1.0 5,424,106 1

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

  • Buckets: 131072 Batches: 128 Memory Usage: 2999kB
26. 980.942 980.942 ↑ 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.011..980.942 rows=5,478,352 loops=1)

27. 20.765 145,542.257 ↓ 5.9 39,987 1

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

  • Buckets: 32768 (originally 8192) Batches: 4 (originally 1) Memory Usage: 3841kB
28. 248.224 145,521.492 ↓ 5.9 39,987 1

Hash Right Join (cost=3,595,745.29..4,568,397.89 rows=6,774 width=201) (actual time=144,282.810..145,521.492 rows=39,987 loops=1)

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

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

  • Hash Cond: ((x_3.max = f_3.ordem) AND (x_3.viagem_id = f_3.viagem_id))
30. 120.652 2,633.212 ↓ 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.033..2,633.212 rows=1,241,458 loops=1)

31. 766.892 2,512.560 ↓ 6.1 1,241,458 1

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

  • Group Key: elementoviagem_1.viagem_id
32. 1,745.668 1,745.668 ↑ 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.027..1,745.668 rows=5,478,352 loops=1)

  • Heap Fetches: 5478352
33. 1,029.504 2,077.350 ↑ 1.0 5,424,106 1

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

  • Buckets: 131072 Batches: 128 Memory Usage: 2999kB
34. 1,047.846 1,047.846 ↑ 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.014..1,047.846 rows=5,478,352 loops=1)

35. 26.827 139,374.471 ↓ 5.9 39,987 1

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

  • Buckets: 32768 (originally 8192) Batches: 4 (originally 1) Memory Usage: 3841kB
36. 16.877 139,347.644 ↓ 5.9 39,987 1

Hash Left Join (cost=3,206,414.19..3,354,593.38 rows=6,774 width=201) (actual time=138,088.047..139,347.644 rows=39,987 loops=1)

  • Hash Cond: (viagem.localidade_id = localidade.id)
37. 9.318 139,312.771 ↓ 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=138,070.026..139,312.771 rows=39,987 loops=1)

38. 26.836 139,103.518 ↓ 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=138,065.978..139,103.518 rows=39,987 loops=1)

39. 24.284 138,836.760 ↓ 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=138,041.887..138,836.760 rows=39,987 loops=1)

40. 55.291 138,356.284 ↓ 5.6 38,016 1

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

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

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

  • Group Key: pesquisa.empresa_id, pesquisa.veiculo_id
42. 711.382 918.848 ↑ 1.0 1,039,590 1

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

  • Sort Key: pesquisa.empresa_id, pesquisa.veiculo_id
  • Sort Method: external merge Disk: 28752kB
43. 207.466 207.466 ↑ 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.027..207.466 rows=1,039,590 loops=1)

44. 22.254 137,238.120 ↓ 5.6 38,016 1

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

  • Buckets: 16384 (originally 8192) Batches: 4 (originally 1) Memory Usage: 3969kB
45. 35.114 137,215.866 ↓ 5.6 38,016 1

Merge Left Join (cost=3,038,442.38..3,051,748.16 rows=6,774 width=217) (actual time=136,734.761..137,215.866 rows=38,016 loops=1)

  • Merge Cond: ((viagem.empresa_id = pesquisa_1.empresa_id) AND (motorista.id = pesquisa_1.motorista_id))
46. 201.256 134,802.495 ↓ 5.6 38,016 1

Sort (cost=2,883,940.02..2,883,956.96 rows=6,774 width=217) (actual time=134,780.057..134,802.495 rows=38,016 loops=1)

  • Sort Key: viagem.empresa_id, motorista.id
  • Sort Method: external merge Disk: 9048kB
47. 20.887 134,601.239 ↓ 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=66,423.990..134,601.239 rows=38,016 loops=1)

48. 10.497 134,511.322 ↓ 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=66,423.944..134,511.322 rows=7,670 loops=1)

49. 9.848 100,890.885 ↓ 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=66,361.276..100,890.885 rows=7,670 loops=1)

50. 8.790 88,470.977 ↓ 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=66,259.939..88,470.977 rows=7,670 loops=1)

51. 13.647 80,930.247 ↓ 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=66,103.747..80,930.247 rows=7,670 loops=1)

52. 279.094 77,288.690 ↓ 5.0 7,670 1

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

  • Hash Cond: (viagem.id = f_1.viagem_id)
53. 8.361 70,341.624 ↓ 5.0 7,670 1

Nested Loop Left Join (cost=513,090.65..1,531,194.99 rows=1,535 width=140) (actual time=25,708.258..70,341.624 rows=7,670 loops=1)

54. 13.972 60,086.143 ↓ 5.0 7,670 1

Nested Loop Left Join (cost=513,090.23..1,521,563.21 rows=1,535 width=112) (actual time=25,640.968..60,086.143 rows=7,670 loops=1)

55. 10.839 44,563.431 ↓ 5.0 7,670 1

Nested Loop (cost=513,089.81..1,511,930.75 rows=1,535 width=104) (actual time=25,592.093..44,563.431 rows=7,670 loops=1)

56. 192.640 27,026.642 ↓ 5.0 7,670 1

Hash Right Join (cost=513,089.39..1,501,790.86 rows=1,535 width=96) (actual time=25,545.987..27,026.642 rows=7,670 loops=1)

  • Hash Cond: (f.viagem_id = viagem.id)
57. 1,627.524 12,449.495 ↓ 45.8 1,241,486 1

Hash Join (cost=257,117.23..1,245,716.72 rows=27,108 width=32) (actual time=7,395.186..12,449.495 rows=1,241,486 loops=1)

  • Hash Cond: ((x.min = f.ordem) AND (x.viagem_id = f.viagem_id))
58. 118.675 3,457.136 ↓ 6.1 1,241,458 1

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

59. 755.643 3,338.461 ↓ 6.1 1,241,458 1

GroupAggregate (cost=0.43..376,662.90 rows=203,729 width=12) (actual time=0.046..3,338.461 rows=1,241,458 loops=1)

  • Group Key: elementoviagem_2.viagem_id
60. 2,582.818 2,582.818 ↑ 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.041..2,582.818 rows=5,478,352 loops=1)

  • Heap Fetches: 5478352
61. 1,435.491 7,364.835 ↑ 1.0 5,424,106 1

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

  • Buckets: 65536 Batches: 128 Memory Usage: 3094kB
62. 5,929.344 5,929.344 ↑ 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=19.141..5,929.344 rows=5,478,352 loops=1)

63. 2.361 14,384.507 ↓ 5.0 7,669 1

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

  • Buckets: 8192 (originally 2048) Batches: 1 (originally 1) Memory Usage: 891kB
64. 74.321 14,382.146 ↓ 5.0 7,669 1

Merge Right Join (cost=180,071.22..255,952.97 rows=1,535 width=72) (actual time=14,372.956..14,382.146 rows=7,669 loops=1)

  • Merge Cond: (viagem_motorista.viagem_id = viagem.id)
65. 369.996 1,506.561 ↓ 1.0 1,240,797 1

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

  • Group Key: viagem_motorista.viagem_id
66. 1,136.565 1,136.565 ↑ 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=43.687..1,136.565 rows=1,246,647 loops=1)

67. 7.305 12,801.264 ↓ 5.0 7,669 1

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

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

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

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

Seq Scan on viagem (cost=0.00..179,913.01 rows=8,655 width=55) (actual time=1,981.456..12,769.714 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.056 16.137 ↑ 1.0 127 1

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

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

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

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

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

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

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

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

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

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

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

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

Hash Join (cost=257,117.23..1,245,716.72 rows=27,108 width=32) (actual time=2,401.748..6,444.414 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.758 2,767.121 ↓ 6.1 1,241,458 1

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

78. 751.225 2,646.363 ↓ 6.1 1,241,458 1

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

  • Group Key: elementoviagem_3.viagem_id
79. 1,895.138 1,895.138 ↑ 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=43.636..1,895.138 rows=5,478,352 loops=1)

  • Heap Fetches: 5478352
80. 1,168.261 2,216.404 ↑ 1.0 5,424,106 1

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

  • Buckets: 65536 Batches: 128 Memory Usage: 3106kB
81. 1,048.143 1,048.143 ↑ 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,048.143 rows=5,478,352 loops=1)

82. 3,627.910 3,627.910 ↑ 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.473..0.473 rows=1 loops=7,670)

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

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

  • Index Cond: (id = pontoorigem.endereco_id)
84. 12,410.060 12,410.060 ↑ 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.617..1.618 rows=1 loops=7,670)

  • Index Cond: (id = f_1.ponto_id)
85. 33,609.940 33,609.940 ↑ 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.381..4.382 rows=1 loops=7,670)

  • Index Cond: (id = pontodestino.endereco_id)
86. 69.030 69.030 ↑ 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.007..0.009 rows=5 loops=7,670)

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

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

88. 161.226 2,349.225 ↓ 2.1 213,727 1

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

  • Group Key: pesquisa_1.empresa_id, pesquisa_1.motorista_id
89. 922.785 2,187.999 ↑ 1.0 1,039,111 1

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

  • Sort Key: pesquisa_1.empresa_id, pesquisa_1.motorista_id
  • Sort Method: external merge Disk: 30904kB
90. 1,265.214 1,265.214 ↑ 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=0.029..1,265.214 rows=1,039,590 loops=1)

91. 456.192 456.192 ↓ 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.012..0.012 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. 199.935 199.935 ↑ 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.005..0.005 rows=1 loops=39,987)

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

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

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

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

96. 104.320 317.534 ↑ 1.0 717,513 1

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

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

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

98. 44.636 278.945 ↑ 1.0 206,532 1

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

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

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

100. 0.038 12.528 ↑ 1.0 105 1

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

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

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

102. 165.436 5,944.108 ↓ 1.0 1,273,799 1

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

103. 236.234 5,778.672 ↑ 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,986.832..5,778.672 rows=1,241,457 loops=1)

104. 334.100 5,542.438 ↑ 1.0 1,241,457 1

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

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

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

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

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

  • Hash Cond: (h.usuario_id = u_1.id)
107. 3,676.446 3,973.566 ↑ 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.067..3,973.566 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.120 297.120 ↑ 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.120..297.120 rows=1,241,457 loops=1)

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

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

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

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

111. 115.754 3,724.312 ↓ 1.0 879,138 1

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

112. 240.434 3,608.558 ↓ 1.0 865,592 1

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

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

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

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

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

  • Hash Cond: (h_1.usuario_id = u_2.id)
115. 2,326.341 2,547.335 ↓ 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=227.782..2,547.335 rows=874,413 loops=1)

  • Recheck Cond: (acao = 'A'::bpchar)
  • Rows Removed by Index Recheck: 2702855
  • Heap Blocks: exact=30522 lossy=26426
116. 220.994 220.994 ↓ 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=220.994..220.994 rows=874,413 loops=1)

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

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

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

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