X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id CFE0CD7930 for ; Thu, 25 Aug 2005 23:30:14 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 96597-05 for ; Fri, 26 Aug 2005 02:30:11 +0000 (GMT) Received: from mail23.sea5.speakeasy.net (mail23.sea5.speakeasy.net [69.17.117.25]) by svr1.postgresql.org (Postfix) with ESMTP id 0611BD78E3 for ; Thu, 25 Aug 2005 23:30:04 -0300 (ADT) Received: (qmail 12130 invoked from network); 26 Aug 2005 02:30:07 -0000 Received: from dsl081-060-184.sfo1.dsl.speakeasy.net (HELO noodles) ([64.81.60.184]) (envelope-sender ) by mail23.sea5.speakeasy.net (qmail-ldap-1.03) with RC4-MD5 encrypted SMTP for ; 26 Aug 2005 02:30:07 -0000 Subject: Re: Limit + group + join From: "Jeffrey W. Baker" To: Tobias Brox Cc: pgsql-performance@postgresql.org In-Reply-To: <1125021419.16451.0.camel@noodles> References: <20050826002709.GK10328@tobias.lan> <1125021419.16451.0.camel@noodles> Content-Type: text/plain Date: Thu, 25 Aug 2005 19:31:20 -0700 Message-Id: <1125023480.16451.2.camel@noodles> Mime-Version: 1.0 X-Mailer: Evolution 2.2.1.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.038 required=5 tests=[AWL=0.038] X-Spam-Level: X-Archive-Number: 200508/430 X-Sequence-Number: 14177 On Thu, 2005-08-25 at 18:56 -0700, Jeffrey W. Baker wrote: > On Fri, 2005-08-26 at 02:27 +0200, Tobias Brox wrote: > > Consider this setup - which is a gross simplification of parts of our > > production system ;-) > > > > create table c (id integer primary key); > > create table b (id integer primary key, c_id integer); > > create index b_on_c on b(c_id) > > > > insert into c (select ... lots of IDs ...); > > insert into b (select id, id from c); /* keep it simple :-) */ > > > > Now, I'm just interessted in some few rows. > > > > All those gives good plans: > > > > explain select c.id from c order by c.id limit 1; > > explain select c.id from c group by c.id order by c.id limit 1; > > explain select c.id from c join b on c_id=c.id order by c.id limit 1; > > > > ... BUT ... combining join, group and limit makes havoc: > > > > explain select c.id from c join b on c_id=c.id group by c.id order by c.id > > desc limit 5; > > Where's b in this join clause? It looks like a cartesian product to me. Nevermind. I read c_id as c.id. -jwb