On Mon, Mar 02, 2026 at 07:39:45AM +0800, Chao Li wrote: > 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.
Not necessarity. We have plenty of these patterns in the code with such partial frees. At the end, two things tend to take priority: the readability of the code as well as its efficiency because repeated pfree() calls can be more expensive than a memory context cleanup, particularly in hot loops, though doing pfree() calls may be better in some cases. In this case, I see a better argument with the code clarity, as we use the same array for the stats built with attributes and expressions. We also cap the number of expressions to 8, which puts some control. But at the end it does not really matter: in this context ANALYZE makes sure that nothing crosses the processing of a single relation, even with a transaction analyzes a lot of relations (same or different). -- Michael
signature.asc
Description: PGP signature
