From 3b60676a079c212a84a4d29fdd18ae02ab1f2b4d Mon Sep 17 00:00:00 2001 From: Ilya Staroverov Date: Mon, 26 Oct 2026 13:06:39 +0300 Subject: [PATCH v1 08/11] Include the fields assigned by FieldStore in query jumbling FieldStore.fieldnums, the fields of a composite column assigned by an INSERT or an UPDATE, has not been part of the query ID since query jumbling was added to pg_stat_statements in 9.2. So queries like UPDATE t SET c.x = 1 and UPDATE t SET c.y = 1 were merged into a single pg_stat_statements entry. Include FieldStore.fieldnums in query jumbling. This changes the query IDs of the queries assigning fields of composite columns, so it is for master only. Author: Ilya Staroverov --- contrib/pg_stat_statements/expected/dml.out | 8 +++++--- src/include/nodes/primnodes.h | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/contrib/pg_stat_statements/expected/dml.out b/contrib/pg_stat_statements/expected/dml.out index b310a97b25..ae33c48e97 100644 --- a/contrib/pg_stat_statements/expected/dml.out +++ b/contrib/pg_stat_statements/expected/dml.out @@ -199,12 +199,14 @@ DROP TYPE pgss_point; SELECT calls, rows, query FROM pg_stat_statements ORDER BY query COLLATE "C"; calls | rows | query -------+------+------------------------------------------------------------ - 2 | 2 | INSERT INTO pgss_fieldstore_tab (c.x) VALUES ($1) + 1 | 1 | INSERT INTO pgss_fieldstore_tab (c.x) VALUES ($1) 1 | 1 | INSERT INTO pgss_fieldstore_tab (c.x, c.y) VALUES ($1, $2) + 1 | 1 | INSERT INTO pgss_fieldstore_tab (c.y) VALUES ($1) 1 | 1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t - 2 | 6 | UPDATE pgss_fieldstore_tab SET c.x = $1 + 1 | 3 | UPDATE pgss_fieldstore_tab SET c.x = $1 1 | 3 | UPDATE pgss_fieldstore_tab SET c.x = $1, c.y = $2 -(5 rows) + 1 | 3 | UPDATE pgss_fieldstore_tab SET c.y = $1 +(7 rows) -- check that [temp] table relation extensions are tracked as writes CREATE TABLE pgss_extend_tab (a int, b text); diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h index 327359e7f7..8d83484ab2 100644 --- a/src/include/nodes/primnodes.h +++ b/src/include/nodes/primnodes.h @@ -1183,7 +1183,7 @@ typedef struct FieldStore Expr *arg; /* input tuple value */ List *newvals; /* new value(s) for field(s) */ /* integer list of field attnums */ - List *fieldnums pg_node_attr(query_jumble_ignore); + List *fieldnums; /* type of result (same as type of arg) */ Oid resulttype pg_node_attr(query_jumble_ignore); /* Like RowExpr, we deliberately omit a typmod and collation here */ -- 2.43.0