Skip to content
Snippets Groups Projects
Commit 758ab1a4 authored by Nikita Pettik's avatar Nikita Pettik Committed by Kirill Yukhin
Browse files

sql: remove numeric affinity

Numeric affinity in SQLite means the same as real, except that it
forces integer values into floating point representation in case
it can be converted without loss (e.g. 2.0 -> 2).
Since in Tarantool core there is no difference between numeric and real
values (both are stored as values of Tarantool type NUMBER), lets
remove numeric affinity and use instead real.

The only real pitfall is implicit conversion mentioned above.  We can't
pass *.0 as an iterator value since our fast comparators (TupleCompare,
TupleCompareWithKey) are designed to work with only values of same MP_
type. They do not use slow tuple_compare_field() which is able to
compare double and integer. Solution to this problem is simple: lets
always attempt at encoding floats as ints if conversion takes place
without loss. This is a straightforward approach, but to implement it we
need to care about reversed (decoding) situation.

OP_Column fetches from msgpack field with given number and stores it as
a native VDBE memory object. Type of that memory is based on type of
msgpack value. So, if space field is of type NUMBER and holds value 1,
type of VDBE memory will be INT (after decoding), not float 1.0.  As a
result, further calculations may be wrong: for instance, instead of
floating point division, we could get integer division.  To cope with
this problem, lets add auxiliary conversion to decoding routine which
uses space format of tuple to be decoded. It is worth mentioning that
ephemeral spaces don't feature space format, so we are going to rely on
type of key parts. Finally, internal VDBE merge sorter also operates on
entries encoded into msgpack. To fix this case, we check type of
ORDER BY/GROUP BY arguments: if they are of type float, we are emitting
additional opcode OP_AffinityReal to force float type after encoding.

Part of #3698
parent 82298c55
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment