From virag@auptyma.com Sat Feb 10 00:05:53 2007 Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 55D7C9FA616 for ; Fri, 9 Feb 2007 20:05:53 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 79797-04 for ; Fri, 9 Feb 2007 20:05:45 -0400 (AST) X-Greylist: delayed 00:05:24.476158 by SQLgrey-1.7.4 Received: from mail.auptyma.com (mail.auptyma.com [64.60.124.12]) by postgresql.org (Postfix) with ESMTP id 2D7B49FA281 for ; Fri, 9 Feb 2007 20:05:48 -0400 (AST) Received: from demo01 (mail.auptyma.com [64.60.124.12] (may be forged)) (authenticated bits=0) by mail.auptyma.com (8.13.1/8.13.1) with ESMTP id l19NHRr2027709 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Fri, 9 Feb 2007 15:17:27 -0800 Message-ID: <00aa01c74ca6$7392a160$2900000a@demo01> From: "Virag Saksena" To: Subject: Is there an equivalent for Oracle's user_tables.num_rows Date: Fri, 9 Feb 2007 16:00:18 -0800 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_00A7_01C74C63.64E9DDB0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-Greylist: Sender succeded SMTP AUTH authentication, not delayed by milter-greylist-1.7.5 (mail.auptyma.com [10.0.0.47]); Fri, 09 Feb 2007 15:17:27 -0800 (PST) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.2 tagged_above=0 required=5 tests=BAYES_40, HTML_MESSAGE, SPF_SOFTFAIL X-Spam-Level: * X-Archive-Number: 200702/109 X-Sequence-Number: 23163 This is a multi-part message in MIME format. ------=_NextPart_000_00A7_01C74C63.64E9DDB0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable All, I am looking to automate analyze table in my application. I have some insert only tables in my application which I need to analyze = as data grows. Since the inserts are application controlled, I can choose to run = analyze when I determine the data has grown more than x% since last analyze. However since users can truncate the tables too, I need to be able to = tell the numbers of rows in the table as perceived by the optimizer.=20 I could not decipher a good way of telling the number of table rows from = pg_stats/pg_statistics. Does someone know of a way of telling what the optimizer believes the = number of rows are ? The tables in question have multi-column primary keys. Regards, Virag ------=_NextPart_000_00A7_01C74C63.64E9DDB0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
All,
    I am looking to = automate analyze=20 table in my application.
 
I have some insert only tables in my = application=20 which I need to analyze as data grows.
Since the inserts are application = controlled, I can=20 choose to run analyze when I determine the
data has grown more than x% since last=20 analyze.
 
However since users can truncate the = tables too, I=20 need to be able to tell the numbers of rows
in the table as perceived by the = optimizer.=20
 
I could not decipher a good way of = telling the=20 number of table rows from pg_stats/pg_statistics.
 
Does someone know of a way of telling = what the=20 optimizer believes the number of rows are ?
 
The tables in question have = multi-column primary=20 keys.
 
Regards,
 
Virag
------=_NextPart_000_00A7_01C74C63.64E9DDB0-- From tgl@sss.pgh.pa.us Sat Feb 10 00:47:51 2007 Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 2CBF19FA281 for ; Fri, 9 Feb 2007 20:47:51 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 52042-10 for ; Fri, 9 Feb 2007 20:47:43 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id F21D79FA19A for ; Fri, 9 Feb 2007 20:47:47 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id l1A0j3m7006479; Fri, 9 Feb 2007 19:45:03 -0500 (EST) To: "Virag Saksena" cc: pgsql-performance@postgresql.org Subject: Re: Is there an equivalent for Oracle's user_tables.num_rows In-reply-to: <00aa01c74ca6$7392a160$2900000a@demo01> References: <00aa01c74ca6$7392a160$2900000a@demo01> Comments: In-reply-to "Virag Saksena" message dated "Fri, 09 Feb 2007 16:00:18 -0800" Date: Fri, 09 Feb 2007 19:45:03 -0500 Message-ID: <6478.1171068303@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200702/110 X-Sequence-Number: 23164 "Virag Saksena" writes: > Does someone know of a way of telling what the optimizer believes the = > number of rows are ? You're looking in the wrong place; see pg_class.relpages and reltuples. But note that in recent releases neither one is taken as gospel. Instead the planner uses the current physical table size in place of relpages, and scales reltuples correspondingly. So neither steady growth nor truncation create a need for re-ANALYZE; at least not as long as the other statistics don't change too much. regards, tom lane From virag@auptyma.com Sat Feb 10 01:08:51 2007 Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 02DE49FA19A for ; Fri, 9 Feb 2007 21:08:51 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 57777-05 for ; Fri, 9 Feb 2007 21:08:43 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mail.auptyma.com (mail.auptyma.com [64.60.124.12]) by postgresql.org (Postfix) with ESMTP id 8DBAE9FA197 for ; Fri, 9 Feb 2007 21:08:47 -0400 (AST) Received: from demo01 (mail.auptyma.com [64.60.124.12] (may be forged)) (authenticated bits=0) by mail.auptyma.com (8.13.1/8.13.1) with ESMTP id l1A0PuZZ028226 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Fri, 9 Feb 2007 16:25:56 -0800 Message-ID: <00c801c74cb0$04a27820$2900000a@demo01> From: "Virag Saksena" To: References: <00aa01c74ca6$7392a160$2900000a@demo01> <6478.1171068303@sss.pgh.pa.us> Subject: Re: Is there an equivalent for Oracle's user_tables.num_rows Date: Fri, 9 Feb 2007 17:08:47 -0800 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-Greylist: Sender succeded SMTP AUTH authentication, not delayed by milter-greylist-1.7.5 (mail.auptyma.com [10.0.0.47]); Fri, 09 Feb 2007 16:25:56 -0800 (PST) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200702/111 X-Sequence-Number: 23165 Thanks, that is exactly what I was looking for I know that number of rows may not be the best indicator, but it is a heuristic that can be tracked easily, causing analyze for the first x insert events, and then only doing it only when an insert event causes total rows to exceed y % of the optimizer perceived rows Other more accurate heuristics like relative distribution of columns would be harder to track in the application, and I'd rather let the database do that by issuing the analyze Regards, Virag ----- Original Message ----- From: "Tom Lane" To: "Virag Saksena" Cc: Sent: Friday, February 09, 2007 4:45 PM Subject: Re: [PERFORM] Is there an equivalent for Oracle's user_tables.num_rows > "Virag Saksena" writes: >> Does someone know of a way of telling what the optimizer believes the = >> number of rows are ? > > You're looking in the wrong place; see pg_class.relpages and reltuples. > > But note that in recent releases neither one is taken as gospel. > Instead the planner uses the current physical table size in place of > relpages, and scales reltuples correspondingly. So neither steady > growth nor truncation create a need for re-ANALYZE; at least not as long > as the other statistics don't change too much. > > regards, tom lane >