Re: Subquery in a JOIN not getting restricted?

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "Jay Levitt" <jay(dot)levitt(at)gmail(dot)com>
Cc: <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Subquery in a JOIN not getting restricted?
Date: 2011-11-09 15:15:35
Message-ID: 4EBA44B70200002500042BC8@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

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?

That said, there might be some room for an optimization which pushes
that test into the query with the "group by" clause. I don't know
if there's a problem with that which I'm missing, the construct was
judged to be too rare to be worth the cost of testing for it, or
it's just that nobody has yet gotten to it.

-Kevin

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Greg Smith 2011-11-09 16:06:46 Re: WAL partition filling up after high WAL activity
Previous Message Scott Marlowe 2011-11-09 14:46:10 Re: : bg_writer overloaded ?