explain.depesz.com

PostgreSQL's explain analyze made readable

Result: NZiU

Settings
# exclusive inclusive rows x rows loops node
1. 0.009 1,480.922 ↓ 50.0 50 1

Limit (cost=1,082.54..1,082.55 rows=1 width=121) (actual time=1,480.910..1,480.922 rows=50 loops=1)

2. 1.249 1,480.913 ↓ 50.0 50 1

Sort (cost=1,082.54..1,082.55 rows=1 width=121) (actual time=1,480.909..1,480.913 rows=50 loops=1)

  • Sort Key: v0_.id
  • Sort Method: top-N heapsort Memory: 50kB
3. 903.888 1,479.664 ↓ 3,950.0 3,950 1

Nested Loop (cost=844.76..1,082.53 rows=1 width=121) (actual time=7.503..1,479.664 rows=3,950 loops=1)

  • Join Filter: ((c1_.contractor_company_id = v0_.company_id) OR (c1_.contractor_person_id = v0_.person_id))
  • Rows Removed by Join Filter: 15618306
4. 0.505 10.497 ↓ 104.0 3,953 1

Subquery Scan on v0_ (cost=764.58..991.38 rows=38 width=121) (actual time=6.271..10.497 rows=3,953 loops=1)

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

WindowAgg (cost=764.58..928.38 rows=5,040 width=121) (actual time=6.270..9.992 rows=3,953 loops=1)

6. 3.604 8.085 ↑ 1.3 3,953 1

HashAggregate (cost=764.58..814.98 rows=5,040 width=113) (actual time=6.265..8.085 rows=3,953 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.198 4.481 ↑ 1.3 3,953 1

Append (cost=322.10..663.78 rows=5,040 width=113) (actual time=1.868..4.481 rows=3,953 loops=1)

8. 1.880 4.275 ↑ 1.0 3,953 1

Hash Join (cost=322.10..551.86 rows=4,069 width=113) (actual time=1.868..4.275 rows=3,953 loops=1)

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

Seq Scan on divisions d (cost=0.00..96.94 rows=4,094 width=44) (actual time=0.008..0.545 rows=3,978 loops=1)

  • Filter: is_visible
10. 0.683 1.850 ↑ 1.0 3,953 1

Hash (cost=272.67..272.67 rows=3,954 width=135) (actual time=1.850..1.850 rows=3,953 loops=1)

  • Buckets: 4096 Batches: 1 Memory Usage: 680kB
11. 1.167 1.167 ↑ 1.0 3,953 1

Seq Scan on companies co (cost=0.00..272.67 rows=3,954 width=135) (actual time=0.006..1.167 rows=3,953 loops=1)

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

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

13. 0.008 0.008 ↓ 0.0 0 1

Seq Scan on persons p (cost=0.00..1.07 rows=4 width=101) (actual time=0.007..0.008 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. 559.078 565.279 ↓ 1,317.3 3,952 3,953

Materialize (cost=80.17..89.16 rows=3 width=8) (actual time=0.000..0.143 rows=3,952 loops=3,953)

16. 0.758 6.201 ↓ 1,317.3 3,952 1

Nested Loop (cost=80.17..89.15 rows=3 width=8) (actual time=0.320..6.201 rows=3,952 loops=1)

17. 0.273 1.491 ↓ 1,317.3 3,952 1

Nested Loop (cost=79.89..88.10 rows=3 width=4) (actual time=0.313..1.491 rows=3,952 loops=1)

18. 0.002 0.299 ↑ 1.0 1 1

Nested Loop (cost=79.60..87.63 rows=1 width=8) (actual time=0.298..0.299 rows=1 loops=1)

19. 0.003 0.291 ↑ 1.0 1 1

HashAggregate (cost=79.32..79.33 rows=1 width=4) (actual time=0.291..0.291 rows=1 loops=1)

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

Nested Loop (cost=0.28..79.32 rows=1 width=4) (actual time=0.038..0.288 rows=1 loops=1)

21. 0.255 0.255 ↑ 1.0 1 1

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

  • Filter: (employee_id = 61)
  • Rows Removed by Filter: 3950
22. 0.032 0.032 ↑ 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.031..0.032 rows=1 loops=1)

  • Index Cond: (id = 61)
  • Heap Fetches: 1
23. 0.006 0.006 ↑ 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.006..0.006 rows=1 loops=1)

  • Index Cond: (id = c4_.group_id)
  • Heap Fetches: 1
24. 0.919 0.919 ↓ 1,317.3 3,952 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.919 rows=3,952 loops=1)

  • Index Cond: (group_id = c2_.id)
  • Heap Fetches: 3952
25. 3.952 3.952 ↑ 1.0 1 3,952

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

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