Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 3F8E64764C3 for ; Wed, 23 Oct 2002 11:27:45 -0400 (EDT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by postgresql.org (Postfix) with ESMTP id C1459476346 for ; Wed, 23 Oct 2002 11:27:44 -0400 (EDT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id BBC1CD613; Wed, 23 Oct 2002 08:27:45 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id B17385C03; Wed, 23 Oct 2002 08:27:45 -0700 (PDT) Date: Wed, 23 Oct 2002 08:27:45 -0700 (PDT) From: Stephan Szabo To: Tomasz Myrta Cc: Subject: Re: sub-select with aggregate In-Reply-To: <20021023081036.M5349-100000@megazone23.bigpanda.com> Message-ID: <20021023082355.G5481-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200210/299 X-Sequence-Number: 10016 On Wed, 23 Oct 2002, Stephan Szabo wrote: > Did you see the other two queries I gave? On 7.3, both of those queries > appear (according to explain output) to do the limiting of group_id > inside the subquery rather than doing the subquery with all rows. > The explanation above was why I believe it was different from your > original query. Replying to myself with a clarification. The other forms only move the filtering clauses around. There's still only a filter on the outer group_id equaling the inner group_id and a filter on group_id=3. It's just a question of whether it's: Scan users in subselect from group_id=3, group and aggregate them and join with users on subselect's group_id = users.group_id or Scan users for group_id=3, scan users in subselect, group and aggregate them and join these two on subselect's group_id=users.group_id. The latter is effectively what your original query gave, the former appears to be what my two queries from a couple of mails ago gives.