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 88825256E1 for ; Thu, 1 Aug 2019 12:42:34 -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 BRxG9gE9Wvnq for ; Thu, 1 Aug 2019 12:42:34 -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 41DBA20A35 for ; Thu, 1 Aug 2019 12:42:34 -0400 (EDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: [tarantool-patches] Re: [PATCH] sql: make default constraint names be consistent From: "n.pettik" In-Reply-To: <20190731105556.42786-1-korablev@tarantool.org> Date: Thu, 1 Aug 2019 19:42:31 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <929F658A-E4E9-4D8A-BD7C-65F42A62AE89@tarantool.org> References: <20190731105556.42786-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: Konstantin Osipov I=E2=80=99ve added another one patch on branch according to my message to you and Peter G.: =46rom 929aefb794f3604681b875ac5051dfd96a9280a3 Mon Sep 17 00:00:00 2001 From: Nikita Pettik Date: Thu, 1 Aug 2019 19:31:52 +0300 Subject: [PATCH] sql: don't mangle name of unique constraint If UNIQUE constraint is specified in CREATE TABLE statement and it has given name, one is mangled with pattern "unique_%s_%d", where %s is original name of constraint and %d - current iid. For instance: CREATE TABLE t (id INT PRIMARY KEY, a INT CONSTRAINT i1 UNIQUE); This statement results in secondary index creation with name "unique_I1_1". Justification for mangling is that constraint namespace should be independent from index namespace. However, ALTER TABLE ADD CONSTRAINT UNIQUE which is alias to CREATE INDEX doesn't mangle name. What is more, users may wonder why name of index is different from name of created constraint. Hence, it has been decided to remove this mangling and create index exactly with specified constraint's name. --- src/box/sql/build.c | 23 +++++++++-------------- test/sql-tap/index7.test.lua | 4 ++-- test/sql-tap/table.test.lua | 4 ++-- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/box/sql/build.c b/src/box/sql/build.c index e02b7f864..27bea1756 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -2496,22 +2496,17 @@ sql_create_index(struct Parse *parse) { */ assert(idx_type =3D=3D SQL_INDEX_TYPE_CONSTRAINT_UNIQUE = || idx_type =3D=3D SQL_INDEX_TYPE_CONSTRAINT_PK); - const char *prefix =3D NULL; - if (idx_type =3D=3D SQL_INDEX_TYPE_CONSTRAINT_UNIQUE) { - prefix =3D constraint_name =3D=3D NULL ? - "unique_unnamed_%s_%d" : "unique_%s_%d"; - } else { - prefix =3D constraint_name =3D=3D NULL ? - "pk_unnamed_%s_%d" : "pk_%s_%d"; - } uint32_t idx_count =3D space->index_count; - if (constraint_name =3D=3D NULL || - strcmp(constraint_name, "") =3D=3D 0) { - name =3D sqlMPrintf(db, prefix, def->name, - idx_count + 1); + if (constraint_name =3D=3D NULL) { + if (idx_type =3D=3D = SQL_INDEX_TYPE_CONSTRAINT_UNIQUE) { + name =3D sqlMPrintf(db, = "unique_unnamed_%s_%d", + def->name, idx_count + = 1); + } else { + name =3D sqlMPrintf(db, = "pk_unnamed_%s_%d", + def->name, idx_count + = 1); + } } else { - name =3D sqlMPrintf(db, prefix, - constraint_name, idx_count = + 1); + name =3D sqlDbStrDup(db, constraint_name); } sqlDbFree(db, constraint_name); } diff --git a/test/sql-tap/index7.test.lua b/test/sql-tap/index7.test.lua index ed2b17c74..ca5cb1910 100755 --- a/test/sql-tap/index7.test.lua +++ b/test/sql-tap/index7.test.lua @@ -367,7 +367,7 @@ test:do_catchsql_test( "_index"."id" =3D "_space"."id" AND "_space"."name"=3D'TEST6'; ]], - {0, {"pk_unnamed_TEST6_1",0,"unique_C1_2",1}}) + {0, {"pk_unnamed_TEST6_1",0,"C1",1}}) =20 -- This test checks that CREATE TABLE statement with PK constraint -- and UNIQUE constraint is executed correctly @@ -397,6 +397,6 @@ test:do_catchsql_test( "_index"."id" =3D "_space"."id" AND "_space"."name"=3D'TEST8'; ]], - {0, {"pk_unnamed_TEST8_2",0,"unique_C1_1",1}}) + {0, {"pk_unnamed_TEST8_2",0,"C1",1}}) =20 test:finish_test() diff --git a/test/sql-tap/table.test.lua b/test/sql-tap/table.test.lua index 55187378b..2e986c59a 100755 --- a/test/sql-tap/table.test.lua +++ b/test/sql-tap/table.test.lua @@ -1283,7 +1283,7 @@ test:do_catchsql_test( INSERT INTO T22 VALUES(2, 1, 1); ]], { -- - 1,"Duplicate key exists in unique index 'unique_ONE_2' in space = 'T22'" + 1,"Duplicate key exists in unique index 'ONE' in space 'T22'" -- }) =20 @@ -1308,7 +1308,7 @@ test:do_catchsql_test( INSERT INTO T24 VALUES(2, 1, 1); ]], { -- - 1, "Duplicate key exists in unique index 'unique_TWO_2' in = space 'T24'" + 1, "Duplicate key exists in unique index 'TWO' in space 'T24'" -- }) =20 --=20 2.15.1