explain.depesz.com

PostgreSQL's explain analyze made readable

Result: 3LMn

Settings
# exclusive inclusive rows x rows loops node
1. 2.565 2,992.329 ↓ 7.3 1,468 1

HashAggregate (cost=15,798.91..15,800.91 rows=200 width=11) (actual time=2,991.956..2,992.329 rows=1,468 loops=1)

  • Group Key: a.id, a.identificacao_usual, ('novilha'::text)
2.          

CTE animais_aptos

3. 2,752.336 2,752.336 ↓ 1,028.4 5,142 1

Function Scan on obtenha_animais_estoque_por_contrato_teste (cost=0.25..12.75 rows=5 width=4) (actual time=2,749.710..2,752.336 rows=5,142 loops=1)

  • Filter: (propriedade_id = 3144)
  • Rows Removed by Filter: 36360
4. 0.773 2,989.764 ↓ 21.9 4,373 1

Append (cost=47.60..15,784.66 rows=200 width=11) (actual time=51.236..2,989.764 rows=4,373 loops=1)

5. 17.365 189.048 ↓ 18.0 3,570 1

Nested Loop Anti Join (cost=47.60..15,681.73 rows=198 width=11) (actual time=51.236..189.048 rows=3,570 loops=1)

6. 4.103 130.831 ↓ 103.2 20,426 1

Nested Loop (cost=47.04..13,967.29 rows=198 width=11) (actual time=48.299..130.831 rows=20,426 loops=1)

7. 12.312 60.344 ↓ 13.3 3,688 1

Bitmap Heap Scan on mbw_animal a (cost=46.48..7,118.56 rows=278 width=11) (actual time=48.169..60.344 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=661
8. 48.032 48.032 ↓ 4.2 7,908 1

Bitmap Index Scan on mbw_animal_62d4a177 (cost=0.00..46.41 rows=1,864 width=0) (actual time=48.032..48.032 rows=7,908 loops=1)

  • Index Cond: (propriedade_id = 3144)
9. 66.384 66.384 ↓ 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.018 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
10. 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.62 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[])))
11. 0.665 2,785.828 ↓ 757.0 757 1

Nested Loop Anti Join (cost=0.99..49.64 rows=1 width=11) (actual time=2,749.827..2,785.828 rows=757 loops=1)

12. 4.280 2,773.652 ↓ 3,837.0 3,837 1

Nested Loop (cost=0.43..42.55 rows=1 width=11) (actual time=2,749.804..2,773.652 rows=3,837 loops=1)

13. 2,753.946 2,753.946 ↓ 1,028.4 5,142 1

CTE Scan on animais_aptos apt (cost=0.00..0.10 rows=5 width=4) (actual time=2,749.715..2,753.946 rows=5,142 loops=1)

14. 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
15. 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..3.82 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
16. 0.176 14.115 ↓ 46.0 46 1

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

17. 1.826 13.023 ↓ 229.0 229 1

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

18. 0.913 0.913 ↓ 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.913 rows=5,142 loops=1)

19. 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
20. 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
Planning time : 8.056 ms
Execution time : 2,993.507 ms