[Tarantool-patches] [PATCH v4 7/10] schema: fix index promotion to functional index
sergeyb at tarantool.org
sergeyb at tarantool.org
Tue Apr 21 17:00:24 MSK 2020
From: Vladislav Shpilevoy <v.shpilevoy at tarantool.org>
When index:alter() was called on a non-functional index with
specified 'func', it led to accessing a not declared variable in
schema.lua.
---
src/box/lua/schema.lua | 2 +-
test/engine/func_index.result | 36 +++++++++++++++++++++++++++++++++
test/engine/func_index.test.lua | 14 +++++++++++++
3 files changed, 51 insertions(+), 1 deletion(-)
diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua
index de47b807e..0beb66510 100644
--- a/src/box/lua/schema.lua
+++ b/src/box/lua/schema.lua
@@ -1210,7 +1210,7 @@ box.schema.index.alter = function(space_id, index_id, options)
index_opts, parts}
if index_opts.func ~= nil then
local _func_index = box.space[box.schema.FUNC_INDEX_ID]
- _func_index:insert{space_id, iid, index_opts.func}
+ _func_index:insert{space_id, index_id, index_opts.func}
end
space_sequence_alter_commit(sequence_proxy)
end
diff --git a/test/engine/func_index.result b/test/engine/func_index.result
index a827c929f..8e7767dce 100644
--- a/test/engine/func_index.result
+++ b/test/engine/func_index.result
@@ -847,3 +847,39 @@ s:drop()
box.func.extr:drop()
| ---
| ...
+
+--
+-- Function is added at alter.
+--
+s = box.schema.space.create('withdata', {engine = engine})
+ | ---
+ | ...
+lua_code = [[function(tuple) return {tuple[2] >= 0 and tuple[2] or -tuple[2]} end]]
+ | ---
+ | ...
+box.schema.func.create('second_field_module', {body = lua_code, is_deterministic = true, is_sandboxed = true})
+ | ---
+ | ...
+pk = s:create_index('pk')
+ | ---
+ | ...
+sk = s:create_index('sk', {parts = {{2, 'unsigned'}}})
+ | ---
+ | ...
+sk:alter({func = 'second_field_module', parts = {{1, 'unsigned'}}})
+ | ---
+ | ...
+s:insert({1, -3})
+ | ---
+ | - [1, -3]
+ | ...
+sk:get{3}
+ | ---
+ | - [1, -3]
+ | ...
+s:drop()
+ | ---
+ | ...
+box.schema.func.drop('second_field_module')
+ | ---
+ | ...
diff --git a/test/engine/func_index.test.lua b/test/engine/func_index.test.lua
index 5db588c1f..3b48bb478 100644
--- a/test/engine/func_index.test.lua
+++ b/test/engine/func_index.test.lua
@@ -294,3 +294,17 @@ idx:get({3})
s:drop()
box.func.extr:drop()
+
+--
+-- Function is added at alter.
+--
+s = box.schema.space.create('withdata', {engine = engine})
+lua_code = [[function(tuple) return {tuple[2] >= 0 and tuple[2] or -tuple[2]} end]]
+box.schema.func.create('second_field_module', {body = lua_code, is_deterministic = true, is_sandboxed = true})
+pk = s:create_index('pk')
+sk = s:create_index('sk', {parts = {{2, 'unsigned'}}})
+sk:alter({func = 'second_field_module', parts = {{1, 'unsigned'}}})
+s:insert({1, -3})
+sk:get{3}
+s:drop()
+box.schema.func.drop('second_field_module')
--
2.23.0
More information about the Tarantool-patches
mailing list