Re: extended stats on partitioned tables

Justin Pryzby <pryzby@telsasoft.com>

From: Justin Pryzby <pryzby@telsasoft.com>
To: Tomas Vondra <tomas.vondra@enterprisedb.com>
Cc: Zhihong Yu <zyu@yugabyte.com>, Jaime Casanova <jcasanov@systemguards.com.ec>, pgsql-hackers@postgresql.org
Date: 2021-12-12T17:52:56Z
Lists: pgsql-hackers
+          * XXX Can't we simply look at rte->inh?
+          */
+         inh = root->append_rel_array == NULL ? false :
+                 root->append_rel_array[onerel->relid]->parent_relid != 0;

I think so.  That's what I came up with while trying to figured this out, and
it's no great surprise that it needed to be cleaned up - thanks.

In your 0003 patch, the "if inh: break" isn't removed from examine_variable(),
but the corresponding thing is removed everywhere else.

In 0003, mcv_clauselist_selectivity still uses simple_rte_array rather than
rt_fetch.

The regression tests changed as a result of not populating stx_data; I think
it's may be better to update like this:

SELECT stxname, stxdndistinct, stxddependencies, stxdmcv, stxoid IS NULL
  FROM pg_statistic_ext s LEFT JOIN pg_statistic_ext_data d
  ON d.stxoid = s.oid
  WHERE s.stxname = 'ab1_a_b_stats';

There's this part about documentation for the changes in backbranches:

On Sun, Sep 26, 2021 at 03:25:50PM -0500, Justin Pryzby wrote:
> Also, I think in backbranches we should document what's being stored in
> pg_statistic_ext, since it's pretty unintuitive:
>  - noninherted stats (FROM ONLY) for inheritence parents;
>  - inherted stats (FROM *) for partitioned tables;

spellcheck: inheritence should be inheritance.

All for now.  I'm going to update the regression tests for dependencies and the
other code paths.

-- 
Justin



Commits

  1. Add stxdinherit flag to pg_statistic_ext_data

  2. Build inherited extended stats on partitioned tables

  3. Ignore extended statistics for inheritance trees

  4. Don't build extended statistics on inheritance trees

  5. Tighten up relation kind checks for extended statistics

  6. Avoid assuming that statistics for a parent relation reflect the properties of