X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3A8FF529C7 for ; Sun, 10 Jul 2005 09:30:39 -0300 (ADT) 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 86692-05 for ; Sun, 10 Jul 2005 12:30:29 +0000 (GMT) Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by svr1.postgresql.org (Postfix) with ESMTP id 06087529FA for ; Sun, 10 Jul 2005 09:30:27 -0300 (ADT) Received: from root by ciao.gmane.org with local (Exim 4.43) id 1Drawr-0001jz-UW for pgsql-sql@postgresql.org; Sun, 10 Jul 2005 14:30:17 +0200 Received: from srv.protecting.net ([212.126.218.242]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 10 Jul 2005 14:30:17 +0200 Received: from hf0614x by srv.protecting.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 10 Jul 2005 14:30:17 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Harald Fuchs Subject: Re: Make COUNT(*) Faster? Date: 10 Jul 2005 14:19:56 +0200 Organization: Linux Private Site Lines: 25 Message-ID: References: <9EF2931D-1097-470D-8ECB-59D00166C96F@apple.com> <60vf3mklue.fsf@dba2.int.libertyrms.com> <42CE89CA.2070607@noao.edu> <758d5e7f05070808305c049aae@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: srv.protecting.net User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200507/95 X-Sequence-Number: 22073 In article <758d5e7f05070808305c049aae@mail.gmail.com>, Dawid Kuroczko writes: > Use > EXPLAIN SELECT * FROM yourcountedtable; > Planner seems to track estimated statistics on-the-fly. :) > You can even wrap EXPLAIN SELECT in a pgsql function if you > need it. Do you know how to do that? A function "approx_count(tablename)" would be really handy, but FOR row IN EXECUTE 'EXPLAIN SELECT * FROM ' || tbl LOOP fails with the following message: ERROR: cannot open non-SELECT query as cursor > PS: And be aware that these are 'statistics'. And the statement that there > are lies, big lies and statistics is sometimes true even for PostgreSQL. ;-) Does this mean that PostgreSQL believes only in statistics it has faked itself? ;-)