From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp16.mail.ru (smtp16.mail.ru [94.100.176.153]) (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 C6084469719 for ; Thu, 17 Sep 2020 18:34:10 +0300 (MSK) Date: Thu, 17 Sep 2020 15:34:09 +0000 From: Nikita Pettik Message-ID: <20200917153409.GH10599@tarantool.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Subject: Re: [Tarantool-patches] [PATCH v5 2/6] sql: add implicit cast between numbers in OP_Seek* List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: imeevma@tarantool.org Cc: tarantool-patches@dev.tarantool.org On 21 Aug 12:19, imeevma@tarantool.org wrote: > This patch adds new rules for implicit casting between numbers in > OP_Seek * opcodes. They are still not used because the ApplyType > opcode is converting numbers, but this will be changed in the next > patch. Conversion within the ApplyType opcode can affect the > result of comparison operations. > > Part of #4230 > --- > src/box/sql/vdbe.c | 332 +++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 332 insertions(+) > > diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c > index 7405009a7..822d7e177 100644 > --- a/src/box/sql/vdbe.c > +++ b/src/box/sql/vdbe.c > @@ -522,6 +522,268 @@ mem_convert_to_numeric(struct Mem *mem, enum field_type type) > return mem_convert_to_integer(mem); > } > > +/** > + * Convert the numeric value contained in the MEM to UNSIGNED. > + * @see mem_prepare_for_cmp() for more info. > + * > + * @param mem The MEM that contains the numeric value. > + * @param[in][out] oc Operation code. > + * @retval 0 if the conversion was successful, -1 otherwise. > + */ > +static int Would be nice to see sort of table containing value/action columns, i.e. what should be done in each seprate case. These three functions are quite complicated and can contain bugs with ease. At first sight I find no obvious mistakes. > +/** > + * Convert the numeric value contained in the MEM to another > + * numeric type according to the specified operation. If the > + * conversion is successful, we will get the converted MEM. If the > + * conversion fails, the MEM will not be changed. > + * > + * @param mem The MEM that contains the numeric value. > + * @param type The type to convert to. > + * @param[in][out] oc Operation code. Just [out] - all parameters are in > + * @retval 0 if the conversion was successful, -1 otherwise. > + */ > +static int > +mem_prepare_for_cmp(struct Mem *mem, enum field_type type, int *oc, int eqOnly) Please rename according to guides eqOnly param and mention it in the comment. > +{ > + if (type == FIELD_TYPE_UNSIGNED) > + return mem_prepare_for_cmp_to_uint(mem, oc, eqOnly); > + if (type == FIELD_TYPE_INTEGER) > + return mem_prepare_for_cmp_to_int(mem, oc, eqOnly); > + assert(type == FIELD_TYPE_DOUBLE); > + return mem_prepare_for_cmp_to_double(mem, oc, eqOnly); > +} > + > /* > * pMem currently only holds a string type (or maybe a BLOB that we can > * interpret as a string if we want to). Compute its corresponding