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 91E488B9E1A for ; Wed, 23 Feb 2005 16:54:59 +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 62108-02 for ; Wed, 23 Feb 2005 16:54:53 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id C0A268B9D49 for ; Wed, 23 Feb 2005 16:54:53 +0000 (GMT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j1NGsqY6020118 for ; Wed, 23 Feb 2005 11:54:53 -0500 (EST) Cc: pgsql-performance@postgresql.org Subject: Re: subquery vs join on 7.4.5 In-reply-to: References: Comments: In-reply-to David Haas message dated "Mon, 21 Feb 2005 23:05:08 -0800" Date: Wed, 23 Feb 2005 11:54:52 -0500 Message-ID: <20117.1109177692@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.007 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200502/327 X-Sequence-Number: 10656 David Haas writes: > I'm comparing the speeds of the following two queries on 7.4.5. I was > curious why query 1 was faster than query 2: > query 1: > Select layer_number > FROM batch_report_index > WHERE device_id = (SELECT device_id FROM device_index WHERE device_name > ='CP8M') > AND technology_id = (SELECT technology_id FROM technology_index WHERE > technology_name = 'G12'); > query 2: > Select b.layer_number > FROM batch_report_index b, device_index d, technology_index t > WHERE b.device_id = d.device_id > AND b.technology_id = t.technology_id > AND d.device_name = 'CP8M' > AND t.technology_name = 'G12'; Why didn't you try a two-column index on batch_report_index(device_id, technology_id) ? Whether this would actually be better than a seqscan I'm not sure, given the large number of matching rows. But the planner would surely try it given that it's drastically underestimating that number :-( regards, tom lane