explain.depesz.com

PostgreSQL's explain analyze made readable

Result: SrR7

Settings
# exclusive inclusive rows x rows loops node
1. 0.001 0.510 ↓ 0.0 0 1

Limit (cost=5,165.60..5,165.61 rows=2 width=129) (actual time=0.510..0.510 rows=0 loops=1)

2. 0.002 0.509 ↓ 0.0 0 1

Sort (cost=5,165.60..5,165.61 rows=2 width=129) (actual time=0.509..0.509 rows=0 loops=1)

  • Sort Key: vr.id
  • Sort Method: quicksort Memory: 25kB
3. 0.002 0.507 ↓ 0.0 0 1

Hash Join (cost=4,933.18..5,165.59 rows=2 width=129) (actual time=0.507..0.507 rows=0 loops=1)

  • Hash Cond: (c1_.id = cg.contractor_id)
4. 0.000 0.000 ↓ 0.0 0

HashAggregate (cost=4,763.22..4,861.07 rows=9,785 width=129) (never executed)

  • Group Key: vr.id, vr.type, vr.external_type, vr.title, vr.sort_title, vr.is_active, vr.division_id, vr.company_id, vr.person_id, c1_.status_id, c1_.id
5. 0.000 0.000 ↓ 0.0 0

Append (cost=2,490.29..4,494.13 rows=9,785 width=129) (never executed)

6. 0.000 0.000 ↓ 0.0 0

Merge Join (cost=2,490.29..2,679.48 rows=9,784 width=129) (never executed)

  • Merge Cond: (vr.company_id = c1_.contractor_company_id)
7. 0.000 0.000 ↓ 0.0 0

Sort (cost=1,103.64..1,109.79 rows=2,462 width=121) (never executed)

  • Sort Key: vr.company_id
8. 0.000 0.000 ↓ 0.0 0

Subquery Scan on vr (cost=755.64..964.96 rows=2,462 width=121) (never executed)

  • Filter: vr.is_active
9. 0.000 0.000 ↓ 0.0 0

WindowAgg (cost=755.64..915.71 rows=4,925 width=121) (never executed)

10. 0.000 0.000 ↓ 0.0 0

HashAggregate (cost=755.64..804.89 rows=4,925 width=113) (never executed)

  • 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
11. 0.000 0.000 ↓ 0.0 0

Append (cost=322.10..657.14 rows=4,925 width=113) (never executed)

12. 0.000 0.000 ↓ 0.0 0

Hash Join (cost=322.10..546.95 rows=3,954 width=113) (never executed)

  • Hash Cond: (d.company_id = co.id)
13. 0.000 0.000 ↓ 0.0 0

Seq Scan on divisions d (cost=0.00..95.78 rows=3,978 width=44) (never executed)

  • Filter: is_visible
14. 0.000 0.000 ↓ 0.0 0

Hash (cost=272.67..272.67 rows=3,954 width=135) (never executed)

15. 0.000 0.000 ↓ 0.0 0

Seq Scan on companies co (cost=0.00..272.67 rows=3,954 width=135) (never executed)

  • Filter: (is_active AND (type_id = ANY ('{2,3}'::integer[])) AND (step_id = 3))
16. 0.000 0.000 ↓ 0.0 0

Nested Loop (cost=0.15..36.32 rows=971 width=113) (never executed)

17. 0.000 0.000 ↓ 0.0 0

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

  • Filter: is_active
18. 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
19. 0.000 0.000 ↓ 0.0 0

Sort (cost=1,386.65..1,426.17 rows=15,808 width=12) (never executed)

  • Sort Key: c1_.contractor_company_id
20. 0.000 0.000 ↓ 0.0 0

Seq Scan on contractors_companies c1_ (cost=0.00..284.18 rows=15,808 width=12) (never executed)

  • Filter: (status_id = 1)
21. 0.000 0.000 ↓ 0.0 0

Nested Loop (cost=755.77..1,667.88 rows=1 width=129) (never executed)

22. 0.000 0.000 ↓ 0.0 0

Subquery Scan on vr_1 (cost=755.64..964.96 rows=2,462 width=121) (never executed)

  • Filter: vr_1.is_active
23. 0.000 0.000 ↓ 0.0 0

WindowAgg (cost=755.64..915.71 rows=4,925 width=121) (never executed)

24. 0.000 0.000 ↓ 0.0 0

HashAggregate (cost=755.64..804.89 rows=4,925 width=113) (never executed)

  • Group Key: (NULL::integer), d_1.id, d_1.company_id, ('division'::text), ((((co_1.name)::text || ', '::text) || CASE WHEN (d_1.id = co_1.head_division_id) THEN (('ИНН: '::text || (co_1.inn)::text) || COALESCE((', ОГРН:'::text || (co_1.ogrn)::text), ''::text)) ELSE ((d_1.title)::text || COALESCE((', КПП: '::text || (d_1.kpp)::text), ''::text)) END)), ((((co_1.name)::text || ((co_1.head_division_id <> d_1.id))::text) || (d_1.title)::text)), co_1.is_active, co_1.external_type
25. 0.000 0.000 ↓ 0.0 0

Append (cost=322.10..657.14 rows=4,925 width=113) (never executed)

26. 0.000 0.000 ↓ 0.0 0

Hash Join (cost=322.10..546.95 rows=3,954 width=113) (never executed)

  • Hash Cond: (d_1.company_id = co_1.id)
27. 0.000 0.000 ↓ 0.0 0

Seq Scan on divisions d_1 (cost=0.00..95.78 rows=3,978 width=44) (never executed)

  • Filter: is_visible
28. 0.000 0.000 ↓ 0.0 0

Hash (cost=272.67..272.67 rows=3,954 width=135) (never executed)

29. 0.000 0.000 ↓ 0.0 0

Seq Scan on companies co_1 (cost=0.00..272.67 rows=3,954 width=135) (never executed)

  • Filter: (is_active AND (type_id = ANY ('{2,3}'::integer[])) AND (step_id = 3))
30. 0.000 0.000 ↓ 0.0 0

Nested Loop (cost=0.15..36.32 rows=971 width=113) (never executed)

31. 0.000 0.000 ↓ 0.0 0

Seq Scan on persons p_1 (cost=0.00..1.07 rows=4 width=101) (never executed)

  • Filter: is_active
32. 0.000 0.000 ↓ 0.0 0

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

  • Index Cond: (person_id = p_1.id)
  • Heap Fetches: 0
33. 0.000 0.000 ↓ 0.0 0

Index Scan using contractors_companies_company_id_contractor_person_id_uq on contractors_companies c1__1 (cost=0.12..0.28 rows=1 width=12) (never executed)

  • Index Cond: (contractor_person_id = vr_1.person_id)
  • Filter: (status_id = 1)
34. 0.000 0.505 ↓ 0.0 0 1

Hash (cost=169.92..169.92 rows=3 width=4) (actual time=0.505..0.505 rows=0 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 8kB
35. 0.003 0.505 ↓ 0.0 0 1

Nested Loop (cost=4.31..169.92 rows=3 width=4) (actual time=0.504..0.505 rows=0 loops=1)

36. 0.496 0.496 ↑ 1.0 2 1

Seq Scan on employee_groups (cost=0.00..141.04 rows=2 width=4) (actual time=0.352..0.496 rows=2 loops=1)

  • Filter: (employee_id = 2715)
  • Rows Removed by Filter: 7901
37. 0.002 0.006 ↓ 0.0 0 2

Bitmap Heap Scan on contractors_groups cg (cost=4.31..14.41 rows=3 width=8) (actual time=0.003..0.003 rows=0 loops=2)

  • Recheck Cond: (group_id = employee_groups.id)
38. 0.004 0.004 ↓ 0.0 0 2

Bitmap Index Scan on contractors_groups_group_id_contractor_id_uq (cost=0.00..4.31 rows=3 width=0) (actual time=0.002..0.002 rows=0 loops=2)

  • Index Cond: (group_id = employee_groups.id)
Planning time : 1.150 ms
Execution time : 0.647 ms