On Mon, 8 Dec 2025 at 12:10, David G. Johnston
<david.g.johnston@gmail.com> wrote:
>
> On Sun, Dec 7, 2025 at 3:09 PM David Rowley <dgrowleyml@gmail.com> wrote:
>>
>> The comment is effectively
>> explaining that we don't want to make the array big enough so that a
>> malloc will always be required.
>
>
> Doesn't what you are saying contradict both the formula (the +1 post-division) and the comments:
>
> /*
> * Initial size of array must be more than ALLOCSET_SEPARATE_THRESHOLD;
> * see comments in grow_memtuples().
> */
Looks like I put too much faith into what the comment was telling me.
I now agree that the comment is describing the opposite of what the
code is doing. The comment seems to have first appeared in the patch
submitted in [1], and per the "Not sure myself, let's ask the other
Alexander." in [2], indicates that Alexander Kuzmenkov
reverse-engineered the comment from his incorrect understanding of the
code.
With that, I think the v2 patch is almost ok. One small quibble I have is:
+ * in grow_memtuples(). However, we don't consider array sizes
+ * less than 1024.
Using "However" here indicates some exception to what's just been
said, but there is no longer an exception. To write about what the
1024 is for, we might need to reverse engineer what that's for. I
assume it's something like "Clamp at 1024 elements to avoid excessive
reallocs of the array". Or perhaps that without the " of the array"
part.
David
[1] https://www.postgresql.org/message-id/CAPpHfdtKHETXhf062CPvkjpG1wnjQ7rv4uLhZgYQ6VZjwqDYpg%40mail.gmail.com
[2] https://www.postgresql.org/message-id/b45ff523-780b-502b-8d03-2763182aa3c6%40postgrespro.ru