Skip to content

Instantly share code, notes, and snippets.

@sitharus
Created June 7, 2012 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sitharus/2887417 to your computer and use it in GitHub Desktop.
Save sitharus/2887417 to your computer and use it in GitHub Desktop.
Query Plans
=# explain update messages set notified = false where NOT EXISTS(SELECT * FROM users u INNER JOIN devices d ON u.id = d.user_id WHERE u.id = messages.user_id);
QUERY PLAN
-------------------------------------------------------------------------------------
Hash Anti Join (cost=305.05..9400.07 rows=1 width=219)
Hash Cond: (messages.user_id = u.id)
-> Seq Scan on messages (cost=0.00..8219.35 rows=175135 width=219)
-> Hash (cost=279.28..279.28 rows=2061 width=4)
-> Hash Join (cost=86.37..279.28 rows=2061 width=4)
Hash Cond: (u.id = d.user_id)
-> Seq Scan on users u (cost=0.00..156.20 rows=3220 width=4)
-> Hash (cost=60.61..60.61 rows=2061 width=4)
-> Seq Scan on devices d (cost=0.00..60.61 rows=2061 width=4)
(9 rows)
=# explain update messages set notified = false FROM users u INNER JOIN devices d ON u.id = d.user_id WHERE u.id = messages.user_id;
QUERY PLAN
-------------------------------------------------------------------------------------
Hash Join (cost=305.05..10521.04 rows=175135 width=219)
Hash Cond: (messages.user_id = u.id)
-> Seq Scan on messages (cost=0.00..8219.35 rows=175135 width=219)
-> Hash (cost=279.28..279.28 rows=2061 width=8)
-> Hash Join (cost=86.37..279.28 rows=2061 width=8)
Hash Cond: (u.id = d.user_id)
-> Seq Scan on users u (cost=0.00..156.20 rows=3220 width=4)
-> Hash (cost=60.61..60.61 rows=2061 width=4)
-> Seq Scan on devices d (cost=0.00..60.61 rows=2061 width=4)
(9 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment