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 D87C06BD14; Sun, 11 Apr 2021 21:01:12 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D87C06BD14 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1618164072; bh=D9etEUP46EqHuPbP9eNcw9kW5QqUUgVAg2HZUrfiiQ0=; 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=xI3dPuTMBr9qNcvH6vpt6eGhU/2CLSlPyFCQX/3/edXK4p9lhjgEA1QUetXt5R7Qf rCJXyIsY5gWKqDvM6y3StG7rFUCN7DxRVIiu7JdKmiVGix3pjefGZYS79g2zjQ0fJN Pye5UIGqa3Kd937gPqlKD0hR7RyTRkGtzddyanUw= 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 dev.tarantool.org (Postfix) with ESMTPS id 78ED96BD13 for ; Sun, 11 Apr 2021 20:59:07 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 78ED96BD13 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1lVeMU-0002fK-GU; Sun, 11 Apr 2021 20:59:07 +0300 To: imeevma@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org References: <6724ff5d04df88fc611d4f921e6bb0b541cd5863.1617984948.git.imeevma@gmail.com> Message-ID: <3e0e446f-25b9-c904-6f2f-e263913dbe17@tarantool.org> Date: Sun, 11 Apr 2021 19:59:05 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 In-Reply-To: <6724ff5d04df88fc611d4f921e6bb0b541cd5863.1617984948.git.imeevma@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E7480D608FE24BC85426BB1B55F651FED8C70182A05F538085040C4BB4C4DA8C0747E50A2E5A849C067958DF72AB9E770CF441AE337C3EF6C5E43 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE774A7370C81A54524EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006373D332FFE8BBF4EB58638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B25C7DA18472C63D0817AA6B7D3232DAF4EBA8952C4932A151D2E47CDBA5A96583C09775C1D3CA48CFE97D2AE7161E217F117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658378DA827A17800CE7D9442B0B5983000E8941B15DA834481F9449624AB7ADAF372E808ACE2090B5E1725E5C173C3A84C3C5EA940A35A165FF2DBA43225CD8A89F00AD5422731CA18C57739F23D657EF2BB5C8C57E37DE458BEDA766A37F9254B7 X-C1DE0DAB: 0D63561A33F958A58957F83B832D5A4A314C786462F752844BEB0AA08DA0FCE7D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34CAFBC0A7A4BEEE018209631820941D279659286DF9C9F87AD1684A275AA70D9EF8AD18D9960BA22F1D7E09C32AA3244C87EDFEFF05C69945BFFE1E40E8026DA6408A6A02710B7304FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojyKKJYJ15DtJpqJRxdDn3FA== X-Mailru-Sender: 689FA8AB762F73936BC43F508A0638220627BAC11CCEF246758067D22926552A3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v5 12/52] sql: introduce mem_is_*() functions() 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 the fixes! >> For the integers we have several functions because we split >> unsigned, signed, and always negative integers. So we would >> need more int-like names. For instance, >> >> mem_set_uint(uint64_t) - for MEM_UInt. >> mem_set_nint(int64_t) - for MEM_Int. >> mem_set_int(int64_t) - for both, checks the sign inside. >> mem_set_sint(int64_t, bool) - for both, takes the sign flag >> in the second argument >> >> This can be discussed. The main point - shorter is better IMO. >> > I do not hink that splitting is needed. I see it more like field_type -> name of > function + some functions for internal use. This does not work already, because MEM_Int != FIELD_TYPE_INTEGER and mem_is_int() does not check for MEM_Int only. >>> } >>> } >>> diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c >>> index ec6aaab64..abc9291ef 100644 >>> --- a/src/box/sql/mem.c >>> +++ b/src/box/sql/mem.c >>> @@ -37,6 +37,142 @@ >>> #include "box/tuple.h" >>> #include "mpstream/mpstream.h" >>> >>> +bool >>> +mem_is_null(const struct Mem *mem) >>> +{ >>> + return (mem->flags & MEM_Null) != 0; >>> +} >> >> 4. Maybe better move them all to mem.h. These one-liners easily >> can be inlined (the ones which are <= 3 lines long could be moved). >> > In one of the patches I move MEM types to mem.c so they are not visible from > outside anymore. I think it is right way, at least for now. We may return > MEM types back after we convert them to enum, so there won't be a possiblity > of setting two or more MEM types at the same moment. But there is now already. AFAIS, MEM_Str might be set along with some other type. Or was it fixed somewhere in this patchset? See one of my comments below. >>> +} >>> + >>> +bool >>> +mem_is_frame(const struct Mem *mem) >>> +{ >>> + return (mem->flags & MEM_Frame) != 0; >>> +} >>> + >>> +bool >>> +mem_is_undefined(const struct Mem *mem) >>> +{ >>> + return (mem->flags & MEM_Undefined) != 0; >>> +} >>> + >>> +bool >>> +mem_is_static(const struct Mem *mem) >>> +{ >>> + return (mem->flags & (MEM_Str | MEM_Blob)) != 0 && >>> + (mem->flags & MEM_Static) != 0; >>> +} >>> + >>> +bool >>> +mem_is_ephemeral(const struct Mem *mem) >>> +{ >>> + return (mem->flags & (MEM_Str | MEM_Blob)) != 0 && >>> + (mem->flags & MEM_Ephem) != 0; >> >> 7. How can it be that MEM_Ephem is set, but Str/Blob are not? >> > There is actually a possiblity. After sqlVdbeMemAboutToChange() is called MEM > may become invalid after which MEM_Undefined is changed to MEM_Ephem and then Where is undefined changed to ephem? > MEM become valid again. For now I disable this SCopyFrom mechanism, but did > not remove it completely. May be we will enable it later. <...> See 4 comments below. > diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c > index 805dc7054..25b2e75ee 100644 > --- a/src/box/sql/mem.c > +++ b/src/box/sql/mem.c > @@ -40,6 +40,149 @@ <...> > + > +bool > +mem_is_map(const struct Mem *mem) > +{ > + return (mem->flags & MEM_Blob) != 0 && > + (mem->flags & MEM_Subtype) != 0 && 1. You could check that in one operation: (mem->flags & (MEM_Blob | MEM_Subtype)) == (MEM_Blob | MEM_Subtype) > + mem->subtype == SQL_SUBTYPE_MSGPACK && > + mp_typeof(*mem->z) == MP_MAP; > +} <...> > + > +bool > +mem_is_cleared(const struct Mem *mem) > +{ > + return (mem->flags & MEM_Null) != 0 && (mem->flags & MEM_Cleared) != 0; 2. Can be 1 operation: (mem->flags & (MEM_Null | MEM_Cleared)) == (MEM_Null | MEM_Cleared) But another question is how is it possible that Cleared is set, but Null isn't? > +} > + > +bool > +mem_is_zerobin(const struct Mem *mem) > +{ > + return (mem->flags & MEM_Blob) != 0 && (mem->flags & MEM_Zero) != 0; 3. The same, can be done in one operation. And the same question - how is it possible that Zero is set, but Blob isn't? > +} > diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c > index 7cc72dc38..f054a0f43 100644 > --- a/src/box/sql/vdbe.c > +++ b/src/box/sql/vdbe.c> @@ -1884,21 +1868,13 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */ > goto compare_op; > } > } else if (type == FIELD_TYPE_STRING) { > - if ((flags1 & MEM_Str) == 0 && > - (flags1 & (MEM_Int | MEM_UInt | MEM_Real)) != 0) { > - testcase( pIn1->flags & MEM_Int); > - testcase( pIn1->flags & MEM_Real); > + if (!mem_is_str(pIn1) && mem_is_num(pIn1)) { 4. Are going to do anything with that hack when a string can be stored in the same mem as the original value? Otherwise you can see yourself how ugly and confusing the 'mem_is' checks might look. Besides, all the mem functions doing something with the mem based on its pure types mask won't work on such mutant mems I suppose. Because there is more than 1 type.