From 4d936cb250e9906b6d892a0ce1cbfdf39f1a3b87 Mon Sep 17 00:00:00 2001
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
Date: Thu, 11 Jul 2019 11:52:05 +0300
Subject: [PATCH] sql: get rid of MATCH sql builtin

In relation with FuncDef cache rework we need to clean-up
builtins list. The MATCH fucntion is a stub that raises an error
and it could be dropped.

Needed for #4182

@kostja: make the patch actually pass the tests, remove
tap count change in e_expr.test.lua, since it's disabled and was
not run
---
 src/box/sql/func.c           | 28 -----------------------
 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 | 24 --------------------
 test/sql-tap/func.test.lua   | 44 +-----------------------------------
 6 files changed, 1 insertion(+), 123 deletions(-)

diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 98cad51fd2..e1c9a722f7 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -1763,34 +1763,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.
  */
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index bfe3d71863..89d83d242e 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 73dc6e4d76..9305f7d5c8 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 f470ac6b1f..ef0ab79d2e 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 7b80651a84..7ee7a2d986 100755
--- a/test/sql-tap/e_expr.test.lua
+++ b/test/sql-tap/e_expr.test.lua
@@ -2405,30 +2405,6 @@ test:do_test(
         -- </e_expr-18.2.4>
     })
 
---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'
-    ]], {
-        -- <e_expr-19.1.1>
-        1, "unable to use function MATCH in the requested context"
-        -- </e_expr-19.1.1>
-    })
-
-test:do_catchsql_test(
-    "e_expr-19.1.2",
-    [[
-        SELECT match('abc', 'def')
-    ]], {
-        -- <e_expr-19.1.2>
-        1, "unable to use function MATCH in the requested context"
-        -- </e_expr-19.1.2>
-    })
-
 -- 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 a0c6b47b57..d6bf1bb981 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,48 +1734,6 @@ test:do_catchsql_test(
         -- </func-18.32>
     })
 
--- 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;
-    ]], {
-        -- <func-19.1>
-        
-        -- </func-19.1>
-    })
-
-test:do_catchsql_test(
-    "func-19.2",
-    [[
-        SELECT 'abc' MATCH 'xyz';
-    ]], {
-        -- <func-19.2>
-        1, "Failed to execute SQL statement: unable to use function MATCH in the requested context"
-        -- </func-19.2>
-    })
-
-test:do_catchsql_test(
-    "func-19.3",
-    [[
-        SELECT 'abc' NOT MATCH 'xyz';
-    ]], {
-        -- <func-19.3>
-        1, "Failed to execute SQL statement: unable to use function MATCH in the requested context"
-        -- </func-19.3>
-    })
-
-test:do_catchsql_test(
-    "func-19.4",
-    [[
-        SELECT match(1,2,3);
-    ]], {
-        -- <func-19.4>
-        1, "wrong number of arguments to function MATCH()"
-        -- </func-19.4>
-    })
-
 -- Soundex tests.
 --
 -- false condition for current tarantool version
-- 
GitLab