From rjessil@yahoo.com Fri May 18 13:15:35 2007 Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id C98AC9FC2B3 for ; Fri, 18 May 2007 10:15:35 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 97340-09 for ; Fri, 18 May 2007 10:15:22 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from web56406.mail.re3.yahoo.com (web56406.mail.re3.yahoo.com [216.252.111.85]) by postgresql.org (Postfix) with SMTP id BF5DD9FC2CB for ; Fri, 18 May 2007 10:15:27 -0300 (ADT) Received: (qmail 36131 invoked by uid 60001); 18 May 2007 13:15:26 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=MBReJuP20RAsPsfBpkOTyYbYh/KtIBx/1AGOxcjG9IMy78CwWL4ZzPYw/xO9GjKWAxUCxdpAreL5QmX72GE+yTUu5GI5a3LDTogsGutlxxivuAEZASgjJwSvBWKenbfQ7aQN9D7acOyiZIvlhmasX0LJvB8FxJmPrmLuCX7AQv0=; X-YMail-OSG: 9FrJZ7QVM1mMUhGqRuuCaHhuYtahT4PpIDoF8gehPoqNomGFkZEOkEm9XY6vVcIRyHW8leT0YIfJhdGGYD6Zgv1av_oHLlCxHxEpBVU098_FjHLZEJSlgUerJS6UOzw- Received: from [198.119.134.32] by web56406.mail.re3.yahoo.com via HTTP; Fri, 18 May 2007 06:15:25 PDT Date: Fri, 18 May 2007 06:15:25 -0700 (PDT) From: Jessica Richard Subject: select count(*) from a large table is very slow To: pgsql-admin@postgresql.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-304417302-1179494125=:35849" Content-Transfer-Encoding: 8bit Message-ID: <133912.35849.qm@web56406.mail.re3.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.257 tagged_above=0 required=5 tests=AWL=-2.855, BAYES_20=-0.74, DNS_FROM_RFC_ABUSE=0.2, DNS_FROM_RFC_POST=1.708, DNS_FROM_RFC_WHOIS=1.447, HTML_40_50=0.496, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200705/181 X-Sequence-Number: 25501 --0-304417302-1179494125=:35849 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit I have a ~30 milliow row table, select count(*) from this table is very very very slow... How dow I get it run faster? Thanks, Jessica --------------------------------- We won't tell. Get more on shows you hate to love (and love to hate): Yahoo! TV's Guilty Pleasures list. --0-304417302-1179494125=:35849 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 8bit I have a ~30 milliow row table, select count(*) from this table is very very very slow...

How dow I get it run faster?

Thanks,
Jessica


We won't tell. Get more on shows you hate to love
(and love to hate): Yahoo! TV's Guilty Pleasures list. --0-304417302-1179494125=:35849-- From ktm@rice.edu Fri May 18 13:19:26 2007 Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 504539FC2F4 for ; Fri, 18 May 2007 10:19:26 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 97858-05 for ; Fri, 18 May 2007 10:19:17 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from is.rice.edu (is.rice.edu [128.42.42.24]) by postgresql.org (Postfix) with ESMTP id B74F69FC2E5 for ; Fri, 18 May 2007 10:19:22 -0300 (ADT) Received: from scan2.mail.rice.edu (scan2.mail.rice.edu [128.42.59.161]) by is.rice.edu (Postfix) with ESMTP id 2F72E41822; Fri, 18 May 2007 08:19:21 -0500 (CDT) Received: from is.rice.edu ([128.42.42.24]) by scan2.mail.rice.edu (scan2.mail.rice.edu [128.42.59.161]) (amavisd-new, port 10024) with ESMTP id 27421-07; Fri, 18 May 2007 08:19:20 -0500 (CDT) Received: by is.rice.edu (Postfix, from userid 18612) id 6D31941820; Fri, 18 May 2007 08:19:20 -0500 (CDT) Date: Fri, 18 May 2007 08:19:20 -0500 From: Kenneth Marshall To: Jessica Richard Cc: pgsql-admin@postgresql.org Subject: Re: select count(*) from a large table is very slow Message-ID: <20070518131920.GA7069@it.is.rice.edu> References: <133912.35849.qm@web56406.mail.re3.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <133912.35849.qm@web56406.mail.re3.yahoo.com> User-Agent: Mutt/1.4.2i X-Virus-Scanned: by amavis-2.2.1 at scan2.mail.rice.edu X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/182 X-Sequence-Number: 25502 Make a summary table and select from there instead. Ken On Fri, May 18, 2007 at 06:15:25AM -0700, Jessica Richard wrote: > I have a ~30 milliow row table, select count(*) from this table is very very very slow... > > How dow I get it run faster? > > Thanks, > Jessica > > > --------------------------------- > We won't tell. Get more on shows you hate to love > (and love to hate): Yahoo! TV's Guilty Pleasures list. From jonah.harris@gmail.com Fri May 18 13:22:43 2007 Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id EFF259FC33E for ; Fri, 18 May 2007 10:22:43 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 88178-02 for ; Fri, 18 May 2007 10:22:40 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from nz-out-0506.google.com (nz-out-0506.google.com [64.233.162.229]) by postgresql.org (Postfix) with ESMTP id 99B329FC2EA for ; Fri, 18 May 2007 10:22:40 -0300 (ADT) Received: by nz-out-0506.google.com with SMTP id s1so1386275nze for ; Fri, 18 May 2007 06:22:39 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=fTFJAt+7fDMt6Xs4YY281aS4pkKNk4fIkm7uOSiFi4Wb6OFHaqUrhvduiSQXQpx5PjMC+0tYNF/IqcnEyTReSTHRzz4ECpJQAL0PcKZKR7x9CjzW1f7mFglQzqPFob5yhcx9WbCMyWhY1zwxbSZSBY4G4h5Z4FEfj0EM6f6/oSo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=h/NlkKR2EBvga0l33E3GoFzy4DxpWLZ890mHIGtoKukiw0wzkQM9xRaGkdb2+irPJnpzhdpdyK+iXKaBhfwbo4sCw+KJ9WQnGjKt7jG3pKbz1WhR0wtcaNFNBzIKtmjx46Wlfj4Km8G5V38j9G8Y+n3NhKz5wCAa57js1V62kbE= Received: by 10.114.205.1 with SMTP id c1mr834051wag.1179494558793; Fri, 18 May 2007 06:22:38 -0700 (PDT) Received: by 10.114.47.12 with HTTP; Fri, 18 May 2007 06:22:38 -0700 (PDT) Message-ID: <36e682920705180622t7e60d5e0rf4143d4af336967f@mail.gmail.com> Date: Fri, 18 May 2007 09:22:38 -0400 From: "Jonah H. Harris" To: "Jessica Richard" Subject: Re: select count(*) from a large table is very slow Cc: pgsql-admin@postgresql.org In-Reply-To: <133912.35849.qm@web56406.mail.re3.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <133912.35849.qm@web56406.mail.re3.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/184 X-Sequence-Number: 25504 On 5/18/07, Jessica Richard wrote: > I have a ~30 milliow row table, select count(*) from this table is very very > very slow... Yes, see the topic "Much Ado about COUNT(*)" > How dow I get it run faster? Unfortunately, aside from reducing the size of the table, you can't. -- Jonah H. Harris, Software Architect | phone: 732.331.1324 EnterpriseDB Corporation | fax: 732.331.1301 33 Wood Ave S, 3rd Floor | jharris@enterprisedb.com Iselin, New Jersey 08830 | http://www.enterprisedb.com/ From jonah.harris@gmail.com Fri May 18 13:30:42 2007 Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 7BDAA9FB412 for ; Fri, 18 May 2007 10:30:42 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 06341-03 for ; Fri, 18 May 2007 10:30:33 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from nz-out-0506.google.com (nz-out-0506.google.com [64.233.162.232]) by postgresql.org (Postfix) with ESMTP id 9C7DB9FB394 for ; Fri, 18 May 2007 10:30:38 -0300 (ADT) Received: by nz-out-0506.google.com with SMTP id s1so1388960nze for ; Fri, 18 May 2007 06:30:37 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=nsyiuMf/I8pMI94HUm9xSHWaFL/ytrWaQzshX5c/KuhmYzA/x/22GgzhK0n85T7tdtkcSlwAM6JLeifdgbAZdsR3Sjvb8wdbEXwXn7uGSAeU7rDd/Wk0zzj7/SRKi5keBDSOjkgj9gCgBS+nqF/ZKa4BIzJrL7RN25FDhRXYU+A= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=LtbFmCv51yUQr+p5H6sLXXog3ybnwKc2aqOZCA1e9sxGj8Ip6NEF+R9aihC++Fju7eCtd2wry7TWKeK7tjI5Ie5SbMeYFne8Op/SFI5uixVkaRTfAxwCJA8MiLtnL5u0mEFf8qnyV4Ix8LEZr1Na53yS0gSN8kr0pkDXQy3uLA0= Received: by 10.114.15.1 with SMTP id 1mr873612wao.1179495036588; Fri, 18 May 2007 06:30:36 -0700 (PDT) Received: by 10.114.47.12 with HTTP; Fri, 18 May 2007 06:30:36 -0700 (PDT) Message-ID: <36e682920705180630y2c28cdc5m14af94d6d62e1daf@mail.gmail.com> Date: Fri, 18 May 2007 09:30:36 -0400 From: "Jonah H. Harris" To: "Kenneth Marshall" Subject: Re: select count(*) from a large table is very slow Cc: "Jessica Richard" , pgsql-admin@postgresql.org In-Reply-To: <20070518131920.GA7069@it.is.rice.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <133912.35849.qm@web56406.mail.re3.yahoo.com> <20070518131920.GA7069@it.is.rice.edu> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/186 X-Sequence-Number: 25506 On 5/18/07, Kenneth Marshall wrote: > Make a summary table and select from there instead. Yes, a summary table updated by triggers is the only way to have correct numbers... but you also pay the overhead of maintaining those numbers on every INSERT/UPDATE statement. If you just need *reasonable* guesstimates, use reltuples in pg_class after an analyze. -- Jonah H. Harris, Software Architect | phone: 732.331.1324 EnterpriseDB Corporation | fax: 732.331.1301 33 Wood Ave S, 3rd Floor | jharris@enterprisedb.com Iselin, New Jersey 08830 | http://www.enterprisedb.com/ From danielcristian@gmail.com Fri May 18 13:59:06 2007 Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 9A3D59FC2D8 for ; Fri, 18 May 2007 10:59:06 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 55095-08 for ; Fri, 18 May 2007 10:59:02 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from nz-out-0506.google.com (nz-out-0506.google.com [64.233.162.230]) by postgresql.org (Postfix) with ESMTP id E792D9FC2AA for ; Fri, 18 May 2007 10:59:02 -0300 (ADT) Received: by nz-out-0506.google.com with SMTP id s1so1399912nze for ; Fri, 18 May 2007 06:59:01 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=YAdpI8vQkaVgenEEgOjrR3WQ1C1VFEmKwqtt4nmqk6N3MGTL/Q83qXWlc6HExhbH0meu0/S13pZymixt/HfKqB6/65lCNwRD7mJu7jwBdTtbfeOIyIBItLhLRno+WQ2bS5hYaHbfMTVoLH7lzqNpf39H545v7uIZAKW0ps8CtEQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=OgxlW4dX2hr8E2TqcXvL/59Z/BERIPC38H4r8eA5ghbDNY+jfrLzB/7AMx0OMuJIzktXKuns5Bksd+efPHNp6GXtURKGYVrXWuxcppNmhMmN1SJorFV5b7lcVybXQqJPAKLhXmhgbtSHVNJ4Yd510Ne/jJ2gqPScvCQlSirVueg= Received: by 10.114.120.1 with SMTP id s1mr849956wac.1179496739840; Fri, 18 May 2007 06:58:59 -0700 (PDT) Received: by 10.115.72.5 with HTTP; Fri, 18 May 2007 06:58:59 -0700 (PDT) Message-ID: <48d0cacb0705180658n1ce65297xa9f28d56dd4f8426@mail.gmail.com> Date: Fri, 18 May 2007 10:58:59 -0300 From: "Daniel Cristian Cruz" To: "Jonah H. Harris" Subject: Re: select count(*) from a large table is very slow Cc: "Kenneth Marshall" , "Jessica Richard" , pgsql-admin@postgresql.org In-Reply-To: <36e682920705180630y2c28cdc5m14af94d6d62e1daf@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <133912.35849.qm@web56406.mail.re3.yahoo.com> <20070518131920.GA7069@it.is.rice.edu> <36e682920705180630y2c28cdc5m14af94d6d62e1daf@mail.gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/187 X-Sequence-Number: 25507 2007/5/18, Jonah H. Harris : > Yes, a summary table updated by triggers is the only way to have > correct numbers... but you also pay the overhead of maintaining those > numbers on every INSERT/UPDATE statement. If you just need > *reasonable* guesstimates, use reltuples in pg_class after an analyze. Oops... INSERT or DELETE... :) And remember that if using TRUNCATE, it will not run your trigger and you will need to reset the counter manually. Regards... -- Daniel Cristian Cruz From jonah.harris@gmail.com Fri May 18 14:00:15 2007 Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 81E0D9FC2F0 for ; Fri, 18 May 2007 11:00:15 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 15168-04-3 for ; Fri, 18 May 2007 10:59:59 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from nz-out-0506.google.com (nz-out-0506.google.com [64.233.162.228]) by postgresql.org (Postfix) with ESMTP id 2391E9FC2EF for ; Fri, 18 May 2007 11:00:04 -0300 (ADT) Received: by nz-out-0506.google.com with SMTP id s1so1400288nze for ; Fri, 18 May 2007 07:00:03 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=fayLFDQ+EemhESiYyJhAxWVZClBmSQrQCOtjGUO3TepBcEjmqYibyDvkWsF8mHsL8ibJO49Cq6PXCCttXMCqqj1x28GN37RAhj46OSRwJKvQmRrw4F3VNnFEJqPmemgZ6zs7QAQBCwf8jLuGSJBxeydMMHvn1Qfl3oUakDEedIE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=YydPLEU0nlApTZfk9rxCv3xHakh5/JEOIoxDCwNKImMh/vHyZAcO+dt3UCaYYn+y45VaJWl8PmJ8rKSL2d8F2HXBqusafh1fNddcZPX6rYzS4jJ501VhcN/cNO9ZDUx+7P6Iynx3GtyOrmWDJIVffHYm0PMAo7m/7F0HUeQoOIk= Received: by 10.114.37.1 with SMTP id k1mr893401wak.1179496802144; Fri, 18 May 2007 07:00:02 -0700 (PDT) Received: by 10.114.47.12 with HTTP; Fri, 18 May 2007 07:00:01 -0700 (PDT) Message-ID: <36e682920705180700n7a6df052pfbbc19ba185886f8@mail.gmail.com> Date: Fri, 18 May 2007 10:00:01 -0400 From: "Jonah H. Harris" To: "Daniel Cristian Cruz" Subject: Re: select count(*) from a large table is very slow Cc: "Kenneth Marshall" , "Jessica Richard" , pgsql-admin@postgresql.org In-Reply-To: <48d0cacb0705180658n1ce65297xa9f28d56dd4f8426@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <133912.35849.qm@web56406.mail.re3.yahoo.com> <20070518131920.GA7069@it.is.rice.edu> <36e682920705180630y2c28cdc5m14af94d6d62e1daf@mail.gmail.com> <48d0cacb0705180658n1ce65297xa9f28d56dd4f8426@mail.gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/188 X-Sequence-Number: 25508 On 5/18/07, Daniel Cristian Cruz wrote: > Oops... INSERT or DELETE... :) Heh, yeah... doh! > And remember that if using TRUNCATE, it will not run your trigger and > you will need to reset the counter manually. Correct. -- Jonah H. Harris, Software Architect | phone: 732.331.1324 EnterpriseDB Corporation | fax: 732.331.1301 33 Wood Ave S, 3rd Floor | jharris@enterprisedb.com Iselin, New Jersey 08830 | http://www.enterprisedb.com/