Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jLez7-0001sU-Cl for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Apr 2020 03:33:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jLez6-0005fW-3B for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Apr 2020 03:33:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jLez5-0005eo-PQ for pgsql-hackers@lists.postgresql.org; Tue, 07 Apr 2020 03:33:07 +0000 Received: from mail-qt1-x842.google.com ([2607:f8b0:4864:20::842]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jLeyy-0000LV-P8 for pgsql-hackers@lists.postgresql.org; Tue, 07 Apr 2020 03:33:06 +0000 Received: by mail-qt1-x842.google.com with SMTP id 14so1728989qtp.1 for ; Mon, 06 Apr 2020 20:33:00 -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=Lq7Lz5mEeJsj1Q0ySNGyNHVyZp68RNl2xiVmvijtE84=; b=NQI44yC84VR/H1PCO7rs+kVWmB/65oQ1y+A8RgmYjQufjEW1jM6MVH8wpT5At8L2YD 18qZ2RFywjAHYClpMwoiIRwbCAiXm9HSu6H5ZMyZSsn1ASs3tjKj21qAq7KpW3BwrqZK 4MTiRglszcXUw1aPApIRAptkWgFnUUv8LHsT8etRq5nPs91BoOuFvZjfEOciezQFvTxd KbD4PGES+4OL7eOHhFYDlPSRAifVOSz1kStPqztRlCXSnPJYKSK1zLEu6qvH9303lG3G TNPmg6s3yTj/Ve6jQXMk5zSuYt6eBCWD4aSFfVs1xAiRfq42FUkma7qt7k8Ldwq1BBrV 0AEg== 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=Lq7Lz5mEeJsj1Q0ySNGyNHVyZp68RNl2xiVmvijtE84=; b=uljwpb7Sh3JsMZfqrHrPjdVZZYJ5sP6gZD++Fcl4Brm4I2HQwbph5AbOjMsVEyQ3G0 eHWvlYilTRpdAWtsrPNU3/Bjuy8ai/TifswLtJMukn83MOFyUe4zGOmca02vyv1NIybN 28NvlgzgHwt253si+VPClETDSCBD/16/XyrtwCR/ZmreFZNMwQcweeXoZqm6V7k5tNUa OUiCMIkgkrPmth03CcmVeyFeXPCU9iBOIVifxKHBJ9fHFyT5jV+UErdCd85OabPJg+Yi FoV4/bDyeBQFOpGrEosMr3lhOl1D5snR/KyPuw2nn4g91D/azWpPREzbfbeufR7UI3g7 +ctg== X-Gm-Message-State: AGi0PuZRvf5ufh6TWpdOLhKKfwi1EzhLjWOQuHgMc/htIdRfNbD1lPuB FwdHPrXoZJZF8u6nndOjXpODhA== X-Google-Smtp-Source: APiQypJlX5OkKFWLaLADaTJyZrPMJ+4bdAEh09Dtp1WzcuQBoPxTxZKAhAgon+OwgMsWReAhOWUJNQ== X-Received: by 2002:aed:314c:: with SMTP id 70mr386715qtg.334.1586230378942; Mon, 06 Apr 2020 20:32:58 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id x65sm16152983qkd.78.2020.04.06.20.32.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Apr 2020 20:32:57 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 574958007F7; Mon, 6 Apr 2020 22:32:56 -0500 (CDT) Date: Mon, 6 Apr 2020 22:32:56 -0500 From: Justin Pryzby To: yuzuko Cc: Amit Langote , Alvaro Herrera , Masahiko Sawada , Laurenz Albe , pgsql-hackers@lists.postgresql.org, Greg Stark Subject: Re: Autovacuum on partitioned table (autoanalyze) Message-ID: <20200407033256.GG2228@telsasoft.com> References: <20200228022545.GA19686@alvherre.pgsql> <20200318163039.GL26184@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200318163039.GL26184@telsasoft.com> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Not sure if you saw my earlier message ? I think it ought to be possible to configure this feature such that an auto-analyze on any child partition would trigger analyze of the parent. I think that would be important for maintaining accurate stats of the partition key column for many cases involving RANGE-partitioned tables, which are likely to rely on histogram rather than MCVs. On Wed, Mar 18, 2020 at 11:30:39AM -0500, Justin Pryzby wrote: > Regarding this patch: > > + * the ANALYZE message as it resets the partition's changes_since_analze > => analyze > > + * If the relation is a partitioned table, we must add up children's > childrens' > > The approach in general: > > I see an issue for timeseries data, where only the most recent partition is > being inserted into, and the histogram endpoint is being continuously extended > (this is our use-case). The most recent partition will be analyzed pretty > often, and I think it'll be problematic if its parent doesn't get similar > treatment. Let's say there are 12 historic, monthly children with 1e6 tuples > each, and the 13th child has 2e5 tuples (6 days into the month). It's analyzed > when it grows by 20% (1.2 days), but at that point the parent has only grown by > 12x less (~2%) and won't be analyzed until 12x further into the future (14 > days). Its histogram is 12x longer (geometrically), but the histogram changed > by just as much (arithmetically). That's an issue for a query over "the last > few days"; if that's past the end of the histogram bound, the query planner > will estimate about ~0 tuples, and tend to give cascades of nested loops. I'm > biased, but I'm guessing that's too common a use case to answer that the proper > fix is to set the parent's analyze_scale_factor=0.0005. I think that suggests > that the parent might sometimes need to be analyzed every time any of its > children are. In other cases (like probably any hash partitioning), that'd be > excessive, and maybe the default settings shouldn't do that, but I think that > behavior ought to be possible, and I think this patch doesn't allow that. > > In the past, I think there's was talk that maybe someone would invent a clever > way to dynamically combine all the partitions' statistics, so analyzing the > parent wasn't needed. I think that's easy enough for reltuples, MCV, and I > think histogram, but ISTM that ndistinct is simultaneously important to get > right and hard to do so. It depends on whether it's the partition key, which > now can be an arbitrary expression. Extended stats further complicates it, > even if we didn't aim to dynamically compute extended stats for a parent. > > While writing this, it occured to me that we could use "CREATE STATISTICS" as a > way to mark a partitioned table (or certain columns) as needing to be handled > by analyze. I understand "CREATE STATs" was intended to (eventually) allow > implementing stats on expressions without using "create index" as a hack. So > if it's excessive to automatically analyze a parent table when any of its > children are analyzed, maybe it's less excessive to only do that for parents > with a stats object, and only on the given colums. I realize this patch is > alot less useful if it requires to do anything extra/nondefault, and it's > desirable to work without creating a stats object at all. Also, using CREATE > STATs would reduces the CPU cost of re-analyzing the entire heirarchy, but > doesn't help to reduce the I/O cost, which is significant. > > -- > Justin -- Justin Pryzby System Administrator Telsasoft +1-952-707-8581