From: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
---|---|
To: | Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov> |
Cc: | Jay Levitt <jay(dot)levitt(at)gmail(dot)com>, pgsql-performance(at)postgresql(dot)org |
Subject: | Re: Subquery in a JOIN not getting restricted? |
Date: | 2011-11-09 19:50:28 |
Message-ID: | CAHyXU0zWLRquK9xu4SbTrxyOTA2kbT1b3r4_H4KdEzE-hvVgoA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
On Wed, Nov 9, 2011 at 9:15 AM, Kevin Grittner
<Kevin(dot)Grittner(at)wicourts(dot)gov> wrote:
> Jay Levitt <jay(dot)levitt(at)gmail(dot)com> wrote:
>
>> I don't get why the GROUP BY in this subquery forces it to scan
>> the entire users table (seq scan here, index scan on a larger
>> table) when there's only one row in users that can match:
>
>> 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;
>
>> Total runtime: 1.262 ms
>
> Are you sure there's a plan significantly faster than 1.3 ms?
Well, this may not fit the OP's 'real' query, but the inner subquery
is probably better written as a semi-join (WHERE EXISTS).
merlin
From | Date | Subject | |
---|---|---|---|
Next Message | Kevin Grittner | 2011-11-09 20:20:00 | Re: Subquery in a JOIN not getting restricted? |
Previous Message | kzsolt | 2011-11-09 19:48:13 | Re: Heavy contgnous load |