Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 9DAC9B604FF for ; Wed, 1 Jun 2011 19:28:45 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 32849-02-3 for ; Wed, 1 Jun 2011 22:28:38 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pv0-f174.google.com (mail-pv0-f174.google.com [74.125.83.174]) by mail.postgresql.org (Postfix) with ESMTP id F2CAEB60703 for ; Wed, 1 Jun 2011 19:28:35 -0300 (ADT) Received: by pvg12 with SMTP id 12so115580pvg.19 for ; Wed, 01 Jun 2011 15:28:35 -0700 (PDT) Received: by 10.143.20.3 with SMTP id x3mr4362wfi.159.1306967315417; Wed, 01 Jun 2011 15:28:35 -0700 (PDT) Received: from issac.consistentstate.com (173-164-51-9-colorado.hfc.comcastbusiness.net [173.164.51.9]) by mx.google.com with ESMTPS id l15sm13519wfe.8.2011.06.01.15.28.33 (version=SSLv3 cipher=OTHER); Wed, 01 Jun 2011 15:28:34 -0700 (PDT) Message-ID: <4DE6BD11.6060603@consistentstate.com> Date: Wed, 01 Jun 2011 16:28:33 -0600 From: CS DBA User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc14 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: Kevin Grittner CC: pgsql-performance@postgresql.org Subject: Re: Problem query References: <4DE69D92.5040407@consistentstate.com> <4DE66AF8020000250003DFB6@gw.wicourts.gov> In-Reply-To: <4DE66AF8020000250003DFB6@gw.wicourts.gov> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201106/8 X-Sequence-Number: 43941 On 06/01/2011 03:38 PM, Kevin Grittner wrote: > CS DBA wrote: > >> 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) > > Why not something simpler? There are a number of possibilities, and > I don't claim this one is necessarily best (or even error free), but > how about something like?: > > select count(*) from > (select distinct max(pri_num) > from max_xtrv_st_t > group by tds_cx_ind, cxs_ind_2) x > > -Kevin I've tried a number of alternates, each one wants to do a seq scan of the table (including your suggestion above). -- --------------------------------------------- Kevin Kempter - Constent State A PostgreSQL Professional Services Company www.consistentstate.com ---------------------------------------------