[Tarantool-discussions] Implicit cast for COMPARISON
Mergen Imeev
imeevma at tarantool.org
Thu Feb 6 15:41:07 MSK 2020
On Tue, Feb 04, 2020 at 09:50:11PM +0300, Nikita Pettik wrote:
<cut>
> > 7) We need to clarify the rules when comparing SCALAR values. I
> > think we cannot use the Tarantool rules here, as the Tarantool
> > rules indicate that “100 < '2' == true”, but we decided that
> > "100 > '2' == true", since '2' implicitly cast to 2. Could you
> > suggest the rules that we should use here?
>
> There's already existing solution: while fetching value from space,
> we preserve its initial field type. For SCALAR values we may use one
> rules, for values fetched from INTEGER/STRING fields - apply another ones.
>
Hi,
After some thinking, I came to the conclusion that your idea is
pretty good. I suggest this algorithm for comparison:
if (has NULL)
<return NULL>
else if (same mp_type) \\MP_TYPE == MEM_TYPE here.
<compare>
else if (both numeric)
<compare>
else if (has SCALAR)
<compare using SCALAR rules>
else if (STRING compared with numeric)
<if possible cast string to number and compare, else error>
else
<error>
In this case, if we still decide to remove the implicit cast from
STRING, we can do this quite easily.
Please note that this is a simplified version. For example, we do
not always need to return NULL if one of the operands is NULL.
In addition, this implementation means that we are moving the
implicit cast for comparison from OP_ApplyType to opcodes
responsible for comparing.
What do you think about this?
More information about the Tarantool-discussions
mailing list