Re: Optimize querry sql

From: "Stanislas de Larocque" <dllstan(at)gmail(dot)com>
To: depesz(at)depesz(dot)com
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Optimize querry sql
Date: 2007-09-17 07:17:58
Message-ID: bc40d0a30709170017p671840eex8626c9d923c4cacd@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

I deleted the fonction date_part and now the time of the querry is : 464 ms !!!

Limit (cost=1373.32..1373.50 rows=15 width=27) (actual
time=463.762..463.857 rows=15 loops=1)
-> HashAggregate (cost=1373.32..1408.52 rows=2816 width=27)
(actual time=463.755..463.820 rows=15 loops=1)
-> Hash Join (cost=149.72..1189.22 rows=24546 width=27)
(actual time=42.106..348.561 rows=18543 loops=1)
Hash Cond: ("outer".idxreseller = "inner".idxreseller)
-> Seq Scan on stat a (cost=0.00..545.27 rows=24877
width=8) (actual time=0.054..167.340 rows=24881 loops=1)
Filter: ((month = 8) AND (year = 2007))
-> Hash (cost=142.68..142.68 rows=2816 width=23)
(actual time=41.954..41.954 rows=2816 loops=1)
-> Seq Scan on reseller b (cost=0.00..142.68
rows=2816 width=23) (actual time=0.035..28.447 rows=2816 loops=1)
Filter: (asp = 6)
Total runtime: 464.337 ms

Have you advices to optimize the query please ?

Stan

2007/9/14, hubert depesz lubaczewski <depesz(at)depesz(dot)com>:
> 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)
>

--
Stanislas de Larocque
dllstan(at)gmail(dot)com
06 63 64 00 47

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message hubert depesz lubaczewski 2007-09-17 07:25:41 Re: Optimize querry sql
Previous Message Gregory Stark 2007-09-16 23:18:56 Re: Extracting hostname from URI column