[tarantool-patches] [PATCH v3 5/9] sql: rename OP_Function to OP_BuiltinFunction

Kirill Shcherbatov kshcherbatov at tarantool.org
Fri Aug 16 16:26:51 MSK 2019


Renamed OP_Function opcode to OP_BuiltinFunction to introduce a
new OP_Function operation in a new meaning: a new OP_Function
would call Tarantool's function with new port-based API while
legacy OP_BuiltinFunction is an efficient implementation of
SQL Builtins functions.

Needed for #2200, #4113, #2233
---
 src/box/sql/vdbeInt.h |  3 ++-
 src/box/sql/analyze.c |  8 ++++----
 src/box/sql/expr.c    |  2 +-
 src/box/sql/vdbe.c    | 29 +++++++++++++++--------------
 4 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h
index 5582d9506..f77c019fb 100644
--- a/src/box/sql/vdbeInt.h
+++ b/src/box/sql/vdbeInt.h
@@ -312,7 +312,8 @@ struct sql_context {
 	FuncDef *pFunc;		/* Pointer to function information */
 	Mem *pMem;		/* Memory cell used to store aggregate context */
 	Vdbe *pVdbe;		/* The VM that owns this context */
-	int iOp;		/* Instruction number of OP_Function */
+	/** Instruction number of OP_BuiltinFunction0. */
+	int iOp;
 	/*
 	 * True, if an error occurred during the execution of the
 	 * function.
diff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c
index 3d45adf32..bd52d12df 100644
--- a/src/box/sql/analyze.c
+++ b/src/box/sql/analyze.c
@@ -718,7 +718,7 @@ callStatGet(Vdbe * v, int regStat4, int iParam, int regOut)
 	struct FuncDef *func =
 		sqlFindFunction(sql_get(), "_sql_stat_get", 2, 0);
 	assert(func != NULL);
-	sqlVdbeAddOp4(v, OP_Function0, 0, regStat4, regOut,
+	sqlVdbeAddOp4(v, OP_BuiltinFunction0, 0, regStat4, regOut,
 		      (char *)func, P4_FUNCDEF);
 	sqlVdbeChangeP5(v, 2);
 }
@@ -858,8 +858,8 @@ vdbe_emit_analyze_space(struct Parse *parse, struct space *space)
 		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 *)init_func, P4_FUNCDEF);
+		sqlVdbeAddOp4(v, OP_BuiltinFunction0, 0, stat4_reg + 1,
+			      stat4_reg, (char *)init_func, P4_FUNCDEF);
 		sqlVdbeChangeP5(v, 3);
 		/*
 		 * Implementation of the following:
@@ -959,7 +959,7 @@ vdbe_emit_analyze_space(struct Parse *parse, struct space *space)
 		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,
+		sqlVdbeAddOp4(v, OP_BuiltinFunction0, 1, stat4_reg, tmp_reg,
 			      (char *)push_func, P4_FUNCDEF);
 		sqlVdbeChangeP5(v, 3);
 		sqlVdbeAddOp2(v, OP_Next, idx_cursor, next_row_addr);
diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c
index 88c602fde..1f9d91705 100644
--- a/src/box/sql/expr.c
+++ b/src/box/sql/expr.c
@@ -4132,7 +4132,7 @@ sqlExprCodeTarget(Parse * pParse, Expr * pExpr, int target)
 				sqlVdbeAddOp4(v, OP_CollSeq, 0, 0, 0,
 						  (char *)coll, P4_COLLSEQ);
 			}
-			sqlVdbeAddOp4(v, OP_Function0, constMask, r1,
+			sqlVdbeAddOp4(v, OP_BuiltinFunction0, constMask, r1,
 					  target, (char *)pDef, P4_FUNCDEF);
 			sqlVdbeChangeP5(v, (u8) nFarg);
 			if (nFarg && constMask == 0) {
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index e096e1f65..28552f64a 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -1664,7 +1664,7 @@ case OP_CollSeq: {
 	break;
 }
 
-/* Opcode: Function0 P1 P2 P3 P4 P5
+/* Opcode: BuiltinFunction0 P1 P2 P3 P4 P5
  * Synopsis: r[P3]=func(r[P2 at P5])
  *
  * Invoke a user function (P4 is a pointer to a FuncDef object that
@@ -1676,9 +1676,9 @@ case OP_CollSeq: {
  * function was determined to be constant at compile time. If the first
  * argument was constant then bit 0 of P1 is set.
  *
- * See also: Function, AggStep, AggFinal
+ * See also: BuiltinFunction, AggStep, AggFinal
  */
-/* Opcode: Function P1 P2 P3 P4 P5
+/* Opcode: BuiltinFunction P1 P2 P3 P4 P5
  * Synopsis: r[P3]=func(r[P2 at P5])
  *
  * Invoke a user function (P4 is a pointer to an sql_context object that
@@ -1690,16 +1690,17 @@ case OP_CollSeq: {
  * function was determined to be constant at compile time. If the first
  * argument was constant then bit 0 of P1 is set.
  *
- * SQL functions are initially coded as OP_Function0 with P4 pointing
- * to a FuncDef object.  But on first evaluation, the P4 operand is
- * automatically converted into an sql_context object and the operation
- * changed to this OP_Function opcode.  In this way, the initialization of
- * the sql_context object occurs only once, rather than once for each
- * evaluation of the function.
+ * SQL functions are initially coded as OP_BuiltinFunction0 with
+ * P4 pointing to a FuncDef object.  But on first evaluation,
+ * the P4 operand is automatically converted into an sql_context
+ * object and the operation changed to this OP_BuiltinFunction
+ * opcode.  In this way, the initialization of the sql_context
+ * object occurs only once, rather than once for each evaluation
+ * of the function.
  *
- * See also: Function0, AggStep, AggFinal
+ * See also: BuiltinFunction0, AggStep, AggFinal
  */
-case OP_Function0: {
+case OP_BuiltinFunction0: {
 	int n;
 	sql_context *pCtx;
 
@@ -1717,11 +1718,11 @@ case OP_Function0: {
 	pCtx->argc = n;
 	pOp->p4type = P4_FUNCCTX;
 	pOp->p4.pCtx = pCtx;
-	pOp->opcode = OP_Function;
-	/* Fall through into OP_Function */
+	pOp->opcode = OP_BuiltinFunction;
+	/* Fall through into OP_BuiltinFunction */
 	FALLTHROUGH;
 }
-case OP_Function: {
+case OP_BuiltinFunction: {
 	int i;
 	sql_context *pCtx;
 
-- 
2.22.1





More information about the Tarantool-patches mailing list