pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ogden <lists@darkstatic.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-performance@postgresql.org
Subject: Re: Query much faster with enable_seqscan=0
Date: Tue, 12 Oct 2010 19:23:24 -0500
Message-ID: <9EE3D98A-CF01-43A3-B3AC-636F5D407FA8@darkstatic.com> (raw)
In-Reply-To: <11723.1285111832@sss.pgh.pa.us>
References: <0D5B9ED0-00C3-4EEB-8336-0B2F8A884620@darkstatic.com>
	<11723.1285111832@sss.pgh.pa.us>


On Sep 21, 2010, at 6:30 PM, Tom Lane wrote:

> 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
> 

Thank you for this suggestion, however, what if I wanted some columns from test_registration_result - this wouldn't work, for example if I wanted test_registration_result.answer to be fetched. Hence, I had to have a JOIN with test_registration_result and a GROUP BY. I still am not happy with my query - the EXISTS executes in great speed however I cannot retrieve any of the columns from that table. 

Thank you

Ogden




view thread (16+ messages)  latest in thread

Message-ID: <9EE3D98A-CF01-43A3-B3AC-636F5D407FA8@darkstatic.com>
Permalink:  ../9EE3D98A-CF01-43A3-B3AC-636F5D407FA8@darkstatic.com/
Also on:    postgresql.org/message-id/9EE3D98A-CF01-43A3-B3AC-636F5D407FA8@darkstatic.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: lists@darkstatic.com, tgl@sss.pgh.pa.us
  Subject: Re: Query much faster with enable_seqscan=0
  In-Reply-To: <9EE3D98A-CF01-43A3-B3AC-636F5D407FA8@darkstatic.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox