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 704296BD19; Tue, 13 Apr 2021 02:31:43 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 704296BD19 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1618270303; bh=KUPA2sYYQOZJEha5LUnXD+uteciLpnrcaOb7Wx2XN+g=; 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=Za2G0sb7hZRccpR/qNfKGCPJnacc5pIVr/Epu58E0CkibUTtlzFOczeWSI7wmZa3F Q2zdUsCeyTmA36FmPKasDwyvwnGwz75xy4i8fKRetC+WafBvTISnHVYHZFjY4laeMi lwRkvfuFWKSM/zdcMVdmWjEOkhMcqraDHkWUd7IQ= 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 8DB4B6BD19 for ; Tue, 13 Apr 2021 02:31:41 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8DB4B6BD19 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1lW61s-0002Dz-LR; Tue, 13 Apr 2021 02:31:41 +0300 To: imeevma@tarantool.org, tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org References: Message-ID: Date: Tue, 13 Apr 2021 01:31:39 +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: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E74806859AC5FE18436AEED970E897805ADA4182A05F53808504035384459B6F7A20C914DDB547EA25A1BD7CABCB6A1C6366FD43DCB530941A0DB X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE788A2BECDB72E1542EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637651D61939D0B3DD78638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B2659D1F29DEC21C7777D77487147BCF9D3896EE2C32233946D2E47CDBA5A96583C09775C1D3CA48CF253F27DA5A70FAF3117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658378DA827A17800CE7ECE82AE7387CF2AD9FA2833FD35BB23DF004C906525384302BEBFE083D3B9BA73A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E73564E4DC1543031AB7C4224003CC83647689D4C264860C145E X-C1DE0DAB: 0D63561A33F958A5C640E67701120170840FE9263A247D77FD43183685B269F0D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7502E6951B79FF9A3F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D344EF254DC71474AA35D8159A4805256DC42B861FF5815A6FAF6F22FE8EFB07AEE00407B5C9F5034FF1D7E09C32AA3244CEE82B16687451656CC75A61A9FFBCFA3A95CA90A1D8AC565FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojq8JA+pXcDukycr0cR75rzA== X-Mailru-Sender: 689FA8AB762F73936BC43F508A0638223BD4F1C50A06E933669D9F9824A754B73841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v5 21/52] sql: introduce bitwise operations for MEM 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" Hi! Thanks for the fixes! See 2 comments below. > diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c > index eee72a7fe..aeb801c7c 100644 > --- a/src/box/sql/mem.c > +++ b/src/box/sql/mem.c > @@ -624,6 +624,115 @@ mem_rem(const struct Mem *left, const struct Mem *right, struct Mem *result) <...> > + > +int > +mem_shift_right(const struct Mem *left, const struct Mem *right, > + struct Mem *result) > +{ > + if (is_result_null(left, right, result, FIELD_TYPE_INTEGER)) > + return 0; > + int64_t a; > + int64_t b; > + if (bitwise_prepare(left, right, &a, &b) != 0) > + return -1; > + if (b <= -64) > + result->u.i = 0; > + else if (b < 0) > + result->u.i = a << -b; > + else if (b > 64) > + result->u.i = a >= 0 ? 0 : -1; > + else > + result->u.i = a >> b; 1. Right shit has different meaning for negative and positive numbers. This code produces invalid output: tarantool> box.execute('SELECT 9223372036854775808 >> 3') --- - metadata: - name: COLUMN_1 type: integer rows: - [-1152921504606846976] ... The number should have decreased, but it should not have changed its sign. It should be 1152921504606846976, positive. But I see the same bug exists on the master branch, even though it had special handling for negative numbers, which is also broken. Is there a ticket for that? Can you fix it right away? > + result->flags = result->u.i < 0 ? MEM_Int : MEM_UInt; > + return 0; > +} > + > +int > +mem_bit_not(const struct Mem *mem, struct Mem *result) > +{ > + mem_clear(result); > + result->field_type = FIELD_TYPE_INTEGER; > + if ((mem->flags & MEM_Null) != 0) > + return 0; > + int64_t i; > + bool unused; > + if (sqlVdbeIntValue(mem, &i, &unused) != 0) { > + diag_set(ClientError, ER_SQL_TYPE_MISMATCH, mem_str(mem), > + "integer"); > + return -1; > + } > + result->u.i = ~i; > + result->flags = result->u.i < 0 ? MEM_Int : MEM_UInt; 2. What if the original value was positive, and the user also expected to get a positive result? For example, what if he did ~CAST(value AS UNSIGNED)? Or is it useless and I am expected to do CAST(~value as UNSIGNED)?