explain.depesz.com

PostgreSQL's explain analyze made readable

Result: R8eE

Settings
# exclusive inclusive rows x rows loops node
1. 0.022 1,287.459 ↓ 50.0 50 1

Limit (cost=938.31..938.31 rows=1 width=121) (actual time=1,287.434..1,287.459 rows=50 loops=1)

2. 2.158 1,287.437 ↓ 50.0 50 1

Sort (cost=938.31..938.31 rows=1 width=121) (actual time=1,287.433..1,287.437 rows=50 loops=1)

  • Sort Key: v0_.id
  • Sort Method: top-N heapsort Memory: 50kB
3. 776.544 1,285.279 ↓ 3,420.0 3,420 1

Nested Loop (cost=729.98..938.30 rows=1 width=121) (actual time=9.667..1,285.279 rows=3,420 loops=1)

  • Join Filter: ((c1_.contractor_company_id = v0_.company_id) OR (c1_.contractor_person_id = v0_.person_id))
  • Rows Removed by Join Filter: 11710086
4. 1.104 15.823 ↓ 103.7 3,423 1

Subquery Scan on v0_ (cost=658.51..856.10 rows=33 width=121) (actual time=8.503..15.823 rows=3,423 loops=1)

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

WindowAgg (cost=658.51..801.22 rows=4,391 width=121) (actual time=8.502..14.719 rows=3,423 loops=1)

6. 6.970 11.074 ↑ 1.3 3,423 1

HashAggregate (cost=658.51..702.42 rows=4,391 width=113) (actual time=8.497..11.074 rows=3,423 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.176 4.104 ↑ 1.3 3,423 1

Append (cost=271.41..570.69 rows=4,391 width=113) (actual time=1.650..4.104 rows=3,423 loops=1)

8. 1.596 3.917 ↓ 1.0 3,423 1

Hash Join (cost=271.41..468.50 rows=3,420 width=113) (actual time=1.650..3.917 rows=3,423 loops=1)

  • Hash Cond: (d.company_id = co.id)
9. 0.687 0.687 ↓ 1.0 3,448 1

Seq Scan on divisions d (cost=0.00..85.44 rows=3,444 width=44) (actual time=0.007..0.687 rows=3,448 loops=1)

  • Filter: is_visible
10. 0.614 1.634 ↓ 1.0 3,423 1

Hash (cost=228.66..228.66 rows=3,420 width=135) (actual time=1.633..1.634 rows=3,423 loops=1)

  • Buckets: 4096 Batches: 1 Memory Usage: 593kB
11. 1.020 1.020 ↓ 1.0 3,423 1

Seq Scan on companies co (cost=0.00..228.66 rows=3,420 width=135) (actual time=0.006..1.020 rows=3,423 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.011 ↓ 0.0 0 1

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

13. 0.010 0.010 ↓ 0.0 0 1

Seq Scan on persons p (cost=0.00..1.07 rows=4 width=101) (actual time=0.010..0.010 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. 486.036 492.912 ↓ 1,140.7 3,422 3,423

Materialize (cost=71.47..80.47 rows=3 width=8) (actual time=0.000..0.144 rows=3,422 loops=3,423)

16. 1.280 6.876 ↓ 1,140.7 3,422 1

Nested Loop (cost=71.47..80.45 rows=3 width=8) (actual time=0.280..6.876 rows=3,422 loops=1)

17. 1.123 2.174 ↓ 1,140.7 3,422 1

Nested Loop (cost=71.19..79.40 rows=3 width=4) (actual time=0.274..2.174 rows=3,422 loops=1)

18. 0.002 0.260 ↑ 1.0 1 1

Nested Loop (cost=70.90..78.93 rows=1 width=8) (actual time=0.259..0.260 rows=1 loops=1)

19. 0.003 0.253 ↑ 1.0 1 1

HashAggregate (cost=70.62..70.63 rows=1 width=4) (actual time=0.253..0.253 rows=1 loops=1)

  • Group Key: c4_.group_id
20. 0.001 0.250 ↑ 1.0 1 1

Nested Loop (cost=0.28..70.62 rows=1 width=4) (actual time=0.036..0.250 rows=1 loops=1)

21. 0.219 0.219 ↑ 1.0 1 1

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

  • Filter: (employee_id = 61)
  • Rows Removed by Filter: 3420
22. 0.030 0.030 ↑ 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.029..0.030 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.791 0.791 ↓ 1,140.7 3,422 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.014..0.791 rows=3,422 loops=1)

  • Index Cond: (group_id = c2_.id)
  • Heap Fetches: 3422
25. 3.422 3.422 ↑ 1.0 1 3,422

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,422)

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