From 9ba37b2cb6a174b37fc51d0649ef73e56eae27fc Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Tue, 7 Feb 2023 09:03:54 +0900 Subject: Include values of A_Const nodes in query jumbling Like the implementation for node copy, write and read, this node requires a custom implementation so as the query jumbling is able to consider the correct value assigned to it, depending on its type (int, float, bool, string, bitstring). Based on a dump of pg_stat_statements from the regression database, this would confuse the query jumbling of the following queries: - SET. - COPY TO with SELECT queries. - START TRANSACTION with different isolation levels. - ALTER TABLE with default expressions. - CREATE TABLE with partition bounds. Note that there may be a long-term argument in tracking the location of such nodes so as query strings holding such nodes could be normalized, but this is left as a separate discussion. Oversight in 3db72eb. Discussion: https://postgr.es/m/Y9+HuYslMAP6yyPb@paquier.xyz --- src/backend/nodes/queryjumblefuncs.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/backend') diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c index 223d1bc8262..d7fd72d70f2 100644 --- a/src/backend/nodes/queryjumblefuncs.c +++ b/src/backend/nodes/queryjumblefuncs.c @@ -49,6 +49,7 @@ static void AppendJumble(JumbleState *jstate, const unsigned char *item, Size size); 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 _jumbleRangeTblEntry(JumbleState *jstate, Node *node); @@ -313,6 +314,40 @@ _jumbleList(JumbleState *jstate, Node *node) } } +static void +_jumbleA_Const(JumbleState *jstate, Node *node) +{ + A_Const *expr = (A_Const *) node; + + JUMBLE_FIELD(isnull); + if (!expr->isnull) + { + JUMBLE_FIELD(val.node.type); + switch (nodeTag(&expr->val)) + { + case T_Integer: + JUMBLE_FIELD(val.ival.ival); + break; + case T_Float: + JUMBLE_STRING(val.fval.fval); + break; + case T_Boolean: + JUMBLE_FIELD(val.boolval.boolval); + break; + case T_String: + JUMBLE_STRING(val.sval.sval); + break; + case T_BitString: + JUMBLE_STRING(val.bsval.bsval); + break; + default: + elog(ERROR, "unrecognized node type: %d", + (int) nodeTag(&expr->val)); + break; + } + } +} + static void _jumbleRangeTblEntry(JumbleState *jstate, Node *node) { -- cgit v1.2.3