From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id AE219248C5 for ; Wed, 10 Jul 2019 07:01:12 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id c1m5m2rYtI5V for ; Wed, 10 Jul 2019 07:01:12 -0400 (EDT) Received: from smtp60.i.mail.ru (smtp60.i.mail.ru [217.69.128.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id E14712106F for ; Wed, 10 Jul 2019 07:01:11 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v2 01/12] sql: get rid of SOUNDEX, MATCH Date: Wed, 10 Jul 2019 14:00:57 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org, korablev@tarantool.org Cc: kostja@tarantool.org, Kirill Shcherbatov In relation with FuncDef cache rework we need to clean-up builtins list. The SOUNDEX function is not in use while MATCH fucntion is a stub that raises an error, so they could be dropped. Needed for #4182 --- src/box/sql/func.c | 92 ------------------------------------ src/box/sql/main.c | 6 --- src/box/sql/sqlInt.h | 2 - src/box/sql/vdbeapi.c | 20 -------- test/sql-tap/e_expr.test.lua | 26 +--------- test/sql-tap/func.test.lua | 75 +---------------------------- 6 files changed, 2 insertions(+), 219 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 761a3abae..f0e1b1f0c 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -1468,67 +1468,6 @@ trim_func_three_args(struct sql_context *context, int argc, sql_value **argv) sql_free(char_len); } -/* IMP: R-25361-16150 This function is omitted from sql by default. It - * is only available if the SQL_SOUNDEX compile-time option is used - * when sql is built. - */ -#ifdef SQL_SOUNDEX -/* - * Compute the soundex encoding of a word. - * - * IMP: R-59782-00072 The soundex(X) function returns a string that is the - * soundex encoding of the string X. - */ -static void -soundexFunc(sql_context * context, int argc, sql_value ** argv) -{ - char zResult[8]; - const u8 *zIn; - int i, j; - static const unsigned char iCode[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 2, 3, 0, 1, 2, 0, 0, 2, 2, 4, 5, 5, 0, - 1, 2, 6, 2, 3, 0, 1, 0, 2, 0, 2, 0, 0, 0, 0, 0, - 0, 0, 1, 2, 3, 0, 1, 2, 0, 0, 2, 2, 4, 5, 5, 0, - 1, 2, 6, 2, 3, 0, 1, 0, 2, 0, 2, 0, 0, 0, 0, 0, - }; - assert(argc == 1); - zIn = (u8 *) sql_value_text(argv[0]); - if (zIn == 0) - zIn = (u8 *) ""; - for (i = 0; zIn[i] && !sqlIsalpha(zIn[i]); i++) { - } - if (zIn[i]) { - u8 prevcode = iCode[zIn[i] & 0x7f]; - zResult[0] = sqlToupper(zIn[i]); - for (j = 1; j < 4 && zIn[i]; i++) { - int code = iCode[zIn[i] & 0x7f]; - if (code > 0) { - if (code != prevcode) { - prevcode = code; - zResult[j++] = code + '0'; - } - } else { - prevcode = 0; - } - } - while (j < 4) { - zResult[j++] = '0'; - } - zResult[j] = 0; - sql_result_text(context, zResult, 4, SQL_TRANSIENT); - } else { - /* IMP: R-64894-50321 The string "?000" is returned if the argument - * is NULL or contains no ASCII alphabetic characters. - */ - sql_result_text(context, "?000", 4, SQL_STATIC); - } -} -#endif /* SQL_SOUNDEX */ - /* * An instance of the following structure holds the context of a * sum() or avg() aggregate computation. @@ -1763,34 +1702,6 @@ groupConcatFinalize(sql_context * context) } } -/* - * If the function already exists as a regular global function, then - * this routine is a no-op. If the function does not exist, then create - * a new one that always throws a run-time error. - */ -static inline int -sql_overload_function(sql * db, const char *zName, - enum field_type type, int nArg) -{ - if (sqlFindFunction(db, zName, nArg, 0) == 0) { - return sqlCreateFunc(db, zName, type, nArg, 0, 0, - sqlInvalidFunction, 0, 0, 0); - } - return 0; -} - -/* - * This routine does per-connection function registration. Most - * of the built-in functions above are part of the global function set. - * This routine only deals with those that are not global. - */ -void -sqlRegisterPerConnectionBuiltinFunctions(sql * db) -{ - if (sql_overload_function(db, "MATCH", FIELD_TYPE_SCALAR, 2) != 0) - sqlOomFault(db); -} - /* * Set the LIKEOPT flag on the 2-argument function with the given name. */ @@ -1869,9 +1780,6 @@ sqlRegisterBuiltinFunctions(void) * For peak efficiency, put the most frequently used function last. */ static FuncDef aBuiltinFunc[] = { -#ifdef SQL_SOUNDEX - FUNCTION(soundex, 1, 0, 0, soundexFunc), -#endif FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQL_FUNC_UNLIKELY, FIELD_TYPE_BOOLEAN), FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQL_FUNC_UNLIKELY, diff --git a/src/box/sql/main.c b/src/box/sql/main.c index bfe3d7186..89d83d242 100644 --- a/src/box/sql/main.c +++ b/src/box/sql/main.c @@ -460,12 +460,6 @@ sql_init_db(sql **out_db) return -1; } - /* Register all built-in functions, but do not attempt to read the - * database schema yet. This is delayed until the first time the database - * is accessed. - */ - sqlRegisterPerConnectionBuiltinFunctions(db); - *out_db = db; return 0; } diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index 73dc6e4d7..9305f7d5c 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -3524,7 +3524,6 @@ void sqlInsertBuiltinFuncs(FuncDef *, int); FuncDef *sqlFindFunction(sql *, const char *, int, u8); void sqlRegisterBuiltinFunctions(void); void sqlRegisterDateTimeFunctions(void); -void sqlRegisterPerConnectionBuiltinFunctions(sql *); /** * Evaluate a view and store its result in an ephemeral table. @@ -4359,7 +4358,6 @@ void sqlParser(void *, int, Token, Parse *); int sqlParserStackPeak(void *); #endif -void sqlInvalidFunction(sql_context *, int, sql_value **); sql_int64 sqlStmtCurrentTime(sql_context *); int sqlVdbeParameterIndex(Vdbe *, const char *, int); int sqlTransferBindings(sql_stmt *, sql_stmt *); diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index f470ac6b1..ef0ab79d2 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -519,26 +519,6 @@ sqlStmtCurrentTime(sql_context * p) return *piTime; } -/* - * The following is the implementation of an SQL function that always - * fails with an error message stating that the function is used in the - * wrong context. The sql_overload_function() API might construct - * SQL function that use this routine so that the functions will exist - * for name resolution. - */ -void -sqlInvalidFunction(sql_context * context, /* The function calling context */ - int NotUsed, /* Number of arguments to the function */ - sql_value ** NotUsed2 /* Value of each argument */ - ) -{ - const char *zName = context->pFunc->zName; - UNUSED_PARAMETER2(NotUsed, NotUsed2); - const char *err = "unable to use function %s in the requested context"; - diag_set(ClientError, ER_SQL_EXECUTE, tt_sprintf(err, zName)); - context->is_aborted = true; -} - /* * Create a new aggregate context for p and return a pointer to * its pMem->z element. diff --git a/test/sql-tap/e_expr.test.lua b/test/sql-tap/e_expr.test.lua index 7b80651a8..6d56bf58b 100755 --- a/test/sql-tap/e_expr.test.lua +++ b/test/sql-tap/e_expr.test.lua @@ -1,6 +1,6 @@ #!/usr/bin/env tarantool test = require("sqltester") -test:plan(10641) +test:plan(10639) --!./tcltestrunner.lua -- 2010 July 16 @@ -2405,30 +2405,6 @@ test:do_test( -- }) ---sql("db", "test.db") --- EVIDENCE-OF: R-42037-37826 The default match() function implementation --- raises an exception and is not really useful for anything. --- -test:do_catchsql_test( - "e_expr-19.1.1", - [[ - SELECT 'abc' MATCH 'def' - ]], { - -- - 1, "unable to use function MATCH in the requested context" - -- - }) - -test:do_catchsql_test( - "e_expr-19.1.2", - [[ - SELECT match('abc', 'def') - ]], { - -- - 1, "unable to use function MATCH in the requested context" - -- - }) - -- EVIDENCE-OF: R-37916-47407 The MATCH operator is a special syntax for -- the match() application-defined function. -- diff --git a/test/sql-tap/func.test.lua b/test/sql-tap/func.test.lua index f9044ad01..64d53bac8 100755 --- a/test/sql-tap/func.test.lua +++ b/test/sql-tap/func.test.lua @@ -1,6 +1,6 @@ #!/usr/bin/env tarantool test = require("sqltester") -test:plan(14590) +test:plan(14586) --!./tcltestrunner.lua -- 2001 September 15 @@ -1734,79 +1734,6 @@ test:do_catchsql_test( -- }) --- The MATCH function exists but is only a stub and always throws an error. --- -test:do_execsql_test( - "func-19.1", - [[ - SELECT match(a,b) FROM t1 WHERE false; - ]], { - -- - - -- - }) - -test:do_catchsql_test( - "func-19.2", - [[ - SELECT 'abc' MATCH 'xyz'; - ]], { - -- - 1, "Failed to execute SQL statement: unable to use function MATCH in the requested context" - -- - }) - -test:do_catchsql_test( - "func-19.3", - [[ - SELECT 'abc' NOT MATCH 'xyz'; - ]], { - -- - 1, "Failed to execute SQL statement: unable to use function MATCH in the requested context" - -- - }) - -test:do_catchsql_test( - "func-19.4", - [[ - SELECT match(1,2,3); - ]], { - -- - 1, "wrong number of arguments to function MATCH()" - -- - }) - --- Soundex tests. --- --- false condition for current tarantool version -if pcall( function() test:execsql("SELECT soundex('hello')") end ) then - for i, val in ipairs({ - {"euler", "E460"}, - {"EULER", "E460"}, - {"Euler", "E460"}, - {"ellery", "E460"}, - {"gauss", "G200"}, - {"ghosh", "G200"}, - {"hilbert", "H416"}, - {"Heilbronn", "H416"}, - {"knuth", "K530"}, - {"kant", "K530"}, - {"Lloyd", "L300"}, - {"LADD", "L300"}, - {"Lukasiewicz", "L222"}, - {"Lissajous", "L222"}, - {"A", "A000"}, - {"12345", "?000"} }) do - local name = val[1] - local sdx = val[2] - test:do_execsql_test( - "func-20."..i, - string.format("SELECT soundex('%s')", name), { - sdx - }) - - end -end -- Tests of the REPLACE function. -- test:do_catchsql_test( -- 2.21.0