From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 008266EC41; Thu, 19 Aug 2021 08:34:12 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 008266EC41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1629351253; bh=+QEBIgPE7Vte8DcX6G5vFsnge1SC8mRxxdyjSppfMpY=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=p+b3TiJZAUp1FxC+DW2o0tc4pervTb2POQ9JosZP5V2HaiemruTyGbggzvMqRyeNb TvLgQefo4GRdLtEukaX85r12Vv3n53A7HSaBH1nYuvK/Zgle8JUnmmwXRxWtaJiXKH HtYA3QcDz2DIN5rWJvGVtLYWLd8LcfGg3sYB74AI= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id E1C1E6EC5D for ; Thu, 19 Aug 2021 08:31:34 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E1C1E6EC5D Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mGaeL-0002NL-Sp; Thu, 19 Aug 2021 08:31:34 +0300 To: vdavydov@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Thu, 19 Aug 2021 08:31:33 +0300 Message-Id: <093559c15773e0097c443fdfe3f6aa66beba40f3.1629350815.git.imeevma@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD972FF4A7D76DB5E242D14FEF1BD8BF4AC182A05F538085040CE1EDE928C6C1527247BF233E51CE9A652A78B91764FE65B74300B6BF0681ECE X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7A8F5C3A6CEAE4685EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637222645A8BD7B05AE8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D81489F818228282058F96CA7BDFF1FE4D117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6300D3B61E77C8D3B089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CF160826E4E1956AEA47F320155B29045708E551C97DD4A5F9C2B6934AE262D3EE7EAB7254005DCED114C52B35DBB74F4E7EAB7254005DCEDA5DF9383870C0FED1E0A4E2319210D9B64D260DF9561598F01A9E91200F654B08C45A656E22914C58E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D345CB6DE26F1654667783100F141849EF7AB2E241A573B02CAAFFC91872334E3392EC94AAF979AEE071D7E09C32AA3244C4CC9581D480D5C4791E2CFFEBFAAA6F78894E9C85370243E729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojGSxK+6r6oBGL2UqlU9XJRg== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DF75F88E73FC27F346FBEBFE1F8BD5CF483D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v2 5/5] sql: remove unused code X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mergen Imeev via Tarantool-patches Reply-To: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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