pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Arnau <arnaulist@andromeiberica.com>
To: pgsql-performance@postgresql.org
Subject: Is it possible to speed this query up?
Date: Wed, 26 Jul 2006 19:01:33 +0200
Message-ID: <44C79FED.5080702@andromeiberica.com> (raw)

Hi all,

   I execute the following query on postgresql 8.1.0:

SELECT
   u.telephone_number
   , u.telecom_operator_id
   , u.name
FROM
   campanas_subcampaign AS sub
   , agenda_users AS u
   , agenda_users_groups ug
WHERE
   sub.customer_app_config_id = 19362
   AND sub.subcampaign_id = 9723
   AND ug.agenda_user_group_id >= sub.ini_user_group_id
   AND ug.user_id=u.user_id
   AND ug.group_id IN ( SELECT group_id FROM campanas_groups WHERE 
customer_app_config_id = 19362 )
   ORDER BY ug.agenda_user_group_id ASC LIMIT 150

the explain analyze shouts the following:

 

    Limit  (cost=1.20..4600.56 rows=150 width=74) (actual 
time=76516.312..76853.191 rows=150 loops=1)
    ->  Nested Loop  (cost=1.20..333424.31 rows=10874 width=74) (actual 
time=76516.307..76852.896 rows=150 loops=1)
          ->  Nested Loop  (cost=1.20..299653.89 rows=10874 width=20) 
(actual time=76506.926..76512.608 rows=150 loops=1)
                Join Filter: ("outer".agenda_user_group_id >= 
"inner".ini_user_group_id)
                ->  Nested Loop IN Join  (cost=1.20..189802.77 
rows=32623 width=20) (actual time=75938.659..76353.748 rows=16200 loops=1)
                      Join Filter: ("outer".group_id = "inner".group_id)
                      ->  Index Scan using pk_agndusrgrp_usergroup on 
agenda_users_groups ug  (cost=0.00..123740.26 rows=2936058 width=30) 
(actual time=0.101..61921.260 rows=2836638 loops=1)
                      ->  Materialize  (cost=1.20..1.21 rows=1 width=10) 
(actual time=0.001..0.002 rows=1 loops=2836638)
                            ->  Seq Scan on campanas_groups 
(cost=0.00..1.20 rows=1 width=10) (actual time=0.052..0.053 rows=1 loops=1)
                                  Filter: (customer_app_config_id = 
19362::numeric)
                ->  Index Scan using pk_cmpnssubc_subcmpnid on 
campanas_subcampaign sub  (cost=0.00..3.35 rows=1 width=8) (actual 
time=0.005..0.006 rows=1 loops=16200)
                      Index Cond: (subcampaign_id = 9723)
                      Filter: (customer_app_config_id = 19362::numeric)
          ->  Index Scan using pk_agenda_uid on agenda_users u 
(cost=0.00..3.09 rows=1 width=78) (actual time=2.262..2.264 rows=1 
loops=150)
                Index Cond: ("outer".user_id = u.user_id)
  Total runtime: 76853.504 ms
(16 rows)



Do you think I could do anything to speed it up?


Cheers!!
-- 
Arnau



view thread (2+ messages)  latest in thread

Message-ID: <44C79FED.5080702@andromeiberica.com>
Permalink:  ../44C79FED.5080702@andromeiberica.com/
Also on:    postgresql.org/message-id/44C79FED.5080702@andromeiberica.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-performance@postgresql.org
  Cc: arnaulist@andromeiberica.com
  Subject: Re: Is it possible to speed this query up?
  In-Reply-To: <44C79FED.5080702@andromeiberica.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