explain.depesz.com

PostgreSQL's explain analyze made readable

Result: zUO

Settings
# exclusive inclusive rows x rows loops node
1. 2.941 17,827.068 ↓ 3.6 4,368 1

HashAggregate (cost=148,422.84..148,434.95 rows=1,211 width=71) (actual time=17,826.121..17,827.068 rows=4,368 loops=1)

  • Group Key: n.id, n.identificacao_usual, n.categoria, (CASE WHEN (vw.cobertura_id IS NOT NULL) THEN true ELSE false END), (CASE WHEN (vw.cobertura_id IS NOT NULL) THEN vw.cobertura_id ELSE NULL::integer END)
2.          

CTE animais_aptos

3. 13,254.342 13,254.342 ↓ 1,028.4 5,142 1

Function Scan on obtenha_animais_estoque_por_contrato_propriedade (cost=0.25..12.75 rows=5 width=4) (actual time=13,250.390..13,254.342 rows=5,142 loops=1)

  • Filter: (propriedade_id = 3144)
  • Rows Removed by Filter: 36360
4.          

CTE novilhas

5. 2.431 13,417.191 ↓ 7.2 1,468 1

HashAggregate (cost=17,031.87..17,033.91 rows=204 width=11) (actual time=13,416.823..13,417.191 rows=1,468 loops=1)

  • Group Key: a.id, a.identificacao_usual, ('novilha'::text)
6. 0.713 13,414.760 ↓ 21.4 4,373 1

Append (cost=48.67..17,030.34 rows=204 width=11) (actual time=2.417..13,414.760 rows=4,373 loops=1)

7. 15.011 115.105 ↓ 17.7 3,570 1

Nested Loop Anti Join (cost=48.67..16,926.73 rows=202 width=11) (actual time=2.416..115.105 rows=3,570 loops=1)

8. 6.525 59.242 ↓ 101.1 20,426 1

Nested Loop (cost=48.11..15,174.89 rows=202 width=11) (actual time=0.787..59.242 rows=20,426 loops=1)

9. 11.536 12.149 ↓ 12.1 3,688 1

Bitmap Heap Scan on mbw_animal a (cost=47.55..7,635.52 rows=306 width=11) (actual time=0.714..12.149 rows=3,688 loops=1)

  • Recheck Cond: (propriedade_id = 3144)
  • Filter: ((data_morte IS NULL) AND ((data_descarte_reprodutor IS NULL) OR (data_descarte_reprodutor < '2018-07-01'::date)) AND (tipo_id <> 4) AND (sexo = 0) AND (((date_part('year'::text, age('2018-07-01 00:00:00'::timestamp without time zone, (data_nascimento)::timestamp without time zone)) * '12'::double precision) + date_part('month'::text, age('2018-07-01 00:00:00'::timestamp without time zone, (data_nascimento)::timestamp without time zone))) > '16'::double precision))
  • Rows Removed by Filter: 4220
  • Heap Blocks: exact=662
10. 0.613 0.613 ↓ 3.9 7,908 1

Bitmap Index Scan on mbw_animal_62d4a177 (cost=0.00..47.48 rows=2,006 width=0) (actual time=0.613..0.613 rows=7,908 loops=1)

  • Index Cond: (propriedade_id = 3144)
11. 40.568 40.568 ↓ 1.5 6 3,688

Index Scan using vw_modelo_reprodutivo_data_hora_cobertura_idx on vw_modelo_reprodutivo cb (cost=0.56..24.60 rows=4 width=4) (actual time=0.004..0.011 rows=6 loops=3,688)

  • Index Cond: ((femea_id = a.id) AND (data_hora_cobertura < '2018-07-01 00:00:00-03'::timestamp with time zone))
  • Filter: (cobertura_situacao_nome <> ALL ('{Servida,Gestante}'::text[]))
  • Rows Removed by Filter: 0
12. 40.852 40.852 ↑ 1.0 1 20,426

Index Scan using vw_modelo_reprodutivo_data_hora_cobertura_idx on vw_modelo_reprodutivo m (cost=0.56..8.63 rows=1 width=4) (actual time=0.002..0.002 rows=1 loops=20,426)

  • Index Cond: ((femea_id = a.id) AND (data_hora_cobertura < '2018-07-01 00:00:00-03'::timestamp with time zone) AND (propriedade_id = 3144))
  • Filter: ((data_parto IS NOT NULL) AND (situacao_cria = ANY ('{Vivo,Descartado}'::text[])))
13. 0.151 13,285.957 ↓ 757.0 757 1

Nested Loop Anti Join (cost=0.99..50.28 rows=1 width=11) (actual time=13,250.452..13,285.957 rows=757 loops=1)

14. 3.114 13,274.295 ↓ 3,837.0 3,837 1

Nested Loop (cost=0.43..42.55 rows=1 width=11) (actual time=13,250.434..13,274.295 rows=3,837 loops=1)

15. 13,255.755 13,255.755 ↓ 1,028.4 5,142 1

CTE Scan on animais_aptos apt (cost=0.00..0.10 rows=5 width=4) (actual time=13,250.393..13,255.755 rows=5,142 loops=1)

16. 15.426 15.426 ↑ 1.0 1 5,142

Index Scan using mbw_animal_pkey on mbw_animal a_1 (cost=0.43..8.48 rows=1 width=11) (actual time=0.003..0.003 rows=1 loops=5,142)

  • Index Cond: (id = apt.id_animal)
  • Filter: ((tipo_id <> 4) AND (contrato_id = 16) AND (sexo = 0) AND (((date_part('year'::text, age('2018-07-01 00:00:00'::timestamp without time zone, (data_nascimento)::timestamp without time zone)) * '12'::double precision) + date_part('month'::text, age('2018-07-01 00:00:00'::timestamp without time zone, (data_nascimento)::timestamp without time zone))) > '16'::double precision))
  • Rows Removed by Filter: 0
17. 11.511 11.511 ↑ 1.0 1 3,837

Index Only Scan using vw_modelo_reprodutivo_data_hora_cobertura_idx on vw_modelo_reprodutivo (cost=0.56..4.14 rows=1 width=4) (actual time=0.003..0.003 rows=1 loops=3,837)

  • Index Cond: ((femea_id = a_1.id) AND (data_hora_cobertura < '2018-07-01 00:00:00-03'::timestamp with time zone) AND (propriedade_id = 3144) AND (contrato_id = 16))
  • Heap Fetches: 0
18. 0.154 12.985 ↓ 46.0 46 1

Nested Loop Anti Join (cost=0.99..51.29 rows=1 width=11) (actual time=11.081..12.985 rows=46 loops=1)

19. 0.860 11.915 ↓ 229.0 229 1

Nested Loop (cost=0.43..42.56 rows=1 width=11) (actual time=0.077..11.915 rows=229 loops=1)

20. 0.771 0.771 ↓ 1,028.4 5,142 1

CTE Scan on animais_aptos apt_1 (cost=0.00..0.10 rows=5 width=4) (actual time=0.001..0.771 rows=5,142 loops=1)

21. 10.284 10.284 ↓ 0.0 0 5,142

Index Scan using mbw_animal_pkey on mbw_animal a_2 (cost=0.43..8.48 rows=1 width=11) (actual time=0.002..0.002 rows=0 loops=5,142)

  • Index Cond: (id = apt_1.id_animal)
  • Filter: ((data_descarte_reprodutor >= '2018-07-01'::date) AND (contrato_id = 16) AND (sexo = 0) AND (tipo_id = 4) AND (((date_part('year'::text, age('2018-07-01 00:00:00'::timestamp without time zone, (data_nascimento)::timestamp without time zone)) * '12'::double precision) + date_part('month'::text, age('2018-07-01 00:00:00'::timestamp without time zone, (data_nascimento)::timestamp without time zone))) > '16'::double precision))
  • Rows Removed by Filter: 1
22. 0.916 0.916 ↑ 1.0 1 229

Index Only Scan using vw_modelo_reprodutivo_data_hora_cobertura_idx on vw_modelo_reprodutivo vw_modelo_reprodutivo_1 (cost=0.56..4.64 rows=1 width=4) (actual time=0.004..0.004 rows=1 loops=229)

  • Index Cond: ((femea_id = a_2.id) AND (data_hora_cobertura < '2018-07-01 00:00:00-03'::timestamp with time zone) AND (propriedade_id = 3144) AND (contrato_id = 16))
  • Heap Fetches: 0
23.          

CTE retirada_em

24. 7.530 45.338 ↓ 32.8 8,101 1

HashAggregate (cost=118,713.69..118,716.16 rows=247 width=11) (actual time=42.484..45.338 rows=8,101 loops=1)

  • Group Key: a_3.id, a_3.identificacao_usual, ('Mortes'::text)
25. 1.333 37.808 ↓ 32.8 8,101 1

Append (cost=40.73..118,711.84 rows=247 width=11) (actual time=0.237..37.808 rows=8,101 loops=1)

26. 0.308 8.950 ↓ 30.8 1,633 1

Nested Loop (cost=40.73..19,377.20 rows=53 width=11) (actual time=0.237..8.950 rows=1,633 loops=1)

27. 0.782 0.942 ↑ 1.0 1,925 1

Bitmap Heap Scan on mbw_morte m_1 (cost=40.30..3,189.93 rows=1,953 width=4) (actual time=0.182..0.942 rows=1,925 loops=1)

  • Recheck Cond: (contrato_id = 16)
  • Filter: (tipo_id <> 98)
  • Rows Removed by Filter: 8
  • Heap Blocks: exact=55
28. 0.160 0.160 ↑ 1.1 1,933 1

Bitmap Index Scan on mbw_morte_868819a8 (cost=0.00..39.81 rows=2,052 width=0) (actual time=0.160..0.160 rows=1,933 loops=1)

  • Index Cond: (contrato_id = 16)
29. 7.700 7.700 ↑ 1.0 1 1,925

Index Scan using mbw_animal_pkey on mbw_animal a_3 (cost=0.43..8.28 rows=1 width=11) (actual time=0.004..0.004 rows=1 loops=1,925)

  • Index Cond: (id = m_1.animal_id)
  • Filter: (data_morte <= '2019-03-31'::date)
  • Rows Removed by Filter: 0
30. 2.707 3.418 ↓ 0.0 0 1

Bitmap Heap Scan on mbw_animal a_4 (cost=47.48..7,585.29 rows=12 width=11) (actual time=3.418..3.418 rows=0 loops=1)

  • Recheck Cond: (propriedade_id = 3144)
  • Filter: ((data_descarte_reprodutor <= '2019-03-31'::date) AND (situacao_id <> 4))
  • Rows Removed by Filter: 7908
  • Heap Blocks: exact=662
31. 0.711 0.711 ↓ 3.9 7,908 1

Bitmap Index Scan on mbw_animal_62d4a177 (cost=0.00..47.48 rows=2,006 width=0) (actual time=0.711..0.711 rows=7,908 loops=1)

  • Index Cond: (propriedade_id = 3144)
32. 0.011 0.179 ↓ 9.0 36 1

Nested Loop (cost=32.45..359.87 rows=4 width=11) (actual time=0.079..0.179 rows=36 loops=1)

33. 0.016 0.096 ↓ 9.0 36 1

Nested Loop (cost=32.02..356.08 rows=4 width=4) (actual time=0.068..0.096 rows=36 loops=1)

34. 0.022 0.058 ↑ 1.0 1 1

Bitmap Heap Scan on mbw_venda v_1 (cost=31.59..35.61 rows=1 width=4) (actual time=0.052..0.058 rows=1 loops=1)

  • Recheck Cond: ((propriedade_id = 3144) AND (contrato_id = 16))
  • Filter: ((tipo_venda_id <> 5) AND (data <= '2019-03-31'::date))
  • Rows Removed by Filter: 12
  • Heap Blocks: exact=5
35. 0.004 0.036 ↓ 0.0 0 1

BitmapAnd (cost=31.59..31.59 rows=1 width=0) (actual time=0.036..0.036 rows=0 loops=1)

36. 0.016 0.016 ↑ 19.5 13 1

Bitmap Index Scan on mbw_venda_62d4a177 (cost=0.00..6.33 rows=254 width=0) (actual time=0.016..0.016 rows=13 loops=1)

  • Index Cond: (propriedade_id = 3144)
37. 0.016 0.016 ↑ 13.6 84 1

Bitmap Index Scan on mbw_venda_868819a8 (cost=0.00..25.00 rows=1,144 width=0) (actual time=0.016..0.016 rows=84 loops=1)

  • Index Cond: (contrato_id = 16)
38. 0.022 0.022 ↑ 2.4 36 1

Index Scan using mbw_vendaitens_2f2a853d on mbw_vendaitens vi (cost=0.43..319.61 rows=87 width=8) (actual time=0.011..0.022 rows=36 loops=1)

  • Index Cond: (venda_id = v_1.id)
39. 0.072 0.072 ↑ 1.0 1 36

Index Scan using mbw_animal_pkey on mbw_animal a_5 (cost=0.43..0.94 rows=1 width=11) (actual time=0.002..0.002 rows=1 loops=36)

  • Index Cond: (id = vi.animal_id)
40. 0.001 0.032 ↓ 0.0 0 1

Nested Loop (cost=115.08..5,661.09 rows=1 width=11) (actual time=0.032..0.032 rows=0 loops=1)

41. 0.000 0.031 ↓ 0.0 0 1

Nested Loop (cost=114.65..5,653.11 rows=1 width=4) (actual time=0.031..0.031 rows=0 loops=1)

42. 0.031 0.031 ↓ 0.0 0 1

Index Scan using mbw_venda_62d4a177 on mbw_venda v_2 (cost=0.42..804.88 rows=41 width=4) (actual time=0.031..0.031 rows=0 loops=1)

  • Index Cond: (propriedade_id = 31557)
  • Filter: ((data <= '2019-03-31'::date) AND (tipo_venda_id = 5))
43. 0.000 0.000 ↓ 0.0 0

Bitmap Heap Scan on mbw_vendaitens vi_1 (cost=114.22..118.24 rows=1 width=8) (never executed)

  • Recheck Cond: ((venda_id = v_2.id) AND (contrato_id = 16))
44. 0.000 0.000 ↓ 0.0 0

BitmapAnd (cost=114.22..114.22 rows=1 width=0) (never executed)

45. 0.000 0.000 ↓ 0.0 0

Bitmap Index Scan on mbw_vendaitens_2f2a853d (cost=0.00..5.08 rows=87 width=0) (never executed)

  • Index Cond: (venda_id = v_2.id)
46. 0.000 0.000 ↓ 0.0 0

Bitmap Index Scan on mbw_vendaitens_868819a8 (cost=0.00..107.46 rows=5,737 width=0) (never executed)

  • Index Cond: (contrato_id = 16)
47. 0.000 0.000 ↓ 0.0 0

Index Scan using mbw_animal_pkey on mbw_animal a_6 (cost=0.43..7.97 rows=1 width=11) (never executed)

  • Index Cond: (id = vi_1.animal_id)
48. 0.867 23.896 ↓ 36.3 6,432 1

Nested Loop (cost=175.90..85,725.93 rows=177 width=11) (actual time=0.721..23.896 rows=6,432 loops=1)

49. 3.058 3.733 ↑ 1.3 6,432 1

Bitmap Heap Scan on mbw_transferenciapropriedade t (cost=175.47..21,788.66 rows=8,193 width=4) (actual time=0.708..3.733 rows=6,432 loops=1)

  • Recheck Cond: (propriedade_origem_id = 3144)
  • Filter: (data <= '2019-03-31'::date)
  • Rows Removed by Filter: 2690
  • Heap Blocks: exact=184
50. 0.675 0.675 ↑ 1.0 9,122 1

Bitmap Index Scan on mbw_transferenciapropriedade_f8de2aa4 (cost=0.00..173.42 rows=9,199 width=0) (actual time=0.675..0.675 rows=9,122 loops=1)

  • Index Cond: (propriedade_origem_id = 3144)
51. 19.296 19.296 ↑ 1.0 1 6,432

Index Scan using mbw_animal_pkey on mbw_animal a_7 (cost=0.43..7.79 rows=1 width=11) (actual time=0.002..0.003 rows=1 loops=6,432)

  • Index Cond: (id = t.animal_id)
  • Filter: (contrato_id = 16)
52. 0.559 17,824.127 ↓ 3.6 4,379 1

Append (cost=1,771.74..12,644.88 rows=1,211 width=71) (actual time=13,422.788..17,824.127 rows=4,379 loops=1)

53. 1.141 13,423.064 ↓ 7.2 1,468 1

HashAggregate (cost=1,771.74..1,773.78 rows=204 width=98) (actual time=13,422.786..13,423.064 rows=1,468 loops=1)

  • Group Key: n.id, n.identificacao_usual, n.categoria, CASE WHEN (vw.cobertura_id IS NOT NULL) THEN true ELSE false END, CASE WHEN (vw.cobertura_id IS NOT NULL) THEN vw.cobertura_id ELSE NULL::integer END
54. 1.134 13,421.923 ↓ 7.2 1,468 1

Nested Loop Left Join (cost=0.56..1,769.19 rows=204 width=98) (actual time=13,416.835..13,421.923 rows=1,468 loops=1)

55. 13,417.853 13,417.853 ↓ 7.2 1,468 1

CTE Scan on novilhas n (cost=0.00..4.08 rows=204 width=94) (actual time=13,416.826..13,417.853 rows=1,468 loops=1)

56. 2.936 2.936 ↓ 0.0 0 1,468

Index Scan using vw_modelo_reprodutivo_data_hora_cobertura_idx on vw_modelo_reprodutivo vw (cost=0.56..8.64 rows=1 width=8) (actual time=0.002..0.002 rows=0 loops=1,468)

  • Index Cond: ((femea_id = n.id) AND (data_hora_cobertura < '2018-07-01 00:00:00-03'::timestamp with time zone) AND (propriedade_id = 3144) AND (contrato_id = 16))
57. 3,888.060 3,888.060 ↑ 1.2 4 1

Function Scan on reprodutivo_partos_previstos (cost=0.25..10.25 rows=5 width=66) (actual time=3,887.786..3,888.060 rows=4 loops=1)

  • Filter: (data_parto IS NULL)
  • Rows Removed by Filter: 2217
58. 3.635 76.888 ↓ 71.0 71 1

Nested Loop (cost=0.56..2,142.72 rows=1 width=14) (actual time=42.752..76.888 rows=71 loops=1)

59. 48.950 48.950 ↓ 32.8 8,101 1

CTE Scan on retirada_em r (cost=0.00..4.94 rows=247 width=4) (actual time=42.489..48.950 rows=8,101 loops=1)

60. 24.303 24.303 ↓ 0.0 0 8,101

Index Scan using vw_modelo_reprodutivo_data_hora_cobertura_idx on vw_modelo_reprodutivo vw_1 (cost=0.56..8.64 rows=1 width=14) (actual time=0.003..0.003 rows=0 loops=8,101)

  • Index Cond: ((femea_id = r.id) AND (propriedade_id = 3144) AND (contrato_id = 16))
  • Filter: (cobertura_situacao_nome = 'Gestante'::text)
  • Rows Removed by Filter: 0
61. 0.158 347.503 ↓ 0.0 0 1

Nested Loop Anti Join (cost=1.24..8,695.77 rows=1 width=66) (actual time=347.503..347.503 rows=0 loops=1)

62. 0.125 345.893 ↓ 242.0 242 1

Nested Loop (cost=0.81..8,639.75 rows=1 width=66) (actual time=341.660..345.893 rows=242 loops=1)

63. 341.654 341.654 ↑ 4.1 242 1

Function Scan on reprodutivo_partos_perdas f (cost=0.25..10.25 rows=1,000 width=66) (actual time=341.612..341.654 rows=242 loops=1)

64. 4.114 4.114 ↑ 1.0 1 242

Index Scan using vw_modelo_reprodutivo_data_hora_cobertura_idx on vw_modelo_reprodutivo vw_2 (cost=0.56..8.62 rows=1 width=8) (actual time=0.015..0.017 rows=1 loops=242)

  • Index Cond: ((femea_id = f.femea_id) AND (propriedade_id = 3144) AND (contrato_id = 16))
  • Filter: ((categoria_femea <> 'Novilha'::text) AND (f.cobertura_id = cobertura_id))
  • Rows Removed by Filter: 5
65. 1.452 1.452 ↑ 1.0 1 242

Index Scan using vw_modelo_reprodutivo_femea_id_idx on vw_modelo_reprodutivo v (cost=0.43..28.22 rows=1 width=4) (actual time=0.006..0.006 rows=1 loops=242)

  • Index Cond: (f.femea_id = femea_id)
  • Filter: ((situacao_cria = 'Vivo'::text) AND (propriedade_id = 3144) AND (contrato_id = 16))
  • Rows Removed by Filter: 1
66. 88.053 88.053 ↓ 2.8 2,836 1

Function Scan on reprodutivo_partos_realizados f_1 (cost=0.25..10.25 rows=1,000 width=66) (actual time=87.506..88.053 rows=2,836 loops=1)

Planning time : 3.967 ms
Execution time : 17,828.897 ms