explain.depesz.com

PostgreSQL's explain analyze made readable

Result: 2rJ

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

HashAggregate (cost=13,775,476,867.71..13,775,476,869.71 rows=200 width=4) (actual rows= loops=)

  • Group Key: expected_apps.account_id
2.          

CTE expected_apps

3. 0.000 0.000 ↓ 0.0

GroupAggregate (cost=42,074,744.46..47,255,846.28 rows=230,271,192 width=12) (actual rows= loops=)

  • Group Key: ru.user_id, g.account_id
4. 0.000 0.000 ↓ 0.0

Sort (cost=42,074,744.46..42,650,422.44 rows=230,271,192 width=12) (actual rows= loops=)

  • Sort Key: ru.user_id, g.account_id
5. 0.000 0.000 ↓ 0.0

Merge Join (cost=157,012.41..6,156,203.07 rows=230,271,192 width=12) (actual rows= loops=)

  • Merge Cond: (ru.role_id = g.role_id)
6. 0.000 0.000 ↓ 0.0

Index Only Scan using index_roles_users_role_user on roles_users ru (cost=0.56..2,450,139.31 rows=61,532,341 width=8) (actual rows= loops=)

7. 0.000 0.000 ↓ 0.0

Sort (cost=154,047.07..154,369.58 rows=129,003 width=12) (actual rows= loops=)

  • Sort Key: g.role_id
8. 0.000 0.000 ↓ 0.0

Hash Join (cost=129,941.83..143,096.62 rows=129,003 width=12) (actual rows= loops=)

  • Hash Cond: (g.account_id = a.id)
9. 0.000 0.000 ↓ 0.0

Seq Scan on grants g (cost=0.00..9,787.33 rows=553,982 width=12) (actual rows= loops=)

  • Filter: (app_id IS NOT NULL)
10. 0.000 0.000 ↓ 0.0

Hash (cost=129,502.75..129,502.75 rows=35,126 width=4) (actual rows= loops=)

11. 0.000 0.000 ↓ 0.0

Seq Scan on accounts a (cost=0.00..129,502.75 rows=35,126 width=4) (actual rows= loops=)

  • Filter: ((enabled IS TRUE) AND (cached_last_user_login > (now() - '2 years'::interval)))
12.          

CTE actual_apps

13. 0.000 0.000 ↓ 0.0

GroupAggregate (cost=9,047,190.38..9,287,388.48 rows=528,483 width=8) (actual rows= loops=)

  • Group Key: l.user_id
14. 0.000 0.000 ↓ 0.0

Sort (cost=9,047,190.38..9,125,054.40 rows=31,145,608 width=8) (actual rows= loops=)

  • Sort Key: l.user_id
15. 0.000 0.000 ↓ 0.0

Hash Join (cost=129,941.83..4,744,905.69 rows=31,145,608 width=8) (actual rows= loops=)

  • Hash Cond: (l.account_id = a_1.id)
16. 0.000 0.000 ↓ 0.0

Seq Scan on logins l (cost=0.00..3,800,638.42 rows=134,098,496 width=12) (actual rows= loops=)

  • Filter: ((NOT override_roles) AND (app_id IS NOT NULL))
17. 0.000 0.000 ↓ 0.0

Hash (cost=129,502.75..129,502.75 rows=35,126 width=4) (actual rows= loops=)

18. 0.000 0.000 ↓ 0.0

Seq Scan on accounts a_1 (cost=0.00..129,502.75 rows=35,126 width=4) (actual rows= loops=)

  • Filter: ((enabled IS TRUE) AND (cached_last_user_login > (now() - '2 years'::interval)))
19. 0.000 0.000 ↓ 0.0

Merge Join (cost=42,945,948.15..10,691,785,175.20 rows=605,429,691,550 width=4) (actual rows= loops=)

  • Merge Cond: (actual_apps.user_id = expected_apps.user_id)
  • Join Filter: (expected_apps.expected_apps <> actual_apps.actual_apps)
20. 0.000 0.000 ↓ 0.0

Sort (cost=60,805.93..62,127.13 rows=528,483 width=36) (actual rows= loops=)

  • Sort Key: actual_apps.user_id
21. 0.000 0.000 ↓ 0.0

CTE Scan on actual_apps (cost=0.00..10,569.66 rows=528,483 width=36) (actual rows= loops=)

22. 0.000 0.000 ↓ 0.0

Materialize (cost=42,885,142.22..44,036,498.18 rows=230,271,192 width=40) (actual rows= loops=)

23. 0.000 0.000 ↓ 0.0

Sort (cost=42,885,142.22..43,460,820.20 rows=230,271,192 width=40) (actual rows= loops=)

  • Sort Key: expected_apps.user_id
24. 0.000 0.000 ↓ 0.0

CTE Scan on expected_apps (cost=0.00..4,605,423.84 rows=230,271,192 width=40) (actual rows= loops=)