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 1miP3v-0000qw-Mv for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Nov 2021 22:48:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1miP3t-0002s5-LJ for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Nov 2021 22:48:53 +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 1miP3t-0002pk-3A for pgsql-hackers@lists.postgresql.org; Wed, 03 Nov 2021 22:48:53 +0000 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1miP3o-0006C1-BO for pgsql-hackers@postgresql.org; Wed, 03 Nov 2021 22:48:51 +0000 Received: by mail-ed1-x52f.google.com with SMTP id o8so14696364edc.3 for ; Wed, 03 Nov 2021 15:48:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=f96XQMSj2fWG7GwYWFrqjIUEcbke17do1gi3eHeK9aY=; b=Uj/8oL0B1e8lyKseXc986KsnSE9eoVFVO2lWb0xS3zSeFXJlfg9NVeRVZ4Csbzo7Uy xjsZLu7TIh2BqbpA5wWpllqrMb97tkuH9pxosaSi89NIo9wouVscdUFhH0Yoxol/qKMp nxGafp2QI1GVPrZ9JFUIe6FtdUWqMgB+F8kZ00w7ROVhSPZEQfO5a8M40XVN1kAmQ9uI Ifzv2gnKecnYYrs58N/Pr6ZAm6BG6oNMTYGMICOKY2tj04IMqp3olGNabFH55WjE0xKV f/TdyS84O6QLfYk9dfBoN8DDorKhpL5T0TsePUL7Bsi0O+0OWDCUAI4FBclqYteMqPy0 hbbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=f96XQMSj2fWG7GwYWFrqjIUEcbke17do1gi3eHeK9aY=; b=Q3CEOLMpDMvu60OpDgstHGdsQ9CFpCuTfASW/bvwhw+w9x9wifwWDHoELSj+7kEbzx MpcBps/HzZEEixe56Cg1aPBX7rLrLet6ITPd+fxXjkCfuZvP8H0zrH41bhpGvrQKozDI 4X2ME6eanQnyJIvcXAJy5YXWqWDak6/VqCJlXNpHjqg00xcYbjoNgNsn7/qVnDRe2hPY wViQy9LQ+4RB0//OhtwBilltT/Uw31fEW+9r438DJkCl1Xxrt7Uj2ek1QmIaOhHfzneG FE1f3PQLS3u/4ymxdwLj01Mlm2IMDPa5mqieYjnRt6af/DHUc+9GGLlTF+tEY+va5lWo WDKA== X-Gm-Message-State: AOAM530A/qyD0vlF9HkuiETxoMpabW9SSQW3CZCpOQx4GnFtwKwg47Vd yDSMcDyI2IIA3Dhz9hFlonUtqCyb6lBsEcpUc/AZZaFlUWML0QtrXfJ56wrAeKfFoAUFjwyM7ta n4PbV1tiDHVYaf3PDBk5dmR5Ef9aAi9VitJ5GhP1jkkbPrC72NehMm/xODds4OU35Tp1B+7aAzP SON/SLzZJoI7+Ip5mrRZ/bN8GLNExOtNojhv0wtAOQjBPyWp/B25dv7yLmIAGftI+esOjo9Al6h KqH9Wwkoi8TLphTwWJlM8dSGrUAkMP6SkZP9A== X-Google-Smtp-Source: ABdhPJwx4dBBZTQAlgp9vLOLz49CzYjADak/P1HcgmxEjpWdkrds02o63FcmBOvIjhafBY1L+IxL6Q== X-Received: by 2002:a17:906:ae48:: with SMTP id lf8mr5980368ejb.451.1635979726734; Wed, 03 Nov 2021 15:48:46 -0700 (PDT) Received: from [10.137.0.19] (ip-86-49-251-104.net.upcbroadband.cz. [86.49.251.104]) by smtp.gmail.com with ESMTPSA id sg17sm1899397ejc.72.2021.11.03.15.48.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 Nov 2021 15:48:46 -0700 (PDT) Subject: Re: extended stats on partitioned tables To: Justin Pryzby , Jaime Casanova Cc: pgsql-hackers@postgresql.org References: <20210923212624.GI831@telsasoft.com> <20210925223152.GA7877@telsasoft.com> <20210926202550.GA831@telsasoft.com> <20211007202646.GA9522@ahch-to> <20211007224543.GH27491@telsasoft.com> From: Tomas Vondra Message-ID: <46f37069-55cb-db6a-a15a-e351a2606592@enterprisedb.com> Date: Wed, 3 Nov 2021 23:48:44 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20211007224543.GH27491@telsasoft.com> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US 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 10/8/21 12:45 AM, Justin Pryzby wrote: > On Thu, Oct 07, 2021 at 03:26:46PM -0500, Jaime Casanova wrote: >> On Sun, Sep 26, 2021 at 03:25:50PM -0500, Justin Pryzby wrote: >>> On Sat, Sep 25, 2021 at 05:31:52PM -0500, Justin Pryzby wrote: >>>> It seems like your patch should also check "inh" in examine_variable and >>>> statext_expressions_load. >>> >>> I tried adding that - I mostly kept my patches separate. >>> Hopefully this is more helpful than a complication. >>> I added at: https://commitfest.postgresql.org/35/3332/ >>> >> >> Actually, this is confusing. Which patch is the one we should be >> reviewing? > > It is confusing, but not as much as I first thought. Please check the commit > messages. > > The first two patches are meant to be applied to master *and* backpatched. The > first one intends to fixes the bug that non-inherited stats are being used for > queries of inheritance trees. The 2nd one fixes the regression that stats are > not collected for inheritence trees of partitioned tables (which is the only > type of stats they could ever possibly have). > I think 0001 and 0002 seem mostly fine, but it seems a bit strange to do the (!rte->inh) check in the rel->statlist loops. AFAICS both places could do that right at the beginning, because it does not depend on the statistics object at all, just the RelOptInfo. > And the 3rd+4th patches (Tomas' plus my changes) allow collecting both > inherited and non-inherited stats, only in master, since it requires a catalog > change. It's a bit confusing that patch #4 removes most what I added in > patches 1 and 2. But that's exactly what's needed to collect and apply both > inherited and non-inherited stats: the first two patches avoid applying stats > collected with the wrong inheritence. That's also what's needed for the > patchset to follow the normal "apply to master and backpatch" process, rather > than 2 patches which are backpatched but not applied to master, and one which > is applied to master and not backpatched.. > Yeah. Af first I was a bit confused because after applying 0003 there are both the fixes and the "correct" way, but then I realized 0004 removes the unnecessary bits. The one thing 0003 still needs is to rework the places that need to touch both inh and !inh stats. The patch simply does for (inh = 0; inh <= 1; inh++) { ... } but that feels a bit too hackish. But if we don't know which of the two stats exist, I'm not sure what to do about it. And I'm not sure we do the right thing after removing children, for example (that should drop the inheritance stats, I guess). The 1:2 mapping between pg_statistic_ext and pg_statistic_ext_data is a bit strange, but I can't think of a better way. > @Tomas: I just found commit 427c6b5b9, which is a remarkably similar issue > affecting column stats 15 years ago. > What can I say? The history repeats itself ... regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company