Tarantool development patches archive
 help / color / mirror / Atom feed
From: Alexander Turenko <alexander.turenko@tarantool.org>
To: Kirill Shcherbatov <kshcherbatov@tarantool.org>
Cc: tarantool-patches@freelists.org,
	Vladimir Davydov <vdavydov.dev@gmail.com>
Subject: Re: [PATCH v2 2/2] lua: add key_def lua module
Date: Thu, 28 Mar 2019 05:01:47 +0300	[thread overview]
Message-ID: <20190328020146.lluz4mg5tacpghwv@tkn_work_nb> (raw)
In-Reply-To: <d1c3d7d8e7934279da2b8437b4e5105e27167cfd.1553696707.git.kshcherbatov@tarantool.org>

Thank you, it works like a charm.

I added a fixup commit on top of your patchset (added a test case,
updated comments in the test a bit). Also please consider comments
below.

Vladimir, I CCed you to ask a question at end of the email (the code is
on kshch/gh-4025-lua-key-kef-methods branch).

WBR, Alexander Turenko.

On Wed, Mar 27, 2019 at 05:29:28PM +0300, Kirill Shcherbatov wrote:
> There are several reasons to add this module:
> 
> * Factor out key parts parsing code from the tuples merger (#3276).
> * Support comparing a tuple with a key / a tuple, support merging
>   key_defs from Lua (#3398).
> * Support extracting a key from a tuple (#4025).
> 
> The format of `parts` parameter in the `key_def.new(parts)` call is
> compatible with the following structures:
> 
> * box.space[...].index[...].parts;
> * net_box_conn.space[...].index[...].parts.
> 
> A key_def instance has the following methods:
> 
> * :extract_key(tuple)           -> key (as tuple)
> * :compare(tuple_a, tuple_b)    -> number
> * :compare_with_key(tuple, key) -> number
> * :merge(another_key_def)       -> new key_def instance
> * :totable()                    -> table
> 

I would add here 'Functions that accept tuple(s) also allow to pass Lua
table(s) instead'.

> +static int
> +lbox_key_def_compare(struct lua_State *L)
> +{
> +	struct key_def *key_def;
> +	if (lua_gettop(L) != 3 || (key_def = check_key_def(L, 1)) == NULL) {
> +		return luaL_error(L, "Usage: key_def:"
> +				     "compare(tuple_a, tuple_b)");
> +	}
> +
> +	struct tuple *tuple_a, *tuple_b;
> +	struct tuple_format *format = box_tuple_format_default();
> +	if ((tuple_a = luaT_tuple_new(L, 2, format)) == NULL ||
> +	    tuple_validate_parts(key_def, tuple_a) != 0)
> +		return luaT_error(L);
> +	tuple_ref(tuple_a);
> +	if ((tuple_b = luaT_tuple_new(L, 3, format)) == NULL ||
> +	    tuple_validate_parts(key_def, tuple_b) != 0) {
> +		tuple_unref(tuple_a);
> +		return luaT_error(L);
> +	}
> +	tuple_ref(tuple_b);

Consider the case when a user get tuples from a local space (or merger)
and they have a format that allows to compare faster using precalculated
offsets. I think we should not create a new tuple(s) in the case.

Applicable for other functions too.

> diff --git a/src/box/tuple.h b/src/box/tuple.h
> index 8b12fd5a8..faa42fdf7 100644
> --- a/src/box/tuple.h
> +++ b/src/box/tuple.h
> @@ -672,6 +672,39 @@ tuple_field_by_part(const struct tuple *tuple, struct key_part *part)
>  				       tuple_field_map(tuple), part);
>  }
>  
> +/**
> + * Check that tuple match with the key definition.
> + * @param key_def Key definition.
> + * @param tuple Tuple for matching.
> + * @param allow_nullable True if nullable parts are allowed.
> + *
> + * @retval 0  The tuple is valid.
> + * @retval -1 The tuple is invalid.
> + */
> +static inline int
> +tuple_validate_parts(struct key_def *key_def, struct tuple *tuple)

I don't sure it worth to inline this function: it is not so lightweight
as, say, a structure field access.

I'm tentative whether this function should be in tuple.[ch] or
key_def.[ch]. What do you think?

(If it is in tuple.[ch] maybe it is better to let a tuple being the
first parameter?)

Maybe we need to ask Vladimir (CCed).

  reply	other threads:[~2019-03-28  2:01 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 [this message]
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
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=20190328020146.lluz4mg5tacpghwv@tkn_work_nb \
    --to=alexander.turenko@tarantool.org \
    --cc=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='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