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 1fEIC9-0005gB-Gg for pgsql-general@arkaria.postgresql.org; Thu, 03 May 2018 17:39:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fEIC8-0004GR-2S for pgsql-general@arkaria.postgresql.org; Thu, 03 May 2018 17:39:04 +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 1fEIC7-0004GH-M5 for pgsql-general@lists.postgresql.org; Thu, 03 May 2018 17:39:03 +0000 Received: from mail-io0-x244.google.com ([2607:f8b0:4001:c06::244]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fEIC2-0000HV-Np for pgsql-general@postgresql.org; Thu, 03 May 2018 17:39:03 +0000 Received: by mail-io0-x244.google.com with SMTP id e20-v6so22605699iof.4 for ; Thu, 03 May 2018 10:38:58 -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=lFniplPSUVGvEY+U7ZXKPygsVzIt58JNLcNKLn2pYh0=; b=mJ5T6zzAObP+spMQzMKSTSUSz6KXBrcQVG4B9BPxj+FA/dYlrPVhLhmw2U/khBrO/R D++7gxDhMARPufn3x5BcWqYP0Y+PyxcSkPS2GgGS8t43Wz0HYUdf1QgZmA+0yuC2i2pV Ug91tAqhmd09sW3SidSbnKrZLc+6TPm2m78IV1FxtufktgzjaJJLZ0qpWRQH6PUa0NzG aEirIFZRy6HIajhThmx+O5y83bDflsOoUUiOfd9N+dFy0a0LlXHC8Fz3t2PwBEdannC9 hdClT6nhYux21KfIc31zl3WLj2JMP1CWBCKmH7jpOPT66G31OkF10+X0L7CVOq7sIF3l RFxQ== 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=lFniplPSUVGvEY+U7ZXKPygsVzIt58JNLcNKLn2pYh0=; b=Fydkb6NnldfQLHJNbpGpvrENMT4Q0NgudvHFlFJmp6qsiFbzdnhwEO8HDZPsLCMnlM TldhoavgHQzbFd0z6Twi90Si7v96TbE9Coho3mzvCSjOlcaaiP9SXDLDA5VlCCDkNduV is4hugMoVOGTvjEK0uvwWWHfVHOhmpqTnhmymQCm8CascYCvr3RsoRZp3RmZCAKL3Wu+ 4bheNlwWdI4DUANdi7Z/5r9qS4z++XAwqsH245Qh9OlIOPUhH88748lmI1nAv3s36Ewg nJRZCzzUCpUm7T921of3vUbkB+5/1lzQg3QNzDwQnmk3IBMOz0p5+P4TgdLsmwXuWZ4W l7jg== X-Gm-Message-State: ALQs6tC5GC5TALLygoie/aUyy1caQl+Ws6wh7JKXIsN4ihZslOD5mxnk UDYDf2iJbO9jG0f10gQJcrqqAQ== X-Google-Smtp-Source: AB8JxZr6OCaA6allrbEc0ARrbjdgngRuL1dEDnKejEpu8UBKofOCa8nNWD+2mQtwh1CFaWCpy9K+/g== X-Received: by 2002:a6b:c912:: with SMTP id z18-v6mr25216199iof.135.1525369136835; Thu, 03 May 2018 10:38:56 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id e133-v6sm5721434iof.28.2018.05.03.10.38.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 May 2018 10:38:56 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 40EEA8021B7; Thu, 3 May 2018 12:38:55 -0500 (CDT) Date: Thu, 3 May 2018 12:38:55 -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: <20180503173855.GH9585@telsasoft.com> References: <20180503162047.37k7km4dx62i6l4d@alvherre.pgsql> <0d1a3f8a-f6f9-4712-6b6c-174e64a38b48@aklaver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0d1a3f8a-f6f9-4712-6b6c-174e64a38b48@aklaver.com> 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 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 ? Justin