Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org, korablev@tarantool.org
Cc: kostja@tarantool.org, Kirill Shcherbatov <kshcherbatov@tarantool.org>
Subject: [tarantool-patches] [PATCH v2 03/12] sql: put analyze helpers to FuncDef cache
Date: Wed, 10 Jul 2019 14:01:02 +0300	[thread overview]
Message-ID: <df60e4bc84f0f7f8c297595618089c9c800b3274.1562756438.git.kshcherbatov@tarantool.org> (raw)
In-Reply-To: <cover.1562756438.git.kshcherbatov@tarantool.org>

Previously analyze functions refer to statically defined
service FuncDef context. We need to change this approach due we
going to rework the builtins functions machinery in following
patches.

Needed for #4113, #2200, #2233
---
 src/box/sql/analyze.c | 62 ++++++++++++++++---------------------------
 src/box/sql/func.c    |  2 +-
 src/box/sql/sqlInt.h  |  4 +++
 src/box/sql/vdbemem.c | 50 ----------------------------------
 4 files changed, 28 insertions(+), 90 deletions(-)

diff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c
index 9af23e985..512904cc1 100644
--- a/src/box/sql/analyze.c
+++ b/src/box/sql/analyze.c
@@ -350,18 +350,6 @@ statInit(sql_context * context, int argc, sql_value ** argv)
 	sql_result_blob(context, p, sizeof(*p), stat4Destructor);
 }
 
-static const FuncDef statInitFuncdef = {
-	3,			/* nArg */
-	0,			/* funcFlags */
-	0,			/* pUserData */
-	0,			/* pNext */
-	statInit,		/* xSFunc */
-	0,			/* xFinalize */
-	"stat_init",		/* zName */
-	{0},
-	0, false
-};
-
 /*
  * pNew and pOld are both candidate non-periodic samples selected for
  * the same column (pNew->iCol==pOld->iCol). Ignoring this column and
@@ -606,18 +594,6 @@ statPush(sql_context * context, int argc, sql_value ** argv)
 	}
 }
 
-static const FuncDef statPushFuncdef = {
-	3,			/* nArg */
-	0,			/* funcFlags */
-	0,			/* pUserData */
-	0,			/* pNext */
-	statPush,		/* xSFunc */
-	0,			/* xFinalize */
-	"stat_push",		/* zName */
-	{0},
-	0, false
-};
-
 #define STAT_GET_STAT1 0	/* "stat" column of stat1 table */
 #define STAT_GET_KEY   1	/* "key" column of stat4 entry */
 #define STAT_GET_NEQ   2	/* "neq" column of stat4 entry */
@@ -734,25 +710,16 @@ UNUSED_PARAMETER(argc);
 #endif
 }
 
-static const FuncDef statGetFuncdef = {
-	2,			/* nArg */
-	0,			/* funcFlags */
-	0,			/* pUserData */
-	0,			/* pNext */
-	statGet,		/* xSFunc */
-	0,			/* xFinalize */
-	"stat_get",		/* zName */
-	{0},
-	0, false
-};
-
 static void
 callStatGet(Vdbe * v, int regStat4, int iParam, int regOut)
 {
 	assert(regOut != regStat4 && regOut != regStat4 + 1);
 	sqlVdbeAddOp2(v, OP_Integer, iParam, regStat4 + 1);
+	struct FuncDef *func =
+		sqlFindFunction(sql_get(), "_sql_stat_get", 2, 0);
+	assert(func != NULL);
 	sqlVdbeAddOp4(v, OP_Function0, 0, regStat4, regOut,
-			  (char *)&statGetFuncdef, P4_FUNCDEF);
+		      (char *)func, P4_FUNCDEF);
 	sqlVdbeChangeP5(v, 2);
 }
 
@@ -888,8 +855,11 @@ vdbe_emit_analyze_space(struct Parse *parse, struct space *space)
 		sqlVdbeAddOp2(v, OP_Count, idx_cursor, stat4_reg + 3);
 		sqlVdbeAddOp2(v, OP_Integer, part_count, stat4_reg + 1);
 		sqlVdbeAddOp2(v, OP_Integer, part_count, stat4_reg + 2);
+		struct FuncDef *init_func =
+			sqlFindFunction(sql_get(), "_sql_stat_init", 3, 0);
+		assert(init_func != NULL);
 		sqlVdbeAddOp4(v, OP_Function0, 0, stat4_reg + 1, stat4_reg,
-				  (char *)&statInitFuncdef, P4_FUNCDEF);
+			      (char *)init_func, P4_FUNCDEF);
 		sqlVdbeChangeP5(v, 3);
 		/*
 		 * Implementation of the following:
@@ -986,8 +956,11 @@ vdbe_emit_analyze_space(struct Parse *parse, struct space *space)
 		sqlVdbeAddOp3(v, OP_MakeRecord, stat_key_reg,
 				  pk_part_count, key_reg);
 		assert(chng_reg == (stat4_reg + 1));
+		struct FuncDef *push_func =
+			sqlFindFunction(sql_get(), "_sql_stat_push", 3, 0);
+		assert(push_func != NULL);
 		sqlVdbeAddOp4(v, OP_Function0, 1, stat4_reg, tmp_reg,
-				  (char *)&statPushFuncdef, P4_FUNCDEF);
+			      (char *)push_func, P4_FUNCDEF);
 		sqlVdbeChangeP5(v, 3);
 		sqlVdbeAddOp2(v, OP_Next, idx_cursor, next_row_addr);
 		/* Add the entry to the stat1 table. */
@@ -1774,3 +1747,14 @@ fail:
 	box_txn_rollback();
 	return -1;
 }
+
+void
+sql_register_analyze_builtins(void)
+{
+	static FuncDef funcs[] = {
+		FUNCTION(_sql_stat_get, 2, 0, 0, statGet, FIELD_TYPE_ANY),
+		FUNCTION(_sql_stat_push, 3, 0, 0, statPush, FIELD_TYPE_ANY),
+		FUNCTION(_sql_stat_init, 3, 0, 0, statInit, FIELD_TYPE_ANY),
+	};
+	sqlInsertBuiltinFuncs(funcs, nelem(funcs));
+}
diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 29f2b5c6a..580571709 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -1843,7 +1843,7 @@ sqlRegisterBuiltinFunctions(void)
 		FUNCTION2(coalesce, -1, 0, 0, noopFunc, SQL_FUNC_COALESCE,
 			  FIELD_TYPE_SCALAR),
 	};
-	sqlAnalyzeFunctions();
+	sql_register_analyze_builtins();
 	sqlRegisterDateTimeFunctions();
 	sqlInsertBuiltinFuncs(aBuiltinFunc, ArraySize(aBuiltinFunc));
 
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 8ab9804fe..9f439fb07 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -4509,6 +4509,10 @@ Expr *sqlExprForVectorField(Parse *, Expr *, int);
  */
 extern int sqlSubProgramsRemaining;
 
+/** Register built-in functions to work with ANALYZE data. */
+void
+sql_register_analyze_builtins(void);
+
 /**
  * Generate VDBE code to halt execution with correct error if
  * the object with specified key is already present (or doesn't
diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
index 4e4bd597d..f52035b0e 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -1466,56 +1466,6 @@ sqlValueFromExpr(sql * db,	/* The database connection */
 	return pExpr ? valueFromExpr(db, pExpr, type, ppVal, 0) : 0;
 }
 
-/*
- * The implementation of the sql_record() function. This function accepts
- * a single argument of any type. The return value is a formatted database
- * record (a blob) containing the argument value.
- *
- * This is used to convert the value stored in the 'sample' column of the
- * sql_stat4 table to the record format sql uses internally.
- */
-static void
-recordFunc(sql_context * context, int argc, sql_value ** argv)
-{
-	const int file_format = 1;
-	u32 iSerial;		/* Serial type */
-	int nSerial;		/* Bytes of space for iSerial as varint */
-	u32 nVal;		/* Bytes of space required for argv[0] */
-	int nRet;
-	sql *db;
-	u8 *aRet;
-
-	UNUSED_PARAMETER(argc);
-	iSerial = sqlVdbeSerialType(argv[0], file_format, &nVal);
-	nSerial = sqlVarintLen(iSerial);
-	db = sql_context_db_handle(context);
-
-	nRet = 1 + nSerial + nVal;
-	aRet = sqlDbMallocRawNN(db, nRet);
-	if (aRet == 0) {
-		context->is_aborted = true;
-	} else {
-		aRet[0] = nSerial + 1;
-		putVarint32(&aRet[1], iSerial);
-		sqlVdbeSerialPut(&aRet[1 + nSerial], argv[0], iSerial);
-		sql_result_blob(context, aRet, nRet, SQL_TRANSIENT);
-		sqlDbFree(db, aRet);
-	}
-}
-
-/*
- * Register built-in functions used to help read ANALYZE data.
- */
-void
-sqlAnalyzeFunctions(void)
-{
-	static FuncDef aAnalyzeTableFuncs[] = {
-		FUNCTION(sql_record, 1, 0, 0, recordFunc, 0),
-	};
-	sqlInsertBuiltinFuncs(aAnalyzeTableFuncs,
-				  ArraySize(aAnalyzeTableFuncs));
-}
-
 /*
  * Attempt to extract a value from pExpr and use it to construct *ppVal.
  *
-- 
2.21.0

  parent reply	other threads:[~2019-07-10 11:01 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-10 11:00 [tarantool-patches] [PATCH v2 00/12] sql: uniform SQL and Lua functions subsystem Kirill Shcherbatov
2019-07-10 11:00 ` [tarantool-patches] [PATCH v2 01/12] sql: get rid of SOUNDEX, MATCH Kirill Shcherbatov
2019-07-10 18:45   ` [tarantool-patches] " Konstantin Osipov
2019-07-12  8:44   ` Kirill Yukhin
2019-07-10 11:00 ` [tarantool-patches] [PATCH v2 10/12] sql: refactor builtins signatures with port Kirill Shcherbatov
2019-07-10 18:47   ` [tarantool-patches] " Konstantin Osipov
2019-07-11  7:33     ` Kirill Shcherbatov
2019-07-10 11:00 ` [tarantool-patches] [PATCH v2 11/12] box: use own vtab per each function object Kirill Shcherbatov
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 12/12] sql: use schema's func hash instead of FuncDef hash Kirill Shcherbatov
2019-07-10 20:22   ` [tarantool-patches] " Konstantin Osipov
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 02/12] sql: get rid of LIKELY, UNLIKELY and LIKEHOOD Kirill Shcherbatov
2019-07-10 19:02   ` [tarantool-patches] " Konstantin Osipov
2019-07-11  7:38     ` Kirill Shcherbatov
2019-07-10 11:01 ` Kirill Shcherbatov [this message]
2019-07-10 19:04   ` [tarantool-patches] Re: [PATCH v2 03/12] sql: put analyze helpers to FuncDef cache Konstantin Osipov
2019-07-12  8:47   ` Kirill Yukhin
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 04/12] sql: rework LIKE case-insensitive mode Kirill Shcherbatov
2019-07-10 19:09   ` [tarantool-patches] " Konstantin Osipov
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 05/12] sql: replace bool is_derived_coll marker with flag Kirill Shcherbatov
2019-07-10 19:10   ` [tarantool-patches] " Konstantin Osipov
2019-07-12  8:48   ` Kirill Yukhin
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 06/12] sql: remove SQL_PreferBuiltin flag Kirill Shcherbatov
2019-07-10 19:11   ` [tarantool-patches] " Konstantin Osipov
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 07/12] sql: move LIKE UConverter object to collation library Kirill Shcherbatov
2019-07-12  8:49   ` [tarantool-patches] " Kirill Yukhin
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 08/12] sql: rfc for SQL and Lua functions Kirill Shcherbatov
2019-07-10 19:17   ` [tarantool-patches] " Konstantin Osipov
2019-07-10 19:18     ` Konstantin Osipov
2019-07-11  7:40       ` Kirill Shcherbatov
2019-07-11 13:59   ` Kirill Yukhin
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 09/12] box: introduce Lua persistent functions Kirill Shcherbatov
2019-07-10 19:26   ` [tarantool-patches] " Konstantin Osipov
2019-07-12 21:49   ` Konstantin Osipov
2019-07-13 13:55     ` Kirill Yukhin
2019-07-13 14:17       ` Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=df60e4bc84f0f7f8c297595618089c9c800b3274.1562756438.git.kshcherbatov@tarantool.org \
    --to=kshcherbatov@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH v2 03/12] sql: put analyze helpers to FuncDef cache' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox