explain.depesz.com

PostgreSQL's explain analyze made readable

Result: ajQw

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

Limit (cost=848.16..848.16 rows=1 width=121) (actual time=971.268..971.282 rows=50 loops=1)

2. 1.449 971.273 ↓ 50.0 50 1

Sort (cost=848.16..848.16 rows=1 width=121) (actual time=971.267..971.273 rows=50 loops=1)

  • Sort Key: v0_.id
  • Sort Method: top-N heapsort Memory: 50kB
3. 586.344 969.824 ↓ 3,032.0 3,032 1

Nested Loop (cost=665.87..848.15 rows=1 width=121) (actual time=6.656..969.824 rows=3,032 loops=1)

  • Join Filter: ((c1_.contractor_company_id = v0_.company_id) OR (c1_.contractor_person_id = v0_.person_id))
  • Rows Removed by Join Filter: 9205158
4. 0.640 10.175 ↓ 104.7 3,035 1

Subquery Scan on v0_ (cost=600.75..772.51 rows=29 width=121) (actual time=5.062..10.175 rows=3,035 loops=1)

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

WindowAgg (cost=600.75..724.80 rows=3,817 width=121) (actual time=5.060..9.535 rows=3,035 loops=1)

6. 3.547 7.192 ↑ 1.3 3,035 1

HashAggregate (cost=600.75..638.92 rows=3,817 width=113) (actual time=5.055..7.192 rows=3,035 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.159 3.645 ↑ 1.3 3,035 1

Append (cost=236.82..524.41 rows=3,817 width=113) (actual time=1.521..3.645 rows=3,035 loops=1)

8. 1.531 3.479 ↓ 1.0 3,035 1

Hash Join (cost=236.82..406.59 rows=2,967 width=113) (actual time=1.521..3.479 rows=3,035 loops=1)

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

Seq Scan on divisions d (cost=0.00..72.90 rows=2,990 width=44) (actual time=0.008..0.456 rows=3,060 loops=1)

  • Filter: is_visible
10. 0.575 1.492 ↑ 1.0 3,035 1

Hash (cost=198.88..198.88 rows=3,035 width=135) (actual time=1.492..1.492 rows=3,035 loops=1)

  • Buckets: 4096 Batches: 1 Memory Usage: 529kB
11. 0.917 0.917 ↑ 1.0 3,035 1

Seq Scan on companies co (cost=0.00..198.88 rows=3,035 width=135) (actual time=0.007..0.917 rows=3,035 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.007 ↓ 0.0 0 1

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

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

Seq Scan on natural_entities ne (cost=0.00..27.00 rows=1,700 width=4) (actual time=0.006..0.006 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. 366.441 373.305 ↓ 1,011.3 3,034 3,035

Materialize (cost=65.12..74.12 rows=3 width=8) (actual time=0.000..0.123 rows=3,034 loops=3,035)

17. 1.835 6.864 ↓ 1,011.3 3,034 1

Nested Loop (cost=65.12..74.10 rows=3 width=8) (actual time=0.285..6.864 rows=3,034 loops=1)

18. 0.394 1.995 ↓ 1,011.3 3,034 1

Nested Loop (cost=64.84..73.05 rows=3 width=4) (actual time=0.278..1.995 rows=3,034 loops=1)

19. 0.003 0.262 ↑ 1.0 1 1

Nested Loop (cost=64.55..72.59 rows=1 width=8) (actual time=0.261..0.262 rows=1 loops=1)

20. 0.003 0.253 ↑ 1.0 1 1

HashAggregate (cost=64.27..64.28 rows=1 width=4) (actual time=0.253..0.253 rows=1 loops=1)

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

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

22. 0.211 0.211 ↑ 1.0 1 1

Seq Scan on contractor_groups_employees c4_ (cost=0.00..55.96 rows=1 width=8) (actual time=0.007..0.211 rows=1 loops=1)

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

  • Index Cond: (id = 61)
  • Heap Fetches: 1
24. 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
25. 1.339 1.339 ↓ 1,011.3 3,034 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.016..1.339 rows=3,034 loops=1)

  • Index Cond: (group_id = c2_.id)
  • Heap Fetches: 3035
26. 3.034 3.034 ↑ 1.0 1 3,034

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

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