Re: pg15 inherited stats expressions: cache lookup failed for statistics object

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: Justin Pryzby <pryzby(at)telsasoft(dot)com>
Cc: Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: pg15 inherited stats expressions: cache lookup failed for statistics object
Date: 2022-10-31 05:12:09
Message-ID: CAMbWs49E+fkLrz2A2f+PGhsgkuAep6egm+cLth5ULedwwiEUrA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Oct 31, 2022 at 12:26 PM Richard Guo <guofenglinux(at)gmail(dot)com> wrote:

> On Mon, Oct 31, 2022 at 1:05 AM Justin Pryzby <pryzby(at)telsasoft(dot)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().
>

To be concrete, I mean something like attached.

BTW, I noticed a micro-optimization opportunity in examine_variable that
we can fetch the RangeTblEntry for 'onerel' outside the foreach loop
when iterating the extended stats so that we can do it only once rather
than for each stat.

Thanks
Richard

Attachment Content-Type Size
v1-0001-Skip-statistics-with-mismatching-stxdinherit-flag.patch application/octet-stream 1.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kyotaro Horiguchi 2022-10-31 05:32:55 Re: heavily contended lwlocks with long wait queues scale badly
Previous Message Michael Paquier 2022-10-31 05:02:49 Re: GUC values - recommended way to declare the C variables?