From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Tue, 16 Oct 2018 12:33:32 +0300 From: Vladimir Davydov Subject: Re: [PATCH v4 10/14] box: introduce JSON indexes Message-ID: <20181016093332.vocmxag2dwbbr6uy@esperanza> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: To: Kirill Shcherbatov Cc: tarantool-patches@freelists.org List-ID: On Thu, Oct 11, 2018 at 10:58:42AM +0300, Kirill Shcherbatov wrote: > @@ -477,34 +833,39 @@ tuple_init_field_map(struct tuple_format *format, uint32_t *field_map, > } > > /* first field is simply accessible, so we do not store offset to it */ > - enum mp_type mp_type = mp_typeof(*pos); > - const struct tuple_field *field = &format->fields[0]; > - if (key_mp_type_validate(field->type, mp_type, ER_FIELD_TYPE, > - TUPLE_INDEX_BASE, field->is_nullable)) > - return -1; > - mp_next(&pos); > - /* other fields...*/ > - ++field; > - uint32_t i = 1; > - uint32_t defined_field_count = MIN(field_count, format->field_count); > - if (field_count < format->index_field_count) { > + struct tuple_field *field = &format->fields[0]; > + uint32_t i = 0; > + if (field_count < format->index_field_count || > + json_tree_node_children_count(&field->path_tree_node) == 0) { > /* > - * Nullify field map to be able to detect by 0, > - * which key fields are absent in tuple_field(). > - */ > + * Nullify field map to be able to detect by 0, > + * which key fields are absent in tuple_field(). > + */ > memset((char *)field_map - format->field_map_size, 0, > - format->field_map_size); > + format->field_map_size); > } > - for (; i < defined_field_count; ++i, ++field) { > - mp_type = mp_typeof(*pos); > + if (json_tree_node_children_count(&field->path_tree_node) == 0) { > + enum mp_type mp_type = mp_typeof(*pos); > if (key_mp_type_validate(field->type, mp_type, ER_FIELD_TYPE, > - i + TUPLE_INDEX_BASE, > - field->is_nullable)) > + TUPLE_INDEX_BASE, field->is_nullable)) > + return -1; > + mp_next(&pos); > + ++field; > + ++i; > + } > + size_t off_stack_size = > + format->max_path_tree_depth * sizeof(const char *); > + const char **off_stack = region_alloc(&fiber()->gc, off_stack_size); > + if (off_stack == NULL) { > + diag_set(OutOfMemory, off_stack_size, "region_alloc", > + "off_stack"); > + return -1; > + } > + uint32_t defined_field_count = MIN(field_count, format->field_count); > + for (; i < defined_field_count; ++i, ++field) { > + if (tuple_field_tree_parse_raw(field, pos, tuple, i, field_map, > + off_stack) != 0) > return -1; > - if (field->offset_slot != TUPLE_OFFSET_SLOT_NIL) { > - field_map[field->offset_slot] = > - (uint32_t) (pos - tuple); > - } > mp_next(&pos); > } > return 0; > @@ -108,6 +109,10 @@ struct tuple_field { > bool is_key_part; > /** True, if a field can store NULL. */ > bool is_nullable; > + /** JSON path tree max depth. */ > + uint32_t path_tree_depth; > + /** JSON root path tree node for registered indexes. */ > + struct json_tree_node path_tree_node; > }; For the record. After discussion with Kostja, we agreed that a json tree should be rooted at struct tuple_format rather than tuple_field so that top level fields are accessed in the same fashion as nested fields. Also, a tuple field map should be initialized as msgpack gets parsed rather than walking over a json tree and looking up fields in msgpack, because that would be more efficient.