From: Kirill Shcherbatov <kshcherbatov@tarantool.org> To: tarantool-patches@freelists.org, vdavydov.dev@gmail.com Cc: kostja@tarantool.org, Kirill Shcherbatov <kshcherbatov@tarantool.org> Subject: [PATCH v6 6/8] box: tune tuple_field_raw_by_path for indexed data Date: Mon, 17 Dec 2018 09:52:50 +0300 [thread overview] Message-ID: <6806148eeaddad12fe55f85ead97b474bb96c9a6.1544995259.git.kshcherbatov@tarantool.org> (raw) In-Reply-To: <cover.1544995259.git.kshcherbatov@tarantool.org> 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.h | 19 ------------------- src/box/tuple_format.c | 23 +++++++++++------------ src/box/tuple_format.h | 24 ------------------------ test/engine/json.result | 5 +++++ test/engine/json.test.lua | 2 ++ 5 files changed, 18 insertions(+), 55 deletions(-) diff --git a/src/box/tuple.h b/src/box/tuple.h index 3c8b8825e..9d1313e93 100644 --- a/src/box/tuple.h +++ b/src/box/tuple.h @@ -547,25 +547,6 @@ tuple_field_by_path(const struct tuple *tuple, const char *path, path_hash, field); } -/** - * Get tuple field by its name. - * @param tuple Tuple to get field from. - * @param name Field name. - * @param name_len Length of @a name. - * @param name_hash Hash of @a name. - * - * @retval not NULL MessagePack field. - * @retval NULL No field with @a name. - */ -static inline const char * -tuple_field_by_name(const struct tuple *tuple, const char *name, - uint32_t name_len, uint32_t name_hash) -{ - return tuple_field_raw_by_name(tuple_format(tuple), tuple_data(tuple), - tuple_field_map(tuple), name, name_len, - name_hash); -} - /** * @brief Tuple Interator */ diff --git a/src/box/tuple_format.c b/src/box/tuple_format.c index 4314d3b1d..7eac3cf50 100644 --- a/src/box/tuple_format.c +++ b/src/box/tuple_format.c @@ -1134,10 +1134,7 @@ tuple_field_raw_by_path(struct tuple_format *format, const char *tuple, goto error; switch(token.type) { case JSON_TOKEN_NUM: { - int index = token.num; - *field = tuple_field_raw(format, tuple, field_map, index); - if (*field == NULL) - return 0; + fieldno = token.num; break; } case JSON_TOKEN_STR: { @@ -1154,10 +1151,8 @@ tuple_field_raw_by_path(struct tuple_format *format, const char *tuple, */ name_hash = field_name_hash(token.str, token.len); } - *field = tuple_field_raw_by_name(format, tuple, field_map, - token.str, token.len, - name_hash); - if (*field == NULL) + if (tuple_fieldno_by_name(format->dict, token.str, token.len, + name_hash, &fieldno) != 0) return 0; break; } @@ -1166,13 +1161,17 @@ tuple_field_raw_by_path(struct tuple_format *format, const char *tuple, *field = NULL; return 0; } - rc = tuple_field_go_to_path(field, path + lexer.offset, - path_len - lexer.offset); + /* Optimize indexed JSON field data access. */ + struct key_part part; + part.fieldno = fieldno; + part.path = (char *)path + lexer.offset; + part.path_len = path_len - lexer.offset; + rc = tuple_field_by_part_raw_slowpath(format, tuple, field_map, &part, + field); if (rc == 0) return 0; /* Setup absolute error position. */ rc += lexer.offset; - error: assert(rc > 0); diag_set(ClientError, ER_ILLEGAL_PARAMS, @@ -1189,7 +1188,7 @@ tuple_field_by_part_raw_slowpath(struct tuple_format *format, const char *data, struct tuple_field *field = tuple_format_field_by_path(format, part->fieldno, part->path, part->path_len); - if (field != NULL) { + if (field != NULL && field->offset_slot != TUPLE_OFFSET_SLOT_NIL) { int32_t offset_slot = field->offset_slot; assert(-offset_slot * sizeof(uint32_t) <= format->field_map_size); diff --git a/src/box/tuple_format.h b/src/box/tuple_format.h index 8c05c3322..a9b4bb675 100644 --- a/src/box/tuple_format.h +++ b/src/box/tuple_format.h @@ -435,30 +435,6 @@ tuple_field_raw(const struct tuple_format *format, const char *tuple, return tuple; } -/** - * Get tuple field by its name. - * @param format Tuple format. - * @param tuple MessagePack tuple's body. - * @param field_map Tuple field map. - * @param name Field name. - * @param name_len Length of @a name. - * @param name_hash Hash of @a name. - * - * @retval not NULL MessagePack field. - * @retval NULL No field with @a name. - */ -static inline const char * -tuple_field_raw_by_name(struct tuple_format *format, const char *tuple, - const uint32_t *field_map, const char *name, - uint32_t name_len, uint32_t name_hash) -{ - uint32_t fieldno; - if (tuple_fieldno_by_name(format->dict, name, name_len, name_hash, - &fieldno) != 0) - return NULL; - return tuple_field_raw(format, tuple, field_map, fieldno); -} - /** * Retrieve msgpack data by JSON path. * @param data Pointer to msgpack with data. diff --git a/test/engine/json.result b/test/engine/json.result index 7e7374e6f..c33e568b3 100644 --- a/test/engine/json.result +++ b/test/engine/json.result @@ -215,6 +215,11 @@ assert(idx2 ~= nil) t = s:insert{5, 7, {town = 'Matrix', FIO = {fname = 'Agent', sname = 'Smith'}}, 4, 5} --- ... +-- Test field_map in tuple speed-up access by indexed path. +t["[3][\"FIO\"][\"fname\"]"] +--- +- Agent +... idx:select() --- - - [5, 7, {'town': 'Matrix', 'FIO': {'fname': 'Agent', 'sname': 'Smith'}}, 4, 5] diff --git a/test/engine/json.test.lua b/test/engine/json.test.lua index 50759a5b1..45153743d 100644 --- a/test/engine/json.test.lua +++ b/test/engine/json.test.lua @@ -59,6 +59,8 @@ s:create_index('test2', {parts = {{2, 'number'}, {3, 'number', path = '["FIO"][" idx2 = s:create_index('test2', {parts = {{2, 'number'}, {3, 'str', path = '["FIO"]["fname"]'}}}) assert(idx2 ~= nil) t = s:insert{5, 7, {town = 'Matrix', FIO = {fname = 'Agent', sname = 'Smith'}}, 4, 5} +-- Test field_map in tuple speed-up access by indexed path. +t["[3][\"FIO\"][\"fname\"]"] idx:select() idx:min() idx:max() -- 2.19.2
next prev parent reply other threads:[~2018-12-17 6:52 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-12-17 6:52 [PATCH v6 0/8] box: Indexes by JSON path Kirill Shcherbatov 2018-12-17 6:52 ` [PATCH v6 1/8] box: refactor tuple_validate_raw Kirill Shcherbatov 2018-12-17 6:52 ` [PATCH v6 2/8] box: refactor ER_{FIELD_TYPE, ACTION_MISMATCH} Kirill Shcherbatov 2018-12-17 6:52 ` [PATCH v6 3/8] box: build path to field string uniformly on error Kirill Shcherbatov 2018-12-17 6:52 ` [PATCH v6 4/8] box: introduce JSON Indexes Kirill Shcherbatov 2018-12-17 6:52 ` [PATCH v6 5/8] box: introduce has_json_paths flag in templates Kirill Shcherbatov 2018-12-27 11:51 ` [tarantool-patches] " Konstantin Osipov 2018-12-27 11:52 ` Konstantin Osipov 2018-12-27 11:57 ` [tarantool-patches] " Konstantin Osipov 2018-12-17 6:52 ` Kirill Shcherbatov [this message] 2018-12-17 6:52 ` [PATCH v6 7/8] box: introduce offset_slot cache in key_part Kirill Shcherbatov 2018-12-17 6:52 ` [PATCH v6 8/8] box: specify indexes in user-friendly form Kirill Shcherbatov 2018-12-18 20:58 ` Vladimir Davydov 2018-12-18 20:46 ` [PATCH v6 0/8] box: Indexes by JSON path 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=6806148eeaddad12fe55f85ead97b474bb96c9a6.1544995259.git.kshcherbatov@tarantool.org \ --to=kshcherbatov@tarantool.org \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=vdavydov.dev@gmail.com \ --subject='Re: [PATCH v6 6/8] 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