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, 30 Jan 2019 00:25:57 +0300 [thread overview]
Message-ID: <83A4D524-1B9B-4E09-BF14-87615268DE8D@tarantool.org> (raw)
In-Reply-To: <80c8045d-bb51-7c2a-1681-9e4bd25f1c42@tarantool.org>
[-- Attachment #1: Type: text/plain, Size: 4377 bytes --]
> On 29 Jan 2019, at 23:20, Vladislav Shpilevoy <v.shpilevoy@tarantool.org> wrote:
> On 29/01/2019 23:04, n.pettik wrote:
>>> On 29 Jan 2019, at 22:29, Vladislav Shpilevoy <v.shpilevoy@tarantool.org> wrote:
>>>
>>> Hi! Thanks for the patchset! See 5 comments below.
>>>
>>>> What is more, we are going to introduce ALTER TABLE ADD CONSTRAINT
>>>> UNIQUE With new hierarchy we can extend ALTER TABLE statement with ease:
>>>> basic structures (alter -> create entity -> create constraint) are the
>>>> same for .. FOREIGN KEY/UNIQUE, but the last one will be different.
>>>> Note that grammar for CREATE TABLE statement is not trivial and consists
>>>> of wide range of sub-clauses (e.g. to parse foreign key or check
>>>> constraints). Therefore, parts of space definition are assembled
>>>> as soon as parser processes sub-rules. For this reason, current patch
>>>> doesn't affect CREATE TABLE handling.
>>>
>>> 1. Why? I do not think, that "create table" port into parse_def.h is
>>> impossible and follows from the facts above. 'Not trivial' does
>>> not mean impossible.
>>>
>>> As I see, you can create struct create_table_def, which will contain
>>> Table *pNewTable, struct rlist new_fkey, uint32_t fkey_count,
>>> bool is_new_table_autoinc. Just move some attributes from struct Parse
>>> to this new structure. Is it possible? I think, it is worth doing,
>>> because the code will look more consistent - any object change will go
>>> through parse_def.h structures.
>> Ok, it is possible.
>>>> +struct alter_entity_def {
>>>> + /** As a rule it is a name of table to be altered. */
>>>> + struct SrcList *entity_name;
>>>> +};
>>>> +
>>>> +struct rename_entity_def {
>>>> + struct alter_entity_def *base;
>>>
>>> 2. Please, look at how we usually do inheritance in C.
>>> We include base structure into a child as an attribute,
>>> not as a pointer. So you can cast the child to the parent
>>> even without touching 'base' field. Also, this change
>>> together with comment 4 allows to remove parse_def.c
>>> completely.
>> Surely, before implementing this patch I checked out
>> inheritance examples in our code base. But here we
>> have slightly different case (or I misunderstood concepts).
>> For instance, when we create memtx space, we allocate
>> enough space for base space and for memtx parent at
>> once. When we are parsing ALTER TABLE, we are able
>> to allocate memory only for base structure (alter_def),
>> since we don’t know where we will get - whether to
>> drop constraint or create constraint or rename.
>> If we used similar inheritance model, we would
>> have to realloc enough memory (for base + parent)
>> each time we get to the next rule.
>
> You haven't, if struct Parse stores a union of all
> terminal defs instead of a pointer. Then this field
> will have enough memory to fit any def, with all its
> base attributes. See the comment 4 from the original
> email. And the comment below.
>
>> What I mean:
>> alter_table_start ::= …
>> struct alter_entity_def *alter_def = malloc(sizeof(alter_def));
>> ….
>> Then we can get to “rename” rule or to “add_constraint_start”.
>> rename ::=
>> …
>> struct rename_entity_def *rename_def = malloc (sizeof(alter_def));
>> memcpy(rename_def, alter_def, sizeof(alter_def));
>> free(alter_def);
>> …
>> The same allocation and free procedures would be called
>> inside add_constraint_start.
>> Or, as an option, we can intensely use region allocation.
>> But then we are going to waste a lot of memory.
>> Is it what you talked about? Or I am wrong and you meant
>> easier way?
>
> No, you have no realloc anything, if you just remove '*' from
> all 'base' members and use union of all terminal symbols
> in struct Parse as I described. Then this union member in struct
> Parse will have enough memory to fit any terminal symbol, with
> all its inheritance levels (because of 'base' attributes, stored
> by value).
>
> It slightly similar to struct port. Base struct port has
> padding, which is able to fit any child attributes, so we
> can create base struct port, and then 'develop' it to a more
> concrete port without reallocs. Here you will have a similar
> situation, if fix my comment 4.
Thx for explanation, I’ve got it.
I forgot about union, now it’s clear.
[-- Attachment #2: Type: text/html, Size: 19700 bytes --]
next prev parent reply other threads:[~2019-01-29 21:26 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 [this message]
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
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=83A4D524-1B9B-4E09-BF14-87615268DE8D@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