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 877D66EC58; Thu, 5 Aug 2021 01:24:08 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 877D66EC58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628115848; bh=Euw+sXwcGgbNA7Wx74JFtn/Puvweds3YKGcBaCljiIY=; 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=v31wm4scCdDUHMjGcqp/ZOb5+7ZbuaZ8grmFc4dXzz6J++SKnVcoTm+gQIeBYxLwg HsymPH5ymqGCVSLEtfZmpFlcU8dxkIaDdm8vztttBPRJGIKFEx+t2tSr1VoFOPnapx 1Grf+mq7GTOFeUk+pBAhj1DLrgysgfwaZ7COxaa4= Received: from smtpng3.i.mail.ru (smtpng3.i.mail.ru [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 8BFCB6EC58 for ; Thu, 5 Aug 2021 01:24:07 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8BFCB6EC58 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1mBPJ0-0004du-Oa; Thu, 05 Aug 2021 01:24:07 +0300 To: imeevma@tarantool.org Cc: tarantool-patches@dev.tarantool.org References: <677f2d9facc0433219b12ca0b523a0691d1a39a1.1627504973.git.imeevma@gmail.com> Message-ID: <33c61d8c-1b92-1a57-247d-4cb3ade3103a@tarantool.org> Date: Thu, 5 Aug 2021 00:24:05 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <677f2d9facc0433219b12ca0b523a0691d1a39a1.1627504973.git.imeevma@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD941C43E597735A9C351B198F4576AC7B21928AAE70459C21B182A05F538085040AB38C17957C4C1B761D78165923BCA7C6C0D1081AEBE8EFB2096EF6613BFF806 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7ACC115E2004B0725EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637A69A378178A91E348638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D869C91A48677DE880B9823C2943DC485C117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC974A882099E279BDA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18E5D25F19253116ADD2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6A45692FFBBD75A6A089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B505881C34328C8F5CEE43BA0A699C12D242 X-C1DE0DAB: 0D63561A33F958A5439D2D713BDF5D624C5C2B2B9CB81DA4AFAFE3762B7F5AA0D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7501A9DF589746230F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3453741B480A6503C318C4C90AE4E8B13D769265B3941685056319B7E34121807A3ED1DED342C969141D7E09C32AA3244CD5444296775993284EBD64B355ED1086E3D93501275E802F729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojh4v93/7HD3Un8csgMrLVeA== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DE71CA51D974D1588B356B20E6593274F3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v1 2/7] sql: remove implicit cast from comparison opcodes 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 patch! See 5 comments below. > diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c > index e804dba67..b04303be2 100644 > --- a/src/box/sql/mem.c > +++ b/src/box/sql/mem.c > @@ -1976,25 +2000,21 @@ mem_bit_not(const struct Mem *mem, struct Mem *result) > return 0; > } > > -int > -mem_cmp_bool(const struct Mem *a, const struct Mem *b, int *result) > +static int > +mem_cmp_bool(const struct Mem *a, const struct Mem *b) > { > - if ((a->type & b->type & MEM_TYPE_BOOL) == 0) > - return -1; > + assert((a->type & b->type & MEM_TYPE_BOOL) != 0); > if (a->u.b == b->u.b) > - *result = 0; > - else if (a->u.b) > - *result = 1; > - else > - *result = -1; > - return 0; > + return 0; > + if (a->u.b) > + return 1; > + return -1; 1. Could be simpler: ==================== @@ -2004,11 +2004,7 @@ static int mem_cmp_bool(const struct Mem *a, const struct Mem *b) { assert((a->type & b->type & MEM_TYPE_BOOL) != 0); - if (a->u.b == b->u.b) - return 0; - if (a->u.b) - return 1; - return -1; + return a->u.b - b->u.b; } ==================== > @@ -2245,8 +2189,11 @@ mem_cmp_msgpack(const struct Mem *a, const char **b, int *result, > if (type == MP_UUID) { > assert(len == UUID_LEN); > mem.type = MEM_TYPE_UUID; > - if (uuid_unpack(b, len, &mem.u.uuid) == NULL) > + if (uuid_unpack(b, len, &mem.u.uuid) == NULL) { > + diag_set(ClientError, ER_SQL_EXECUTE, > + "cannot parse UUID"); 2. Shouldn't this be a separate commit as a bugfix? > return -1; > + } > break; > } > diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c > index d143ce364..62f58def9 100644 > --- a/src/box/sql/vdbe.c > +++ b/src/box/sql/vdbe.c <...> > - switch( pOp->opcode) { > - case OP_Eq: res2 = res==0; break; > - case OP_Ne: res2 = res; break; > - case OP_Lt: res2 = res<0; break; > - case OP_Le: res2 = res<=0; break; > - case OP_Gt: res2 = res>0; break; > - default: res2 = res>=0; break; > + bool result; > + switch(pOp->opcode) { 3. It does not look good to have a second switch-case here. But I can't find a better solution right away. We can't wrap this all into a function, because need to make goto abort_due_to_error and goto jump_to_p2 in some places. Up to you if you want to find a way to fix it. As a side note, the code now is incomparably simpler than it was. It is getting actually understable, nice. > + case OP_Eq: > + result = cmp_res == 0; > + break; > + case OP_Ne: > + result = cmp_res != 0; > + break; > + case OP_Lt: > + result = cmp_res < 0; > + break; > + case OP_Le: > + result = cmp_res <= 0; > + break; > + case OP_Gt: > + result = cmp_res > 0; > + break; > + case OP_Ge: > + result = cmp_res >= 0; > + break; > + default: > + unreachable(); > } > diff --git a/test/sql-tap/transitive1.test.lua b/test/sql-tap/transitive1.test.lua > index dbc2559fa..2d502f5e8 100755 > --- a/test/sql-tap/transitive1.test.lua > +++ b/test/sql-tap/transitive1.test.lua > @@ -73,7 +73,7 @@ test:do_execsql_test( > test:do_execsql_test( > "transitive1-210", > [[ > - SELECT a,b,c FROM t2 WHERE a=b AND c=b AND c>='20' ORDER BY +a; > + SELECT a,b,c FROM t2 WHERE a = b AND c >= '20' ORDER BY +a; 4. Might worth adding whitespaces after ',' in the select list. > ]], { > -- > 3, 3, "3", 20, 20, "20" > diff --git a/test/sql/boolean.result b/test/sql/boolean.result > index d54de8fe7..81d79ee78 100644 > --- a/test/sql/boolean.result > +++ b/test/sql/boolean.result > @@ -4898,12 +4898,12 @@ SELECT a1, a1 != 2.3 FROM t6 > SELECT a1, 2.3 == a1 FROM t6 > | --- > | - null > - | - 'Type mismatch: can not convert double(2.3) to boolean' > + | - 'Type mismatch: can not convert boolean(FALSE) to number' 5. Is it possible to keep the old error messages? For the sake of smaller diff.