mirror of
https://github.com/postgres/postgres.git
synced 2025-06-26 12:21:12 +03:00
Add back SQLValueFunction for SQL keywords
This is equivalent to a revert off193883
andfb32748
, 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
This commit is contained in:
@ -83,6 +83,27 @@ static Timestamp timestamptz2timestamp(TimestampTz timestamp);
|
||||
|
||||
/* common code for timestamptypmodin and timestamptztypmodin */
|
||||
static int32
|
||||
anytimestamp_typmodin(bool istz, ArrayType *ta)
|
||||
{
|
||||
int32 *tl;
|
||||
int n;
|
||||
|
||||
tl = ArrayGetIntegerTypmods(ta, &n);
|
||||
|
||||
/*
|
||||
* we're not too tense about good error message here because grammar
|
||||
* shouldn't allow wrong number of modifiers for TIMESTAMP
|
||||
*/
|
||||
if (n != 1)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("invalid type modifier")));
|
||||
|
||||
return anytimestamp_typmod_check(istz, tl[0]);
|
||||
}
|
||||
|
||||
/* exported so parse_expr.c can use it */
|
||||
int32
|
||||
anytimestamp_typmod_check(bool istz, int32 typmod)
|
||||
{
|
||||
if (typmod < 0)
|
||||
@ -103,26 +124,6 @@ anytimestamp_typmod_check(bool istz, int32 typmod)
|
||||
return typmod;
|
||||
}
|
||||
|
||||
static int32
|
||||
anytimestamp_typmodin(bool istz, ArrayType *ta)
|
||||
{
|
||||
int32 *tl;
|
||||
int n;
|
||||
|
||||
tl = ArrayGetIntegerTypmods(ta, &n);
|
||||
|
||||
/*
|
||||
* we're not too tense about good error message here because grammar
|
||||
* shouldn't allow wrong number of modifiers for TIMESTAMP
|
||||
*/
|
||||
if (n != 1)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("invalid type modifier")));
|
||||
|
||||
return anytimestamp_typmod_check(istz, tl[0]);
|
||||
}
|
||||
|
||||
/* common code for timestamptypmodout and timestamptztypmodout */
|
||||
static char *
|
||||
anytimestamp_typmodout(bool istz, int32 typmod)
|
||||
@ -1594,42 +1595,33 @@ GetCurrentTimestamp(void)
|
||||
}
|
||||
|
||||
/*
|
||||
* current_timestamp -- implements CURRENT_TIMESTAMP, CURRENT_TIMESTAMP(n)
|
||||
* GetSQLCurrentTimestamp -- implements CURRENT_TIMESTAMP, CURRENT_TIMESTAMP(n)
|
||||
*/
|
||||
Datum
|
||||
current_timestamp(PG_FUNCTION_ARGS)
|
||||
TimestampTz
|
||||
GetSQLCurrentTimestamp(int32 typmod)
|
||||
{
|
||||
TimestampTz ts;
|
||||
int32 typmod = -1;
|
||||
|
||||
if (!PG_ARGISNULL(0))
|
||||
typmod = anytimestamp_typmod_check(true, PG_GETARG_INT32(0));
|
||||
|
||||
ts = GetCurrentTransactionStartTimestamp();
|
||||
if (typmod >= 0)
|
||||
AdjustTimestampForTypmod(&ts, typmod, NULL);
|
||||
return TimestampTzGetDatum(ts);
|
||||
return ts;
|
||||
}
|
||||
|
||||
/*
|
||||
* sql_localtimestamp -- implements LOCALTIMESTAMP, LOCALTIMESTAMP(n)
|
||||
* GetSQLLocalTimestamp -- implements LOCALTIMESTAMP, LOCALTIMESTAMP(n)
|
||||
*/
|
||||
Datum
|
||||
sql_localtimestamp(PG_FUNCTION_ARGS)
|
||||
Timestamp
|
||||
GetSQLLocalTimestamp(int32 typmod)
|
||||
{
|
||||
Timestamp ts;
|
||||
int32 typmod = -1;
|
||||
|
||||
if (!PG_ARGISNULL(0))
|
||||
typmod = anytimestamp_typmod_check(false, PG_GETARG_INT32(0));
|
||||
|
||||
ts = timestamptz2timestamp(GetCurrentTransactionStartTimestamp());
|
||||
if (typmod >= 0)
|
||||
AdjustTimestampForTypmod(&ts, typmod, NULL);
|
||||
return TimestampGetDatum(ts);
|
||||
return ts;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* timeofday(*) -- returns the current time as a text.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user