From: | Ragnar Hafstað <gnari(at)simnet(dot)is> |
---|---|
To: | Ken Egervari <ken(at)upfactor(dot)com> |
Cc: | pgsql-performance(at)postgresql(dot)org |
Subject: | Re: Help with tuning this query |
Date: | 2005-03-02 18:13:47 |
Message-ID: | 1109787227.31084.12.camel@localhost.localdomain |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers-win32 pgsql-performance |
On Wed, 2005-03-02 at 01:51 -0500, Ken Egervari wrote:
>
> select s.*
> from shipment s
> inner join carrier_code cc on s.carrier_code_id = cc.id
> inner join carrier c on cc.carrier_id = c.id
> inner join carrier_to_person ctp on ctp.carrier_id = c.id
> inner join person p on p.id = ctp.person_id
> inner join shipment_status cs on s.current_status_id = cs.id
> inner join release_code rc on cs.release_code_id = rc.id
> left join shipment_status ss on ss.shipment_id = s.id
> where
> p.id = :personId and
> s.is_purged = false and
> rc.number = '9' and
> cs is not null and
> cs.date >= current_date - 31
> order by cs.date desc
> ...
> shipment contains 40,000 rows
> shipment_status contains 80,000 rows
I may be missing something, but it looks like the second join
on shipment_status (the left join) is not adding anything to your
results, except more work. ss is not used for output, nor in the where
clause, so what is its purpose ?
if cs.date has an upper limit, it might be helpful to change the
condition to a BETWEEN
in any case, i would think you might need an index on
shipment(carrier_code_id)
shipment(current_status_id)
shipment_status(id)
gnari
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2005-03-02 18:21:47 | Re: [pgsql-hackers-win32] snprintf causes regression tests to fail |
Previous Message | massimo.zanforlin | 2005-03-02 17:58:36 | Problem during postgresql-8.0.msi installation |
From | Date | Subject | |
---|---|---|---|
Next Message | Ken Egervari | 2005-03-02 18:28:43 | Re: Help with tuning this query |
Previous Message | Shawn Chisholm | 2005-03-02 17:52:10 | Performance tradeoff |