From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (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 6C39B43D67A for ; Tue, 15 Oct 2019 18:15:58 +0300 (MSK) Date: Tue, 15 Oct 2019 18:15:57 +0300 From: Nikita Pettik Message-ID: <20191015151557.GA93939@tarantool.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Subject: Re: [Tarantool-patches] [tarantool-patches] [PATCH v4 4/4] sql: use name instead of function pointer for UDF List-Id: Tarantool development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kirill Shcherbatov Cc: tarantool-patches@freelists.org, tarantool-patches@dev.tarantool.org On 15 Oct 14:13, Kirill Shcherbatov wrote: > > Could you add test case covering mentioned situation? > Yes. Appended. > > ================================================= > > This patch changes OP_Function parameters convention: now a > function's name is passed instead of pointer to the function > object. This allows to normally handle the situation, when UDF > has been deleted to the moment of the VDBE code execution. > In particular case this may happen with CK constraints that > refers to a deleted persistent function. > > Closes #4176 > --- > src/box/sql/expr.c | 17 ++++++++++++----- > src/box/sql/vdbe.c | 11 ++++++++--- > test/sql/checks.result | 28 ++++++++++++++++++++++++++++ > test/sql/checks.test.lua | 11 +++++++++++ > 4 files changed, 59 insertions(+), 8 deletions(-) > > diff --git a/test/sql/checks.result b/test/sql/checks.result > index b8bd19a84..02ee82a4b 100644 > --- a/test/sql/checks.result > +++ b/test/sql/checks.result > @@ -918,6 +918,34 @@ box.execute("DROP TABLE test;") > --- > - row_count: 1 > ... > +-- > +-- gh-4176: Can't recover if check constraint involves function. > +-- > +function myfunc(x) return x < 10 end > +--- > +... > +box.schema.func.create('MYFUNC', {param_list = {'integer'}, returns = 'integer', is_deterministic = true, exports = {'LUA', 'SQL'}}) > +--- > +... > +box.execute("CREATE TABLE t6(a INT CHECK (myfunc(a)) primary key);"); > +--- > +- row_count: 1 > +... > +myfunc = nil > +--- > +... > +box.execute("INSERT INTO t6 VALUES(11);"); > +--- > +- null > +- Procedure 'MYFUNC' is not defined Something is wrong with this test case. Firstly, it works fine even on master branch. Secondly, I've dropped myfunc = nil and got the same error (on master as well) - i.e. INSERT fails with 'procedure is not defined' error even if function is not dropped. Obviously, to make it crash on master you should drop function before insertion; to fix second problem you should uppercase function's name. > +box.execute("DROP TABLE t6") > +--- > +- row_count: 1 > +... > +box.func.MYFUNC:drop() > +--- > +... > test_run:cmd("clear filter") > --- > - true > diff --git a/test/sql/checks.test.lua b/test/sql/checks.test.lua > index 832322190..fa68920f6 100644 > --- a/test/sql/checks.test.lua > +++ b/test/sql/checks.test.lua > @@ -302,4 +302,15 @@ assert(box.space.TEST.ck_constraint.some_ck.is_enabled == true) > box.space.TEST:insert({12}) > box.execute("DROP TABLE test;") > > +-- > +-- gh-4176: Can't recover if check constraint involves function. > +-- > +function myfunc(x) return x < 10 end > +box.schema.func.create('MYFUNC', {param_list = {'integer'}, returns = 'integer', is_deterministic = true, exports = {'LUA', 'SQL'}}) > +box.execute("CREATE TABLE t6(a INT CHECK (myfunc(a)) primary key);"); > +myfunc = nil > +box.execute("INSERT INTO t6 VALUES(11);"); > +box.execute("DROP TABLE t6") > +box.func.MYFUNC:drop() > + > test_run:cmd("clear filter") > -- > 2.23.0 >