explain.depesz.com

PostgreSQL's explain analyze made readable

Result: YFTW

Settings
# exclusive inclusive rows x rows loops node
1. 0.010 659.817 ↓ 50.0 50 1

Limit (cost=739.83..739.84 rows=1 width=121) (actual time=659.791..659.817 rows=50 loops=1)

2. 1.149 659.807 ↓ 50.0 50 1

Sort (cost=739.83..739.84 rows=1 width=121) (actual time=659.791..659.807 rows=50 loops=1)

  • Sort Key: v0_.id
  • Sort Method: top-N heapsort Memory: 50kB
3. 397.863 658.658 ↓ 2,544.0 2,544 1

Nested Loop (cost=577.51..739.82 rows=1 width=121) (actual time=5.462..658.658 rows=2,544 loops=1)

  • Join Filter: ((c1_.contractor_company_id = v0_.company_id) OR (c1_.contractor_person_id = v0_.person_id))
  • Rows Removed by Join Filter: 6482118
4. 0.599 8.642 ↓ 101.9 2,547 1

Subquery Scan on v0_ (cost=523.74..675.75 rows=25 width=121) (actual time=4.365..8.642 rows=2,547 loops=1)

  • Filter: (v0_.is_active AND ((v0_.external_type IS NULL) OR (v0_.external_type = ANY ('{1,2}'::integer[]))))
5. 2.114 8.043 ↑ 1.3 2,547 1

WindowAgg (cost=523.74..633.53 rows=3,378 width=121) (actual time=4.364..8.043 rows=2,547 loops=1)

6. 3.017 5.929 ↑ 1.3 2,547 1

HashAggregate (cost=523.74..557.52 rows=3,378 width=113) (actual time=4.359..5.929 rows=2,547 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.136 2.912 ↑ 1.3 2,547 1

Append (cost=198.88..456.18 rows=3,378 width=113) (actual time=1.271..2.912 rows=2,547 loops=1)

8. 1.150 2.772 ↓ 1.0 2,547 1

Hash Join (cost=198.88..344.95 rows=2,528 width=113) (actual time=1.270..2.772 rows=2,547 loops=1)

  • Hash Cond: (d.company_id = co.id)
9. 0.368 0.368 ↓ 1.0 2,572 1

Seq Scan on divisions d (cost=0.00..63.52 rows=2,552 width=44) (actual time=0.007..0.368 rows=2,572 loops=1)

  • Filter: is_visible
10. 0.536 1.254 ↓ 1.0 2,547 1

Hash (cost=167.28..167.28 rows=2,528 width=134) (actual time=1.254..1.254 rows=2,547 loops=1)

  • Buckets: 4096 Batches: 1 Memory Usage: 449kB
11. 0.718 0.718 ↓ 1.0 2,547 1

Seq Scan on companies co (cost=0.00..167.28 rows=2,528 width=134) (actual time=0.006..0.718 rows=2,547 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.004 ↓ 0.0 0 1

Hash Join (cost=16.34..60.56 rows=850 width=113) (actual time=0.004..0.004 rows=0 loops=1)

  • Hash Cond: (ne.person_id = p.id)
13. 0.003 0.003 ↓ 0.0 0 1

Seq Scan on natural_entities ne (cost=0.00..27.00 rows=1,700 width=4) (actual time=0.003..0.003 rows=0 loops=1)

14. 0.000 0.000 ↓ 0.0 0

Hash (cost=13.90..13.90 rows=195 width=101) (never executed)

15. 0.000 0.000 ↓ 0.0 0

Seq Scan on persons p (cost=0.00..13.90 rows=195 width=101) (never executed)

  • Filter: is_active
16. 248.394 252.153 ↓ 848.7 2,546 2,547

Materialize (cost=53.77..62.77 rows=3 width=8) (actual time=0.000..0.099 rows=2,546 loops=2,547)

17. 0.285 3.759 ↓ 848.7 2,546 1

Nested Loop (cost=53.77..62.75 rows=3 width=8) (actual time=0.206..3.759 rows=2,546 loops=1)

18. 0.185 0.928 ↓ 848.7 2,546 1

Nested Loop (cost=53.48..61.70 rows=3 width=4) (actual time=0.199..0.928 rows=2,546 loops=1)

19. 0.003 0.180 ↑ 1.0 1 1

Nested Loop (cost=53.20..61.24 rows=1 width=8) (actual time=0.180..0.180 rows=1 loops=1)

20. 0.002 0.170 ↑ 1.0 1 1

HashAggregate (cost=52.92..52.93 rows=1 width=4) (actual time=0.170..0.170 rows=1 loops=1)

  • Group Key: c4_.group_id
21. 0.001 0.168 ↑ 1.0 1 1

Nested Loop (cost=0.28..52.92 rows=1 width=4) (actual time=0.018..0.168 rows=1 loops=1)

22. 0.156 0.156 ↑ 1.0 1 1

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

  • Filter: (employee_id = 61)
  • Rows Removed by Filter: 2544
23. 0.011 0.011 ↑ 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.010..0.011 rows=1 loops=1)

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

  • Index Cond: (id = c4_.group_id)
  • Heap Fetches: 1
25. 0.563 0.563 ↓ 848.7 2,546 1

Index Only Scan using contractors_groups_group_id_contractor_id_uq on contractors_groups c3_ (cost=0.28..0.44 rows=3 width=8) (actual time=0.018..0.563 rows=2,546 loops=1)

  • Index Cond: (group_id = c2_.id)
  • Heap Fetches: 2547
26. 2.546 2.546 ↑ 1.0 1 2,546

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=2,546)

  • Index Cond: (id = c3_.contractor_id)
  • Filter: (status_id = 1)
Planning time : 1.120 ms
Execution time : 659.912 ms