[tarantool-patches] [PATCH v3 4/4] sql: use name instead of function pointer for UDF
Kirill Shcherbatov
kshcherbatov at tarantool.org
Mon Sep 16 15:47:12 MSK 2019
This patch changes OP_Function parameters convention: now a
function's name is passed instead of pointer to the function
object. This allows to normally handle the situation, when UDF
has been deleted to the moment of the VDBE code execution.
In particular case this may happen with CK constraints that
refers to a deleted persistent function.
---
src/box/sql/expr.c | 17 ++++++++++++-----
src/box/sql/vdbe.c | 7 ++++++-
2 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c
index 6d5ad2a27..990eaf3f1 100644
--- a/src/box/sql/expr.c
+++ b/src/box/sql/expr.c
@@ -4136,11 +4136,18 @@ sqlExprCodeTarget(Parse * pParse, Expr * pExpr, int target)
sqlVdbeAddOp4(v, OP_CollSeq, 0, 0, 0,
(char *)coll, P4_COLLSEQ);
}
- int op = func->def->language ==
- FUNC_LANGUAGE_SQL_BUILTIN ?
- OP_BuiltinFunction0 : OP_Function;
- sqlVdbeAddOp4(v, op, constMask, r1, target,
- (char *)func, P4_FUNC);
+ if (func->def->language == FUNC_LANGUAGE_SQL_BUILTIN) {
+ sqlVdbeAddOp4(v, OP_BuiltinFunction0, constMask,
+ r1, target, (char *)func,
+ P4_FUNC);
+ } else {
+ sqlVdbeAddOp4(v, OP_Function, constMask, r1,
+ target,
+ sqlDbStrNDup(pParse->db,
+ func->def->name,
+ func->def->name_len),
+ P4_DYNAMIC);
+ }
sqlVdbeChangeP5(v, (u8) nFarg);
if (nFarg && constMask == 0) {
sqlReleaseTempRange(pParse, r1, nFarg);
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 02e16da19..9a9648c1a 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -1804,7 +1804,12 @@ case OP_BuiltinFunction: {
* stored in register P3.
*/
case OP_Function: {
- struct func *func = pOp->p4.func;
+ assert(pOp->p4type == P4_DYNAMIC);
+ struct func *func = func_by_name(pOp->p4.z, strlen(pOp->p4.z));
+ if (unlikely(func == NULL)) {
+ diag_set(ClientError, ER_NO_SUCH_FUNCTION, pOp->p4.z);
+ goto abort_due_to_error;
+ }
int argc = pOp->p5;
struct Mem *argv = &aMem[pOp->p2];
struct port args, ret;
--
2.23.0
More information about the Tarantool-patches
mailing list