[tarantool-patches] Re: [PATCH v2 1/5] sql: introduce structs assembling DDL arguments during parsing

n.pettik korablev at tarantool.org
Wed Mar 27 16:00:47 MSK 2019



> On 26 Mar 2019, at 21:06, Vladislav Shpilevoy <v.shpilevoy at tarantool.org> wrote:
> 
> Thanks for the fixes! This commit LGTM.
> Lets proceed to the next patches, and start
> with a rebase, which is going to be hard.

Ok. Then I would like to clarify some details to avoid wasting time.
In previous patch version, I used next (reworked) grammar to add
FK constraints using ALTER:

cmd ::= alter_table_start alter_table_action .

alter_table_start ::= ALTER TABLE fullname(Z) . (1)

alter_table_action ::= add_constraint_def.
alter_table_action ::= drop_constraint_def.
alter_table_action ::= rename.

add_constraint_def ::= add_constraint_start constraint_def.

add_constraint_start(N) ::= ADD CONSTRAINT nm(Z). (2)
constraint_def ::= foreign_key_def.

foreign_key_def ::= FOREIGN KEY LP eidlist(FA) RP REFERENCES nm(T)
                       eidlist_opt(TA) matcharg(M) refargs(R) defer_subclause_opt(D).

Now obviously I can’t use it since foreign_key_def should call
create_fk_def_init() which in turn requires table name and name
of constraint defined in rules (1) and (2).

Why I want to use grammar mentioned above: it allows to remove
code duplication. Rules to parse constraints are defined three times:

1. ccons rule - that is part of column definition: …, a INT REFERENCES t1);
2. tcons rule - that is part of CREATE TABLE: …, CONSTRAINT c FOREIGN KEY …);
3. ALTER TABLE statement

All of them use the same grammar to parse statement starting from
REFERENCES keyword. The same applies to UNIQUE and CHECK
constraints. 

IDK how to avoid using alter_entity_def_init() and create_constraint_def_init()
and at the same time divide constraint definition into several stages.

Ofc, we can still use simple approach like:

cmd ::= ALTER TABLE fullname(Z) ADD CONSTRAINT nm(Z)  FOREIGN KEY
             LP eidlist(FA) RP REFERENCES nm(T) eidlist_opt(TA) matcharg(M)
             refargs(R) defer_subclause_opt(D)

cmd ::= ALTER TABLE fullname(Z) ADD CONSTRAINT nm(Z)  UNIQUE
             LP sortlist(X) RP

cmd ::= ALTER TABLE fullname(Z) ADD CONSTRAINT nm(Z)  PRIMARY KEY
             LP sortlist(X) RP

cmd ::= ALTER TABLE fullname(Z) ADD CONSTRAINT nm(Z) CHECK …

cmd ::= ALTER TABLE fullname(Z) RENAME TO nm(N) .

Is this OK?





More information about the Tarantool-patches mailing list