From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 314972AB1B for ; Fri, 24 Aug 2018 17:04:13 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SJiLzq_Aq-Tr for ; Fri, 24 Aug 2018 17:04:13 -0400 (EDT) Received: from smtp39.i.mail.ru (smtp39.i.mail.ru [94.100.177.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id E69272AB05 for ; Fri, 24 Aug 2018 17:04:12 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH 09/10] sql: disable ON CONFLICT actions for indexes References: <75ebea5a7bc472e83a844cc98fc6fb88369e4b10.1534001739.git.korablev@tarantool.org> <317b019c-61ad-83f4-5a47-3818e90fa4a8@tarantool.org> From: Vladislav Shpilevoy Message-ID: Date: Sat, 25 Aug 2018 00:04:11 +0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: "n.pettik" , tarantool-patches@freelists.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 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. --