On Fri, Sep 14, 2007 at 03:02:59PM +0200, Stanislas de Larocque wrote:
> I want to optimize my query sql (execution time : 2665 ms) :
SELECT
    b.idxreseller,
    sum(a.nbrq),
    b.namereseller
from
    stat a,
    reseller b
where
     b.asp=6
     and a.idxreseller=b.reseller
     and a.month=date_part('month',now() - interval '1 month')
     and a.year=date_part('year',now() - interval '1 month')
GROUP BY
    b.idxreseller,b.namereseller limit 15;

1. cast all date_parts to int4, like in:
    a.month = cast( date_part('month',now() - interval '1 month') as int4)
2. why there is a limit without any order by?
3. change it to get namereseller from subselect, not from join.

depesz

-- 
quicksil1er: "postgres is excellent, but like any DB it requires a
highly paid DBA.  here's my CV!" :)
http://www.depesz.com/ - blog dla ciebie (i moje CV)

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq

Reply via email to