Re: Query much faster with enable_seqscan=0 - Mailing list pgsql-performance

From Tom Lane
Subject Re: Query much faster with enable_seqscan=0
Date
Msg-id 11723.1285111832@sss.pgh.pa.us
Whole thread Raw
In response to Query much faster with enable_seqscan=0  (Ogden <lists@darkstatic.com>)
Responses Re: Query much faster with enable_seqscan=0
Re: Query much faster with enable_seqscan=0
List pgsql-performance
Ogden <lists@darkstatic.com> 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

pgsql-performance by date:

Previous
From: Tom Lane
Date:
Subject: Re: Query much faster with enable_seqscan=0
Next
From: "Joshua D. Drake"
Date:
Subject: Re: Query much faster with enable_seqscan=0