I think there are some fields from the RangeTblEntry struct missing in the jumble (function _jumbleRangeTblEntry()). Probably, some of these were really just forgotten, in other cases this might be an intentional decision, but then it might be good to document it. This has come up in thread [0] and there is a patch [1], but I figured I'd start a new thread here to get the attention of those who know more about pg_stat_statements.

I think the following fields are missing.  (See also attached patch.)

- alias

Currently, two queries like

SELECT * FROM t1 AS foo
SELECT * FROM t1 AS bar

are counted together by pg_stat_statements -- that might be ok, but they both get listed under whichever one is run first, so here if you are looking for the "AS bar" query, you won't find it.

- join_using_alias

Similar situation, currently

SELECT * FROM t1 JOIN t2 USING (a, b)
SELECT * FROM t1 JOIN t2 USING (a, b) AS x

are counted together.

- funcordinality

This was probably just forgotten. It should be included because the WITH ORDINALITY clause changes the query result.

- lateral

Also probably forgotten. A query specifying LATERAL is clearly different from one without it.

Thoughts?  Anything else missing perhaps?


[0]: https://www.postgresql.org/message-id/flat/4b27fc50-8cd6-46f5-ab20-88dbaadca...@eisentraut.org [1]: https://www.postgresql.org/message-id/attachment/154249/v2-0002-Remove-custom-_jumbleRangeTblEntry.patch
From 8176e6f91abd8809e79e1c8e9335522031da2755 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Fri, 23 Feb 2024 16:10:57 +0100
Subject: [PATCH] Add more RangeTblEntry fields to jumble

---
 src/backend/nodes/queryjumblefuncs.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/backend/nodes/queryjumblefuncs.c 
b/src/backend/nodes/queryjumblefuncs.c
index 82f725baaa5..3b0012a720d 100644
--- a/src/backend/nodes/queryjumblefuncs.c
+++ b/src/backend/nodes/queryjumblefuncs.c
@@ -372,9 +372,11 @@ _jumbleRangeTblEntry(JumbleState *jstate, Node *node)
                        break;
                case RTE_JOIN:
                        JUMBLE_FIELD(jointype);
+                       JUMBLE_NODE(join_using_alias);
                        break;
                case RTE_FUNCTION:
                        JUMBLE_NODE(functions);
+                       JUMBLE_FIELD(funcordinality);
                        break;
                case RTE_TABLEFUNC:
                        JUMBLE_NODE(tablefunc);
@@ -400,4 +402,6 @@ _jumbleRangeTblEntry(JumbleState *jstate, Node *node)
                        elog(ERROR, "unrecognized RTE kind: %d", (int) 
expr->rtekind);
                        break;
        }
+       JUMBLE_NODE(alias);
+       JUMBLE_FIELD(lateral);
 }
-- 
2.43.2

Reply via email to