From: "n.pettik" <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Imeev Mergen <imeevma@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH v1 1/1] sql: increase row_count when adding CHECK constraint
Date: Mon, 22 Jul 2019 14:22:26 +0300 [thread overview]
Message-ID: <16B9D8C3-A880-4002-8C06-BEC3D152FE8D@tarantool.org> (raw)
In-Reply-To: <5dba4410ecdc97004cd4a9890e302baa20b07529.1563525363.git.imeevma@gmail.com>
> On 19 Jul 2019, at 11:38, imeevma@tarantool.org wrote:
>
> If a CHECK constraint was added using an ALTER TABLE statement,
> row_count should be increased. Note that row_count does not
> increase if a CHECK constraint is added during the execution of a
> CREATE TABLE statement.
> For example:
>
> box.execute('CREATE TABLE t1(id INTEGER PRIMARY KEY);')
> box.execute('ALTER TABLE t1 ADD CONSTRAINT ck1 CHECK(id > 0);')
>
> Should return:
> - row_count: 1
>
> However it was '0' before the patch.
>
> Closes #4363
> —
I’ve pushed this fix:
diff --git a/src/box/sql/build.c b/src/box/sql/build.c
index 183f87505..a1a71174c 100644
--- a/src/box/sql/build.c
+++ b/src/box/sql/build.c
@@ -772,9 +772,13 @@ sql_create_check_contraint(struct Parse *parser)
return;
}
int space_id_reg = ++parser->nMem;
- sqlVdbeAddOp2(sqlGetVdbe(parser), OP_Integer, space->def->id,
+ struct Vdbe *v = sqlGetVdbe(parser);
+ sqlVdbeAddOp2(v, OP_Integer, space->def->id,
space_id_reg);
vdbe_emit_ck_constraint_create(parser, ck_def, space_id_reg);
+ assert(sqlVdbeGetOp(v, v->nOp)->opcode == OP_SInsert);
+ sqlVdbeCountChanges(v);
+ sqlVdbeChangeP5(v, OPFLAG_NCHANGE);
} else {
rlist_add_entry(&parser->create_table_def.new_check, ck_parse,
link);
@@ -1124,14 +1128,6 @@ vdbe_emit_ck_constraint_create(struct Parse *parser,
return;
sqlVdbeAddOp3(v, OP_SInsert, BOX_CK_CONSTRAINT_ID, 0,
ck_constraint_reg + 5);
- /*
- * In case constraint was added using ALTER TABLE
- * statement we should increase row_count.
- */
- if (parser->create_table_def.new_space == NULL) {
- sqlVdbeCountChanges(v);
- sqlVdbeChangeP5(v, OPFLAG_NCHANGE);
- }
save_record(parser, BOX_CK_CONSTRAINT_ID, ck_constraint_reg, 2,
v->nOp - 1, true);
VdbeComment((v, "Create CK constraint %s", ck_def->name));
next prev parent reply other threads:[~2019-07-22 11:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-19 8:38 [tarantool-patches] " imeevma
2019-07-22 11:22 ` n.pettik [this message]
2019-07-24 14:10 ` [tarantool-patches] " Kirill Yukhin
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=16B9D8C3-A880-4002-8C06-BEC3D152FE8D@tarantool.org \
--to=korablev@tarantool.org \
--cc=imeevma@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='[tarantool-patches] Re: [PATCH v1 1/1] sql: increase row_count when adding CHECK constraint' \
/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