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 2/6] sql: rework ALTER TABLE grammar
Date: Wed, 16 Jan 2019 23:06:38 +0300	[thread overview]
Message-ID: <9D3AFBAC-9E9B-4CD9-8818-4125386985D0@tarantool.org> (raw)
In-Reply-To: <65ef264c-c582-3d4d-2f5c-269c75decd98@tarantool.org>


> On 09/01/2019 15:13, Nikita Pettik wrote:
>> Since ALTER TABLE ADD CONSTRAINT can be used to add various constraint
>> types (foreign key, unique etc), we should rework its grammar.
> 
> 1. But you still can not add a unique constraint via ADD CONSTRAINT ...
> The reworked grammar can be used for foreign keys only, until the last
> commit.

Yep, and what is your objection?
Sorry, really can’t understand.

>> As a reference for it lets use one from ANSI.
>> Needed for #3097
>> ---
>>  src/box/sql/parse.y | 44 +++++++++++++++++++++++++++++---------------
>>  1 file changed, 29 insertions(+), 15 deletions(-)
>> diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y
>> index f4fdf58f2..874a67a9b 100644
>> --- a/src/box/sql/parse.y
>> +++ b/src/box/sql/parse.y
>> @@ -318,10 +318,8 @@ tcons ::= UNIQUE LP sortlist(X) RP.
>>                                                     SQL_INDEX_TYPE_CONSTRAINT_UNIQUE);}
>>  tcons ::= CHECK LP expr(E) RP onconf.
>>                                   {sql_add_check_constraint(pParse,&E);}
>> -tcons ::= FOREIGN KEY LP eidlist(FA) RP
>> -          REFERENCES nm(T) eidlist_opt(TA) refargs(R) defer_subclause_opt(D). {
>> -    sql_create_foreign_key(pParse, FA, &T, TA, D, R);
>> -}
>> +tcons ::= foreign_key_def.
> 
> 2. Sorry for a nit, but I do not like _def for non-struct things. Why not
> just foreign_key? For example, 'expr' rule is just 'expr', not 'expr_def'.
> The same about other new _def prefixes here and in the last commit.

I took these names from ANSI grammar:

<referential constraint definition> ::= …

I can expose it to foreign_key_definition, for instance.

> 
>> +
>>  %type defer_subclause_opt {int}
>>  defer_subclause_opt(A) ::= .                    {A = 0;}
>>  defer_subclause_opt(A) ::= defer_subclause(A).
>> @@ -1444,22 +1442,38 @@ cmd ::= ANALYZE.                {sqlite3Analyze(pParse, 0);}
>>  cmd ::= ANALYZE nm(X).          {sqlite3Analyze(pParse, &X);}
>>    //////////////////////// ALTER TABLE table ... ////////////////////////////////
>> -cmd ::= ALTER TABLE fullname(X) RENAME TO nm(Z). {
>> -  pParse->constraint->table_name = X;
>> +cmd ::= alter_table_start alter_table_action .
> 
> 3. The same. How about 'alter_table_action' -> 'alter_table’?

I used _action for the same reason:

<alter table statement> ::= ALTER TABLE <table name> <alter table action>
(11.10 alter table statement)

To be honest I like this naming, so I am going to keep it as is.

> Also, as I understand, you did not inline alter_table_start here
> because you need its C code be executed before alter_table_action,
> right? Then how about a comment on it?

Yep, I just followed the same pattern as for CREATE TABLE.
Came up with poor comment:

diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y
index 696400f51..de5429498 100644
--- a/src/box/sql/parse.y
+++ b/src/box/sql/parse.y
@@ -1446,6 +1446,11 @@ cmd ::= ANALYZE nm(X).          {sqlite3Analyze(pParse, &X);}
 //////////////////////// ALTER TABLE table ... ////////////////////////////////
 cmd ::= alter_table_start alter_table_action .
 
+/**
+ * We should get name of the table before processing
+ * any other rules. So, we've put this routine at
+ * the separate rule.
+ */
 alter_table_start ::= ALTER TABLE fullname(Z) . {
   pParse->constraint.table = Z;
   pParse->constraint.name.n = 0;

>> +
>> +alter_table_start ::= ALTER TABLE fullname(Z) . {
>> +  pParse->constraint->table_name = Z;
>> +  pParse->constraint->name.n = 0;
>> +}
>> +
>> +alter_table_action ::= add_constraint_def.
>> +alter_table_action ::= drop_constraint_def.
>> +/** RENAME is ANSI extension, so it comes as a very special case. */
>> +alter_table_action ::= rename.
> 
> 4. It is an extension but why is it special? It is just one of
> the ways of table alteration.

Because other actions starts from ADD/DROP/ALTER (which we still don’t have).
But ok, I’ve removed comment:

diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y
index 696400f51..82736e76a 100644
--- a/src/box/sql/parse.y
+++ b/src/box/sql/parse.y
@@ -1453,7 +1453,6 @@ alter_table_start ::= ALTER TABLE fullname(Z) . {
 
 alter_table_action ::= add_constraint_def.
 alter_table_action ::= drop_constraint_def.
-/** RENAME is ANSI extension, so it comes as a very special case. */
 alter_table_action ::= rename.

> 
>> +
>> +rename ::= RENAME TO nm(Z). {
>>    sql_alter_table_rename(pParse, &Z);
>>  }
>>  -cmd ::= ALTER TABLE fullname(X) ADD CONSTRAINT nm(Z) FOREIGN KEY
>> -        LP eidlist(FA) RP REFERENCES nm(T) eidlist_opt(TA) refargs(R)
>> -        defer_subclause_opt(D). {
>> -    pParse->constraint->table_name = X;
>> -    pParse->constraint->name = Z;
>> -    sql_create_foreign_key(pParse, FA, &T, TA, D, R);
>> +add_constraint_def ::= add_constraint_start constraint_def.
>> +
>> +add_constraint_start ::= ADD CONSTRAINT nm(Z). {
>> +  pParse->constraint->name = Z;
>>  }
>>  -cmd ::= ALTER TABLE fullname(X) DROP CONSTRAINT nm(Z). {
>> -    pParse->constraint->table_name = X;
>> -    sql_drop_foreign_key(pParse, &Z);
>> +constraint_def ::= foreign_key_def.
>> +
>> +foreign_key_def ::= FOREIGN KEY LP eidlist(FA) RP REFERENCES nm(T)
>> +                    eidlist_opt(TA) refargs(R) defer_subclause_opt(D). {
>> +  sql_create_foreign_key(pParse, FA, &T, TA, D, R);
>> +}
>> +
>> +
> 
> 5. Double empty-line.

Fixed:

@@ -1474,7 +1473,6 @@ foreign_key_def ::= FOREIGN KEY LP eidlist(FA) RP REFERENCES nm(T)
   sql_create_foreign_key(pParse, &T, TA, D, R);
 }
 
-
 drop_constraint_def ::= DROP CONSTRAINT nm(Z). {
   sql_drop_foreign_key(pParse, &Z);
 }

  reply	other threads:[~2019-01-16 20:06 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-09 12:13 [tarantool-patches] [PATCH 0/6] Introduce ALTER TABLE ADD CONSTRAINT UNIQUE/PK Nikita Pettik
2019-01-09 12:13 ` [tarantool-patches] [PATCH 1/6] sql: move constraint name to struct contraint_parse Nikita Pettik
2019-01-14 14:04   ` [tarantool-patches] " Vladislav Shpilevoy
2019-01-16 20:06     ` n.pettik
2019-01-16 20:54       ` Vladislav Shpilevoy
2019-01-17 10:56       ` Konstantin Osipov
2019-01-17 17:14         ` n.pettik
2019-01-09 12:13 ` [tarantool-patches] [PATCH 2/6] sql: rework ALTER TABLE grammar Nikita Pettik
2019-01-14 14:05   ` [tarantool-patches] " Vladislav Shpilevoy
2019-01-16 20:06     ` n.pettik [this message]
2019-01-16 20:54       ` Vladislav Shpilevoy
2019-01-17 11:51   ` Konstantin Osipov
2019-01-17 17:14     ` n.pettik
2019-01-18  1:42       ` Konstantin Osipov
2019-01-09 12:13 ` [tarantool-patches] [PATCH 3/6] sql: remove start token from sql_create_index args Nikita Pettik
2019-01-09 12:13 ` [tarantool-patches] [PATCH 4/6] sql: refactor getNewIid() function Nikita Pettik
2019-01-14 14:05   ` [tarantool-patches] " Vladislav Shpilevoy
2019-01-09 12:13 ` [tarantool-patches] [PATCH 5/6] sql: fix error message for improperly created index Nikita Pettik
2019-01-14 14:06   ` [tarantool-patches] " Vladislav Shpilevoy
2019-01-16 20:06     ` n.pettik
2019-01-09 12:13 ` [tarantool-patches] [PATCH 6/6] sql: introduce ALTER TABLE ADD CONSTRAINT UNIQUE/PRIMARY KEY Nikita Pettik
2019-01-14 14:06   ` [tarantool-patches] " Vladislav Shpilevoy
2019-01-16 20:06     ` n.pettik
2019-01-16 20:54       ` 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=9D3AFBAC-9E9B-4CD9-8818-4125386985D0@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='[tarantool-patches] Re: [PATCH 2/6] sql: rework ALTER TABLE grammar' \
    /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