From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 92FD6230F5 for ; Tue, 9 Jul 2019 11:56:37 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1q7-0efUlm_Q for ; Tue, 9 Jul 2019 11:56:37 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 52E9020CE1 for ; Tue, 9 Jul 2019 11:56:37 -0400 (EDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.8\)) Subject: [tarantool-patches] Re: [PATCH v1 05/12] sql: put analyze helpers to FuncDef cache From: "n.pettik" In-Reply-To: Date: Tue, 9 Jul 2019 18:56:34 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <9F3E18B0-FBB3-40CC-ACF3-95003DA43EFD@tarantool.org> References: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: Kirill Shcherbatov Prior patches are OK and I guess can be pushed - they are quite trivial (except for previous one - which introduces persistent functions in Tarantool). Hence you can swap order of patches (i.e. this and previous one) so that push series of patches independently from non-trivial. Also, please fix compilation errors which appear on Travis. > On 8 Jul 2019, at 14:26, Kirill Shcherbatov = wrote: >=20 > 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. >=20 > Needed for #4113, #2200, #2233 > =E2=80=94 Unfortunately, analyze is currently disabled, so there=E2=80=99s no opportunity to check functionality of this patch :) > @@ -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 =3D=3D (stat4_reg + 1)); > + struct FuncDef *push_func =3D > + sqlFindFunction(sql_get(), "_sql_stat_push", 3, = 0); > + assert(push_func !=3D 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,58 @@ fail: > box_txn_rollback(); > return -1; > } > + > +/** > + * 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 > +sql_record_func(sql_context * context, int argc, sql_value ** argv) I guess there=E2=80=99s no need in this function at all. Could you simply remove it? > +{ > + const int file_format =3D 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 =3D sqlVdbeSerialType(argv[0], file_format, &nVal); > + nSerial =3D sqlVarintLen(iSerial); > + db =3D sql_context_db_handle(context); > + > + nRet =3D 1 + nSerial + nVal; > + aRet =3D sqlDbMallocRawNN(db, nRet); > + if (aRet =3D=3D 0) { > + context->is_aborted =3D true; > + } else { > + aRet[0] =3D nSerial + 1; > + putVarint32(&aRet[1], iSerial); > + sqlVdbeSerialPut(&aRet[1 + nSerial], argv[0], iSerial); > + sql_result_blob(context, aRet, nRet, SQL_TRANSIENT); > + sqlDbFree(db, aRet); > + } > +} > + > +#define FUNCTION_ANALYZE(zName, nArg, xFunc) \ > + {nArg, SQL_FUNC_CONSTANT, NULL, 0, xFunc, 0, #zName, {0},\ > + FIELD_TYPE_ANY, false} Could you move this macro to other FUNCTION_=E2=80=A6 ones (sqlInt.h)? > + > +void > +sql_register_analyze_builtins(void) > +{ > + static FuncDef aAnalyzeTableFuncs[] =3D { Please, use names according to our code style.