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 1miPXF-0002CY-7r for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Nov 2021 23:19:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1miPXD-0006fl-R4 for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Nov 2021 23:19:11 +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 1miPXD-0006fb-ID for pgsql-hackers@lists.postgresql.org; Wed, 03 Nov 2021 23:19:11 +0000 Received: from mail-io1-xd2a.google.com ([2607:f8b0:4864:20::d2a]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1miPXA-0006PQ-57 for pgsql-hackers@postgresql.org; Wed, 03 Nov 2021 23:19:10 +0000 Received: by mail-io1-xd2a.google.com with SMTP id d70so3892256iof.7 for ; Wed, 03 Nov 2021 16:19:07 -0700 (PDT) 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=32hwS8ABE2/gP96qdvDQ5elEQ4k0vB0sKohIQT9gOmI=; b=W4kV4o/5X+N0+b9FOWc2F99T6KRg0VVl583TKuV57OLGPsphLKggYm5EJYzrjCkN4S MM4S9uUnHlTLWxiSe5Ge9kJrCdkOlVFUaVqyl++NFGszsyl+HiGbXnK3Yo4stgC1hOXw cdAxkVrv4rxj/BKl+C1qWo9f0/xD4nzJKbgj1n1XBbVMf53K6bikBKJ2p6jkh5fx9IgM KDEMxkcymcEGEXth9UoRmuu/+fyHBwcgI/3aGehjdDkC1Urb+uxQlUlsQGp1QXna2F/E QZqdO16tNySp7EQIbRRqsavTZWEKh7HpVqV3UQw6aSuWrVo4Dc2koco9oYFivHTB7kf7 rQ2g== 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=32hwS8ABE2/gP96qdvDQ5elEQ4k0vB0sKohIQT9gOmI=; b=cPtsmbp4YhJXMPm4RD1nUmWbWIXvw7zXmK3zsJIUzi7mv992umTH7mi8Mx7qazByNU ICpChrAroY1QXv3S2YjrA/rW81LYjjr7qYmImnxmepcWlZqvYQhAQlKxnG/wN51WRk3u 66OLe2TH7aM8me6NXT+Cpam+dy7OUATBmvPgWHKIgmw64rD2y7klZovw5bl20Y1g49Nm pcDKrhRP6ESa/VK6NIwKgJ2ccaDncql/LdQUIwErM0PiY4aMdryALnpg9TOdSjn8TjAU MYyIKocCnjj679xxTClqofE/NsikQie6pg7Sc+DBj1VHhjIfqpmIKZtWJGwkX+mB5NZo Jb/A== X-Gm-Message-State: AOAM5300qx/7VhoISF903TdPPmiN28Q3QW4zBTtaf5aS6lLZ1NCqD7Uh tnkEfbOGFKogwWeVLngtRrHQ1A== X-Google-Smtp-Source: ABdhPJyGc2gFANcpLxE55fECYjo2rZLurI6iu17oigs1MGraHLwFVyehyUqb16eV7NpZ4WFkR+ehMg== X-Received: by 2002:a02:c9c1:: with SMTP id c1mr1109822jap.0.1635981546245; Wed, 03 Nov 2021 16:19:06 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id j8sm2146267ils.62.2021.11.03.16.19.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Nov 2021 16:19:05 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id A6303800E15; Wed, 3 Nov 2021 18:19:04 -0500 (CDT) Date: Wed, 3 Nov 2021 18:19:04 -0500 From: Justin Pryzby To: Tomas Vondra Cc: Jaime Casanova , pgsql-hackers@postgresql.org Subject: Re: extended stats on partitioned tables Message-ID: <20211103231904.GP17618@telsasoft.com> References: <20210923212624.GI831@telsasoft.com> <20210925223152.GA7877@telsasoft.com> <20210926202550.GA831@telsasoft.com> <20211007202646.GA9522@ahch-to> <20211007224543.GH27491@telsasoft.com> <46f37069-55cb-db6a-a15a-e351a2606592@enterprisedb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <46f37069-55cb-db6a-a15a-e351a2606592@enterprisedb.com> 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 Wed, Nov 03, 2021 at 11:48:44PM +0100, Tomas Vondra wrote: > 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. I probably did this to make the code change small, to avoid indentin the whole block. > > 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. This was to leave your 0003 (mostly) unchanged, so you can see and/or apply my changes. They should be squished together. > 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. There's also this: On Sun, Sep 26, 2021 at 03:25:50PM -0500, Justin Pryzby wrote: > + /* create only the "stxdinherit=false", because that always exists */ > + datavalues[Anum_pg_statistic_ext_data_stxdinherit - 1] = ObjectIdGetDatum(false); > > That'd be confusing for partitioned tables, no? > They'd always have an row with no data. > I guess it could be stxdinherit = BoolGetDatum(rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE). > (not ObjectIdGetDatum). > Then, that affects the loops which delete the tuples - neither inh nor !inh is > guaranteed, unless you check relkind there, too. Maybe the for inh<=1 loop should instead be two calls to new functions factored out of get_relation_statistics() and RemoveStatisticsById(), which take "bool inh". > And I'm not sure we do the right thing after removing children, for example > (that should drop the inheritance stats, I guess). Do you mean for inheritance only ? Or partitions too ? I think for partitions, the stats should stay. And for inheritence, they can stay, for consistency with partitions, and since it does no harm.