Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Roman Khabibov <roman.habibov@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v4 2/6] sql: refactor create_table_def and parse
Date: Sun, 4 Oct 2020 15:45:52 +0200	[thread overview]
Message-ID: <d8f137c3-ac15-1c02-7fbc-690aa1972e92@tarantool.org> (raw)
In-Reply-To: <F65D415F-203D-486C-A825-E0D11893EC6F@tarantool.org>

Hi! Thanks for the patch!

See 3 comments below.

> diff --git a/src/box/sql/build.c b/src/box/sql/build.c
> index d55c1cd71..b9f7e4638 100644
> --- a/src/box/sql/build.c
> +++ b/src/box/sql/build.c
> @@ -1147,6 +1147,88 @@ resolve_link(struct Parse *parse_context, const struct space_def *def,
>  	return -1;
>  }
>  
> +/**
> + * Emit code to create sequences, indexes, check and foreign key
> + * constraints appeared in <CREATE TABLE>.
> + */
> +static void
> +sql_vdbe_create_constraints(struct Parse *parse, int reg_space_id)

1. After looking at another SQL patch I realized that this patch
has the same issue - vdbe code generation methods should be started
from 'vdbe_emit_' prefix. We can't invent a new prefix in every
patch doing something with VDBE code. The code will eventually become
unreadable.

> +{
> +	assert(reg_space_id != 0);
> +	struct space *space = parse->create_table_def.new_space;
> +	assert(space != NULL);
> +	uint32_t i = 0;
> +	for (; i < space->index_count; ++i) {
> +		struct index *idx = space->index[i];
> +		vdbe_emit_create_index(parse, space->def, idx->def,
> +				       reg_space_id, idx->def->iid);
> +	}
> @@ -1923,10 +1942,10 @@ sql_create_foreign_key(struct Parse *parse_context)
>  	}
>  	if (!is_alter) {
>  		if (create_def->name.n == 0) {
> +			uint32_t i = ++parse_context->create_fkeys_def.count;
>  			constraint_name =
>  				sqlMPrintf(db, "fk_unnamed_%s_%d",
> -					   space->def->name,
> -					   ++table_def->fkey_count);
> +					   space->def->name, i);

2. The format uses '%d', and you pass uint32_t, which is usually '%u'
(not always). Why can't you use a mere 'int' for the counter? In
the new struct definitions and here.

>  		} else {
>  			constraint_name =
>  				sql_name_from_token(db, &create_def->name);
> diff --git a/src/box/sql/parse_def.h b/src/box/sql/parse_def.h
> index cb0ecd2fc..504d190b2 100644
> --- a/src/box/sql/parse_def.h
> +++ b/src/box/sql/parse_def.h
> @@ -205,26 +205,20 @@ struct create_entity_def {
>  struct create_table_def {
>  	struct create_entity_def base;
>  	struct space *new_space;
> -	/**
> -	 * Number of FK constraints declared within
> -	 * CREATE TABLE statement.
> -	 */
> -	uint32_t fkey_count;
> -	/**
> -	 * Foreign key constraint appeared in CREATE TABLE stmt.
> -	 */
> -	struct rlist new_fkey;
> -	/**
> -	 * Number of CK constraints declared within
> -	 * CREATE TABLE statement.
> -	 */
> -	uint32_t check_count;
> -	/** Check constraint appeared in CREATE TABLE stmt. */
> -	struct rlist new_check;
> -	/** True, if table to be created has AUTOINCREMENT PK. */
> -	bool has_autoinc;
> -	/** Id of field with AUTOINCREMENT. */
> -	uint32_t autoinc_fieldno;
> +};
> +
> +struct create_checks_def {
> +	/** List of check constraint objects. */

3. Lets try second time. What is 'check constraint object'? I can't
find 'struct check_constraint_object' in the code. The same for
foreign key constraints below.

> +	struct rlist checks;
> +	/** Count of check constraint objects. */
> +	uint32_t count;
> +};
> +
> +struct create_fkeys_def {
> +	/** List of foreign key constraint objects. */
> +	struct rlist fkeys;
> +	/** Count of foreign key constraint objects. */
> +	uint32_t count;
>  };

  reply	other threads:[~2020-10-04 13:45 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-11 21:51 [Tarantool-patches] [PATCH v4 0/6] Support column addition Roman Khabibov
2020-09-11 21:51 ` [Tarantool-patches] [PATCH v4 1/6] sql: rename TK_COLUMN to TK_COLUMN_NAME Roman Khabibov
2020-09-16 13:17   ` Nikita Pettik
2020-09-28 23:29     ` Roman Khabibov
2020-09-11 21:51 ` [Tarantool-patches] [PATCH v4 2/6] sql: refactor create_table_def and parse Roman Khabibov
2020-09-16 13:27   ` Nikita Pettik
2020-09-17 14:43     ` Vladislav Shpilevoy
2020-09-18 12:31       ` Nikita Pettik
2020-09-18 13:21         ` Roman Khabibov
2020-09-28 23:29     ` Roman Khabibov
2020-09-17 14:43   ` Vladislav Shpilevoy
2020-10-02 22:08     ` Vladislav Shpilevoy
2020-10-03 21:37     ` Roman Khabibov
2020-10-04 13:45       ` Vladislav Shpilevoy [this message]
2020-10-04 21:44         ` Roman Khabibov
2020-10-05 21:22           ` Vladislav Shpilevoy
2020-10-07 13:53             ` Roman Khabibov
2020-10-07 22:35               ` Vladislav Shpilevoy
2020-10-08 10:32                 ` Roman Khabibov
2020-09-17 15:16   ` Vladislav Shpilevoy
2020-10-02 22:08     ` Vladislav Shpilevoy
2020-09-11 21:51 ` [Tarantool-patches] [PATCH v4 3/6] schema: add box_space_field_MAX Roman Khabibov
2020-09-11 21:51 ` [Tarantool-patches] [PATCH v4 4/6] sql: use parser's region of "index" array Roman Khabibov
2020-09-16 13:30   ` Nikita Pettik
2020-09-28 23:29     ` Roman Khabibov
2020-09-17 14:53   ` Vladislav Shpilevoy
2020-09-23 14:25     ` Roman Khabibov
2020-09-24 21:30       ` Vladislav Shpilevoy
2020-10-05 21:22   ` Vladislav Shpilevoy
2020-10-07 13:53     ` Roman Khabibov
2020-09-11 21:51 ` [Tarantool-patches] [PATCH v4 5/6] box: disallow to modify format of a view Roman Khabibov
2020-09-16 13:37   ` Nikita Pettik
2020-09-22 15:59     ` Roman Khabibov
2020-09-17 15:01   ` Vladislav Shpilevoy
2020-09-22 15:59     ` Roman Khabibov
2020-09-11 21:51 ` [Tarantool-patches] [PATCH v4 6/6] sql: support column addition Roman Khabibov
2020-09-16 20:18   ` Nikita Pettik
2020-09-17 15:19     ` Vladislav Shpilevoy
2020-09-18 12:59       ` Nikita Pettik
2020-09-28 23:28         ` Roman Khabibov
2020-10-02 22:08           ` Vladislav Shpilevoy
2020-10-03 21:37             ` Roman Khabibov
2020-09-17 15:45   ` Vladislav Shpilevoy
2020-10-04 13:45   ` Vladislav Shpilevoy
2020-10-04 21:44     ` Roman Khabibov
2020-09-11 22:00 ` [Tarantool-patches] [PATCH v4 0/6] Support " Roman Khabibov
2020-10-08 22:07 ` 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=d8f137c3-ac15-1c02-7fbc-690aa1972e92@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=roman.habibov@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v4 2/6] sql: refactor create_table_def and parse' \
    /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