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 2A8E82280E for ; Thu, 19 Jul 2018 13:26:34 -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 OAf-AWUF6E11 for ; Thu, 19 Jul 2018 13:26:33 -0400 (EDT) Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 4E71322603 for ; Thu, 19 Jul 2018 13:26:33 -0400 (EDT) Received: by mail-lf1-f51.google.com with SMTP id b22-v6so93194lfa.3 for ; Thu, 19 Jul 2018 10:26:32 -0700 (PDT) MIME-Version: 1.0 References: <5BB99B27-5F86-4664-AAD5-57A22ECED854@tarantool.org> <93E4DAEA-EF90-479D-9F62-3D1CEB3CBE3F@tarantool.org> <20180628101839.fhnijezdpwviohop@tkn_work_nb> <20180709155006.fwrikbznqk23ger5@tkn_work_nb> <79D03E96-0BD0-418D-9DB2-45318C734628@tarantool.org> <8B8D5501-075D-4BEB-B282-35B0B81CD555@tarantool.org> <605B15EF-BD1C-4B03-8A9F-6E6225076812@tarantool.org> <12B62C73-9BEC-49FA-B3FD-590C445CF25B@tarantool.org> In-Reply-To: <12B62C73-9BEC-49FA-B3FD-590C445CF25B@tarantool.org> From: Nikita Tatunov Date: Thu, 19 Jul 2018 20:26:19 +0300 Message-ID: Subject: [tarantool-patches] Re: [PATCH] sql: xfer optimization issue Content-Type: multipart/alternative; boundary="000000000000e4e16f05715d7a7c" 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: korablev@tarantool.org Cc: tarantool-patches@freelists.org --000000000000e4e16f05715d7a7c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable =D1=87=D1=82, 19 =D0=B8=D1=8E=D0=BB. 2018 =D0=B3. =D0=B2 3:20, n.pettik : > When answering on review, include only chunks related to your answers. > Otherwise, letter becomes really long.. > > I'm sorry. > > > > > @@ -1725,9 +1727,9 @@ xferOptimization(Parse * pParse, /* > Parser context */ > > > int emptyDestTest =3D 0; /* Address of test for empty pDest */ > > > int emptySrcTest =3D 0; /* Address of test for empty pSrc */ > > > Vdbe *v; /* The VDBE we are building */ > > > - int destHasUniqueIdx =3D 0; /* True if pDest has a UNIQUE > index */ > > > int regData, regTupleid; /* Registers holding data and > tupleid */ > > > struct session *user_session =3D current_session(); > > > + bool is_err_action_default =3D false; > > > > Again: why do you need this flag? Default action is just synonym for > ABORT, > > so why should we care about it? > > > > > > It's all about conflict action priorities as I said before. > > Consider the following example: > > ``` > > CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT REPLACE= , > b); > > CREATE TABLE t2(a INTEGER PRIMARY KEY ON CONFLICT REPLACE= , > b); > > INSERT INTO t1 VALUES (1, 1), (3, 3), (5, 5); > > INSERT INTO t2 VALUES (2, 2), (3, 4); > > BEGIN; > > INSERT INTO t2 VALUES (4, 4); > > INSERT INTO t2 SELECT * FROM t1; > > INSERT INTO t2 VALUES (10, 10); > > COMMIT; > > onError is an action of whole statement, not of index. > In your example onError =3D=3D ABORT =3D=3D DEFAULT. > Replace action of index is not involved in code you wrote. > As we discussed, was *_ABORT explicitly set or not makes sense till we have conflict actions on indices. > > >+ uint32_t src_space_id =3D SQLITE_PAGENO_TO_SPACEID(pSrc->tnum); > >+ struct space *src_space =3D space_by_id(src_space_id); > >+ uint32_t dest_space_id =3D SQLITE_PAGENO_TO_SPACEID(pDest->tnum); > >+ struct space *dest_space =3D space_by_id(dest_space_id); > > Move here also assert: > > assert(src_space !=3D NULL && dest_space !=3D NULL); > > Done. > > > diff --git a/test/sql-tap/gh-3307-xfer-optimization-issue.test.lua > b/test/sql-tap/gh-3307-xfer-optimization-issue.test.lua > > > new file mode 100755 > > > index 0000000..e75fabc > > > --- /dev/null > > > +test:do_catchsql_test( > > > + "xfer-optimization-1.15", > > > + [[ > > > + DROP TABLE t1; > > > + DROP TABLE t2; > > > + CREATE TABLE t1(a INTEGER PRIMARY KEY, b UNIQUE); > > > + CREATE TABLE t2(a INTEGER PRIMARY KEY, b UNIQUE); > > > + INSERT INTO t1 VALUES (2, 2), (3, 3), (5, 5); > > > + INSERT INTO t2 VALUES (1, 1), (4, 4); > > > + INSERT OR ROLLBACK INTO t2 SELECT * FROM t1; > > > > INSERT OT ROLLBACK outside transaction works the same as ABORT and > DEFAULT. > > So, surround it with transaction and check that it really rollbacks. > > > > There are basically almost the same tests surrounded by transactions > (1.30 - 1.35). > > If so, remove redundant tests pls. > > Removed them. Also added tests that check if xfer was actually used in first bunch of tests. > > -/* Opcode: RowData P1 P2 * * * > > +/* Opcode: RowData P1 P2 * * P5 > > * Synopsis: r[P2]=3Ddata > > * > > * Write into register P2 the complete row content for the row at > > @@ -3984,6 +3994,8 @@ case OP_SorterData: { > > * There is no interpretation of the data. > > * It is just copied onto the P2 register exactly as > > * it is found in the database file. > > + * P5 can be used in debug mode to check if xferOptimization has > > + * actually started processing. > > * > > * If cursor P1 is an index, then the content is the key of the row. > > * If cursor P2 is a table, then the content extracted is the data. > > @@ -3996,6 +4008,13 @@ case OP_RowData: { > > BtCursor *pCrsr; > > u32 n; > > > > +#ifdef SQLITE_TEST > > + if (pOp->p5 =3D=3D 1) { > > Use named value (i.e. OPFLAG_XFER_OPT) even if they are the same. > > Thank you, forgot about this place when defined it. > > + > > +test:do_execsql_test( > > + "xfer-optimization-1.37", > > + [[ > > + INSERT INTO t2 VALUES (10, 10); > > Here (and in some other places) smth wrong with indentation, fix it pls. > > Indentation shows if stmt is in transaction, probably it looks a little weird, but I'm more inclined to leave it there. Diff that compares patch to prev. one: diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c index c2df1c2..3c3bf37 100644 --- a/src/box/sql/insert.c +++ b/src/box/sql/insert.c @@ -1733,12 +1733,8 @@ xferOptimization(Parse * pParse, /* Parser context *= / if (space_trigger_list(pDest->def->id) !=3D NULL) return 0; if (onError =3D=3D ON_CONFLICT_ACTION_DEFAULT) { - if (pDest->iPKey >=3D 0) - onError =3D pDest->keyConf; - if (onError =3D=3D ON_CONFLICT_ACTION_DEFAULT) { - onError =3D ON_CONFLICT_ACTION_ABORT; - is_err_action_default =3D true; - } + onError =3D ON_CONFLICT_ACTION_ABORT; + is_err_action_default =3D true; } assert(pSelect->pSrc); /* allocated even if there is no FROM clause */ if (pSelect->pSrc->nSrc !=3D 1) { @@ -1804,6 +1800,7 @@ xferOptimization(Parse * pParse, /* Parser context */ struct space *src_space =3D space_by_id(src_space_id); uint32_t dest_space_id =3D SQLITE_PAGENO_TO_SPACEID(pDest->tnum); struct space *dest_space =3D space_by_id(dest_space_id); + assert(src_space !=3D NULL && dest_space !=3D NULL); for (i =3D 0; i < (int)pDest->def->field_count; i++) { enum affinity_type dest_affinity =3D pDest->def->fields[i].affinity; @@ -1823,7 +1820,6 @@ xferOptimization(Parse * pParse, /* Parser context */ } /* Default values for second and subsequent columns need to match. */ if (i > 0) { - assert(src_space !=3D NULL && dest_space !=3D NULL); char *src_expr_str =3D src_space->def->fields[i].default_value; char *dest_expr_str =3D @@ -1885,12 +1881,11 @@ xferOptimization(Parse * pParse, /* Parser context */ /* * Xfer optimization is unable to correctly insert data - * in case there's a conflict action other than *_ABORT. - * This is the reason we want to only run it if the - * destination table is initially empty. + * in case there's a conflict action other than + * explicit *_ABORT. This is the reason we want to only + * run it if the destination table is initially empty. * That block generates code to make that determination. */ - if (!(onError =3D=3D ON_CONFLICT_ACTION_ABORT && is_err_action_default =3D=3D false)) { addr1 =3D sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0); diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index 5f9bc13..bc169d9 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -4009,7 +4009,7 @@ case OP_RowData: { u32 n; #ifdef SQLITE_TEST - if (pOp->p5 =3D=3D 1) { + if (pOp->p5 =3D=3D OPFLAG_XFER_OPT) { pOp->p5 =3D 0; sql_xfer_count++; } diff --git a/test/sql-tap/gh-3307-xfer-optimization-issue.test.lua b/test/sql-tap/gh-3307-xfer-optimization-issue.test.lua index 34f603f..29f0efe 100755 --- a/test/sql-tap/gh-3307-xfer-optimization-issue.test.lua +++ b/test/sql-tap/gh-3307-xfer-optimization-issue.test.lua @@ -1,9 +1,29 @@ #!/usr/bin/env tarantool test =3D require("sqltester") -test:plan(44) +test:plan(46) local bfr, aftr +local function do_xfer_test(test_number, return_code) + test_name =3D string.format("xfer-optimization-1.%d", test_number) + test:do_test( + test_name, + function() + if (aftr - bfr =3D=3D 1) then + return {1} + end + if (aftr =3D=3D bfr) then + return {0} + end + end, { + -- + return_code + -- + }) +end + +bfr =3D box.sql.debug().sql_xfer_count + test:do_catchsql_test( "xfer-optimization-1.1", [[ @@ -17,6 +37,8 @@ test:do_catchsql_test( -- }) +aftr =3D box.sql.debug().sql_xfer_count + test:do_execsql_test( "xfer-optimization-1.2", [[ @@ -27,8 +49,12 @@ test:do_execsql_test( -- }) +do_xfer_test(3, 1) + +bfr =3D box.sql.debug().sql_xfer_count + test:do_catchsql_test( - "xfer-optimization-1.3", + "xfer-optimization-1.4", [[ DROP TABLE t1; DROP TABLE t2; @@ -39,23 +65,29 @@ test:do_catchsql_test( INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3); INSERT INTO t2 SELECT * FROM t1; ]], { - -- + -- 0 - -- + -- }) +aftr =3D box.sql.debug().sql_xfer_count + test:do_execsql_test( - "xfer-optimization-1.4", + "xfer-optimization-1.5", [[ SELECT * FROM t2; ]], { - -- + -- 1, 1, 2, 2, 3, 3 - -- + -- }) +do_xfer_test(6, 1) + +bfr =3D box.sql.debug().sql_xfer_count + test:do_catchsql_test( - "xfer-optimization-1.5", + "xfer-optimization-1.7", [[ DROP TABLE t1; DROP TABLE t2; @@ -64,23 +96,29 @@ test:do_catchsql_test( CREATE TABLE t2(a INTEGER PRIMARY KEY, b INTEGER); INSERT INTO t2 SELECT * FROM t1; ]], { - -- + -- 1, "table T2 has 2 columns but 3 values were supplied" - -- + -- }) +aftr =3D box.sql.debug().sql_xfer_count + test:do_execsql_test( - "xfer-optimization-1.6", + "xfer-optimization-1.8", [[ SELECT * FROM t2; ]], { - -- + -- - -- + -- }) +do_xfer_test(9, 0) + +bfr =3D box.sql.debug().sql_xfer_count + test:do_catchsql_test( - "xfer-optimization-1.7", + "xfer-optimization-1.10", [[ DROP TABLE t1; DROP TABLE t2; @@ -89,23 +127,29 @@ test:do_catchsql_test( CREATE TABLE t2(a INTEGER PRIMARY KEY, b INTEGER); INSERT INTO t2 SELECT * FROM t1; ]], { - -- + -- 0 - -- + -- }) +aftr =3D box.sql.debug().sql_xfer_count + test:do_execsql_test( - "xfer-optimization-1.8", + "xfer-optimization-1.11", [[ SELECT * FROM t2; ]], { - -- + -- 1, 1, 2, 2, 3, 3 - -- + -- }) +do_xfer_test(12, 1); + +bfr =3D box.sql.debug().sql_xfer_count + test:do_catchsql_test( - "xfer-optimization-1.9", + "xfer-optimization-1.13", [[ DROP TABLE t1; DROP TABLE t2; @@ -114,23 +158,29 @@ test:do_catchsql_test( CREATE TABLE t2(b INTEGER, a INTEGER PRIMARY KEY); INSERT INTO t2 SELECT * FROM t1; ]], { - -- + -- 1, "Duplicate key exists in unique index 'sqlite_autoindex_T2_1' in space 'T2'" - -- + -- }) +aftr =3D box.sql.debug().sql_xfer_count + test:do_execsql_test( - "xfer-optimization-1.10", + "xfer-optimization-1.14", [[ SELECT * FROM t2; ]], { - -- + -- - -- + -- }) +do_xfer_test(15, 0) + +bfr =3D box.sql.debug().sql_xfer_count + test:do_catchsql_test( - "xfer-optimization-1.11", + "xfer-optimization-1.16", [[ DROP TABLE t1; DROP TABLE t2; @@ -139,72 +189,24 @@ test:do_catchsql_test( CREATE TABLE t2(b INTEGER PRIMARY KEY, a INTEGER); INSERT INTO t2 SELECT * FROM t1; ]], { - -- + -- 0 - -- - }) - -test:do_execsql_test( - "xfer-optimization-1.12", - [[ - SELECT * FROM t2; - ]], { - -- - 1, 1, 2, 2, 3, 2 - -- + -- }) -test:do_catchsql_test( - "xfer-optimization-1.13", - [[ - DROP TABLE t1; - DROP TABLE t2; - CREATE TABLE t1(a INTEGER PRIMARY KEY, b); - CREATE TABLE t2(a INTEGER PRIMARY KEY, b); - INSERT INTO t1 VALUES (3, 3), (4, 4), (5, 5); - INSERT INTO t2 VALUES (1, 1), (2, 2); - INSERT INTO t2 SELECT * FROM t1; - ]], { - -- - 0 - -- - }) +aftr =3D box.sql.debug().sql_xfer_count test:do_execsql_test( - "xfer-optimization-1.14", + "xfer-optimization-1.17", [[ SELECT * FROM t2; ]], { - -- - 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 - -- + -- + 1, 1, 2, 2, 3, 2 + -- }) -test:do_catchsql_test( - "xfer-optimization-1.15", - [[ - DROP TABLE t1; - DROP TABLE t2; - CREATE TABLE t1(a INTEGER PRIMARY KEY, b UNIQUE); - CREATE TABLE t2(a INTEGER PRIMARY KEY, b UNIQUE); - INSERT INTO t1 VALUES (2, 2), (3, 3), (5, 5); - INSERT INTO t2 VALUES (1, 1), (4, 4); - INSERT OR ROLLBACK INTO t2 SELECT * FROM t1; - ]], { - -- - 0 - -- - }) - -test:do_execsql_test( - "xfer-optimization-1.16", - [[ - SELECT * FROM t2; - ]], { - -- - 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 - -- - }) +do_xfer_test(18, 1) -- The following tests are supposed to test if xfer-optimization is actually -- used in the given cases (if the conflict actually occurs): @@ -220,23 +222,6 @@ test:do_execsql_test( -- 5) insert with fail -- 6) insert with ignore -local function do_xfer_test(test_number, return_code) - test_name =3D string.format("xfer-optimization-1.%d", test_number) - test:do_test( - test_name, - function() - if (aftr - bfr =3D=3D 1) then - return {1} - end - if (aftr =3D=3D bfr) then - return {0} - end - end, { - -- - return_code - -- - }) -end -- 1.0) insert w/o explicit confl. action & w/o index replace action --------------------------------------------------------------------------= ---- @@ -244,7 +229,7 @@ end bfr =3D box.sql.debug().sql_xfer_count test:do_catchsql_test( - "xfer-optimization-1.17", + "xfer-optimization-1.19", [[ DROP TABLE t1; DROP TABLE t2; @@ -256,26 +241,26 @@ test:do_catchsql_test( INSERT INTO t2 VALUES (4, 4); INSERT INTO t2 SELECT * FROM t1; ]], { - -- + -- 1, "Duplicate key exists in unique index 'sqlite_autoindex_T2_1' in space 'T2'" - -- + -- }) test:do_execsql_test( - "xfer-optimization-1.18", + "xfer-optimization-1.20", [[ INSERT INTO t2 VALUES (10, 10); COMMIT; SELECT * FROM t2; ]], { - -- + -- 2, 2, 3, 4, 4, 4, 10, 10 - -- + -- }) aftr =3D box.sql.debug().sql_xfer_count -do_xfer_test(19, 0) +do_xfer_test(21, 0) -- 1.1) insert w/o explicit confl. action & w/ -- index replace action & empty dest_table @@ -284,7 +269,7 @@ do_xfer_test(19, 0) bfr =3D box.sql.debug().sql_xfer_count test:do_catchsql_test( - "xfer-optimization-1.20", + "xfer-optimization-1.22", [[ DROP TABLE t1; DROP TABLE t2; @@ -296,36 +281,36 @@ test:do_catchsql_test( INSERT INTO t3 VALUES (1); INSERT INTO t2 SELECT * FROM t1; ]], { - -- + -- 0 - -- + -- }) test:do_execsql_test( - "xfer-optimization-1.21", + "xfer-optimization-1.23", [[ INSERT INTO t2 VALUES (10, 10); COMMIT; SELECT * FROM t2; ]], { - -- + -- 1, 1, 3, 3, 5, 5, 10, 10 - -- + -- }) aftr =3D box.sql.debug().sql_xfer_count test:do_execsql_test( - "xfer-optimization-1.22", + "xfer-optimization-1.24", [[ SELECT * FROM t3; ]], { - -- + -- 1 - -- + -- }) -do_xfer_test(23, 1) +do_xfer_test(25, 1) -- 1.2) insert w/o explicit confl. action & w/ -- index replace action & non-empty dest_table @@ -334,7 +319,7 @@ do_xfer_test(23, 1) bfr =3D box.sql.debug().sql_xfer_count test:do_catchsql_test( - "xfer-optimization-1.24", + "xfer-optimization-1.26", [[ DROP TABLE t1; DROP TABLE t2; @@ -347,26 +332,26 @@ test:do_catchsql_test( INSERT INTO t2 VALUES (4, 4); INSERT INTO t2 SELECT * FROM t1; ]], { - -- + -- 0 - -- + -- }) test:do_execsql_test( - "xfer-optimization-1.25", + "xfer-optimization-1.27", [[ INSERT INTO t2 VALUES (10, 10); COMMIT; SELECT * FROM t2; ]], { - -- + -- 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 10, 10 - -- + -- }) aftr =3D box.sql.debug().sql_xfer_count -do_xfer_test(26, 0) +do_xfer_test(28, 0) -- 2) insert with abort --------------------------------------------------------------------------= ---- @@ -374,7 +359,7 @@ do_xfer_test(26, 0) bfr =3D box.sql.debug().sql_xfer_count test:do_catchsql_test( - "xfer-optimization-1.27", + "xfer-optimization-1.29", [[ DROP TABLE t1; DROP TABLE t2; @@ -386,26 +371,26 @@ test:do_catchsql_test( INSERT INTO t2 VALUES (4, 4); INSERT OR ABORT INTO t2 SELECT * FROM t1; ]], { - -- + -- 1, "Duplicate key exists in unique index 'sqlite_autoindex_T2_1' in space 'T2'" - -- + -- }) test:do_execsql_test( - "xfer-optimization-1.28", + "xfer-optimization-1.30", [[ INSERT INTO t2 VALUES (10, 10); COMMIT; SELECT * FROM t2; ]], { - -- + -- 2, 2, 3, 4, 4, 4, 10, 10 - -- + -- }) aftr =3D box.sql.debug().sql_xfer_count -do_xfer_test(29, 1) +do_xfer_test(31, 1) -- 3.0) insert with rollback (into empty table) --------------------------------------------------------------------------= ---- @@ -413,7 +398,7 @@ do_xfer_test(29, 1) bfr =3D box.sql.debug().sql_xfer_count test:do_catchsql_test( - "xfer-optimization-1.30", + "xfer-optimization-1.32", [[ DROP TABLE t1; DROP TABLE t2; @@ -423,26 +408,26 @@ test:do_catchsql_test( BEGIN; INSERT OR ROLLBACK INTO t2 SELECT * FROM t1; ]], { - -- + -- 0 - -- + -- }) test:do_execsql_test( - "xfer-optimization-1.31", + "xfer-optimization-1.33", [[ INSERT INTO t2 VALUES (10, 10); COMMIT; SELECT * FROM t2; ]], { - -- + -- 1, 1, 3, 3, 5, 5, 10, 10 - -- + -- }) aftr =3D box.sql.debug().sql_xfer_count -do_xfer_test(32, 1) +do_xfer_test(34, 1) -- 3.1) insert with rollback (into non-empty table) --------------------------------------------------------------------------= ---- @@ -450,7 +435,7 @@ do_xfer_test(32, 1) bfr =3D box.sql.debug().sql_xfer_count test:do_catchsql_test( - "xfer-optimization-1.33", + "xfer-optimization-1.35", [[ DROP TABLE t1; DROP TABLE t2; @@ -462,24 +447,24 @@ test:do_catchsql_test( INSERT INTO t2 VALUES (4, 4); INSERT OR ROLLBACK INTO t2 SELECT * FROM t1; ]], { - -- + -- 1, "UNIQUE constraint failed: T2.A" - -- + -- }) test:do_execsql_test( - "xfer-optimization-1.34", + "xfer-optimization-1.36", [[ SELECT * FROM t2; ]], { - -- + -- 2, 2, 3, 4 - -- + -- }) aftr =3D box.sql.debug().sql_xfer_count -do_xfer_test(35, 0) +do_xfer_test(37, 0) -- 4) insert with replace --------------------------------------------------------------------------= ---- @@ -487,7 +472,7 @@ do_xfer_test(35, 0) bfr =3D box.sql.debug().sql_xfer_count test:do_catchsql_test( - "xfer-optimization-1.36", + "xfer-optimization-1.38", [[ DROP TABLE t1; DROP TABLE t2; @@ -499,26 +484,26 @@ test:do_catchsql_test( INSERT INTO t2 VALUES (4, 4); INSERT OR REPLACE INTO t2 SELECT * FROM t1; ]], { - -- + -- 0 - -- + -- }) test:do_execsql_test( - "xfer-optimization-1.37", + "xfer-optimization-1.39", [[ INSERT INTO t2 VALUES (10, 10); COMMIT; SELECT * FROM t2; ]], { - -- + -- 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 10, 10 - -- + -- }) aftr =3D box.sql.debug().sql_xfer_count -do_xfer_test(38, 0) +do_xfer_test(40, 0) -- 5) insert with fail --------------------------------------------------------------------------= ---- @@ -526,7 +511,7 @@ do_xfer_test(38, 0) bfr =3D box.sql.debug().sql_xfer_count test:do_catchsql_test( - "xfer-optimization-1.39", + "xfer-optimization-1.41", [[ DROP TABLE t1; DROP TABLE t2; @@ -538,26 +523,26 @@ test:do_catchsql_test( INSERT INTO t2 VALUES (4, 4); INSERT OR FAIL INTO t2 SELECT * FROM t1; ]], { - -- + -- 1, "Duplicate key exists in unique index 'sqlite_autoindex_T2_1' in space 'T2'" - -- + -- }) test:do_execsql_test( - "xfer-optimization-1.40", + "xfer-optimization-1.42", [[ INSERT INTO t2 VALUES (10, 10); COMMIT; SELECT * FROM t2; ]], { - -- + -- 1, 1, 2, 2, 3, 4, 4, 4, 10, 10 - -- + -- }) aftr =3D box.sql.debug().sql_xfer_count -do_xfer_test(41, 0) +do_xfer_test(43, 0) -- 6) insert with ignore --------------------------------------------------------------------------= ---- @@ -565,7 +550,7 @@ do_xfer_test(41, 0) bfr =3D box.sql.debug().sql_xfer_count test:do_catchsql_test( - "xfer-optimization-1.42", + "xfer-optimization-1.44", [[ DROP TABLE t1; DROP TABLE t2; @@ -577,25 +562,25 @@ test:do_catchsql_test( INSERT INTO t2 VALUES (4, 4); INSERT OR IGNORE INTO t2 SELECT * FROM t1; ]], { - -- + -- 0 - -- + -- }) test:do_execsql_test( - "xfer-optimization-1.43", + "xfer-optimization-1.45", [[ INSERT INTO t2 VALUES (10, 10); COMMIT; SELECT * FROM t2; ]], { - -- + -- 1, 1, 2, 2, 3, 4, 4, 4, 5, 5, 10, 10 - -- + -- }) aftr =3D box.sql.debug().sql_xfer_count -do_xfer_test(44, 0) +do_xfer_test(46, 0) test:finish_test() --000000000000e4e16f05715d7a7c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=D1=87= =D1=82, 19 =D0=B8=D1=8E=D0=BB. 2018 =D0=B3. =D0=B2 3:20, n.pettik <korablev@tarantool.org>:
When answering on revi= ew, include only chunks related to your answers.
Otherwise, letter becomes really long..


I'm sorry.
=C2=A0
<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex"> >
> > @@ -1725,9 +1727,9 @@ xferOptimization(Parse * pParse,=C2=A0 =C2= =A0 =C2=A0 =C2=A0 /* Parser context */
> >=C2=A0 =C2=A0 =C2=A0 =C2=A0int emptyDestTest =3D 0;=C2=A0 /* Addre= ss of test for empty pDest */
> >=C2=A0 =C2=A0 =C2=A0 =C2=A0int emptySrcTest =3D 0;=C2=A0 =C2=A0/* = Address of test for empty pSrc */
> >=C2=A0 =C2=A0 =C2=A0 =C2=A0Vdbe *v;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 /* The VDBE we are building */
> > -=C2=A0 =C2=A0 =C2=A0int destHasUniqueIdx =3D 0;=C2=A0 =C2=A0 =C2= =A0 =C2=A0/* True if pDest has a UNIQUE index */
> >=C2=A0 =C2=A0 =C2=A0 =C2=A0int regData, regTupleid;=C2=A0 =C2=A0 = =C2=A0 =C2=A0 /* Registers holding data and tupleid */
> >=C2=A0 =C2=A0 =C2=A0 =C2=A0struct session *user_session =3D curren= t_session();
> > +=C2=A0 =C2=A0 =C2=A0bool is_err_action_default =3D false;
>
> Again: why do you need this flag? Default action is just synonym for A= BORT,
> so why should we care about it?
>
>
> It's all about conflict action priorities as I said before.
> Consider the following example:
> ```
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0CREATE TABLE t1(= a INTEGER PRIMARY KEY ON CONFLICT REPLACE, b);
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0CREATE TABLE t2(= a INTEGER PRIMARY KEY ON CONFLICT REPLACE, b);
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0INSERT INTO t1 V= ALUES (1, 1), (3, 3), (5, 5);
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0INSERT INTO t2 V= ALUES (2, 2), (3, 4);
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0BEGIN;
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0INSERT INTO t2 VALUES (4, 4);
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0INSERT INTO t2 SELECT * FROM t1;
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0INSERT INTO t2 VALUES (10, 10);
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0COMMIT;

onError is an action of whole statement, not of index.
In your example onError =3D=3D ABORT =3D=3D DEFAULT.
Replace action of index is not involved in code you wrote.
=

As we discussed, was *_ABORT explicitly set or not make= s sense
till we have conflict actions on indices.=C2=A0
=C2=A0

>+=C2=A0 =C2=A0 =C2=A0 uint32_t src_space_id =3D SQLITE_PAGENO_TO_SPACEI= D(pSrc->tnum);
>+=C2=A0 =C2=A0 =C2=A0 struct space *src_space =3D space_by_id(src_space= _id);
>+=C2=A0 =C2=A0 =C2=A0 uint32_t dest_space_id =3D SQLITE_PAGENO_TO_SPACE= ID(pDest->tnum);
>+=C2=A0 =C2=A0 =C2=A0 struct space *dest_space =3D space_by_id(dest_spa= ce_id);

Move here also assert:

assert(src_space !=3D NULL && dest_space !=3D NULL);


Done.
=C2=A0
> > diff --git a/test/sql-tap/gh-3307-xfer-optimization-issue.test.lu= a b/test/sql-tap/gh-3307-xfer-optimization-issue.test.lua
> > new file mode 100755
> > index 0000000..e75fabc
> > --- /dev/null
> > +test:do_catchsql_test(
> > +=C2=A0 =C2=A0 =C2=A0"xfer-optimization-1.15",
> > +=C2=A0 =C2=A0 =C2=A0[[
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0DROP TABLE t1; > > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0DROP TABLE t2; > > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0CREATE TABLE t1(= a INTEGER PRIMARY KEY, b UNIQUE);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0CREATE TABLE t2(= a INTEGER PRIMARY KEY, b UNIQUE);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0INSERT INTO t1 V= ALUES (2, 2), (3, 3), (5, 5);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0INSERT INTO t2 V= ALUES (1, 1), (4, 4);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0INSERT OR ROLLBA= CK INTO t2 SELECT * FROM t1;
>
> INSERT OT ROLLBACK outside transaction works the same as ABORT and DEF= AULT.
> So, surround it with transaction and check that it really rollbacks. >
> There are basically almost the same tests surrounded by transactions (= 1.30 - 1.35).

If so, remove redundant tests pls.


Removed them. Also added tests that ch= eck if xfer
was actually used in first bunch of tests.
= =C2=A0
> -/* Opcode: RowData P1 P2 * * *
> +/* Opcode: RowData P1 P2 * * P5
>=C2=A0 =C2=A0* Synopsis: r[P2]=3Ddata
>=C2=A0 =C2=A0*
>=C2=A0 =C2=A0* Write into register P2 the complete row content for the = row at
> @@ -3984,6 +3994,8 @@ case OP_SorterData: {
>=C2=A0 =C2=A0* There is no interpretation of the data.
>=C2=A0 =C2=A0* It is just copied onto the P2 register exactly as
>=C2=A0 =C2=A0* it is found in the database file.
> + * P5 can be used in debug mode to check if xferOptimization has
> + * actually started processing.
>=C2=A0 =C2=A0*
>=C2=A0 =C2=A0* If cursor P1 is an index, then the content is the key of= the row.
>=C2=A0 =C2=A0* If cursor P2 is a table, then the content extracted is t= he data.
> @@ -3996,6 +4008,13 @@ case OP_RowData: {
>=C2=A0 =C2=A0 =C2=A0 =C2=A0BtCursor *pCrsr;
>=C2=A0 =C2=A0 =C2=A0 =C2=A0u32 n;
>=C2=A0
> +#ifdef SQLITE_TEST
> +=C2=A0 =C2=A0 =C2=A0if (pOp->p5 =3D=3D 1) {

Use named value (i.e. OPFLAG_XFER_OPT) even if they are the same.


Thank you, forgot about this place whe= n defined it.
=C2=A0
> +
> +test:do_execsql_test(
> +=C2=A0 =C2=A0 =C2=A0"xfer-optimization-1.37",
> +=C2=A0 =C2=A0 =C2=A0[[
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0INSERT INTO t2 VALUES (10, 10);

Here (and in some other places) smth wrong with indentation, fix it pls.

Indentation shows if stmt is in transa= ction, probably it looks a little weird,
but I'm more incline= d to leave it there.

Diff that compares patch to p= rev. one:

diff --git a/src/box/sql/insert.c b/src/box/sql/inser= t.c
index c2df1c2..3c3bf37 100644
--- a/src/box/sql/ins= ert.c
+++ b/src/box/sql/insert.c
@@ -1733,12 +1733,8 @@= xferOptimization(Parse * pParse, /*= Parser context */
=C2=A0 = if (space_trigger_list(pDest->def->id) !=3D NULL)
=C2=A0 return 0;
=C2=A0 if (onError =3D=3D ON_CONFLICT_ACTION_DEFAULT)= {
- if (pDest->iPKey = >=3D 0)
- onError =3D= pDest->keyConf;
- if = (onError =3D=3D ON_CONFLICT_ACTION_DEFAULT) {
- onError =3D ON_CONFLICT_ACTION_ABORT;
- is_err_action_default =3D true;
- }
+ onError =3D ON_CONFLICT_ACTION_ABORT;
+ is_err_action_default =3D true= ;
=C2=A0 }
=C2= =A0 assert(pSelect->pSrc); /* allocated even if there is no FROM clau= se */
=C2=A0 if (pSelect-&= gt;pSrc->nSrc !=3D 1) {
@@ -1804,6 +1800,7 @@ xferOptimization= (Parse * pParse, /* Parser context *= /
=C2=A0 struct space *src= _space =3D space_by_id(src_space_id);
=C2=A0 uint32_t dest_space_id =3D SQLITE_PAGENO_TO_SPACEID(pDes= t->tnum);
=C2=A0 struct= space *dest_space =3D space_by_id(dest_space_id);
+ assert(src_space !=3D NULL && dest_spa= ce !=3D NULL);
=C2=A0 for = (i =3D 0; i < (int)pDest->def->field_count; i++) {
=C2= =A0 enum affinity_type dest_affinit= y =3D
=C2=A0 pDest->d= ef->fields[i].affinity;
@@ -1823,7 +1820,6 @@ xferOptimization= (Parse * pParse, /* Parser context *= /
=C2=A0 }
=C2= =A0 /* Default values for second an= d subsequent columns need to match. */
=C2=A0 if (i > 0) {
- assert(src_space !=3D NULL && dest_space !=3D NULL);=
=C2=A0 char *src_expr_s= tr =3D
=C2=A0 src_space= ->def->fields[i].default_value;
=C2=A0 char *dest_expr_str =3D
@@ -1885,12 +1881,11= @@ xferOptimization(Parse * pParse, /* Parser context */
=C2=A0
=C2=A0 /*
=C2=A0 * Xfer optimization is unable to correctly insert data
- * in case there's a conflict actio= n other than *_ABORT.
- *= This is the reason we want to only run it if the
- * destination table is initially empty.
+ * in case there's a conflic= t action other than
+ * e= xplicit *_ABORT. This is the reason we want to only
+ * run it if the destination table is initiall= y empty.
=C2=A0 * That bl= ock generates code to make that determination.
=C2=A0 */
-
=C2=A0 if (!(onError =3D=3D ON_CONFLICT_ACTION_ABORT &am= p;&
=C2=A0 =C2=A0 =C2= =A0 is_err_action_default =3D=3D false)) {
=C2=A0 addr1 =3D sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0= );
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 5f9bc13..bc169d9 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -4009,7 +4009,7 @@ case OP_RowData: = {
=C2=A0 u32 n;
= =C2=A0
=C2=A0#ifdef SQLITE_TEST
- if (pOp->p5 =3D=3D 1) {
+ if (pOp->p5 =3D=3D OPFLAG_XFER_OPT) {
=C2= =A0 pOp->p5 =3D 0;
=C2= =A0 sql_xfer_count++;
=C2= =A0 }
diff --git a/test/sq= l-tap/gh-3307-xfer-optimization-issue.test.lua b/test/sql-tap/gh-3307-xfer-= optimization-issue.test.lua
index 34f603f..29f0efe 100755
--- a/test/sql-tap/gh-3307-xfer-optimization-issue.test.lua
++= + b/test/sql-tap/gh-3307-xfer-optimization-issue.test.lua
@@ -1,9= +1,29 @@
=C2=A0#!/usr/bin/env tarantool
=C2=A0test =3D= require("sqltester")
-test:plan(44)
+test:pl= an(46)
=C2=A0
=C2=A0local bfr, aftr
=C2=A0
+local function do_xfer_test(test_number, return_code)
+<= span style=3D"white-space:pre"> test_name =3D string.format("xf= er-optimization-1.%d", test_number)
+ test:do_test(
+ = test_name,
+ func= tion()
+ if (aftr - bfr = =3D=3D 1) then
+ return= {1}
+ end
+ if (aftr =3D=3D bfr) then
+ return {0}
+ end
+ end, {
+ = -- <test_name>
+ r= eturn_code
+ -- <test= _name>
+ })
= +end
+
+bfr =3D box.sql.debug().sql_xfer_count
+
=C2=A0test:do_catchsql_test(
=C2=A0 "xfer-optimization-1.1",
=C2=A0= [[
@@ -17,6 +37,8 @@ test= :do_catchsql_test(
=C2=A0 -- <xfer-optimization-1.1>
=C2=A0 })
=C2=A0
+aftr =3D box.sql.debug().sql_= xfer_count
+
=C2=A0test:do_execsql_test(
=C2= =A0 "xfer-optimization-1.2"= ;,
=C2=A0 [[
@@ = -27,8 +49,12 @@ test:do_execsql_test(
=C2=A0 -- <xfer-optimization-1.2>
=C2=A0 })
=C2=A0
+do_xfer_te= st(3, 1)
+
+bfr =3D box.sql.debug().sql_xfer_count
+
=C2=A0test:do_catchsql_test(
- "xfer-optimization-1.3",
+ "xfer-optimization-1.4",
<= div>=C2=A0 [[
=C2=A0 DROP TABLE t1;
=C2=A0 DROP TABLE t2;
@@ -39,23 +65,29 @= @ test:do_catchsql_test(
=C2=A0 = INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3);
=C2=A0 INSERT INTO t2 SELECT * FROM t1;
=C2=A0 ]], {
- -- <xfer-optimization-1.3>
= + -- <xfer-optimization-1.4><= /div>
=C2=A0 0
- -- <xfer-optimization-1.3>
<= div>+ -- <xfer-optimization-1.4&= gt;
=C2=A0 })
= =C2=A0
+aftr =3D box.sql.debug().sql_xfer_count
+
=
=C2=A0test:do_execsql_test(
- "xfer-optimization-1.4",
+ "xfer-optimization-1.5",
=C2=A0 [[
=C2=A0 SELECT * FROM t2;
=C2=A0 ]], {
- -- <xfer-optimization-1.4>
+ -- <xfer-optimization-1.5>
=C2=A0 1, 1, 2, 2, 3, 3
- -- <xfer-optimization-1.4>
+ -- <xfer-optimization-1.5>
=C2=A0 })
=C2=A0
+do_xfer_test(6, 1)
+
+bfr =3D box.sql.debug().sql_x= fer_count
+
=C2=A0test:do_catchsql_test(
- "xfer-optimization-1.5",
+ "xfer-optimization-1.7= ",
=C2=A0 [[
=C2=A0 DROP TABLE t1;
= =C2=A0 DROP TABLE t2;
@@ = -64,23 +96,29 @@ test:do_catchsql_test(
=C2=A0 CREATE TABLE t2(a INTEGER PRIMARY KEY, b INTEGER);
=C2=A0 INSERT INTO t2 SELEC= T * FROM t1;
=C2=A0 ]], {<= /div>
- -- <xfer-optimizatio= n-1.5>
+ -- <xfer-o= ptimization-1.7>
=C2=A0 1, "table T2 has 2 columns but 3 values were supplied"
- -- <xfer-optimization-1.5>= ;
+ -- <xfer-optimizat= ion-1.7>
=C2=A0 })
=C2=A0
+aftr =3D box.sql.debug().sql_xfer_count
+=
=C2=A0test:do_execsql_test(
- "xfer-optimization-1.6",
+ "xfer-optimization-1.8",
=C2= =A0 [[
=C2=A0 SELECT * FROM t2;
=C2=A0 ]], {
- -- <xfer-optimization-1.6>
+ -- <xfer-optimization-1.8>
=C2=A0
- -- <xfer-optimization-1= .6>
+ -- <xfer-opti= mization-1.8>
=C2=A0 })=
=C2=A0
+do_xfer_test(9, 0)
+
+bfr = =3D box.sql.debug().sql_xfer_count
+
=C2=A0test:do_catc= hsql_test(
- "xfer-op= timization-1.7",
+ &q= uot;xfer-optimization-1.10",
=C2=A0 [[
=C2=A0 = DROP TABLE t1;
=C2=A0 DRO= P TABLE t2;
@@ -89,23 +127,29 @@ test:do_catchsql_test(
=C2=A0 CREATE TABLE t2(a INTEGER P= RIMARY KEY, b INTEGER);
=C2=A0 <= /span>INSERT INTO t2 SELECT * FROM t1;
=C2=A0 ]], {
- -- <xfer-optimization-1.7>
+ -- <xfer-optimization-1.10>
=C2=A0 0
-= -- <xfer-optimization-1.7>
+ -- <xfer-optimization-1.10>
=C2=A0 })
=C2=A0
+aftr =3D b= ox.sql.debug().sql_xfer_count
+
=C2=A0test:do_execsql_t= est(
- "xfer-optimiza= tion-1.8",
+ "xf= er-optimization-1.11",
=C2=A0 [[
=C2=A0 SELECT= * FROM t2;
=C2=A0 ]], {
- -- <xfer-optimization= -1.6>
+ -- <xfer-op= timization-1.11>
=C2=A0 1, 1, 2, 2, 3, 3
- -- &= lt;xfer-optimization-1.6>
+ <= /span>-- <xfer-optimization-1.11>
=C2=A0 })
=C2=A0
+do_xfer_test(12, 1);
+
+bfr =3D box.sql.debug().sql_xfer_count
+
=C2=A0test:do_catchsql_test(
- "xfer-optimization-1.9",
+ "xfer-optimization-1.13",
=C2=A0= [[
=C2=A0 DROP TABLE t1;
=C2=A0 DROP TABLE t2;
@@ -114,23 +158,29 @@ test:d= o_catchsql_test(
=C2=A0 C= REATE TABLE t2(b INTEGER, a INTEGER PRIMARY KEY);
=C2=A0 INSERT INTO t2 SELECT * FROM t1;
= =C2=A0 ]], {
- -- <xfer-optimization-1.9>
+<= span style=3D"white-space:pre"> -- <xfer-optimization-1.13>
=C2=A0 1, "Duplicate = key exists in unique index 'sqlite_autoindex_T2_1' in space 'T2= '"
- -- <xfer= -optimization-1.9>
+ -= - <xfer-optimization-1.13>
=C2=A0 })
=C2=A0
+aftr =3D box.sql.debug().sql_x= fer_count
+
=C2=A0test:do_execsql_test(
- "xfer-optimization-1.10",
+ "xfer-optimization-1.1= 4",
=C2=A0 [[
=C2=A0 SELECT * FROM t2;
=C2=A0 ]], {
- -- <xfer-optimization-1.10>
+ -- <xfer-optimization-1.14>= ;
=C2=A0
- -- &= lt;xfer-optimization-1.10>
+ = -- <xfer-optimization-1.14>
=C2=A0 })
=C2=A0
+do_xfer_test(15, 0)
+
+bfr =3D box.sql.debug().sql_xfer_count
+
=C2=A0test:do_catchsql_test(
- "xfer-optimization-1.11",
+ "xfer-optimization-1.16",
=C2= =A0 [[
=C2=A0 DROP TABLE t1;
=C2=A0 DROP TABLE t2;
@@ -139,72 +189,24 @@ t= est:do_catchsql_test(
=C2=A0 CREATE TABLE t2(b INTEGER PRIMARY KEY, a INTEGER);
=C2=A0 INSERT INTO t2 SELECT * FROM t1;
=
=C2=A0 ]], {
- -- <xfer-optimization-1.11>
+ -- <xfer-optimization-1.16&= gt;
=C2=A0 0
-<= span style=3D"white-space:pre"> -- <xfer-optimization-1.11>
- })
-
= -test:do_execsql_test(
- &= quot;xfer-optimization-1.12",
- [[
- SELECT * = FROM t2;
- ]], {
- -- <xfer-optimization-1.12>= ;
- 1, 1, 2, 2, 3, 2
- -- <xfer-optimization-1.= 12>
+ -- <xfer-opti= mization-1.16>
=C2=A0 }= )
=C2=A0
-test:do_catchsql_test(
- "xfer-optimization-1.13",
= - [[
- DROP TABLE t1;
- DROP TABLE t2;
- CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
- CREATE TABLE t2(a INTEGER PRIMARY KEY, b);
- INSERT INTO t1 VALUES (3, 3), = (4, 4), (5, 5);
- INSERT = INTO t2 VALUES (1, 1), (2, 2);
- = INSERT INTO t2 SELECT * FROM t1;
- ]], {
- = -- <xfer-optimization-1.13>
- 0
- -- <xfe= r-optimization-1.13>
- = })
+aftr =3D box.sql.debug().sql_xfer_count
=C2=A0
=C2=A0test:do_execsql_test(
- "xfer-optimization-1.14",
+ "xfer-optimization-1.17",
=C2=A0<= span style=3D"white-space:pre"> [[
=C2=A0 SELECT * FROM t2;
=C2=A0 ]], {
- <= /span>-- <xfer-optimization-1.14>
- 1, 1, 2, 2, 3, 3, 4, 4, 5, 5
- -- <xfer-optimization-1.14>
+ -- <xfer-optimization-1.17>
+ 1, 1, 2, 2, 3, 2
+ -- <xfer-optimization-1.17>
=C2=A0 })
=C2=A0
-test:do_catchsql_test(
- "xfer-optimization-1.15",
- [[
- DROP TABLE t1;
- DROP TA= BLE t2;
- CREATE TABLE t1= (a INTEGER PRIMARY KEY, b UNIQUE);
- CREATE TABLE t2(a INTEGER PRIMARY KEY, b UNIQUE);
- INSERT INTO t1 VALUES (2, 2), (3, 3)= , (5, 5);
- INSERT INTO t= 2 VALUES (1, 1), (4, 4);
- INSERT OR ROLLBACK INTO t2 SELECT * FROM t1;
- ]], {
- <= /span>-- <xfer-optimization-1.15>
- 0
- -- &= lt;xfer-optimization-1.15>
- <= /span>})
-
-test:do_execsql_test(
- "xfer-optimization-1.16",
- [[
- SELECT * FROM t2;
- ]], {
- -= - <xfer-optimization-1.16>
- 1, 1, 2, 2, 3, 3, 4, 4, 5, 5
- -- <xfer-optimization-1.16>
- })
+do_xfer_test(18, 1)
=C2= =A0
=C2=A0-- The following tests are supposed to test if xfer-opt= imization is actually
=C2=A0-- used in the given cases (if the co= nflict actually occurs):
@@ -220,23 +222,6 @@ test:do_execsql_tes= t(
=C2=A0-- 5) insert wit= h fail
=C2=A0-- 6) insert= with ignore
=C2=A0
-local function do_xfer_test(test_n= umber, return_code)
- test= _name =3D string.format("xfer-optimization-1.%d", test_number)
- test:do_test(
-<= span style=3D"white-space:pre"> test_name,
- function()
- if (aftr - bfr =3D=3D 1) then
- return {1}
- end
- i= f (aftr =3D=3D bfr) then
- return {0}
- end
- end, {
- -- <test_name>
- return_code
- -- <test_name>
- })
-end
=C2=A0
=C2=A0-- = 1.0) insert w/o explicit confl. action & w/o index replace action
=
=C2=A0----------------------------------------------------------------= --------------
@@ -244,7 +229,7 @@ end
=C2=A0bfr =3D bo= x.sql.debug().sql_xfer_count
=C2=A0
=C2=A0test:do_catch= sql_test(
- "xfer-opt= imization-1.17",
+ &q= uot;xfer-optimization-1.19",
=C2=A0 [[
=C2=A0 = DROP TABLE t1;
=C2=A0 DRO= P TABLE t2;
@@ -256,26 +241,26 @@ test:do_catchsql_test(
=C2=A0 INSERT INTO t2 VALUES (4,= 4);
=C2=A0 INSERT INTO = t2 SELECT * FROM t1;
=C2=A0 ]], {
- -- <xfer-opt= imization-1.17>
+ -- &= lt;xfer-optimization-1.19>
=C2=A0 1, "Duplicate key exists in unique index 'sqlite_autoi= ndex_T2_1' in space 'T2'"
- -- <xfer-optimization-1.17>
+ -- <xfer-optimization-1.19>
= =C2=A0 })
=C2=A0
=C2=A0test:do_execsql_test(
- "xfer-optimization-1.18",
+ "xfer-optimization-1.20",
=C2=A0 [[
=C2=A0 INSERT INTO t2 VALUES (10, 10);
=C2=A0 COMMIT;
=C2=A0 SELECT * FROM t2;
=C2=A0 ]], {
- <= /span>-- <xfer-optimization-1.18>
+ -- <xfer-optimization-1.20>
=C2=A0 2, 2, 3, 4, 4, 4, 10, 10
- -- <xfer-optimization-1.18>
<= div>+ -- <xfer-optimization-1.20= >
=C2=A0 })
= =C2=A0
=C2=A0aftr =3D box.sql.debug().sql_xfer_count
= =C2=A0
-do_xfer_test(19, 0)
+do_xfer_test(21, 0)
<= div>=C2=A0
=C2=A0-- 1.1) insert w/o explicit confl. action & = w/
=C2=A0--=C2=A0 =C2=A0 =C2=A0 index replace action & empty = dest_table
@@ -284,7 +269,7 @@ do_xfer_test(19, 0)
=C2= =A0bfr =3D box.sql.debug().sql_xfer_count
=C2=A0
=C2=A0= test:do_catchsql_test(
- &= quot;xfer-optimization-1.20",
+ "xfer-optimization-1.22",
=C2=A0 [[
=C2=A0 DROP TABLE t1;
=C2=A0 DROP TABLE t2;
@@ -296,36 +281,36 @@ test:do_catchsql_= test(
=C2=A0 INSERT INTO= t3 VALUES (1);
=C2=A0 I= NSERT INTO t2 SELECT * FROM t1;
=C2=A0 ]], {
- -- &= lt;xfer-optimization-1.20>
+ = -- <xfer-optimization-1.22>
=C2=A0 0
- -- <xfer-optimization-1.20>
+ -- <xfer-optimization-1.22>
=C2=A0 })
=C2=A0
=C2=A0test:do_ex= ecsql_test(
- "xfer-o= ptimization-1.21",
+ = "xfer-optimization-1.23",
=C2=A0 [[
=C2=A0 INSERT INTO t2 VALUES (10, 10);
=C2=A0 COMMIT;
=C2=A0 = SELECT * FROM t2;
=C2=A0 <= /span>]], {
- -- <xfer= -optimization-1.21>
+ = -- <xfer-optimization-1.23>
=C2=A0 1, 1, 3, 3, 5, 5, 10, 10
- -- <xfer-optimization-1.21>
+ -- <xfer-optimization-1.23>
= =C2=A0 })
=C2=A0
=C2=A0aftr =3D box.sql.debug().sql_xfer_count
=C2=A0
= =C2=A0test:do_execsql_test(
- "xfer-optimization-1.22",
+ "xfer-optimization-1.24",
=C2=A0 [[
=C2=A0 SELECT * FROM t3;
=C2=A0 ]], {
- = -- <xfer-optimization-1.22>
+ -- <xfer-optimization-1.24>
=C2=A0 1
- <= /span>-- <xfer-optimization-1.22>
+ -- <xfer-optimization-1.24>
=C2=A0 })
=C2=A0
-do_xfer_test= (23, 1)
+do_xfer_test(25, 1)
=C2=A0
=C2=A0-- = 1.2) insert w/o explicit confl. action & w/
=C2=A0-- index re= place action & non-empty dest_table
@@ -334,7 +319,7 @@ do_xf= er_test(23, 1)
=C2=A0bfr =3D box.sql.debug().sql_xfer_count
=
=C2=A0
=C2=A0test:do_catchsql_test(
- "xfer-optimization-1.24",
= + "xfer-optimization-1.26"= ,
=C2=A0 [[
=C2= =A0 DROP TABLE t1;
=C2=A0= DROP TABLE t2;
@@ -347,2= 6 +332,26 @@ test:do_catchsql_test(
=C2=A0 INSERT INTO t2 VALUES (4, 4);
=C2=A0 INSERT INTO t2 SELECT * FROM t1;
= =C2=A0 ]], {
- -- <xfer-optimization-1.24>
+= -- <xfer-optimization-1.26><= /div>
=C2=A0 0
- -- <xfer-optimization-1.24>
=
+ -- <xfer-optimization-1.2= 6>
=C2=A0 })
= =C2=A0
=C2=A0test:do_execsql_test(
- "xfer-optimization-1.25",
+ "xfer-optimization-1.27",
<= div>=C2=A0 [[
=C2=A0 INSERT INTO t2 VALUES (10, 10);
=C2=A0 COMMIT;
=C2=A0<= span style=3D"white-space:pre"> SELECT * FROM t2;
=C2=A0<= span style=3D"white-space:pre"> ]], {
- -- <xfer-optimization-1.25>
+ -- <xfer-optimization-1.27>
=C2=A0 1, 1, 2, 2, 3, 3, 4, 4, 5,= 5, 10, 10
- -- <xfer-= optimization-1.25>
+ -= - <xfer-optimization-1.27>
=C2=A0 })
=C2=A0
=C2=A0aftr =3D box.sql.debug().= sql_xfer_count
=C2=A0
-do_xfer_test(26, 0)
+d= o_xfer_test(28, 0)
=C2=A0
=C2=A0-- 2) insert with abort=
=C2=A0----------------------------------------------------------= --------------------
@@ -374,7 +359,7 @@ do_xfer_test(26, 0)
=C2=A0bfr =3D box.sql.debug().sql_xfer_count
=C2=A0
=C2=A0test:do_catchsql_test(
-= "xfer-optimization-1.27",
+ "xfer-optimization-1.29",
=C2=A0 [[
=C2=A0 DROP TABLE t1;
=C2=A0 DROP TABLE t2;
@@ -386,26 +371,26 @@ test:do_c= atchsql_test(
=C2=A0 INS= ERT INTO t2 VALUES (4, 4);
=C2=A0= INSERT OR ABORT INTO t2 SELECT * FROM t1;
=C2=A0 ]], {
- -- <xfer-optimization-1.27>
+ -- <xfer-optimization-1.29>
=C2= =A0 1, "Duplicate key exists i= n unique index 'sqlite_autoindex_T2_1' in space 'T2'"<= /div>
- -- <xfer-optimizatio= n-1.27>
+ -- <xfer-= optimization-1.29>
=C2=A0 })
=C2=A0
=C2=A0test:do_execsql_test(
- "xfer-optimization-1.28",
+ "xfer-optimization-1.= 30",
=C2=A0 [[
<= div>=C2=A0 INSERT INTO t2 VALUES (= 10, 10);
=C2=A0 COMMIT;
=C2=A0 SELECT * FROM t2;
=C2=A0 ]], {
- -- <xfer-optimization-1.28>
+ -- <xfer-optimization-1= .30>
=C2=A0 2, 2, 3, 4= , 4, 4, 10, 10
- -- <x= fer-optimization-1.28>
+ -- <xfer-optimization-1.30>
=C2=A0 })
=C2=A0
=C2=A0aftr =3D box.sql.debu= g().sql_xfer_count
=C2=A0
-do_xfer_test(29, 1)
+do_xfer_test(31, 1)
=C2=A0
=C2=A0-- 3.0) insert with= rollback (into empty table)
=C2=A0------------------------------= ------------------------------------------------
@@ -413,7 +398,7= @@ do_xfer_test(29, 1)
=C2=A0bfr =3D box.sql.debug().sql_xfer_co= unt
=C2=A0
=C2=A0test:do_catchsql_test(
- "xfer-optimization-1.30",
+ "xfer-optimization-1.3= 2",
=C2=A0 [[
=C2=A0 DROP TABLE t1;
= =C2=A0 DROP TABLE t2;
@@ = -423,26 +408,26 @@ test:do_catchsql_test(
=C2=A0 BEGIN;
=C2=A0 INSERT OR ROLLBACK INTO t2 SELECT * FROM t1;
=C2=A0= ]], {
- -- <xfer-optimization-1.30>
+ -- <xfer-optimization-1.32>
=C2=A0 0
- -- <xfer-optimization-1.30>
+= -- <xfer-optimization-1.32><= /div>
=C2=A0 })
=C2=A0=
=C2=A0test:do_execsql_test(
- "xfer-optimization-1.31",
+ "xfer-optimization-1.33",
= =C2=A0 [[
=C2=A0 INSERT INTO t2 VALUES (10, 10);
= =C2=A0 COMMIT;
=C2=A0 SELECT * FROM t2;
=C2=A0 ]], {
- -- <xfer-optimization-1.31>
+ -- <xfer-optimization-1.33>
= =C2=A0 1, 1, 3, 3, 5, 5, 10, 10
- -- <xfer-optimization-1= .31>
+ -- <xfer-opt= imization-1.33>
=C2=A0 = })
=C2=A0
=C2=A0aftr =3D box.sql.debug().sql_xfer_count=
=C2=A0
-do_xfer_test(32, 1)
+do_xfer_test(34= , 1)
=C2=A0
=C2=A0-- 3.1) insert with rollback (into no= n-empty table)
=C2=A0--------------------------------------------= ----------------------------------
@@ -450,7 +435,7 @@ do_xfer_te= st(32, 1)
=C2=A0bfr =3D box.sql.debug().sql_xfer_count
= =C2=A0
=C2=A0test:do_catchsql_test(
- "xfer-optimization-1.33",
+ "xfer-optimization-1.35",
=
=C2=A0 [[
=C2=A0 DROP TABLE t1;
=C2=A0 DROP TABLE t2;
@@ -462,24 +447,2= 4 @@ test:do_catchsql_test(
=C2=A0 INSERT INTO t2 VALUES (4, 4);
=C2=A0 INSERT OR ROLLBACK INTO t2 SELECT * FROM t1;
<= div>=C2=A0 ]], {
- -- <xfer-optimization-1.33>
+ -- <xfer-optimization-1.35&g= t;
=C2=A0 1, "UNIQUE= constraint failed: T2.A"
- = -- <xfer-optimization-1.33>
+ -- <xfer-optimization-1.35>
=C2=A0 })
=C2=A0
=C2=A0test:= do_execsql_test(
- "x= fer-optimization-1.34",
+ "xfer-optimization-1.36",
=C2=A0 [[
=C2=A0 = SELECT * FROM t2;
=C2=A0 <= /span>]], {
- -- <xfer= -optimization-1.34>
+ = -- <xfer-optimization-1.36>
=C2=A0 2, 2, 3, 4
- -- <xfer-optimization-1.34>
+ -- <xfer-optimization-1.36>
=C2=A0 })
=C2=A0
=C2=A0aftr =3D = box.sql.debug().sql_xfer_count
=C2=A0
-do_xfer_test(35,= 0)
+do_xfer_test(37, 0)
=C2=A0
=C2=A0-- 4) i= nsert with replace
=C2=A0----------------------------------------= --------------------------------------
@@ -487,7 +472,7 @@ do_xfe= r_test(35, 0)
=C2=A0bfr =3D box.sql.debug().sql_xfer_count
<= div>=C2=A0
=C2=A0test:do_catchsql_test(
- "xfer-optimization-1.36",
+ "xfer-optimization-1.38",
=C2=A0 [[
=C2=A0<= span style=3D"white-space:pre"> DROP TABLE t1;
=C2=A0 DROP TABLE t2;
@@ -499,26 +4= 84,26 @@ test:do_catchsql_test(
=C2=A0 INSERT INTO t2 VALUES (4, 4);
=C2=A0 INSERT OR REPLACE INTO t2 SELECT * FROM t1;
=C2=A0 ]], {
- -- <xfer-optimization-1.36>
=
+ -- <xfer-optimization-1.3= 8>
=C2=A0 0
= - -- <xfer-optimization-1.36>=
+ -- <xfer-optimizati= on-1.38>
=C2=A0 })
=C2=A0
=C2=A0test:do_execsql_test(
- "xfer-optimization-1.37",
= + "xfer-optimization-1.39"= ,
=C2=A0 [[
=C2= =A0 INSERT INTO t2 VALUES (10, 10)= ;
=C2=A0 COMMIT;
=C2=A0 SELECT * FROM t2;
=C2=A0 ]], {
- -- <xfer-optimization-1.37>
= + -- <xfer-optimization-1.39>=
=C2=A0 1, 1, 2, 2, 3, 3,= 4, 4, 5, 5, 10, 10
- -- = <xfer-optimization-1.37>
+ = -- <xfer-optimization-1.39>
=C2=A0 })
=C2=A0
=C2=A0aftr =3D box.sql= .debug().sql_xfer_count
=C2=A0
-do_xfer_test(38, 0)
+do_xfer_test(40, 0)
=C2=A0
=C2=A0-- 5) insert w= ith fail
=C2=A0--------------------------------------------------= ----------------------------
@@ -526,7 +511,7 @@ do_xfer_test(38,= 0)
=C2=A0bfr =3D box.sql.debug().sql_xfer_count
=C2=A0=
=C2=A0test:do_catchsql_test(
- "xfer-optimization-1.39",
+ "xfer-optimization-1.41",
= =C2=A0 [[
=C2=A0 DROP TABLE t1;
=C2=A0 DROP TABLE t2;
@@ -538,26 +523,26 @= @ test:do_catchsql_test(
=C2=A0 = INSERT INTO t2 VALUES (4, 4);
=C2=A0 INSERT OR FAIL INTO t2 SELECT * FROM t1;
=C2= =A0 ]], {
- -- <xfer-optimization-1.39>
+ -- <xfer-optimization-1.41>
=C2=A0 1, "Duplicate key= exists in unique index 'sqlite_autoindex_T2_1' in space 'T2= 9;"
- -- <xfer-op= timization-1.39>
+ -- = <xfer-optimization-1.41>
=C2=A0 })
=C2=A0
=C2=A0test:do_execsql_test(
=
- "xfer-optimization-1.40&= quot;,
+ "xfer-optimi= zation-1.42",
=C2=A0 = [[
=C2=A0 INSERT INTO t2= VALUES (10, 10);
=C2=A0 = COMMIT;
=C2=A0 SELECT * F= ROM t2;
=C2=A0 ]], {
=
- -- <xfer-optimization-1.4= 0>
+ -- <xfer-optim= ization-1.42>
=C2=A0 1= , 1, 2, 2, 3, 4, 4, 4, 10, 10
- = -- <xfer-optimization-1.40>
+ -- <xfer-optimization-1.42>
=C2=A0 })
=C2=A0
=C2=A0aftr = =3D box.sql.debug().sql_xfer_count
=C2=A0
-do_xfer_test= (41, 0)
+do_xfer_test(43, 0)
=C2=A0
=C2=A0-- = 6) insert with ignore
=C2=A0-------------------------------------= -----------------------------------------
@@ -565,7 +550,7 @@ do_= xfer_test(41, 0)
=C2=A0bfr =3D box.sql.debug().sql_xfer_count
=C2=A0
=C2=A0test:do_catchsql_test(
- "xfer-optimization-1.42",
= + "xfer-optimization-1.44"= ,
=C2=A0 [[
=C2= =A0 DROP TABLE t1;
=C2=A0= DROP TABLE t2;
@@ -577,2= 5 +562,25 @@ test:do_catchsql_test(
=C2=A0 INSERT INTO t2 VALUES (4, 4);
=C2=A0 INSERT OR IGNORE INTO t2 SELECT * FROM t1;<= /div>
=C2=A0 ]], {
- -- <xfer-optimization-1.42>
+ -- <xfer-optimization-= 1.44>
=C2=A0 0
- -- <xfer-optimization-1.42&= gt;
+ -- <xfer-optimiz= ation-1.44>
=C2=A0 })
=C2=A0
=C2=A0test:do_execsql_test(
- "xfer-optimization-1.43",
+ "xfer-optimization-1.45"= ;,
=C2=A0 [[
=C2= =A0 INSERT INTO t2 VALUES (10, 10)= ;
=C2=A0 COMMIT;
=C2=A0 SELECT * FROM t2;
=C2=A0 ]], {
- -- <xfer-optimization-1.43>
= + -- <xfer-optimization-1.45>=
=C2=A0 1, 1, 2, 2, 3, 4,= 4, 4, 5, 5, 10, 10
- -- = <xfer-optimization-1.43>
+ = -- <xfer-optimization-1.45>
=C2=A0 })
=C2=A0
=C2=A0aftr =3D box.sql= .debug().sql_xfer_count
=C2=A0
-do_xfer_test(44, 0)
+do_xfer_test(46, 0)
=C2=A0
=C2=A0test:finish_te= st()

--000000000000e4e16f05715d7a7c--