<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 27 Mar 2019, at 17:03, Vladislav Shpilevoy <<a href="mailto:v.shpilevoy@tarantool.org" class="">v.shpilevoy@tarantool.org</a>> wrote:</div><div class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">On 27/03/2019 16:44, n.pettik wrote:</span><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><blockquote type="cite" class="">On 27 Mar 2019, at 16:29, Vladislav Shpilevoy <<a href="mailto:v.shpilevoy@tarantool.org" class="">v.shpilevoy@tarantool.org</a>> wrote:<br class="">On 27/03/2019 16:00, n.pettik wrote:<br class=""><blockquote type="cite" class=""><br class=""><blockquote type="cite" class="">On 26 Mar 2019, at 21:06, Vladislav Shpilevoy <<a href="mailto:v.shpilevoy@tarantool.org" class="">v.shpilevoy@tarantool.org</a>> wrote:<br class=""><br class="">Thanks for the fixes! This commit LGTM.<br class="">Lets proceed to the next patches, and start<br class="">with a rebase, which is going to be hard.<br class=""></blockquote><br class="">Ok. Then I would like to clarify some details to avoid wasting time.<br class="">In previous patch version, I used next (reworked) grammar to add<br class="">FK constraints using ALTER:<br class=""><br class="">cmd ::= alter_table_start alter_table_action .<br class=""><br class="">alter_table_start ::= ALTER TABLE fullname(Z) . (1)<br class=""><br class="">alter_table_action ::= add_constraint_def.<br class="">alter_table_action ::= drop_constraint_def.<br class="">alter_table_action ::= rename.<br class=""><br class="">add_constraint_def ::= add_constraint_start constraint_def.<br class=""><br class="">add_constraint_start(N) ::= ADD CONSTRAINT nm(Z). (2)<br class="">constraint_def ::= foreign_key_def.<br class=""><br class="">foreign_key_def ::= FOREIGN KEY LP eidlist(FA) RP REFERENCES nm(T)<br class="">                     eidlist_opt(TA) matcharg(M) refargs(R) defer_subclause_opt(D).<br class=""><br class="">Now obviously I can’t use it since foreign_key_def should call<br class="">create_fk_def_init() which in turn requires table name and name<br class="">of constraint defined in rules (1) and (2).<br class=""><br class="">Why I want to use grammar mentioned above: it allows to remove<br class="">code duplication. Rules to parse constraints are defined three times:<br class=""><br class="">1. ccons rule - that is part of column definition: …, a INT REFERENCES t1);<br class="">2. tcons rule - that is part of CREATE TABLE: …, CONSTRAINT c FOREIGN KEY …);<br class="">3. ALTER TABLE statement<br class=""><br class="">All of them use the same grammar to parse statement starting from<br class="">REFERENCES keyword. The same applies to UNIQUE and CHECK<br class="">constraints.<span class="Apple-converted-space"> </span><br class=""><br class="">IDK how to avoid using alter_entity_def_init() and create_constraint_def_init()<br class="">and at the same time divide constraint definition into several stages.<br class=""><br class="">Ofc, we can still use simple approach like:<br class=""><br class="">cmd ::= ALTER TABLE fullname(Z) ADD CONSTRAINT nm(Z)  FOREIGN KEY<br class="">           LP eidlist(FA) RP REFERENCES nm(T) eidlist_opt(TA) matcharg(M)<br class="">           refargs(R) defer_subclause_opt(D)<br class=""><br class="">cmd ::= ALTER TABLE fullname(Z) ADD CONSTRAINT nm(Z)  UNIQUE<br class="">           LP sortlist(X) RP<br class=""><br class="">cmd ::= ALTER TABLE fullname(Z) ADD CONSTRAINT nm(Z)  PRIMARY KEY<br class="">           LP sortlist(X) RP<br class=""><br class="">cmd ::= ALTER TABLE fullname(Z) ADD CONSTRAINT nm(Z) CHECK …<br class=""><br class="">cmd ::= ALTER TABLE fullname(Z) RENAME TO nm(N) .<br class=""><br class="">Is this OK?<br class=""><br class=""></blockquote><br class="">Obviously, it is not. Why can't you define this?<br class=""><br class="">alter_table_start(T) ::= ALTER TABLE fullname(T)<br class="">alter_add_constraint(T, N) ::= alter_table_start(T) ADD CONSTRAINT nm(N).<br class=""></blockquote><br class="">Lemon can’t use two aliases as rule parameters at the same time.<br class="">Instead we can introduce *another one* local struct to hold these names.<br class=""></blockquote><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Yes, you can define a structure in parse.y to store these two parameters,</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">and unpack it back inside the concrete rules. It means, that such a</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">helper struct will never be stored anywhere out of parse.y.</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">Anyway my initial worry was not about duplication of ALTER TABLE CREATE CONSTRAINT,<br class="">but rather of constraints grammar (i.e. starting from FOREIGN KEY…).<br class=""></blockquote><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">For constraints grammar you can consult the standard. I do not remember</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">how it defines FOREIGN KEY rules, if it does at all. Personally for me</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">it looks ok.</span><br class=""></div></blockquote><div><br class=""></div><div>Thank you for your feedback. I’m going to send rebased version of</div><div>top-most patches soon.</div><br class=""><blockquote type="cite" class=""><div class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><blockquote type="cite" class="">cmd ::= alter_add_constraint(T, N) FOREIGN KEY ...<br class="">cmd ::= alter_add_constraint(T, N) UNIQUE LP sortlist(X) RP<br class="">cmd ::= alter_add_constraint(T, N) PRIMARY KEY LP sortlist(X) RP<br class="">cmd ::= alter_add_constraint(T, N) CHECK ...<br class="">cmd ::= alter_table_start RENAME TO nm(N) .<br class=""><br class="">Then inside each cmd you have both table and constraint names.</blockquote></blockquote></div></blockquote></div><br class=""></body></html>