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 BA4FB2CD41 for ; Wed, 14 Nov 2018 07:32:57 -0500 (EST) 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 6h23cV3lB3Hy for ; Wed, 14 Nov 2018 07:32:57 -0500 (EST) Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (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 6C2812AC16 for ; Wed, 14 Nov 2018 07:32:57 -0500 (EST) Subject: [tarantool-patches] Re: [PATCH v2 2/4] sql: account REPLACE as two row changes References: <60bebfba861b6378f0bf5de24effba83370a4e7b.1542124689.git.korablev@tarantool.org> From: Vladislav Shpilevoy Message-ID: <1cb8f01c-80a8-658a-895f-31649a9e70e8@tarantool.org> Date: Wed, 14 Nov 2018 15:32:52 +0300 MIME-Version: 1.0 In-Reply-To: <60bebfba861b6378f0bf5de24effba83370a4e7b.1542124689.git.korablev@tarantool.org> 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: tarantool-patches@freelists.org, Nikita Pettik Thanks for the patch! On 13/11/2018 19:11, Nikita Pettik wrote: > In our SQL implementation REPLACE acts as DELETE + INSERT, so we should > account it as two row changes. > > Needed for #2181 > --- > src/box/sql/insert.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-)> > diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c > index fd05c0254..a53568810 100644 > --- a/src/box/sql/insert.c > +++ b/src/box/sql/insert.c > @@ -1076,7 +1076,7 @@ process_index: ; > sql_triggers_exist(tab, TK_DELETE, NULL, NULL); > sql_generate_row_delete(parse_context, tab, trigger, > cursor, idx_key_reg, part_count, > - false, > + true, > ON_CONFLICT_ACTION_REPLACE, > ONEPASS_SINGLE, -1); > sqlite3VdbeResolveLabel(v, skip_index); > I added a test on the branch and here: ========================================================== commit faff2944f609b443ec7c32b03ed8101e381f2828 Author: Vladislav Shpilevoy Date: Wed Nov 14 15:18:02 2018 +0300 Review fix diff --git a/test/sql/iproto.result b/test/sql/iproto.result index e75f79110..d077ee861 100644 --- a/test/sql/iproto.result +++ b/test/sql/iproto.result @@ -742,11 +742,11 @@ box.sql.execute('drop table test3') -- -- Ensure that FK inside CREATE TABLE does not affect rowcount. -- -cn:execute('create table test (id integer primary key)') +cn:execute('create table test (id integer primary key, a integer)') --- - rowcount: 1 ... -cn:execute('create table test2 (id integer primary key, ref integer references test)') +cn:execute('create table test2 (id integer primary key, ref integer references test(id))') --- - rowcount: 1 ... @@ -754,6 +754,18 @@ cn:execute('drop table test2') --- - rowcount: 1 ... +-- +-- Ensure that REPLACE is accounted twice in rowcount. As delete + +-- insert. +-- +cn:execute('insert into test values(1, 1)') +--- +- rowcount: 1 +... +cn:execute('insert or replace into test values(1, 2)') +--- +- rowcount: 2 +... cn:execute('drop table test') --- - rowcount: 1 diff --git a/test/sql/iproto.test.lua b/test/sql/iproto.test.lua index fb5685a9e..1470edad7 100644 --- a/test/sql/iproto.test.lua +++ b/test/sql/iproto.test.lua @@ -233,9 +233,16 @@ box.sql.execute('drop table test3') -- -- Ensure that FK inside CREATE TABLE does not affect rowcount. -- -cn:execute('create table test (id integer primary key)') -cn:execute('create table test2 (id integer primary key, ref integer references test)') +cn:execute('create table test (id integer primary key, a integer)') +cn:execute('create table test2 (id integer primary key, ref integer references test(id))') cn:execute('drop table test2') + +-- +-- Ensure that REPLACE is accounted twice in rowcount. As delete + +-- insert. +-- +cn:execute('insert into test values(1, 1)') +cn:execute('insert or replace into test values(1, 2)') cn:execute('drop table test') cn:close()