[Tarantool-patches] [PATCH v3 3/3] sql: do not change order of inserted values
Nikita Pettik
korablev at tarantool.org
Thu Apr 16 03:09:57 MSK 2020
On 15 Apr 10:09, imeevma at tarantool.org wrote:
> My answers and new patch below.
>
> On 4/14/20 1:59 AM, Nikita Pettik wrote:
>
> diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c
> index 43a0de5..787855e 100644
> --- a/src/box/sql/insert.c
> +++ b/src/box/sql/insert.c
> @@ -455,8 +455,31 @@ sqlInsert(Parse * pParse, /* Parser context */
> reg_eph = ++pParse->nMem;
> regRec = sqlGetTempReg(pParse);
> regCopy = sqlGetTempRange(pParse, nColumn + 1);
> - sqlVdbeAddOp2(v, OP_OpenTEphemeral, reg_eph,
> - nColumn + 1);
> + /*
> + * This key_info is used to show that
> + * rowid should be the first part of PK in
> + * case we used AUTOINCREMENT feature.
> + * This way we will save initial order of
> + * the inserted values. The order is
> + * important if we use the AUTOINCREMENT
> + * feature, since changing the order can
> + * change the number inserted instead of
> + * NULL.
> + */
> + if (space->sequence != NULL) {
> + struct sql_key_info *key_info =
> + sql_key_info_new(pParse->db,
> + nColumn + 1);
> + key_info->parts[nColumn].type =
> + FIELD_TYPE_UNSIGNED;
> + key_info->is_pk_rowid = true;
> + sqlVdbeAddOp4(v, OP_OpenTEphemeral, reg_eph,
> + nColumn + 1, 0, (char *)key_info,
> + P4_KEYINFO);
> + } else {
> + sqlVdbeAddOp2(v, OP_OpenTEphemeral, reg_eph,
> + nColumn + 1);
> + }
You can remove 'else' branch and always add OP_OPenTEphemeral with
2 operands. Then inside 'if' branch invoke sqlVdbeChangeP4().
Otherwise LGTM.
More information about the Tarantool-patches
mailing list