[Tarantool-patches] [PATCH v2 5/5] sql: remove unused code
imeevma at tarantool.org
imeevma at tarantool.org
Thu Aug 19 08:31:33 MSK 2021
This patch removes code that become unused due to changes in SQL
built-in functions.
Part of #6105
---
src/box/box.cc | 1 -
src/box/sql.c | 1 -
src/box/sql.h | 9 -
src/box/sql/func.c | 837 ------------------------------------------
src/box/sql/sqlInt.h | 42 ---
src/box/sql/vdbe.h | 7 -
src/box/sql/vdbeInt.h | 2 -
src/box/sql/vdbeaux.c | 6 -
8 files changed, 905 deletions(-)
diff --git a/src/box/box.cc b/src/box/box.cc
index 0b12b1328..ce44df85b 100644
--- a/src/box/box.cc
+++ b/src/box/box.cc
@@ -3056,7 +3056,6 @@ box_free(void)
gc_free();
engine_shutdown();
wal_free();
- sql_built_in_functions_cache_free();
}
}
diff --git a/src/box/sql.c b/src/box/sql.c
index d15159d6e..7cadb8db5 100644
--- a/src/box/sql.c
+++ b/src/box/sql.c
@@ -75,7 +75,6 @@ sql_init(void)
panic("failed to initialize SQL subsystem");
sql_stmt_cache_init();
- sql_built_in_functions_cache_init();
assert(db != NULL);
}
diff --git a/src/box/sql.h b/src/box/sql.h
index 3ff00e64a..40fef2903 100644
--- a/src/box/sql.h
+++ b/src/box/sql.h
@@ -56,15 +56,6 @@ sql_init(void);
struct sql *
sql_get(void);
-/** Initialize global cache for built-in functions. */
-void
-sql_built_in_functions_cache_init(void);
-
-/** Free global cache for built-in functions. */
-void
-sql_built_in_functions_cache_free(void);
-
-
struct Expr;
struct Parse;
struct Select;
diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index e09224bb8..dd2122436 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -50,8 +50,6 @@
#include "box/user.h"
#include "assoc.h"
-static struct mh_strnptr_t *built_in_functions = NULL;
-
static const unsigned char *
mem_as_ustr(struct Mem *mem)
{
@@ -1913,16 +1911,6 @@ sql_is_like_func(struct Expr *expr)
return 1;
}
-static int
-func_sql_builtin_call_stub(struct func *func, struct port *args,
- struct port *ret)
-{
- (void) func; (void) args; (void) ret;
- diag_set(ClientError, ER_UNSUPPORTED,
- "sql builtin function", "Lua frontend");
- return -1;
-}
-
static void
sql_builtin_stub(sql_context *ctx, int argc, sql_value **argv)
{
@@ -1931,831 +1919,6 @@ sql_builtin_stub(sql_context *ctx, int argc, sql_value **argv)
ctx->is_aborted = true;
}
-/**
- * A sequence of SQL builtins definitions in
- * lexicographic order.
- */
-static struct {
- /**
- * Name is used to find corresponding entry in array
- * sql_builtins applying binary search.
- */
- const char *name;
- /** Members below are related to struct func_sql_builtin. */
- uint16_t flags;
- void (*call)(sql_context *ctx, int argc, sql_value **argv);
- void (*finalize)(sql_context *ctx);
- /** Members below are related to struct func_def. */
- bool is_deterministic;
- int param_count;
- enum field_type returns;
- enum func_aggregate aggregate;
- bool export_to_sql;
-} sql_builtins[] = {
- {.name = "ABS",
- .param_count = 1,
- .returns = FIELD_TYPE_NUMBER,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = 0,
- .call = absFunc,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "AVG",
- .param_count = 1,
- .returns = FIELD_TYPE_NUMBER,
- .is_deterministic = false,
- .aggregate = FUNC_AGGREGATE_GROUP,
- .flags = 0,
- .call = sum_step,
- .finalize = avgFinalize,
- .export_to_sql = true,
- }, {
- .name = "CEIL",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "CEILING",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "CHAR",
- .param_count = -1,
- .returns = FIELD_TYPE_STRING,
- .is_deterministic = true,
- .aggregate = FUNC_AGGREGATE_NONE,
- .flags = 0,
- .call = charFunc,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "CHARACTER_LENGTH",
- .param_count = 1,
- .returns = FIELD_TYPE_INTEGER,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = 0,
- .call = lengthFunc,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "CHAR_LENGTH",
- .param_count = 1,
- .returns = FIELD_TYPE_INTEGER,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = 0,
- .call = lengthFunc,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "COALESCE",
- .param_count = -1,
- .returns = FIELD_TYPE_SCALAR,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = SQL_FUNC_COALESCE,
- .call = sql_builtin_stub,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "COUNT",
- .param_count = -1,
- .returns = FIELD_TYPE_INTEGER,
- .aggregate = FUNC_AGGREGATE_GROUP,
- .is_deterministic = false,
- .flags = 0,
- .call = countStep,
- .finalize = countFinalize,
- .export_to_sql = true,
- }, {
- .name = "CURRENT_DATE",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "CURRENT_TIME",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "CURRENT_TIMESTAMP",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "DATE",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "DATETIME",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "EVERY",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "EXISTS",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "EXP",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "EXTRACT",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "FLOOR",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "GREATER",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "GREATEST",
- .param_count = -1,
- .returns = FIELD_TYPE_SCALAR,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = SQL_FUNC_NEEDCOLL | SQL_FUNC_MAX,
- .call = minmaxFunc,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "GROUP_CONCAT",
- .param_count = -1,
- .returns = FIELD_TYPE_STRING,
- .aggregate = FUNC_AGGREGATE_GROUP,
- .is_deterministic = false,
- .flags = 0,
- .call = groupConcatStep,
- .finalize = groupConcatFinalize,
- .export_to_sql = true,
- }, {
- .name = "HEX",
- .param_count = 1,
- .returns = FIELD_TYPE_STRING,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = 0,
- .call = hexFunc,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "IFNULL",
- .param_count = 2,
- .returns = FIELD_TYPE_SCALAR,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = SQL_FUNC_COALESCE,
- .call = sql_builtin_stub,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "JULIANDAY",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "LEAST",
- .param_count = -1,
- .returns = FIELD_TYPE_SCALAR,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = SQL_FUNC_NEEDCOLL | SQL_FUNC_MIN,
- .call = minmaxFunc,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "LENGTH",
- .param_count = 1,
- .returns = FIELD_TYPE_INTEGER,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = SQL_FUNC_LENGTH,
- .call = lengthFunc,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "LESSER",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "LIKE",
- .param_count = -1,
- .returns = FIELD_TYPE_INTEGER,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = SQL_FUNC_NEEDCOLL | SQL_FUNC_LIKE,
- .call = likeFunc,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "LIKELIHOOD",
- .param_count = 2,
- .returns = FIELD_TYPE_BOOLEAN,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = SQL_FUNC_UNLIKELY,
- .call = sql_builtin_stub,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "LIKELY",
- .param_count = 1,
- .returns = FIELD_TYPE_BOOLEAN,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = SQL_FUNC_UNLIKELY,
- .call = sql_builtin_stub,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "LN",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "LOWER",
- .param_count = 1,
- .returns = FIELD_TYPE_STRING,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = SQL_FUNC_DERIVEDCOLL | SQL_FUNC_NEEDCOLL,
- .call = LowerICUFunc,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "MAX",
- .param_count = 1,
- .returns = FIELD_TYPE_SCALAR,
- .aggregate = FUNC_AGGREGATE_GROUP,
- .is_deterministic = false,
- .flags = SQL_FUNC_NEEDCOLL | SQL_FUNC_MAX,
- .call = minmaxStep,
- .finalize = minMaxFinalize,
- .export_to_sql = true,
- }, {
- .name = "MIN",
- .param_count = 1,
- .returns = FIELD_TYPE_SCALAR,
- .aggregate = FUNC_AGGREGATE_GROUP,
- .is_deterministic = false,
- .flags = SQL_FUNC_NEEDCOLL | SQL_FUNC_MIN,
- .call = minmaxStep,
- .finalize = minMaxFinalize,
- .export_to_sql = true,
- }, {
- .name = "MOD",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "NULLIF",
- .param_count = 2,
- .returns = FIELD_TYPE_SCALAR,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = SQL_FUNC_NEEDCOLL,
- .call = nullifFunc,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "OCTET_LENGTH",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "POSITION",
- .param_count = 2,
- .returns = FIELD_TYPE_INTEGER,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = SQL_FUNC_NEEDCOLL,
- .call = position_func,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "POWER",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "PRINTF",
- .param_count = -1,
- .returns = FIELD_TYPE_STRING,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = 0,
- .call = printfFunc,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "QUOTE",
- .param_count = 1,
- .returns = FIELD_TYPE_STRING,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = 0,
- .call = quoteFunc,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "RANDOM",
- .param_count = 0,
- .returns = FIELD_TYPE_INTEGER,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .call = randomFunc,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "RANDOMBLOB",
- .param_count = 1,
- .returns = FIELD_TYPE_VARBINARY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .call = randomBlob,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "REPLACE",
- .param_count = 3,
- .returns = FIELD_TYPE_STRING,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = SQL_FUNC_DERIVEDCOLL,
- .call = replaceFunc,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "ROUND",
- .param_count = -1,
- .returns = FIELD_TYPE_INTEGER,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = 0,
- .call = roundFunc,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "ROW_COUNT",
- .param_count = 0,
- .returns = FIELD_TYPE_INTEGER,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = 0,
- .call = sql_row_count,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "SOME",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "SOUNDEX",
- .param_count = 1,
- .returns = FIELD_TYPE_STRING,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = 0,
- .call = soundexFunc,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "SQRT",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "STRFTIME",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "SUBSTR",
- .param_count = -1,
- .returns = FIELD_TYPE_STRING,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = SQL_FUNC_DERIVEDCOLL,
- .call = substrFunc,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "SUM",
- .param_count = 1,
- .returns = FIELD_TYPE_NUMBER,
- .aggregate = FUNC_AGGREGATE_GROUP,
- .is_deterministic = false,
- .flags = 0,
- .call = sum_step,
- .finalize = sumFinalize,
- .export_to_sql = true,
- }, {
- .name = "TIME",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "TOTAL",
- .param_count = 1,
- .returns = FIELD_TYPE_NUMBER,
- .aggregate = FUNC_AGGREGATE_GROUP,
- .is_deterministic = false,
- .flags = 0,
- .call = total_step,
- .finalize = totalFinalize,
- .export_to_sql = true,
- }, {
- .name = "TRIM",
- .param_count = -1,
- .returns = FIELD_TYPE_STRING,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = SQL_FUNC_DERIVEDCOLL,
- .call = trim_func,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "TYPEOF",
- .param_count = 1,
- .returns = FIELD_TYPE_STRING,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = SQL_FUNC_TYPEOF,
- .call = typeofFunc,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "UNICODE",
- .param_count = 1,
- .returns = FIELD_TYPE_STRING,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = 0,
- .call = unicodeFunc,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "UNLIKELY",
- .param_count = 1,
- .returns = FIELD_TYPE_BOOLEAN,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = SQL_FUNC_UNLIKELY,
- .call = sql_builtin_stub,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "UPPER",
- .param_count = 1,
- .returns = FIELD_TYPE_STRING,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = SQL_FUNC_DERIVEDCOLL | SQL_FUNC_NEEDCOLL,
- .call = UpperICUFunc,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "UUID",
- .param_count = -1,
- .returns = FIELD_TYPE_UUID,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .call = sql_func_uuid,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "VERSION",
- .param_count = 0,
- .returns = FIELD_TYPE_STRING,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = 0,
- .call = sql_func_version,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "ZEROBLOB",
- .param_count = 1,
- .returns = FIELD_TYPE_VARBINARY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = true,
- .flags = 0,
- .call = zeroblobFunc,
- .finalize = NULL,
- .export_to_sql = true,
- }, {
- .name = "_sql_stat_get",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "_sql_stat_init",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- }, {
- .name = "_sql_stat_push",
- .call = sql_builtin_stub,
- .export_to_sql = false,
- .param_count = -1,
- .returns = FIELD_TYPE_ANY,
- .aggregate = FUNC_AGGREGATE_NONE,
- .is_deterministic = false,
- .flags = 0,
- .finalize = NULL,
- },
-};
-
-static struct func *
-built_in_func_get(const char *name)
-{
- uint32_t len = strlen(name);
- mh_int_t k = mh_strnptr_find_inp(built_in_functions, name, len);
- if (k == mh_end(built_in_functions))
- return NULL;
- return mh_strnptr_node(built_in_functions, k)->val;
-}
-
-static void
-built_in_func_put(struct func *func)
-{
- const char *name = func->def->name;
- uint32_t len = strlen(name);
- assert(built_in_func_get(name) == NULL);
-
- uint32_t hash = mh_strn_hash(name, len);
- const struct mh_strnptr_node_t strnode = {name, len, hash, func};
- mh_int_t k = mh_strnptr_put(built_in_functions, &strnode, NULL, NULL);
- if (k == mh_end(built_in_functions)) {
- panic("Out of memory on insertion into SQL built-in functions "
- "hash");
- }
-}
-
-struct func *
-sql_func_find(struct Expr *expr)
-{
- const char *name = expr->u.zToken;
- int n = expr->x.pList ? expr->x.pList->nExpr : 0;
- struct func *func = built_in_func_get(name);
- if (func != NULL) {
- assert(func->def->exports.sql);
- int param_count = func->def->param_count;
- if (param_count != -1 && param_count != n) {
- diag_set(ClientError, ER_FUNC_WRONG_ARG_COUNT, name,
- tt_sprintf("%d", func->def->param_count), n);
- return NULL;
- }
- return func;
- }
- func = func_by_name(name, strlen(name));
- if (func == NULL) {
- diag_set(ClientError, ER_NO_SUCH_FUNCTION, name);
- return NULL;
- }
- if (!func->def->exports.sql) {
- diag_set(ClientError, ER_SQL_PARSER_GENERIC,
- tt_sprintf("function %s() is not available in SQL",
- name));
- return NULL;
- }
- if (func->def->param_count != n) {
- diag_set(ClientError, ER_FUNC_WRONG_ARG_COUNT, name,
- tt_sprintf("%d", func->def->param_count), n);
- return NULL;
- }
- return func;
-}
-
-static struct func_vtab func_sql_builtin_vtab;
-
-void
-sql_built_in_functions_cache_init(void)
-{
- built_in_functions = mh_strnptr_new();
- if (built_in_functions == NULL)
- panic("Out of memory on creating SQL built-in functions hash");
- for (uint32_t i = 0; i < nelem(sql_builtins); ++i) {
- const char *name = sql_builtins[i].name;
- if (!sql_builtins[i].export_to_sql)
- continue;
- uint32_t len = strlen(name);
- uint32_t size = sizeof(struct func_def) + len + 1;
- struct func_def *def = malloc(size);
- if (def == NULL)
- panic("Out of memory on creating SQL built-in");
- def->fid = i;
- def->uid = 1;
- def->body = NULL;
- def->comment = NULL;
- def->setuid = true;
- def->is_deterministic = sql_builtins[i].is_deterministic;
- def->is_sandboxed = false;
- def->param_count = sql_builtins[i].param_count;
- def->returns = sql_builtins[i].returns;
- def->aggregate = sql_builtins[i].aggregate;
- def->language = FUNC_LANGUAGE_SQL_BUILTIN;
- def->name_len = len;
- def->exports.sql = sql_builtins[i].export_to_sql;
- func_opts_create(&def->opts);
- memcpy(def->name, name, len + 1);
-
- struct func_sql_builtin *func = malloc(sizeof(*func));
- if (func == NULL)
- panic("Out of memory on creating SQL built-in");
-
- func->base.def = def;
- func->base.vtab = &func_sql_builtin_vtab;
- credentials_create_empty(&func->base.owner_credentials);
- memset(func->base.access, 0, sizeof(func->base.access));
-
- func->flags = sql_builtins[i].flags;
- func->call = sql_builtins[i].call;
- func->finalize = sql_builtins[i].finalize;
- built_in_func_put(&func->base);
- }
-}
-
-void
-sql_built_in_functions_cache_free(void)
-{
- if (built_in_functions == NULL)
- return;
- for (uint32_t i = 0; i < nelem(sql_builtins); ++i) {
- const char *name = sql_builtins[i].name;
- uint32_t len = strlen(name);
- mh_int_t k = mh_strnptr_find_inp(built_in_functions, name, len);
- if (k == mh_end(built_in_functions))
- continue;
- struct func *func = mh_strnptr_node(built_in_functions, k)->val;
- mh_strnptr_del(built_in_functions, k, NULL);
- func_delete(func);
- }
- assert(mh_size(built_in_functions) == 0);
- mh_strnptr_delete(built_in_functions);
-}
-
-static void
-func_sql_builtin_destroy(struct func *func)
-{
- assert(func->vtab == &func_sql_builtin_vtab);
- assert(func->def->language == FUNC_LANGUAGE_SQL_BUILTIN);
- free(func);
-}
-
-static struct func_vtab func_sql_builtin_vtab = {
- .call = func_sql_builtin_call_stub,
- .destroy = func_sql_builtin_destroy,
-};
-
uint32_t
sql_func_flags(uint8_t id)
{
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 8edee0cef..a4257fc0f 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -4359,48 +4359,6 @@ Expr *sqlExprForVectorField(Parse *, Expr *, int);
*/
extern int sqlSubProgramsRemaining;
-struct func_sql_builtin {
- /** Function object base class. */
- struct func base;
- /** A bitmask of SQL flags. */
- uint16_t flags;
- /**
- * A VDBE-memory-compatible call method.
- * SQL built-ins don't use func base class "call"
- * method to provide a best performance for SQL requests.
- * Access checks are redundant, because all SQL built-ins
- * are predefined and are executed on SQL privilege level.
- */
- void (*call)(sql_context *ctx, int argc, sql_value **argv);
- /**
- * A VDBE-memory-compatible finalize method
- * (is valid only for aggregate function).
- */
- void (*finalize)(sql_context *ctx);
-};
-
-/**
- * Test whether SQL-specific flag is set for given function.
- * Currently only SQL Builtin Functions have such hint flags,
- * so function returns false for other functions. Such approach
- * decreases code complexity and allows do not distinguish
- * functions by implementation details where it is unnecessary.
- *
- * Returns true when given flag is set for a given function and
- * false otherwise.
- */
-static inline bool
-sql_func_flag_is_set(struct func *func, uint16_t flag)
-{
- if (func->def->language != FUNC_LANGUAGE_SQL_BUILTIN)
- return false;
- return (((struct func_sql_builtin *)func)->flags & flag) != 0;
-}
-
-/** Return a function that matches the parameters described in given expr. */
-struct func *
-sql_func_find(struct Expr *expr);
-
/** Return user-defined function with given name and number of arguments. */
struct func *
sql_func_by_signature(const char *name, uint32_t argc);
diff --git a/src/box/sql/vdbe.h b/src/box/sql/vdbe.h
index 1f6e566e1..eef472ed9 100644
--- a/src/box/sql/vdbe.h
+++ b/src/box/sql/vdbe.h
@@ -72,11 +72,6 @@ struct VdbeOp {
char *z; /* Pointer to data for string (char array) types */
i64 *pI64; /* Used when p4type is P4_INT64/UINT64 */
double *pReal; /* Used when p4type is P4_REAL */
- /**
- * A pointer to function implementation.
- * Used when p4type is P4_FUNC.
- */
- struct func *func;
sql_context *pCtx; /* Used when p4type is P4_FUNCCTX */
struct coll *pColl; /* Used when p4type is P4_COLLSEQ */
Mem *pMem; /* Used when p4type is P4_MEM */
@@ -132,8 +127,6 @@ struct SubProgram {
#define P4_DYNAMIC (-1) /* Pointer to a string obtained from sqlMalloc() */
#define P4_STATIC (-2) /* Pointer to a static string */
#define P4_COLLSEQ (-3) /* P4 is a pointer to a CollSeq structure */
-/** P4 is a pointer to a func structure. */
-#define P4_FUNC (-4)
#define P4_MEM (-7) /* P4 is a pointer to a Mem* structure */
#define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */
#define P4_REAL (-9) /* P4 is a 64-bit floating point value */
diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h
index 0a0e6cc97..231605e61 100644
--- a/src/box/sql/vdbeInt.h
+++ b/src/box/sql/vdbeInt.h
@@ -46,8 +46,6 @@
*/
typedef struct VdbeOp Op;
-struct func;
-
/*
* Boolean values
*/
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 3913dc637..0c37a30f9 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -1062,12 +1062,6 @@ displayP4(Op * pOp, char *zTemp, int nTemp)
sqlXPrintf(&x, "(binary)");
break;
}
- case P4_FUNC:{
- struct func *func = pOp->p4.func;
- sqlXPrintf(&x, "%s(%d)", func->def->name,
- func->def->param_count);
- break;
- }
#if defined(SQL_DEBUG) || defined(VDBE_PROFILE)
case P4_FUNCCTX:{
sqlXPrintf(&x, "%s(%d)", pOp->p4.pCtx->name,
--
2.25.1
More information about the Tarantool-patches
mailing list