From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: tarantool-patches@freelists.org
Subject: [PATCH 2/4] schema: fix error while altering index with sequence
Date: Wed, 15 May 2019 13:33:47 +0300 [thread overview]
Message-ID: <697f71dedae5de2a0c3c4b56477c0e30f80f9d03.1557916311.git.vdavydov.dev@gmail.com> (raw)
In-Reply-To: <cover.1557916311.git.vdavydov.dev@gmail.com>
In-Reply-To: <cover.1557916311.git.vdavydov.dev@gmail.com>
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
next prev parent reply other threads:[~2019-05-15 10:33 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-15 10:33 [PATCH 0/4] A few fixes/improvements for autoincrement indexes Vladimir Davydov
2019-05-15 10:33 ` [PATCH 1/4] schema: use tuple field names in Lua Vladimir Davydov
2019-05-15 10:33 ` Vladimir Davydov [this message]
2019-05-16 7:45 ` [tarantool-patches] Re: [PATCH 2/4] schema: fix error while altering index with sequence Konstantin Osipov
2019-05-15 10:33 ` [PATCH 3/4] schema: allow to set sequence for any index part, not just the first Vladimir Davydov
2019-05-16 7:45 ` [tarantool-patches] " Konstantin Osipov
2019-05-16 8:02 ` Vladimir Davydov
2019-05-15 10:33 ` [PATCH 4/4] schema: explicitly forbid setting sequence for json path key part Vladimir Davydov
2019-05-15 13:00 ` [tarantool-patches] " Konstantin Osipov
2019-05-15 13:11 ` Vladimir Davydov
2019-05-15 13:16 ` Vladimir Davydov
2019-05-15 13:44 ` [PATCH] box: fix autoincrement for json path indexes Vladimir Davydov
2019-05-16 7:42 ` [tarantool-patches] " Konstantin Osipov
2019-05-21 13:28 ` Vladimir Davydov
2019-05-21 10:42 ` [tarantool-patches] Re: [PATCH 0/4] A few fixes/improvements for autoincrement indexes Kirill Yukhin
2019-05-21 14:58 ` Konstantin Osipov
2019-05-21 16:02 ` Kirill Yukhin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=697f71dedae5de2a0c3c4b56477c0e30f80f9d03.1557916311.git.vdavydov.dev@gmail.com \
--to=vdavydov.dev@gmail.com \
--cc=tarantool-patches@freelists.org \
--subject='Re: [PATCH 2/4] schema: fix error while altering index with sequence' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox