public inbox for [email protected]  
help / color / mirror / Atom feed
From: David Rowley <[email protected]>
To: [email protected]
Subject: pgsql: Fix query jumbling to account for NULL nodes
Date: Thu, 27 Mar 2025 05:23:24 +0000
Message-ID: <[email protected]> (raw)

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 <[email protected]>
Author: Michael Paquier <[email protected]>
Author: David Rowley <[email protected]>
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(-)



reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: pgsql: Fix query jumbling to account for NULL nodes
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox