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 1fEIuh-0007xl-1y for pgsql-general@arkaria.postgresql.org; Thu, 03 May 2018 18:25:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fEIue-0003rc-Vm for pgsql-general@arkaria.postgresql.org; Thu, 03 May 2018 18:25:04 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fEIue-0003rQ-KN for pgsql-general@lists.postgresql.org; Thu, 03 May 2018 18:25:04 +0000 Received: from mail-io0-x241.google.com ([2607:f8b0:4001:c06::241]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fEIub-0000UH-HY for pgsql-general@postgresql.org; Thu, 03 May 2018 18:25:03 +0000 Received: by mail-io0-x241.google.com with SMTP id e12-v6so22766672iob.8 for ; Thu, 03 May 2018 11:25:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=QvOL9Nr97m9bYxwQtg3Bo08ObatGceDykzV7hKw+G/k=; b=C7ckBolWuMN8JdlteB5mnQ9ZuPJ6nPrCMb1M3I97a/Gc2aARI0z+JTYYM4XtS1wF57 pvHwFH5c53euvxm02sLGKK4nX5SXZs+aSTAwc6jS4fHLTcuW3fzhxn8TB/wzT8H5RYNt evA/KVsngIunbs9pYMSpIvLp2yc9xE+BBIAxvU4mZ3Mz8x5k1Rs0VhxMCUPpM2fqbrF/ 8seE8vDNpuMdWuegbjjXreDKlzg+stFFY6AF5QGFYfanHzDdnAyvNVsOaiqukXbYrbuT 58LYcTckqHthdCRaW47GEp636XCQ9SDgAQiARUjjAX8vHsBCqnKbR7Sp7Pu7ctZGLiuo RKYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=QvOL9Nr97m9bYxwQtg3Bo08ObatGceDykzV7hKw+G/k=; b=AqPbhzSnZPeiMN2fpdOD93/TvNuWmqwiDOhmkLgTp3n2a6OqHAqsdspl8otDnNRIAZ EOwkRh07rZZMMAJpZiCCZPogJT0kyLOxI8ItVW+9vV0doChaMKTVyhtR7Q1wTvARTe+h Xfe3wD/0J5KkeGghn3Mb8hwdWlROSNwJDcjfqVz2ZtLUU42tUdHgAFgAJSRVtOnXEPjV 7SY6Py6M1R26Bi6UCJKpN0dJgnBOZ6oBgtW8nKycr05PHauU7ITXrRzvcdrock78aqRw jK40TY5pM4IalhLXKQKMdax960IYKoVCSGqIPykhTuwKpXgFwsP0pbgoac/kOkNrwEHa hNIw== X-Gm-Message-State: ALQs6tCvJoeedvnvkjx81fPvTbt1qtySzJ06XJIlJHQhNHOWzcd0NgtO j+uDO2HMeCufBoQVoyhJLsAkJg== X-Google-Smtp-Source: AB8JxZqt9GGQ5s6N0KSmCfa8S13B3b19yYgOqax/lDB5Adem/KJ0t4ROWUAFPoc4LIk1o4AvOM6DrQ== X-Received: by 2002:a6b:5804:: with SMTP id m4-v6mr26821878iob.46.1525371900697; Thu, 03 May 2018 11:25:00 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id k76-v6sm76413itk.22.2018.05.03.11.25.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 May 2018 11:25:00 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 298168021B7; Thu, 3 May 2018 13:24:59 -0500 (CDT) Date: Thu, 3 May 2018 13:24:59 -0500 From: Justin Pryzby To: Adrian Klaver Cc: Alvaro Herrera , pgsql-general@postgresql.org Subject: Re: relkind='p' has no pg_stat_user_tables Message-ID: <20180503182459.GI9585@telsasoft.com> References: <20180503162047.37k7km4dx62i6l4d@alvherre.pgsql> <0d1a3f8a-f6f9-4712-6b6c-174e64a38b48@aklaver.com> <20180503173855.GH9585@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, May 03, 2018 at 11:15:19AM -0700, Adrian Klaver wrote: > 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. Yes, I was surprised about the difference between ANALYZE relkind_p and relkind_r. But I see that's a documented behavior I'd missed until now: https://www.postgresql.org/docs/current/static/sql-analyze.html |If the specified table is a partitioned table, both the inheritance statistics |of the partitioned table as a whole and statistics of the individual partitions |are updated. Thanks, Justin