Re: pg15 inherited stats expressions: cache lookup failed for statistics object - Mailing list pgsql-hackers

From Richard Guo
Subject Re: pg15 inherited stats expressions: cache lookup failed for statistics object
Date
Msg-id CAMbWs4-2Lp89W5X0XtV=XwpZgpozmabgWLun_U7UsuqdHW8g_A@mail.gmail.com
Whole thread Raw
In response to pg15 inherited stats expressions: cache lookup failed for statistics object  (Justin Pryzby <pryzby@telsasoft.com>)
Responses Re: pg15 inherited stats expressions: cache lookup failed for statistics object  (Richard Guo <guofenglinux@gmail.com>)
List pgsql-hackers

On Mon, Oct 31, 2022 at 1:05 AM Justin Pryzby <pryzby@telsasoft.com> wrote:
I think this is what's needed.

diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 14e0885f19f..4450f0d682f 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -5240,6 +5240,8 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
                        /* skip stats without per-expression stats */
                        if (info->kind != STATS_EXT_EXPRESSIONS)
                                continue;
+                       if (info->inherit != rte->inh)
+                               continue;

                        pos = 0;
                        foreach(expr_item, info->exprs)
 
I think we also need to do this when loading the ndistinct value, to
skip statistics with mismatching stxdinherit in
estimate_multivariate_ndistinct().

Thanks
Richard

pgsql-hackers by date:

Previous
From: David Rowley
Date:
Subject: Prefetch the next tuple's memory during seqscans
Next
From: Michael Paquier
Date:
Subject: Re: GUC values - recommended way to declare the C variables?