summaryrefslogtreecommitdiff
path: root/src/include/nodes
diff options
context:
space:
mode:
authorDavid Rowley2025-03-27 05:23:00 +0000
committerDavid Rowley2025-03-27 05:23:00 +0000
commitf31aad9b07b7a6ef693d7059830bd2f1504976ae (patch)
treed90ded979f91064021c4801a7cb3349cdbf48dbe /src/include/nodes
parent44fe6ceb51f001689048c19ea3ea53fbf2572581 (diff)
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.bykov@modernsys.ru> Author: Michael Paquier <michael@paquier.xyz> Author: David Rowley <dgrowleyml@gmail.com> Discussion: https://postgr.es/m/aafce7966e234372b2ba876c0193f1e9%40localhost.localdomain
Diffstat (limited to 'src/include/nodes')
-rw-r--r--src/include/nodes/queryjumble.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/include/nodes/queryjumble.h b/src/include/nodes/queryjumble.h
index 905f66bc0bd..62794c5a901 100644
--- a/src/include/nodes/queryjumble.h
+++ b/src/include/nodes/queryjumble.h
@@ -54,6 +54,18 @@ typedef struct JumbleState
/* highest Param id we've seen, in order to start normalization correctly */
int highest_extern_param_id;
+
+ /*
+ * Count of the number of NULL nodes seen since last appending a value.
+ * These are flushed out to the jumble buffer before subsequent appends
+ * and before performing the final jumble hash.
+ */
+ unsigned int pending_nulls;
+
+#ifdef USE_ASSERT_CHECKING
+ /* The total number of bytes added to the jumble buffer */
+ Size total_jumble_len;
+#endif
} JumbleState;
/* Values for the compute_query_id GUC */