[tarantool-patches] Re: [PATCH 09/10] sql: disable ON CONFLICT actions for indexes

n.pettik korablev at tarantool.org
Sun Aug 26 22:44:42 MSK 2018


>> 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?

As comments says: field_count for raw data to be encoded into tuple,
one memory cell for encoded tuple, and the last one for rowid (or tupleid):
it is used for ephemeral spaces to distinguish entries. If it is not required,
then mem will contain NULL. Tuple id (regTupleId) comes first, then
raw tuple and in the end - encoded msgpack.

> 
> Then could you do it slightly more clear, like this?
> 
>    regTupleid = regIns = ++pParse->nMem;
>    pParse->nMem += def->field_count + 1;

As you wish. Simply applied your code:

+++ b/src/box/sql/insert.c
@@ -357,8 +357,8 @@ sqlite3Insert(Parse * pParse,       /* Parser context */
         * NULL), the content of the new row, and the assembled
         * row record.
         */
-       regTupleid = regIns = pParse->nMem + 1;
-       pParse->nMem += def->field_count + 2;
+       regTupleid = regIns = ++pParse->nMem;
+       pParse->nMem += def->field_count + 1



More information about the Tarantool-patches mailing list