[PATCH 2/4] schema: fix error while altering index with sequence
Vladimir Davydov
vdavydov.dev at gmail.com
Wed May 15 13:33:47 MSK 2019
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
More information about the Tarantool-patches
mailing list