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
Showing
- src/box/field_def.h 0 additions, 1 deletionsrc/box/field_def.h
- src/box/lua/lua_sql.c 1 addition, 1 deletionsrc/box/lua/lua_sql.c
- src/box/sql.c 6 additions, 3 deletionssrc/box/sql.c
- src/box/sql/build.c 0 additions, 1 deletionsrc/box/sql/build.c
- src/box/sql/expr.c 12 additions, 9 deletionssrc/box/sql/expr.c
- src/box/sql/select.c 7 additions, 3 deletionssrc/box/sql/select.c
- src/box/sql/sqliteInt.h 1 addition, 1 deletionsrc/box/sql/sqliteInt.h
- src/box/sql/vdbe.c 18 additions, 8 deletionssrc/box/sql/vdbe.c
- src/box/sql/vdbemem.c 17 additions, 7 deletionssrc/box/sql/vdbemem.c
- test/sql-tap/tkt-80e031a00f.test.lua 6 additions, 6 deletionstest/sql-tap/tkt-80e031a00f.test.lua
Loading
Please register or sign in to comment