From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH 2/4] schema: fix error while altering index with sequence Date: Wed, 15 May 2019 13:33:47 +0300 Message-Id: <697f71dedae5de2a0c3c4b56477c0e30f80f9d03.1557916311.git.vdavydov.dev@gmail.com> In-Reply-To: References: In-Reply-To: References: To: tarantool-patches@freelists.org List-ID: A check was missing in index.alter. This resulted in an attempt to drop the sequence attached to the altered index even if the sequence was not modified. Closes #4214 --- src/box/lua/schema.lua | 3 ++- test/box/sequence.result | 33 +++++++++++++++++++++++++++++++++ test/box/sequence.test.lua | 13 +++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua index 036e5f2d..14ad4de1 100644 --- a/src/box/lua/schema.lua +++ b/src/box/lua/schema.lua @@ -1068,7 +1068,8 @@ box.schema.index.alter = function(space_id, index_id, options) if sequence then _space_sequence:replace{space_id, sequence, sequence_is_generated} end - if sequence_tuple ~= nil and sequence_tuple.is_generated == true and + if sequence ~= nil and sequence_tuple ~= nil and + sequence_tuple.is_generated == true and sequence_tuple.sequence_id ~= sequence then -- Delete automatically generated sequence. box.schema.sequence.drop(sequence_tuple.sequence_id) diff --git a/test/box/sequence.result b/test/box/sequence.result index b3907659..5eed0ef4 100644 --- a/test/box/sequence.result +++ b/test/box/sequence.result @@ -1871,3 +1871,36 @@ test_run:cmd("setopt delimiter ''"); --- - true ... +-- +-- gh-4214: error while altering an index with attached sequence. +-- +s = box.schema.space.create('test') +--- +... +_ = s:create_index('pk', {sequence = true}) +--- +... +sequence_id = s.index.pk.sequence_id +--- +... +sequence_id ~= nil +--- +- true +... +s.index.pk:alter{parts = {1, 'integer'}} +--- +... +s.index.pk.parts[1].type +--- +- integer +... +s.index.pk:alter{sequence = true} +--- +... +sequence_id == s.index.pk.sequence_id +--- +- true +... +s:drop() +--- +... diff --git a/test/box/sequence.test.lua b/test/box/sequence.test.lua index 96297d6f..6459419e 100644 --- a/test/box/sequence.test.lua +++ b/test/box/sequence.test.lua @@ -634,3 +634,16 @@ identifier.run_test( function (identifier) box.schema.sequence.drop(identifier) end ); test_run:cmd("setopt delimiter ''"); + +-- +-- gh-4214: error while altering an index with attached sequence. +-- +s = box.schema.space.create('test') +_ = s:create_index('pk', {sequence = true}) +sequence_id = s.index.pk.sequence_id +sequence_id ~= nil +s.index.pk:alter{parts = {1, 'integer'}} +s.index.pk.parts[1].type +s.index.pk:alter{sequence = true} +sequence_id == s.index.pk.sequence_id +s:drop() -- 2.11.0