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 47897295EE for ; Tue, 21 Aug 2018 11:50:15 -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 gQX9hhmDqfVf for ; Tue, 21 Aug 2018 11:50:15 -0400 (EDT) Received: from smtp41.i.mail.ru (smtp41.i.mail.ru [94.100.177.101]) (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 06DDD295E3 for ; Tue, 21 Aug 2018 11:50:14 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH v2 1/1] sql: return last_insert_id via IPROTO References: <8f24acf7f3f1583077ba1e40ba55a849ff8864a1.1533292030.git.imeevma@gmail.com> From: Vladislav Shpilevoy Message-ID: Date: Tue, 21 Aug 2018 18:50:12 +0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Language: en-US Content-Transfer-Encoding: 8bit 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: Imeev Mergen , tarantool-patches@freelists.org Hi! Thanks for the fixes! See my 5 comments below. > commit c87a9ae3b3446e016956f6b52d34677b3e321286 > Author: Mergen Imeev > Date:   Fri Aug 17 13:24:58 2018 +0300 > >     sql: move autoincrement in vdbe > >     This patch expands changes made in issue #2981. Now NULL >     in primary key always replaced by generated value inside >     of vdbe. It allows us to get last_insert_id with easy. > >     Part of #2618 > 1. This commit LGTM. > > commit 010ec9b016ae6a49914b9e88544547ea9049e145 > Author: Mergen Imeev > Date:   Tue Jul 31 16:43:38 2018 +0300 > >     sql: return last_insert_id via IPROTO > >     After this patch client will get last_insert_id >     as additional metadata when he executes some >     statements. > >     Part of #2618 > >     @TarantoolBot document >     Title: SQL function last_insert_id() >     and IPROTO key last_insert_id. 2. Please, do not wrap Title section. TarantoolBot reads a request line by line splitting by '\n'. >     Function last_insert_id() returns first primary key value >     autogenerated in last INSERT/REPLACE statement in current >     session. User can have more than one session and this >     function will work propertly for each one of them. Return 3. Typo: 'propertly'. >     value of function is undetermined when more than one >     INSERT/REPLACE statements executed asynchronously. >     IPROTO key last_insert_id is a metadata returned through >     IPROTO after such statements as INSERT, REPLACE, UPDATE >     etc. Value of this key is equal to value returned by >     function last_insert_id() executed after the statment. 4. Typo: 'statment'. >     Example: >     CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT, a INTEGER); >     INSERT INTO test VALUES (NULL, 1); >     SELECT last_insert_id(); > diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c > index 30cd6b9..f7fbd71 100644 > --- a/src/box/sql/vdbe.c > +++ b/src/box/sql/vdbe.c > @@ -600,6 +600,11 @@ int sqlite3VdbeExec(Vdbe *p) >      u64 start;                 /* CPU clock count at start of opcode */ >  #endif >      struct session *user_session = current_session(); > +    /* > +     * Field sql_last_insert_id of current session should be > +     * set no more than once for each statement. > +     */ > +    bool is_last_insert_id_set = false; 5. Kirill Sch. is implementing #2370 feature that allows (as I hope for his implementation) to interrupt Vdbe on DML just like for DQL (SELECT) to return each affected tuple. It means, that VdbeExec will be called multiple times for a DML request. So lets move this flag into struct Vdbe into the flags section (next to 'isPrepareV2', 'expired', 'doingRerun' etc.) Let me admonish you before you started against 'bft' type usage. Use simple 'bool'. >      /*** INSERT STACK UNION HERE ***/ > >      assert(p->magic==VDBE_MAGIC_RUN);  /* sqlite3_step() verifies this */