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 8A5C02ADBF for ; Wed, 27 Mar 2019 10:03:45 -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 iQr_24lke8DM for ; Wed, 27 Mar 2019 10:03:45 -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 DBA011FA2B for ; Wed, 27 Mar 2019 10:03:44 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH v2 1/5] sql: introduce structs assembling DDL arguments during parsing References: <0fcc585532a1f1200a7dfd4a8e911ecf9f2c94aa.1548265148.git.korablev@tarantool.org> <45655E85-4DBB-4AC4-8161-5B783C66C688@tarantool.org> <6e4d0aae-5dbe-f8d6-3bfe-7723ea2f3d9d@tarantool.org> <78138FFB-162A-4703-9A8F-CB88FD0570EE@tarantool.org> <4841a3f7-5b21-10ea-4f58-160a5639b7d9@tarantool.org> <89C4A9F1-CB69-4F7B-95FF-9FEF751F1BB6@tarantool.org> <611D6548-9882-4FB0-9D2A-828E2CAFF83D@tarantool.org> <573b3a69-3b68-c40d-e0b5-2d36a45964fb@tarantool.org> <39DC5EC0-E609-4DB9-B6A3-9B5824B88C96@tarantool.org> <29be7940-0421-9c09-df78-be9d3977f8d7@tarantool.org> <1B451F1D-39CE-410E-8EAE-55D2DB822C49@tarantool.org> From: Vladislav Shpilevoy Message-ID: <6b72e8ff-ff1c-2cc7-ced0-1811df66b3dd@tarantool.org> Date: Wed, 27 Mar 2019 17:03:42 +0300 MIME-Version: 1.0 In-Reply-To: <1B451F1D-39CE-410E-8EAE-55D2DB822C49@tarantool.org> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit 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: "n.pettik" , tarantool-patches@freelists.org On 27/03/2019 16:44, n.pettik wrote: > >> On 27 Mar 2019, at 16:29, Vladislav Shpilevoy wrote: >> On 27/03/2019 16:00, n.pettik wrote: >>> >>>> On 26 Mar 2019, at 21:06, Vladislav Shpilevoy 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. > >> 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. >