Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id A36F69F9BA3 for ; Fri, 31 Aug 2007 11:45:46 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 14046-01 for ; Fri, 31 Aug 2007 11:45:33 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from oxford.xeocode.com (unknown [62.232.55.118]) by postgresql.org (Postfix) with ESMTP id D8DBD9F9DA4 for ; Fri, 31 Aug 2007 11:45:39 -0300 (ADT) Received: from localhost ([127.0.0.1] helo=oxford.xeocode.com) by oxford.xeocode.com with esmtp (Exim 4.67) (envelope-from ) id 1IR7kf-0001Y4-Jm; Fri, 31 Aug 2007 15:45:37 +0100 To: "Aleksandr Vinokurov" Cc: Subject: Re: Incomprehensible dogged sort in Merge Join In-Reply-To: <46D82318.3070700@gmail.com> (Aleksandr Vinokurov's message of "Fri\, 31 Aug 2007 18\:18\:00 +0400") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) X-Draft-From: ("nnimap+mail01.enterprisedb.com:INBOX.sql" 949) References: <46D82318.3070700@gmail.com> From: Gregory Stark Organization: EnterpriseDB Date: Fri, 31 Aug 2007 15:45:37 +0100 Message-ID: <877inb225q.fsf@oxford.xeocode.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/261 X-Sequence-Number: 29199 "Aleksandr Vinokurov" writes: > And that is its plan (attached one is the same, but with costs): > >>-----------------------------------------------------------------< > Merge Left Join > Merge Cond: ("outer".name =3D "inner".name) > -> Sort > Sort Key: log.name > -> Seq Scan on log_example_3 log > -> Sort > Sort Key: uh.name > -> Subquery Scan uh > -> Sort > Sort Key: name > -> Seq Scan on user_history >>-----------------------------------------------------------------< What version are you running with? Incidentally with CVS HEAD I see it working: postgres=3D# explain select * from (select * from a order by i) as a right = join b on a.i =3D b.i ; QUERY PLAN=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ----------------------------------------------------------------- Merge Right Join (cost=3D299.56..675.13 rows=3D22898 width=3D16) Merge Cond: (public.a.i =3D b.i) -> Sort (cost=3D149.78..155.13 rows=3D2140 width=3D8) Sort Key: public.a.i -> Seq Scan on a (cost=3D0.00..31.40 rows=3D2140 width=3D8) -> Sort (cost=3D149.78..155.13 rows=3D2140 width=3D8) Sort Key: b.i -> Seq Scan on b (cost=3D0.00..31.40 rows=3D2140 width=3D8) (8 rows) > With best regards to all of you, > Aleksandr.