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 A44512B510 for ; Fri, 29 Mar 2019 14:24:30 -0400 (EDT) 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 hNrOoaWRZJ51 for ; Fri, 29 Mar 2019 14:24:30 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (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 558482B509 for ; Fri, 29 Mar 2019 14:24:30 -0400 (EDT) From: Nikita Pettik Subject: [tarantool-patches] [PATCH 1/4] Drop foreign keys before indexes in space:drop() Date: Fri, 29 Mar 2019 21:24:21 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: 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 Implicitly involved in foreign key constraint index can't be dropped before constraint itself. So, to drop self-referenced table, we should firstly drop foreign key constraints, and only then indexes. --- src/box/lua/schema.lua | 6 +++--- test/sql/foreign-keys.result | 8 ++++++++ test/sql/foreign-keys.test.lua | 5 +++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua index d9483a6b2..f31cf7f2c 100644 --- a/src/box/lua/schema.lua +++ b/src/box/lua/schema.lua @@ -521,14 +521,14 @@ box.schema.space.drop = function(space_id, space_name, opts) for _, t in _trigger.index.space_id:pairs({space_id}) do _trigger:delete({t.name}) end + for _, t in _fk_constraint.index.child_id:pairs({space_id}) do + _fk_constraint:delete({t.name, space_id}) + end local keys = _vindex:select(space_id) for i = #keys, 1, -1 do local v = keys[i] _index:delete{v[1], v[2]} end - for _, t in _fk_constraint.index.child_id:pairs({space_id}) do - _fk_constraint:delete({t.name, space_id}) - end revoke_object_privs('space', space_id) _truncate:delete{space_id} if _space:delete{space_id} == nil then diff --git a/test/sql/foreign-keys.result b/test/sql/foreign-keys.result index 3c6464e7d..731807227 100644 --- a/test/sql/foreign-keys.result +++ b/test/sql/foreign-keys.result @@ -377,5 +377,13 @@ box.sql.execute('CREATE TABLE t2 (id INT PRIMARY KEY REFERENCES t2 ON DELETE CAS box.space.T1:drop() --- ... +-- Make sure that space:drop() works fine on self-referenced spaces. +-- +box.sql.execute("CREATE TABLE t4 (id INT PRIMARY KEY REFERENCES t4);") +--- +... +box.space.T4:drop() +--- +... --- Clean-up SQL DD hash. -test_run:cmd('restart server default with cleanup=1') diff --git a/test/sql/foreign-keys.test.lua b/test/sql/foreign-keys.test.lua index 3fb7cab18..6f4941e09 100644 --- a/test/sql/foreign-keys.test.lua +++ b/test/sql/foreign-keys.test.lua @@ -169,5 +169,10 @@ box.sql.execute('CREATE TABLE t2 (id INT PRIMARY KEY REFERENCES t2 ON DELETE CAS box.sql.execute('CREATE TABLE t2 (id INT PRIMARY KEY REFERENCES t2 ON DELETE CASCADE MATCH FULL);') box.space.T1:drop() +-- Make sure that space:drop() works fine on self-referenced spaces. +-- +box.sql.execute("CREATE TABLE t4 (id INT PRIMARY KEY REFERENCES t4);") +box.space.T4:drop() + --- Clean-up SQL DD hash. -test_run:cmd('restart server default with cleanup=1') -- 2.15.1