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 1mws7Q-0003vE-Gv for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Dec 2021 20:40:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mws7P-0004pz-9F for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Dec 2021 20:40:19 +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 1mws7O-0004pq-KO for pgsql-hackers@lists.postgresql.org; Mon, 13 Dec 2021 20:40:18 +0000 Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mws7J-0002aH-Kd for pgsql-hackers@postgresql.org; Mon, 13 Dec 2021 20:40:18 +0000 Received: by mail-ed1-x52e.google.com with SMTP id l25so56581529eda.11 for ; Mon, 13 Dec 2021 12:40:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=j89lUDQ3CRcXJhFVzOKG9Y5q5XNxmDXJ+MA/3vTTS3A=; b=huame+aKxLMlxIazyWedYEPbOvH8yLbdu6p6XfOGRGE8j5FvytKFKkjWaelfNSq8tc hhEE0xBU0UY0xFhXTtq6kqzbMgU57rMGuycqzKPkw2rn/etEXmavOEaS3rKGp4GmGkBu OxaSTqgov8NiX5movvNvUgN9sHPo7CMfPPM0er3Ft+3gau1fQqbccMutvNBqcvmnLzzu jsVZWTuAzrHX3juDAyHiVdGC2YGqsvicun+iuD2uo/LyjPYgZVT8URyzkUTerTeikdpm Ptd4IBMpjsUmnJrwKMgELSbAMLb92cGmRonth8rh0glON7Bzhyv+GXR47baNYj9MLHbT PNHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=j89lUDQ3CRcXJhFVzOKG9Y5q5XNxmDXJ+MA/3vTTS3A=; b=s2s6/XU4z7nQbSeupeeHv7xFijKITcQwsXYX9cwrqd0Pl62x/H9KGZQxQUEE5uaEFF E7d0xZRJUgWXb7anWjjsT7o3Pl4R3mtHNyKcDK3CbOjWCAD9lS7VFhI/5k49mEFJ9kk0 wLCCTKLJUujQumcGuXQqrbgRl/8RF9XD1I24AmUedapq9XkTBtsyBqX25cdOIeHceXly FB9qzW9vAu/oNfXGNDT9QdnYObC9aXr8nZjUuTTpCBQsczcapXlq5MgrN7RdS3aNp72B 3cLKxrNjci7h5TUQ7DqsRcar3uaZQQYaj5GFCOko6Rr7BYtVyrkabiA7HYfVok63hUPq nSYw== X-Gm-Message-State: AOAM533Njte7CBIbuqLt5d2pc4gMQv5kVNZ+2scdX9kmPvIVbgYouRi7 0JYRUDW7SuWddblCXsyQNqGrCrhPxOhmE2M4BDSRxIGbAmwhULpNxk3r55sAhtBWH5XPoBg1/TM mAq6hKzs4aTzgk+UT+XIngvCOErOAUFDqrNMaxMiP13Usw48ezllF+4S0HIc3BxVdALjam8O/6w HTUa7t1wGNbFKdynLeiHE8dyUNrHGAeSYZpyQ9 X-Google-Smtp-Source: ABdhPJxpnCCCcD5DJJiBHsaOrishGx1tZThBGViuSmXghVNoF9q9kXlBvGeEeJooQxy9D78wBrWh8Q== X-Received: by 2002:a50:ce51:: with SMTP id k17mr1525769edj.356.1639428011154; Mon, 13 Dec 2021 12:40:11 -0800 (PST) Received: from [10.137.0.19] (ip-86-49-251-241.net.upcbroadband.cz. [86.49.251.241]) by smtp.gmail.com with ESMTPSA id qb28sm6508663ejc.93.2021.12.13.12.40.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Dec 2021 12:40:10 -0800 (PST) Message-ID: Date: Mon, 13 Dec 2021 21:40:09 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: extended stats on partitioned tables Content-Language: en-US To: Justin Pryzby Cc: Zhihong Yu , Jaime Casanova , pgsql-hackers@postgresql.org 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> <20211213135348.GT17618@telsasoft.com> From: Tomas Vondra In-Reply-To: <20211213135348.GT17618@telsasoft.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 12/13/21 14:53, Justin Pryzby wrote: > 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. > OK. Makes sense. > 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?). > Yeah, that's probably right. But I'm not 100% sure the whole inheritance tree can't be treated as a single relation by some queries ... > 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. > Yeah, we can't really prohibit them in backbranches - that'd mean some CREATE STATISTICS commands suddenly start failing, which would be quite annoying. Not building them for partitioned tables seems like a better option - BuildRelationExtStatistics can check relkind and pick what to ignore. But I'd choose to do that in a separate patch, probably - after all, it shouldn't really change the behavior of any tests/queries, no? This reminds me we need to consider if these patches could cause any issues. The way I see it is this: 1) If the table is a separate relation (not part of an inheritance tree), this should make no difference. -> OK 2) If the table is using "old" inheritance, this reverts back to pre-regression behavior. So people will keep using the old statistics until the ANALYZE, and we need to tell them to ANALYZE or something. 3) If the table is using partitioning, it's guaranteed to be empty and there are no stats at all. Again, we should tell people to run ANALYZE. Of course, we can't be sure query plans will change in the right direction :-( regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company