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 0787B20198 for ; Tue, 11 Dec 2018 04:57:16 -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 bghkrRVqyJox for ; Tue, 11 Dec 2018 04:57:15 -0500 (EST) Received: from smtp63.i.mail.ru (smtp63.i.mail.ru [217.69.128.43]) (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 F313420196 for ; Tue, 11 Dec 2018 04:57:12 -0500 (EST) From: "n.pettik" Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_4E864035-AE5D-486E-AA92-1C4DE8269129" Mime-Version: 1.0 (Mac OS X Mail 12.0 \(3445.100.39\)) Subject: [tarantool-patches] Re: [PATCH] sql: disallow to rename space if it is referenced by view Date: Tue, 11 Dec 2018 12:57:01 +0300 In-Reply-To: <20181211070218.GA19289@chai> References: <20181209155735.32694-1-korablev@tarantool.org> <20181211070218.GA19289@chai> 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: Vladislav Shpilevoy , Konstantin Osipov --Apple-Mail=_4E864035-AE5D-486E-AA92-1C4DE8269129 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On 11 Dec 2018, at 10:02, Konstantin Osipov = wrote: >=20 > * Nikita Pettik > [18/12/09 20:53]: >> 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. >>=20 >> 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). >>=20 >> Closes #3746 >> --- >> Branch: = https://github.com/tarantool/tarantool/tree/np/gh-3746-view-rename >> Issue: https://github.com/tarantool/tarantool/issues/3746 >>=20 >> src/box/alter.cc | 6 ++++++ >> test/sql/view.result | 6 ++++++ >> test/sql/view.test.lua | 3 +++ >> 3 files changed, 15 insertions(+) >>=20 >> 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) !=3D 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"); >=20 > Please specify which view is referencing this space in the error > message. If I could do it without over-engineering, I would have already done it. As you may see, space features only reference counter, so to get name of view we should iterate over all VIEWs and compile SELECT for each = VIEW. > --=20 > Konstantin Osipov, Moscow, Russia, +7 903 626 22 32 = > http://tarantool.io - = www.twitter.com/kostja_osipov --Apple-Mail=_4E864035-AE5D-486E-AA92-1C4DE8269129 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii

On 11 Dec 2018, at 10:02, Konstantin Osipov <kostja@tarantool.org> wrote:

* Nikita Pettik <korablev@tarantool.org> [18/12/09 20:53]:
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-ren= ame
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),<= br class=3D"">   "can not convert a = space to "
  "a view and vice = versa");
+ if (strcmp(def->name, = old_space->def->name) !=3D 0 &&
+     old_space-&= gt;def->view_ref_count > 0)
+ = tnt_raise(ClientError, ER_ALTER_SPACE,
+   space_name(old_space),<= br class=3D"">+   "can not rename space = which is referenced by "
+   "view");

Please specify which view is referencing this space in the = error
message.

If I could do it without over-engineering, I would = have already done it.
As you may see, space features only = reference counter, so to get name
of view we should iterate = over all VIEWs and compile SELECT for each VIEW.

-- 
Konstantin Osipov, Moscow, = Russia, +7 903 626 22 32
http://tarantool.io - www.twitter.com/kostja_osipov

= --Apple-Mail=_4E864035-AE5D-486E-AA92-1C4DE8269129--