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 71CD224660 for ; Mon, 22 Jul 2019 15:15:29 -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 DD5pXhk5D3QB for ; Mon, 22 Jul 2019 15:15:29 -0400 (EDT) Received: from smtp39.i.mail.ru (smtp39.i.mail.ru [94.100.177.99]) (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 D9C2024681 for ; Mon, 22 Jul 2019 15:15:28 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH 6/6] sql: allow to specify UNSIGNED column type References: <734EC309-6DCF-42C2-8041-135A8B68E935@tarantool.org> <9a397d31-1cae-0dd0-cdd6-733388cb01af@tarantool.org> <552F96C1-DAC5-4F18-9F5A-BF50C6BBC205@tarantool.org> <8e4feefd-7bfb-18af-fd0f-b45384e5d2ef@tarantool.org> <127420CE-540E-439C-B2BD-20007EE98328@tarantool.org> <989f9710-043f-447a-0cc4-76eb317bc1e9@tarantool.org> <77AF4BF0-D597-425F-A4AF-EDA7EB3901C6@tarantool.org> From: Vladislav Shpilevoy Message-ID: <0cb431d6-e3f2-46a7-22dc-1c4971262ae5@tarantool.org> Date: Mon, 22 Jul 2019 21:17:16 +0200 MIME-Version: 1.0 In-Reply-To: <77AF4BF0-D597-425F-A4AF-EDA7EB3901C6@tarantool.org> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit 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: "n.pettik" , tarantool-patches@freelists.org, Kirill Yukhin Hi! TLDR: LGTM. Detailed answer below. On 22/07/2019 12:20, n.pettik wrote: > > >> On 19 Jul 2019, at 00:13, Vladislav Shpilevoy wrote: >> >> Why are you keep trying not to fix this obvious bug? >> If that path is unreachable, then either delete it, >> or add an assertion. Or fix this place. > > Sorry, message threads now seem to be entangled a bit, > so I guess you are talking about valueFromExpr() func. > I’ve removed the single reachable to this function path, > but left function itself (valueFromExpr()) since it seem > to be quite meaningful and can be applied somewhere > later. In the next patch I’ve added assertion fault to the > place of conversion of double negative values (-(-5)): No, I was talking about mem_apply_type. With the place you are talking above I agree. Sorry, I will bring your answer from another email here: > So, you want to see smth like this: > > diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c > index 73a1f321b..835544d44 100644 > --- a/src/box/sql/vdbe.c > +++ b/src/box/sql/vdbe.c > @@ -306,8 +306,6 @@ mem_apply_type(struct Mem *record, enum field_type type) > switch (type) { > case FIELD_TYPE_INTEGER: > case FIELD_TYPE_UNSIGNED: > - if ((record->flags & MEM_Int) == MEM_Int) > - return 0; > if ((record->flags & MEM_UInt) == MEM_UInt) > return 0; > if ((record->flags & MEM_Real) == MEM_Real) { > @@ -317,7 +315,14 @@ mem_apply_type(struct Mem *record, enum field_type type) > record->u.r <= -1); > return 0; > } > - return sqlVdbeMemIntegerify(record, false); > + if (sqlVdbeMemIntegerify(record, false) != 0) > + return -1; > + if ((record->flags & MEM_Int) == MEM_Int) { > + if (type == FIELD_TYPE_UNSIGNED) > + return -1; > + return 0; > + } > + return 0; > > The difference can be seen in queries like this: > > box.execute("CREATE TABLE t1 (id UNSIGNED PRIMARY KEY);") > box.execute("INSERT INTO t1 VALUES (-3);") > --- > - error: 'Type mismatch: can not convert -3 to unsigned' > … > > Without this change we got: > 'Tuple field 1 type does not match one required by operation: expected unsigned’ > > I consider this check to be a bit inappropriate since It is redundant. > Comparison between unsigned and signed is well defined; > insertion to the unsigned field is prohibited and checked in more > low level core mechanisms. I would say I don’t mind applying this > change (and already applied to speed up review process), but on > the other side I don’t understand why do we need to add extra checks > on top (SQL) layer. I agree, all the checks should be done by box when possible. The only single problem I am talking about is not a check, but a function name mismatching what it is doing. 'mem_apply_type' does not apply unsigned type to a negative value. I just feel uncomfortable about that. The function just ignores this case. I was thinking, that perhaps some day the function mem_apply_type will evolve and consume MemCast and other functions related to type conversions, and we will forget to fix this place, and will got a bug. At this moment it is not a bug, because mem_apply_type is used only before calling comparators, which check types in box. But if someday it will be used for something else, we will forget that it ignores negative -> unsigned conversion. Anyway, never mind. The patchset LGTM.