diff options
author | Michael Paquier <michael@paquier.xyz> | 2024-09-30 14:02:00 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2024-09-30 14:02:00 +0900 |
commit | dc68515968e80d75f8106d0df05da346be537628 (patch) | |
tree | db62ee7af853db2c30ef4cf8aad6bedc6695e9fc /src/backend/nodes/queryjumblefuncs.c | |
parent | 559efce1d684069acf234a5cb032acba84e70938 (diff) | |
download | postgresql-dc68515968e80d75f8106d0df05da346be537628.tar.gz postgresql-dc68515968e80d75f8106d0df05da346be537628.zip |
Show values of SET statements as constants in pg_stat_statements
This is a continuation of work like 11c34b342bd7, done to reduce the
bloat of pg_stat_statements by applying more normalization to query
entries. This commit is able to detect and normalize values in
VariableSetStmt, resulting in:
SET conf_param = $1
Compared to other parse nodes, VariableSetStmt is embedded in much more
places in the parser, impacting many query patterns in
pg_stat_statements. A custom jumble function is used, with an extra
field in the node to decide if arguments should be included in the
jumbling or not, a location field being not enough for this purpose.
This approach allows for a finer tuning.
Clauses relying on one or more keywords are not normalized, for example:
* DEFAULT
* FROM CURRENT
* List of keywords. SET SESSION CHARACTERISTICS AS TRANSACTION,
where it is critical to differentiate different sets of options, is a
good example of why normalization should not happen.
Some queries use VariableSetStmt for some subclauses with SET, that also
have their values normalized:
- ALTER DATABASE
- ALTER ROLE
- ALTER SYSTEM
- CREATE/ALTER FUNCTION
ba90eac7a995 has added test coverage for most of the existing SET
patterns. The expected output of these tests shows the difference this
commit creates. Normalization could be perhaps applied to more portions
of the grammar but what is done here is conservative, and good enough as
a starting point.
Author: Greg Sabino Mullane, Michael Paquier
Discussion: https://postgr.es/m/36e5bffe-e989-194f-85c8-06e7bc88e6f7@amazon.com
Discussion: https://postgr.es/m/B44FA29D-EBD0-4DD9-ABC2-16F1CB087074@amazon.com
Discussion: https://postgr.es/m/CAKAnmmJtJY2jzQN91=2QAD2eAJAA-Per61eyO48-TyxEg-q0Rg@mail.gmail.com
Diffstat (limited to 'src/backend/nodes/queryjumblefuncs.c')
-rw-r--r-- | src/backend/nodes/queryjumblefuncs.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c index 129fb447099..5e43fd92294 100644 --- a/src/backend/nodes/queryjumblefuncs.c +++ b/src/backend/nodes/queryjumblefuncs.c @@ -57,6 +57,7 @@ static void RecordConstLocation(JumbleState *jstate, int location); static void _jumbleNode(JumbleState *jstate, Node *node); static void _jumbleA_Const(JumbleState *jstate, Node *node); static void _jumbleList(JumbleState *jstate, Node *node); +static void _jumbleVariableSetStmt(JumbleState *jstate, Node *node); /* * Given a possibly multi-statement source string, confine our attention to the @@ -352,3 +353,21 @@ _jumbleA_Const(JumbleState *jstate, Node *node) } } } + +static void +_jumbleVariableSetStmt(JumbleState *jstate, Node *node) +{ + VariableSetStmt *expr = (VariableSetStmt *) node; + + JUMBLE_FIELD(kind); + JUMBLE_STRING(name); + + /* + * Account for the list of arguments in query jumbling only if told by the + * parser. + */ + if (expr->jumble_args) + JUMBLE_NODE(args); + JUMBLE_FIELD(is_local); + JUMBLE_LOCATION(location); +} |