From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: Kirill Shcherbatov <kshcherbatov@tarantool.org>
Cc: tarantool-patches@freelists.org,
Alexander Turenko <alexander.turenko@tarantool.org>
Subject: Re: [tarantool-patches] Re: [PATCH v2 2/2] lua: add key_def lua module
Date: Thu, 4 Apr 2019 12:05:45 +0300 [thread overview]
Message-ID: <20190404090544.ya6nvcpygtxe4eiw@esperanza> (raw)
In-Reply-To: <1a4f5fe8-c2d3-47eb-f596-a2104de182fb@tarantool.org>
On Thu, Apr 04, 2019 at 11:04:10AM +0300, Kirill Shcherbatov wrote:
> >> The code checking a tuple against key_def should live somewhere in
> >> src/box - chances are high that we miss lua/key_def.c when we extend
> >> key_def struct again.>
> > Can you suggest where it is better to place this code: src/box/key_def.c
> > or src/box/tuple.c?
> Due to the fact that this code needs table_field_by_part and
> tuple_format_min_field_count, it cannot be placed in key_def.c
> Placing it in tuple.h is not quite correct either; that's why we've got it inlined.
Well, you could put it in tuple_format.c.
>
> >> Probably, we should reuse tuple_validate() for checking a tuple against
> >> a key_def so as not to implement the same code again.
>
> Unfortunately tuple_validate() is designed for format validation while we don't
> have format here and I don't like create it for validation event in case of error.
Creating a format on each call to 'compare' is prohibitive from
performance pov, you're right. However, we could attach a format to
Lua's key_def object. This would also speed up comparisons, as tuples
created for this format would have fieldmap.
>
>
> As for assertion you've found, that is my fault; required fix doesn't increase
> code complexity (not sure about error message):
>
> @@ -243,8 +242,11 @@ lbox_key_def_check_tuple(struct lua_State *L, struct key_def *key_def, int idx)
> struct key_part *part = &key_def->parts[idx];
> const char *field = tuple_field_by_part(tuple, part);
> if (field == NULL) {
> - assert(key_def->has_optional_parts);
> - continue;
> + if (key_part_is_nullable(part))
> + continue;
> + diag_set(IllegalParams, "tuple doesn't match key "
> + "definition (part %d)", idx);
> + return NULL;
Again, mixing IllegalParams and ClientError (from key_part_validate)
doesn't look good.
Also, after this fix you don't need the min_field_count check.
However, what I don't like is that in case a tuple is created from a Lua
table, you'll have to access all fields twice - on validation and
comparison - which is costly without a fieldmap. One more argument for
attaching a format to Lua's key_def object.
> }
> if (key_part_validate(part->type, field, idx,
> key_part_is_nullable(part)) != 0)
>
>
> >> Mixing ER_WRONG_INDEX_OPTIONS and IllegalParams looks ugly. Please fix.
>
> @@ -143,8 +143,7 @@ luaT_key_def_set_part(struct lua_State *L, struct key_part_def *parts,
> size_t path_len;
> const char *path = lua_tolstring(L, -1, &path_len);
> if (json_path_validate(path, path_len, TUPLE_INDEX_BASE) != 0) {
> - diag_set(ClientError, ER_WRONG_INDEX_OPTIONS,
> - part_idx + TUPLE_INDEX_BASE, "invalid path");
> + diag_set(IllegalParams, "invalid path: \"%s\"", path);
Then you don't need to pass parts+part_idx to this function -
you can pass only the part you need to set, as it was initially
done by Alexander.
next prev parent reply other threads:[~2019-04-04 9:05 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-27 14:29 [tarantool-patches] [PATCH v2 0/2] " Kirill Shcherbatov
2019-03-27 14:29 ` [tarantool-patches] [PATCH v2 1/2] lua: add luaT_tuple_new() Kirill Shcherbatov
2019-03-28 9:01 ` [tarantool-patches] " Konstantin Osipov
2019-03-28 9:18 ` Alexander Turenko
2019-04-03 18:01 ` [tarantool-patches] " Vladimir Davydov
2019-04-04 2:51 ` Alexander Turenko
2019-04-04 8:14 ` Vladimir Davydov
2019-03-27 14:29 ` [tarantool-patches] [PATCH v2 2/2] lua: add key_def lua module Kirill Shcherbatov
2019-03-28 2:01 ` Alexander Turenko
2019-03-28 7:38 ` [tarantool-patches] " Kirill Shcherbatov
2019-03-28 8:41 ` Kirill Shcherbatov
[not found] ` <6d915212-e80f-4a6d-d884-b838bf25f8a7@tarantool.org>
2019-03-28 11:22 ` Alexander Turenko
2019-04-03 11:10 ` Vladimir Davydov
2019-04-03 11:46 ` Alexander Turenko
2019-04-03 12:01 ` Vladimir Davydov
2019-04-03 13:26 ` Alexander Turenko
2019-04-04 5:07 ` Alexander Turenko
2019-04-04 8:04 ` Kirill Shcherbatov
2019-04-04 9:05 ` Vladimir Davydov [this message]
2019-04-04 11:46 ` Alexander Turenko
2019-04-04 14:36 ` Vladimir Davydov
2019-04-04 8:38 ` Vladimir Davydov
2019-04-04 11:17 ` Alexander Turenko
2019-04-04 12:00 ` Alexander Turenko
2019-04-04 14:42 ` Vladimir Davydov
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=20190404090544.ya6nvcpygtxe4eiw@esperanza \
--to=vdavydov.dev@gmail.com \
--cc=alexander.turenko@tarantool.org \
--cc=kshcherbatov@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='Re: [tarantool-patches] Re: [PATCH v2 2/2] lua: add key_def lua module' \
/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