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 42E736EC41; Mon, 9 Aug 2021 10:20:28 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 42E736EC41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628493628; bh=pEl3eS4vgJX2CPm2ELImwmPA/6gfnpFfBKbpbrOcaA8=; 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=SS4iuqu0+TG7bUqsg/roNZfyb2DIYP1AoJYcH0Jhr7jACmEbIeyHhLr7NkiV86L5K n8j42vexJXsSj53H1O8RQOvVZctBzjTD+tCfW7Keq9DNf/zrc5hWVIhXeastwtHMRv Rf+W/gXpL5rRDOJQoaDtZwP8YnM9DwmI+cHAnGro= Received: from smtp44.i.mail.ru (smtp44.i.mail.ru [94.100.177.104]) (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 1CB646EC44 for ; Mon, 9 Aug 2021 10:19:00 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1CB646EC44 Received: by smtp44.i.mail.ru with esmtpa (envelope-from ) id 1mCzYo-0001Qa-RV; Mon, 09 Aug 2021 10:18:59 +0300 To: kyukhin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Mon, 9 Aug 2021 10:18:58 +0300 Message-Id: <11992521e3347773167ab6009b9f67bac0385a58.1628493342.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: 4F1203BC0FB41BD92087353F0EC44DD9736CF3E71F18CE0C3E1D5927724F4AAA182A05F5380850402ACD4291674B12BB6DF4D68DA9A54B7E992F83C430D3B265E104AA3B5E4AA79F X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE746B03E86F7BE0434EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637E81CF8DC92FD26598638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D82ACA62D0AA24BAB0D7B68715E6AFD52D117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF1175FABE1C0F9B6A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735201E561CDFBCA1751FF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947C5E59ED9F8991241776E601842F6C81A12EF20D2F80756B5F7E9C4E3C761E06A776E601842F6C81A127C277FBC8AE2E8BE32D9E0CF56347DF3AA81AA40904B5D9DBF02ECDB25306B2201CA6A4E26CD07C3BBE47FD9DD3FB595F5C1EE8F4F765FC72CEEB2601E22B093A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E735E4A630A5B664A4FFC4224003CC83647689D4C264860C145E X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B505D8E9F0B02E82798DA2AB858EE45E6711 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C4C7A0BC55FA0FE5FCB7EDD5838D525CDD089109BCCCA78EBEB5D2B78A1C50AE34B1881A6453793CE9C32612AADDFBE061C61BE10805914D3804EBA3D8E7E5B87ABF8C51168CD8EBDBF80095D1ED7F4578DC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D348E5EF936B2E46EBAC0C678C209A918E2B5B4A343B1CD194D782AC1F13749B24FF8AF8C7F93C1A5001D7E09C32AA3244CE818552AD78859E15CC294A222A9A14BF2F5F14F68F1805B729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojMTMPlNJj3ShY6yOzE70YTA== X-Mailru-Sender: 5C3750E245F362008BC1685FEC6306ED66C1E80F5C2A44C06DF4D68DA9A54B7EEC9A243AB1C8B1BC5105BD0848736F9966FEC6BF5C9C28D97E07721503EA2E00ED97202A5A4E92BF7402F9BA4338D657ED14614B50AE0675 X-Mras: Ok Subject: [Tarantool-patches] [PATCH v2 3/6] sql: remove SQL built-in functions from _func 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 SQL built-in functions from _func. These functions could be called directly from Lua, however all they did was returned an error. After this patch, no SQL built-in functions can be called directly from LUA. Part of #6106 --- ...gh-6106-remove-sql-built-ins-from-_func.md | 7 ++ src/box/alter.cc | 7 -- src/box/bootstrap.snap | Bin 6016 -> 4891 bytes src/box/box.cc | 1 + src/box/lua/upgrade.lua | 16 +-- src/box/sql.c | 1 + src/box/sql.h | 9 ++ src/box/sql/func.c | 118 +++++++++++++++++- test/box-py/bootstrap.result | 66 ---------- test/box/access_bin.result | 4 +- test/box/access_bin.test.lua | 4 +- test/box/access_sysview.result | 8 +- test/box/function1.result | 32 +---- test/box/function1.test.lua | 13 +- test/sql-tap/func5.test.lua | 25 +++- test/wal_off/func_max.result | 8 +- 16 files changed, 184 insertions(+), 135 deletions(-) create mode 100644 changelogs/unreleased/gh-6106-remove-sql-built-ins-from-_func.md diff --git a/changelogs/unreleased/gh-6106-remove-sql-built-ins-from-_func.md b/changelogs/unreleased/gh-6106-remove-sql-built-ins-from-_func.md new file mode 100644 index 000000000..02f33dd50 --- /dev/null +++ b/changelogs/unreleased/gh-6106-remove-sql-built-ins-from-_func.md @@ -0,0 +1,7 @@ +## feature/sql + +* SQL built-in functions were removed from \_func system space (gh-6106). +* Function are now looked up first in SQL built-in functions and then in + user-defined functions. +* Fixed incorrect error message in case of misuse of the function used to set + the default value. diff --git a/src/box/alter.cc b/src/box/alter.cc index 390199298..935790df4 100644 --- a/src/box/alter.cc +++ b/src/box/alter.cc @@ -3548,13 +3548,6 @@ on_replace_dd_func(struct trigger * /* trigger */, void *event) "function has references"); return -1; } - /* Can't' drop a builtin function. */ - if (old_func->def->language == FUNC_LANGUAGE_SQL_BUILTIN) { - diag_set(ClientError, ER_DROP_FUNCTION, - (unsigned) old_func->def->uid, - "function is SQL built-in"); - return -1; - } struct trigger *on_commit = txn_alter_trigger_new(on_drop_func_commit, old_func); struct trigger *on_rollback = diff --git a/src/box/bootstrap.snap b/src/box/bootstrap.snap index 57374decc0f9de140772d9809a227e3ba4ce61eb..018670d2a6558e64ba691ce0002320b76ac1c97b 100644 GIT binary patch literal 4891 zcmV+$6XfhuPC-x#FfK7O3RY!ub7^mGIv_GGIW90QF*!CZXEHH4GB;#2VlxU!ZgX^D zZewLSATlyFFkv?`W-T@_GG#3^Fk@jYIWS>jEjeT|VP;`uIAJ$qW(rnAY;R+0Iv{&} z3JTS_3%bn`p#aW#B#y(S0000004TLD{Qy|SlmPms=p;rEh}k&+0000005BMOz-BjK zEcy1k{S!#N{Q$r==I?(gQ&N*D$;g(Zlu6_?%r8?VM(P)P($NwZDINckgJ^ z4ow1F0tx~pzm0m|MzXw(x3Ni|V9WEa+t%EOP4U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l zYa8XC0T^a)iL(Zw4HZsRoivHaESR!gA8)`3iq?Lk>P>FEC}vE6%v?JAP{S5-|E zcr@Zg0u_+G2CTAtHqU1DQ?+qK>iWG+&s&94x(a`M*;^_G?5*n6n}B@m{fQj>)GIk< z5kjuVQog*O{?9x_;PspE;&g&hl${-3a8+zo?Ky4ot$La}dD?@s>*9-UXP diff --git a/src/box/box.cc b/src/box/box.cc index 8dc3b130b..66e658fc3 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -3041,6 +3041,7 @@ box_free(void) gc_free(); engine_shutdown(); wal_free(); + sql_built_in_functions_cache_free(); } } diff --git a/src/box/lua/upgrade.lua b/src/box/lua/upgrade.lua index 97afc0b4d..6abce50f4 100644 --- a/src/box/lua/upgrade.lua +++ b/src/box/lua/upgrade.lua @@ -1003,19 +1003,19 @@ end -------------------------------------------------------------------------------- -- Tarantool 2.9.1 -------------------------------------------------------------------------------- -local function sql_builtin_function_uuid() +local function remove_sql_builtin_functions_from_func() local _func = box.space._func local _priv = box.space._priv - local datetime = os.date("%Y-%m-%d %H:%M:%S") - local t = _func:auto_increment({ADMIN, 'UUID', 1, 'SQL_BUILTIN', '', - 'function', {}, 'any', 'none', 'none', - false, false, true, {}, setmap({}), '', - datetime, datetime}) - _priv:replace{ADMIN, PUBLIC, 'function', t.id, box.priv.X} + for _, v in _func:pairs() do + if v.language == "SQL_BUILTIN" then + _priv:delete({2, 'function', v.id}) + _func:delete({v.id}) + end + end end local function upgrade_to_2_9_1() - sql_builtin_function_uuid() + remove_sql_builtin_functions_from_func() end -------------------------------------------------------------------------------- diff --git a/src/box/sql.c b/src/box/sql.c index 433264abe..f18dfa063 100644 --- a/src/box/sql.c +++ b/src/box/sql.c @@ -75,6 +75,7 @@ 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 4c364306c..2ac97c762 100644 --- a/src/box/sql.h +++ b/src/box/sql.h @@ -56,6 +56,15 @@ 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 7cdcce6bc..2a3a5d457 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -47,6 +47,10 @@ #include #include "box/coll_id_cache.h" #include "box/schema.h" +#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) @@ -2643,11 +2647,49 @@ static struct { }, }; +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; - struct func *func = func_by_name(name, strlen(name)); + 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; @@ -2658,8 +2700,7 @@ sql_func_find(struct Expr *expr) name)); return NULL; } - int n = expr->x.pList != NULL ? expr->x.pList->nExpr : 0; - if (func->def->param_count != -1 && func->def->param_count != n) { + 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; @@ -2670,9 +2711,10 @@ sql_func_find(struct Expr *expr) uint32_t sql_func_flags(const char *name) { - struct func *func = func_by_name(name, strlen(name)); - if (func == NULL || func->def->language != FUNC_LANGUAGE_SQL_BUILTIN) + struct func *func = built_in_func_get(name); + if (func == NULL) return 0; + assert(func->def->language == FUNC_LANGUAGE_SQL_BUILTIN); uint32_t flags = ((struct func_sql_builtin *)func)->flags; if (func->def->aggregate == FUNC_AGGREGATE_GROUP) flags |= SQL_FUNC_AGG; @@ -2681,6 +2723,72 @@ sql_func_flags(const char *name) 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); +} + struct func * func_sql_builtin_new(struct func_def *def) { diff --git a/test/box-py/bootstrap.result b/test/box-py/bootstrap.result index b2328487c..cea440c64 100644 --- a/test/box-py/bootstrap.result +++ b/test/box-py/bootstrap.result @@ -176,73 +176,7 @@ box.space._priv:select{} - [1, 0, 'universe', 0, 24] - [1, 1, 'universe', 0, 4294967295] - [1, 2, 'function', 1, 4] - - [1, 2, 'function', 2, 4] - - [1, 2, 'function', 3, 4] - - [1, 2, 'function', 4, 4] - - [1, 2, 'function', 5, 4] - - [1, 2, 'function', 6, 4] - - [1, 2, 'function', 7, 4] - - [1, 2, 'function', 8, 4] - - [1, 2, 'function', 9, 4] - - [1, 2, 'function', 10, 4] - - [1, 2, 'function', 11, 4] - - [1, 2, 'function', 12, 4] - - [1, 2, 'function', 13, 4] - - [1, 2, 'function', 14, 4] - - [1, 2, 'function', 15, 4] - - [1, 2, 'function', 16, 4] - - [1, 2, 'function', 17, 4] - - [1, 2, 'function', 18, 4] - - [1, 2, 'function', 19, 4] - - [1, 2, 'function', 20, 4] - - [1, 2, 'function', 21, 4] - - [1, 2, 'function', 22, 4] - - [1, 2, 'function', 23, 4] - - [1, 2, 'function', 24, 4] - - [1, 2, 'function', 25, 4] - - [1, 2, 'function', 26, 4] - - [1, 2, 'function', 27, 4] - - [1, 2, 'function', 28, 4] - - [1, 2, 'function', 29, 4] - - [1, 2, 'function', 30, 4] - - [1, 2, 'function', 31, 4] - - [1, 2, 'function', 32, 4] - - [1, 2, 'function', 33, 4] - - [1, 2, 'function', 34, 4] - - [1, 2, 'function', 35, 4] - - [1, 2, 'function', 36, 4] - - [1, 2, 'function', 37, 4] - - [1, 2, 'function', 38, 4] - - [1, 2, 'function', 39, 4] - - [1, 2, 'function', 40, 4] - - [1, 2, 'function', 41, 4] - - [1, 2, 'function', 42, 4] - - [1, 2, 'function', 43, 4] - - [1, 2, 'function', 44, 4] - - [1, 2, 'function', 45, 4] - - [1, 2, 'function', 46, 4] - - [1, 2, 'function', 47, 4] - - [1, 2, 'function', 48, 4] - - [1, 2, 'function', 49, 4] - - [1, 2, 'function', 50, 4] - - [1, 2, 'function', 51, 4] - - [1, 2, 'function', 52, 4] - - [1, 2, 'function', 53, 4] - - [1, 2, 'function', 54, 4] - - [1, 2, 'function', 55, 4] - - [1, 2, 'function', 56, 4] - - [1, 2, 'function', 57, 4] - - [1, 2, 'function', 58, 4] - - [1, 2, 'function', 59, 4] - - [1, 2, 'function', 60, 4] - - [1, 2, 'function', 61, 4] - - [1, 2, 'function', 62, 4] - - [1, 2, 'function', 63, 4] - - [1, 2, 'function', 64, 4] - [1, 2, 'function', 65, 4] - - [1, 2, 'function', 66, 4] - - [1, 2, 'function', 67, 4] - - [1, 2, 'function', 68, 4] - [1, 2, 'space', 276, 2] - [1, 2, 'space', 277, 1] - [1, 2, 'space', 281, 1] diff --git a/test/box/access_bin.result b/test/box/access_bin.result index aeb8b3bd8..7c720192f 100644 --- a/test/box/access_bin.result +++ b/test/box/access_bin.result @@ -295,10 +295,10 @@ test:drop() box.schema.user.grant('guest', 'execute', 'universe') --- ... -function f1() return box.space._func:get(1)[4] end +function f1() return box.space._func.index[2]:get({'f1'})[4] end --- ... -function f2() return box.space._func:get(69)[4] end +function f2() return box.space._func.index[2]:get({'f1'})[4] end --- ... box.schema.func.create('f1') diff --git a/test/box/access_bin.test.lua b/test/box/access_bin.test.lua index 954266858..e82ec759c 100644 --- a/test/box/access_bin.test.lua +++ b/test/box/access_bin.test.lua @@ -111,8 +111,8 @@ test:drop() -- -- notice that guest can execute stuff, but can't read space _func box.schema.user.grant('guest', 'execute', 'universe') -function f1() return box.space._func:get(1)[4] end -function f2() return box.space._func:get(69)[4] end +function f1() return box.space._func.index[2]:get({'f1'})[4] end +function f2() return box.space._func.index[2]:get({'f1'})[4] end box.schema.func.create('f1') box.schema.func.create('f2',{setuid=true}) c = net.connect(box.cfg.listen) diff --git a/test/box/access_sysview.result b/test/box/access_sysview.result index d7a7b7534..071fc8de2 100644 --- a/test/box/access_sysview.result +++ b/test/box/access_sysview.result @@ -258,11 +258,11 @@ box.session.su('guest') ... #box.space._vpriv:select{} --- -- 83 +- 17 ... #box.space._vfunc:select{} --- -- 68 +- 2 ... #box.space._vcollation:select{} --- @@ -290,11 +290,11 @@ box.session.su('guest') ... #box.space._vpriv:select{} --- -- 83 +- 17 ... #box.space._vfunc:select{} --- -- 68 +- 2 ... #box.space._vsequence:select{} --- diff --git a/test/box/function1.result b/test/box/function1.result index 0166c828f..a49a133f7 100644 --- a/test/box/function1.result +++ b/test/box/function1.result @@ -97,7 +97,7 @@ box.func["function1.args"] exports: lua: true sql: false - id: 69 + id: 66 setuid: false is_multikey: false is_deterministic: false @@ -593,7 +593,7 @@ func exports: lua: true sql: false - id: 69 + id: 66 setuid: false is_multikey: false is_deterministic: false @@ -665,7 +665,7 @@ func exports: lua: true sql: false - id: 69 + id: 66 setuid: false is_multikey: false is_deterministic: false @@ -1032,7 +1032,7 @@ box.func.test ~= nil box.func.test:drop() --- ... --- Check SQL builtins +-- Make sure there is no SQL built-in functions in _func. test_run:cmd("setopt delimiter ';'") --- - true @@ -1048,7 +1048,7 @@ sql_builtin_list = { "RANDOMBLOB", "NULLIF", "ZEROBLOB", "MIN", "MAX", "COALESCE", "EVERY", "EXISTS", "EXTRACT", "SOME", "GREATER", "LESSER", "SOUNDEX", "LIKELIHOOD", "LIKELY", "UNLIKELY", "_sql_stat_get", "_sql_stat_push", - "_sql_stat_init", "GREATEST", "LEAST" + "_sql_stat_init", "GREATEST", "LEAST", "UUID" } test_run:cmd("setopt delimiter ''"); --- @@ -1056,7 +1056,7 @@ test_run:cmd("setopt delimiter ''"); ok = true --- ... -for _, v in pairs(sql_builtin_list) do ok = ok and (box.space._func.index.name:get(v) ~= nil) end +for _, v in pairs(sql_builtin_list) do ok = ok and (box.space._func.index.name:get(v) == nil) end --- ... ok == true @@ -1067,26 +1067,6 @@ box.func.LUA:call({"return 1 + 1"}) --- - 2 ... -box.schema.user.grant('guest', 'execute', 'function', 'SUM') ---- -... -c = net.connect(box.cfg.listen) ---- -... -c:call("SUM") ---- -- error: sql builtin function does not support Lua frontend -... -c:close() ---- -... -box.schema.user.revoke('guest', 'execute', 'function', 'SUM') ---- -... -box.schema.func.drop("SUM") ---- -- error: 'Can''t drop function 1: function is SQL built-in' -... -- Introduce function options box.schema.func.create('test', {body = "function(tuple) return tuple end", is_deterministic = true, opts = {is_multikey = true}}) --- diff --git a/test/box/function1.test.lua b/test/box/function1.test.lua index ab7b586a0..4fdd48520 100644 --- a/test/box/function1.test.lua +++ b/test/box/function1.test.lua @@ -363,7 +363,7 @@ f == nil box.func.test ~= nil box.func.test:drop() --- Check SQL builtins +-- Make sure there is no SQL built-in functions in _func. test_run:cmd("setopt delimiter ';'") sql_builtin_list = { "TRIM", "TYPEOF", "PRINTF", "UNICODE", "CHAR", "HEX", "VERSION", @@ -376,22 +376,15 @@ sql_builtin_list = { "RANDOMBLOB", "NULLIF", "ZEROBLOB", "MIN", "MAX", "COALESCE", "EVERY", "EXISTS", "EXTRACT", "SOME", "GREATER", "LESSER", "SOUNDEX", "LIKELIHOOD", "LIKELY", "UNLIKELY", "_sql_stat_get", "_sql_stat_push", - "_sql_stat_init", "GREATEST", "LEAST" + "_sql_stat_init", "GREATEST", "LEAST", "UUID" } test_run:cmd("setopt delimiter ''"); ok = true -for _, v in pairs(sql_builtin_list) do ok = ok and (box.space._func.index.name:get(v) ~= nil) end +for _, v in pairs(sql_builtin_list) do ok = ok and (box.space._func.index.name:get(v) == nil) end ok == true box.func.LUA:call({"return 1 + 1"}) -box.schema.user.grant('guest', 'execute', 'function', 'SUM') -c = net.connect(box.cfg.listen) -c:call("SUM") -c:close() -box.schema.user.revoke('guest', 'execute', 'function', 'SUM') -box.schema.func.drop("SUM") - -- Introduce function options box.schema.func.create('test', {body = "function(tuple) return tuple end", is_deterministic = true, opts = {is_multikey = true}}) box.func['test'].is_multikey == true diff --git a/test/sql-tap/func5.test.lua b/test/sql-tap/func5.test.lua index 13698582b..bd4561afc 100755 --- a/test/sql-tap/func5.test.lua +++ b/test/sql-tap/func5.test.lua @@ -1,6 +1,6 @@ #!/usr/bin/env tarantool local test = require("sqltester") -test:plan(27) +test:plan(29) --!./tcltestrunner.lua -- 2010 August 27 @@ -346,4 +346,27 @@ box.func.F2:drop() box.space.T01:drop() box.space.T02:drop() +-- +-- gh-6105: Make sure that functions that were described in _func but were not +-- implemented are now removed. +-- +test:do_catchsql_test( + "func-7.3", + [[ + SELECT SQRT(); + ]], { + 1, "Function 'SQRT' does not exist" + }) + +-- Make sure that functions are looked up in built-in functions first. +box.schema.func.create('ABS', {language = 'Lua', param_list = {"INTEGER"}, + body = body, returns = 'number', exports = {'LUA'}}); +test:do_execsql_test( + "func-7.4", + [[ + SELECT ABS(-111); + ]], { + 111 + }) + test:finish_test() diff --git a/test/wal_off/func_max.result b/test/wal_off/func_max.result index cc5bcc141..a3ab5b431 100644 --- a/test/wal_off/func_max.result +++ b/test/wal_off/func_max.result @@ -42,11 +42,11 @@ test_run:cmd("setopt delimiter ''"); ... func_limit() --- -- error: 'Failed to create function ''func31933'': function id is too big' +- error: 'Failed to create function ''func31936'': function id is too big' ... drop_limit_func() --- -- error: Function 'func31933' does not exist +- error: Function 'func31936' does not exist ... box.schema.user.create('testuser') --- @@ -62,11 +62,11 @@ session.su('testuser') ... func_limit() --- -- error: 'Failed to create function ''func31933'': function id is too big' +- error: 'Failed to create function ''func31936'': function id is too big' ... drop_limit_func() --- -- error: Function 'func31933' does not exist +- error: Function 'func31936' does not exist ... session.su('admin') --- -- 2.25.1