Fix query jumbling to account for NULL nodes Previously NULL nodes were ignored. This could cause issues where the computed query ID could match for queries where fields that are next to each other in their Node struct where one field was NULL and the other non-NULL. For example, the Query struct had distinctClause and sortClause next to each other. If someone wrote;
SELECT DISTINCT c1 FROM t; and then; SELECT c1 FROM t ORDER BY c1; these would produce the same query ID since, in the first query, we ignored the NULL sortClause and appended the jumble bytes for the distictClause. In the latter query, since we did nothing for the NULL distinctClause then jumble the non-NULL sortClause, and since the node representation stored is the same in both cases, the query IDs were identical. Here we fix this by always accounting for NULL nodes by recording that we saw a NULL in the jumble buffer. This fixes the issue as the order that the NULL is recorded isn't the same in the above two queries. Author: Bykov Ivan <i.by...@modernsys.ru> Author: Michael Paquier <mich...@paquier.xyz> Author: David Rowley <dgrowle...@gmail.com> Discussion: https://postgr.es/m/aafce7966e234372b2ba876c0193f1e9%40localhost.localdomain Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/f31aad9b07b7a6ef693d7059830bd2f1504976ae Modified Files -------------- contrib/pg_stat_statements/expected/select.out | 87 ++++++++++++++- contrib/pg_stat_statements/sql/select.sql | 20 ++++ src/backend/nodes/queryjumblefuncs.c | 140 +++++++++++++++++++++---- src/include/nodes/queryjumble.h | 12 +++ 4 files changed, 238 insertions(+), 21 deletions(-)