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 722A68B9F6B for ; Thu, 17 Feb 2005 17:56:10 +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 89066-03 for ; Thu, 17 Feb 2005 17:56:08 +0000 (GMT) Received: from hotmail.com (bay103-f17.bay103.hotmail.com [65.54.174.27]) by svr1.postgresql.org (Postfix) with ESMTP id E17C38B9F37 for ; Thu, 17 Feb 2005 17:56:07 +0000 (GMT) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Thu, 17 Feb 2005 09:56:02 -0800 Message-ID: Received: from 68.146.188.239 by by103fd.bay103.hotmail.msn.com with HTTP; Thu, 17 Feb 2005 17:55:30 GMT X-Originating-IP: [68.146.188.239] X-Originating-Email: [jbowen333@hotmail.com] X-Sender: jbowen333@hotmail.com From: "T- Bone" To: pgsql-sql@postgresql.org Subject: Comments on subquery performance Date: Thu, 17 Feb 2005 10:55:30 -0700 Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-OriginalArrivalTime: 17 Feb 2005 17:56:02.0975 (UTC) FILETIME=[F214EAF0:01C51519] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.548 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_POST, FROM_ENDS_IN_NUMS, MSGID_FROM_MTA_HEADER X-Spam-Level: * X-Archive-Number: 200502/197 X-Sequence-Number: 20308 (second attempt in two days to post this message...I appologise if for some reason a duplicate appears) Hello all, I created a query that contains two subqueries and joins and would like some feedback on whether: 1) this approach is logical; and, 2) if this is an optimal approach (performance wise) to return the records I seek. Essentially, I am attempting to perform a 'lookup' on a value in another table 3 times, for three different columns. I have three columns with category codes in tblListings and would like to 'lookup' the actual category text in tblCategory. I have created a functional query that contains two subqueries and joins, but am concerned this may not be the fastest (or logical?) way to achieve what I seek. I thought of another approach to create a function to evaluate the records on a row-by-row and column-by-column approach, but thought that may prove even slower. I would appreciate any comments on my logic or learning of any alternative means that would result in better performance. I have included the SQL for reference. Thanks in advance. Regards, Jim ----------------------------------------8<------------------------------------------------- SELECT "CatID1", "CatID2", "CatID3", c1 AS "CatName1", c2 AS "CatName2", t6."CatName" AS "CatName3" FROM (SELECT "CatID1", "CatID2", "CatID3", c1, t4."CatName" AS c2 FROM (SELECT t1."CatID1", t1."CatID2", t1."CatID3", t2."CatName" AS c1 FROM "MySchema"."tblListings" t1 INNER JOIN "MySchema"."tblCategories" t2 ON (t1."CatID1" = t2."CatID")) t3 LEFT OUTER JOIN "MySchema"."tblCategories" t4 ON (t3."CatID2" = t4."CatID")) t5 LEFT OUTER JOIN "MySchema"."tblCategories" t6 ON (t5."CatID3" = t6."CatID"); ----------------------------------------8<------------------------------------------------- _________________________________________________________________ Take advantage of powerful junk e-mail filters built on patented Microsoft® SmartScreen Technology. http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines Start enjoying all the benefits of MSN® Premium right now and get the first two months FREE*.