aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorÁlvaro Herrera <alvherre@kurilemu.de>2025-06-24 19:36:12 +0200
committerÁlvaro Herrera <alvherre@kurilemu.de>2025-06-24 19:36:12 +0200
commitdebad29d22152d7fe4c4e671090e20238647c460 (patch)
treef420a350cfd116a4ea6faf9791d20c8ad21e4e6d /src
parent303ba0573ce656b98620133cd17418dcd217318f (diff)
downloadpostgresql-debad29d22152d7fe4c4e671090e20238647c460.tar.gz
postgresql-debad29d22152d7fe4c4e671090e20238647c460.zip
Improve jumble squashing through CoerceViaIO and RelabelType
There's no principled reason for query jumbling to only remove the first layer of RelabelType and CoerceViaIO. Change it to see through as many layers as there are.
Diffstat (limited to 'src')
-rw-r--r--src/backend/nodes/queryjumblefuncs.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c
index fb33e6931ad..62e3a677cd1 100644
--- a/src/backend/nodes/queryjumblefuncs.c
+++ b/src/backend/nodes/queryjumblefuncs.c
@@ -414,7 +414,7 @@ RecordConstLocation(JumbleState *jstate, int location, int len)
* Subroutine for _jumbleElements: Verify a few simple cases where we can
* deduce that the expression is a constant:
*
- * - Ignore a possible wrapping RelabelType and CoerceViaIO.
+ * - See through any wrapping RelabelType and CoerceViaIO layers.
* - If it's a FuncExpr, check that the function is a builtin
* cast and its arguments are Const.
* - Otherwise test if the expression is a simple Const.
@@ -422,14 +422,22 @@ RecordConstLocation(JumbleState *jstate, int location, int len)
static bool
IsSquashableConstant(Node *element)
{
- if (IsA(element, RelabelType))
- element = (Node *) ((RelabelType *) element)->arg;
-
- if (IsA(element, CoerceViaIO))
- element = (Node *) ((CoerceViaIO *) element)->arg;
-
+restart:
switch (nodeTag(element))
{
+ case T_RelabelType:
+ /* Unwrap RelabelType */
+ element = (Node *) ((RelabelType *) element)->arg;
+ goto restart;
+
+ case T_CoerceViaIO:
+ /* Unwrap CoerceViaIO */
+ element = (Node *) ((CoerceViaIO *) element)->arg;
+ goto restart;
+
+ case T_Const:
+ return true;
+
case T_FuncExpr:
{
FuncExpr *func = (FuncExpr *) element;
@@ -468,11 +476,8 @@ IsSquashableConstant(Node *element)
}
default:
- if (!IsA(element, Const))
- return false;
+ return false;
}
-
- return true;
}
/*