pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stanislas de Larocque <dllstan@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Optimize querry sql
Date: Fri, 14 Sep 2007 15:02:59 +0200
Message-ID: <bc40d0a30709140602x2a7914bcs8fa65d738abc4e92@mail.gmail.com> (raw)

Hi,

I had errors in my last emails. sorry

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;


Explain analyse :

Limit  (cost=1057.15..1057.16 rows=1 width=27) (actual
time=2655.083..2655.176 rows=15 loops=1)
   ->  HashAggregate  (cost=1057.15..1057.16 rows=1 width=27) (actual
time=2655.074..2655.132 rows=15 loops=1)
         ->  Nested Loop  (cost=0.00..1057.14 rows=1 width=27) (actual
time=0.646..2464.563 rows=18543 loops=1)
               ->  Seq Scan on stat a  (cost=0.00..1042.98 rows=1
width=8) (actual time=0.273..1239.510 rows=24881 loops=1)
                     Filter: (((month)::double precision =
date_part('month'::text, (now() - '1 mon'::interval))) AND
((year)::double precision = date_part('year'::text, (now() - '1
mon'::interval))))
               ->  Index Scan using reseller_pkey on reseller b
(cost=0.00..14.15 rows=1 width=23) (actual time=0.034..0.038 rows=1
loops=24881)
                     Index Cond: ("outer".idxrreseller = b.idxreseller)
                     Filter: (asp = 6)
 Total runtime: 2655.713 ms




dns=> \d stat;
                           Table «public.stat»

 idxreseller | integer | not null
 idxdo   | integer | not null
 idxd       | integer | not null
 nbrq         | integer | default 0
 month         | integer | default date_part('month'::text, (now() -
'1 mon'::interval))
 year        | integer | default date_part('year'::text, (now() - '1
mon'::interval))

Index :
   «stat_dns_domaine_idx_idxr_idxreseller» btree (dxreseller)
   «stat_dns_domaine_idx_month_year_idxres» btree (month, year, idxreseller)




\d reseller;
                                       Table «public.reseller»

 idxreseller    | integer | not null default
nextval(('idxrevendeur_seq'::text)::regclass)
 namereseller     | text    |
 asp              | integer |
Index :
   «reseller_pkey» PRIMARY KEY, btree (idxreseller)


Have you advices ?

Thank you

Stan



view thread (14+ messages)  latest in thread

Message-ID: <bc40d0a30709140602x2a7914bcs8fa65d738abc4e92@mail.gmail.com>
Permalink:  ../bc40d0a30709140602x2a7914bcs8fa65d738abc4e92@mail.gmail.com/
Also on:    postgresql.org/message-id/bc40d0a30709140602x2a7914bcs8fa65d738abc4e92@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dllstan@gmail.com
  Subject: Re: Optimize querry sql
  In-Reply-To: <bc40d0a30709140602x2a7914bcs8fa65d738abc4e92@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox