From: Nikita Pettik <korablev@tarantool.org> To: Roman Khabibov <roman.habibov@tarantool.org> Cc: tarantool-patches@dev.tarantool.org, Vladislav Shpilevoy <v.shpilevoy@tarantool.org> Subject: Re: [Tarantool-patches] [PATCH v2 2/3] box: make constraint operations transactional Date: Sat, 28 Dec 2019 02:18:33 +0200 [thread overview] Message-ID: <20191228001833.GA45089@tarantool.org> (raw) In-Reply-To: <88F2A14C-2D86-4C17-90F1-4B0388CF71C9@tarantool.org> On 17 Dec 18:03, Roman Khabibov wrote: > >> > >> @TarantoolBot document > >> Title: Table constraints in SQL > >> > >> SQL: > >> According to ANSI SQL, table constraint is one of the following > >> entities: PRIMARY KEY, UNIQUE, FOREIGN KEY, CHECK. Every > >> constraint have its own name passed by user or automatically have -> has > >> generated. And these names must be unique within one table/space. > >> Naming in SQL is case-insensitive, so "CONSTRAINT c" and False. Naming in SQL is case-sensitive. It's all about uppercasing unquoted identifiers: CREATE TABLE t2 (i INT, CONSTRAINT "c" CHECK (i > 0), CONSTRAINT c PRIMARY KEY (i)); --- - row_count: 1 ... > >> "CONSTRAINT C" are the same. For example, you will get error, if > >> you try to: > >> > >> CREATE TABLE t2 (i INT, CONSTRAINT c CHECK (i > 0), > >> CONSTRAINT c PRIMARY KEY (i)); > >> > >> or > >> > >> CREATE TABLE t2 (i INT CONSTRAINT c PRIMARY KEY); > >> ALTER TABLE t2 ADD CONSTRAINT c CHECK(i > 0);'); > >> The same is for any other constraint types. > >> > > +/** > + * Check if constraint with @a name exists within @a space. Call > + * diag_set() if it is so. > + */ > +static inline int > +space_check_constraint_existence(struct space *space, const char *name) IMHO this function looks a bit strange (or I'd say - contradictory). Let's simply inline it, only 2 usages tho. > +{ > + struct constraint_id *id = space_find_constraint_id(space, name); > + if (id == NULL) > + return 0; > + diag_set(ClientError, ER_CONSTRAINT_EXISTS, > + constraint_type_strs[id->type], name, space_name(space)); > + return -1; > +} > + > + > +static inline void > +space_delete_constraint_id(struct space *space, const char *name) Why do we need this wrapper? > +{ > + constraint_id_delete(space_pop_constraint_id(space, name)); > +} > + > diff --git a/src/box/errcode.h b/src/box/errcode.h > index c660b1c70..094a63ee1 100644 > --- a/src/box/errcode.h > +++ b/src/box/errcode.h > @@ -222,7 +222,7 @@ struct errcode_record { > /*167 */_(ER_CREATE_FK_CONSTRAINT, "Failed to create foreign key constraint '%s': %s") \ > /*168 */_(ER_DROP_FK_CONSTRAINT, "Failed to drop foreign key constraint '%s': %s") \ > /*169 */_(ER_NO_SUCH_CONSTRAINT, "Constraint %s does not exist") \ > - /*170 */_(ER_CONSTRAINT_EXISTS, "Constraint %s already exists") \ > + /*170 */_(ER_CONSTRAINT_EXISTS, "Constraint %s '%s' already exists in space '%s'") \ I'd better place type of constraint at the beggining of sentence: Check constraint xxx already exists Foreign key constraint ... Unique constraint ... Sounds way much better, doesn't it? > new file mode 100755 > index 000000000..b41e16dc2 > --- /dev/null > +++ b/test/sql/constraint.test.lua > @@ -0,0 +1,93 @@ > +test_run = require('test_run').new() > +engine = test_run:get_cfg('engine') > +box.execute('pragma sql_default_engine=\''..engine..'\'') > + > +-- Make sure, that altering of an index name affects its record > +-- in the space's constraint hash table. > +-- > +box.execute('CREATE UNIQUE INDEX d ON t2(i);') > +box.space.T2.index.D:alter({name = 'E'}) > +box.execute('ALTER TABLE t2 ADD CONSTRAINT e CHECK(i > 0);') As far as I see, you missed case of altering index (or other constraint) name to already occupied by another constraint. > +-- > +-- Make sure, that altering of an index uniqueness puts/drops > +-- its name to/from the space's constraint hash table. > +-- > +box.space.T2.index.E:alter({unique = false}) > +box.execute('ALTER TABLE t2 ADD CONSTRAINT e CHECK(i > 0);') > +box.space.T2.index.E:alter({unique = true}) > +box.space.T2.ck_constraint.E:drop() > +box.space.T2.index.E:alter({unique = true}) > +box.execute('ALTER TABLE t2 ADD CONSTRAINT e CHECK(i > 0);') > + > +-- Alter name and uniqueness of an unique index simultaneously. > +box.space.T2.index.E:alter({name = 'D', unique = false}) > +box.execute('CREATE UNIQUE INDEX e ON t2(i);') And make sure that CREATE UNIQUE INDEX d ON t2(i); fails What about circle renaming of consraint inside transaction which is rolled back later?
next prev parent reply other threads:[~2019-12-28 0:18 UTC|newest] Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-11-28 18:34 [Tarantool-patches] [PATCH v2 0/2] Add constraint names hash table to space Roman Khabibov 2019-11-28 18:34 ` [Tarantool-patches] [PATCH v2 1/2] box: introduce constraint names hash table Roman Khabibov 2019-11-30 1:03 ` Vladislav Shpilevoy 2019-12-04 16:23 ` [Tarantool-patches] [PATCH v2 1/3] " Roman Khabibov 2019-12-07 16:34 ` Vladislav Shpilevoy 2019-12-10 12:48 ` Roman Khabibov 2019-11-28 18:34 ` [Tarantool-patches] [PATCH v2 2/2] sql: make constraint operations transactional Roman Khabibov 2019-11-29 7:38 ` Roman Khabibov 2019-11-30 1:03 ` Vladislav Shpilevoy 2019-12-04 16:23 ` [Tarantool-patches] [PATCH v2 2/3] " Roman Khabibov 2019-12-05 18:43 ` Roman Khabibov 2019-12-07 16:35 ` Vladislav Shpilevoy 2019-12-10 12:49 ` [Tarantool-patches] [PATCH v2 2/3] box: " Roman Khabibov 2019-12-15 22:26 ` Vladislav Shpilevoy 2019-12-17 15:03 ` Roman Khabibov 2019-12-28 0:18 ` Nikita Pettik [this message] 2019-12-28 11:07 ` Vladislav Shpilevoy 2019-12-29 0:07 ` Nikita Pettik 2019-12-29 15:51 ` Vladislav Shpilevoy 2019-12-29 22:28 ` Nikita Pettik 2019-12-29 22:35 ` Vladislav Shpilevoy 2019-12-30 11:12 ` Sergey Ostanevich 2019-12-30 12:05 ` Nikita Pettik 2019-12-21 20:54 ` Sergey Ostanevich 2019-12-22 14:59 ` Vladislav Shpilevoy 2019-12-24 12:06 ` Roman Khabibov 2019-11-30 1:03 ` [Tarantool-patches] [PATCH v2 0/2] Add constraint names hash table to space Vladislav Shpilevoy 2019-12-04 16:23 ` [Tarantool-patches] [PATCH v2 0/3] " Roman Khabibov 2019-12-07 16:34 ` Vladislav Shpilevoy
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20191228001833.GA45089@tarantool.org \ --to=korablev@tarantool.org \ --cc=roman.habibov@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v2 2/3] box: make constraint operations transactional' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox