1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-06 07:49:08 +03:00

Replace SQLValueFunction by COERCE_SQL_SYNTAX

This switch impacts 9 patterns related to a SQL-mandated special syntax
for function calls:
- LOCALTIME [ ( typmod ) ]
- LOCALTIMESTAMP [ ( typmod ) ]
- CURRENT_TIME [ ( typmod ) ]
- CURRENT_TIMESTAMP [ ( typmod ) ]
- CURRENT_DATE

Five new entries are added to pg_proc to compensate the removal of
SQLValueFunction to provide backward-compatibility and making this
change transparent for the end-user (for example for the attribute
generated when a keyword is specified in a SELECT or in a FROM clause
without an alias, or when specifying something else than an Iconst to
the parser).

The parser included a set of checks coming from the files in charge of
holding the C functions used for the SQLValueFunction calls (as of
transformSQLValueFunction()), which are now moved within each function's
execution path, so this reduces the dependencies between the execution
and the parsing steps.  As of this change, all the SQL keywords use the
same paths for their work, relying only on COERCE_SQL_SYNTAX.  Like
fb32748, no performance difference has been noticed, while the perf
profiles get reduced with ExecEvalSQLValueFunction() gone.

Bump catalog version.

Reviewed-by: Corey Huinker, Ted Yu
Discussion: https://postgr.es/m/YzaG3MoryCguUOym@paquier.xyz
This commit is contained in:
Michael Paquier
2022-11-21 18:31:59 +09:00
parent 240e0dbacd
commit f193883fc9
24 changed files with 231 additions and 390 deletions

View File

@@ -46,27 +46,6 @@
/* common code for timetypmodin and timetztypmodin */
static int32
anytime_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 TIME
*/
if (n != 1)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid type modifier")));
return anytime_typmod_check(istz, tl[0]);
}
/* exported so parse_expr.c can use it */
int32
anytime_typmod_check(bool istz, int32 typmod)
{
if (typmod < 0)
@@ -87,6 +66,26 @@ anytime_typmod_check(bool istz, int32 typmod)
return typmod;
}
static int32
anytime_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 TIME
*/
if (n != 1)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid type modifier")));
return anytime_typmod_check(istz, tl[0]);
}
/* common code for timetypmodout and timetztypmodout */
static char *
anytime_typmodout(bool istz, int32 typmod)
@@ -296,10 +295,10 @@ EncodeSpecialDate(DateADT dt, char *str)
/*
* GetSQLCurrentDate -- implements CURRENT_DATE
* current_date -- implements CURRENT_DATE
*/
DateADT
GetSQLCurrentDate(void)
Datum
current_date(PG_FUNCTION_ARGS)
{
struct pg_tm tm;
@@ -325,46 +324,62 @@ GetSQLCurrentDate(void)
cache_mday = tm.tm_mday;
}
return cache_date;
return DateADTGetDatum(cache_date);
}
/*
* GetSQLCurrentTime -- implements CURRENT_TIME, CURRENT_TIME(n)
* current_time -- implements CURRENT_TIME, CURRENT_TIME(n)
*/
TimeTzADT *
GetSQLCurrentTime(int32 typmod)
Datum
current_time(PG_FUNCTION_ARGS)
{
TimeTzADT *result;
struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
int tz;
int32 typmod = -1;
if (!PG_ARGISNULL(0))
{
typmod = PG_GETARG_INT32(0);
anytime_typmod_check(true, typmod);
}
GetCurrentTimeUsec(tm, &fsec, &tz);
result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
tm2timetz(tm, fsec, tz, result);
AdjustTimeForTypmod(&(result->time), typmod);
return result;
return TimeTzADTPGetDatum(result);
}
/*
* GetSQLLocalTime -- implements LOCALTIME, LOCALTIME(n)
* sql_localtime -- implements LOCALTIME, LOCALTIME(n)
*/
TimeADT
GetSQLLocalTime(int32 typmod)
Datum
sql_localtime(PG_FUNCTION_ARGS)
{
TimeADT result;
struct pg_tm tt,
*tm = &tt;
fsec_t fsec;
int tz;
int32 typmod = -1;
if (!PG_ARGISNULL(0))
{
typmod = PG_GETARG_INT32(0);
anytime_typmod_check(false, typmod);
}
GetCurrentTimeUsec(tm, &fsec, &tz);
tm2time(tm, fsec, &result);
AdjustTimeForTypmod(&result, typmod);
return result;
return TimeADTGetDatum(result);
}