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

Attachment: signature.asc
Description: PGP signature

Reply via email to