From: imeevma@tarantool.org To: korablev@tarantool.org Cc: tarantool-patches@freelists.org Subject: [tarantool-patches] [PATCH v2 3/3] sql: Fix destructors for constraints Date: Fri, 28 Jun 2019 15:07:57 +0300 [thread overview] Message-ID: <601cfb013ff3054f095261494fabcad0dc141246.1561720728.git.imeevma@gmail.com> (raw) In-Reply-To: <cover.1561720728.git.imeevma@gmail.com> Prior to this patch, the data needed to create the constraints in VDBE was stored in the temporary registers of the parser. Since this data is necessary for creating destructors, it was transferred to standard registers. 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 15b8162..aa2d55d 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -1078,7 +1078,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); @@ -1102,7 +1107,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); } /** @@ -1121,10 +1125,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; @@ -1211,7 +1216,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 4e10b0e..cb98765 100644 --- a/test/sql/clear.result +++ b/test/sql/clear.result @@ -195,3 +195,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 4e212e3..a2ec209 100644 --- a/test/sql/clear.test.lua +++ b/test/sql/clear.test.lua @@ -40,3 +40,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-06-28 12:08 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-06-28 12:07 [tarantool-patches] [PATCH v2 0/3] sql: clean-up in case constraint creation failed imeevma 2019-06-28 12:07 ` [tarantool-patches] [PATCH v2 1/3] sql: add OP_SetDiag opcode in VDBE imeevma 2019-07-02 23:27 ` [tarantool-patches] " n.pettik 2019-06-28 12:07 ` [tarantool-patches] [PATCH v2 2/3] sql: clean-up in case constraint creation failed imeevma 2019-06-28 12:07 ` imeevma [this message] 2019-07-02 23:27 ` [tarantool-patches] Re: [PATCH v2 3/3] sql: Fix destructors for constraints n.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=601cfb013ff3054f095261494fabcad0dc141246.1561720728.git.imeevma@gmail.com \ --to=imeevma@tarantool.org \ --cc=korablev@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH v2 3/3] sql: Fix destructors for 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