[Tarantool-patches] [PATCH v4 6/6] sql: support column addition

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Sun Oct 4 16:45:54 MSK 2020


Thanks for the patch!

>   * !IMPORTANT! Please follow instructions at start of the file
> diff --git a/src/box/sql/build.c b/src/box/sql/build.c
> index d1d240315..677099b48 100644
> --- a/src/box/sql/build.c
> +++ b/src/box/sql/build.c
> @@ -1921,29 +2110,42 @@ sql_create_foreign_key(struct Parse *parse_context)
> -	if (!is_alter) {
> +	if (!is_alter_add_constr) {
>  		if (create_def->name.n == 0) {
> -			constraint_name =
> -				sqlMPrintf(db, "fk_unnamed_%s_%d",
> -					   space->def->name,
> -					   ++parse_context->fkeys_def.count);
> +			uint32_t idx = ++parse_context->fkeys_def.count;
> +			/*
> +			 * If it is <ALTER TABLE ADD COLUMN> we
> +			 * should count the existing FK
> +			 * constraints in the space and form a
> +			 * name based on this.
> +			 */
> +			if (table_def->new_space == NULL) {
> +				struct space *original_space =
> +					space_by_name(space->def->name);
> +				assert(original_space != NULL);
> +				struct rlist *child_fk =
> +					&original_space->child_fk_constraint;
> +				struct fk_constraint *fk;
> +				rlist_foreach_entry(fk, child_fk,
> +						    in_child_space)
> +					idx++;
> +			}
> +			constraint_name = sqlMPrintf(db, "fk_unnamed_%s_%d",
> +						     space->def->name, idx);

idx is uint32_t, but the format is %d, which is int.

>  		} else {
>  			constraint_name =
>  				sql_name_from_token(db, &create_def->name);


More information about the Tarantool-patches mailing list