Tarantool development patches archive
 help / color / mirror / Atom feed
From: "n.pettik" <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH v2 1/5] sql: introduce structs assembling DDL arguments during parsing
Date: Wed, 27 Mar 2019 17:11:12 +0300	[thread overview]
Message-ID: <19303130-D659-43C1-A90B-7F996E994645@tarantool.org> (raw)
In-Reply-To: <6b72e8ff-ff1c-2cc7-ced0-1811df66b3dd@tarantool.org>

[-- Attachment #1: Type: text/plain, Size: 4235 bytes --]


> On 27 Mar 2019, at 17:03, Vladislav Shpilevoy <v.shpilevoy@tarantool.org> wrote:
> On 27/03/2019 16:44, n.pettik wrote:
>> 
>>> On 27 Mar 2019, at 16:29, Vladislav Shpilevoy <v.shpilevoy@tarantool.org> wrote:
>>> On 27/03/2019 16:00, n.pettik wrote:
>>>> 
>>>>> On 26 Mar 2019, at 21:06, Vladislav Shpilevoy <v.shpilevoy@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?
>>>> 
>>> 
>>> Obviously, it is not. Why can't you define this?
>>> 
>>> alter_table_start(T) ::= ALTER TABLE fullname(T)
>>> alter_add_constraint(T, N) ::= alter_table_start(T) ADD CONSTRAINT nm(N).
>> 
>> Lemon can’t use two aliases as rule parameters at the same time.
>> Instead we can introduce *another one* local struct to hold these names.
> 
> Yes, you can define a structure in parse.y to store these two parameters,
> and unpack it back inside the concrete rules. It means, that such a
> helper struct will never be stored anywhere out of parse.y.
> 
>> Anyway my initial worry was not about duplication of ALTER TABLE CREATE CONSTRAINT,
>> but rather of constraints grammar (i.e. starting from FOREIGN KEY…).
> 
> For constraints grammar you can consult the standard. I do not remember
> how it defines FOREIGN KEY rules, if it does at all. Personally for me
> it looks ok.

Thank you for your feedback. I’m going to send rebased version of
top-most patches soon.

>>> cmd ::= alter_add_constraint(T, N) FOREIGN KEY ...
>>> cmd ::= alter_add_constraint(T, N) UNIQUE LP sortlist(X) RP
>>> cmd ::= alter_add_constraint(T, N) PRIMARY KEY LP sortlist(X) RP
>>> cmd ::= alter_add_constraint(T, N) CHECK ...
>>> cmd ::= alter_table_start RENAME TO nm(N) .
>>> 
>>> Then inside each cmd you have both table and constraint names.


[-- Attachment #2: Type: text/html, Size: 12475 bytes --]

  reply	other threads:[~2019-03-27 14:11 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-23 17:56 [tarantool-patches] [PATCH v2 0/5] Introduce ALTER TABLE ADD CONSTRAINT UNIQUE/PK Nikita Pettik
2019-01-23 17:56 ` [tarantool-patches] [PATCH v2 1/5] sql: introduce structs assembling DDL arguments during parsing Nikita Pettik
2019-01-24  8:36   ` [tarantool-patches] " Konstantin Osipov
2019-01-24 10:47     ` n.pettik
2019-01-24 12:30       ` Konstantin Osipov
2019-01-29 19:03         ` n.pettik
2019-01-29 19:29   ` Vladislav Shpilevoy
2019-01-29 20:04     ` n.pettik
2019-01-29 20:20       ` Vladislav Shpilevoy
2019-01-29 21:25         ` n.pettik
2019-01-31 19:32     ` n.pettik
2019-02-04 15:25       ` Vladislav Shpilevoy
2019-02-08 14:25         ` n.pettik
2019-02-15 20:13           ` Vladislav Shpilevoy
2019-02-27 22:56             ` n.pettik
2019-03-12 12:50               ` Vladislav Shpilevoy
2019-03-14 18:13                 ` n.pettik
2019-03-25 11:25                   ` Vladislav Shpilevoy
2019-03-26 18:01                     ` n.pettik
2019-03-26 18:06                       ` Vladislav Shpilevoy
2019-03-27 13:00                         ` n.pettik
2019-03-27 13:29                           ` Vladislav Shpilevoy
2019-03-27 13:44                             ` n.pettik
2019-03-27 14:03                               ` Vladislav Shpilevoy
2019-03-27 14:11                                 ` n.pettik [this message]
2019-01-23 17:56 ` [tarantool-patches] [PATCH v2 2/5] sql: rework ALTER TABLE grammar Nikita Pettik
2019-01-23 17:56 ` [tarantool-patches] [PATCH v2 3/5] sql: refactor getNewIid() function Nikita Pettik
2019-01-23 17:56 ` [tarantool-patches] [PATCH v2 4/5] sql: fix error message for improperly created index Nikita Pettik
2019-02-08 17:14   ` [tarantool-patches] " Konstantin Osipov
2019-01-23 17:56 ` [tarantool-patches] [PATCH v2 5/5] sql: introduce ALTER TABLE ADD CONSTRAINT UNIQUE/PRIMARY KEY Nikita Pettik
2019-01-24  8:31   ` [tarantool-patches] " Konstantin Osipov
2019-01-29 19:29   ` Vladislav Shpilevoy
2019-02-08 17:16   ` Konstantin Osipov
2019-02-08 17:36     ` n.pettik

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=19303130-D659-43C1-A90B-7F996E994645@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='[tarantool-patches] Re: [PATCH v2 1/5] sql: introduce structs assembling DDL arguments during parsing' \
    /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