Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fEIlR-0007Q1-Jf for pgsql-general@arkaria.postgresql.org; Thu, 03 May 2018 18:15:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fEIlQ-00046A-CV for pgsql-general@arkaria.postgresql.org; Thu, 03 May 2018 18:15:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fEIlQ-000460-44 for pgsql-general@lists.postgresql.org; Thu, 03 May 2018 18:15:32 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fEIlG-0001FE-Pw for pgsql-general@postgresql.org; Thu, 03 May 2018 18:15:31 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id F0DDE21BBA; Thu, 3 May 2018 14:15:20 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 03 May 2018 14:15:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=UqO0AaCPKeDoMHW5+KGpHfwxdaymn 6Xm9ldu5Qffgjo=; b=esZT5CMgUPVKKaV/9WjJ0eFCBrWUSE6s3RvrzW8G7/7Nf QHgfIPq+bdFbcY3FcUf361by71d0jDIs1QGwPRgaqnhJpO0yj+JyRXH+ObWbMBqM KOG2rz0DNBCa/N6XGCb2DbseCtWp8SEQSwTwXWPw4fh+L7XDviu6j3kLfZVMCXYX ZT9W68KyLucohacMabakXhZOXplNSR4zGUDuBN/F7JoPBxlFaFc22fksg54nsAKv rfALKePYCvxHsY0lm2TWagn4b7QiNDBbb8d76UUJisPHXoqgcuLGSnqB3Tqqid3P 0eFCVz0TTmZK/2R13eCG3VAUta0TeSitypepr62Fg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=UqO0Aa CPKeDoMHW5+KGpHfwxdaymn6Xm9ldu5Qffgjo=; b=eRs/g1OsFPj27coIdpShdX DN/yYq148O4/Slh72wzwZ/Xep9hwZ7uwi8qktEtlcgT8/zz1GY3KXLpQfWA64WtJ Yue8FGLfg8BzOCiN76npZUXqf31y2WTrbm38oBBaCsxeN+ehCV2VAMkv0CHjQmeb QJ2ldZ8WQAVUp7wWOUSR66VGBHl6ocRah3MQz5NliPWTGPAlqf6HthuJglzLEeKS 8IR6f9gfZIgha/QD7pOxnhzdpI+EKtiBB/EUhynF+5AUSpwmFeeQ7eCHbW472ybs og2pPaWjhUDIxQUv8/uRj1mNH8ZF+ghjnEh69lzAPWObF77E/SGVX5zl5xX0wjMw == X-ME-Sender: Received: from [192.168.1.2] (unknown [71.212.135.74]) by mail.messagingengine.com (Postfix) with ESMTPA id 4ED8DE4E8F; Thu, 3 May 2018 14:15:20 -0400 (EDT) Subject: Re: relkind='p' has no pg_stat_user_tables To: Justin Pryzby Cc: Alvaro Herrera , pgsql-general@postgresql.org References: <20180503162047.37k7km4dx62i6l4d@alvherre.pgsql> <0d1a3f8a-f6f9-4712-6b6c-174e64a38b48@aklaver.com> <20180503173855.GH9585@telsasoft.com> From: Adrian Klaver Message-ID: Date: Thu, 3 May 2018 11:15:19 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180503173855.GH9585@telsasoft.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 05/03/2018 10:38 AM, Justin Pryzby wrote: > On Thu, May 03, 2018 at 09:31:12AM -0700, Adrian Klaver wrote: >> On 05/03/2018 09:20 AM, Alvaro Herrera wrote: >>>> https://www.postgresql.org/docs/10/static/sql-createtable.html >>>> >>>> "A partitioned table is divided into sub-tables (called partitions), which >>>> are created using separate CREATE TABLE commands. The partitioned table is >>>> itself empty. A data row inserted into the table is routed to a partition >>>> based on the value of columns or expressions in the partition key. ... " >>> >>> Yeah, but I think Justin has a valid question from the POV of the user: >>> how can we figure out if we need to re-run analyze on a partitioned >>> table, if the time of last analyze is not stored anywhere? >> >> I agree. The only thing I can think of is, that knowing : >> >> ANALYZE VERBOSE t; >> >> walks the inheritance tree, look at the pg_stat_user_tables for one of the >> children for the last time analyzed. > > I think I can make this work for my purposes: > > SELECT MIN(GREATEST(last_analyze,last_autoanalyze)) > FROM pg_stat_user_tables psut > JOIN pg_inherits i > ON i.inhrelid=psut.relid > WHERE i.inhparent=... > > I was about to say that it's perhaps more correct for relkind='r' parents, too. > > But actually, it looks like for relkind='p', ANALYZE populates stats on child > tables in addition to the parent. For relkind='r', the behavior (introduced in > PG9.0 as I recall) is that ANALYZE on parent creates stats only for parent > (both "inherited" stats including children, and "ONLY" stats for the > potentially-nonempty parent). > > I guess ability to update child tables' stats is a nice feature, but I'm > surprised. I wonder if that was a deliberate/documented change ? I was with you until I got to the above. You seem to be comparing apples and oranges unless I am missing something. The behavior for 'r' tables has not changed: https://www.postgresql.org/docs/9.0/static/sql-analyze.html https://www.postgresql.org/docs/10/static/sql-analyze.html The 'p' type table does not appear until version 10: https://www.postgresql.org/docs/9.6/static/catalog-pg-class.html https://www.postgresql.org/docs/10/static/catalog-pg-class.html so there is no past behavior to compare to. > > Justin > -- Adrian Klaver adrian.klaver@aklaver.com