From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> To: "n.pettik" <korablev@tarantool.org>, tarantool-patches@freelists.org Subject: [tarantool-patches] Re: [PATCH 09/10] sql: disable ON CONFLICT actions for indexes Date: Sat, 25 Aug 2018 00:04:11 +0300 [thread overview] Message-ID: <dbe085fd-79d8-68ef-dd84-b757f1b2224d@tarantool.org> (raw) In-Reply-To: <FBAE2A6B-26FD-4056-8C92-DA9B0D70F600@tarantool.org> Thanks for the fixes! See 1 comment below and a commit on the branch. > diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c > index 33d243414..9da971415 100644 > --- a/src/box/sql/insert.c > +++ b/src/box/sql/insert.c > @@ -354,11 +351,14 @@ sqlite3Insert(Parse * pParse, /* Parser context */ > } > #endif /* SQLITE_OMIT_XFER_OPT */ > > - /* Allocate registers for holding the tupleid of the new row, > - * the content of the new row, and the assembled row record. > + /* > + * Allocate registers for holding the tupleid of the new > + * row (if it isn't required first register will contain > + * NULL), the content of the new row, and the assembled > + * row record. > */ > regTupleid = regIns = pParse->nMem + 1; > - pParse->nMem += def->field_count + 1; > + pParse->nMem += def->field_count + 2; Why +2? My presumption is because nMem was not incremented one line above here 'regTupleid = regIns = pParse->nMem + 1;', am I right? Why did it work before? Then could you do it slightly more clear, like this? regTupleid = regIns = ++pParse->nMem; pParse->nMem += def->field_count + 1; ... > regData = regTupleid + 1; > My diff: ==================================================== commit afd06f5dcd83715db8bf57553b784db5104c9b49 Author: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> Date: Fri Aug 24 23:41:42 2018 +0300 Review fixes diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c index 9da971415..975360f21 100644 --- a/src/box/sql/insert.c +++ b/src/box/sql/insert.c @@ -994,10 +994,10 @@ vdbe_emit_constraint_checks(struct Parse *parse_context, struct Table *tab, for (uint32_t i = 0; i < kd->part_count; ++i) { if (upd_cols[kd->parts[i].fieldno] >= 0) goto process_index; - } + } continue; } -process_index: ; +process_index: ; int cursor = parse_context->nTab++; vdbe_emit_open_cursor(parse_context, cursor, idx->def->iid, space_by_id(tab->def->id)); @@ -1047,7 +1047,6 @@ vdbe_emit_insertion_completion(struct Vdbe *v, int cursor_id, int raw_data_reg, enum on_conflict_action on_conflict) { assert(v != NULL); - int opcode = OP_IdxInsert; u16 pik_flags = OPFLAG_NCHANGE; if (on_conflict == ON_CONFLICT_ACTION_IGNORE) pik_flags |= OPFLAG_OE_IGNORE; @@ -1057,7 +1056,7 @@ vdbe_emit_insertion_completion(struct Vdbe *v, int cursor_id, int raw_data_reg, pik_flags |= OPFLAG_OE_ROLLBACK; sqlite3VdbeAddOp3(v, OP_MakeRecord, raw_data_reg, tuple_len, raw_data_reg + tuple_len); - sqlite3VdbeAddOp2(v, opcode, cursor_id, raw_data_reg + tuple_len); + sqlite3VdbeAddOp2(v, OP_IdxInsert, cursor_id, raw_data_reg + tuple_len); sqlite3VdbeChangeP5(v, pik_flags); } diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h index 9a45acedd..7340941c0 100644 --- a/src/box/sql/sqliteInt.h +++ b/src/box/sql/sqliteInt.h @@ -3916,10 +3916,10 @@ vdbe_emit_constraint_checks(struct Parse *parse_context, /** * This routine generates code to finish the INSERT or UPDATE * operation that was started by a prior call to - * sqlite3GenerateConstraintChecks. It encodes raw data which - * is held in a range of registers starting from @raw_data_reg - * and length of @tuple_len and inserts this record to space - * using given @cursor_id. + * vdbe_emit_constraint_checks. It encodes raw data which is held + * in a range of registers starting from @raw_data_reg and length + * of @tuple_len and inserts this record to space using given + * @cursor_id. * * @param v Virtual database engine. * @param cursor_id Primary index cursor. diff --git a/src/box/sql/update.c b/src/box/sql/update.c index 459ee3540..3e39688a5 100644 --- a/src/box/sql/update.c +++ b/src/box/sql/update.c @@ -148,12 +148,13 @@ sqlite3Update(Parse * pParse, /* The parser context */ int pk_cursor = pParse->nTab++; pTabList->a[0].iCursor = pk_cursor; pPk = is_view ? NULL : sqlite3PrimaryKeyIndex(pTab); - - aXRef = sqlite3DbMallocRawNN(db, sizeof(int) * def->field_count); - if (aXRef == NULL) + i = sizeof(int) * def->field_count; + aXRef = (int *) region_alloc(&pParse->region, i); + if (aXRef == NULL) { + diag_set(OutOfMemory, i, "region_alloc", "aXRef"); goto update_cleanup; - for (i = 0; i < (int)def->field_count; i++) - aXRef[i] = -1; + } + memset(aXRef, -1, i); /* Initialize the name-context */ memset(&sNC, 0, sizeof(sNC)); @@ -238,16 +239,16 @@ sqlite3Update(Parse * pParse, /* The parser context */ if (sqlite3ResolveExprNames(&sNC, pWhere)) { goto update_cleanup; } - int iPk; /* First of nPk memory cells holding PRIMARY KEY value */ - int addrOpen; /* Address of the OpenEphemeral instruction */ - - iPk = pParse->nMem + 1; + /* First of nPk memory cells holding PRIMARY KEY value. */ + int iPk = pParse->nMem + 1; pParse->nMem += pk_part_count; regKey = ++pParse->nMem; iEph = pParse->nTab++; sqlite3VdbeAddOp2(v, OP_Null, 0, iPk); - addrOpen = sqlite3VdbeAddOp2(v, OP_OpenTEphemeral, iEph, pk_part_count); + /* Address of the OpenEphemeral instruction. */ + int addrOpen = sqlite3VdbeAddOp2(v, OP_OpenTEphemeral, iEph, + pk_part_count); pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, WHERE_ONEPASS_DESIRED, pk_cursor); if (pWInfo == 0) @@ -425,14 +426,13 @@ sqlite3Update(Parse * pParse, /* The parser context */ /* Do FK constraint checks. */ if (hasFK) fkey_emit_check(pParse, pTab, regOldPk, 0, aXRef); - int addr1 = 0; /* * Delete the index entries associated with the - * current record. It can be already be removed - * by trigger or REPLACE conflict action. + * current record. It can be already removed by + * trigger or REPLACE conflict action. */ - addr1 = sqlite3VdbeAddOp4Int(v, OP_NotFound, pk_cursor, 0, - regKey, nKey); + int addr1 = sqlite3VdbeAddOp4Int(v, OP_NotFound, pk_cursor, 0, + regKey, nKey); assert(regNew == regNewPk + 1); sqlite3VdbeAddOp2(v, OP_Delete, pk_cursor, 0); sqlite3VdbeJumpHere(v, addr1); @@ -483,7 +483,6 @@ sqlite3Update(Parse * pParse, /* The parser context */ } update_cleanup: - sqlite3DbFree(db, aXRef); sqlite3SrcListDelete(db, pTabList); sql_expr_list_delete(db, pChanges); sql_expr_delete(db, pWhere, false); diff --git a/test/sql/on-conflict.result b/test/sql/on-conflict.result index 4b5d2cd7e..63fe48e79 100644 --- a/test/sql/on-conflict.result +++ b/test/sql/on-conflict.result @@ -1,24 +1,13 @@ test_run = require('test_run').new() --- ... ---- -... ---- -... engine = test_run:get_cfg('engine') --- ... ---- -... ---- -... box.sql.execute('pragma sql_default_engine=\''..engine..'\'') --- ... ---- -... ---- -... +-- -- Check that original SQLite ON CONFLICT clause is really -- disabled. -- diff --git a/test/sql/on-conflict.test.lua b/test/sql/on-conflict.test.lua index ab73249ef..b2d8e0589 100644 --- a/test/sql/on-conflict.test.lua +++ b/test/sql/on-conflict.test.lua @@ -1,12 +1,7 @@ test_run = require('test_run').new() ---- -... engine = test_run:get_cfg('engine') ---- -... box.sql.execute('pragma sql_default_engine=\''..engine..'\'') ---- -... +-- -- Check that original SQLite ON CONFLICT clause is really -- disabled. --
next prev parent reply other threads:[~2018-08-24 21:04 UTC|newest] Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-08-12 14:12 [tarantool-patches] [PATCH 00/10] sql: cleanup in struct Index and struct Table Nikita Pettik 2018-08-12 14:12 ` [tarantool-patches] [PATCH 01/10] sql: remove suport of ALTER TABLE ADD COLUMN Nikita Pettik 2018-08-13 20:24 ` [tarantool-patches] " Vladislav Shpilevoy 2018-08-12 14:12 ` [tarantool-patches] [PATCH 02/10] sql: remove string of fields collation from Table Nikita Pettik 2018-08-13 20:24 ` [tarantool-patches] " Vladislav Shpilevoy 2018-08-12 14:12 ` [tarantool-patches] [PATCH 03/10] sql: remove index hash from struct Table Nikita Pettik 2018-08-13 20:24 ` [tarantool-patches] " Vladislav Shpilevoy 2018-08-12 14:13 ` [tarantool-patches] [PATCH 04/10] sql: remove flags " Nikita Pettik 2018-08-13 20:24 ` [tarantool-patches] " Vladislav Shpilevoy 2018-08-12 14:13 ` [tarantool-patches] [PATCH 05/10] sql: remove affinity string of columns from Index Nikita Pettik 2018-08-13 20:24 ` [tarantool-patches] " Vladislav Shpilevoy 2018-08-21 16:31 ` n.pettik 2018-08-24 21:04 ` Vladislav Shpilevoy 2018-08-26 19:45 ` n.pettik 2018-08-12 14:13 ` [tarantool-patches] [PATCH 06/10] sql: completely remove support of partial indexes Nikita Pettik 2018-08-13 20:24 ` [tarantool-patches] " Vladislav Shpilevoy 2018-08-21 16:31 ` n.pettik 2018-08-24 21:04 ` Vladislav Shpilevoy 2018-08-26 19:44 ` n.pettik 2018-08-12 14:13 ` [tarantool-patches] [PATCH 07/10] sql: remove index type from struct Index Nikita Pettik 2018-08-13 20:24 ` [tarantool-patches] " Vladislav Shpilevoy 2018-08-21 16:31 ` n.pettik 2018-08-12 14:13 ` [tarantool-patches] [PATCH 08/10] sql: use secondary indexes to process OP_Delete Nikita Pettik 2018-08-13 20:24 ` [tarantool-patches] " Vladislav Shpilevoy 2018-08-12 14:13 ` [tarantool-patches] [PATCH 09/10] sql: disable ON CONFLICT actions for indexes Nikita Pettik 2018-08-13 20:24 ` [tarantool-patches] " Vladislav Shpilevoy 2018-08-21 16:31 ` n.pettik 2018-08-24 21:04 ` Vladislav Shpilevoy [this message] 2018-08-26 19:44 ` n.pettik 2018-08-27 17:24 ` Vladislav Shpilevoy 2018-08-12 14:13 ` [tarantool-patches] [PATCH 10/10] sql: move autoincrement field number to server Nikita Pettik 2018-08-13 20:24 ` [tarantool-patches] " Vladislav Shpilevoy 2018-08-21 16:31 ` n.pettik 2018-08-24 21:03 ` Vladislav Shpilevoy 2018-08-26 19:44 ` n.pettik 2018-08-27 17:24 ` Vladislav Shpilevoy 2018-08-27 17:24 ` [tarantool-patches] Re: [PATCH 00/10] sql: cleanup in struct Index and struct Table Vladislav Shpilevoy 2018-08-29 14:11 ` 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=dbe085fd-79d8-68ef-dd84-b757f1b2224d@tarantool.org \ --to=v.shpilevoy@tarantool.org \ --cc=korablev@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='[tarantool-patches] Re: [PATCH 09/10] sql: disable ON CONFLICT actions for indexes' \ /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