Tarantool development patches archive
 help / color / mirror / Atom feed
From: Konstantin Osipov <kostja.osipov@gmail.com>
To: tarantool-patches@freelists.org
Cc: vdavydov.dev@gmail.com, alexander.turenko@tarantool.org,
	Kirill Shcherbatov <kshcherbatov@tarantool.org>
Subject: Re: [tarantool-patches] [PATCH v3 1/1] lua: add key_def lua module
Date: Wed, 24 Apr 2019 21:13:02 +0300	[thread overview]
Message-ID: <20190424181302.GG13687@atlas> (raw)
In-Reply-To: <f554aadad77a9fc316e42cdfabd57e1b0158cbfc.1555935845.git.kshcherbatov@tarantool.org>

* Kirill Shcherbatov <kshcherbatov@tarantool.org> [19/04/22 17:40]:
> --- a/src/box/errcode.h
> +++ b/src/box/errcode.h
> @@ -246,6 +246,7 @@ struct errcode_record {
>  	/*191 */_(ER_SQL_PARSER_LIMIT,		"%s %d exceeds the limit (%d)") \
>  	/*192 */_(ER_INDEX_DEF_UNSUPPORTED,	"%s are prohibited in an index definition") \
>  	/*193 */_(ER_CK_DEF_UNSUPPORTED,	"%s are prohibited in a CHECK constraint definition") \
> +	/*194 */_(ER_TUPLE_KEY_PART_MISSED,	"Supplied tuple field for part %u does not exists") \

I don't understand this error message. 
Besides key part number, the message should contain field name or
number.

Besides, we already have ER_NO_SUCH_FIELD_NO and
why not use it?


ER_NO_FIELD_FOR_KEY_PART "The supplied tuple has no field %s for key part %u"

> +
> +static uint32_t key_def_type_id = 0;

Please rename to key_def_ctype_id

> +static int
> +lbox_key_def_compare(struct lua_State *L)
> +{
> +	struct key_def *key_def;
> +	if (lua_gettop(L) != 3 ||
> +	    (key_def = luaT_check_key_def(L, 1)) == NULL) {
> +		return luaL_error(L, "Usage: key_def:"
> +				     "compare(tuple_a, tuple_b)");
> +	}
> +
> +	struct tuple *tuple_a, *tuple_b;
> +	if ((tuple_a = luaT_key_def_check_tuple(L, key_def, 2)) == NULL)
> +		return luaT_error(L);
> +	if ((tuple_b = luaT_key_def_check_tuple(L, key_def, 3)) == NULL) {
> +		tuple_unref(tuple_a);
> +		return luaT_error(L);
> +	}

Invoking tuple_validate and possibly tuple_new on each compare is
awfully slow.
> +static int
> +lbox_key_def_compare_with_key(struct lua_State *L)
> +{
> +	struct key_def *key_def;
> +	if (lua_gettop(L) != 3 ||
> +	    (key_def = luaT_check_key_def(L, 1)) == NULL) {
> +		return luaL_error(L, "Usage: key_def:"
> +				     "compare_with_key(tuple, key)");
> +	}
> +
> +	struct tuple *tuple = luaT_key_def_check_tuple(L, key_def, 2);
> +	if (tuple == NULL)
> +		return luaT_error(L);
> +
> +	size_t key_len;
> +	const char *key = lbox_encode_tuple_on_gc(L, 3, &key_len);
> +	uint32_t part_count = mp_decode_array(&key);
> +	if (key_validate_parts(key_def, key, part_count, true) != 0) {
> +		tuple_unref(tuple);
> +		return luaT_error(L);
> +	}
> +
> +	int rc = tuple_compare_with_key(tuple, key, part_count, key_def);
> +	tuple_unref(tuple);
> +	lua_pushinteger(L, rc);
> +	return 1;
> +}

This also looks as a terribly inefficient implementation for
compare.

Overall, the API looks good to me, while the implementation seems
to be too inefficient. I would consider changing extract_key() to
return char *, not struct tuple, the buffer could be allocated on
transaction region. I also think that compare should not allocate
memory or create tuples, and it should not call tuple_validate()
either.

If this is urgent, I would push since the code quality is very
good and the api would stable, but I don't see how soo inefficient
compare functions could be useful.

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

  reply	other threads:[~2019-04-24 18:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-22 12:28 Kirill Shcherbatov
2019-04-24 18:13 ` Konstantin Osipov [this message]
2019-04-25  8:42   ` [tarantool-patches] " Alexander Turenko
2019-04-30 10:30 ` Vladimir Davydov
2019-05-06 15:27   ` [tarantool-patches] " Kirill Shcherbatov
2019-05-06 15:35     ` Alexander Turenko
2019-05-06 16:25     ` 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=20190424181302.GG13687@atlas \
    --to=kostja.osipov@gmail.com \
    --cc=alexander.turenko@tarantool.org \
    --cc=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [tarantool-patches] [PATCH v3 1/1] 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