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 1mTWEo-0007jE-HN for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Sep 2021 21:26:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mTWEn-0003NE-Gu for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Sep 2021 21:26:37 +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 1mTWEn-0003N6-20 for pgsql-hackers@lists.postgresql.org; Thu, 23 Sep 2021 21:26:37 +0000 Received: from mail-io1-xd2e.google.com ([2607:f8b0:4864:20::d2e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mTWEe-0001Ul-TJ for pgsql-hackers@postgresql.org; Thu, 23 Sep 2021 21:26:36 +0000 Received: by mail-io1-xd2e.google.com with SMTP id b10so9943717ioq.9 for ; Thu, 23 Sep 2021 14:26:28 -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:mime-version:content-disposition :user-agent; bh=ymf9eB5Jopp8+LeZwTgelb9L4u4vNi0Cbur8sVo+DA0=; b=fAsZQ69yWI1S1+DTGKKICFRGfgp17w14wEhKsjr9CJDgIIauXOxUK9tYLLAsaZs3mP l5ygIHAghfuLVhkLjfZuqB6s8P//sSEr5DH9yg5gvccB8olRNWAAWlFHMr2BSFcXvj2v UHMdSCm8EcquAlMzZaxBApSvc2UaSN3WTYWgLTLJWWbJhC1BPrb76cgKB1CdyQENyRJg vxMom1qVyrrGQRh5bzvC3ntp7hLIwwXcRb7mmSd38cx2+gFebUzgOw6IzI30gGl6u31w 6K40llIZisNqkHH7U88bDedxrugxlZWAJIu7yqDl3Jw0G++SpSnT8SdGLIZjNK8jcCCB Idcw== 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:mime-version :content-disposition:user-agent; bh=ymf9eB5Jopp8+LeZwTgelb9L4u4vNi0Cbur8sVo+DA0=; b=swZnzBUDx8o/2Li5F+NIRyigToEhQah3Iy/lZQnyTKFX17Exk2yHrusETb9jrLu4XJ 9A8euvuB7bunvodv0ffanK+nvZgSZckdJYPaLtZvN3423MDAYf5v5P0mEYIdsNzf1FfG VZ5GH8QukFW5Hhl/8QwdYprowsgHYkfZscTOC8d3HpINlFStpYf/rP0UuwDRbkZh+OfM Mo2T8v0Nyaqh4w65cM+RArEHVxS3K7ZK7gbfIkceyGZxw0WBHCUUix28dsCVPTqzSuae 2JbP6kAiHJCZpmZjQhkScbUZdctEAMWIGdpR5Ezli8oyCKLYkNCN6fknDdSkW7FAGIis 83bw== X-Gm-Message-State: AOAM530JIKIIjh6kwiM4ai1gAAd84s/Ou9oiwVkVDTajh19IRdy9fwav GnuwaIj2Sjairw71lolsrjo4BVvzKXCa5g== X-Google-Smtp-Source: ABdhPJzHQwerP07J/By27DYwRK9BEOJ8ftdvjFDLOfWhcVTlaMLgGIS/oMSJD+AIQLajGmMRPaAPzQ== X-Received: by 2002:a5e:c20c:: with SMTP id v12mr5818187iop.46.1632432386579; Thu, 23 Sep 2021 14:26:26 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id r15sm3003088iln.87.2021.09.23.14.26.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Sep 2021 14:26:26 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 04E95800C5C; Thu, 23 Sep 2021 16:26:24 -0500 (CDT) Date: Thu, 23 Sep 2021 16:26:24 -0500 From: Justin Pryzby To: pgsql-hackers@postgresql.org Cc: Tomas Vondra , David Rowley , Alvaro Herrera Subject: extended stats on partitioned tables Message-ID: <20210923212624.GI831@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 extended stats objects are allowed on partitioned tables since v10. https://www.postgresql.org/message-id/flat/CAKJS1f-BmGo410bh5RSPZUvOO0LhmHL2NYmdrC_Jm8pk_FfyCA%40mail.gmail.com 8c5cdb7f4f6e1d6a6104cb58ce4f23453891651b But since 859b3003de they're not populated - pg_statistic_ext(_data) is empty. This was the consequence of a commit to avoid an error I reported with stats on inheritence parents (not partitioned tables). preceding 859b3003de, stats on the parent table *did* improve the estimate, so this part of the commit message seems to have been wrong? |commit 859b3003de87645b62ee07ef245d6c1f1cd0cedb | Don't build extended statistics on inheritance trees ... | Moreover, the current selectivity estimation code only works with individual | relations, so building statistics on inheritance trees would be pointless | anyway. |CREATE TABLE p (i int, a int, b int) PARTITION BY RANGE (i); |CREATE TABLE pd PARTITION OF p FOR VALUES FROM (1)TO(100); |TRUNCATE p; INSERT INTO p SELECT 1, a/100, a/100 FROM generate_series(1,999)a; |CREATE STATISTICS pp ON (a),(b) FROM p; |VACUUM ANALYZE p; |SELECT * FROM pg_statistic_ext WHERE stxrelid ='p'::regclass; |postgres=# begin; DROP STATISTICS pp; explain analyze SELECT a,b FROM p GROUP BY 1,2; abort; | HashAggregate (cost=20.98..21.98 rows=100 width=8) (actual time=1.088..1.093 rows=10 loops=1) |postgres=# explain analyze SELECT a,b FROM p GROUP BY 1,2; | HashAggregate (cost=20.98..21.09 rows=10 width=8) (actual time=1.082..1.086 rows=10 loops=1) So I think this is a regression, and extended stats should be populated for partitioned tables - I had actually done that for some parent tables and hadn't noticed that the stats objects no longer do anything. That begs the question if the current behavior for inheritence parents is correct.. CREATE TABLE p (i int, a int, b int); CREATE TABLE pd () INHERITS (p); INSERT INTO pd SELECT 1, a/100, a/100 FROM generate_series(1,999)a; CREATE STATISTICS pp ON (a),(b) FROM p; VACUUM ANALYZE p; explain analyze SELECT a,b FROM p GROUP BY 1,2; | HashAggregate (cost=25.99..26.99 rows=100 width=8) (actual time=3.268..3.284 rows=10 loops=1) Since child tables can be queried directly, it's a legitimate question whether we should collect stats for the table heirarchy or (since the catalog only supports one) only the table itself. I'd think that stats for the table hierarchy would be more commonly useful (but we shouldn't change the behavior in existing releases again). Anyway it seems unfortunate that statistic_ext_data still has no stxinherited. Note that for partitioned tables if I enable enable_partitionwise_aggregate, then stats objects on the child tables can be helpful (but that's also confusing to the question at hand).