From: | Shaik Mohammad Mujeeb <mujeeb(dot)sk(at)zohocorp(dot)com> |
---|---|
To: | "michael" <michael(at)paquier(dot)xyz> |
Cc: | "ilyaevdokimov" <ilya(dot)evdokimov(at)tantorlabs(dot)com>, "pgsql-hackers" <pgsql-hackers(at)postgresql(dot)org>, "mujeebskdev" <mujeeb(dot)sk(dot)dev(at)gmail(dot)com>, "pgsql-hackers" <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Add comment explaining why queryid is int64 in pg_stat_statements |
Date: | 2025-05-17 18:35:56 |
Message-ID: | 196df8808a5.3d67d83b31489.5800534984824472391@zohocorp.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi Michael Paquier,
> I don't quite see the value in the comment addition you are suggesting
> here: all the user-facing features related to query IDs use signed 64b
> integers, and are documented as such in the official docs. The fact
> that we store an unsigned value in the backend core code is an
> internal implementation artifact, the important point is that we have
> a value stored in 8 bytes.
Originally, queryId used to be of type uint32, which fit into int64 without any overflow. However, after commit cff440d36 (which changed queryId to uint64), overflow started happening when assigning it to an int64. In that commit, queryId was updated to uint64 in most places - except in pg_stat_statements_internal(). Given that this was an intentional choice, I feel a brief comment should have been included in that commit itself to clarify the reasoning.
Although the commit was made back in 2017, this discrepancy still causes confusion. I found myself revisiting and analyzing it simply because there was no explanatory comment. Others might raise the same question again in the future unless this is clarified explicitly.
I also noticed that a similar comment is already present in ExplainPrintPlan():
/*
* Output the queryid as an int64 rather than a uint64 so we match
* what would be seen in the BIGINT pg_stat_statements.queryid column.
*/
Since such a comment exists there, I believe it would be equally reasonable and helpful to include a similar one in pg_stat_statements_internal() as well.
Of course, if this still seems unnecessary, I’m happy to drop the suggestion - just wanted to put it forward in case it helps reduce ambiguity for future readers or contributors.
Thanks and Regards,
Shaik Mohammad Mujeeb
Member Technical Staff
Zoho Corp
---- On Sat, 17 May 2025 18:19:23 +0530 Michael Paquier <michael(at)paquier(dot)xyz> wrote ---
On Fri, May 16, 2025 at 04:05:01PM +0530, Shaik Mohammad Mujeeb wrote:
> This conversion is intentional - most likely to match the bigint
> type of the queryid column in pg_stat_statements. However, without
> an explicit comment, this can be misleading. A beginner reading this
> might misinterpret it as an unintentional overflow or bug and raise
> unnecessary concerns. Therefore, it´s worth adding a brief comment
> clarifying the intent behind this assignment.
I don't quite see the value in the comment addition you are suggesting
here: all the user-facing features related to query IDs use signed 64b
integers, and are documented as such in the official docs. The fact
that we store an unsigned value in the backend core code is an
internal implementation artifact, the important point is that we have
a value stored in 8 bytes.
--
Michael
From | Date | Subject | |
---|---|---|---|
Next Message | Sami Imseih | 2025-05-17 18:39:43 | Re: Possible regression in PG18 beta1 |
Previous Message | Andreas Karlsson | 2025-05-17 18:09:55 | Re: pg_upgrade ability to create extension from scripts |