[Tarantool-patches] [PATCH v3 7/6] schema: fix index promotion to functional index

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Wed Apr 15 02:30:39 MSK 2020


    When index:alter() was called on a non-functional index with
    specified 'func', it led to accessing a not declared variable in
    schema.lua.

diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua
index 545abe714..ad4a5470b 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..dfa609ce8 100644
--- a/test/engine/func_index.result
+++ b/test/engine/func_index.result
@@ -847,3 +847,42 @@ 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..98df886f4 100644
--- a/test/engine/func_index.test.lua
+++ b/test/engine/func_index.test.lua
@@ -294,3 +294,18 @@ 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')


More information about the Tarantool-patches mailing list