From: "n.pettik" <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH 4/5] sql: display error on FK creation and drop failure
Date: Wed, 25 Jul 2018 13:03:54 +0300 [thread overview]
Message-ID: <365C3F06-42B2-4C3D-88F6-00CF5434939A@tarantool.org> (raw)
In-Reply-To: <364e571a-da8c-f6de-fa3f-0d6f39e0d4e4@tarantool.org>
>> Before insertion to _fk_constraint we must be sure that there in no
>> entry with given <name, child id>. Otherwise, insertion will fail and
>> 'duplicate key' will be shown. Such error message doesn't seem to be
>> informative enough, so lets manually iterate through whole space looking
>> for appropriate record.
>
> 1. As I know, vdbe_emit_halt_with_presence_test do not iterate through
> the whole space. It uses an index to search for the record fast.
You are right, I’ve fixed commit message.
>
>> The same is for dropping constraint, but here vice versa: we test
>> that _fk_contraint contains entry with given name and child id.
>
> 2. Typo: _fk_contraint -> _fk_constraint.
Fixed.
>
>> It is worth mentioning that during CREATE TABLE processing schema id
>> changes and check in OP_OpenRead opcode fails (which in turn shows that
>> pointer to space may expire). On the other hand, _fk_constraint space
>> itself remains immutable, so as a temporary workaround lets use flag
>> indicating pointer to system space passed to OP_OpenRead. It makes
>> possible to use pointer to space, even if schema has changed.
>> Closes #3271
>> ---
>> src/box/errcode.h | 2 ++
>> src/box/sql/build.c | 43 +++++++++++++++++++++++++++++++------------
>> src/box/sql/sqliteInt.h | 10 +++++++---
>> src/box/sql/trigger.c | 24 ++++++++++++++++--------
>> src/box/sql/vdbe.c | 3 ++-
>> test/box/misc.result | 2 ++
>> test/sql-tap/alter2.test.lua | 25 ++++++++++++++++++++++++-
>> 7 files changed, 84 insertions(+), 25 deletions(-)
>> diff --git a/src/box/sql/build.c b/src/box/sql/build.c
>> index c2d3cd035..20ace09e4 100644
>> --- a/src/box/sql/build.c
>> +++ b/src/box/sql/build.c
>> @@ -1784,6 +1784,20 @@ vdbe_fkey_code_creation(struct Parse *parse_context, const struct fkey_def *fk)
>> sqlite3VdbeAddOp2(vdbe, OP_Integer, fk->parent_id,
>> constr_tuple_reg + 2);
>> }
>> + /*
>> + * Lets check that constraint with this name hasn't
>> + * been created before.
>> + */
>> + const char *error_msg =
>> + tt_sprintf(tnt_errcode_desc(ER_CONSTRAINT_EXISTS), name_copy);
>> + if (vdbe_emit_halt_with_presence_test(parse_context,
>> + BOX_FK_CONSTRAINT_ID, 0,
>> + constr_tuple_reg, 2,
>> + ER_CONSTRAINT_EXISTS, error_msg,
>> + false, OP_NoConflict) != 0) {
>> + free((void *) name_copy);
>
> 3. Name_copy is allocated on db.
Fixed:
+++ b/src/box/sql/build.c
@@ -1603,7 +1603,7 @@ vdbe_emit_fkey_create(struct Parse *parse_context, const struct fkey_def *fk)
constr_tuple_reg, 2,
ER_CONSTRAINT_EXISTS, error_msg,
false, OP_NoConflict) != 0) {
- free((void *) name_copy);
+ sqlite3DbFree(parse_context->db, (void *) name_copy);
>> + return;
>> + }
>> diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
>> index b9723e2e7..0f227e637 100644
>> --- a/src/box/sql/vdbe.c
>> +++ b/src/box/sql/vdbe.c
>> @@ -3172,7 +3172,8 @@ case OP_OpenWrite:
>> * during runtime.
>> */
>> if (box_schema_version() != p->schema_ver &&
>> - (pOp->p5 & OPFLAG_FRESH_PTR) == 0) {
>> + (pOp->p5 & OPFLAG_FRESH_PTR) == 0 &&
>> + (pOp->p5 & OPFLAG_SYSTEMSP) == 0) {
>
> 4. Why not p5 & (FRESH_PTR | SYSTEMSP) ?
Because I am not used to work with bit flags..
This is definitely proper way to do it. Anyway, FRESH_PTR flag has gone,
so now it is again simple (pOp->p5 & OPFLAG_SYSTEMSP) == 0 check.
next prev parent reply other threads:[~2018-07-25 10:03 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-13 2:04 [tarantool-patches] [PATCH 0/5] Move FK constraints to server Nikita Pettik
2018-07-13 2:04 ` [tarantool-patches] [PATCH 1/5] sql: prohibit creation of FK on unexisting tables Nikita Pettik
2018-07-17 21:05 ` [tarantool-patches] " Vladislav Shpilevoy
2018-07-25 10:03 ` n.pettik
2018-07-26 20:12 ` Vladislav Shpilevoy
2018-08-01 20:54 ` n.pettik
2018-08-02 22:15 ` Vladislav Shpilevoy
2018-08-06 0:27 ` n.pettik
2018-07-13 2:04 ` [tarantool-patches] [PATCH 2/5] schema: add new system space for FK constraints Nikita Pettik
2018-07-17 21:05 ` [tarantool-patches] " Vladislav Shpilevoy
2018-07-25 10:03 ` n.pettik
2018-07-26 20:12 ` Vladislav Shpilevoy
2018-08-01 20:54 ` n.pettik
2018-08-02 22:15 ` Vladislav Shpilevoy
2018-08-06 0:28 ` n.pettik
2018-08-06 18:24 ` Vladislav Shpilevoy
2018-07-13 2:04 ` [tarantool-patches] [PATCH 3/5] sql: introduce ADD CONSTRAINT statement Nikita Pettik
2018-07-17 21:05 ` [tarantool-patches] " Vladislav Shpilevoy
2018-07-25 10:03 ` n.pettik
2018-07-26 20:12 ` Vladislav Shpilevoy
2018-08-01 20:54 ` n.pettik
2018-08-02 22:15 ` Vladislav Shpilevoy
2018-08-06 0:28 ` n.pettik
2018-08-06 18:24 ` Vladislav Shpilevoy
2018-08-06 23:43 ` n.pettik
2018-07-13 2:04 ` [tarantool-patches] [PATCH 4/5] sql: display error on FK creation and drop failure Nikita Pettik
2018-07-17 21:04 ` [tarantool-patches] " Vladislav Shpilevoy
2018-07-25 10:03 ` n.pettik [this message]
2018-07-26 20:11 ` Vladislav Shpilevoy
2018-07-13 2:04 ` [tarantool-patches] [PATCH 5/5] sql: remove SQLITE_OMIT_FOREIGN_KEY define guard Nikita Pettik
2018-07-17 21:04 ` [tarantool-patches] Re: [PATCH 0/5] Move FK constraints to server Vladislav Shpilevoy
2018-08-07 14:57 ` 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=365C3F06-42B2-4C3D-88F6-00CF5434939A@tarantool.org \
--to=korablev@tarantool.org \
--cc=tarantool-patches@freelists.org \
--cc=v.shpilevoy@tarantool.org \
--subject='[tarantool-patches] Re: [PATCH 4/5] sql: display error on FK creation and drop failure' \
/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