Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 2433A64FC93 for ; Thu, 27 Nov 2008 04:55:42 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 03215-08 for ; Thu, 27 Nov 2008 04:55:35 -0400 (AST) Received: from mx3.hub.org (mx3.hub.org [206.223.169.73]) by mail.postgresql.org (Postfix) with ESMTP id 8E82864FC92 for ; Thu, 27 Nov 2008 04:55:35 -0400 (AST) X-Greylist: delayed 00:06:38.530904 by SQLgrey-1.7.6 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.171]) by mx3.hub.org (Postfix) with ESMTP id 9DFD137B8F3 for ; Thu, 27 Nov 2008 02:20:12 -0400 (AST) Received: from webserv.wug.de ([194.25.154.138]) by mrelayeu.kundenserver.de (node=mrelayeu0) with ESMTP (Nemesis) id 0MKwh2-1L5a703oVP-0004oU; Thu, 27 Nov 2008 07:12:29 +0100 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1L5a70-0000ZM-00 for pgsql-performance@postgresql.org; Thu, 27 Nov 2008 07:12:26 +0100 Date: Thu, 27 Nov 2008 07:12:26 +0100 From: "A. Kretschmer" To: pgsql-performance@postgresql.org Subject: Re: performance tuning queries Message-ID: <20081127061226.GA1087@a-kretschmer.de> References: <200811262121.05463.kevin@kevinkempterllc.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200811262121.05463.kevin@kevinkempterllc.com> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! User-Agent: Mutt/1.5.9i X-Provags-ID: V01U2FsdGVkX1+iJ85/9j/AqyMORPW3H0bDkqwlC/7g83BTEdR c8EzOF6ycF8BbUNXngLaxowAl626/ajGDnYOC62vxNlpZK+f/V T2D08V9pYXtFw4kXv7bYy5ggODm62KV X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200811/282 X-Sequence-Number: 32013 am Wed, dem 26.11.2008, um 21:21:04 -0700 mailte Kevin Kempter folgendes: > Next we have a select count(*) that also one of the top offenders: > > select count(*) from public.tab3 where user_id=31 > and state='A' > and amount>0; > > QUERY PLAN > ----------------------------------------------------------------------------------------------------- > Aggregate (cost=3836.53..3836.54 rows=1 width=0) > -> Index Scan using order_user_indx ontab3 user_id (cost=0.00..3834.29 > rows=897 width=0) > Index Cond: (idx_user_id = 31406948::numeric) > Filter: ((state = 'A'::bpchar) AND (amount > 0::numeric)) > (4 rows) > > We have an index on the user_id but not on the state or amount, > > add index to amount ? Depends. - Is the index on user_id a unique index? - how many different values are in the table for state, i.e., maybe an index on state can help - how many rows in the table with amount > 0? If almost all rows contains an amount > 0 an index can't help in this case Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net