Re: pg_stat_statements: add missing tests for nesting_level - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: pg_stat_statements: add missing tests for nesting_level
Date
Msg-id aXXJIorDJDdxReF9@paquier.xyz
Whole thread Raw
In response to Re: pg_stat_statements: add missing tests for nesting_level  (Alexander Lakhin <exclusion@gmail.com>)
Responses Re: pg_stat_statements: add missing tests for nesting_level
List pgsql-hackers
On Sun, Jan 25, 2026 at 08:00:00AM +0200, Alexander Lakhin wrote:
> I can reproduce this locally with no extra tricks. Could you please adjust
> the test for this mode?

Reproduced here.  That was trickier than it looks.  A trick with
debug_discard_caches cannot help, because with a CLOBBER_CACHE_ALWAYS
build we would still do a GetCachedPlan() -> RevalidateCachedQuery()
that goes through the post-parse analyze hook where the query would
still be normalized, showing up in the output anyway.

So I have come up with a plan B.  If we do a DISCARD PLANS before the
*first* function call, we can force the test to revalidate the cached
query without caring about CLOBBER_CACHE_ALWAYS, meaning that we would
always store a normalized version of the inner query.  The point of
the test is to check after the nesting level calculation in the
planner hook, and the test is still able to check that correctly.  If
I remove the nesting_level bits from the code while the DISCARD is
around, the entry is stored as a top level entry incorrectly, but it
should be stored as toplevel=false.  I'll go apply the attached
shortly, after some more checks..
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Tender Wang
Date:
Subject: Re: Fix a reference error for window functions: In the function 'find_window_functions', the deduplication logic should be removed
Next
From: Dean Rasheed
Date:
Subject: Re: ABI Compliance Checker GSoC Project