[Tarantool-patches] [PATCH 1/5] sql: remove PRAGMA "count_changes"

imeevma at tarantool.org imeevma at tarantool.org
Wed Nov 27 13:13:28 MSK 2019


Pragma "count_changes" forces the INSERT, REPLACE, DELETE, and
UPDATE statements to return the number of changed rows as a
result set. This is not necessary, as these statements return the
number of changed rows as metadata.

Part of #4511
---
 src/box/sql/delete.c         |  26 -----------
 src/box/sql/insert.c         |  35 +--------------
 src/box/sql/pragma.h         | 104 ++++++++++++++++++++-----------------------
 src/box/sql/sqlInt.h         |   3 --
 src/box/sql/update.c         |  27 -----------
 src/box/sql/vdbe.c           |  29 +-----------
 test/sql-tap/update.test.lua |  49 ++++++++++----------
 test/sql/iproto.result       |  31 -------------
 test/sql/iproto.test.lua     |   8 ----
 test/sql/sql-debug.result    |   1 -
 10 files changed, 74 insertions(+), 239 deletions(-)

diff --git a/src/box/sql/delete.c b/src/box/sql/delete.c
index 91c2157..8d9ae4f 100644
--- a/src/box/sql/delete.c
+++ b/src/box/sql/delete.c
@@ -191,15 +191,6 @@ sql_table_delete_from(struct Parse *parse, struct SrcList *tab_list,
 				     tab_cursor);
 	}
 
-	/* Initialize the counter of the number of rows deleted,
-	 * if we are counting rows.
-	 */
-	int reg_count = -1;
-	uint32_t sql_flags = parse->sql_flags;
-	if ((sql_flags & SQL_CountRows) != 0) {
-		reg_count = ++parse->nMem;
-		sqlVdbeAddOp2(v, OP_Integer, 0, reg_count);
-	}
 	/* Special case: A DELETE without a WHERE clause deletes
 	 * everything. It is easier just to erase the whole table.
 	 */
@@ -284,12 +275,6 @@ sql_table_delete_from(struct Parse *parse, struct SrcList *tab_list,
 		 */
 		/* assert(is_complex || one_pass != ONEPASS_OFF); */
 
-		/* Keep track of the number of rows to be
-		 * deleted.
-		 */
-		if ((sql_flags & SQL_CountRows) != 0)
-			sqlVdbeAddOp2(v, OP_AddImm, reg_count, 1);
-
 		/* Extract the primary key for the current row */
 		if (!is_view) {
 			struct key_part_def *part = pk_info->parts;
@@ -413,17 +398,6 @@ sql_table_delete_from(struct Parse *parse, struct SrcList *tab_list,
 		}
 	}
 
-	/* Return the number of rows that were deleted. */
-	if ((sql_flags & SQL_CountRows) != 0 &&
-	    parse->triggered_space != NULL) {
-		sqlVdbeAddOp2(v, OP_ResultRow, reg_count, 1);
-		sqlVdbeSetNumCols(v, 1);
-		sqlVdbeSetColName(v, 0, COLNAME_NAME, "rows deleted",
-				      SQL_STATIC);
-		sqlVdbeSetColName(v, 0, COLNAME_DECLTYPE, "integer",
-				  SQL_STATIC);
-	}
-
  delete_from_cleanup:
 	sqlSrcListDelete(db, tab_list);
 	sql_expr_delete(db, where, false);
diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c
index 70504c8..43a0de5 100644
--- a/src/box/sql/insert.c
+++ b/src/box/sql/insert.c
@@ -251,7 +251,6 @@ sqlInsert(Parse * pParse,	/* Parser context */
 
 	/* Register allocations */
 	int regFromSelect = 0;	/* Base register for data coming from SELECT */
-	int regRowCount = 0;	/* Memory cell used for the row counter */
 	int regIns;		/* Block of regs holding data being inserted */
 	int regTupleid;		/* registers holding insert tupleid */
 	int regData;		/* register holding first column to insert */
@@ -334,7 +333,7 @@ sqlInsert(Parse * pParse,	/* Parser context */
 	    xferOptimization(pParse, space, pSelect, on_error)) {
 		assert(trigger == NULL);
 		assert(pList == 0);
-		goto insert_end;
+		goto insert_cleanup;
 	}
 
 	/*
@@ -512,12 +511,6 @@ sqlInsert(Parse * pParse,	/* Parser context */
 		goto insert_cleanup;
 	}
 
-	/* Initialize the count of rows to be inserted
-	 */
-	if ((pParse->sql_flags & SQL_CountRows) != 0) {
-		regRowCount = ++pParse->nMem;
-		sqlVdbeAddOp2(v, OP_Integer, 0, regRowCount);
-	}
 	/* This is the top of the main insertion loop */
 	if (useTempTable) {
 		/* This block codes the top of loop only.  The complete loop is the
@@ -745,12 +738,6 @@ sqlInsert(Parse * pParse,	/* Parser context */
 					       on_error, autoinc_reg);
 	}
 
-	/* Update the count of rows that are inserted
-	 */
-	if ((pParse->sql_flags & SQL_CountRows) != 0) {
-		sqlVdbeAddOp2(v, OP_AddImm, regRowCount, 1);
-	}
-
 	if (trigger != NULL) {
 		/* Code AFTER triggers */
 		vdbe_code_row_trigger(pParse, trigger, TK_INSERT, 0,
@@ -773,23 +760,6 @@ sqlInsert(Parse * pParse,	/* Parser context */
 		sqlVdbeJumpHere(v, addrInsTop);
 	}
 
- insert_end:
-
-	/* Return the number of rows inserted. */
-	if ((pParse->sql_flags & SQL_CountRows) != 0 &&
-	    pParse->triggered_space == NULL) {
-		sqlVdbeAddOp2(v, OP_ResultRow, regRowCount, 1);
-		sqlVdbeSetNumCols(v, 1);
-		const char *column_name;
-		if (on_error == ON_CONFLICT_ACTION_REPLACE)
-			column_name = "rows replaced";
-		else
-			column_name = "rows inserted";
-		sqlVdbeSetColName(v, 0, COLNAME_NAME, column_name, SQL_STATIC);
-		sqlVdbeSetColName(v, 0, COLNAME_DECLTYPE, "integer",
-				  SQL_STATIC);
-	}
-
  insert_cleanup:
 	sqlSrcListDelete(db, pTabList);
 	sql_expr_list_delete(db, pList);
@@ -1182,9 +1152,6 @@ xferOptimization(Parse * pParse,	/* Parser context */
 	 */
 	if (!rlist_empty(&dest->child_fk_constraint))
 		return 0;
-	if ((pParse->sql_flags & SQL_CountRows) != 0) {
-		return 0;	/* xfer opt does not play well with PRAGMA count_changes */
-	}
 
 	/* If we get this far, it means that the xfer optimization is at
 	 * least a possibility, though it might only work if the destination
diff --git a/src/box/sql/pragma.h b/src/box/sql/pragma.h
index 30a1fc4..511de23 100644
--- a/src/box/sql/pragma.h
+++ b/src/box/sql/pragma.h
@@ -93,57 +93,54 @@ static const char *const pragCName[] = {
 	/*  55 */ "text",
 	/*  56 */ "match",
 	/*  57 */ "text",
-	/* Used by: count_changes */
-	/*  58 */ "count_changes",
-	/*  59 */ "integer",
 	/* Used by: defer_foreign_keys */
-	/*  60 */ "defer_foreign_keys",
-	/*  61 */ "integer",
+	/*  58 */ "defer_foreign_keys",
+	/*  59 */ "integer",
 	/* Used by: full_column_names */
-	/*  62 */ "full_column_names",
-	/*  63 */ "integer",
+	/*  60 */ "full_column_names",
+	/*  61 */ "integer",
 	/* Used by: parser_trace */
-	/*  64 */ "parser_trace",
-	/*  65 */ "integer",
+	/*  62 */ "parser_trace",
+	/*  63 */ "integer",
 	/* Used by: recursive_triggers */
-	/*  66 */ "recursive_triggers",
-	/*  67 */ "integer",
+	/*  64 */ "recursive_triggers",
+	/*  65 */ "integer",
 	/* Used by: reverse_unordered_selects */
-	/*  68 */ "reverse_unordered_selects",
-	/*  69 */ "integer",
+	/*  66 */ "reverse_unordered_selects",
+	/*  67 */ "integer",
 	/* Used by: select_trace */
-	/*  70 */ "select_trace",
-	/*  71 */ "integer",
+	/*  68 */ "select_trace",
+	/*  69 */ "integer",
 	/* Used by: short_column_names */
-	/*  72 */ "short_column_names",
-	/*  73 */ "integer",
+	/*  70 */ "short_column_names",
+	/*  71 */ "integer",
 	/* Used by: sql_compound_select_limit */
-	/*  74 */ "sql_compound_select_limit",
-	/*  75 */ "integer",
+	/*  72 */ "sql_compound_select_limit",
+	/*  73 */ "integer",
 	/* Used by: sql_default_engine */
-	/*  76 */ "sql_default_engine",
-	/*  77 */ "text",
+	/*  74 */ "sql_default_engine",
+	/*  75 */ "text",
 	/* Used by: sql_trace */
-	/*  78 */ "sql_trace",
-	/*  79 */ "integer",
+	/*  76 */ "sql_trace",
+	/*  77 */ "integer",
 	/* Used by: vdbe_addoptrace */
-	/*  80 */ "vdbe_addoptrace",
-	/*  81 */ "integer",
+	/*  78 */ "vdbe_addoptrace",
+	/*  79 */ "integer",
 	/* Used by: vdbe_debug */
-	/*  82 */ "vdbe_debug",
-	/*  83 */ "integer",
+	/*  80 */ "vdbe_debug",
+	/*  81 */ "integer",
 	/* Used by: vdbe_eqp */
-	/*  84 */ "vdbe_eqp",
-	/*  85 */ "integer",
+	/*  82 */ "vdbe_eqp",
+	/*  83 */ "integer",
 	/* Used by: vdbe_listing */
-	/*  86 */ "vdbe_listing",
-	/*  87 */ "integer",
+	/*  84 */ "vdbe_listing",
+	/*  85 */ "integer",
 	/* Used by: vdbe_trace */
-	/*  88 */ "vdbe_trace",
-	/*  89 */ "integer",
+	/*  86 */ "vdbe_trace",
+	/*  87 */ "integer",
 	/* Used by: where_trace */
-	/*  90 */ "where_trace",
-	/*  91 */ "integer",
+	/*  88 */ "where_trace",
+	/*  89 */ "integer",
 };
 
 /* Definitions of all built-in pragmas */
@@ -165,15 +162,10 @@ static const PragmaName aPragmaName[] = {
 	 /* ePragFlg:  */ PragFlg_Result0,
 	 /* ColNames:  */ 38, 2,
 	 /* iArg:      */ 0},
-	{ /* zName:     */ "count_changes",
-	 /* ePragTyp:  */ PragTyp_FLAG,
-	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 60, 1,
-	 /* iArg:      */ SQL_CountRows},
 	{ /* zName:     */ "defer_foreign_keys",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 62, 1,
+	 /* ColNames:  */ 58, 1,
 	 /* iArg:      */ SQL_DeferFKs},
 	{ /* zName:     */ "foreign_key_list",
 	 /* ePragTyp:  */ PragTyp_FOREIGN_KEY_LIST,
@@ -184,7 +176,7 @@ static const PragmaName aPragmaName[] = {
 	{ /* zName:     */ "full_column_names",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 64, 1,
+	 /* ColNames:  */ 60, 1,
 	 /* iArg:      */ SQL_FullColNames},
 	{ /* zName:     */ "index_info",
 	 /* ePragTyp:  */ PragTyp_INDEX_INFO,
@@ -202,46 +194,46 @@ static const PragmaName aPragmaName[] = {
 	{ /* zName:     */ "parser_trace",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 64, 1,
+	 /* ColNames:  */ 62, 1,
 	 /* iArg:      */ PARSER_TRACE_FLAG},
 #endif
 	{ /* zName:     */ "recursive_triggers",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 66, 1,
+	 /* ColNames:  */ 64, 1,
 	 /* iArg:      */ SQL_RecTriggers},
 	{ /* zName:     */ "reverse_unordered_selects",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 68, 1,
+	 /* ColNames:  */ 66, 1,
 	 /* iArg:      */ SQL_ReverseOrder},
 #if defined(SQL_DEBUG)
 	{ /* zName:     */ "select_trace",
 	/* ePragTyp:  */ PragTyp_FLAG,
 	/* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	/* ColNames:  */ 70, 1,
+	/* ColNames:  */ 68, 1,
 	/* iArg:      */ SQL_SelectTrace},
 #endif
 	{ /* zName:     */ "short_column_names",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 72, 1,
+	 /* ColNames:  */ 70, 1,
 	 /* iArg:      */ SQL_ShortColNames},
 	{ /* zName:     */ "sql_compound_select_limit",
 	/* ePragTyp:  */ PragTyp_COMPOUND_SELECT_LIMIT,
 	/* ePragFlg:  */ PragFlg_Result0,
-	/* ColNames:  */ 74, 1,
+	/* ColNames:  */ 72, 1,
 	/* iArg:      */ 0},
 	{ /* zName:     */ "sql_default_engine",
 	 /* ePragTyp:  */ PragTyp_DEFAULT_ENGINE,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 76, 1,
+	 /* ColNames:  */ 74, 1,
 	 /* iArg:      */ 0},
 #if defined(SQL_DEBUG)
 	{ /* zName:     */ "sql_trace",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 78, 1,
+	 /* ColNames:  */ 76, 1,
 	 /* iArg:      */ SQL_SqlTrace},
 #endif
 	{ /* zName:     */ "stats",
@@ -260,33 +252,33 @@ static const PragmaName aPragmaName[] = {
 	{ /* zName:     */ "vdbe_addoptrace",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 80, 1,
+	 /* ColNames:  */ 78, 1,
 	 /* iArg:      */ SQL_VdbeAddopTrace},
 	{ /* zName:     */ "vdbe_debug",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 82, 1,
+	 /* ColNames:  */ 80, 1,
 	 /* iArg:      */
 	 SQL_SqlTrace | SQL_VdbeListing | SQL_VdbeTrace},
 	{ /* zName:     */ "vdbe_eqp",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 84, 1,
+	 /* ColNames:  */ 82, 1,
 	 /* iArg:      */ SQL_VdbeEQP},
 	{ /* zName:     */ "vdbe_listing",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 86, 1,
+	 /* ColNames:  */ 84, 1,
 	 /* iArg:      */ SQL_VdbeListing},
 	{ /* zName:     */ "vdbe_trace",
 	 /* ePragTyp:  */ PragTyp_FLAG,
 	 /* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	 /* ColNames:  */ 88, 1,
+	 /* ColNames:  */ 86, 1,
 	 /* iArg:      */ SQL_VdbeTrace},
 	{ /* zName:     */ "where_trace",
 	/* ePragTyp:  */ PragTyp_FLAG,
 	/* ePragFlg:  */ PragFlg_Result0 | PragFlg_NoColumns1,
-	/* ColNames:  */ 90, 1,
+	/* ColNames:  */ 88, 1,
 	/* iArg:      */ SQL_WhereTrace},
 #endif
 };
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 2594b73..b4f1d4c 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -1167,9 +1167,6 @@ struct sql {
 #define PARSER_TRACE_FLAG  0x00000002
 #define SQL_FullColNames   0x00000004	/* Show full column names on SELECT */
 #define SQL_ShortColNames  0x00000040	/* Show short columns names */
-#define SQL_CountRows      0x00000080	/* Count rows changed by INSERT, */
-					  /*   DELETE, or UPDATE and return */
-					  /*   the count using a callback. */
 #define SQL_SqlTrace       0x00000200	/* Debug print SQL as it executes */
 #define SQL_SelectTrace    0x00000800       /* Debug info about select statement */
 #define SQL_WhereTrace     0x00008000       /* Debug info about optimizer's work */
diff --git a/src/box/sql/update.c b/src/box/sql/update.c
index 6d69b72..d25262c 100644
--- a/src/box/sql/update.c
+++ b/src/box/sql/update.c
@@ -76,7 +76,6 @@ sqlUpdate(Parse * pParse,		/* The parser context */
 	int aiCurOnePass[2];	/* The write cursors opened by WHERE_ONEPASS */
 
 	/* Register Allocations */
-	int regRowCount = 0;	/* A count of rows changed */
 	int regOldPk = 0;
 	int regNewPk = 0;
 	int regNew = 0;		/* Content of the NEW.* table in triggers */
@@ -268,14 +267,6 @@ sqlUpdate(Parse * pParse,		/* The parser context */
 	 */
 	sqlWhereEnd(pWInfo);
 
-
-	/* Initialize the count of updated rows
-	 */
-	if ((pParse->sql_flags & SQL_CountRows) != 0 &&
-	    pParse->triggered_space == NULL) {
-		regRowCount = ++pParse->nMem;
-		sqlVdbeAddOp2(v, OP_Integer, 0, regRowCount);
-	}
 	labelBreak = sqlVdbeMakeLabel(v);
 	/* Top of the update loop */
 	if (okOnePass) {
@@ -470,13 +461,6 @@ sqlUpdate(Parse * pParse,		/* The parser context */
 			fk_constraint_emit_actions(pParse, space, regOldPk, aXRef);
 	}
 
-	/* Increment the row counter
-	 */
-	if ((pParse->sql_flags & SQL_CountRows) != 0 &&
-	     pParse->triggered_space == NULL) {
-		sqlVdbeAddOp2(v, OP_AddImm, regRowCount, 1);
-	}
-
 	vdbe_code_row_trigger(pParse, trigger, TK_UPDATE, pChanges,
 			      TRIGGER_AFTER, space, regOldPk, on_error,
 			      labelContinue);
@@ -493,17 +477,6 @@ sqlUpdate(Parse * pParse,		/* The parser context */
 	}
 	sqlVdbeResolveLabel(v, labelBreak);
 
-	/* Return the number of rows that were changed. */
-	if ((pParse->sql_flags & SQL_CountRows) != 0 &&
-	    pParse->triggered_space == NULL) {
-		sqlVdbeAddOp2(v, OP_ResultRow, regRowCount, 1);
-		sqlVdbeSetNumCols(v, 1);
-		sqlVdbeSetColName(v, 0, COLNAME_NAME, "rows updated",
-				      SQL_STATIC);
-		sqlVdbeSetColName(v, 0, COLNAME_DECLTYPE, "integer",
-				  SQL_STATIC);
-	}
-
  update_cleanup:
 	sqlSrcListDelete(db, pTabList);
 	sql_expr_list_delete(db, pChanges);
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index ab86be9..2e51a0d 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -1411,34 +1411,7 @@ case OP_ResultRow: {
 	assert(p->nResColumn==pOp->p2);
 	assert(pOp->p1>0);
 	assert(pOp->p1+pOp->p2<=(p->nMem+1 - p->nCursor)+1);
-
-	/* If this statement has violated immediate foreign key constraints, do
-	 * not return the number of rows modified. And do not RELEASE the statement
-	 * transaction. It needs to be rolled back.
-	 */
-	if (sqlVdbeCheckFk(p, 0) != 0) {
-		assert((p->sql_flags & SQL_CountRows) != 0);
-		goto abort_due_to_error;
-	}
-
-	/* If the SQL_CountRows flag is set in sql.flags mask, then
-	 * DML statements invoke this opcode to return the number of rows
-	 * modified to the user. This is the only way that a VM that
-	 * opens a statement transaction may invoke this opcode.
-	 *
-	 * In case this is such a statement, close any statement transaction
-	 * opened by this VM before returning control to the user. This is to
-	 * ensure that statement-transactions are always nested, not overlapping.
-	 * If the open statement-transaction is not closed here, then the user
-	 * may step another VM that opens its own statement transaction. This
-	 * may lead to overlapping statement transactions.
-	 *
-	 * The statement transaction is never a top-level transaction.  Hence
-	 * the RELEASE call below can never fail.
-	 */
-	assert(p->iStatement == 0 || (p->sql_flags & SQL_CountRows) != 0);
-	rc = sqlVdbeCloseStatement(p, SAVEPOINT_RELEASE);
-	assert(rc==0);
+	assert(p->iStatement == 0 && p->anonymous_savepoint == NULL);
 
 	/* Invalidate all ephemeral cursor row caches */
 	p->cacheCtr = (p->cacheCtr + 2)|1;
diff --git a/test/sql-tap/update.test.lua b/test/sql-tap/update.test.lua
index 07e4e43..ac0389a 100755
--- a/test/sql-tap/update.test.lua
+++ b/test/sql-tap/update.test.lua
@@ -21,6 +21,11 @@ test:plan(111)
 -- ["source",[["testdir"],"\/tester.tcl"]]
 -- Try to update an non-existent table
 --
+
+local function update_row_count(sql)
+    return box.execute(sql).row_count
+end
+
 test:do_catchsql_test("update-1.1", [[
   UPDATE test1 SET f2=5 WHERE f1<1
 ]], {
@@ -124,13 +129,12 @@ test:do_execsql_test("update-3.6", [[
 })
 
 test:do_test("update-3.7", function()
-  test:execsql "PRAGMA count_changes=on"
-  return test:execsql "UPDATE test1 SET f2=f2/3 WHERE f1<=5"
-end, {
+    return update_row_count("UPDATE test1 SET f2 = f2 / 3 WHERE f1 <= 5")
+  end,
   -- <update-3.7>
   5
   -- </update-3.7>
-})
+)
 
 test:do_execsql_test("update-3.8", [[
   SELECT f1,f2 FROM test1 ORDER BY f1
@@ -140,13 +144,13 @@ test:do_execsql_test("update-3.8", [[
   -- </update-3.8>
 })
 
-test:do_execsql_test("update-3.9", [[
-  UPDATE test1 SET f2=f2/3 WHERE f1>5
-]], {
+test:do_test("update-3.9", function()
+    return update_row_count("UPDATE test1 SET f2 = f2 / 3 WHERE f1 > 5")
+  end,
   -- <update-3.9>
   5
   -- </update-3.9>
-})
+)
 
 test:do_execsql_test("update-3.10", [[
   SELECT f1,f2 FROM test1 ORDER BY f1
@@ -158,13 +162,13 @@ test:do_execsql_test("update-3.10", [[
 
 -- Swap the values of f1 and f2 for all elements
 --
-test:do_execsql_test("update-3.11", [[
-  UPDATE test1 SET F2=f1, F1=f2
-]], {
+test:do_test("update-3.11", function()
+    return update_row_count("UPDATE test1 SET F2 = f1, F1 = f2")
+  end,
   -- <update-3.11>
   10
   -- </update-3.11>
-})
+)
 
 test:do_execsql_test("update-3.12", [[
   SELECT f1,f2 FROM test1 ORDER BY F1
@@ -175,7 +179,6 @@ test:do_execsql_test("update-3.12", [[
 })
 
 test:do_test("update-3.13", function()
-  test:execsql "PRAGMA count_changes=off"
   return test:execsql "UPDATE test1 SET F2=f1, F1=f2"
 end, {
   -- <update-3.13>
@@ -254,17 +257,15 @@ end, {
   -- </update-4.5>
 })
 
-test:do_execsql_test("update-4.6", [[
-  PRAGMA count_changes=on;
-  UPDATE test1 SET f1=f1-1 WHERE f1<=100 and f2==128;
-]], {
+test:do_test("update-4.6", function()
+    return update_row_count("UPDATE test1 SET f1 = f1 - 1 WHERE f1 <= 100 and f2 == 128;")
+  end,
   -- <update-4.6>
   2
   -- </update-4.6>
-})
+)
 
 test:do_execsql_test("update-4.7", [[
-  PRAGMA count_changes=off;
   SELECT f1,f2 FROM test1 ORDER BY f1,f2
 ]], {
   -- <update-4.7>
@@ -391,17 +392,15 @@ test:do_execsql_test("update-5.5.5", [[
   -- </update-5.5.5>
 })
 
-test:do_execsql_test("update-5.6", [[
-  PRAGMA count_changes=on;
-  UPDATE test1 SET f1=f1-1 WHERE f1<=100 and f2==128;
-]], {
+test:do_test("update-5.6", function()
+    return update_row_count("UPDATE test1 SET f1 = f1 - 1 WHERE f1 <= 100 and f2 == 128;")
+  end,
   -- <update-5.6>
   2
   -- </update-5.6>
-})
+)
 
 test:do_execsql_test("update-5.6.1", [[
-  PRAGMA count_changes=off;
   SELECT f1,f2 FROM test1 ORDER BY f1,f2
 ]], {
   -- <update-5.6.1>
diff --git a/test/sql/iproto.result b/test/sql/iproto.result
index 67acd0a..ffc7cd9 100644
--- a/test/sql/iproto.result
+++ b/test/sql/iproto.result
@@ -732,37 +732,6 @@ res.metadata
   - name: detail
     type: text
 ...
--- When pragma count_changes is on, statements INSERT, REPLACE and
--- UPDATE returns number of changed columns. Make sure that this
--- result has a column type.
-cn:execute("PRAGMA count_changes = 1;")
----
-- row_count: 0
-...
-cn:execute("INSERT INTO t1 VALUES (1), (2), (3);")
----
-- metadata:
-  - name: rows inserted
-    type: integer
-  rows:
-  - [3]
-...
-cn:execute("REPLACE INTO t1 VALUES (2), (3), (4), (5);")
----
-- metadata:
-  - name: rows replaced
-    type: integer
-  rows:
-  - [4]
-...
-cn:execute("UPDATE t1 SET id = id + 100 WHERE id > 10;")
----
-- metadata:
-  - name: rows updated
-    type: integer
-  rows:
-  - [0]
-...
 -- Make sure that built-in functions have a right returning type.
 --
 cn:execute("SELECT zeroblob(1);")
diff --git a/test/sql/iproto.test.lua b/test/sql/iproto.test.lua
index 5dfe95c..b5ec2c0 100644
--- a/test/sql/iproto.test.lua
+++ b/test/sql/iproto.test.lua
@@ -220,14 +220,6 @@ res.metadata
 res = cn:execute("EXPLAIN QUERY PLAN SELECT COUNT(*) FROM t1")
 res.metadata
 
--- When pragma count_changes is on, statements INSERT, REPLACE and
--- UPDATE returns number of changed columns. Make sure that this
--- result has a column type.
-cn:execute("PRAGMA count_changes = 1;")
-cn:execute("INSERT INTO t1 VALUES (1), (2), (3);")
-cn:execute("REPLACE INTO t1 VALUES (2), (3), (4), (5);")
-cn:execute("UPDATE t1 SET id = id + 100 WHERE id > 10;")
-
 -- Make sure that built-in functions have a right returning type.
 --
 cn:execute("SELECT zeroblob(1);")
diff --git a/test/sql/sql-debug.result b/test/sql/sql-debug.result
index b190753..e52a13a 100644
--- a/test/sql/sql-debug.result
+++ b/test/sql/sql-debug.result
@@ -38,7 +38,6 @@ box.execute('PRAGMA')
   - name: pragma_value
     type: integer
   rows:
-  - ['count_changes', 0]
   - ['defer_foreign_keys', 0]
   - ['full_column_names', 0]
   - ['parser_trace', 0]
-- 
2.7.4



More information about the Tarantool-patches mailing list