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 1mwloE-0000R7-3o for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Dec 2021 13:56:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mwloD-0001kY-1o for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Dec 2021 13:56:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mwlm6-0004h4-DA for pgsql-hackers@lists.postgresql.org; Mon, 13 Dec 2021 13:53:54 +0000 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mwlm2-0004Qz-LQ for pgsql-hackers@postgresql.org; Mon, 13 Dec 2021 13:53:53 +0000 Received: by mail-io1-xd35.google.com with SMTP id 14so18462780ioe.2 for ; Mon, 13 Dec 2021 05:53:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=SvzEuPee/VEXINkwfjiWqsrsGX9Mk0+UyEDyeHae9Co=; b=KRRXmaCpwmT0mAg+gHq0WUsgDmQo8w0iE5Vqbts1936yIN+YWT9KTlROLsDBezFly8 Lc0mNi7M/AKuXmM4aFFlXMAwJ4usomlcmQjK/BB6GknshbEXxZ6VHFYIK6uGdxNFHzvZ vYbALLzGL6/7WFCTSizTY9u0LmcY5MYEUkhnamh+vS3XUg7Mnj6NpLdC3WS3Cv6qOSfB 0QroNmHKM892IBKgyFq18k9LhytUp7hHFUBdoW8EByMXjawVOtqpm1XcKpAWptkfMX4J orxrp856is0rESTmo6RVMyLo0zdQ6w+JuaaUGRhD9BDUEvf/5yobwBYweXQTCAKawS7W Ye/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=SvzEuPee/VEXINkwfjiWqsrsGX9Mk0+UyEDyeHae9Co=; b=SS2WAB51X6MRdbBPJAkyYLBABsq99W3ch5Et4UIt1nH2kBPKBhm5/NLk8n+vHlHFu+ EVh3ZTHXdu6bXcYjjByOoTbg/9dk0n5mmHi8YEyB7F/H7e8jqxdiLmxmvgtCNA2yOGU8 n1mXna8htG/AyR+xU6qLeDPox6ad5/DSC2kQWx6mWhZMzI+qjK69vSID6eLpho5LEbZ1 44hFtfkCG8U6ht0X0F1JCKA+O8nFBqitbftBWhhXkSYPb5/lmzEf3xpuvh+ABaJqITw+ r6ibe3B6UWVWSKOwV4MDyENINVJnE3cyF2u5UCmjJv1HlCr0IKaUZBT9Xtenh4E8veEZ kVuA== X-Gm-Message-State: AOAM533FkoREvwQBeSLv0vrYx5yEAv+pN6Y1d30beyxYtAPIossmOBdf 8RX5ltUWHIHtvqC/PGg6bPwobycDBL+fng== X-Google-Smtp-Source: ABdhPJwoc8uGNSsHbEL8YBHACg40aJ9jqZBv7x6OuQuwapt29JVsHCXa9BFYRjqdLCFroQoPAOIx2w== X-Received: by 2002:a05:6602:27cc:: with SMTP id l12mr34400178ios.59.1639403629785; Mon, 13 Dec 2021 05:53:49 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id o7sm7561696ilt.19.2021.12.13.05.53.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Dec 2021 05:53:49 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 96147800A3B; Mon, 13 Dec 2021 07:53:48 -0600 (CST) Date: Mon, 13 Dec 2021 07:53:48 -0600 From: Justin Pryzby To: Tomas Vondra Cc: Zhihong Yu , Jaime Casanova , pgsql-hackers@postgresql.org Subject: Re: extended stats on partitioned tables Message-ID: <20211213135348.GT17618@telsasoft.com> References: <20211007202646.GA9522@ahch-to> <20211007224543.GH27491@telsasoft.com> <46f37069-55cb-db6a-a15a-e351a2606592@enterprisedb.com> <20211103231904.GP17618@telsasoft.com> <689accb1-76e8-5115-6ed0-336749cdca57@enterprisedb.com> <20211203052411.GU17618@telsasoft.com> <8052505e-2dd2-e8cb-26c9-cbb5dff7d750@enterprisedb.com> <20211212213210.GP17618@telsasoft.com> 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: Archived-At: Precedence: bulk On Sun, Dec 12, 2021 at 11:23:19PM +0100, Tomas Vondra wrote: > On 12/12/21 22:32, Justin Pryzby wrote: > > On Sun, Dec 12, 2021 at 05:17:10AM +0100, Tomas Vondra wrote: > > > The one thing bugging me a bit is that the regression test checks only a > > > GROUP BY query. It'd be nice to add queries testing MCV/dependencies > > > too, but that seems tricky because most queries will use per-partitions > > > stats. > > > > You mean because the quals are pushed down to the scan node. > > > > Does that indicate a deficiency ? > > > > If extended stats are collected for a parent table, selectivity estimates based > > from the parent would be better; but instead we use uncorrected column > > estimates from the child tables. > > > > From what I see, we could come up with a way to avoid the pushdown, involving > > volatile functions/foreign tables/RLS/window functions/SRF/wholerow vars/etc. > > But would it be better if extended stats objects on partitioned tables were to > > collect stats for both parent AND CHILD ? I'm not sure. Maybe that's the > > wrong solution, but maybe we should still document that extended stats on > > (empty) parent tables are often themselves not used/useful for selectivity > > estimates, and the user should instead (or in addition) create stats on child > > tables. > > > > Or, maybe if there's no extended stats on the child tables, stats on the parent > > table should be consulted ? > > Maybe, but that seems like a mostly separate improvement. At this point I'm > interested only in testing the behavior implemented in the current patches. I don't want to change the scope of the patch, or this thread, but my point is that the behaviour already changed once (the original regression) and now we're planning to change it again to fix that, so we ought to decide on the expected behavior before writing tests to verify it. I think it may be impossible to use the "dependencies" statistic with inherited stats. Normally the quals would be pushed down to the child tables. But, if they weren't pushed down, they'd be attached to something other than a scan node on the parent table, so the stats on that table wouldn't apply (right?). Maybe the useless stats types should have been prohibited on partitioned tables since v10. It's too late to change that, but perhaps now they shouldn't even be collected during analyze. The dependencies and MCV paths are never called with rte->inh==true, so maybe we should Assert(!inh), or add a comment to that effect. Or the regression tests should "memorialize" the behavior. I'm still thinking about it. -- Justin