X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 8602C5571D for ; Thu, 3 Mar 2005 02:51:53 +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 82612-04 for ; Thu, 3 Mar 2005 02:51:45 +0000 (GMT) Received: from fep2.cogeco.net (smtp.cogeco.net [216.221.81.25]) by svr1.postgresql.org (Postfix) with ESMTP id E10CB52A5A for ; Thu, 3 Mar 2005 02:51:44 +0000 (GMT) Received: from windsortransportationclub.com (d57-59-156.home.cgocable.net [24.57.59.156]) by fep2.cogeco.net (Postfix) with SMTP id DC9013E68 for ; Wed, 2 Mar 2005 21:51:47 -0500 (EST) Received: (qmail 31013 invoked from network); 3 Mar 2005 03:22:47 -0000 Received: from d36-80-110.home1.cgocable.net (HELO KEN) (24.36.80.110) by 0 with SMTP; 3 Mar 2005 03:22:47 -0000 Message-ID: <001001c51f9b$f606cd40$6a01a8c0@KEN> From: "Ken Egervari" To: "Ken Egervari" , References: <001001c51ef4$3849eeb0$6a01a8c0@KEN> <1109787227.31084.12.camel@localhost.localdomain> <000901c51f55$aa4b7400$6a01a8c0@KEN> <1109789394.31084.20.camel@localhost.localdomain> <000601c51f63$63c8bb10$6a01a8c0@KEN> <13490.1109795370@sss.pgh.pa.us> <000801c51f67$c3abdcc0$6a01a8c0@KEN> <14444.1109802588@sss.pgh.pa.us> <001a01c51f8f$32bba5b0$6a01a8c0@KEN> <000401c51f9b$219ebbd0$6a01a8c0@KEN> Subject: Re: Help with tuning this query (more musings) Date: Wed, 2 Mar 2005 21:51:55 -0500 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.749 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO, RCVD_IN_NJABL_DUL, RCVD_IN_SORBS_DUL X-Spam-Level: * X-Archive-Number: 200503/43 X-Sequence-Number: 10748 >I took John's advice and tried to work with sub-selects. I tried this >variation, which actually seems like it would make a difference >conceptually since it drives on the person table quickly. But to my >surprise, the query runs at about 375 milliseconds. I think it's because >it's going over that shipment table multiple times, which is where the >results are coming from. I also made a version that runs over shipment a single time, but it's exactly 250 milliseconds. I guess the planner does the exact same thing. select s.*, ss.* from shipment s inner join shipment_status ss on s.current_status_id=ss.id inner join release_code rc on ss.release_code_id=rc.id left outer join driver d on s.driver_id=d.id left outer join carrier_code cc on s.carrier_code_id=cc.id where s.carrier_code_id in ( select cc.id from person p inner join carrier_to_person ctp on p.id=ctp.person_id inner join carrier c on ctp.carrier_id=c.id inner join carrier_code cc on cc.carrier_id = c.id where p.id = 355 ) and s.current_status_id is not null and s.is_purged=false and(rc.number='9' ) and(ss.date>=current_date-31 ) order by ss.date desc