[tarantool-patches] Re: [PATCH 09/10] sql: disable ON CONFLICT actions for indexes
Vladislav Shpilevoy
v.shpilevoy at tarantool.org
Sat Aug 25 00:04:11 MSK 2018
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 at 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.
--
More information about the Tarantool-patches
mailing list