Skip site navigation (1) Skip section navigation (2)

Re: Optimize querry sql

From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: Stanislas de Larocque <dllstan(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Optimize querry sql
Date: 2007-09-14 13:36:41
Message-ID: 20070914133641.GA31759@depesz.com (view raw or flat)
Thread:
Lists: pgsql-sql
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)

In response to

Responses

pgsql-sql by date

Next:From: Scott MarloweDate: 2007-09-14 13:36:47
Subject: Re: Optimize querry sql
Previous:From: Stanislas de LarocqueDate: 2007-09-14 13:02:59
Subject: Optimize querry sql

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group