pgsql: Fix query jumbling to account for NULL nodes - Mailing list pgsql-committers

From David Rowley
Subject pgsql: Fix query jumbling to account for NULL nodes
Date
Msg-id E1txfi8-001CxO-1c@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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

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(-)


pgsql-committers by date:

Previous
From: Michael Paquier
Date:
Subject: pgsql: doc: Correct description of values used in FSM for indexes
Next
From: David Rowley
Date:
Subject: pgsql: Optimize Query jumble