public inbox for [email protected]  
help / color / mirror / Atom feed
From: Chao Li <[email protected]>
To: Michael Paquier <[email protected]>
Cc: Corey Huinker <[email protected]>
Cc: Postgres hackers <[email protected]>
Cc: Tomas Vondra <[email protected]>
Subject: Re: Defects with invalid stats data for expressions in extended stats
Date: Mon, 2 Mar 2026 07:39:45 +0800
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<CADkLM=c_3mPHr0JGP_72csQkpAt-v2fRN830RO8or1_R1qX2Wg@mail.gmail.com>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>



> On Mar 2, 2026, at 07:05, Michael Paquier <[email protected]> wrote:
> 
> On Fri, Feb 27, 2026 at 04:33:24PM +0900, Michael Paquier wrote:
>> On Fri, Feb 27, 2026 at 02:51:40PM +0800, Chao Li wrote:
>>> Here stats itself is destroyed, but memory pointed by
>>> stats[0]~stats[i-1] are not free-ed, those memory are returned from
>>> examine_attribute() by palloc0_object().
>> 
>> I am aware of that.  This is not done on simplicity ground, keeping
>> the cleanup of the memory context to ANALYZE in this case.
> 
> About this one, something worth noting is the beginning of
> do_analyze_rel(), which does the following:
>    /*
>     * Set up a working context so that we can easily free whatever junk gets
>     * created.
>     */
>    anl_context = AllocSetContextCreate(CurrentMemoryContext,
>                                        "Analyze",
>                                        ALLOCSET_DEFAULT_SIZES);
>    caller_context = MemoryContextSwitchTo(anl_context);
> 
> So these extra allocations would just be freed under this memory
> context umbrella once we are done processing a single relation.  This
> works even if we begin to repeat ANALYZE commands that fail to build
> some of the stats in a repeated fashion in a single transaction block.
> Code simplicity and readability is just a better choice for this path.
> --
> Michael

Yeah, memory context is a great mechanism.

But why do we still explicitly free the stats array? My concern is mostly about “partial free”: either free everything, or free nothing and let the memory context clean it up. “Partial free” tends to confuse code readers, and future readers may keep running into the same question.

This feels similar to what we discussed in [1]. If we don’t free the container at all, that’s fine too. But freeing the container while leaving its members behind is also a kind of “partial free”, and it’s hard to reason about.

[1] https://www.postgresql.org/message-id/5DED17B4-D948-4C0B-9DE1-A915D0BFAA54%40gmail.com

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/









view thread (11+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: Defects with invalid stats data for expressions in extended stats
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox