From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org
Cc: vdavydov.dev@gmail.com, Kirill Shcherbatov <kshcherbatov@tarantool.org>
Subject: [PATCH v5 10/12] box: tune tuple_field_raw_by_path for indexed data
Date: Mon, 29 Oct 2018 09:56:31 +0300 [thread overview]
Message-ID: <7a44e73bcc4c3b2780be79360c720f7cfec9dbe4.1540795996.git.kshcherbatov@tarantool.org> (raw)
In-Reply-To: <cover.1540795996.git.kshcherbatov@tarantool.org>
In-Reply-To: <cover.1540795996.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_format.c | 32 +++++++++++++++++++++++---------
test/engine/tuple.result | 5 +++++
test/engine/tuple.test.lua | 2 ++
3 files changed, 30 insertions(+), 9 deletions(-)
diff --git a/src/box/tuple_format.c b/src/box/tuple_format.c
index 151d9e5..920968c 100644
--- a/src/box/tuple_format.c
+++ b/src/box/tuple_format.c
@@ -928,15 +928,12 @@ tuple_field_raw_by_path(struct tuple_format *format, const char *tuple,
goto error;
switch(node.type) {
case JSON_PATH_NUM: {
- int index = node.num;
- if (index == 0) {
+ fieldno = node.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_PATH_STR: {
@@ -953,9 +950,8 @@ tuple_field_raw_by_path(struct tuple_format *format, const char *tuple,
*/
name_hash = field_name_hash(node.str, node.len);
}
- *field = tuple_field_raw_by_name(format, tuple, field_map,
- node.str, node.len, name_hash);
- if (*field == NULL)
+ if (tuple_fieldno_by_name(format->dict, node.str, node.len,
+ name_hash, &fieldno) != 0)
return 0;
break;
}
@@ -964,6 +960,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 + parser.offset,
+ path_len - parser.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;
rc = tuple_field_go_to_path(field, path + parser.offset,
path_len - parser.offset);
if (rc == 0)
diff --git a/test/engine/tuple.result b/test/engine/tuple.result
index 9a1ceb8..92927a0 100644
--- a/test/engine/tuple.result
+++ b/test/engine/tuple.result
@@ -1148,6 +1148,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/tuple.test.lua b/test/engine/tuple.test.lua
index f1000dd..9e6807e 100644
--- a/test/engine/tuple.test.lua
+++ b/test/engine/tuple.test.lua
@@ -367,6 +367,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.7.4
next prev parent reply other threads:[~2018-10-29 6:56 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-29 6:56 [PATCH v5 00/12] box: indexes by JSON path Kirill Shcherbatov
2018-10-29 6:56 ` [PATCH v5 01/12] box: refactor key_def_find routine Kirill Shcherbatov
2018-11-19 17:48 ` Vladimir Davydov
2018-10-29 6:56 ` Kirill Shcherbatov [this message]
2018-10-29 6:56 ` [PATCH v5 11/12] box: introduce offset slot cache in key_part Kirill Shcherbatov
2018-11-01 13:32 ` [tarantool-patches] " Konstantin Osipov
2018-11-06 12:15 ` [tarantool-patches] " Kirill Shcherbatov
2018-10-29 6:56 ` [PATCH v5 12/12] box: specify indexes in user-friendly form Kirill Shcherbatov
2018-11-01 13:34 ` [tarantool-patches] " Konstantin Osipov
2018-11-01 14:18 ` Konstantin Osipov
2018-11-06 12:15 ` [tarantool-patches] " Kirill Shcherbatov
2018-10-29 6:56 ` [PATCH v5 02/12] box: introduce key_def_parts_are_sequential Kirill Shcherbatov
2018-11-01 14:23 ` [tarantool-patches] " Konstantin Osipov
2018-11-06 12:14 ` [tarantool-patches] " Kirill Shcherbatov
2018-11-19 17:48 ` Vladimir Davydov
2018-10-29 6:56 ` [PATCH v5 03/12] box: introduce tuple_field_go_to_path Kirill Shcherbatov
2018-11-19 17:48 ` Vladimir Davydov
2018-10-29 6:56 ` [PATCH v5 04/12] box: introduce tuple_format_add_key_part Kirill Shcherbatov
2018-11-01 14:38 ` [tarantool-patches] " Konstantin Osipov
2018-11-06 12:15 ` [tarantool-patches] " Kirill Shcherbatov
2018-11-19 17:50 ` Vladimir Davydov
2018-10-29 6:56 ` [PATCH v5 05/12] lib: implement JSON tree class for json library Kirill Shcherbatov
2018-11-01 15:08 ` [tarantool-patches] " Konstantin Osipov
2018-11-06 12:15 ` [tarantool-patches] " Kirill Shcherbatov
2018-11-19 17:53 ` Vladimir Davydov
2018-11-20 16:43 ` Vladimir Davydov
2018-11-21 10:37 ` [tarantool-patches] " Kirill Shcherbatov
2018-11-26 10:50 ` Kirill Shcherbatov
2018-10-29 6:56 ` [PATCH v5 06/12] box: manage format fields with JSON tree class Kirill Shcherbatov
2018-10-29 6:56 ` [PATCH v5 07/12] lib: introduce json_path_normalize routine Kirill Shcherbatov
2018-11-01 15:22 ` [tarantool-patches] " Konstantin Osipov
2018-11-01 15:27 ` [tarantool-patches] " Kirill Shcherbatov
2018-11-20 15:13 ` Vladimir Davydov
2018-11-26 10:50 ` Kirill Shcherbatov
2018-11-20 15:14 ` Vladimir Davydov
2018-10-29 6:56 ` [PATCH v5 08/12] box: introduce JSON indexes Kirill Shcherbatov
2018-11-20 16:52 ` Vladimir Davydov
2018-11-26 10:50 ` [tarantool-patches] " Kirill Shcherbatov
2018-10-29 6:56 ` [tarantool-patches] [PATCH v5 09/12] box: introduce has_json_paths flag in templates Kirill Shcherbatov
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=7a44e73bcc4c3b2780be79360c720f7cfec9dbe4.1540795996.git.kshcherbatov@tarantool.org \
--to=kshcherbatov@tarantool.org \
--cc=tarantool-patches@freelists.org \
--cc=vdavydov.dev@gmail.com \
--subject='Re: [PATCH v5 10/12] 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