From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp53.i.mail.ru (smtp53.i.mail.ru [94.100.177.113]) (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 90A744696C6 for ; Wed, 15 Apr 2020 02:30:41 +0300 (MSK) References: From: Vladislav Shpilevoy Message-ID: <9cbf485c-4612-4514-a2b5-782eee81b26c@tarantool.org> Date: Wed, 15 Apr 2020 01:30:39 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: [Tarantool-patches] [PATCH v3 7/6] schema: fix index promotion to functional index List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Sergey Bronnikov , avtikhon@tarantool.org, alexander.turenko@tarantool.org, o.piskunov@tarantool.org, tarantool-patches@dev.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. 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')