From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id AD01C20AD1 for ; Sun, 9 Dec 2018 10:57:53 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zSMAMWDosW4V for ; Sun, 9 Dec 2018 10:57:53 -0500 (EST) Received: from smtp57.i.mail.ru (smtp57.i.mail.ru [217.69.128.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 4958920ACE for ; Sun, 9 Dec 2018 10:57:52 -0500 (EST) From: Nikita Pettik Subject: [tarantool-patches] [PATCH] sql: disallow to rename space if it is referenced by view Date: Sun, 9 Dec 2018 18:57:35 +0300 Message-Id: <20181209155735.32694-1-korablev@tarantool.org> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: v.shpilevoy@tarantool.org, Nikita Pettik Before this patch it was allowed to rename space which is referenced by a view. In turn, view contains SELECT statement in a raw form (i.e. as a string) and it is not modified during renaming routine. Hence, after renaming space still has referencing counter > 0, but no usage of view is allowed (since execution of SELECT results in "Space does not exist"). To avoid such situations, lets ban renaming space if its view reference counter > 0. Note that RENAME is ANSI extension, so different DBs behave in this case in different ways - some of them allow to rename tables referenced by a view (PostgreSQL), others - don't (Oracle). Closes #3746 --- Branch: https://github.com/tarantool/tarantool/tree/np/gh-3746-view-rename Issue: https://github.com/tarantool/tarantool/issues/3746 src/box/alter.cc | 6 ++++++ test/sql/view.result | 6 ++++++ test/sql/view.test.lua | 3 +++ 3 files changed, 15 insertions(+) diff --git a/src/box/alter.cc b/src/box/alter.cc index 029da029e..f3b267401 100644 --- a/src/box/alter.cc +++ b/src/box/alter.cc @@ -1823,6 +1823,12 @@ on_replace_dd_space(struct trigger * /* trigger */, void *event) space_name(old_space), "can not convert a space to " "a view and vice versa"); + if (strcmp(def->name, old_space->def->name) != 0 && + old_space->def->view_ref_count > 0) + tnt_raise(ClientError, ER_ALTER_SPACE, + space_name(old_space), + "can not rename space which is referenced by " + "view"); /* * Allow change of space properties, but do it * in WAL-error-safe mode. diff --git a/test/sql/view.result b/test/sql/view.result index b211bcb2e..8adbe568c 100644 --- a/test/sql/view.result +++ b/test/sql/view.result @@ -69,6 +69,12 @@ box.schema.create_space('view', {view = true}) --- - error: Illegal parameters, unexpected option 'view' ... +-- Space referenced by a view can't be renamed. +box.sql.execute("ALTER TABLE t1 RENAME TO new_name;") +--- +- error: 'Can''t modify space ''T1'': can not rename space which is referenced by + view' +... -- View can be created via straight insertion into _space. sp = box.schema.create_space('test'); --- diff --git a/test/sql/view.test.lua b/test/sql/view.test.lua index a6269a1bf..ba4d0bb2c 100644 --- a/test/sql/view.test.lua +++ b/test/sql/view.test.lua @@ -33,6 +33,9 @@ box.space._space:replace(v1); -- Views can't be created via space_create(). box.schema.create_space('view', {view = true}) +-- Space referenced by a view can't be renamed. +box.sql.execute("ALTER TABLE t1 RENAME TO new_name;") + -- View can be created via straight insertion into _space. sp = box.schema.create_space('test'); raw_sp = box.space._space:get(sp.id):totable(); -- 2.15.1