explain.depesz.com

PostgreSQL's explain analyze made readable

Result: 3H8X

Settings
# exclusive inclusive rows x rows loops node
1. 0.000 0.000 ↓ 0.0

​​​​Seq Scan on companies (cost=642,275.23..645,174.38 rows=54,249 width=4) (actual rows= loops=)

  • Filter: ((deleted_at IS NULL) AND ((hashed SubPlan 3) OR (hashed SubPlan 4)))
2.          

SubPlan (for ​​​​Seq Scan on companies)

3. 0.000 0.000 ↓ 0.0

Hash Join (cost=4,215.90..641,964.98 rows=117,444 width=4) (actual rows= loops=)

  • Hash Cond: (locations_1.company_id = companies_4.id)
4. 0.000 0.000 ↓ 0.0

Seq Scan on locations locations_1 (cost=774.98..636,908.33 rows=117,679 width=4) (actual rows= loops=)

  • Filter: ((deleted_at IS NULL) AND ((hashed SubPlan 1) OR (hashed SubPlan 2)))
5.          

SubPlan (for Seq Scan)

6. 0.000 0.000 ↓ 0.0

Nested Loop Semi Join (cost=1.14..757.74 rows=69 width=4) (actual rows= loops=)

7. 0.000 0.000 ↓ 0.0

Index Only Scan using location_users_user_id_location_id_key on location_users (cost=0.43..148.71 rows=69 width=4) (actual rows= loops=)

  • Index Cond: (user_id = 555,123)
8. 0.000 0.000 ↓ 0.0

Nested Loop Semi Join (cost=0.71..8.82 rows=1 width=4) (actual rows= loops=)

9. 0.000 0.000 ↓ 0.0

Index Scan using locations_pkey on locations (cost=0.42..8.45 rows=1 width=8) (actual rows= loops=)

  • Index Cond: (id = location_users.location_id)
  • Filter: (deleted_at IS NULL)
10. 0.000 0.000 ↓ 0.0

Index Scan using companies_pkey on companies companies_1 (cost=0.29..0.36 rows=1 width=4) (actual rows= loops=)

  • Index Cond: (id = locations.company_id)
  • Filter: (deleted_at IS NULL)
11. 0.000 0.000 ↓ 0.0

Nested Loop Semi Join (cost=0.88..17.06 rows=1 width=4) (actual rows= loops=)

12. 0.000 0.000 ↓ 0.0

Nested Loop (cost=0.58..16.63 rows=1 width=8) (actual rows= loops=)

13. 0.000 0.000 ↓ 0.0

Index Scan using company_users_user_id_company_id_key on company_users (cost=0.29..8.31 rows=1 width=4) (actual rows= loops=)

  • Index Cond: (user_id = 555,123)
  • Filter: ((role_name)::text <> 'Billing'::text)
14. 0.000 0.000 ↓ 0.0

Index Scan using companies_pkey on companies companies_2 (cost=0.29..8.31 rows=1 width=4) (actual rows= loops=)

  • Index Cond: (id = company_users.company_id)
  • Filter: (deleted_at IS NULL)
15. 0.000 0.000 ↓ 0.0

Index Scan using companies_pkey on companies companies_3 (cost=0.29..0.42 rows=1 width=4) (actual rows= loops=)

  • Index Cond: (id = companies_2.id)
  • Filter: (deleted_at IS NULL)
16. 0.000 0.000 ↓ 0.0

Hash (cost=2,536.77..2,536.77 rows=72,332 width=4) (actual rows= loops=)

17. 0.000 0.000 ↓ 0.0

Seq Scan on companies companies_4 (cost=0.00..2,536.77 rows=72,332 width=4) (actual rows= loops=)

  • Filter: (deleted_at IS NULL)
18. 0.000 0.000 ↓ 0.0

Nested Loop Semi Join (cost=0.58..16.63 rows=1 width=4) (actual rows= loops=)

19. 0.000 0.000 ↓ 0.0

Index Scan using company_users_user_id_company_id_key on company_users company_users_1 (cost=0.29..8.31 rows=1 width=4) (actual rows= loops=)

  • Index Cond: (user_id = 555,123)
  • Filter: ((role_name)::text = 'Billing'::text)
20. 0.000 0.000 ↓ 0.0

Index Scan using companies_pkey on companies companies_5 (cost=0.29..8.31 rows=1 width=4) (actual rows= loops=)

  • Index Cond: (id = company_users_1.company_id)
  • Filter: (deleted_at IS NULL)