Skip to content

Commit

Permalink
Use function oids instead of names when transforming the sort keys
Browse files Browse the repository at this point in the history
This is more explicit, and looking up the function name each time has a
performance impact.
  • Loading branch information
akuzm committed Dec 13, 2021
1 parent 519e5de commit babcc8e
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/sort_transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
#include <nodes/makefuncs.h>
#include <nodes/nodeFuncs.h>
#include <nodes/plannodes.h>
#include <optimizer/paths.h>
#include <optimizer/planner.h>
#include <parser/parsetree.h>
#include <utils/fmgroids.h>
#include <utils/guc.h>
#include <optimizer/planner.h>
#include <optimizer/paths.h>
#include <utils/lsyscache.h>

#include "compat/compat.h"
#include "func_cache.h"
#include "sort_transform.h"

Expand Down Expand Up @@ -195,7 +197,6 @@ ts_sort_transform_expr(Expr *orig_expr)
if (IsA(orig_expr, FuncExpr))
{
FuncExpr *func = (FuncExpr *) orig_expr;
char *func_name = get_func_name(func->funcid);
FuncInfo *finfo = ts_func_cache_get_bucketing_func(func->funcid);

if (NULL != finfo)
Expand All @@ -206,10 +207,24 @@ ts_sort_transform_expr(Expr *orig_expr)
return finfo->sort_transform(func);
}

if (strncmp(func_name, "timestamp", NAMEDATALEN) == 0)
/* Functions of one argument that convert something to timestamp(tz). */
#if PG14_LT
if (func->funcid == F_DATE_TIMESTAMP || func->funcid == F_TIMESTAMPTZ_TIMESTAMP)
#else
if (func->funcid == F_TIMESTAMP_DATE || func->funcid == F_TIMESTAMP_TIMESTAMPTZ)
#endif
{
return transform_timestamp_cast(func);
if (strncmp(func_name, "timestamptz", NAMEDATALEN) == 0)
}

#if PG14_LT
if (func->funcid == F_DATE_TIMESTAMPTZ || func->funcid == F_TIMESTAMP_TIMESTAMPTZ)
#else
if (func->funcid == F_TIMESTAMPTZ_DATE || func->funcid == F_TIMESTAMPTZ_TIMESTAMP)
#endif
{
return transform_timestamptz_cast(func);
}
}
if (IsA(orig_expr, OpExpr))
{
Expand Down

0 comments on commit babcc8e

Please sign in to comment.