[Tarantool-patches] [PATCH v5 2/6] sql: add implicit cast between numbers in OP_Seek*
Nikita Pettik
korablev at tarantool.org
Thu Sep 17 18:34:09 MSK 2020
On 21 Aug 12:19, imeevma at 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
More information about the Tarantool-patches
mailing list