pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: CS DBA <cs_dba@consistentstate.com>
To: Merlin Moncure <mmoncure@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Problem query
Date: Wed, 01 Jun 2011 16:26:57 -0600
Message-ID: <4DE6BCB1.3010706@consistentstate.com> (raw)
In-Reply-To: <BANLkTimirG-4HDFXKbcgkagLes8eCjWwLQ@mail.gmail.com>
References: <4DE69D92.5040407@consistentstate.com>
	<BANLkTimirG-4HDFXKbcgkagLes8eCjWwLQ@mail.gmail.com>

On 06/01/2011 03:15 PM, Merlin Moncure wrote:
> On Wed, Jun 1, 2011 at 3:14 PM, CS DBA<cs_dba@consistentstate.com>  wrote:
>> Hi All;
>>
>> We have a table with approx 200 columns. about a dozen columns are text data
>> types and the rest are a mix of integers , bigint's and double precision
>> types.
>>
>> The table has about 25million rows.
>>
>>
>> The app wants to run a query like this:
>>
>> select count(pri_num) from max_xtrv_st_t
>> where pri_num in (select max(pri_num) from max_xtrv_st_t where 1=1
>>                                group by tds_cx_ind, cxs_ind_2 )
>>
>> I've tried to split the query up but made little progress, pri_num and
>>   tds_cx_ind are bigint's and  cxs_ind_2 is an integer
>>
>> The table has an index on all 3 columns (3 separate indexes)
>>
>> Anyone have any thoughts on tuning this query?
> need postgres version# and the current explain analyze (or explain, if
> you can't wait for it)
>
> merlin


Postgresql version 8.4.2


Explain:

                                            QUERY PLAN
------------------------------------------------------------------------------------------------
  Aggregate  (cost=6551481.85..6551481.86 rows=1 width=8)
    ->  Nested Loop  (cost=6550474.85..6551481.35 rows=200 width=8)
          ->  HashAggregate  (cost=6550474.85..6550476.85 rows=200 width=8)
                ->  GroupAggregate  (cost=5918263.18..6334840.58 
rows=17250742 width=20)
                      ->  Sort  (cost=5918263.18..5968498.96 
rows=20094312 width=20)
                            Sort Key: tds_cx_ind, cxs_ind_2
                            ->  Seq Scan on max_xtrv_st_t  
(cost=0.00..3068701.12 rows=20094312 width=20)
          ->  Index Scan using max_xtrv_st_t_pkey on max_xtrv_st_t   
(cost=0.00..5.01 rows=1 width=8)
                Index Cond: (max_xtrv_st_t.pri_num = 
(max(max_xtrv_st_t.pri_num)))
(9 rows)




-- 
---------------------------------------------
Kevin Kempter       -       Constent State
A PostgreSQL Professional Services Company
           www.consistentstate.com
---------------------------------------------




view thread (13+ messages)  latest in thread

Message-ID: <4DE6BCB1.3010706@consistentstate.com>
Permalink:  ../4DE6BCB1.3010706@consistentstate.com/
Also on:    postgresql.org/message-id/4DE6BCB1.3010706@consistentstate.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: cs_dba@consistentstate.com, mmoncure@gmail.com
  Subject: Re: Problem query
  In-Reply-To: <4DE6BCB1.3010706@consistentstate.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