Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: Kirill Shcherbatov <kshcherbatov@tarantool.org>
Cc: tarantool-patches@freelists.org, kostja@tarantool.org
Subject: Re: [PATCH v5 7/9] box: tune tuple_field_raw_by_path for indexed data
Date: Sat, 1 Dec 2018 20:20:57 +0300	[thread overview]
Message-ID: <20181201172057.ewodzt376fb4hp6r@esperanza> (raw)
In-Reply-To: <42e5b2becbb0ad788d2664f329ddfa9bd29f5922.1543229303.git.kshcherbatov@tarantool.org>

On Mon, Nov 26, 2018 at 01:49:41PM +0300, Kirill Shcherbatov wrote:
> We don't need to parse tuple in tuple_field_raw_by_path if
> required field has been indexed. We do path lookup in field
> tree of JSON paths and return data by it's offset from field_map
> instead of whole tuple parsing.
> 
> Part of #1012
> ---
>  src/box/tuple_format.c     | 34 ++++++++++++++++++++++++----------
>  test/engine/tuple.result   |  5 +++++
>  test/engine/tuple.test.lua |  2 ++
>  3 files changed, 31 insertions(+), 10 deletions(-)
> 
> diff --git a/src/box/tuple_format.c b/src/box/tuple_format.c
> index 193d0d8..be89764 100644
> --- a/src/box/tuple_format.c
> +++ b/src/box/tuple_format.c
> @@ -956,15 +956,12 @@ tuple_field_raw_by_path(struct tuple_format *format, const char *tuple,
>  		goto error;
>  	switch(token.key.type) {
>  	case JSON_TOKEN_NUM: {
> -		int index = token.key.num;
> -		if (index == 0) {
> +		fieldno = token.key.num;
> +		if (fieldno == 0) {
>  			*field = NULL;
>  			return 0;
>  		}
> -		index -= TUPLE_INDEX_BASE;
> -		*field = tuple_field_raw(format, tuple, field_map, index);
> -		if (*field == NULL)
> -			return 0;
> +		fieldno -= TUPLE_INDEX_BASE;
>  		break;
>  	}
>  	case JSON_TOKEN_STR: {
> @@ -982,10 +979,9 @@ tuple_field_raw_by_path(struct tuple_format *format, const char *tuple,
>  			name_hash = field_name_hash(token.key.str,
>  						    token.key.len);
>  		}
> -		*field = tuple_field_raw_by_name(format, tuple, field_map,
> -						 token.key.str, token.key.len,
> -						 name_hash);
> -		if (*field == NULL)

After this patch tuple_field_raw_by_name and tuple_field_by_name are not
used. Please remove them in this patch.

> +		if (tuple_fieldno_by_name(format->dict, token.key.str,
> +					  token.key.len, name_hash,
> +					  &fieldno) != 0)
>  			return 0;
>  		break;
>  	}
> @@ -994,6 +990,24 @@ tuple_field_raw_by_path(struct tuple_format *format, const char *tuple,
>  		*field = NULL;
>  		return 0;
>  	}
> +	/* Optimize indexed JSON field data access. */
> +	assert(field != NULL);
> +	struct tuple_field *indexed_field =
> +		unlikely(fieldno >= tuple_format_field_count(format)) ? NULL :
> +		tuple_format_field_by_path(format,
> +					   tuple_format_field(format, fieldno),
> +					   path + lexer.offset,
> +					   path_len - lexer.offset);
> +	if (indexed_field != NULL &&
> +	    indexed_field->offset_slot != TUPLE_OFFSET_SLOT_NIL) {
> +		*field = tuple + field_map[indexed_field->offset_slot];
> +		return 0;
> +	}
> +
> +	/* No such field in index. Continue parsing JSON path. */
> +	*field = tuple_field_raw(format, tuple, field_map, fieldno);
> +	if (*field == NULL)
> +		return 0;

This code essentially does the same thing as tuple_field_by_part_raw.
Please reuse.

  reply	other threads:[~2018-12-01 17:20 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-26 10:49 [PATCH v5 0/9] box: indexes by JSON path Kirill Shcherbatov
2018-11-26 10:49 ` [PATCH v5 1/9] box: refactor json_path_parser class Kirill Shcherbatov
2018-11-26 12:53   ` [tarantool-patches] " Kirill Shcherbatov
2018-11-29 15:39     ` Vladimir Davydov
2018-11-26 10:49 ` [PATCH v5 2/9] lib: implement JSON tree class for json library Kirill Shcherbatov
2018-11-26 12:53   ` [tarantool-patches] " Kirill Shcherbatov
2018-11-29 17:38     ` Vladimir Davydov
2018-11-29 17:50       ` Vladimir Davydov
2018-12-04 15:22       ` Vladimir Davydov
2018-12-04 15:47       ` [tarantool-patches] " Kirill Shcherbatov
2018-12-04 17:54         ` Vladimir Davydov
2018-12-05  8:37           ` Kirill Shcherbatov
2018-12-05  9:07             ` Vladimir Davydov
2018-12-05  9:52               ` Vladimir Davydov
2018-12-06  7:56                 ` Kirill Shcherbatov
2018-12-06  7:56                 ` [tarantool-patches] Re: [PATCH v5 2/9] lib: make index_base support for json_lexer Kirill Shcherbatov
2018-11-26 10:49 ` [PATCH v5 3/9] box: manage format fields with JSON tree class Kirill Shcherbatov
2018-11-29 19:07   ` Vladimir Davydov
2018-12-04 15:47     ` [tarantool-patches] " Kirill Shcherbatov
2018-12-04 16:09       ` Vladimir Davydov
2018-12-04 16:32         ` Kirill Shcherbatov
2018-12-05  8:37         ` Kirill Shcherbatov
2018-12-06  7:56         ` Kirill Shcherbatov
2018-12-06  8:06           ` Vladimir Davydov
2018-11-26 10:49 ` [PATCH v5 4/9] lib: introduce json_path_cmp routine Kirill Shcherbatov
2018-11-30 10:46   ` Vladimir Davydov
2018-12-03 17:37     ` [tarantool-patches] " Konstantin Osipov
2018-12-03 18:48       ` Vladimir Davydov
2018-12-03 20:14         ` Konstantin Osipov
2018-12-06  7:56           ` [tarantool-patches] Re: [PATCH v5 4/9] lib: introduce json_path_cmp, json_path_validate Kirill Shcherbatov
2018-11-26 10:49 ` [tarantool-patches] [PATCH v5 5/9] box: introduce JSON indexes Kirill Shcherbatov
2018-11-30 21:28   ` Vladimir Davydov
2018-12-01 16:49     ` Vladimir Davydov
2018-11-26 10:49 ` [PATCH v5 6/9] box: introduce has_json_paths flag in templates Kirill Shcherbatov
2018-11-26 10:49 ` [PATCH v5 7/9] box: tune tuple_field_raw_by_path for indexed data Kirill Shcherbatov
2018-12-01 17:20   ` Vladimir Davydov [this message]
2018-11-26 10:49 ` [PATCH v5 8/9] box: introduce offset slot cache in key_part Kirill Shcherbatov
2018-12-03 21:04   ` Vladimir Davydov
2018-12-04 15:51     ` Vladimir Davydov
2018-11-26 10:49 ` [PATCH v5 9/9] box: specify indexes in user-friendly form Kirill Shcherbatov
2018-12-04 12:22   ` 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=20181201172057.ewodzt376fb4hp6r@esperanza \
    --to=vdavydov.dev@gmail.com \
    --cc=kostja@tarantool.org \
    --cc=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH v5 7/9] box: tune tuple_field_raw_by_path for indexed data' \
    /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