From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 591826EC40; Thu, 19 Aug 2021 08:33:13 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 591826EC40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1629351193; bh=8MrEMI7SDOo5IqvFQGBTD2CtEfSsYLwnPJ7pNxy/85c=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=rTIga9U0C2H/sdNYDjjgP/96ow0wYMwZUoN8Mdm4mhOI/JulSqqzBvK3vb6f+Md+K UK87c2ChkG4ahhACVaEIFjGh2agsp4V8uiObUF07TgnjfxOnWhOz1CViuXfv6NKqoy 2d78OMydsFwb38QRlGPKv8h8gUsWOJdSqJIG8E6w= Received: from smtpng2.i.mail.ru (smtpng2.i.mail.ru [94.100.179.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 4F0256EC45 for ; Thu, 19 Aug 2021 08:31:31 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4F0256EC45 Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1mGaeI-000099-Gn; Thu, 19 Aug 2021 08:31:30 +0300 To: vdavydov@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Thu, 19 Aug 2021 08:31:30 +0300 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD972FF4A7D76DB5E242D14FEF1BD8BF4AC182A05F538085040FF50B53D8E8195400EC3AD908A3C3F957C660E71C44A277A57BDBE8FBA478AAE X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE77603ADE015AF816DEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637222645A8BD7B05AE8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8EB14D5255EB46116E055DD4F2C4F8098117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6300D3B61E77C8D3B089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CF160826E4E1956AE65740194C996A9604E793B2602CC1E979C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF5A3EDA775A1E0ED0699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34CA9B3B5DE5D383E6A5D9B4DB6411F117A5B2C71AFDB99FF7E2C47482C3730EB7C163EAA8C49235AC1D7E09C32AA3244C61953F581EE5FA15E0DD118A29F82E5B4DBEAD0ED6C55A80729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojGSxK+6r6oBFbuMNJ58FsxA== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DB0B2BD2AED69253A9AAD797B1779B58783D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v2 3/5] sql: remove struct func from struct sql_context X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mergen Imeev via Tarantool-patches Reply-To: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This patch removes struct func from struct sql_context since we don't need the functionality of struct func here. Without this structure, we can make it easier to work with SQL built-in functions. Part of #6105 --- src/box/sql/func.c | 123 +++++++++++++++++++++++++++++++++++++----- src/box/sql/vdbe.c | 8 +-- src/box/sql/vdbeInt.h | 6 ++- src/box/sql/vdbeaux.c | 5 +- 4 files changed, 119 insertions(+), 23 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 4a0d2d097..adbc6d5a4 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -132,8 +132,7 @@ minmaxFunc(sql_context * context, int argc, sql_value ** argv) int i; int iBest; struct coll *pColl; - struct func *func = context->func; - int mask = sql_func_flag_is_set(func, SQL_FUNC_MAX) ? -1 : 0; + int mask = (context->flags & SQL_FUNC_MAX) != 0 ? -1 : 0; if (argc < 2) { diag_set(ClientError, ER_FUNC_WRONG_ARG_COUNT, mask ? "GREATEST" : "LEAST", "at least two", argc); @@ -1799,8 +1798,6 @@ minmaxStep(sql_context * context, int NotUsed, sql_value ** argv) Mem *pBest; UNUSED_PARAMETER(NotUsed); - struct func_sql_builtin *func = - (struct func_sql_builtin *)context->func; pBest = sql_context_agg_mem(context); if (!pBest) return; @@ -1816,7 +1813,7 @@ minmaxStep(sql_context * context, int NotUsed, sql_value ** argv) * between the two being that the sense of the * comparison is inverted. */ - bool is_max = (func->flags & SQL_FUNC_MAX) != 0; + bool is_max = (context->flags & SQL_FUNC_MAX) != 0; int cmp = mem_cmp_scalar(pBest, pArg, pColl); if ((is_max && cmp < 0) || (!is_max && cmp > 0)) { mem_copy(pBest, pArg); @@ -1930,9 +1927,7 @@ static void sql_builtin_stub(sql_context *ctx, int argc, sql_value **argv) { (void) argc; (void) argv; - diag_set(ClientError, ER_SQL_EXECUTE, - tt_sprintf("function '%s' is not implemented", - ctx->func->def->name)); + diag_set(ClientError, ER_SQL_EXECUTE, "function is not implemented"); ctx->is_aborted = true; } @@ -2886,20 +2881,124 @@ int sql_emit_func_call(struct Vdbe *vdbe, struct Expr *expr, int op, int mask, int r1, int r2, uint8_t argc) { - struct func *func = sql_func_find(expr); - if (func == NULL) - return -1; uint32_t size = sizeof(struct sql_context); if (argc > 1) size += (argc - 1) * sizeof(struct Mem); struct sql_context *ctx = sqlDbMallocRawNN(sql_get(), size); if (ctx == NULL) return -1; + switch(expr->func_id) { + case TK_ABS: + ctx->call = absFunc; + break; + case TK_AVG: + case TK_SUM: + ctx->call = sum_step; + break; + case TK_CHAR: + ctx->call = charFunc; + break; + case TK_CHAR_LEN: + case TK_LENGTH: + ctx->call = lengthFunc; + break; + case TK_COALESCE: + case TK_IFNULL: + case TK_LIKELIHOOD: + case TK_LIKELY: + case TK_UNLIKELY: + ctx->call = sql_builtin_stub; + break; + case TK_COUNT: + ctx->call = countStep; + break; + case TK_GREATEST: + case TK_LEAST: + ctx->call = minmaxFunc; + break; + case TK_GROUP_CONCAT: + ctx->call = groupConcatStep; + break; + case TK_HEX: + ctx->call = hexFunc; + break; + case TK_LIKE_KW: + ctx->call = likeFunc; + break; + case TK_LOWER: + ctx->call = LowerICUFunc; + break; + case TK_MAX: + case TK_MIN: + ctx->call = minmaxStep; + break; + case TK_NULLIF: + ctx->call = nullifFunc; + break; + case TK_POSITION: + ctx->call = position_func; + break; + case TK_PRINTF: + ctx->call = printfFunc; + break; + case TK_QUOTE: + ctx->call = quoteFunc; + break; + case TK_RANDOM: + ctx->call = randomFunc; + break; + case TK_RANDOMBLOB: + ctx->call = randomBlob; + break; + case TK_REPLACE: + ctx->call = replaceFunc; + break; + case TK_ROUND: + ctx->call = roundFunc; + break; + case TK_ROW_COUNT: + ctx->call = sql_row_count; + break; + case TK_SOUNDEX: + ctx->call = soundexFunc; + break; + case TK_SUBSTR: + ctx->call = substrFunc; + break; + case TK_TOTAL: + ctx->call = total_step; + break; + case TK_TRIM: + ctx->call = trim_func; + break; + case TK_TYPEOF: + ctx->call = typeofFunc; + break; + case TK_UNICODE: + ctx->call = unicodeFunc; + break; + case TK_UPPER: + ctx->call = UpperICUFunc; + break; + case TK_UUID: + ctx->call = sql_func_uuid; + break; + case TK_VERSION: + ctx->call = sql_func_version; + break; + case TK_ZEROBLOB: + ctx->call = zeroblobFunc; + break; + default: + unreachable(); + } + assert(strlen(expr->u.zToken) < 24); + strcpy(ctx->name, expr->u.zToken); ctx->pOut = NULL; - ctx->func = func; ctx->iOp = 0; ctx->pVdbe = vdbe; ctx->argc = argc; + ctx->flags = sql_func_flags(expr->func_id); sqlVdbeAddOp4(vdbe, op, mask, r1, r2, (char *)ctx, P4_FUNCCTX); sqlVdbeChangeP5(vdbe, argc); return 0; diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index 9fb103e82..c63dbaa5a 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -1221,9 +1221,7 @@ case OP_BuiltinFunction: { } #endif pCtx->is_aborted = false; - assert(pCtx->func->def->language == FUNC_LANGUAGE_SQL_BUILTIN); - struct func_sql_builtin *func = (struct func_sql_builtin *)pCtx->func; - func->call(pCtx, pCtx->argc, pCtx->argv); + pCtx->call(pCtx, pCtx->argc, pCtx->argv); /* If the function returned an error, throw an exception */ if (pCtx->is_aborted) @@ -4185,9 +4183,7 @@ case OP_AggStep: { pCtx->pOut = &t; pCtx->is_aborted = false; pCtx->skipFlag = 0; - assert(pCtx->func->def->language == FUNC_LANGUAGE_SQL_BUILTIN); - struct func_sql_builtin *func = (struct func_sql_builtin *)pCtx->func; - func->call(pCtx, pCtx->argc, pCtx->argv); + pCtx->call(pCtx, pCtx->argc, pCtx->argv); if (pCtx->is_aborted) { mem_destroy(&t); goto abort_due_to_error; diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h index 073ac0b97..0a0e6cc97 100644 --- a/src/box/sql/vdbeInt.h +++ b/src/box/sql/vdbeInt.h @@ -169,9 +169,8 @@ struct VdbeFrame { * (Mem) which are only defined there. */ struct sql_context { + char name[24]; Mem *pOut; /* The return value is stored here */ - /* A pointer to function implementation. */ - struct func *func; Mem *pMem; /* Memory cell used to store aggregate context */ Vdbe *pVdbe; /* The VM that owns this context */ /** Instruction number of OP_BuiltinFunction or OP_AggStep. */ @@ -183,6 +182,9 @@ struct sql_context { bool is_aborted; u8 skipFlag; /* Skip accumulator loading if true */ u8 argc; /* Number of arguments */ + uint32_t flags; + /* Implementation of SQL built-in function. */ + void (*call)(struct sql_context *ctx, int argc, struct Mem **argv); sql_value *argv[1]; /* Argument set */ }; diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c index 662fbbf81..3913dc637 100644 --- a/src/box/sql/vdbeaux.c +++ b/src/box/sql/vdbeaux.c @@ -1070,9 +1070,8 @@ displayP4(Op * pOp, char *zTemp, int nTemp) } #if defined(SQL_DEBUG) || defined(VDBE_PROFILE) case P4_FUNCCTX:{ - struct func *func = pOp->p4.pCtx->func; - sqlXPrintf(&x, "%s(%d)", func->def->name, - func->def->param_count); + sqlXPrintf(&x, "%s(%d)", pOp->p4.pCtx->name, + pOp->p4.pCtx->argc); break; } #endif -- 2.25.1