Skip to content

Instantly share code, notes, and snippets.

@arossouw
Created October 15, 2015 04:15
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 arossouw/cd1bc8a36a6c898c8132 to your computer and use it in GitHub Desktop.
Save arossouw/cd1bc8a36a6c898c8132 to your computer and use it in GitHub Desktop.
postgresql semi-join
select *
from country
where country.code in
(select code
from country
where population > 7*1000*1000)
and country.continent = 'Europe';
QUERY PLAN
------------------------------------------------------------------------
Hash Join (cost=8.56..17.08 rows=18 width=113)
Hash Cond: (country_1.code = country.code)
-> Seq Scan on country country_1 (cost=0.00..7.99 rows=93 width=4)
Filter: (population > 7000000)
-> Hash (cost=7.99..7.99 rows=46 width=113)
-> Seq Scan on country (cost=0.00..7.99 rows=46 width=113)
Filter: (continent = 'Europe'::text)
(7 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment