From: Nikita Pettik <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [tarantool-patches] [PATCH v4 2/4] sql: add an ability to disable CK constraints
Date: Mon, 14 Oct 2019 19:56:57 +0300 [thread overview]
Message-ID: <20191014165657.GB30792@tarantool.org> (raw)
In-Reply-To: <d4002407f749fff0c1f0facb1ed4cf66b8b7edd6.1570539526.git.kshcherbatov@tarantool.org>
On 08 Oct 16:02, Kirill Shcherbatov wrote:
> Closes #4244
>
> @TarantoolBot document
> Title: an ability to disable CK constraints
>
> Now it is possible to disable and enable ck constraints.
> This option is not persistent.
Outdated comment.
> All ck constraints are enabled
> by default when Tarantool is configured. Ck constraints checks
> are not performed during standard recovery, but performed during
> force_recovery - all conflicting tuples are skipped in case of
> ck_constraint conflict.
>
> To change CK constraint "is_enabled" state, call
> -- in LUA
> ck_obj:enable(new_state in {true, false})
> -- in SQL
> ALTER TABLE {TABLE_NAME} {EN, DIS}ABLE CHECK CONSTRAINT {CK_NAME};
>
> Example:
> box.space.T6.ck_constraint.ck_unnamed_T6_1:enable(false)
> box.space.T6.ck_constraint.ck_unnamed_T6_1
> - space_id: 512
> is_enabled: false
> name: ck_unnamed_T6_1
> expr: a < 10
> box.space.T6:insert({11})
> -- passed
> box.execute("ALTER TABLE t6 ENABLE CHECK CONSTRAINT \"ck_unnamed_T6_1\"")
> box.space.T6:insert({12})
> - error: 'Check constraint failed ''ck_unnamed_T6_1'': a < 10'
> ---
> diff --git a/src/box/sql/alter.c b/src/box/sql/alter.c
> index 765600186..500cabc5f 100644
> --- a/src/box/sql/alter.c
> +++ b/src/box/sql/alter.c
> @@ -79,6 +79,71 @@ tnt_error:
> goto exit_rename_table;
> }
>
> +void
> +sql_alter_ck_constraint_enable(struct Parse *parse)
> +{
> + struct enable_entity_def *enable_def = &parse->enable_entity_def;
> + struct SrcList *src_tab = enable_def->base.entity_name;
> + assert(enable_def->base.entity_type == ENTITY_TYPE_CK);
> + assert(enable_def->base.alter_action == ALTER_ACTION_ENABLE);
> + assert(src_tab->nSrc == 1);
> + struct sql *db = parse->db;
> +
> + char *constraint_name = NULL;
> + const char *tbl_name = src_tab->a[0].zName;
> + struct space *space = space_by_name(tbl_name);
> + if (space == NULL) {
> + diag_set(ClientError, ER_NO_SUCH_SPACE, tbl_name);
> + parse->is_aborted = true;
> + goto exit_alter_ck_constraint;
> + }
> +
> + constraint_name = sql_name_from_token(db, &enable_def->name);
> + if (constraint_name == NULL) {
> + parse->is_aborted = true;
> + goto exit_alter_ck_constraint;
> + }
> +
> + struct Vdbe *v = sqlGetVdbe(parse);
> + if (v == NULL)
> + goto exit_alter_ck_constraint;
> +
> + struct space *ck_space = space_by_id(BOX_CK_CONSTRAINT_ID);
> + assert(ck_space != NULL);
> + int cursor = parse->nTab++;
> + vdbe_emit_open_cursor(parse, cursor, 0, ck_space);
> + sqlVdbeChangeP5(v, OPFLAG_SYSTEMSP);
> +
> + int key_reg = sqlGetTempRange(parse, 2);
> + sqlVdbeAddOp2(v, OP_Integer, space->def->id, key_reg);
> + sqlVdbeAddOp4(v, OP_String8, 0, key_reg + 1, 0,
> + sqlDbStrDup(db, constraint_name), P4_DYNAMIC);
> + int addr = sqlVdbeAddOp4Int(v, OP_Found, cursor, 0, key_reg, 2);
> + sqlVdbeAddOp4(v, OP_SetDiag, ER_NO_SUCH_CONSTRAINT, 0, 0,
> + sqlMPrintf(db, tnt_errcode_desc(ER_NO_SUCH_CONSTRAINT),
> + constraint_name), P4_DYNAMIC);
> + sqlVdbeAddOp2(v, OP_Halt, -1, ON_CONFLICT_ACTION_ABORT);
> + sqlVdbeJumpHere(v, addr);
> +
> + const int field_count = 6;
> + int tuple_reg = sqlGetTempRange(parse, field_count + 1);
> + for (int i = 0; i < field_count - 1; ++i)
> + sqlVdbeAddOp3(v, OP_Column, cursor, i, tuple_reg + i);
> + sqlVdbeAddOp1(v, OP_Close, cursor);
> + sqlVdbeAddOp2(v, OP_Bool, enable_def->is_enabled,
> + tuple_reg + field_count - 1);
> + sqlVdbeAddOp3(v, OP_MakeRecord, tuple_reg, field_count,
> + tuple_reg + field_count);
> + sqlVdbeAddOp4(v, OP_IdxReplace, tuple_reg + field_count, 0, 0,
> + (char *)ck_space, P4_SPACEPTR);
> +
> +
> +
Too many new lines.
> +exit_alter_ck_constraint:
> + sqlDbFree(db, constraint_name);
> + sqlSrcListDelete(db, src_tab);
> +}
> +
> /* This function is used to implement the ALTER TABLE command.
> * The table name in the CREATE TRIGGER statement is replaced with the third
> * argument and the result returned. This is analagous to rename_table()
next prev parent reply other threads:[~2019-10-14 16:56 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1570539526.git.kshcherbatov@tarantool.org>
[not found] ` <8232b0466f3878280a9ad35cb08f437610a36486.1570539526.git.kshcherbatov@tarantool.org>
2019-10-14 16:49 ` [Tarantool-patches] [tarantool-patches] [PATCH v4 1/4] box: " Nikita Pettik
2019-10-15 11:13 ` [Tarantool-patches] [tarantool-patches] " Kirill Shcherbatov
2019-10-15 21:47 ` Nikita Pettik
2019-10-16 5:52 ` Konstantin Osipov
2019-10-16 11:19 ` Nikita Pettik
2019-10-16 13:50 ` Kirill Shcherbatov
2019-10-16 18:09 ` Nikita Pettik
[not found] ` <d4002407f749fff0c1f0facb1ed4cf66b8b7edd6.1570539526.git.kshcherbatov@tarantool.org>
2019-10-14 16:56 ` Nikita Pettik [this message]
2019-10-15 11:13 ` [Tarantool-patches] [tarantool-patches] Re: [PATCH v4 2/4] sql: " Kirill Shcherbatov
2019-10-16 18:10 ` Nikita Pettik
[not found] ` <f462f55eebcb13abb8a0611a4d84d7ed8b1a6b6a.1570539526.git.kshcherbatov@tarantool.org>
[not found] ` <af095dba-bacd-e35f-9143-30ae59188697@tarantool.org>
2019-10-15 15:15 ` [Tarantool-patches] [tarantool-patches] [PATCH v4 4/4] sql: use name instead of function pointer for UDF Nikita Pettik
2019-10-16 13:51 ` [Tarantool-patches] [tarantool-patches] " Kirill Shcherbatov
2019-10-16 18:08 ` Nikita Pettik
[not found] ` <4eb8f545449842bc4c468ccf50c494e4c44c32d6.1570539526.git.kshcherbatov@tarantool.org>
[not found] ` <20191013125109.GA24391@atlas>
[not found] ` <7114925b-190a-4f0d-409f-974d2e6a65dd@tarantool.org>
2019-10-17 13:58 ` [Tarantool-patches] [tarantool-patches] Re: [PATCH v4 3/4] box: do not evaluate ck constraints on recovery Nikita Pettik
2019-10-17 14:12 ` Konstantin Osipov
2019-10-17 14:39 ` Nikita Pettik
2019-10-17 15:18 ` Konstantin Osipov
2019-10-17 16:28 ` Nikita 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=20191014165657.GB30792@tarantool.org \
--to=korablev@tarantool.org \
--cc=tarantool-patches@dev.tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='Re: [Tarantool-patches] [tarantool-patches] [PATCH v4 2/4] sql: add an ability to disable CK constraints' \
/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