Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 8E9C5133729E for ; Tue, 21 Sep 2010 20:30:39 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 07167-05 for ; Tue, 21 Sep 2010 23:30:32 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 5DECC1336B42 for ; Tue, 21 Sep 2010 20:30:32 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id o8LNUWiw011724; Tue, 21 Sep 2010 19:30:32 -0400 (EDT) To: Ogden cc: pgsql-performance@postgresql.org Subject: Re: Query much faster with enable_seqscan=0 In-reply-to: <0D5B9ED0-00C3-4EEB-8336-0B2F8A884620@darkstatic.com> References: <0D5B9ED0-00C3-4EEB-8336-0B2F8A884620@darkstatic.com> Comments: In-reply-to Ogden message dated "Tue, 21 Sep 2010 12:32:01 -0500" Date: Tue, 21 Sep 2010 19:30:32 -0400 Message-ID: <11723.1285111832@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201009/138 X-Sequence-Number: 40341 Ogden writes: > SELECT tr.id, tr.sid > FROM > test_registration tr, > INNER JOIN test_registration_result r on (tr.id = r.test_registration_id) > WHERE. > tr.test_administration_id='32a22b12-aa21-11df-a606-96551e8f4e4c'::uuid > GROUP BY tr.id, tr.sid Seeing that tr.id is a primary key, I think you might be a lot better off if you avoided the inner join and group by. I think what you really want here is something like SELECT tr.id, tr.sid FROM test_registration tr WHERE tr.test_administration_id='32a22b12-aa21-11df-a606-96551e8f4e4c'::uuid AND EXISTS(SELECT 1 FROM test_registration_result r WHERE tr.id = r.test_registration_id) regards, tom lane