X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D264D5691A for ; Tue, 22 Mar 2005 21:00:04 +0000 (GMT) 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 75627-10 for ; Tue, 22 Mar 2005 21:00:02 +0000 (GMT) Received: from anchor-post-33.mail.demon.net (anchor-post-33.mail.demon.net [194.217.242.91]) by svr1.postgresql.org (Postfix) with ESMTP id B75B756902 for ; Tue, 22 Mar 2005 21:00:00 +0000 (GMT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-33.mail.demon.net with esmtp (Exim 4.42) id 1DDqTo-000BlR-9g; Tue, 22 Mar 2005 21:00:00 +0000 Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id D58B9175FF; Tue, 22 Mar 2005 20:59:58 +0000 (GMT) Message-ID: <4240874E.2080301@archonet.com> Date: Tue, 22 Mar 2005 20:59:58 +0000 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Sean Davis Cc: PostgreSQL SQL Subject: Re: Self-referencing table question References: <0af8c6d3baaf3d4a6d918df294019507@mail.nih.gov> <7e154914b76fb1a7c55912b621400860@mail.nih.gov> In-Reply-To: <7e154914b76fb1a7c55912b621400860@mail.nih.gov> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.061 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200503/304 X-Sequence-Number: 20783 Sean Davis wrote: > I answer my own question, if only for my own records. The following > query is about 5-6 times faster than the original. Of course, if > anyone else has other ideas, I'd be happy to hear them. > > Sean > > explain analyze select from_id,to_id,val from exprsdb.correlation where > from_id in (select to_id from exprsdb.correlation where from_id=2424 > order by val desc limit 100) and to_id in (select to_id from > exprsdb.correlation where from_id=2424 order by val desc limit 100) and > val>0.6 and to_id 0.5 AND c1.to_id < from_id ; I think PG should be smart enough nowadays to figure out these two queries are basically the same. -- Richard Huxton Archonet Ltd