Re: Defects with invalid stats data for expressions in extended stats
Michael Paquier <michael@paquier.xyz>
From: Michael Paquier <michael@paquier.xyz>
To: Chao Li <li.evan.chao@gmail.com>
Cc: Corey Huinker <corey.huinker@gmail.com>, Postgres hackers <pgsql-hackers@lists.postgresql.org>, Tomas Vondra <tomas@vondra.me>
Date: 2026-03-02T00:20:37Z
Lists: pgsql-hackers
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
Commits
-
test_custom_types: Test module with fancy custom data types
- 858c83b3e666 14.23 landed
- 8eedbc2cc4b3 15.18 landed
- c0676c8294f7 16.14 landed
- d4f33d026a6b 17.10 landed
- 017e4e395d0d 18.4 landed
- 2176520089e8 19 (unreleased) landed
-
Fix set of issues with extended statistics on expressions
- 038c7d4a3b24 14.23 landed
- f033abc6c4f2 15.18 landed
- 04745ba9c72e 16.14 landed
- 530b6b02f891 17.10 landed
- 83671c0da049 18.4 landed
- 3b7a6fa15720 19 (unreleased) landed