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 E88786F872; Fri, 30 Apr 2021 00:05:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E88786F872 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1619730322; bh=QMwOsffY/6RheFepMZaFdUfOVlf0BIuFOBNrfgGTsqg=; h=To:Cc:References:Date:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=mSm0X9U2VsRRpP7xBeg6JVCUZ8yoOp07/iqh17PV0tnwlCBcIkONdwoE1OKVBKrzf VR2aXt7mAdlz95qWAUV307iQc/R8e/Ht4+XfymkCk5XnaJ8OO+QTCYCZlqLoXl/IpC n4XcCWP2vHGA1NlxcuRnq1aj5KjefRySzLQOR7EA= Received: from smtp63.i.mail.ru (smtp63.i.mail.ru [217.69.128.43]) (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 9D4236F872 for ; Fri, 30 Apr 2021 00:05:20 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9D4236F872 Received: by smtp63.i.mail.ru with esmtpa (envelope-from ) id 1lcDqZ-0007yW-R5; Fri, 30 Apr 2021 00:05:20 +0300 To: imeevma@tarantool.org Cc: tarantool-patches@dev.tarantool.org References: <73769b1c3a358ebdbdb603592bda2353c0e6b800.1619542456.git.imeevma@gmail.com> Message-ID: Date: Thu, 29 Apr 2021 23:05:19 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <73769b1c3a358ebdbdb603592bda2353c0e6b800.1619542456.git.imeevma@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD95978C26455E69BE0BB6090B4F8997C21AA3492AFA30115D5182A05F538085040D555CE6827856FAA244EFCFDC6D63BEB997A9F265BC4953B864D7753D4903D3F X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7747FD4AFDBA6C67AEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006378B49D47CE295E66E8638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B2E15020EAA1221714912E889DED2BEB70F04B652EEC242312D2E47CDBA5A96583C09775C1D3CA48CFED8438A78DFE0A9E117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658378DA827A17800CE70F3DDF2BBF19B93A9FA2833FD35BB23DF004C90652538430302FCEF25BFAB3454AD6D5ED66289B5278DA827A17800CE74F027AFC87681B85D32BA5DBAC0009BE395957E7521B51C20BC6067A898B09E4090A508E0FED6299176DF2183F8FC7C0F1C62B71A124858CCD04E86FAF290E2D7E9C4E3C761E06A71DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6AC294AFEFA671E80089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2368A440D3B0F6089093C9A16E5BC824A2A04A2ABAA09D25379311020FFC8D4AD9380091DD32562D37C8488192658A1EA X-C1DE0DAB: 0D63561A33F958A50A3017B5BB79B91B33C264881E6E5249B9636AAEE7DD04E6D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34C75F910DBB8BE8983B47FAB436AB30ECBB2D881E9ABA888E72A555C9E0639E222277F344DC8955A71D7E09C32AA3244C9E782B05F964EAF2B4CF90BAA62843A205AB220A9D022EBC729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojVCmWsvwT1HaD8bnc1mXZjw== X-Mailru-Sender: 504CC1E875BF3E7D9BC0E5172ADA311070C1B8510446DBAA79A811E58C576AAEEF94FA4E030543D007784C02288277CA03E0582D3806FB6A5317862B1921BA260ED6CFD6382C13A6112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v2 2/3] sql: make mem_is_bin() to check only for VARBINARY 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: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thanks for working on this! See 11 comments below! On 27.04.2021 18:55, Mergen Imeev via Tarantool-patches wrote: > After this patch, the mem_is_bin() function will return 'true' only if > the value that the MEM contains is of type VARBINARY. This patch also > adds the mem_is_bin_ext() function, which is used to check if a MEM > contains value of type VARBINARY or value of types that are currently > considered VARBINARY extensions - MAP and ARRAY. > > Part of #4906 > --- > src/box/sql/func.c | 10 +++++----- > src/box/sql/mem.h | 8 +++++++- > src/box/sql/vdbe.c | 16 ++++++++-------- > 3 files changed, 20 insertions(+), 14 deletions(-) > > diff --git a/src/box/sql/func.c b/src/box/sql/func.c > index d282b2cea..bed7e8488 100644 > --- a/src/box/sql/func.c > +++ b/src/box/sql/func.c > @@ -553,7 +553,7 @@ roundFunc(sql_context * context, int argc, sql_value ** argv) > } > if (mem_is_null(argv[0])) > return; > - if (mem_is_bin(argv[0])) { > + if (mem_is_bin_ext(argv[0])) { 1. The name is quite confusing. I spent some time thinking about a better one, but can't find any. Maybe because such a function looks very strange in its purpose, as well as some of its usages. Maybe better add a function mem_is_nested() to check for MP_ARRAY and MP_MAP. Or mem_is_scalar(), which checks it is not MP_ARRAY and not MP_MAP and you call it with negation. Or add special checks for array and map. mem_is_bin_ext() would be either mem_is_bin() || mem_is_nested() or mem_is_bin() || !mem_is_scalar() or mem_is_bin() || mem_is_array() || mem_is_map() Then you would see something strange below. Why in ROUND() we check for types we do not accept instead of checking the types we do accept? I mean, why not if (!mem_is_number() && !mem_is_str()) return error; instead of if (mem_is_bin_ext()) return error; What will happen when you will add UUID, date? Will you change this on each new type like that?: if (mem_is_bin_ext() || mem_is_uuid() || mem_is_date() || ...) return error; IMO would be easier to maintain a list of supported types than a list of not supported types. Worth changing now? > diag_set(ClientError, ER_SQL_TYPE_MISMATCH, > mem_str(argv[0]), "numeric"); > context->is_aborted = true; > @@ -613,7 +613,7 @@ case_type##ICUFunc(sql_context *context, int argc, sql_value **argv) \ > const char *z2; \ > int n; \ > UNUSED_PARAMETER(argc); \ > - if (mem_is_bin(argv[0])) { \ > + if (mem_is_bin_ext(argv[0])) { \ 2. Ditto. > diag_set(ClientError, ER_INCONSISTENT_TYPES, "text", \ > "varbinary"); \ > context->is_aborted = true; \ > @@ -694,7 +694,7 @@ randomBlob(sql_context * context, int argc, sql_value ** argv) > unsigned char *p; > assert(argc == 1); > UNUSED_PARAMETER(argc); > - if (mem_is_bin(argv[0])) { > + if (mem_is_bin_ext(argv[0])) { 3. Ditto. > diag_set(ClientError, ER_SQL_TYPE_MISMATCH, > mem_str(argv[0]), "numeric"); > context->is_aborted = true; > @@ -1455,7 +1455,7 @@ trim_func_one_arg(struct sql_context *context, sql_value *arg) > const unsigned char *default_trim; > if (mem_is_null(arg)) > return; > - if (mem_is_bin(arg)) > + if (mem_is_bin_ext(arg)) 4. TBH, I would ban MP_ARRAY and MP_MAP from TRIM(). It makes 0 sense for them. I am not sure it is even tested. So we are not talking about a notable 'behaviour change' really. > default_trim = (const unsigned char *) "\0"; > else > default_trim = (const unsigned char *) " "; > @@ -1584,7 +1584,7 @@ soundexFunc(sql_context * context, int argc, sql_value ** argv) > 1, 2, 6, 2, 3, 0, 1, 0, 2, 0, 2, 0, 0, 0, 0, 0, > }; > assert(argc == 1); > - if (mem_is_bin(argv[0])) { > + if (mem_is_bin_ext(argv[0])) { 5. Ditto. > diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c > index 2308587e7..bedfa87af 100644 > --- a/src/box/sql/vdbe.c > +++ b/src/box/sql/vdbe.c > @@ -1634,9 +1634,9 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */ > "boolean"); > goto abort_due_to_error; > } > - } else if (mem_is_bin(pIn3) || mem_is_bin(pIn1)) { > + } else if (mem_is_bin_ext(pIn3) || mem_is_bin_ext(pIn1)) { > if (mem_cmp_bin(pIn3, pIn1, &res) != 0) { 6. Arrays and maps are not comparable by memcmp(). The same numbers can be encoded in MessagePack as 8 bytes and as 1 byte (you can do that legally, just not widely used). In 2 maps elements might be in different order. And obviously you can't compare map and array. Such places would draw more attention for future fixes if we wouldn't mask them behind _ext() suffix but would rather use more explicit checks. > - char *str = !mem_is_bin(pIn3) ? > + char *str = !mem_is_bin_ext(pIn3) ? > mem_type_to_str(pIn3) : > mem_type_to_str(pIn1); > diag_set(ClientError, ER_SQL_TYPE_MISMATCH, str, > @@ -2991,7 +2991,7 @@ case OP_Found: { /* jump, in3 */ > } else { > pFree = pIdxKey = sqlVdbeAllocUnpackedRecord(db, pC->key_def); > if (pIdxKey==0) goto no_mem; > - assert(mem_is_bin(pIn3)); > + assert(mem_is_bin_ext(pIn3)); 7. This would be mem_is_array() AFAIU. Because it is a tuple, right? > (void)ExpandBlob(pIn3); > sqlVdbeRecordUnpackMsgpack(pC->key_def, > pIn3->z, pIdxKey); > @@ -3253,7 +3253,7 @@ case OP_SorterData: { > assert(isSorter(pC)); > if (sqlVdbeSorterRowkey(pC, pOut) != 0) > goto abort_due_to_error; > - assert(mem_is_bin(pOut)); > + assert(mem_is_bin_ext(pOut)); 8. Ditto. > assert(pOp->p1>=0 && pOp->p1nCursor); > p->apCsr[pOp->p3]->cacheStatus = CACHE_STALE; > break; > @@ -3616,7 +3616,7 @@ case OP_SorterInsert: { /* in2 */ > assert(cursor != NULL); > assert(isSorter(cursor)); > pIn2 = &aMem[pOp->p2]; > - assert(mem_is_bin(pIn2)); > + assert(mem_is_bin_ext(pIn2)); 9. Ditto. > if (ExpandBlob(pIn2) != 0 || > sqlVdbeSorterWrite(cursor, pIn2) != 0) > goto abort_due_to_error; > @@ -3650,7 +3650,7 @@ case OP_SorterInsert: { /* in2 */ > case OP_IdxReplace: > case OP_IdxInsert: { > pIn2 = &aMem[pOp->p1]; > - assert(mem_is_bin(pIn2)); > + assert(mem_is_bin_ext(pIn2)); 10. Ditto. > if (ExpandBlob(pIn2) != 0) > goto abort_due_to_error; > struct space *space; > @@ -3741,10 +3741,10 @@ case OP_Update: { > assert(pOp->p4type == P4_SPACEPTR); > > struct Mem *key_mem = &aMem[pOp->p2]; > - assert(mem_is_bin(key_mem)); > + assert(mem_is_bin_ext(key_mem)); 11. Ditto here and below. > struct Mem *upd_fields_mem = &aMem[pOp->p3]; > - assert(mem_is_bin(upd_fields_mem)); > + assert(mem_is_bin_ext(upd_fields_mem)); > uint32_t *upd_fields = (uint32_t *)upd_fields_mem->z; > uint32_t upd_fields_cnt = upd_fields_mem->n / sizeof(uint32_t);