[tarantool-patches] Re: [PATCH 3/8] sql: remove numeric affinity

Konstantin Osipov kostja at tarantool.org
Wed Jan 9 11:20:43 MSK 2019


* Nikita Pettik <korablev at tarantool.org> [18/12/28 12:36]:
> 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 type NUMBER), lets remove numeric
> affinity and use instead real.
> 
> The only real pitfall is implicit conversion mentioned above.
> What is more, vinyl engine complicates problem since it relies
> on data encoding (i.e. whether it is encoded as MP_INT or MP_FLOAT).
> For instance, if we encode 1.0 as MP_FLOAT during insertion, we won't
> be able to use iterators from Lua, since they implicitly change type of
> 1.0 and pass it to the iterator as MP_INT.  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.

Nikita, you're mixing up msgpack formats, msgpack types, and
tarantool types.

You're also putting some unjust blame on vinyl, while, albeit
there is a problem in vinyl, it's the responsibility of SQL layer
to encode and decode data properly.

> 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.

NUMBER is not a msgpack type, it's a tarantool type.

Msgpack data types (check out on wikipedia or in the spec) are
int, bool, float, str, bin, array, map and ext.

Tarantool data types, check out in the manual, are integer,
string, number.

We're not using msgpack data types - generally they should be
irrelevant, except perhaps on the client side, when data is
received over the binary protocol. 


-- 
Konstantin Osipov, Moscow, Russia, +7 903 626 22 32
http://tarantool.io - www.twitter.com/kostja_osipov




More information about the Tarantool-patches mailing list