From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp49.i.mail.ru (smtp49.i.mail.ru [94.100.177.109]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id BE5BD4696C3 for ; Tue, 21 Apr 2020 17:02:50 +0300 (MSK) From: sergeyb@tarantool.org Date: Tue, 21 Apr 2020 17:00:24 +0300 Message-Id: <0b86996f4cac3e620137abf271a43bde499e5334.1587476678.git.sergeyb@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v4 7/10] schema: fix index promotion to functional index List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, imun@tarantool.org, v.shpilevoy@tarantool.org Cc: o.piskunov@tarantool.org From: Vladislav Shpilevoy 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