X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A1B58D7281 for ; Fri, 25 Nov 2005 08:31:49 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 88048-03 for ; Fri, 25 Nov 2005 12:31:51 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mx2.surnet.cl (mx2.surnet.cl [216.155.73.181]) by svr1.postgresql.org (Postfix) with ESMTP id A8843D721C for ; Fri, 25 Nov 2005 08:31:46 -0400 (AST) Received: from unknown (HELO cluster.surnet.cl) ([216.155.73.165]) by mx2.surnet.cl with ESMTP; 25 Nov 2005 09:32:41 -0300 Received: from alvh.no-ip.org (200.85.218.89) by cluster.surnet.cl (7.0.043) (authenticated as alvherre@surnet.cl) id 43501597005A0448 for pgsql-performance@postgresql.org; Fri, 25 Nov 2005 09:31:49 -0300 Received: by alvh.no-ip.org (Postfix, from userid 1000) id C5E33C30B0D; Fri, 25 Nov 2005 09:32:00 -0300 (CLST) Date: Fri, 25 Nov 2005 09:32:00 -0300 From: Alvaro Herrera To: pgsql-performance@postgresql.org Subject: Re: 8.1 count(*) distinct: IndexScan/SeqScan Message-ID: <20051125123200.GD14707@surnet.cl> Mail-Followup-To: pgsql-performance@postgresql.org References: <334D9941-B5B3-4D18-8312-F85D0FB054ED@rilk.com> <17380.1132886273@sss.pgh.pa.us> <438681E0.6070006@kylecordes.com> <20051125114017.GA10575@uio.no> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20051125114017.GA10575@uio.no> User-Agent: Mutt/1.5.11 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=3.487 required=5 tests=[AWL=-0.582, DNS_FROM_RFC_ABUSE=0.479, DNS_FROM_RFC_POST=1.44, RCVD_IN_NJABL_PROXY=0.327, RCVD_IN_SORBS_SOCKS=1.823] X-Spam-Score: 3.487 X-Spam-Level: *** X-Archive-Number: 200511/511 X-Sequence-Number: 15768 Steinar H. Gunderson wrote: > On Thu, Nov 24, 2005 at 09:15:44PM -0600, Kyle Cordes wrote: > > I have hit cases where I have a query for which there is a somewhat > > "obvious" (to a human...) query plan that should make it possible to get > > a query answer pretty quickly. Yet the query "never" finishes (or > > rather, after hours of waiting I finally kill it). I assume this is > > because of a sub-optimal query plan. But, it appears that an EXPLAIN > > ANALYZE runs the actual query, so it takes as long as the actual query. > > In this case, you probably can't do better than EXPLAIN. Look at the > estimates, find out if the cost is way high somewhere. Also you want to make absolutely sure all the involved tables have been ANALYZEd recently. If you have weird cases where there is an obvious query plan and the optimizer is not using it, by all means submit it so that developers can take a look at how to improve the optimizer. -- Alvaro Herrera http://www.CommandPrompt.com/ The PostgreSQL Company - Command Prompt, Inc.