Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jEbak-00076G-95 for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Mar 2020 16:30:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jEbaj-0004os-3J for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Mar 2020 16:30:49 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1jEbai-0004ol-Mw for pgsql-hackers@lists.postgresql.org; Wed, 18 Mar 2020 16:30:48 +0000 Received: from mail-qv1-xf42.google.com ([2607:f8b0:4864:20::f42]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jEbad-0003Hj-G7 for pgsql-hackers@lists.postgresql.org; Wed, 18 Mar 2020 16:30:48 +0000 Received: by mail-qv1-xf42.google.com with SMTP id w5so13195626qvp.11 for ; Wed, 18 Mar 2020 09:30:43 -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=3FJIK67ekuN8YebEosddBOdwkxKE88e5I9B/K7NVEEo=; b=dQPZ1RllZaVKqs14jOzo4pFa+fSRiWvtUfY80tNXj9qqJ1NqhvwXSVLgJH7Tv+c2JD yZOFbZpSSdYbIK/i4UfqdHSP8WrWWhmhDxOlqOVuav3BYQxZS9xFxF0UI3IQ/7NQ+iyJ C1X0EuhFoNV/13FCRTwJVPhrLM177n8Y8AFQnsK5f1qgHiJE0bfBEsFmF+EWqJfiezyW 4K/I5dyQVI3+AiE3NshiAyUkmdTF6ouYNIHKBjPRhzIbld4549c/VhOgOO6GduEllWzP yAAMZujaW7IVLkuChPuoCM2uTs13rT6aaWXY0bKXNAHrdFtiIkB0e10LroNHzeLhEpY9 DAYw== 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=3FJIK67ekuN8YebEosddBOdwkxKE88e5I9B/K7NVEEo=; b=OkHyJ0B/xPadK70hhOCDfwo0ABX+AGlytrP/YcjSeb65Q29vfHYpE3HaPFK5Wr3Nbd d09vIjrhWcqtTBZQRCGgAytzxwifrsvddbm98yEl0T0CIRpbmdqKfArunDNYw+QJI0oQ 6in6TWY/oD69LG2gfDog8pNSrNisHqPr48IdUEsoCv0VIm1ZKPgOzwkhP6LgSDFMw/a6 ht7cTx8neGq/9x41FibMI5v43mQk9vVxQYOceSTu/MmiXOEEyDD3EspQqXM7Ye4F4w3m dTXg8otsNjrEzlq6W/iWMHVPOhDDRlw7zns9T4VwDDGLWVpkDd9fUudKFAMGeQ2BYjol eLZw== X-Gm-Message-State: ANhLgQ3Vzsa0bMY5FyK95D4686p1dRpQyjPUHJDwC0BgeKnFnFhRvD9o XsTsDJUb63FxnliiU2U4NAn5EA== X-Google-Smtp-Source: ADFU+vv5PWFKLwvaZ7OlwQr89jideIioznsTA7lFxYvKZ/o0RYHRjVUTLTK6AEK6ucrLAEKXY84DIw== X-Received: by 2002:ad4:556e:: with SMTP id w14mr5326595qvy.144.1584549041862; Wed, 18 Mar 2020 09:30:41 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id e130sm4451261qkb.72.2020.03.18.09.30.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Mar 2020 09:30:41 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 5DDDF800CF1; Wed, 18 Mar 2020 11:30:39 -0500 (CDT) Date: Wed, 18 Mar 2020 11:30:39 -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: <20200318163039.GL26184@telsasoft.com> References: <20200228022545.GA19686@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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