From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Kirill Shcherbatov Subject: [PATCH v2 3/5] box: move offset_slot init to tuple_format_add_field Date: Tue, 19 Mar 2019 15:32:08 +0300 Message-Id: <8f6727d635bb4b30280e42e02d528e685a3406d1.1552998554.git.kshcherbatov@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: tarantool-patches@freelists.org, vdavydov.dev@gmail.com Cc: Kirill Shcherbatov List-ID: Due to the fact that the allocation of offset_slot in the case of multikey indexes will become more complicated and will be necessary for intermediate nodes of the tuple_field tree, let's move this logic to the tuple_format_add_field. Needed for #1257 --- src/box/tuple_format.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/box/tuple_format.c b/src/box/tuple_format.c index 22a84af86..1043707ad 100644 --- a/src/box/tuple_format.c +++ b/src/box/tuple_format.c @@ -205,13 +205,14 @@ tuple_format_field_by_id(struct tuple_format *format, uint32_t id) */ static struct tuple_field * tuple_format_add_field(struct tuple_format *format, uint32_t fieldno, - const char *path, uint32_t path_len, char **path_pool) + const char *path, uint32_t path_len, bool is_sequential, + int *current_slot, char **path_pool) { struct tuple_field *field = NULL; struct tuple_field *parent = tuple_format_field(format, fieldno); assert(parent != NULL); if (path == NULL) - return parent; + goto end; field = tuple_field_new(); if (field == NULL) goto fail; @@ -279,12 +280,23 @@ tuple_format_add_field(struct tuple_format *format, uint32_t fieldno, assert(parent != NULL); /* Update tree depth information. */ format->fields_depth = MAX(format->fields_depth, token_count + 1); -end: +cleanup: tuple_field_delete(field); +end: + /* + * In the tuple, store only offsets necessary to access + * fields of non-sequential keys. First field is always + * simply accessible, so we don't store an offset for it. + */ + if (parent != NULL && parent->offset_slot == TUPLE_OFFSET_SLOT_NIL && + is_sequential == false && (fieldno > 0 || path != NULL)) { + *current_slot = *current_slot - 1; + parent->offset_slot = *current_slot; + } return parent; fail: parent = NULL; - goto end; + goto cleanup; } static int @@ -295,7 +307,8 @@ tuple_format_use_key_part(struct tuple_format *format, uint32_t field_count, assert(part->fieldno < tuple_format_field_count(format)); struct tuple_field *field = tuple_format_add_field(format, part->fieldno, part->path, - part->path_len, path_pool); + part->path_len, is_sequential, + current_slot, path_pool); if (field == NULL) return -1; /* @@ -350,17 +363,6 @@ tuple_format_use_key_part(struct tuple_format *format, uint32_t field_count, return -1; } field->is_key_part = true; - /* - * In the tuple, store only offsets necessary to access - * fields of non-sequential keys. First field is always - * simply accessible, so we don't store an offset for it. - */ - if (field->offset_slot == TUPLE_OFFSET_SLOT_NIL && - is_sequential == false && - (part->fieldno > 0 || part->path != NULL)) { - *current_slot = *current_slot - 1; - field->offset_slot = *current_slot; - } return 0; } -- 2.21.0