From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> To: "n.pettik" <korablev@tarantool.org>, tarantool-patches@freelists.org Subject: [tarantool-patches] Re: [PATCH 3/8] sql: remove numeric affinity Date: Tue, 22 Jan 2019 18:41:34 +0300 [thread overview] Message-ID: <bb4e9808-1044-3de4-0f0c-4e98e53f4e32@tarantool.org> (raw) In-Reply-To: <AAE8BC06-EFD7-467A-ADF1-7369837B277A@tarantool.org> Hi! Thanks for the fixes! On 16/01/2019 17:26, n.pettik wrote: > >>> 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. >> >> The bug is confirmed: https://github.com/tarantool/tarantool/issues/3907 >> >> I agree with Kostja - it is just a bug, that Vinyl treats differently >> integers and their double casts. It should not affect design decisions >> of this patchset. > > Ok, we may consider part of this patch as a workaround. > Now affinity removal would significantly help me to fix > other issues connected with strict typing (e.g. implicit casts). > afterwards code introduced in this commit may be simplified/removed. > I don’t know what priority of #3907 issue (milestone is 2.1.1 but > we know that sometimes it may take a while). As we agreed, it is just a Vinyl bug, and now this part of the commit message looks strange: " 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. " Here you've stated that Vinyl even for number indexes sees a difference between 2.0 and 2, but it is wrong (in an ideal world, but in our it is just a bug). It is better to write here about not a temporary bug, but about, for instance, the example I've showed you below. > >> But there is another reason why we can't pass *.0 as an iterator value - >> 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. > > Yep, it is sad. I can’t say anything more now,I need to "think about it”. Please, use this example or find another to support your decision always 'integerifying' float numbers having zero fraction. > > The only workaround I can come up right now with is to add to > every OP_Found/OP_Seek etc opcode OP_PromoteType. > It would attempt at fetching space from cursor and gently > applying types from format to record to be passed to iterator. > But this doesn’t seem to be acceptable solution for many reasons. I think, the implementation in this patch is ok. It is not necessary to create new opcodes, nor think up another solution. > > Otherwise, I have no idea how to determine required conversions > *.0 -> * without execution context. It is impossible of course. You can not learn what a value you will fetch from cursors before VDBE execution. > >> Moreover, I think, we should forbid implicit *.0 -> * This is why we >> designed strict typing, isn't it? > > It is too strict rule, ANSI allows this kind of conversion. > The only restriction is that there shouldn’t be precision loss > during conversion. It has been already discussed with > Konstantin and Peter Gulutzan, I inline part of that thread > (Topic “[dev] Re: Casts") Understood, ok. Thanks for the investigation. >>> diff --git a/src/box/sql.c b/src/box/sql.c >>> index a06c50dca..a498cd8fe 100644 >>> --- a/src/box/sql.c >>> +++ b/src/box/sql.c >>> @@ -376,14 +376,18 @@ sql_ephemeral_space_create(uint32_t field_count, struct sql_key_info *key_info) >>> for (uint32_t i = 0; i < field_count; ++i) { >>> struct key_part_def *part = &ephemer_key_parts[i]; >>> part->fieldno = i; >>> - part->type = FIELD_TYPE_SCALAR; >>> part->nullable_action = ON_CONFLICT_ACTION_NONE; >>> part->is_nullable = true; >>> part->sort_order = SORT_ORDER_ASC; >>> - if (def != NULL && i < def->part_count) >>> + if (def != NULL && i < def->part_count) { >>> + assert(def->parts[i].type < field_type_MAX); >>> + part->type = def->parts[i].type != FIELD_TYPE_ANY ? >>> + def->parts[i].type : FIELD_TYPE_SCALAR; >>> part->coll_id = def->parts[i].coll_id; >> >> 1. How can key_part have FIELD_TYPE_ANY? We have no comparators for ANY >> type, it is impossible, isn't it? > > We don’t, and that is why I replace ANY with SCALAR. No, you still check for "def->parts[i].type != FIELD_TYPE_ANY", and I can not understand how is it possible. struct key_def can not have FIELD_TYPE_ANY in its parts. > >> >>> - else >>> + } else { >>> part->coll_id = COLL_NONE; >>> + part->type = FIELD_TYPE_SCALAR; >>> + } >>> } >>> struct key_def *ephemer_key_def = key_def_new(ephemer_key_parts, >>> field_count);
next prev parent reply other threads:[~2019-01-22 15:41 UTC|newest] Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-12-28 9:34 [tarantool-patches] [PATCH 0/8] Eliminate affinity from source code Nikita Pettik 2018-12-28 9:34 ` [tarantool-patches] [PATCH 1/8] sql: remove SQLITE_ENABLE_UPDATE_DELETE_LIMIT define Nikita Pettik 2018-12-29 17:42 ` [tarantool-patches] " Vladislav Shpilevoy 2019-01-16 14:25 ` n.pettik 2018-12-28 9:34 ` [tarantool-patches] [PATCH 2/8] sql: use field type instead of affinity for type_def Nikita Pettik 2018-12-29 17:42 ` [tarantool-patches] " Vladislav Shpilevoy 2019-01-16 14:26 ` n.pettik 2018-12-28 9:34 ` [tarantool-patches] [PATCH 3/8] sql: remove numeric affinity Nikita Pettik 2018-12-29 9:01 ` [tarantool-patches] " Konstantin Osipov 2018-12-29 17:42 ` Vladislav Shpilevoy 2019-01-09 8:26 ` Konstantin Osipov 2019-01-16 14:26 ` n.pettik 2019-01-22 15:41 ` Vladislav Shpilevoy [this message] 2019-01-28 16:39 ` n.pettik 2019-01-30 13:04 ` Vladislav Shpilevoy 2019-02-01 16:39 ` n.pettik 2019-01-09 8:20 ` Konstantin Osipov 2018-12-28 9:34 ` [tarantool-patches] [PATCH 4/8] sql: replace affinity with field type for func Nikita Pettik 2018-12-28 9:34 ` [tarantool-patches] [PATCH 5/8] sql: replace field type with affinity for VDBE runtime Nikita Pettik 2018-12-29 17:42 ` [tarantool-patches] " Vladislav Shpilevoy 2019-01-16 14:26 ` n.pettik 2019-01-22 15:41 ` Vladislav Shpilevoy 2019-01-28 16:39 ` n.pettik 2019-01-30 13:04 ` Vladislav Shpilevoy 2019-02-01 16:39 ` n.pettik 2019-02-05 15:08 ` Vladislav Shpilevoy 2019-02-05 17:46 ` n.pettik 2018-12-28 9:34 ` [tarantool-patches] [PATCH 6/8] sql: replace affinity with field type in struct Expr Nikita Pettik 2018-12-29 17:42 ` [tarantool-patches] " Vladislav Shpilevoy 2019-01-16 14:26 ` n.pettik 2019-01-22 15:41 ` Vladislav Shpilevoy 2019-01-28 16:39 ` n.pettik 2019-01-30 13:04 ` Vladislav Shpilevoy 2019-02-01 16:39 ` n.pettik 2019-02-05 15:08 ` Vladislav Shpilevoy 2019-02-05 17:46 ` n.pettik 2018-12-28 9:34 ` [tarantool-patches] [PATCH 7/8] sql: clean-up affinity from SQL source code Nikita Pettik 2018-12-29 17:42 ` [tarantool-patches] " Vladislav Shpilevoy 2019-01-16 14:26 ` n.pettik 2019-01-22 15:41 ` Vladislav Shpilevoy 2019-01-28 16:40 ` n.pettik 2019-01-30 13:04 ` Vladislav Shpilevoy 2019-02-01 16:39 ` n.pettik 2019-02-05 15:08 ` Vladislav Shpilevoy 2019-02-05 17:46 ` n.pettik 2018-12-28 9:34 ` [tarantool-patches] [PATCH 8/8] Remove affinity from field definition Nikita Pettik 2019-02-05 19:41 ` [tarantool-patches] Re: [PATCH 0/8] Eliminate affinity from source code Vladislav Shpilevoy 2019-02-08 13:37 ` Kirill Yukhin
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bb4e9808-1044-3de4-0f0c-4e98e53f4e32@tarantool.org \ --to=v.shpilevoy@tarantool.org \ --cc=korablev@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='[tarantool-patches] Re: [PATCH 3/8] sql: remove numeric affinity' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox