From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id B9E972F191 for ; Thu, 1 Nov 2018 09:50:42 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6Brn7znbuhyW for ; Thu, 1 Nov 2018 09:50:42 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 79DEB2F18F for ; Thu, 1 Nov 2018 09:50:42 -0400 (EDT) From: imeevma@tarantool.org Subject: [tarantool-patches] [PATCH v1 1/1] box: wrong is_nullable for multiple indexes Date: Thu, 1 Nov 2018 16:50:39 +0300 Message-Id: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org, v.shpilevoy@tarantool.org If field isn't defined by space format, than in case of multiple indexes field option is_nullable was the same as it was for last index that defines it. This is wrong as it should be 'true' only if it is 'true' for all indexes that defines it. Closes #3744. --- Issue: https://github.com/tarantool/tarantool/issues/3744 Branch: https://github.com/tarantool/tarantool/tree/imeevma/gh-3744-wrong-is_nullable-for-multiple-indexes src/box/tuple_format.c | 12 ++---------- test/engine/null.result | 24 ++++++++++++++++++++++++ test/engine/null.test.lua | 9 +++++++++ 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/box/tuple_format.c b/src/box/tuple_format.c index 5f4899d..d4af54c 100644 --- a/src/box/tuple_format.c +++ b/src/box/tuple_format.c @@ -38,7 +38,7 @@ static intptr_t recycled_format_ids = FORMAT_ID_NIL; static uint32_t formats_size = 0, formats_capacity = 0; static const struct tuple_field tuple_field_default = { - FIELD_TYPE_ANY, TUPLE_OFFSET_SLOT_NIL, false, false, + FIELD_TYPE_ANY, TUPLE_OFFSET_SLOT_NIL, false, true, }; /** @@ -81,15 +81,7 @@ tuple_format_create(struct tuple_format *format, struct key_def * const *keys, assert(part->fieldno < format->field_count); struct tuple_field *field = &format->fields[part->fieldno]; - if (part->fieldno >= field_count) { - field->is_nullable = part->is_nullable; - } else if (field->is_nullable != part->is_nullable) { - /* - * In case of mismatch set the most - * strict option for is_nullable. - */ - field->is_nullable = false; - } + field->is_nullable &= part->is_nullable; /* * Check that there are no conflicts diff --git a/test/engine/null.result b/test/engine/null.result index 48d6784..4ec0142 100644 --- a/test/engine/null.result +++ b/test/engine/null.result @@ -1693,3 +1693,27 @@ s:insert{9, 10} -- Success. s:drop() --- ... +-- gh-3744: Assertion after improper index creation +s = box.schema.space.create('test', {engine=engine}) +--- +... +pk = s:create_index('primary', {parts={1, 'unsigned'}}) +--- +... +sk1 = s:create_index('sk1', {parts={{2, 'number', is_nullable=false}}}) +--- +... +s:insert{1, -1, 1} +--- +- [1, -1, 1] +... +sk2 = s:create_index('sk2', {parts={{2, 'number', is_nullable=true}}}) +--- +... +s:insert{2, nil, 2} --error +--- +- error: 'Tuple field 2 type does not match one required by operation: expected number' +... +s:drop() +--- +... diff --git a/test/engine/null.test.lua b/test/engine/null.test.lua index 5eb0684..ba13adf 100644 --- a/test/engine/null.test.lua +++ b/test/engine/null.test.lua @@ -505,3 +505,12 @@ s:insert{5} -- Fail. s:insert{9, 10} -- Success. s:drop() + +-- gh-3744: Assertion after improper index creation +s = box.schema.space.create('test', {engine=engine}) +pk = s:create_index('primary', {parts={1, 'unsigned'}}) +sk1 = s:create_index('sk1', {parts={{2, 'number', is_nullable=false}}}) +s:insert{1, -1, 1} +sk2 = s:create_index('sk2', {parts={{2, 'number', is_nullable=true}}}) +s:insert{2, nil, 2} --error +s:drop() -- 2.7.4