explain.depesz.com

PostgreSQL's explain analyze made readable

Result: Ohhr

Settings
# exclusive inclusive rows x rows loops node
1. 0.011 1,053.624 ↓ 50.0 50 1

Limit (cost=876.26..876.26 rows=1 width=121) (actual time=1,053.608..1,053.624 rows=50 loops=1)

2. 1.612 1,053.613 ↓ 50.0 50 1

Sort (cost=876.26..876.26 rows=1 width=121) (actual time=1,053.607..1,053.613 rows=50 loops=1)

  • Sort Key: v0_.id
  • Sort Method: top-N heapsort Memory: 50kB
3. 638.995 1,052.001 ↓ 3,162.0 3,162 1

Nested Loop (cost=676.09..876.25 rows=1 width=121) (actual time=9.597..1,052.001 rows=3,162 loops=1)

  • Join Filter: ((c1_.contractor_company_id = v0_.company_id) OR (c1_.contractor_person_id = v0_.person_id))
  • Rows Removed by Join Filter: 10010898
4. 0.625 14.216 ↓ 102.1 3,165 1

Subquery Scan on v0_ (cost=607.91..797.45 rows=31 width=121) (actual time=8.399..14.216 rows=3,165 loops=1)

  • Filter: (v0_.is_active AND ((v0_.external_type IS NULL) OR (v0_.external_type = ANY ('{1,2}'::integer[]))))
5. 2.836 13.591 ↑ 1.3 3,165 1

WindowAgg (cost=607.91..744.80 rows=4,212 width=121) (actual time=8.398..13.591 rows=3,165 loops=1)

6. 6.824 10.755 ↑ 1.3 3,165 1

HashAggregate (cost=607.91..650.03 rows=4,212 width=113) (actual time=8.392..10.755 rows=3,165 loops=1)

  • Group Key: (NULL::integer), d.id, d.company_id, ('division'::text), ((((co.name)::text || ', '::text) || CASE WHEN (d.id = co.head_division_id) THEN (('ИНН: '::text || (co.inn)::text) || COALESCE((', ОГРН:'::text || (co.ogrn)::text), ''::text)) ELSE ((d.title)::text || COALESCE((', КПП: '::text || (d.kpp)::text), ''::text)) END)), ((((co.name)::text || ((co.head_division_id <> d.id))::text) || (d.title)::text)), co.is_active, co.external_type
7. 0.168 3.931 ↑ 1.3 3,165 1

Append (cost=238.69..523.67 rows=4,212 width=113) (actual time=1.619..3.931 rows=3,165 loops=1)

8. 1.628 3.753 ↑ 1.0 3,165 1

Hash Join (cost=238.69..424.17 rows=3,241 width=113) (actual time=1.618..3.753 rows=3,165 loops=1)

  • Hash Cond: (d.company_id = co.id)
9. 0.536 0.536 ↑ 1.0 3,190 1

Seq Scan on divisions d (cost=0.00..79.66 rows=3,266 width=44) (actual time=0.009..0.536 rows=3,190 loops=1)

  • Filter: is_visible
10. 0.598 1.589 ↓ 1.0 3,165 1

Hash (cost=199.91..199.91 rows=3,103 width=135) (actual time=1.589..1.589 rows=3,165 loops=1)

  • Buckets: 4096 Batches: 1 Memory Usage: 551kB
11. 0.991 0.991 ↓ 1.0 3,165 1

Seq Scan on companies co (cost=0.00..199.91 rows=3,103 width=135) (actual time=0.007..0.991 rows=3,165 loops=1)

  • Filter: (is_active AND (type_id = ANY ('{2,3}'::integer[])) AND (step_id = 3))
  • Rows Removed by Filter: 25
12. 0.001 0.010 ↓ 0.0 0 1

Nested Loop (cost=0.15..36.32 rows=971 width=113) (actual time=0.010..0.010 rows=0 loops=1)

13. 0.009 0.009 ↓ 0.0 0 1

Seq Scan on persons p (cost=0.00..1.07 rows=4 width=101) (actual time=0.009..0.009 rows=0 loops=1)

  • Filter: is_active
  • Rows Removed by Filter: 7
14. 0.000 0.000 ↓ 0.0 0

Index Only Scan using natural_entities_person_idx on natural_entities ne (cost=0.15..5.17 rows=1 width=4) (never executed)

  • Index Cond: (person_id = p.id)
  • Heap Fetches: 0
15. 393.845 398.790 ↓ 1,054.7 3,164 3,165

Materialize (cost=68.19..77.18 rows=3 width=8) (actual time=0.000..0.126 rows=3,164 loops=3,165)

16. 0.599 4.945 ↓ 1,054.7 3,164 1

Nested Loop (cost=68.19..77.16 rows=3 width=8) (actual time=0.248..4.945 rows=3,164 loops=1)

17. 0.230 1.182 ↓ 1,054.7 3,164 1

Nested Loop (cost=67.90..76.11 rows=3 width=4) (actual time=0.241..1.182 rows=3,164 loops=1)

18. 0.003 0.226 ↑ 1.0 1 1

Nested Loop (cost=67.62..75.65 rows=1 width=8) (actual time=0.225..0.226 rows=1 loops=1)

19. 0.003 0.218 ↑ 1.0 1 1

HashAggregate (cost=67.34..67.35 rows=1 width=4) (actual time=0.218..0.218 rows=1 loops=1)

  • Group Key: c4_.group_id
20. 0.002 0.215 ↑ 1.0 1 1

Nested Loop (cost=0.28..67.33 rows=1 width=4) (actual time=0.016..0.215 rows=1 loops=1)

21. 0.204 0.204 ↑ 1.0 1 1

Seq Scan on contractor_groups_employees c4_ (cost=0.00..59.03 rows=1 width=8) (actual time=0.006..0.204 rows=1 loops=1)

  • Filter: (employee_id = 61)
  • Rows Removed by Filter: 3162
22. 0.009 0.009 ↑ 1.0 1 1

Index Only Scan using employees_pkey on employees e5_ (cost=0.28..8.30 rows=1 width=4) (actual time=0.009..0.009 rows=1 loops=1)

  • Index Cond: (id = 61)
  • Heap Fetches: 1
23. 0.005 0.005 ↑ 1.0 1 1

Index Only Scan using contractor_groups_pkey on contractor_groups c2_ (cost=0.28..8.30 rows=1 width=4) (actual time=0.005..0.005 rows=1 loops=1)

  • Index Cond: (id = c4_.group_id)
  • Heap Fetches: 1
24. 0.726 0.726 ↓ 1,054.7 3,164 1

Index Only Scan using contractors_groups_group_id_contractor_id_uq on contractors_groups c3_ (cost=0.29..0.44 rows=3 width=8) (actual time=0.015..0.726 rows=3,164 loops=1)

  • Index Cond: (group_id = c2_.id)
  • Heap Fetches: 3165
25. 3.164 3.164 ↑ 1.0 1 3,164

Index Scan using contractors_companies_pkey on contractors_companies c1_ (cost=0.29..0.35 rows=1 width=12) (actual time=0.001..0.001 rows=1 loops=3,164)

  • Index Cond: (id = c3_.contractor_id)
  • Filter: (status_id = 1)
Planning time : 1.786 ms
Execution time : 1,053.745 ms