Created
September 20, 2012 00:14
-
-
Save jaylevitt/3753166 to your computer and use it in GitHub Desktop.
Subquery in a JOIN not getting restricted
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
drop schema if exists jaytest cascade; | |
create schema jaytest; | |
set search_path to jaytest; | |
create table questions ( | |
id int not null primary key, | |
user_id int not null | |
); | |
insert into questions | |
select generate_series(1,1100), (random()*200000)::int; | |
create table users ( | |
id int not null primary key | |
); | |
insert into users select generate_series(1, 200000); | |
vacuum freeze analyze; | |
explain analyze | |
select questions.id | |
from questions | |
join ( | |
select u.id | |
from users as u | |
group by u.id | |
) as s | |
on s.id = questions.user_id | |
where questions.id = 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment