From: imeevma@tarantool.org To: v.shpilevoy@tarantool.org Cc: korablev@tarantool.org, tarantool-patches@freelists.org Subject: [tarantool-patches] [PATCH v3 3/3] sql: use common registers instead of temp. for constraints data Date: Mon, 15 Jul 2019 18:16:25 +0300 [thread overview] Message-ID: <48c8fdb8e532302dee23309a0890a1511dc43b2e.1563203545.git.imeevma@gmail.com> (raw) In-Reply-To: <cover.1563203545.git.imeevma@gmail.com> Prior to this patch, data needed to form tuple to be inserted to _fk_constraint and _ck_constraint system spaces (to create corresponding constraints) was stored in the range of temporary register. After insertion, temporary registers are released. On the other hand, this data is required for providing clean-up in case of creation fail (i.e. removing already created constraints within one CREATE TABLE statement). Hence, instead of using temporary registers let's use ordinary ones. Closes #4183 --- src/box/sql/build.c | 16 ++++++++++------ test/sql/clear.result | 20 ++++++++++++++++++++ test/sql/clear.test.lua | 9 +++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/box/sql/build.c b/src/box/sql/build.c index c071886..2aefa2a 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -1098,7 +1098,12 @@ vdbe_emit_ck_constraint_create(struct Parse *parser, struct sql *db = parser->db; struct Vdbe *v = sqlGetVdbe(parser); assert(v != NULL); - int ck_constraint_reg = sqlGetTempRange(parser, 6); + /* + * Occupy registers for 5 fields: each member in + * _ck_constraint space plus one for final msgpack tuple. + */ + int ck_constraint_reg = parser->nMem + 1; + parser->nMem += 6; sqlVdbeAddOp2(v, OP_SCopy, reg_space_id, ck_constraint_reg); sqlVdbeAddOp4(v, OP_String8, 0, ck_constraint_reg + 1, 0, sqlDbStrDup(db, ck_def->name), P4_DYNAMIC); @@ -1122,7 +1127,6 @@ vdbe_emit_ck_constraint_create(struct Parse *parser, save_record(parser, BOX_CK_CONSTRAINT_ID, ck_constraint_reg, 2, v->nOp - 1, true); VdbeComment((v, "Create CK constraint %s", ck_def->name)); - sqlReleaseTempRange(parser, ck_constraint_reg, 5); } /** @@ -1141,10 +1145,11 @@ vdbe_emit_fk_constraint_create(struct Parse *parse_context, struct Vdbe *vdbe = sqlGetVdbe(parse_context); assert(vdbe != NULL); /* - * Occupy registers for 8 fields: each member in - * _constraint space plus one for final msgpack tuple. + * Occupy registers for 9 fields: each member in + * _fk_constraint space plus one for final msgpack tuple. */ - int constr_tuple_reg = sqlGetTempRange(parse_context, 10); + int constr_tuple_reg = parse_context->nMem + 1; + parse_context->nMem += 10; char *name_copy = sqlDbStrDup(parse_context->db, fk->name); if (name_copy == NULL) return; @@ -1231,7 +1236,6 @@ vdbe_emit_fk_constraint_create(struct Parse *parse_context, } save_record(parse_context, BOX_FK_CONSTRAINT_ID, constr_tuple_reg, 2, vdbe->nOp - 1, true); - sqlReleaseTempRange(parse_context, constr_tuple_reg, 10); return; error: parse_context->is_aborted = true; diff --git a/test/sql/clear.result b/test/sql/clear.result index 2034d82..2fb1761 100644 --- a/test/sql/clear.result +++ b/test/sql/clear.result @@ -198,3 +198,23 @@ box.space._fk_constraint:select() --- - [] ... +-- +-- Make sure that keys for tuples inserted into system spaces were +-- not stored in temporary cells. +-- +box.execute("CREATE TABLE t3(id INT PRIMARY KEY, CONSTRAINT ck1 CHECK(id > 0), CONSTRAINT ck1 FOREIGN KEY(id) REFERENCES t3, CONSTRAINT fk1 FOREIGN KEY(id) REFERENCES t3, CONSTRAINT ck1 CHECK(id < 0));") +--- +- error: Constraint CK1 already exists +... +box.space.t1 +--- +- null +... +box.space._ck_constraint:select() +--- +- [] +... +box.space._fk_constraint:select() +--- +- [] +... diff --git a/test/sql/clear.test.lua b/test/sql/clear.test.lua index 7ed18a4..4c58767 100644 --- a/test/sql/clear.test.lua +++ b/test/sql/clear.test.lua @@ -43,3 +43,12 @@ box.space._ck_constraint:select() box.execute("CREATE TABLE t2(id INT PRIMARY KEY, CONSTRAINT fk1 FOREIGN KEY(id) REFERENCES t2, CONSTRAINT fk1 FOREIGN KEY(id) REFERENCES t2);") box.space.t2 box.space._fk_constraint:select() + +-- +-- Make sure that keys for tuples inserted into system spaces were +-- not stored in temporary cells. +-- +box.execute("CREATE TABLE t3(id INT PRIMARY KEY, CONSTRAINT ck1 CHECK(id > 0), CONSTRAINT ck1 FOREIGN KEY(id) REFERENCES t3, CONSTRAINT fk1 FOREIGN KEY(id) REFERENCES t3, CONSTRAINT ck1 CHECK(id < 0));") +box.space.t1 +box.space._ck_constraint:select() +box.space._fk_constraint:select() -- 2.7.4
next prev parent reply other threads:[~2019-07-15 15:16 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-07-15 15:16 [tarantool-patches] [PATCH v3 0/3] sql: clean-up in case constraint creation failed imeevma 2019-07-15 15:16 ` [tarantool-patches] [PATCH v3 1/3] sql: add OP_SetDiag opcode in VDBE imeevma 2019-07-15 15:16 ` [tarantool-patches] [PATCH v3 2/3] sql: clean-up in case constraint creation failed imeevma 2019-07-15 15:16 ` imeevma [this message] -- strict thread matches above, loose matches on Subject: below -- 2019-07-04 10:49 [tarantool-patches] [PATCH v3 0/3] " imeevma 2019-07-04 10:49 ` [tarantool-patches] [PATCH v3 3/3] sql: use common registers instead of temp. for constraints data imeevma
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=48c8fdb8e532302dee23309a0890a1511dc43b2e.1563203545.git.imeevma@gmail.com \ --to=imeevma@tarantool.org \ --cc=korablev@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [tarantool-patches] [PATCH v3 3/3] sql: use common registers instead of temp. for constraints data' \ /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