Re: Performance trouble finding records through related records

From: sverhagen <sverhagen(at)wps-nl(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: Performance trouble finding records through related records
Date: 2011-03-03 09:19:20
Message-ID: 1299143960277-3407689.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance


Andy Colson wrote:
>
> For your query, I think a join would be the best bet, can we see its
> explain analyze?
>

Here is a few variations:

SELECT events_events.* FROM events_events WHERE transactionid IN (
SELECT transactionid FROM events_eventdetails customerDetails
WHERE customerDetails.keyname='customer_id'
AND substring(customerDetails.value,0,32)='1957'
AND transactionid IS NOT NULL
) ORDER BY id LIMIT 50;

-- http://explain.depesz.com/s/Pnb

explain analyze SELECT events_events.* FROM events_events,
events_eventdetails customerDetails
WHERE events_events.transactionid = customerDetails.transactionid
AND customerDetails.keyname='customer_id'
AND substring(customerDetails.value,0,32)='1957'
AND customerDetails.transactionid IS NOT NULL
ORDER BY id LIMIT 50;

-- http://explain.depesz.com/s/rDh

explain analyze SELECT events_events.* FROM events_events
JOIN events_eventdetails customerDetails
ON events_events.transactionid = customerDetails.transactionid
AND customerDetails.keyname='customer_id'
AND substring(customerDetails.value,0,32)='1957'
AND customerDetails.transactionid IS NOT NULL
ORDER BY id LIMIT 50;

-- http://explain.depesz.com/s/6aB

Thanks for your efforts!

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Performance-trouble-finding-records-through-related-records-tp3405914p3407689.html
Sent from the PostgreSQL - performance mailing list archive at Nabble.com.

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Matt Burke 2011-03-03 14:13:28 Slowing UPDATEs inside a transaction
Previous Message Grzegorz Jaśkiewicz 2011-03-03 09:07:10 Re: Is Query need to be optimized