aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/ruleutils.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2023-05-17 10:19:17 +0900
committerMichael Paquier <michael@paquier.xyz>2023-05-17 10:19:17 +0900
commitd8c3106bb60e4f87be595f241e173ba3c2b7aa2c (patch)
tree48ebeb093661e58b99c7d5645b40e4a5336524ab /src/backend/utils/adt/ruleutils.c
parent1d369c9e90f311ec98b07a259cac48c404c773d5 (diff)
downloadpostgresql-d8c3106bb60e4f87be595f241e173ba3c2b7aa2c.tar.gz
postgresql-d8c3106bb60e4f87be595f241e173ba3c2b7aa2c.zip
Add back SQLValueFunction for SQL keywords
This is equivalent to a revert of f193883 and fb32748, with the addition that the declaration of the SQLValueFunction node needs to gain a couple of node_attr for query jumbling. The performance impact of removing the function call inlining is proving to be too huge for some workloads where these are used. A worst-case test case of involving only simple SELECT queries with a SQL keyword is proving to lead to a reduction of 10% in TPS via pgbench and prepared queries on a high-end machine. None of the tests I ran back for this set of changes saw such a huge gap, but Alexander Lakhin and Andres Freund have found that this can be noticeable. Keeping the older performance would mean to do more inlining in the executor when using COERCE_SQL_SYNTAX for a function expression, similarly to what SQLValueFunction does. This requires more redesign work and there is little time until 16beta1 is released, so for now reverting the change is the best way forward, bringing back the previous performance. Bump catalog version. Reported-by: Alexander Lakhin Discussion: https://postgr.es/m/b32bed1b-0746-9b20-1472-4bdc9ca66d52@gmail.com
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r--src/backend/utils/adt/ruleutils.c128
1 files changed, 63 insertions, 65 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 60f9d08d5dd..e93d66a7ec5 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -8254,6 +8254,7 @@ isSimpleNode(Node *node, Node *parentNode, int prettyFlags)
case T_RowExpr:
case T_CoalesceExpr:
case T_MinMaxExpr:
+ case T_SQLValueFunction:
case T_XmlExpr:
case T_NextValueExpr:
case T_NullIfExpr:
@@ -9242,6 +9243,67 @@ get_rule_expr(Node *node, deparse_context *context,
}
break;
+ case T_SQLValueFunction:
+ {
+ SQLValueFunction *svf = (SQLValueFunction *) node;
+
+ /*
+ * Note: this code knows that typmod for time, timestamp, and
+ * timestamptz just prints as integer.
+ */
+ switch (svf->op)
+ {
+ case SVFOP_CURRENT_DATE:
+ appendStringInfoString(buf, "CURRENT_DATE");
+ break;
+ case SVFOP_CURRENT_TIME:
+ appendStringInfoString(buf, "CURRENT_TIME");
+ break;
+ case SVFOP_CURRENT_TIME_N:
+ appendStringInfo(buf, "CURRENT_TIME(%d)", svf->typmod);
+ break;
+ case SVFOP_CURRENT_TIMESTAMP:
+ appendStringInfoString(buf, "CURRENT_TIMESTAMP");
+ break;
+ case SVFOP_CURRENT_TIMESTAMP_N:
+ appendStringInfo(buf, "CURRENT_TIMESTAMP(%d)",
+ svf->typmod);
+ break;
+ case SVFOP_LOCALTIME:
+ appendStringInfoString(buf, "LOCALTIME");
+ break;
+ case SVFOP_LOCALTIME_N:
+ appendStringInfo(buf, "LOCALTIME(%d)", svf->typmod);
+ break;
+ case SVFOP_LOCALTIMESTAMP:
+ appendStringInfoString(buf, "LOCALTIMESTAMP");
+ break;
+ case SVFOP_LOCALTIMESTAMP_N:
+ appendStringInfo(buf, "LOCALTIMESTAMP(%d)",
+ svf->typmod);
+ break;
+ case SVFOP_CURRENT_ROLE:
+ appendStringInfoString(buf, "CURRENT_ROLE");
+ break;
+ case SVFOP_CURRENT_USER:
+ appendStringInfoString(buf, "CURRENT_USER");
+ break;
+ case SVFOP_USER:
+ appendStringInfoString(buf, "USER");
+ break;
+ case SVFOP_SESSION_USER:
+ appendStringInfoString(buf, "SESSION_USER");
+ break;
+ case SVFOP_CURRENT_CATALOG:
+ appendStringInfoString(buf, "CURRENT_CATALOG");
+ break;
+ case SVFOP_CURRENT_SCHEMA:
+ appendStringInfoString(buf, "CURRENT_SCHEMA");
+ break;
+ }
+ }
+ break;
+
case T_XmlExpr:
{
XmlExpr *xexpr = (XmlExpr *) node;
@@ -9816,6 +9878,7 @@ looks_like_function(Node *node)
case T_NullIfExpr:
case T_CoalesceExpr:
case T_MinMaxExpr:
+ case T_SQLValueFunction:
case T_XmlExpr:
/* these are all accepted by func_expr_common_subexpr */
return true;
@@ -10218,33 +10281,6 @@ get_windowfunc_expr_helper(WindowFunc *wfunc, deparse_context *context,
}
/*
- * get_func_sql_syntax_time
- *
- * Parse back argument of SQL-syntax function call related to a time or a
- * timestamp. These require a specific handling when their typmod is given
- * by the function caller through their SQL keyword.
- */
-static void
-get_func_sql_syntax_time(List *args, deparse_context *context)
-{
- StringInfo buf = context->buf;
- Const *cons;
-
- if (list_length(args) != 1)
- return;
-
- cons = (Const *) linitial(args);
- Assert(IsA(cons, Const));
-
- if (!cons->constisnull)
- {
- appendStringInfoString(buf, "(");
- get_rule_expr((Node *) cons, context, false);
- appendStringInfoString(buf, ")");
- }
-}
-
-/*
* get_func_sql_syntax - Parse back a SQL-syntax function call
*
* Returns true if we successfully deparsed, false if we did not
@@ -10470,48 +10506,10 @@ get_func_sql_syntax(FuncExpr *expr, deparse_context *context)
appendStringInfoChar(buf, ')');
return true;
- case F_CURRENT_CATALOG:
- appendStringInfoString(buf, "CURRENT_CATALOG");
- return true;
- case F_CURRENT_ROLE:
- appendStringInfoString(buf, "CURRENT_ROLE");
- return true;
- case F_CURRENT_SCHEMA:
- appendStringInfoString(buf, "CURRENT_SCHEMA");
- return true;
- case F_CURRENT_USER:
- appendStringInfoString(buf, "CURRENT_USER");
- return true;
- case F_USER:
- appendStringInfoString(buf, "USER");
- return true;
- case F_SESSION_USER:
- appendStringInfoString(buf, "SESSION_USER");
- return true;
case F_SYSTEM_USER:
appendStringInfoString(buf, "SYSTEM_USER");
return true;
- case F_CURRENT_DATE:
- appendStringInfoString(buf, "CURRENT_DATE");
- return true;
- case F_CURRENT_TIME:
- appendStringInfoString(buf, "CURRENT_TIME");
- get_func_sql_syntax_time(expr->args, context);
- return true;
- case F_CURRENT_TIMESTAMP:
- appendStringInfoString(buf, "CURRENT_TIMESTAMP");
- get_func_sql_syntax_time(expr->args, context);
- return true;
- case F_LOCALTIME:
- appendStringInfoString(buf, "LOCALTIME");
- get_func_sql_syntax_time(expr->args, context);
- return true;
- case F_LOCALTIMESTAMP:
- appendStringInfoString(buf, "LOCALTIMESTAMP");
- get_func_sql_syntax_time(expr->args, context);
- return true;
-
case F_XMLEXISTS:
/* XMLEXISTS ... extra parens because args are c_expr */
appendStringInfoString(buf, "XMLEXISTS((");