Last active
December 1, 2015 03:19
-
-
Save zerothabhishek/a8beba59082964a4af01 to your computer and use it in GitHub Desktop.
Explain Join with indexes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EXPLAIN | |
SELECT posts.*, comments.* | |
FROM posts LEFT JOIN comments | |
ON posts.id = comments.post_id; | |
# Before adding indexes | |
QUERY PLAN | |
------------------------------------------------------------------------ | |
Hash Right Join (cost=394.50..2589.00 rows=50000 width=150) | |
Hash Cond: (comments.post_id = posts.id) | |
-> Seq Scan on comments (cost=0.00..1257.00 rows=50000 width=72) | |
-> Hash (cost=257.00..257.00 rows=11000 width=78) | |
-> Seq Scan on posts (cost=0.00..257.00 rows=11000 width=78) | |
# After adding indexes | |
QUERY PLAN | |
------------------------------------------------------------------------ | |
Hash Right Join (cost=394.50..2589.00 rows=50000 width=150) | |
Hash Cond: (comments.post_id = posts.id) | |
-> Seq Scan on comments (cost=0.00..1257.00 rows=50000 width=72) | |
-> Hash (cost=257.00..257.00 rows=11000 width=78) | |
-> Seq Scan on posts (cost=0.00..257.00 rows=11000 width=78) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment