RE: Query ID Calculation Fix for DISTINCT / ORDER BY and LIMIT / OFFSET
Ivan Bykov <i.bykov@modernsys.ru>
From: Bykov Ivan <i.bykov@modernsys.ru>
To: Michael Paquier <michael@paquier.xyz>, David Rowley <dgrowleyml@gmail.com>
Cc: Sami Imseih <samimseih@gmail.com>, "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2025-03-10T10:17:45Z
Lists: pgsql-hackers
Attachments
- Query-ID-collision-at_pg_stat_statements-1ea6e890b22.txt (text/plain)
- v2-0001-Query-ID-Calculation-Fix-Variant-A.patch (application/octet-stream) patch v2-0001
Hello!
>> Variant B is not acceptable IMO as it adds a whole bunch of
>> null-terminators unnecessarily. For example, in a simple "select 1",
>> (expr == NULL) is true 19 times, so that is an extra 19 bytes.
> Variant B is not acceptable here.
Could we improve Variant B?
I was thinking about adding a count of NULL pointers encountered by the query
jumble walker since the last scalar or non-null field visited.
This way, we can traverse the query as follows:
====
QueryA->subNodeOne = &(Value X);
/* JumbleState->Count = 0;
QueryA_ID = hash_any_extended(&(Value X), sizeof(Value X), QueryA_ID) */
QueryA->subNodeTwo = NULL;
/* JumbleState->Count = 1; */
QueryA->subNodeThee = NULL;
/* JumbleState->Count = 2; */
QueryA->subNodeFour = NULL;
/* JumbleState->Count = 3; */
QueryA->scalar = Value Z;
/* QueryA_ID = hash_any_extended(&(JumbleState->Count),
sizeof(JumbleState->Count), QueryA_ID)
JumbleState->Count = 0;
QueryA_ID = hash_any_extended(&(Value Y), sizeof(Value Y), QueryA_ID) */
====
Variant A improvement
---------------------
I have attached the updated Variant A patch with the following changes:
- Implemented a pg_stat_statements regression test (see similar test results
on REL_17_3 in Query-ID-collision-at_pg_stat_statements-1ea6e890b22.txt).
- Added extra description about the Query ID collision
in src/include/nodes/parsenodes.h.
Commits
-
Optimize Query jumble
- ad9a23bc4f51 18.0 landed