Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system
@ 2019-06-10 13:56 imeevma
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 01/28] sql: remove field zErrMsg from struct Vdbe imeevma
                   ` (31 more replies)
  0 siblings, 32 replies; 56+ messages in thread
From: imeevma @ 2019-06-10 13:56 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

This patch-set removes unused and unnecessary code of SQL error
system.

Mergen Imeev (26):
  sql: remove field zErrMsg from struct Vdbe
  sql: remove field pErr from struct sql
  sql: remove field errCode from struct sql
  sql: remove sqlError() and remove sqlErrorWithMsg()
  sql: remove unused functions of SQL error system
  sql: disable lookaside system
  sql: remove SQL_OK error/status code
  sql: remove SQL_PERM, SQL_WARNING, SQL_ABORT errcodes
  sql: remove SQL_CANTOPEN errcode
  sql: remove SQL_NOTFOUND error/status code
  sql: remove SQL_LOCKED errcode
  sql: remove SQL_FULL errcode
  sql: remove SQL_MISUSE errcode
  sql: remove SQL_RANGE errcode
  sql: remove SQL_SCHEMA errcode
  sql: remove SQL_TOOBIG errcode
  sql: remove SQL_BUSY errcode
  sql: remove SQL_CONSTRAINT errcode
  sql: remove SQL_ERROR errcode
  sql: remove SQL_NOMEM errcode
  sql: remove SQL_IOERR errcode
  sql: remove SQL_TARANTOOL_ERROR errcode
  sql: remove field errMask from struct sql
  sql: replace rc by is_aborted in struct VDBE
  sql: remove sql_log()
  sql: remove function sqlApiExit()

Nikita Pettik (2):
  sql: cleanup of legacy memory management system
  sql: make function return void instead of int

 src/box/bind.c                |  37 +---
 src/box/ck_constraint.c       |   4 +-
 src/box/execute.c             |   6 +-
 src/box/lua/lua_sql.c         |   2 +-
 src/box/sql.c                 | 104 ++++------
 src/box/sql/analyze.c         |   2 +-
 src/box/sql/build.c           |   6 +-
 src/box/sql/cursor.c          |   4 +-
 src/box/sql/date.c            |  14 +-
 src/box/sql/expr.c            |   7 +-
 src/box/sql/fault.c           |   4 +-
 src/box/sql/fk_constraint.c   |   8 +-
 src/box/sql/func.c            |  16 +-
 src/box/sql/global.c          |   3 -
 src/box/sql/insert.c          |   9 +-
 src/box/sql/legacy.c          |  21 +-
 src/box/sql/main.c            | 266 ++++---------------------
 src/box/sql/malloc.c          | 445 +-----------------------------------------
 src/box/sql/os.c              |  14 +-
 src/box/sql/os_unix.c         | 281 ++++++++------------------
 src/box/sql/prepare.c         |  73 ++-----
 src/box/sql/printf.c          |  36 +---
 src/box/sql/resolve.c         |   3 +-
 src/box/sql/select.c          |  61 +++---
 src/box/sql/sqlInt.h          | 173 +---------------
 src/box/sql/status.c          | 182 -----------------
 src/box/sql/tarantoolInt.h    |  11 +-
 src/box/sql/tokenize.c        |   5 -
 src/box/sql/trigger.c         |   2 +-
 src/box/sql/util.c            | 162 ---------------
 src/box/sql/vdbe.c            | 111 ++++-------
 src/box/sql/vdbeInt.h         |  13 +-
 src/box/sql/vdbeapi.c         | 357 +++++++++------------------------
 src/box/sql/vdbeaux.c         | 217 ++++++--------------
 src/box/sql/vdbemem.c         | 120 ++++++------
 src/box/sql/vdbesort.c        | 274 ++++++++++++--------------
 src/box/sql/where.c           | 108 +++++-----
 src/box/sql/whereexpr.c       |   3 +-
 test/sql/bind.result          |   8 +
 test/sql/bind.test.lua        |   3 +
 test/sql/func-recreate.result |   3 +-
 41 files changed, 726 insertions(+), 2452 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 01/28] sql: remove field zErrMsg from struct Vdbe
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
@ 2019-06-10 13:56 ` imeevma
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 02/28] sql: remove field pErr from struct sql imeevma
                   ` (30 subsequent siblings)
  31 siblings, 0 replies; 56+ messages in thread
From: imeevma @ 2019-06-10 13:56 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

This field has become unused and should be removed.
---
 src/box/sql/vdbeInt.h |  1 -
 src/box/sql/vdbeaux.c | 29 ++++-------------------------
 2 files changed, 4 insertions(+), 26 deletions(-)

diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h
index 15eb55c..8b212e3 100644
--- a/src/box/sql/vdbeInt.h
+++ b/src/box/sql/vdbeInt.h
@@ -384,7 +384,6 @@ struct Vdbe {
 	Mem **apArg;		/* Arguments to currently executing user function */
 	Mem *aColName;		/* Column names to return */
 	Mem *pResultSet;	/* Pointer to an array of results */
-	char *zErrMsg;		/* Error message written here */
 	VdbeCursor **apCsr;	/* One element of this array for each open cursor */
 	Mem *aVar;		/* Values for the OP_Variable opcode. */
 	/**
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 3f573d0..ae1f38f 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -1957,7 +1957,6 @@ closeCursorsAndFree(Vdbe * p)
 static void
 Cleanup(Vdbe * p)
 {
-	sql *db = p->db;
 
 #ifdef SQL_DEBUG
 	/* Execute assert() statements to ensure that the Vdbe.apCsr[] and
@@ -1973,8 +1972,6 @@ Cleanup(Vdbe * p)
 	}
 #endif
 
-	sqlDbFree(db, p->zErrMsg);
-	p->zErrMsg = 0;
 	p->pResultSet = 0;
 }
 
@@ -2317,8 +2314,6 @@ sqlVdbeHalt(Vdbe * p)
 				if (p->rc == SQL_OK
 				    || (p->rc & 0xff) == SQL_CONSTRAINT) {
 					p->rc = rc;
-					sqlDbFree(db, p->zErrMsg);
-					p->zErrMsg = 0;
 				}
 				closeCursorsAndFree(p);
 				sqlRollbackAll(p);
@@ -2381,24 +2376,13 @@ sqlVdbeTransferError(Vdbe * p)
 {
 	sql *db = p->db;
 	int rc = p->rc;
-	if (p->zErrMsg) {
-		db->bBenignMalloc++;
-		sqlBeginBenignMalloc();
-		if (db->pErr == 0)
-			db->pErr = sqlValueNew(db);
-		sqlValueSetStr(db->pErr, -1, p->zErrMsg, SQL_TRANSIENT);
-		sqlEndBenignMalloc();
-		db->bBenignMalloc--;
-		db->errCode = rc;
-	} else {
-		sqlError(db, rc);
-	}
+	sqlError(db, rc);
 	return rc;
 }
 
 /*
  * Clean up a VDBE after execution but do not delete the VDBE just yet.
- * Write any error messages into *pzErrMsg.  Return the result code.
+ * Return the result code.
  *
  * After this routine is run, the VDBE should be ready to be executed
  * again.
@@ -2426,8 +2410,6 @@ sqlVdbeReset(Vdbe * p)
 	 */
 	if (p->pc >= 0) {
 		sqlVdbeTransferError(p);
-		sqlDbFree(db, p->zErrMsg);
-		p->zErrMsg = 0;
 		if (p->runOnlyOnce)
 			p->expired = 1;
 	} else if (p->rc && p->expired) {
@@ -2435,10 +2417,7 @@ sqlVdbeReset(Vdbe * p)
 		 * to sql_step(). For consistency (since sql_step() was
 		 * called), set the database error in this case as well.
 		 */
-		sqlErrorWithMsg(db, p->rc, p->zErrMsg ? "%s" : 0,
-				    p->zErrMsg);
-		sqlDbFree(db, p->zErrMsg);
-		p->zErrMsg = 0;
+		sqlErrorWithMsg(db, p->rc, NULL);
 	}
 
 	/* Reclaim all memory used by the VDBE
@@ -2492,7 +2471,7 @@ sqlVdbeReset(Vdbe * p)
 
 /*
  * Clean up and delete a VDBE after execution.  Return an integer which is
- * the result code.  Write any error message text into *pzErrMsg.
+ * the result code.
  */
 int
 sqlVdbeFinalize(Vdbe * p)
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 02/28] sql: remove field pErr from struct sql
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 01/28] sql: remove field zErrMsg from struct Vdbe imeevma
@ 2019-06-10 13:56 ` imeevma
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 03/28] sql: remove field errCode " imeevma
                   ` (29 subsequent siblings)
  31 siblings, 0 replies; 56+ messages in thread
From: imeevma @ 2019-06-10 13:56 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

This field has become unused and should be removed.
---
 src/box/sql/malloc.c  |  3 +--
 src/box/sql/sqlInt.h  |  1 -
 src/box/sql/util.c    | 14 ++------------
 src/box/sql/vdbeapi.c |  3 ---
 4 files changed, 3 insertions(+), 18 deletions(-)

diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index dbc6846..72a1fb9 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -939,8 +939,7 @@ apiOomError(sql * db)
  * function. However, if a malloc() failure has occurred since the previous
  * invocation SQL_NOMEM is returned instead.
  *
- * If an OOM as occurred, then the connection error-code (the value
- * returned by sql_errcode()) is set to SQL_NOMEM.
+ * If an OOM as occurred, SQL_NOMEM is returned.
  */
 int
 sqlApiExit(sql * db, int rc)
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index a7487c7..fe5e64c 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -1471,7 +1471,6 @@ struct sql {
 	void *pUpdateArg;
 	void (*xUpdateCallback) (void *, int, const char *, const char *,
 				 sql_int64);
-	sql_value *pErr;	/* Most recent error message */
 	Lookaside lookaside;	/* Lookaside malloc configuration */
 	Hash aFunc;		/* Hash table of connection functions */
 	int *pnBytesFreed;	/* If not NULL, increment this in DbFree() */
diff --git a/src/box/sql/util.c b/src/box/sql/util.c
index d5c93f8..62c29ce 100644
--- a/src/box/sql/util.c
+++ b/src/box/sql/util.c
@@ -138,8 +138,6 @@ sqlStrlen30(const char *z)
 static SQL_NOINLINE void
 sqlErrorFinish(sql * db, int err_code)
 {
-	if (db->pErr)
-		sqlValueSetNull(db->pErr);
 	sqlSystemError(db, err_code);
 }
 
@@ -153,7 +151,7 @@ sqlError(sql * db, int err_code)
 {
 	assert(db != 0);
 	db->errCode = err_code;
-	if (err_code || db->pErr)
+	if (err_code)
 		sqlErrorFinish(db, err_code);
 }
 
@@ -199,16 +197,8 @@ sqlErrorWithMsg(sql * db, int err_code, const char *zFormat, ...)
 	assert(db != 0);
 	db->errCode = err_code;
 	sqlSystemError(db, err_code);
-	if (zFormat == 0) {
+	if (zFormat == 0)
 		sqlError(db, err_code);
-	} else if (db->pErr || (db->pErr = sqlValueNew(db)) != 0) {
-		char *z;
-		va_list ap;
-		va_start(ap, zFormat);
-		z = sqlVMPrintf(db, zFormat, ap);
-		va_end(ap);
-		sqlValueSetStr(db->pErr, -1, z, SQL_DYNAMIC);
-	}
 }
 
 /*
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 85059ed..81ee36b 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -107,9 +107,6 @@ invokeProfileCallback(sql * db, Vdbe * p)
  * the sql_compile() routine. The integer returned is an SQL_
  * success/failure code that describes the result of executing the virtual
  * machine.
- *
- * This routine sets the error code and string returned by
- * sql_errcode(), sql_errmsg() and sql_errmsg16().
  */
 int
 sql_finalize(sql_stmt * pStmt)
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 03/28] sql: remove field errCode from struct sql
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 01/28] sql: remove field zErrMsg from struct Vdbe imeevma
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 02/28] sql: remove field pErr from struct sql imeevma
@ 2019-06-10 13:56 ` imeevma
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 04/28] sql: remove sqlError() and remove sqlErrorWithMsg() imeevma
                   ` (28 subsequent siblings)
  31 siblings, 0 replies; 56+ messages in thread
From: imeevma @ 2019-06-10 13:56 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

This field has become unused and should be removed.
---
 src/box/sql/main.c    | 18 ------------------
 src/box/sql/prepare.c |  2 --
 src/box/sql/sqlInt.h  |  1 -
 src/box/sql/util.c    |  2 --
 src/box/sql/vdbeapi.c |  1 -
 5 files changed, 24 deletions(-)

diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index a3c6aa1..155cbcc 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -568,22 +568,6 @@ sqlTempInMemory(const sql * db)
 }
 
 /*
- * Return the most recent error code generated by an sql routine. If NULL is
- * passed to this function, we assume a malloc() failed during sql_open().
- */
-int
-sql_errcode(sql * db)
-{
-	if (db && !sqlSafetyCheckSickOrOk(db)) {
-		return SQL_MISUSE;
-	}
-	if (!db || db->mallocFailed) {
-		return SQL_NOMEM;
-	}
-	return db->errCode & db->errMask;
-}
-
-/*
  * This array defines hard upper bounds on limit values.  The
  * initializer must be kept in sync with the SQL_LIMIT_*
  * #defines in sql.h.
@@ -734,7 +718,6 @@ sql_init_db(sql **out_db)
 	 */
 	sqlError(db, SQL_OK);
 	sqlRegisterPerConnectionBuiltinFunctions(db);
-	rc = sql_errcode(db);
 
 	if (rc)
 		sqlError(db, rc);
@@ -744,7 +727,6 @@ sql_init_db(sql **out_db)
 		       sqlGlobalConfig.nLookaside);
 
 opendb_out:
-	rc = sql_errcode(db);
 	assert(db != 0 || rc == SQL_NOMEM);
 	if (rc == SQL_NOMEM) {
 		sql_close(db);
diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index ad4c71c..e2f8c0b 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -166,8 +166,6 @@ sqlPrepare(sql * db,	/* Database handle. */
 		*ppStmt = (sql_stmt *) sParse.pVdbe;
 	}
 
-	db->errCode = rc;
-
 	/* Delete any TriggerPrg structures allocated while parsing this statement. */
 	while (sParse.pTriggerPrg) {
 		TriggerPrg *pT = sParse.pTriggerPrg;
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index fe5e64c..bda3df1 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -1436,7 +1436,6 @@ struct sql {
 	struct Vdbe *pVdbe;	/* List of active virtual machines */
 	struct coll *pDfltColl;	/* The default collating sequence (BINARY) */
 	i64 szMmap;		/* Default mmap_size setting */
-	int errCode;		/* Most recent error code (sql_*) */
 	int errMask;		/* & result codes with this before returning */
 	int iSysErrno;		/* Errno value from last system error */
 	u16 dbOptFlags;		/* Flags to enable/disable optimizations */
diff --git a/src/box/sql/util.c b/src/box/sql/util.c
index 62c29ce..819f7fa 100644
--- a/src/box/sql/util.c
+++ b/src/box/sql/util.c
@@ -150,7 +150,6 @@ void
 sqlError(sql * db, int err_code)
 {
 	assert(db != 0);
-	db->errCode = err_code;
 	if (err_code)
 		sqlErrorFinish(db, err_code);
 }
@@ -195,7 +194,6 @@ void
 sqlErrorWithMsg(sql * db, int err_code, const char *zFormat, ...)
 {
 	assert(db != 0);
-	db->errCode = err_code;
 	sqlSystemError(db, err_code);
 	if (zFormat == 0)
 		sqlError(db, err_code);
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 81ee36b..db1726a 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -515,7 +515,6 @@ sqlStep(Vdbe * p)
 		checkProfileCallback(db, p);
 #endif
 
-	db->errCode = rc;
 	if (SQL_NOMEM == sqlApiExit(p->db, p->rc)) {
 		p->rc = SQL_NOMEM;
 	}
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 04/28] sql: remove sqlError() and remove sqlErrorWithMsg()
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (2 preceding siblings ...)
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 03/28] sql: remove field errCode " imeevma
@ 2019-06-10 13:56 ` imeevma
  2019-06-13 22:25   ` [tarantool-patches] " Vladislav Shpilevoy
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 05/28] sql: remove unused functions of SQL error system imeevma
                   ` (27 subsequent siblings)
  31 siblings, 1 reply; 56+ messages in thread
From: imeevma @ 2019-06-10 13:56 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

These functions are part of the SQL error system, which is
replaced by the Tarantool error system. They are not needed now,
so they will be deleted.
---
 src/box/lua/lua_sql.c         |  2 +-
 src/box/sql/legacy.c          |  2 --
 src/box/sql/main.c            | 83 +++++++------------------------------------
 src/box/sql/malloc.c          |  1 -
 src/box/sql/prepare.c         |  6 ++--
 src/box/sql/sqlInt.h          |  6 ----
 src/box/sql/util.c            | 69 -----------------------------------
 src/box/sql/vdbeInt.h         |  1 -
 src/box/sql/vdbeapi.c         |  7 +---
 src/box/sql/vdbeaux.c         | 31 +++++-----------
 test/sql/func-recreate.result |  3 +-
 11 files changed, 27 insertions(+), 184 deletions(-)

diff --git a/src/box/lua/lua_sql.c b/src/box/lua/lua_sql.c
index 529ee59..4d90a53 100644
--- a/src/box/lua/lua_sql.c
+++ b/src/box/lua/lua_sql.c
@@ -199,6 +199,6 @@ lbox_sql_create_function(struct lua_State *L)
 					   func_info, lua_sql_call, NULL, NULL,
 					   lua_sql_destroy);
 	if (rc != 0)
-		return luaL_error(L, sqlErrStr(rc));
+		return luaT_error(L);
 	return 0;
 }
diff --git a/src/box/sql/legacy.c b/src/box/sql/legacy.c
index a57677e..d519991 100644
--- a/src/box/sql/legacy.c
+++ b/src/box/sql/legacy.c
@@ -69,7 +69,6 @@ sql_exec(sql * db,	/* The database on which the SQL executes */
 	if (zSql == 0)
 		zSql = "";
 
-	sqlError(db, SQL_OK);
 	while (rc == SQL_OK && zSql[0]) {
 		int nCol;
 		char **azVals = 0;
@@ -141,7 +140,6 @@ sql_exec(sql * db,	/* The database on which the SQL executes */
 					rc = SQL_ABORT;
 					sqlVdbeFinalize((Vdbe *) pStmt);
 					pStmt = 0;
-					sqlError(db, SQL_ABORT);
 					goto exec_out;
 				}
 			}
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index 155cbcc..f35c84f 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -284,61 +284,6 @@ functionDestroy(sql * db, FuncDef * p)
 }
 
 /*
- * Return TRUE if database connection db has unfinalized prepared
- * statement.
- */
-static int
-connectionIsBusy(sql * db)
-{
-	if (db->pVdbe)
-		return 1;
-	return 0;
-}
-
-/*
- * Close an existing sql database
- */
-static int
-sqlClose(sql * db, int forceZombie)
-{
-	assert(db);
-	if (!sqlSafetyCheckSickOrOk(db)) {
-		return SQL_MISUSE;
-	}
-	if (db->mTrace & SQL_TRACE_CLOSE) {
-		db->xTrace(SQL_TRACE_CLOSE, db->pTraceArg, db, 0);
-	}
-
-	/* Legacy behavior (sql_close() behavior) is to return
-	 * SQL_BUSY if the connection can not be closed immediately.
-	 */
-	if (!forceZombie && connectionIsBusy(db)) {
-		sqlErrorWithMsg(db, SQL_BUSY,
-				    "unable to close due to unfinalized "
-				    "statements");
-		return SQL_BUSY;
-	}
-
-	/* Convert the connection into a zombie and then close it.
-	 */
-	db->magic = SQL_MAGIC_ZOMBIE;
-
-	return SQL_OK;
-}
-
-/*
- * Two variations on the public interface for closing a database
- * connection. The sql_close() version returns SQL_BUSY and
- * leaves the connection option if there are unfinalized prepared
- * statements.
- */
-int
-sql_close(sql * db)
-{
-	return sqlClose(db, 0);
-}
-
-/*
  * Rollback all database files.  If tripCode is not SQL_OK, then
  * any write cursors are invalidated ("tripped" - as in "tripping a circuit
  * breaker") and made to return tripCode if there are any further
@@ -417,7 +362,9 @@ sqlCreateFunc(sql * db,
 	    (!xSFunc && (!xFinal && xStep)) ||
 	    (nArg < -1 || nArg > SQL_MAX_FUNCTION_ARG) ||
 	    (255 < (sqlStrlen30(zFunctionName)))) {
-		return SQL_MISUSE;
+		diag_set(ClientError, ER_CREATE_FUNCTION, zFunctionName,
+			 "wrong function definition");
+		return SQL_TARANTOOL_ERROR;
 	}
 
 	assert(SQL_FUNC_CONSTANT == SQL_DETERMINISTIC);
@@ -432,10 +379,10 @@ sqlCreateFunc(sql * db,
 	p = sqlFindFunction(db, zFunctionName, nArg, 0);
 	if (p && p->nArg == nArg) {
 		if (db->nVdbeActive) {
-			sqlErrorWithMsg(db, SQL_BUSY,
-					    "unable to delete/modify user-function due to active statements");
-			assert(!db->mallocFailed);
-			return SQL_BUSY;
+			diag_set(ClientError, ER_CREATE_FUNCTION, zFunctionName,
+				 "unable to create function due to active "\
+				 "statements");
+			return SQL_TARANTOOL_ERROR;
 		} else {
 			sqlExpirePreparedStatements(db);
 		}
@@ -443,9 +390,8 @@ sqlCreateFunc(sql * db,
 
 	p = sqlFindFunction(db, zFunctionName, nArg, 1);
 	assert(p || db->mallocFailed);
-	if (!p) {
-		return SQL_NOMEM;
-	}
+	if (p == NULL)
+		return SQL_TARANTOOL_ERROR;
 
 	/* If an older version of the function with a configured destructor is
 	 * being replaced invoke the destructor function here.
@@ -716,22 +662,17 @@ sql_init_db(sql **out_db)
 	 * database schema yet. This is delayed until the first time the database
 	 * is accessed.
 	 */
-	sqlError(db, SQL_OK);
 	sqlRegisterPerConnectionBuiltinFunctions(db);
 
-	if (rc)
-		sqlError(db, rc);
-
 	/* Enable the lookaside-malloc subsystem */
 	setupLookaside(db, 0, sqlGlobalConfig.szLookaside,
 		       sqlGlobalConfig.nLookaside);
 
 opendb_out:
 	assert(db != 0 || rc == SQL_NOMEM);
-	if (rc == SQL_NOMEM) {
-		sql_close(db);
-		db = 0;
-	} else if (rc != SQL_OK)
+	if (rc == SQL_NOMEM)
+		db = NULL;
+	else if (rc != SQL_OK)
 		db->magic = SQL_MAGIC_SICK;
 
 	*out_db = db;
diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index 72a1fb9..925ffb2 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -926,7 +926,6 @@ static SQL_NOINLINE int
 apiOomError(sql * db)
 {
 	sqlOomClear(db);
-	sqlError(db, SQL_NOMEM);
 	return SQL_NOMEM;
 }
 
diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index e2f8c0b..e692be0 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -81,9 +81,9 @@ sqlPrepare(sql * db,	/* Database handle. */
 		testcase(nBytes == mxLen);
 		testcase(nBytes == mxLen + 1);
 		if (nBytes > mxLen) {
-			sqlErrorWithMsg(db, SQL_TOOBIG,
-					    "statement too long");
-			rc = sqlApiExit(db, SQL_TOOBIG);
+			diag_set(ClientError, ER_SQL_PARSER_LIMIT,
+				 "SQL command length", nBytes, mxLen);
+			rc = SQL_TARANTOOL_ERROR;
 			goto end_prepare;
 		}
 		zSqlCopy = sqlDbStrNDup(db, zSql, nBytes);
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index bda3df1..2b7aa8b 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -931,8 +931,6 @@ sql_stmt_busy(sql_stmt *);
 int
 sql_init_db(sql **db);
 
-int
-sql_close(sql *);
 
 /**
  * Get number of the named parameter in the prepared sql
@@ -1437,7 +1435,6 @@ struct sql {
 	struct coll *pDfltColl;	/* The default collating sequence (BINARY) */
 	i64 szMmap;		/* Default mmap_size setting */
 	int errMask;		/* & result codes with this before returning */
-	int iSysErrno;		/* Errno value from last system error */
 	u16 dbOptFlags;		/* Flags to enable/disable optimizations */
 	u8 enc;			/* Text encoding */
 	u8 temp_store;		/* 1: file 2: memory 0: default */
@@ -4460,9 +4457,6 @@ sql_atoi64(const char *z, int64_t *val, int length);
 int
 sql_dec_or_hex_to_i64(const char *z, int64_t *val);
 
-void sqlErrorWithMsg(sql *, int, const char *, ...);
-void sqlError(sql *, int);
-void sqlSystemError(sql *, int);
 void *sqlHexToBlob(sql *, const char *z, int n);
 u8 sqlHexToInt(int h);
 
diff --git a/src/box/sql/util.c b/src/box/sql/util.c
index 819f7fa..d5f6447 100644
--- a/src/box/sql/util.c
+++ b/src/box/sql/util.c
@@ -131,75 +131,6 @@ sqlStrlen30(const char *z)
 }
 
 /*
- * Helper function for sqlError() - called rarely.  Broken out into
- * a separate routine to avoid unnecessary register saves on entry to
- * sqlError().
- */
-static SQL_NOINLINE void
-sqlErrorFinish(sql * db, int err_code)
-{
-	sqlSystemError(db, err_code);
-}
-
-/*
- * Set the current error code to err_code and clear any prior error message.
- * Also set iSysErrno (by calling sqlSystem) if the err_code indicates
- * that would be appropriate.
- */
-void
-sqlError(sql * db, int err_code)
-{
-	assert(db != 0);
-	if (err_code)
-		sqlErrorFinish(db, err_code);
-}
-
-/*
- * Load the sql.iSysErrno field if that is an appropriate thing
- * to do based on the sql error code in rc.
- */
-void
-sqlSystemError(sql * db, int rc)
-{
-	if (rc == SQL_IOERR_NOMEM)
-		return;
-	rc &= 0xff;
-	if (rc == SQL_CANTOPEN || rc == SQL_IOERR) {
-		db->iSysErrno = sqlOsGetLastError(db->pVfs);
-	}
-}
-
-/*
- * Set the most recent error code and error string for the sql
- * handle "db". The error code is set to "err_code".
- *
- * If it is not NULL, string zFormat specifies the format of the
- * error string in the style of the printf functions: The following
- * format characters are allowed:
- *
- *      %s      Insert a string
- *      %z      A string that should be freed after use
- *      %d      Insert an integer
- *      %T      Insert a token
- *      %S      Insert the first element of a SrcList
- *
- * zFormat and any string tokens that follow it are assumed to be
- * encoded in UTF-8.
- *
- * To clear the most recent error for sql handle "db", sqlError
- * should be called with err_code set to SQL_OK and zFormat set
- * to NULL.
- */
-void
-sqlErrorWithMsg(sql * db, int err_code, const char *zFormat, ...)
-{
-	assert(db != 0);
-	sqlSystemError(db, err_code);
-	if (zFormat == 0)
-		sqlError(db, err_code);
-}
-
-/*
  * Convert an SQL-style quoted string into a normal string by removing
  * the quote characters.  The conversion is done in-place.  If the
  * input does not begin with a quote character, then this routine
diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h
index 8b212e3..8da0c29 100644
--- a/src/box/sql/vdbeInt.h
+++ b/src/box/sql/vdbeInt.h
@@ -507,7 +507,6 @@ int sqlVdbeMemClearAndResize(Mem * pMem, int n);
 int sqlVdbeCloseStatement(Vdbe *, int);
 void sqlVdbeFrameDelete(VdbeFrame *);
 int sqlVdbeFrameRestore(VdbeFrame *);
-int sqlVdbeTransferError(Vdbe * p);
 
 int sqlVdbeSorterInit(struct sql *db, struct VdbeCursor *cursor);
 void sqlVdbeSorterReset(sql *, VdbeSorter *);
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index db1726a..c151a52 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -524,7 +524,7 @@ sqlStep(Vdbe * p)
 		 * error has occurred, then return the error code in p->rc to the
 		 * caller. Set the error code in the database handle to the same value.
 		 */
-		rc = sqlVdbeTransferError(p);
+		rc = p->rc;
 	}
 	return (rc & db->errMask);
 }
@@ -756,7 +756,6 @@ columnMem(sql_stmt * pStmt, int i)
 	if (pVm->pResultSet != 0 && i < pVm->nResColumn && i >= 0) {
 		pOut = &pVm->pResultSet[i];
 	} else {
-		sqlError(pVm->db, SQL_RANGE);
 		pOut = (Mem *) columnNullValue();
 	}
 	return pOut;
@@ -1027,20 +1026,17 @@ vdbeUnbind(Vdbe * p, int i)
 		return SQL_MISUSE;
 	}
 	if (p->magic != VDBE_MAGIC_RUN || p->pc >= 0) {
-		sqlError(p->db, SQL_MISUSE);
 		sql_log(SQL_MISUSE,
 			    "bind on a busy prepared statement: [%s]", p->zSql);
 		return SQL_MISUSE;
 	}
 	if (i < 1 || i > p->nVar) {
-		sqlError(p->db, SQL_RANGE);
 		return SQL_RANGE;
 	}
 	i--;
 	pVar = &p->aVar[i];
 	sqlVdbeMemRelease(pVar);
 	pVar->flags = MEM_Null;
-	sqlError(p->db, SQL_OK);
 
 	/* If the bit corresponding to this variable in Vdbe.expmask is set, then
 	 * binding a new value to this variable invalidates the current query plan.
@@ -1126,7 +1122,6 @@ bindText(sql_stmt * pStmt,	/* The statement to bind against */
 			rc = sqlVdbeMemSetStr(pVar, zData, nData, 1, xDel);
 			if (rc == SQL_OK)
 				rc = sql_bind_type(p, i, "TEXT");
-			sqlError(p->db, rc);
 			rc = sqlApiExit(p->db, rc);
 		}
 	} else if (xDel != SQL_STATIC && xDel != SQL_TRANSIENT) {
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index ae1f38f..697dffd 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -2364,23 +2364,6 @@ sqlVdbeResetStepResult(Vdbe * p)
 }
 
 /*
- * Copy the error code and error message belonging to the VDBE passed
- * as the first argument to its database handle (so that they will be
- * returned by calls to sql_errcode() and sql_errmsg()).
- *
- * This function does not clear the VDBE error code or message, just
- * copies them to the database handle.
- */
-int
-sqlVdbeTransferError(Vdbe * p)
-{
-	sql *db = p->db;
-	int rc = p->rc;
-	sqlError(db, rc);
-	return rc;
-}
-
-/*
  * Clean up a VDBE after execution but do not delete the VDBE just yet.
  * Return the result code.
  *
@@ -2409,15 +2392,17 @@ sqlVdbeReset(Vdbe * p)
 	 * instructions yet, leave the main database error information unchanged.
 	 */
 	if (p->pc >= 0) {
-		sqlVdbeTransferError(p);
 		if (p->runOnlyOnce)
 			p->expired = 1;
-	} else if (p->rc && p->expired) {
-		/* The expired flag was set on the VDBE before the first call
-		 * to sql_step(). For consistency (since sql_step() was
-		 * called), set the database error in this case as well.
+	} else {
+		/*
+		 * An error should be thrown here if the expired
+		 * flag is set on the VDBE flag with the first
+		 * call to sql_step(). However, the expired flag
+		 * is currently disabled, so this error has been
+		 * replaced with assert.
 		 */
-		sqlErrorWithMsg(db, p->rc, NULL);
+		assert(p->rc == 0 || p->expired == 0);
 	}
 
 	/* Reclaim all memory used by the VDBE
diff --git a/test/sql/func-recreate.result b/test/sql/func-recreate.result
index d713292..73fb03c 100644
--- a/test/sql/func-recreate.result
+++ b/test/sql/func-recreate.result
@@ -26,7 +26,8 @@ fiber.sleep(0.1)
 ...
 box.internal.sql_create_function('WAITFOR', 'INT', function (n) require('fiber').sleep(n) return n end)
 ---
-- error: database is locked
+- error: 'Failed to create function ''WAITFOR'': unable to create function due to
+    active statements'
 ...
 ch:get()
 ---
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 05/28] sql: remove unused functions of SQL error system
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (3 preceding siblings ...)
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 04/28] sql: remove sqlError() and remove sqlErrorWithMsg() imeevma
@ 2019-06-10 13:56 ` imeevma
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 06/28] sql: disable lookaside system imeevma
                   ` (26 subsequent siblings)
  31 siblings, 0 replies; 56+ messages in thread
From: imeevma @ 2019-06-10 13:56 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

These functions are not currently used and should be removed.
---
 src/box/sql.c              |  7 ----
 src/box/sql/global.c       |  3 --
 src/box/sql/legacy.c       |  3 +-
 src/box/sql/main.c         | 34 -------------------
 src/box/sql/prepare.c      |  4 +--
 src/box/sql/sqlInt.h       | 13 --------
 src/box/sql/tarantoolInt.h |  3 --
 src/box/sql/util.c         | 81 ----------------------------------------------
 src/box/sql/vdbeapi.c      | 40 ++---------------------
 src/box/sql/vdbesort.c     | 11 ++-----
 10 files changed, 8 insertions(+), 191 deletions(-)

diff --git a/src/box/sql.c b/src/box/sql.c
index f2ef5b3..ae92ba0 100644
--- a/src/box/sql.c
+++ b/src/box/sql.c
@@ -155,13 +155,6 @@ cursor_seek(BtCursor *pCur, int *pRes);
 static int
 cursor_advance(BtCursor *pCur, int *pRes);
 
-const char *tarantoolErrorMessage()
-{
-	if (diag_is_empty(&fiber()->diag))
-		return NULL;
-	return box_error_message(box_error_last());
-}
-
 const void *tarantoolsqlPayloadFetch(BtCursor *pCur, u32 *pAmt)
 {
 	assert(pCur->curFlags & BTCF_TaCursor ||
diff --git a/src/box/sql/global.c b/src/box/sql/global.c
index 9af671a..e394db8 100644
--- a/src/box/sql/global.c
+++ b/src/box/sql/global.c
@@ -204,9 +204,6 @@ SQL_WSD struct sqlConfig sqlConfig = {
 	0,			/* xVdbeBranch */
 	0,			/* pVbeBranchArg */
 #endif
-#ifndef SQL_UNTESTABLE
-	0,			/* xTestCallback */
-#endif
 	0,			/* bLocaltimeFault */
 	0x7ffffffe		/* iOnceResetThreshold */
 };
diff --git a/src/box/sql/legacy.c b/src/box/sql/legacy.c
index d519991..1a3804e 100644
--- a/src/box/sql/legacy.c
+++ b/src/box/sql/legacy.c
@@ -64,8 +64,7 @@ sql_exec(sql * db,	/* The database on which the SQL executes */
 	char **azCols = 0;	/* Names of result columns */
 	int callbackIsInit;	/* True if callback data is initialized */
 
-	if (!sqlSafetyCheckOk(db))
-		return SQL_MISUSE;
+	assert(db != NULL);
 	if (zSql == 0)
 		zSql = "";
 
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index f35c84f..450f7d1 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -302,40 +302,6 @@ sqlRollbackAll(Vdbe * pVdbe)
 }
 
 /*
- * Return a static string that describes the kind of error specified in the
- * argument.
- */
-const char *
-sqlErrStr(int rc)
-{
-	static const char *const aMsg[] = {
-		/* SQL_OK          */ "not an error",
-		/* SQL_ERROR       */ "SQL logic error or missing database",
-		/* SQL_PERM        */ "access permission denied",
-		/* SQL_ABORT       */ "callback requested query abort",
-		/* SQL_BUSY        */ "database is locked",
-		/* SQL_LOCKED      */ "database table is locked",
-		/* SQL_NOMEM       */ "out of memory",
-		/* SQL_IOERR       */ "disk I/O error",
-		/* SQL_NOTFOUND    */ "unknown operation",
-		/* SQL_FULL        */ "database or disk is full",
-		/* SQL_CANTOPEN    */ "unable to open database file",
-		/* SQL_SCHEMA      */ "database schema has changed",
-		/* SQL_TOOBIG      */ "string or blob too big",
-		/* SQL_CONSTRAINT  */ "constraint failed",
-		/* SQL_MISUSE      */
-		    "library routine called out of sequence",
-		/* SQL_RANGE       */ "bind or column index out of range",
-		/* SQL_TARANTOOL_ERROR */ "SQL-/Tarantool error",
-	};
-	const char *zErr = "unknown error";
-	rc &= 0xff;
-	if (ALWAYS(rc >= 0) && rc < ArraySize(aMsg) && aMsg[rc] != 0)
-		zErr = aMsg[rc];
-	return zErr;
-}
-
-/*
  * This function is exactly the same as sql_create_function(), except
  * that it is designed to be called by internal code. The difference is
  * that if a malloc() fails in sql_create_function(), an error code
diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index e692be0..2b3ac29 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -193,9 +193,7 @@ sqlLockAndPrepare(sql * db,		/* Database handle. */
 	int rc;
 
 	*ppStmt = 0;
-	if (!sqlSafetyCheckOk(db) || zSql == 0) {
-		return SQL_MISUSE;
-	}
+	assert(zSql != NULL && db != NULL);
 	rc = sqlPrepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt,
 			    pzTail);
 	if (rc == SQL_SCHEMA) {
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 2b7aa8b..7c00990 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -2908,9 +2908,6 @@ struct sqlConfig {
 	void (*xVdbeBranch) (void *, int iSrcLine, u8 eThis, u8 eMx);	/* Callback */
 	void *pVdbeBranchArg;	/* 1st argument */
 #endif
-#ifndef SQL_UNTESTABLE
-	int (*xTestCallback) (int);	/* Invoked by sqlFaultSim() */
-#endif
 	int bLocaltimeFault;	/* True to fail localtime() calls */
 	int iOnceResetThreshold;	/* When to reset OP_Once counters */
 };
@@ -3369,12 +3366,6 @@ int
 vdbe_emit_open_cursor(struct Parse *parse, int cursor, int index_id,
 		      struct space *space);
 
-#ifdef SQL_UNTESTABLE
-#define sqlFaultSim(X) SQL_OK
-#else
-int sqlFaultSim(int);
-#endif
-
 /**
  * The parser calls this routine in order to create a new VIEW.
  *
@@ -3936,8 +3927,6 @@ FuncDef *sqlFindFunction(sql *, const char *, int, u8);
 void sqlRegisterBuiltinFunctions(void);
 void sqlRegisterDateTimeFunctions(void);
 void sqlRegisterPerConnectionBuiltinFunctions(sql *);
-int sqlSafetyCheckOk(sql *);
-int sqlSafetyCheckSickOrOk(sql *);
 
 /**
  * Evaluate a view and store its result in an ephemeral table.
@@ -4460,8 +4449,6 @@ sql_dec_or_hex_to_i64(const char *z, int64_t *val);
 void *sqlHexToBlob(sql *, const char *z, int n);
 u8 sqlHexToInt(int h);
 
-const char *sqlErrStr(int);
-
 /**
  * Return the collation sequence for the expression pExpr. If
  * there is no defined collating sequence, return NULL.
diff --git a/src/box/sql/tarantoolInt.h b/src/box/sql/tarantoolInt.h
index f688a02..375a8cc 100644
--- a/src/box/sql/tarantoolInt.h
+++ b/src/box/sql/tarantoolInt.h
@@ -10,9 +10,6 @@
 
 struct fk_constraint_def;
 
-/* Misc */
-const char *tarantoolErrorMessage();
-
 /* Storage interface. */
 const void *tarantoolsqlPayloadFetch(BtCursor * pCur, u32 * pAmt);
 
diff --git a/src/box/sql/util.c b/src/box/sql/util.c
index d5f6447..713e535 100644
--- a/src/box/sql/util.c
+++ b/src/box/sql/util.c
@@ -58,26 +58,6 @@ sqlCoverage(int x)
 #endif
 
 /*
- * Give a callback to the test harness that can be used to simulate faults
- * in places where it is difficult or expensive to do so purely by means
- * of inputs.
- *
- * The intent of the integer argument is to let the fault simulator know
- * which of multiple sqlFaultSim() calls has been hit.
- *
- * Return whatever integer value the test callback returns, or return
- * SQL_OK if no test callback is installed.
- */
-#ifndef SQL_UNTESTABLE
-int
-   sqlFaultSim(int iTest)
-{
-	int (*xCallback) (int) = sqlGlobalConfig.xTestCallback;
-	return xCallback ? xCallback(iTest) : SQL_OK;
-}
-#endif
-
-/*
  * Return true if the floating point value is Not a Number (NaN).
  *
  * Use the math library isnan() function if compiled with SQL_HAVE_ISNAN.
@@ -1131,67 +1111,6 @@ sqlHexToBlob(sql * db, const char *z, int n)
 #endif				/* !SQL_OMIT_BLOB_LITERAL || SQL_HAS_CODEC */
 
 /*
- * Log an error that is an API call on a connection pointer that should
- * not have been used.  The "type" of connection pointer is given as the
- * argument.  The zType is a word like "NULL" or "closed" or "invalid".
- */
-static void
-logBadConnection(const char *zType)
-{
-	sql_log(SQL_MISUSE,
-		    "API call with %s database connection pointer", zType);
-}
-
-/*
- * Check to make sure we have a valid db pointer.  This test is not
- * foolproof but it does provide some measure of protection against
- * misuse of the interface such as passing in db pointers that are
- * NULL or which have been previously closed.  If this routine returns
- * 1 it means that the db pointer is valid and 0 if it should not be
- * dereferenced for any reason.  The calling function should invoke
- * SQL_MISUSE immediately.
- *
- * sqlSafetyCheckOk() requires that the db pointer be valid for
- * use.  sqlSafetyCheckSickOrOk() allows a db pointer that failed to
- * open properly and is not fit for general use but which can be
- * used as an argument to sql_errmsg() or sql_close().
- */
-int
-sqlSafetyCheckOk(sql * db)
-{
-	u32 magic;
-	if (db == 0) {
-		logBadConnection("NULL");
-		return 0;
-	}
-	magic = db->magic;
-	if (magic != SQL_MAGIC_OPEN) {
-		if (sqlSafetyCheckSickOrOk(db)) {
-			testcase(sqlGlobalConfig.xLog != 0);
-			logBadConnection("unopened");
-		}
-		return 0;
-	} else {
-		return 1;
-	}
-}
-
-int
-sqlSafetyCheckSickOrOk(sql * db)
-{
-	u32 magic;
-	magic = db->magic;
-	if (magic != SQL_MAGIC_SICK &&
-	    magic != SQL_MAGIC_OPEN && magic != SQL_MAGIC_BUSY) {
-		testcase(sqlGlobalConfig.xLog != 0);
-		logBadConnection("invalid");
-		return 0;
-	} else {
-		return 1;
-	}
-}
-
-/*
  * Attempt to add, substract, or multiply the 64-bit signed value iB against
  * the other 64-bit signed integer at *pA and store the result in *pA.
  * Return 0 on success.  Or if the operation would have resulted in an
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index c151a52..d52fc21 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -37,35 +37,6 @@
 #include "sqlInt.h"
 #include "vdbeInt.h"
 
-/*
- * Check on a Vdbe to make sure it has not been finalized.  Log
- * an error and return true if it has been finalized (or is otherwise
- * invalid).  Return false if it is ok.
- */
-static int
-vdbeSafety(Vdbe * p)
-{
-	if (p->db == 0) {
-		sql_log(SQL_MISUSE,
-			    "API called with finalized prepared statement");
-		return 1;
-	} else {
-		return 0;
-	}
-}
-
-static int
-vdbeSafetyNotNull(Vdbe * p)
-{
-	if (p == 0) {
-		sql_log(SQL_MISUSE,
-			    "API called with NULL prepared statement");
-		return 1;
-	} else {
-		return vdbeSafety(p);
-	}
-}
-
 #ifndef SQL_OMIT_TRACE
 /*
  * Invoke the profile callback.  This routine is only called if we already
@@ -120,8 +91,7 @@ sql_finalize(sql_stmt * pStmt)
 	} else {
 		Vdbe *v = (Vdbe *) pStmt;
 		sql *db = v->db;
-		if (vdbeSafety(v))
-			return SQL_MISUSE;
+		assert(db != NULL);
 		checkProfileCallback(db, v);
 		rc = sqlVdbeFinalize(v);
 		rc = sqlApiExit(db, rc);
@@ -541,9 +511,7 @@ sql_step(sql_stmt * pStmt)
 	Vdbe *v = (Vdbe *) pStmt;	/* the prepared statement */
 	int cnt = 0;		/* Counter to prevent infinite loop of reprepares */
 
-	if (vdbeSafetyNotNull(v)) {
-		return SQL_MISUSE;
-	}
+	assert(v != NULL);
 	v->doingRerun = 0;
 	while ((rc = sqlStep(v)) == SQL_SCHEMA
 	       && cnt++ < SQL_MAX_SCHEMA_RETRY) {
@@ -1022,9 +990,7 @@ static int
 vdbeUnbind(Vdbe * p, int i)
 {
 	Mem *pVar;
-	if (vdbeSafetyNotNull(p)) {
-		return SQL_MISUSE;
-	}
+	assert(p != NULL);
 	if (p->magic != VDBE_MAGIC_RUN || p->pc >= 0) {
 		sql_log(SQL_MISUSE,
 			    "bind on a busy prepared statement: [%s]", p->zSql);
diff --git a/src/box/sql/vdbesort.c b/src/box/sql/vdbesort.c
index 779e832..da9ee3e 100644
--- a/src/box/sql/vdbesort.c
+++ b/src/box/sql/vdbesort.c
@@ -679,8 +679,6 @@ vdbePmaReaderSeek(SortSubtask * pTask,	/* Task context */
 
 	assert(pReadr->pIncr == 0 || pReadr->pIncr->bEof == 0);
 
-	if (sqlFaultSim(201))
-		return SQL_IOERR_READ;
 	if (pReadr->aMap) {
 		sqlOsUnfetch(pReadr->pFd, 0, pReadr->aMap);
 		pReadr->aMap = 0;
@@ -1105,8 +1103,7 @@ vdbeMergeEngineNew(int nReader)
 		N += N;
 	nByte = sizeof(MergeEngine) + N * (sizeof(int) + sizeof(PmaReader));
 
-	pNew =
-	    sqlFaultSim(100) ? 0 : (MergeEngine *) sqlMallocZero(nByte);
+	pNew = (MergeEngine *) sqlMallocZero(nByte);
 	if (pNew) {
 		pNew->nTree = N;
 		pNew->pTask = 0;
@@ -1243,8 +1240,6 @@ vdbeSorterOpenTempFile(sql * db,	/* Database handle doing sort */
 		       sql_file ** ppFd)
 {
 	int rc;
-	if (sqlFaultSim(202))
-		return SQL_IOERR_ACCESS;
 	rc = sqlOsOpenMalloc(db->pVfs, 0, ppFd,
 				 SQL_OPEN_READWRITE | SQL_OPEN_CREATE |
 				 SQL_OPEN_EXCLUSIVE |
@@ -2001,8 +1996,8 @@ vdbeIncrMergerNew(SortSubtask * pTask,	/* The thread that will be using the new
     )
 {
 	int rc = SQL_OK;
-	IncrMerger *pIncr = *ppOut = (IncrMerger *)
-	    (sqlFaultSim(100) ? 0 : sqlMallocZero(sizeof(*pIncr)));
+	IncrMerger *pIncr = *ppOut =
+		(IncrMerger *) sqlMallocZero(sizeof(*pIncr));
 	if (pIncr) {
 		pIncr->pMerger = pMerger;
 		pIncr->pTask = pTask;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 06/28] sql: disable lookaside system
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (4 preceding siblings ...)
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 05/28] sql: remove unused functions of SQL error system imeevma
@ 2019-06-10 13:56 ` imeevma
  2019-06-13 22:25   ` [tarantool-patches] " Vladislav Shpilevoy
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 07/28] sql: remove SQL_OK error/status code imeevma
                   ` (25 subsequent siblings)
  31 siblings, 1 reply; 56+ messages in thread
From: imeevma @ 2019-06-10 13:56 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Since the lookaside system is not currently in use, it must be
completely disabled.
---
 src/box/sql/main.c      |  76 ------------------------------
 src/box/sql/malloc.c    | 123 ++++--------------------------------------------
 src/box/sql/printf.c    |   2 +-
 src/box/sql/sqlInt.h    |  44 +----------------
 src/box/sql/vdbeaux.c   |   2 +-
 src/box/sql/vdbemem.c   |   9 ++--
 src/box/sql/whereexpr.c |   3 +-
 7 files changed, 17 insertions(+), 242 deletions(-)

diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index 450f7d1..29a7911 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -173,78 +173,6 @@ sql_initialize(void)
 	return rc;
 }
 
-/*
- * Set up the lookaside buffers for a database connection.
- * Return SQL_OK on success.
- * If lookaside is already active, return SQL_BUSY.
- *
- * The sz parameter is the number of bytes in each lookaside slot.
- * The cnt parameter is the number of slots.  If pStart is NULL the
- * space for the lookaside memory is obtained from sql_malloc().
- * If pStart is not NULL then it is sz*cnt bytes of memory to use for
- * the lookaside memory.
- */
-static int
-setupLookaside(sql * db, void *pBuf, int sz, int cnt)
-{
-#ifndef SQL_OMIT_LOOKASIDE
-	void *pStart;
-	if (db->lookaside.nOut) {
-		return SQL_BUSY;
-	}
-	/* Free any existing lookaside buffer for this handle before
-	 * allocating a new one so we don't have to have space for
-	 * both at the same time.
-	 */
-	if (db->lookaside.bMalloced) {
-		sql_free(db->lookaside.pStart);
-	}
-	/* The size of a lookaside slot after ROUNDDOWN8 needs to be larger
-	 * than a pointer to be useful.
-	 */
-	sz = ROUNDDOWN8(sz);	/* IMP: R-33038-09382 */
-	if (sz <= (int)sizeof(LookasideSlot *))
-		sz = 0;
-	if (cnt < 0)
-		cnt = 0;
-	if (sz == 0 || cnt == 0) {
-		sz = 0;
-		pStart = 0;
-	} else if (pBuf == 0) {
-		sqlBeginBenignMalloc();
-		pStart = sqlMalloc(sz * cnt);	/* IMP: R-61949-35727 */
-		sqlEndBenignMalloc();
-		if (pStart)
-			cnt = sqlMallocSize(pStart) / sz;
-	} else {
-		pStart = pBuf;
-	}
-	db->lookaside.pStart = pStart;
-	db->lookaside.pFree = 0;
-	db->lookaside.sz = (u16) sz;
-	if (pStart) {
-		int i;
-		LookasideSlot *p;
-		assert(sz > (int)sizeof(LookasideSlot *));
-		p = (LookasideSlot *) pStart;
-		for (i = cnt - 1; i >= 0; i--) {
-			p->pNext = db->lookaside.pFree;
-			db->lookaside.pFree = p;
-			p = (LookasideSlot *) & ((u8 *) p)[sz];
-		}
-		db->lookaside.pEnd = p;
-		db->lookaside.bDisable = 0;
-		db->lookaside.bMalloced = pBuf == 0 ? 1 : 0;
-	} else {
-		db->lookaside.pStart = db;
-		db->lookaside.pEnd = db;
-		db->lookaside.bDisable = 1;
-		db->lookaside.bMalloced = 0;
-	}
-#endif				/* SQL_OMIT_LOOKASIDE */
-	return SQL_OK;
-}
-
 void
 sql_row_count(struct sql_context *context, MAYBE_UNUSED int unused1,
 	      MAYBE_UNUSED sql_value **unused2)
@@ -630,10 +558,6 @@ sql_init_db(sql **out_db)
 	 */
 	sqlRegisterPerConnectionBuiltinFunctions(db);
 
-	/* Enable the lookaside-malloc subsystem */
-	setupLookaside(db, 0, sqlGlobalConfig.szLookaside,
-		       sqlGlobalConfig.nLookaside);
-
 opendb_out:
 	assert(db != 0 || rc == SQL_NOMEM);
 	if (rc == SQL_NOMEM)
diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index 925ffb2..a7549db 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -412,7 +412,6 @@ sqlScratchMalloc(int n)
 			sqlStatusUp(SQL_STATUS_SCRATCH_OVERFLOW,
 					sqlMallocSize(p));
 		}
-		sqlMemdebugSetType(p, MEMTYPE_SCRATCH);
 	}
 
 #if !defined(NDEBUG)
@@ -457,10 +456,6 @@ sqlScratchFree(void *p)
 			sqlStatusDown(SQL_STATUS_SCRATCH_USED, 1);
 		} else {
 			/* Release memory back to the heap */
-			assert(sqlMemdebugHasType(p, MEMTYPE_SCRATCH));
-			assert(sqlMemdebugNoType
-			       (p, (u8) ~ MEMTYPE_SCRATCH));
-			sqlMemdebugSetType(p, MEMTYPE_HEAP);
 			if (sqlGlobalConfig.bMemstat) {
 				int iSize = sqlMallocSize(p);
 				sqlStatusDown
@@ -477,55 +472,25 @@ sqlScratchFree(void *p)
 }
 
 /*
- * TRUE if p is a lookaside memory allocation from db
- */
-#ifndef SQL_OMIT_LOOKASIDE
-static int
-isLookaside(sql * db, void *p)
-{
-	return SQL_WITHIN(p, db->lookaside.pStart, db->lookaside.pEnd);
-}
-#else
-#define isLookaside(A,B) 0
-#endif
-
-/*
  * Return the size of a memory allocation previously obtained from
  * sqlMalloc() or sql_malloc().
  */
 int
 sqlMallocSize(void *p)
 {
-	assert(sqlMemdebugHasType(p, MEMTYPE_HEAP));
 	return sql_sized_sizeof(p);
 }
 
 int
-sqlDbMallocSize(sql * db, void *p)
+sqlDbMallocSize(void *p)
 {
 	assert(p != 0);
-	if (db == 0 || !isLookaside(db, p)) {
-#if SQL_DEBUG
-		if (db == 0) {
-			assert(sqlMemdebugNoType(p, (u8) ~ MEMTYPE_HEAP));
-			assert(sqlMemdebugHasType(p, MEMTYPE_HEAP));
-		} else {
-			assert(sqlMemdebugHasType
-			       (p, (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP)));
-			assert(sqlMemdebugNoType
-			       (p, (u8) ~ (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP)));
-		}
-#endif
-		return sql_sized_sizeof(p);
-	} else
-		return db->lookaside.sz;
+	return sql_sized_sizeof(p);
 }
 
 sql_uint64
 sql_msize(void *p)
 {
-	assert(sqlMemdebugNoType(p, (u8) ~ MEMTYPE_HEAP));
-	assert(sqlMemdebugHasType(p, MEMTYPE_HEAP));
 	return p ? sql_sized_sizeof(p) : 0;
 }
 
@@ -537,8 +502,6 @@ sql_free(void *p)
 {
 	if (p == 0)
 		return;		/* IMP: R-49053-54554 */
-	assert(sqlMemdebugHasType(p, MEMTYPE_HEAP));
-	assert(sqlMemdebugNoType(p, (u8) ~ MEMTYPE_HEAP));
 	if (sqlGlobalConfig.bMemstat) {
 		sqlStatusDown(SQL_STATUS_MEMORY_USED,
 				  sqlMallocSize(p));
@@ -555,7 +518,7 @@ sql_free(void *p)
 static SQL_NOINLINE void
 measureAllocationSize(sql * db, void *p)
 {
-	*db->pnBytesFreed += sqlDbMallocSize(db, p);
+	*db->pnBytesFreed += sqlDbMallocSize(p);
 }
 
 /*
@@ -572,23 +535,7 @@ sqlDbFree(sql * db, void *p)
 			measureAllocationSize(db, p);
 			return;
 		}
-		if (isLookaside(db, p)) {
-			LookasideSlot *pBuf = (LookasideSlot *) p;
-#if SQL_DEBUG
-			/* Trash all content in the buffer being freed */
-			memset(p, 0xaa, db->lookaside.sz);
-#endif
-			pBuf->pNext = db->lookaside.pFree;
-			db->lookaside.pFree = pBuf;
-			db->lookaside.nOut--;
-			return;
-		}
 	}
-	assert(sqlMemdebugHasType(p, (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP)));
-	assert(sqlMemdebugNoType
-	       (p, (u8) ~ (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP)));
-	assert(db != 0 || sqlMemdebugNoType(p, MEMTYPE_LOOKASIDE));
-	sqlMemdebugSetType(p, MEMTYPE_HEAP);
 	sql_free(p);
 }
 
@@ -600,8 +547,6 @@ sqlRealloc(void *pOld, u64 nBytes)
 {
 	int nOld, nNew, nDiff;
 	void *pNew;
-	assert(sqlMemdebugHasType(pOld, MEMTYPE_HEAP));
-	assert(sqlMemdebugNoType(pOld, (u8) ~ MEMTYPE_HEAP));
 	if (pOld == 0) {
 		return sqlMalloc(nBytes);	/* IMP: R-04300-56712 */
 	}
@@ -698,9 +643,6 @@ dbMallocRawFinish(sql * db, u64 n)
 	p = sqlMalloc(n);
 	if (!p)
 		sqlOomFault(db);
-	sqlMemdebugSetType(p,
-			       (db->lookaside.bDisable ==
-				0) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP);
 	return p;
 }
 
@@ -733,42 +675,15 @@ sqlDbMallocRaw(sql * db, u64 n)
 	if (db)
 		return sqlDbMallocRawNN(db, n);
 	p = sqlMalloc(n);
-	sqlMemdebugSetType(p, MEMTYPE_HEAP);
 	return p;
 }
 
 void *
 sqlDbMallocRawNN(sql * db, u64 n)
 {
-#ifndef SQL_OMIT_LOOKASIDE
-	LookasideSlot *pBuf;
-	assert(db != 0);
-	assert(db->pnBytesFreed == 0);
-	if (db->lookaside.bDisable == 0) {
-		assert(db->mallocFailed == 0);
-		if (n > db->lookaside.sz) {
-			db->lookaside.anStat[1]++;
-		} else if ((pBuf = db->lookaside.pFree) == 0) {
-			db->lookaside.anStat[2]++;
-		} else {
-			db->lookaside.pFree = pBuf->pNext;
-			db->lookaside.nOut++;
-			db->lookaside.anStat[0]++;
-			if (db->lookaside.nOut > db->lookaside.mxOut) {
-				db->lookaside.mxOut = db->lookaside.nOut;
-			}
-			return (void *)pBuf;
-		}
-	} else if (db->mallocFailed) {
-		return 0;
-	}
-#else
-	assert(db != 0);
-	assert(db->pnBytesFreed == 0);
-	if (db->mallocFailed) {
-		return 0;
-	}
-#endif
+	assert(db != NULL && db->pnBytesFreed == NULL);
+	if (db->mallocFailed)
+		return NULL;
 	return dbMallocRawFinish(db, n);
 }
 
@@ -785,8 +700,6 @@ sqlDbRealloc(sql * db, void *p, u64 n)
 	assert(db != 0);
 	if (p == 0)
 		return sqlDbMallocRawNN(db, n);
-	if (isLookaside(db, p) && n <= db->lookaside.sz)
-		return p;
 	return dbReallocFinish(db, p, n);
 }
 
@@ -797,27 +710,9 @@ dbReallocFinish(sql * db, void *p, u64 n)
 	assert(db != 0);
 	assert(p != 0);
 	if (db->mallocFailed == 0) {
-		if (isLookaside(db, p)) {
-			pNew = sqlDbMallocRawNN(db, n);
-			if (pNew) {
-				memcpy(pNew, p, db->lookaside.sz);
-				sqlDbFree(db, p);
-			}
-		} else {
-			assert(sqlMemdebugHasType
-			       (p, (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP)));
-			assert(sqlMemdebugNoType
-			       (p, (u8) ~ (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP)));
-			sqlMemdebugSetType(p, MEMTYPE_HEAP);
-			pNew = sql_realloc64(p, n);
-			if (!pNew) {
-				sqlOomFault(db);
-			}
-			sqlMemdebugSetType(pNew,
-					       (db->lookaside.bDisable ==
-						0 ? MEMTYPE_LOOKASIDE :
-						MEMTYPE_HEAP));
-		}
+		pNew = sql_realloc64(p, n);
+		if (!pNew)
+			sqlOomFault(db);
 	}
 	return pNew;
 }
diff --git a/src/box/sql/printf.c b/src/box/sql/printf.c
index 31d21db..c364055 100644
--- a/src/box/sql/printf.c
+++ b/src/box/sql/printf.c
@@ -874,7 +874,7 @@ sqlStrAccumEnlarge(StrAccum * p, int N)
 			if (!isMalloced(p) && p->nChar > 0)
 				memcpy(zNew, p->zText, p->nChar);
 			p->zText = zNew;
-			p->nAlloc = sqlDbMallocSize(p->db, zNew);
+			p->nAlloc = sqlDbMallocSize(zNew);
 			p->printfFlags |= SQL_PRINTF_MALLOCED;
 		} else {
 			sqlStrAccumReset(p);
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 7c00990..d2e429e 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -3021,7 +3021,7 @@ void *sqlDbReallocOrFree(sql *, void *, u64);
 void *sqlDbRealloc(sql *, void *, u64);
 void sqlDbFree(sql *, void *);
 int sqlMallocSize(void *);
-int sqlDbMallocSize(sql *, void *);
+int sqlDbMallocSize(void *);
 void *sqlScratchMalloc(int);
 void sqlScratchFree(void *);
 void *sqlPageMalloc(int);
@@ -4946,48 +4946,6 @@ void sqlVdbeIOTraceSql(Vdbe *);
 #endif
 
 /*
- * These routines are available for the mem2.c debugging memory allocator
- * only.  They are used to verify that different "types" of memory
- * allocations are properly tracked by the system.
- *
- * sqlMemdebugSetType() sets the "type" of an allocation to one of
- * the MEMTYPE_* macros defined below.  The type must be a bitmask with
- * a single bit set.
- *
- * sqlMemdebugHasType() returns true if any of the bits in its second
- * argument match the type set by the previous sqlMemdebugSetType().
- * sqlMemdebugHasType() is intended for use inside assert() statements.
- *
- * sqlMemdebugNoType() returns true if none of the bits in its second
- * argument match the type set by the previous sqlMemdebugSetType().
- *
- * Perhaps the most important point is the difference between MEMTYPE_HEAP
- * and MEMTYPE_LOOKASIDE.  If an allocation is MEMTYPE_LOOKASIDE, that means
- * it might have been allocated by lookaside, except the allocation was
- * too large or lookaside was already full.  It is important to verify
- * that allocations that might have been satisfied by lookaside are not
- * passed back to non-lookaside free() routines.  Asserts such as the
- * example above are placed on the non-lookaside free() routines to verify
- * this constraint.
- *
- * All of this is no-op for a production build.  It only comes into
- * play when the sql_MEMDEBUG compile-time option is used.
- */
-#ifdef SQL_MEMDEBUG
-void sqlMemdebugSetType(void *, u8);
-int sqlMemdebugHasType(void *, u8);
-int sqlMemdebugNoType(void *, u8);
-#else
-#define sqlMemdebugSetType(X,Y)	/* no-op */
-#define sqlMemdebugHasType(X,Y)  1
-#define sqlMemdebugNoType(X,Y)   1
-#endif
-#define MEMTYPE_HEAP       0x01	/* General heap allocations */
-#define MEMTYPE_LOOKASIDE  0x02	/* Heap that might have been lookaside */
-#define MEMTYPE_SCRATCH    0x04	/* Scratch allocations */
-#define MEMTYPE_PCACHE     0x08	/* Page cache allocations */
-
-/*
  * Threading interface
  */
 #if SQL_MAX_WORKER_THREADS>0
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 697dffd..fbe5338 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -192,7 +192,7 @@ growOpArray(Vdbe * v, int nOp)
 	assert(nNew >= (p->nOpAlloc + nOp));
 	pNew = sqlDbRealloc(p->db, v->aOp, nNew * sizeof(Op));
 	if (pNew) {
-		p->szOpAlloc = sqlDbMallocSize(p->db, pNew);
+		p->szOpAlloc = sqlDbMallocSize(pNew);
 		p->nOpAlloc = p->szOpAlloc / sizeof(Op);
 		v->aOp = pNew;
 	}
diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
index 248f80b..2bb9bd3 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -70,7 +70,7 @@ sqlVdbeCheckMemInvariants(Mem * p)
 
 	/* The szMalloc field holds the correct memory allocation size */
 	assert(p->szMalloc == 0
-	       || p->szMalloc == sqlDbMallocSize(p->db, p->zMalloc));
+	       || p->szMalloc == sqlDbMallocSize(p->zMalloc));
 
 	/* If p holds a string or blob, the Mem.z must point to exactly
 	 * one of the following:
@@ -112,8 +112,7 @@ sqlVdbeMemGrow(Mem * pMem, int n, int bPreserve)
 	testcase(bPreserve && pMem->z == 0);
 
 	assert(pMem->szMalloc == 0
-	       || pMem->szMalloc == sqlDbMallocSize(pMem->db,
-							pMem->zMalloc));
+	       || pMem->szMalloc == sqlDbMallocSize(pMem->zMalloc));
 	if (pMem->szMalloc < n) {
 		if (n < 32)
 			n = 32;
@@ -133,7 +132,7 @@ sqlVdbeMemGrow(Mem * pMem, int n, int bPreserve)
 			return SQL_NOMEM;
 		} else {
 			pMem->szMalloc =
-			    sqlDbMallocSize(pMem->db, pMem->zMalloc);
+			    sqlDbMallocSize(pMem->zMalloc);
 		}
 	}
 
@@ -1007,7 +1006,7 @@ sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
 	} else if (xDel == SQL_DYNAMIC) {
 		sqlVdbeMemRelease(pMem);
 		pMem->zMalloc = pMem->z = (char *)z;
-		pMem->szMalloc = sqlDbMallocSize(pMem->db, pMem->zMalloc);
+		pMem->szMalloc = sqlDbMallocSize(pMem->zMalloc);
 	} else {
 		sqlVdbeMemRelease(pMem);
 		pMem->z = (char *)z;
diff --git a/src/box/sql/whereexpr.c b/src/box/sql/whereexpr.c
index 30017b0..a954b17 100644
--- a/src/box/sql/whereexpr.c
+++ b/src/box/sql/whereexpr.c
@@ -107,8 +107,7 @@ whereClauseInsert(WhereClause * pWC, Expr * p, u16 wtFlags)
 		if (pOld != pWC->aStatic) {
 			sqlDbFree(db, pOld);
 		}
-		pWC->nSlot =
-		    sqlDbMallocSize(db, pWC->a) / sizeof(pWC->a[0]);
+		pWC->nSlot = sqlDbMallocSize(pWC->a) / sizeof(pWC->a[0]);
 	}
 	pTerm = &pWC->a[idx = pWC->nTerm++];
 	if (p && ExprHasProperty(p, EP_Unlikely)) {
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 07/28] sql: remove SQL_OK error/status code
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (5 preceding siblings ...)
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 06/28] sql: disable lookaside system imeevma
@ 2019-06-10 13:56 ` imeevma
  2019-06-13 22:24   ` [tarantool-patches] " Vladislav Shpilevoy
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 08/28] sql: remove SQL_PERM, SQL_WARNING, SQL_ABORT errcodes imeevma
                   ` (24 subsequent siblings)
  31 siblings, 1 reply; 56+ messages in thread
From: imeevma @ 2019-06-10 13:56 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Removing this error/status code is part of getting rid of the SQL
error system.
---
 src/box/bind.c             |   2 +-
 src/box/ck_constraint.c    |   4 +-
 src/box/execute.c          |   6 +-
 src/box/sql.c              |  39 ++++-----
 src/box/sql/analyze.c      |   2 +-
 src/box/sql/cursor.c       |   4 +-
 src/box/sql/date.c         |  10 +--
 src/box/sql/expr.c         |   2 +-
 src/box/sql/func.c         |   6 +-
 src/box/sql/insert.c       |   2 +-
 src/box/sql/legacy.c       |  10 +--
 src/box/sql/main.c         |  26 +++---
 src/box/sql/os.c           |  10 +--
 src/box/sql/os_unix.c      |  96 ++++++++++-----------
 src/box/sql/prepare.c      |  16 ++--
 src/box/sql/select.c       |  26 +++---
 src/box/sql/sqlInt.h       |   8 +-
 src/box/sql/status.c       |   4 +-
 src/box/sql/tarantoolInt.h |   4 +-
 src/box/sql/trigger.c      |   2 +-
 src/box/sql/vdbe.c         |  58 ++++++-------
 src/box/sql/vdbeapi.c      |  38 ++++----
 src/box/sql/vdbeaux.c      |  50 +++++------
 src/box/sql/vdbemem.c      |  76 ++++++++--------
 src/box/sql/vdbesort.c     | 210 ++++++++++++++++++++++-----------------------
 src/box/sql/where.c        |  74 ++++++++--------
 26 files changed, 392 insertions(+), 393 deletions(-)

diff --git a/src/box/bind.c b/src/box/bind.c
index f159153..90d56d6 100644
--- a/src/box/bind.c
+++ b/src/box/bind.c
@@ -205,7 +205,7 @@ sql_bind_column(struct sql_stmt *stmt, const struct sql_bind *p,
 	default:
 		unreachable();
 	}
-	if (rc == SQL_OK)
+	if (rc == 0)
 		return 0;
 
 	switch (rc) {
diff --git a/src/box/ck_constraint.c b/src/box/ck_constraint.c
index 543c8b3..c54c870 100644
--- a/src/box/ck_constraint.c
+++ b/src/box/ck_constraint.c
@@ -172,7 +172,9 @@ ck_constraint_program_run(struct ck_constraint *ck_constraint,
 	 * Get VDBE execution state and reset VM to run it
 	 * next time.
 	 */
-	return sql_reset(ck_constraint->stmt) != SQL_OK ? -1 : 0;
+	if (sql_reset(ck_constraint->stmt) != 0)
+		return -1;
+	return 0;
 }
 
 void
diff --git a/src/box/execute.c b/src/box/execute.c
index e81cc32..64ed3d4 100644
--- a/src/box/execute.c
+++ b/src/box/execute.c
@@ -420,11 +420,11 @@ sql_execute(struct sql_stmt *stmt, struct port *port, struct region *region)
 					    port) != 0)
 				return -1;
 		}
-		assert(rc == SQL_DONE || rc != SQL_OK);
+		assert(rc == SQL_DONE || rc != 0);
 	} else {
 		/* No rows. Either DONE or ERROR. */
 		rc = sql_step(stmt);
-		assert(rc != SQL_ROW && rc != SQL_OK);
+		assert(rc != SQL_ROW && rc != 0);
 	}
 	if (rc != SQL_DONE)
 		return -1;
@@ -438,7 +438,7 @@ sql_prepare_and_execute(const char *sql, int len, const struct sql_bind *bind,
 {
 	struct sql_stmt *stmt;
 	struct sql *db = sql_get();
-	if (sql_prepare_v2(db, sql, len, &stmt, NULL) != SQL_OK)
+	if (sql_prepare_v2(db, sql, len, &stmt, NULL) != 0)
 		return -1;
 	assert(stmt != NULL);
 	port_sql_create(port, stmt);
diff --git a/src/box/sql.c b/src/box/sql.c
index ae92ba0..51f7b77 100644
--- a/src/box/sql.c
+++ b/src/box/sql.c
@@ -71,7 +71,7 @@ sql_init()
 
 	current_session()->sql_flags |= default_sql_flags;
 
-	if (sql_init_db(&db) != SQL_OK)
+	if (sql_init_db(&db) != 0)
 		panic("failed to initialize SQL subsystem");
 
 	assert(db != NULL);
@@ -86,7 +86,7 @@ sql_load_schema()
 	if (stat->def->field_count == 0)
 		return;
 	db->init.busy = 1;
-	if (sql_analysis_load(db) != SQL_OK) {
+	if (sql_analysis_load(db) != 0) {
 		if(!diag_is_empty(&fiber()->diag)) {
 			diag_log();
 		}
@@ -199,7 +199,7 @@ int tarantoolsqlNext(BtCursor *pCur, int *pRes)
 {
 	if (pCur->eState == CURSOR_INVALID) {
 		*pRes = 1;
-		return SQL_OK;
+		return 0;
 	}
 	assert(iterator_direction(pCur->iter_type) > 0);
 	return cursor_advance(pCur, pRes);
@@ -214,7 +214,7 @@ int tarantoolsqlPrevious(BtCursor *pCur, int *pRes)
 {
 	if (pCur->eState == CURSOR_INVALID) {
 		*pRes = 1;
-		return SQL_OK;
+		return 0;
 	}
 	assert(iterator_direction(pCur->iter_type) < 0);
 	return cursor_advance(pCur, pRes);
@@ -292,12 +292,11 @@ int tarantoolsqlMovetoUnpacked(BtCursor *pCur, UnpackedRecord *pIdxKey,
 }
 
 /*
- * Count number of tuples in ephemeral space and write it to pnEntry.
+ * Count number of tuples in ephemeral space.
  *
  * @param pCur Cursor which will point to ephemeral space.
- * @param[out] pnEntry Number of tuples in ephemeral space.
  *
- * @retval SQL_OK
+ * @retval Number of tuples in ephemeral space.
  */
 int64_t
 tarantoolsqlEphemeralCount(struct BtCursor *pCur)
@@ -385,7 +384,7 @@ int tarantoolsqlEphemeralInsert(struct space *space, const char *tuple,
 	mp_tuple_assert(tuple, tuple_end);
 	if (space_ephemeral_replace(space, tuple, tuple_end) != 0)
 		return SQL_TARANTOOL_ERROR;
-	return SQL_OK;
+	return 0;
 }
 
 /* Simply delete ephemeral space by calling space_delete(). */
@@ -395,7 +394,7 @@ int tarantoolsqlEphemeralDrop(BtCursor *pCur)
 	assert(pCur->curFlags & BTCF_TEphemCursor);
 	space_delete(pCur->space);
 	pCur->space = NULL;
-	return SQL_OK;
+	return 0;
 }
 
 static inline int
@@ -411,7 +410,7 @@ insertOrReplace(struct space *space, const char *tuple, const char *tuple_end,
 	request.type = type;
 	mp_tuple_assert(request.tuple, request.tuple_end);
 	int rc = box_process_rw(&request, space, NULL);
-	return rc == 0 ? SQL_OK : SQL_TARANTOOL_ERROR;
+	return rc == 0 ? 0 : SQL_TARANTOOL_ERROR;
 }
 
 int tarantoolsqlInsert(struct space *space, const char *tuple,
@@ -432,7 +431,7 @@ int tarantoolsqlReplace(struct space *space, const char *tuple,
  *
  * @param pCur Cursor pointing to ephemeral space.
  *
- * @retval SQL_OK on success, SQL_TARANTOOL_ERROR otherwise.
+ * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise.
  */
 int tarantoolsqlEphemeralDelete(BtCursor *pCur)
 {
@@ -453,7 +452,7 @@ int tarantoolsqlEphemeralDelete(BtCursor *pCur)
 		diag_log();
 		return SQL_TARANTOOL_ERROR;
 	}
-	return SQL_OK;
+	return 0;
 }
 
 int tarantoolsqlDelete(BtCursor *pCur, u8 flags)
@@ -476,7 +475,7 @@ int tarantoolsqlDelete(BtCursor *pCur, u8 flags)
 	rc = sql_delete_by_key(pCur->space, pCur->index->def->iid, key,
 			       key_size);
 
-	return rc == 0 ? SQL_OK : SQL_TARANTOOL_ERROR;
+	return rc == 0 ? 0 : SQL_TARANTOOL_ERROR;
 }
 
 int
@@ -494,7 +493,7 @@ sql_delete_by_key(struct space *space, uint32_t iid, char *key,
 	assert(space_index(space, iid)->def->opts.is_unique);
 	int rc = box_process_rw(&request, space, &unused);
 
-	return rc == 0 ? SQL_OK : SQL_TARANTOOL_ERROR;
+	return rc == 0 ? 0 : SQL_TARANTOOL_ERROR;
 }
 
 /*
@@ -504,7 +503,7 @@ sql_delete_by_key(struct space *space, uint32_t iid, char *key,
  *
  * @param pCur Cursor pointing to ephemeral space.
  *
- * @retval SQL_OK on success, SQL_TARANTOOL_ERROR otherwise.
+ * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise.
  */
 int tarantoolsqlEphemeralClearTable(BtCursor *pCur)
 {
@@ -533,7 +532,7 @@ int tarantoolsqlEphemeralClearTable(BtCursor *pCur)
 	}
 	iterator_delete(it);
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -569,7 +568,7 @@ int tarantoolsqlClearTable(struct space *space, uint32_t *tuple_count)
 	}
 	iterator_delete(iter);
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -849,7 +848,7 @@ key_alloc(BtCursor *cur, size_t key_size)
  * @param key Start of buffer containing key.
  * @param key_end End of buffer containing key.
  *
- * @retval SQL_OK on success, SQL_TARANTOOL_ERROR otherwise.
+ * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise.
  */
 static int
 cursor_seek(BtCursor *pCur, int *pRes)
@@ -895,7 +894,7 @@ cursor_seek(BtCursor *pCur, int *pRes)
  * @param pCur Cursor which contains space and tuple.
  * @param[out] pRes Flag which is 0 if reached end of space, 1 otherwise.
  *
- * @retval SQL_OK on success, SQL_TARANTOOL_ERROR otherwise.
+ * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise.
  */
 static int
 cursor_advance(BtCursor *pCur, int *pRes)
@@ -915,7 +914,7 @@ cursor_advance(BtCursor *pCur, int *pRes)
 		*pRes = 1;
 	}
 	pCur->last_tuple = tuple;
-	return SQL_OK;
+	return 0;
 }
 
 /*********************************************************************
diff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c
index 4106bce..410d9e8 100644
--- a/src/box/sql/analyze.c
+++ b/src/box/sql/analyze.c
@@ -1518,7 +1518,7 @@ load_stat_from_space(struct sql *db, const char *sql_select_prepare,
 		stats[current_idx_count].sample_count++;
 	}
 	rc = sql_finalize(stmt);
-	if (rc == SQL_OK && prev_index != NULL)
+	if (rc == 0 && prev_index != NULL)
 		init_avg_eq(prev_index, &stats[current_idx_count]);
 	assert(current_idx_count <= index_count);
 	for (uint32_t i = 0; i < current_idx_count; ++i) {
diff --git a/src/box/sql/cursor.c b/src/box/sql/cursor.c
index 2187b90..f4b19db 100644
--- a/src/box/sql/cursor.c
+++ b/src/box/sql/cursor.c
@@ -94,7 +94,7 @@ sqlCursorIsValidNN(BtCursor *pCur)
  * For sqlCursorPayload(), the caller must ensure that pCur is pointing
  * to a valid row in the table.
  *
- * Return SQL_OK on success or an error code if anything goes
+ * Return 0 on success or an error code if anything goes
  * wrong.  An error is returned if "offset+amt" is larger than
  * the available payload.
  */
@@ -110,7 +110,7 @@ sqlCursorPayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf)
 	pPayload = tarantoolsqlPayloadFetch(pCur, &sz);
 	assert((uptr) (offset + amt) <= sz);
 	memcpy(pBuf, pPayload + offset, amt);
-	return SQL_OK;
+	return 0;
 }
 
 /* Move the cursor so that it points to an entry near the key
diff --git a/src/box/sql/date.c b/src/box/sql/date.c
index 6d3a2b0..e193035 100644
--- a/src/box/sql/date.c
+++ b/src/box/sql/date.c
@@ -576,7 +576,7 @@ osLocaltime(time_t * t, struct tm *pTm)
 /*
  * Compute the difference (in milliseconds) between localtime and UTC
  * (a.k.a. GMT) for the time value p where p is in UTC. If no error occurs,
- * return this value and set *pRc to SQL_OK.
+ * return this value and set *pRc to 0.
  *
  * Or, if an error does occur, set *pRc to SQL_ERROR. The returned value
  * is undefined in this case.
@@ -584,7 +584,7 @@ osLocaltime(time_t * t, struct tm *pTm)
 static sql_int64
 localtimeOffset(DateTime * p,	/* Date at which to calculate offset */
 		sql_context * pCtx,	/* Write error here if one occurs */
-		int *pRc	/* OUT: Error code. SQL_OK or ERROR */
+		int *pRc	/* OUT: Error code. 0 or ERROR */
     )
 {
 	DateTime x, y;
@@ -635,7 +635,7 @@ localtimeOffset(DateTime * p,	/* Date at which to calculate offset */
 	y.validTZ = 0;
 	y.isError = 0;
 	computeJD(&y);
-	*pRc = SQL_OK;
+	*pRc = 0;
 	return y.iJD - x.iJD;
 }
 #endif				/* SQL_OMIT_LOCALTIME */
@@ -736,7 +736,7 @@ parseModifier(sql_context * pCtx,	/* Function context */
 					sql_int64 c1;
 					computeJD(p);
 					c1 = localtimeOffset(p, pCtx, &rc);
-					if (rc == SQL_OK) {
+					if (rc == 0) {
 						p->iJD -= c1;
 						clearYMD_HMS_TZ(p);
 						p->iJD +=
@@ -746,7 +746,7 @@ parseModifier(sql_context * pCtx,	/* Function context */
 					}
 					p->tzSet = 1;
 				} else {
-					rc = SQL_OK;
+					rc = 0;
 				}
 			}
 #endif
diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c
index 694edea..054c516 100644
--- a/src/box/sql/expr.c
+++ b/src/box/sql/expr.c
@@ -4387,7 +4387,7 @@ sqlExprCodeTarget(Parse * pParse, Expr * pExpr, int target)
 		}
 		assert(!ExprHasProperty(pExpr, EP_IntValue));
 		if (pExpr->on_conflict_action == ON_CONFLICT_ACTION_IGNORE) {
-			sqlVdbeAddOp4(v, OP_Halt, SQL_OK,
+			sqlVdbeAddOp4(v, OP_Halt, 0,
 					  ON_CONFLICT_ACTION_IGNORE, 0,
 					  pExpr->u.zToken, 0);
 		} else {
diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 593aa94..29712e0 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -1191,7 +1191,7 @@ zeroblobFunc(sql_context * context, int argc, sql_value ** argv)
 	n = sql_value_int64(argv[0]);
 	if (n < 0)
 		n = 0;
-	if (sql_result_zeroblob64(context, n) != SQL_OK) {
+	if (sql_result_zeroblob64(context, n) != 0) {
 		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob too big");
 		context->is_aborted = true;
 	}
@@ -1799,7 +1799,7 @@ static inline int
 sql_overload_function(sql * db, const char *zName,
 			  enum field_type type, int nArg)
 {
-	int rc = SQL_OK;
+	int rc = 0;
 
 	if (sqlFindFunction(db, zName, nArg, 0) == 0) {
 		rc = sqlCreateFunc(db, zName, type, nArg, 0, 0,
@@ -1818,7 +1818,7 @@ void
 sqlRegisterPerConnectionBuiltinFunctions(sql * db)
 {
 	int rc = sql_overload_function(db, "MATCH", FIELD_TYPE_SCALAR, 2);
-	assert(rc == SQL_NOMEM || rc == SQL_OK);
+	assert(rc == SQL_NOMEM || rc == 0);
 	if (rc == SQL_NOMEM) {
 		sqlOomFault(db);
 	}
diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c
index f096629..3309753 100644
--- a/src/box/sql/insert.c
+++ b/src/box/sql/insert.c
@@ -1249,7 +1249,7 @@ xferOptimization(Parse * pParse,	/* Parser context */
 	sqlReleaseTempReg(pParse, regTupleid);
 	sqlReleaseTempReg(pParse, regData);
 	if (emptyDestTest) {
-		sqlVdbeAddOp2(v, OP_Halt, SQL_OK, 0);
+		sqlVdbeAddOp2(v, OP_Halt, 0, 0);
 		sqlVdbeJumpHere(v, emptyDestTest);
 		sqlVdbeAddOp2(v, OP_Close, iDest, 0);
 		return 0;
diff --git a/src/box/sql/legacy.c b/src/box/sql/legacy.c
index 1a3804e..f7e069a 100644
--- a/src/box/sql/legacy.c
+++ b/src/box/sql/legacy.c
@@ -58,7 +58,7 @@ sql_exec(sql * db,	/* The database on which the SQL executes */
     )
 {
 	(void)pzErrMsg;
-	int rc = SQL_OK;	/* Return code */
+	int rc = 0;	/* Return code */
 	const char *zLeftover;	/* Tail of unprocessed SQL */
 	sql_stmt *pStmt = 0;	/* The current SQL statement */
 	char **azCols = 0;	/* Names of result columns */
@@ -68,14 +68,14 @@ sql_exec(sql * db,	/* The database on which the SQL executes */
 	if (zSql == 0)
 		zSql = "";
 
-	while (rc == SQL_OK && zSql[0]) {
+	while (rc == 0 && zSql[0]) {
 		int nCol;
 		char **azVals = 0;
 
 		pStmt = 0;
 		rc = sql_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
-		assert(rc == SQL_OK || pStmt == 0);
-		if (rc != SQL_OK) {
+		assert(rc == 0 || pStmt == 0);
+		if (rc != 0) {
 			continue;
 		}
 		if (!pStmt) {
@@ -163,7 +163,7 @@ sql_exec(sql * db,	/* The database on which the SQL executes */
 	sqlDbFree(db, azCols);
 
 	rc = sqlApiExit(db, rc);
-	assert(rc == SQL_OK);
+	assert(rc == 0);
 	assert((rc & db->errMask) == rc);
 	return rc;
 }
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index 29a7911..65d8de5 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -99,7 +99,7 @@ char *sql_data_directory = 0;
 int
 sql_initialize(void)
 {
-	int rc = SQL_OK;
+	int rc = 0;
 
 	/* If the following assert() fails on some obscure processor/compiler
 	 * combination, the work-around is to set the correct pointer
@@ -113,17 +113,17 @@ sql_initialize(void)
 	 * of this routine.
 	 */
 	if (sqlGlobalConfig.isInit)
-		return SQL_OK;
+		return 0;
 
 	if (!sqlGlobalConfig.isMallocInit)
 		sqlMallocInit();
-	if (rc == SQL_OK)
+	if (rc == 0)
 		sqlGlobalConfig.isMallocInit = 1;
 
-	/* If rc is not SQL_OK at this point, then the malloc
+	/* If rc is not 0 at this point, then the malloc
 	 * subsystem could not be initialized.
 	 */
-	if (rc != SQL_OK)
+	if (rc != 0)
 		return rc;
 
 	/* Do the rest of the initialization
@@ -144,10 +144,10 @@ sql_initialize(void)
 		memset(&sqlBuiltinFunctions, 0,
 		       sizeof(sqlBuiltinFunctions));
 		sqlRegisterBuiltinFunctions();
-		if (rc == SQL_OK) {
+		if (rc == 0) {
 			rc = sqlOsInit();
 		}
-		if (rc == SQL_OK) {
+		if (rc == 0) {
 			sqlGlobalConfig.isInit = 1;
 		}
 		sqlGlobalConfig.inProgress = 0;
@@ -160,7 +160,7 @@ sql_initialize(void)
 	 */
 #ifndef NDEBUG
 	/* This section of code's only "output" is via assert() statements. */
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		u64 x = (((u64) 1) << 63) - 1;
 		double y;
 		assert(sizeof(x) == 8);
@@ -212,7 +212,7 @@ functionDestroy(sql * db, FuncDef * p)
 }
 
 /*
- * Rollback all database files.  If tripCode is not SQL_OK, then
+ * Rollback all database files.  If tripCode is not 0, then
  * any write cursors are invalidated ("tripped" - as in "tripping a circuit
  * breaker") and made to return tripCode if there are any further
  * attempts to use that cursor.  Read cursors remain open and valid
@@ -303,7 +303,7 @@ sqlCreateFunc(sql * db,
 	p->pUserData = pUserData;
 	p->nArg = (u16) nArg;
 	p->ret_type = type;
-	return SQL_OK;
+	return 0;
 }
 
 int
@@ -338,7 +338,7 @@ sql_create_function_v2(sql * db,
 	rc = sqlCreateFunc(db, zFunc, type, nArg, flags, p, xSFunc, xStep,
 			       xFinal, pArg);
 	if (pArg && pArg->nRef == 0) {
-		assert(rc != SQL_OK);
+		assert(rc != 0);
 		xDestroy(p);
 		sqlDbFree(db, pArg);
 	}
@@ -364,7 +364,7 @@ sql_trace_v2(sql * db,		/* Trace this connection */
 	db->mTrace = mTrace;
 	db->xTrace = xTrace;
 	db->pTraceArg = pArg;
-	return SQL_OK;
+	return 0;
 }
 
 #endif				/* SQL_OMIT_TRACE */
@@ -562,7 +562,7 @@ opendb_out:
 	assert(db != 0 || rc == SQL_NOMEM);
 	if (rc == SQL_NOMEM)
 		db = NULL;
-	else if (rc != SQL_OK)
+	else if (rc != 0)
 		db->magic = SQL_MAGIC_SICK;
 
 	*out_db = db;
diff --git a/src/box/sql/os.c b/src/box/sql/os.c
index eb7450b..273aa6b 100644
--- a/src/box/sql/os.c
+++ b/src/box/sql/os.c
@@ -90,7 +90,7 @@ sqlOsFetch(MAYBE_UNUSED sql_file * id,
 	       MAYBE_UNUSED int iAmt, void **pp)
 {
 	*pp = 0;
-	return SQL_OK;
+	return 0;
 }
 
 int
@@ -98,7 +98,7 @@ sqlOsUnfetch(MAYBE_UNUSED sql_file * id,
 		 MAYBE_UNUSED i64 iOff,
 		 MAYBE_UNUSED void *p)
 {
-	return SQL_OK;
+	return 0;
 }
 #endif
 
@@ -118,7 +118,7 @@ sqlOsOpen(sql_vfs * pVfs,
 	 * reaching the VFS.
 	 */
 	rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x87f7f, pFlagsOut);
-	assert(rc == SQL_OK || pFile->pMethods == 0);
+	assert(rc == 0 || pFile->pMethods == 0);
 	return rc;
 }
 
@@ -164,7 +164,7 @@ sqlOsOpenMalloc(sql_vfs * pVfs,
 	pFile = (sql_file *) sqlMallocZero(pVfs->szOsFile);
 	if (pFile) {
 		rc = sqlOsOpen(pVfs, zFile, pFile, flags, pOutFlags);
-		if (rc != SQL_OK) {
+		if (rc != 0) {
 			sql_free(pFile);
 		} else {
 			*ppFile = pFile;
@@ -261,5 +261,5 @@ sql_vfs_register(sql_vfs * pVfs, int makeDflt)
 		vfsList->pNext = pVfs;
 	}
 	assert(vfsList);
-	return SQL_OK;
+	return 0;
 }
diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index 615d539..fd9576e 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -486,7 +486,7 @@ findInodeInfo(unixFile * pFile,	/* Unix file with file desc used in the key */
 		pInode->nRef++;
 	}
 	*ppInode = pInode;
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -625,13 +625,13 @@ posixUnlock(sql_file * id, int eFileLock, int handleNFSUnlock)
 	unixFile *pFile = (unixFile *) id;
 	unixInodeInfo *pInode;
 	struct flock lock;
-	int rc = SQL_OK;
+	int rc = 0;
 
 	assert(pFile);
 
 	assert(eFileLock <= SHARED_LOCK);
 	if (pFile->eFileLock <= eFileLock) {
-		return SQL_OK;
+		return 0;
 	}
 	pInode = pFile->pInode;
 	assert(pInode->nShared != 0);
@@ -714,7 +714,7 @@ posixUnlock(sql_file * id, int eFileLock, int handleNFSUnlock)
 	}
 
  end_unlock:
-	if (rc == SQL_OK)
+	if (rc == 0)
 		pFile->eFileLock = eFileLock;
 	return rc;
 }
@@ -755,7 +755,7 @@ closeUnixFile(sql_file * id)
 	}
 	sql_free(pFile->pUnused);
 	memset(pFile, 0, sizeof(unixFile));
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -862,7 +862,7 @@ seekAndRead(unixFile * id, sql_int64 offset, void *pBuf, int cnt)
 }
 
 /*
- * Read data from a file into a buffer.  Return SQL_OK if all
+ * Read data from a file into a buffer.  Return 0 if all
  * bytes were read successfully and SQL_IOERR if anything goes
  * wrong.
  */
@@ -883,7 +883,7 @@ unixRead(sql_file * id, void *pBuf, int amt, sql_int64 offset)
 		if (offset + amt <= pFile->mmapSize) {
 			memcpy(pBuf, &((u8 *) (pFile->pMapRegion))[offset],
 			       amt);
-			return SQL_OK;
+			return 0;
 		} else {
 			int nCopy = pFile->mmapSize - offset;
 			memcpy(pBuf, &((u8 *) (pFile->pMapRegion))[offset],
@@ -897,7 +897,7 @@ unixRead(sql_file * id, void *pBuf, int amt, sql_int64 offset)
 
 	got = seekAndRead(pFile, offset, pBuf, amt);
 	if (got == amt) {
-		return SQL_OK;
+		return 0;
 	} else if (got < 0) {
 		/* lastErrno set by seekAndRead */
 		return SQL_IOERR_READ;
@@ -958,7 +958,7 @@ seekAndWrite(unixFile * id, i64 offset, const void *pBuf, int cnt)
 }
 
 /*
- * Write data from a buffer into a file.  Return SQL_OK on success
+ * Write data from a buffer into a file.  Return 0 on success
  * or some other error code on failure.
  */
 static int
@@ -986,13 +986,13 @@ unixWrite(sql_file * id, const void *pBuf, int amt, sql_int64 offset)
 		}
 	}
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
  * Open a file descriptor to the directory containing file zFilename.
  * If successful, *pFd is set to the opened file descriptor and
- * SQL_OK is returned. If an error occurs, either SQL_NOMEM
+ * 0 is returned. If an error occurs, either SQL_NOMEM
  * or SQL_CANTOPEN is returned and *pFd is set to an undefined
  * value.
  *
@@ -1006,10 +1006,10 @@ unixWrite(sql_file * id, const void *pBuf, int amt, sql_int64 offset)
  * chromium sandbox.  Opening a directory is a security risk (we are
  * told) so making it overrideable allows the chromium sandbox to
  * replace this routine with a harmless no-op.  To make this routine
- * a no-op, replace it with a stub that returns SQL_OK but leaves
+ * a no-op, replace it with a stub that returns 0 but leaves
  * *pFd set to a negative number.
  *
- * If SQL_OK is returned, the caller is responsible for closing
+ * If 0 is returned, the caller is responsible for closing
  * the file descriptor *pFd using close().
  */
 static int
@@ -1032,7 +1032,7 @@ openDirectory(const char *zFilename, int *pFd)
 
 	*pFd = fd;
 	if (fd >= 0)
-		return SQL_OK;
+		return 0;
 	return unixLogError(SQL_CANTOPEN, "openDirectory", zDirname);
 }
 
@@ -1087,7 +1087,7 @@ fcntlSizeHint(unixFile * pFile, i64 nByte)
 		return rc;
 	}
 
-	return SQL_OK;
+	return 0;
 }
 
 /* Forward declaration */
@@ -1103,15 +1103,15 @@ unixFileControl(sql_file * id, int op, void *pArg)
 	switch (op) {
 	case SQL_FCNTL_LOCKSTATE:{
 			*(int *)pArg = pFile->eFileLock;
-			return SQL_OK;
+			return 0;
 		}
 	case SQL_FCNTL_LAST_ERRNO:{
 			*(int *)pArg = pFile->lastErrno;
-			return SQL_OK;
+			return 0;
 		}
 	case SQL_FCNTL_CHUNK_SIZE:{
 			pFile->szChunk = *(int *)pArg;
-			return SQL_OK;
+			return 0;
 		}
 	case SQL_FCNTL_SIZE_HINT:{
 			int rc;
@@ -1121,7 +1121,7 @@ unixFileControl(sql_file * id, int op, void *pArg)
 	case SQL_FCNTL_VFSNAME:{
 			*(char **)pArg =
 			    sql_mprintf("%s", pFile->pVfs->zName);
-			return SQL_OK;
+			return 0;
 		}
 	case SQL_FCNTL_TEMPFILENAME:{
 			char *zTFile =
@@ -1131,15 +1131,15 @@ unixFileControl(sql_file * id, int op, void *pArg)
 						zTFile);
 				*(char **)pArg = zTFile;
 			}
-			return SQL_OK;
+			return 0;
 		}
 	case SQL_FCNTL_HAS_MOVED:{
 			*(int *)pArg = fileHasMoved(pFile);
-			return SQL_OK;
+			return 0;
 		}
 	case SQL_FCNTL_MMAP_SIZE:{
 			i64 newLimit = *(i64 *) pArg;
-			int rc = SQL_OK;
+			int rc = 0;
 			if (newLimit > sqlGlobalConfig.mxMmap) {
 				newLimit = sqlGlobalConfig.mxMmap;
 			}
@@ -1241,7 +1241,7 @@ unixRemapfile(unixFile * pFd,	/* File descriptor object */
 	if (pNew == MAP_FAILED) {
 		pNew = 0;
 		nNew = 0;
-		unixLogError(SQL_OK, zErr, pFd->zPath);
+		unixLogError(0, zErr, pFd->zPath);
 
 		/* If the mmap() above failed, assume that all subsequent mmap() calls
 		 * will probably fail too. Fall back to using xRead/xWrite exclusively
@@ -1265,7 +1265,7 @@ unixRemapfile(unixFile * pFd,	/* File descriptor object */
  * created mapping is either the requested size or the value configured
  * using SQL_FCNTL_MMAP_LIMIT, whichever is smaller.
  *
- * SQL_OK is returned if no error occurs (even if the mapping is not
+ * 0 is returned if no error occurs (even if the mapping is not
  * recreated as a result of outstanding references) or an sql error
  * code otherwise.
  */
@@ -1275,7 +1275,7 @@ unixMapfile(unixFile * pFd, i64 nMap)
 	assert(nMap >= 0 || pFd->nFetchOut == 0);
 	assert(nMap > 0 || (pFd->mmapSize == 0 && pFd->pMapRegion == 0));
 	if (pFd->nFetchOut > 0)
-		return SQL_OK;
+		return 0;
 
 	if (nMap < 0) {
 		struct stat statbuf;	/* Low-level file information */
@@ -1292,15 +1292,15 @@ unixMapfile(unixFile * pFd, i64 nMap)
 		unixRemapfile(pFd, nMap);
 	}
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
  * If possible, return a pointer to a mapping of file fd starting at offset
  * iOff. The mapping must be valid for at least nAmt bytes.
  *
- * If such a pointer can be obtained, store it in *pp and return SQL_OK.
- * Or, if one cannot but no error occurs, set *pp to 0 and return SQL_OK.
+ * If such a pointer can be obtained, store it in *pp and return 0.
+ * Or, if one cannot but no error occurs, set *pp to 0 and return 0.
  * Finally, if an error does occur, return an sql error code. The final
  * value of *pp is undefined in this case.
  *
@@ -1321,7 +1321,7 @@ unixFetch(sql_file * fd MAYBE_UNUSED,
 	if (pFd->mmapSizeMax > 0) {
 		if (pFd->pMapRegion == 0) {
 			int rc = unixMapfile(pFd, -1);
-			if (rc != SQL_OK)
+			if (rc != 0)
 				return rc;
 		}
 		if (pFd->mmapSize >= iOff + nAmt) {
@@ -1330,7 +1330,7 @@ unixFetch(sql_file * fd MAYBE_UNUSED,
 		}
 	}
 #endif
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -1365,7 +1365,7 @@ unixUnfetch(sql_file * fd, i64 iOff, void *p)
 	}
 
 	assert(pFd->nFetchOut >= 0);
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -1466,7 +1466,7 @@ fillInUnixFile(sql_vfs * pVfs,	/* Pointer to vfs object */
 {
 	const sql_io_methods *pLockingStyle;
 	unixFile *pNew = (unixFile *) pId;
-	int rc = SQL_OK;
+	int rc = 0;
 
 	assert(pNew->pInode == NULL);
 
@@ -1499,7 +1499,7 @@ fillInUnixFile(sql_vfs * pVfs,	/* Pointer to vfs object */
 
 	if (pLockingStyle == &posixIoMethods) {
 		rc = findInodeInfo(pNew, &pNew->pInode);
-		if (rc != SQL_OK) {
+		if (rc != 0) {
 			/* If an error occurred in findInodeInfo(), close the file descriptor
 			 * immediately. findInodeInfo() may fail
 			 * in two scenarios:
@@ -1523,7 +1523,7 @@ fillInUnixFile(sql_vfs * pVfs,	/* Pointer to vfs object */
 		}
 	}
 	storeLastErrno(pNew, 0);
-	if (rc != SQL_OK) {
+	if (rc != 0) {
 		if (h >= 0)
 			robust_close(pNew, h, __LINE__);
 	} else {
@@ -1598,7 +1598,7 @@ unixGetTempname(int nBuf, char *zBuf)
 		if (zBuf[nBuf - 2] != 0 || (iLimit++) > 10)
 			return SQL_ERROR;
 	} while (access(zBuf, 0) == 0);
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -1667,7 +1667,7 @@ getFileMode(const char *zFile,	/* File name */
     )
 {
 	struct stat sStat;	/* Output of stat() on database file */
-	int rc = SQL_OK;
+	int rc = 0;
 	if (0 == stat(zFile, &sStat)) {
 		*pMode = sStat.st_mode & 0777;
 		*pUid = sStat.st_uid;
@@ -1680,7 +1680,7 @@ getFileMode(const char *zFile,	/* File name */
 
 /*
  * This function is called by unixOpen() to determine the unix permissions
- * to create new files with. If no error occurs, then SQL_OK is returned
+ * to create new files with. If no error occurs, then 0 is returned
  * and a value suitable for passing as the third argument to open(2) is
  * written to *pMode. If an IO error occurs, an sql error code is
  * returned and the value of *pMode is not modified.
@@ -1702,7 +1702,7 @@ findCreateFileMode(const char *zPath,	/* Path of file (possibly) being created *
 		   gid_t * pGid	/* OUT: gid to set on the file */
     )
 {
-	int rc = SQL_OK;	/* Return Code */
+	int rc = 0;	/* Return Code */
 	*pMode = 0;
 	*pUid = 0;
 	*pGid = 0;
@@ -1827,7 +1827,7 @@ unixOpen(sql_vfs * pVfs,	/* The VFS for which this is the xOpen method */
 		/* If zName is NULL, the upper layer is requesting a temp file. */
 		assert(isDelete);
 		rc = unixGetTempname(pVfs->mxPathname, zTmpname);
-		if (rc != SQL_OK) {
+		if (rc != 0) {
 			return rc;
 		}
 		zName = zTmpname;
@@ -1861,7 +1861,7 @@ unixOpen(sql_vfs * pVfs,	/* The VFS for which this is the xOpen method */
 		uid_t uid;	/* Userid for the file */
 		gid_t gid;	/* Groupid for the file */
 		rc = findCreateFileMode(zName, flags, &openMode, &uid, &gid);
-		if (rc != SQL_OK) {
+		if (rc != 0) {
 			assert(!p->pUnused);
 			return rc;
 		}
@@ -1911,7 +1911,7 @@ unixOpen(sql_vfs * pVfs,	/* The VFS for which this is the xOpen method */
 	rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
 
  open_finished:
-	if (rc != SQL_OK) {
+	if (rc != 0) {
 		sql_free(p->pUnused);
 	}
 	return rc;
@@ -1927,7 +1927,7 @@ unixDelete(sql_vfs * NotUsed,	/* VFS containing this as the xDelete method */
 	   int dirSync		/* If true, fsync() directory after deleting file */
     )
 {
-	int rc = SQL_OK;
+	int rc = 0;
 	UNUSED_PARAMETER(NotUsed);
 	if (unlink(zPath) == (-1)) {
 		if (errno == ENOENT) {
@@ -1941,7 +1941,7 @@ unixDelete(sql_vfs * NotUsed,	/* VFS containing this as the xDelete method */
 	if ((dirSync & 1) != 0) {
 		int fd;
 		rc = openDirectory(zPath, &fd);
-		if (rc == SQL_OK) {
+		if (rc == 0) {
 			struct stat buf;
 			if (fstat(fd, &buf)) {
 				rc = unixLogError(SQL_IOERR_DIR_FSYNC,
@@ -1950,7 +1950,7 @@ unixDelete(sql_vfs * NotUsed,	/* VFS containing this as the xDelete method */
 			robust_close(0, fd, __LINE__);
 		} else {
 			assert(rc == SQL_CANTOPEN);
-			rc = SQL_OK;
+			rc = 0;
 		}
 	}
 #endif
@@ -1993,7 +1993,7 @@ int sql_current_time = 0;
  * epoch of noon in Greenwich on November 24, 4714 B.C according to the
  * proleptic Gregorian calendar.
  *
- * On success, return SQL_OK.  Return SQL_ERROR if the time and date
+ * On success, return 0.  Return SQL_ERROR if the time and date
  * cannot be found.
  */
 static int
@@ -2001,7 +2001,7 @@ unixCurrentTimeInt64(sql_vfs * NotUsed, sql_int64 * piNow)
 {
 	static const sql_int64 unixEpoch =
 	    24405875 * (sql_int64) 8640000;
-	int rc = SQL_OK;
+	int rc = 0;
 	struct timeval sNow;
 	(void)gettimeofday(&sNow, 0);	/* Cannot fail given valid arguments */
 	*piNow =
@@ -2092,7 +2092,7 @@ sql_os_init(void)
 	/* Register all VFSes defined in the aVfs[] array. */
 	for (unsigned int i = 0; i < (sizeof(aVfs) / sizeof(sql_vfs)); i++)
 		sql_vfs_register(&aVfs[i], i == 0);
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -2105,5 +2105,5 @@ sql_os_init(void)
 int
 sql_os_end(void)
 {
-	return SQL_OK;
+	return 0;
 }
diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index 2b3ac29..ecae5d4 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -52,7 +52,7 @@ sqlPrepare(sql * db,	/* Database handle. */
 	       const char **pzTail	/* OUT: End of parsed string */
     )
 {
-	int rc = SQL_OK;	/* Result code */
+	int rc = 0;	/* Result code */
 	Parse sParse;		/* Parsing context */
 	sql_parser_create(&sParse, db, current_session()->sql_flags);
 	sParse.pReprepare = pReprepare;
@@ -107,7 +107,7 @@ sqlPrepare(sql * db,	/* Database handle. */
 	if (sParse.is_aborted)
 		rc = SQL_TARANTOOL_ERROR;
 
-	if (rc == SQL_OK && sParse.pVdbe && sParse.explain) {
+	if (rc == 0 && sParse.pVdbe && sParse.explain) {
 		static const char *const azColName[] = {
 			/*  0 */ "addr",
 			/*  1 */ "INTEGER",
@@ -159,7 +159,7 @@ sqlPrepare(sql * db,	/* Database handle. */
 		sqlVdbeSetSql(pVdbe, zSql, (int)(sParse.zTail - zSql),
 				  saveSqlFlag);
 	}
-	if (sParse.pVdbe && (rc != SQL_OK || db->mallocFailed)) {
+	if (sParse.pVdbe && (rc != 0 || db->mallocFailed)) {
 		sqlVdbeFinalize(sParse.pVdbe);
 		assert(!(*ppStmt));
 	} else {
@@ -201,14 +201,14 @@ sqlLockAndPrepare(sql * db,		/* Database handle. */
 		rc = sqlPrepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt,
 				    pzTail);
 	}
-	assert(rc == SQL_OK || *ppStmt == 0);
+	assert(rc == 0 || *ppStmt == 0);
 	return rc;
 }
 
 /*
  * Rerun the compilation of a statement after a schema change.
  *
- * If the statement is successfully recompiled, return SQL_OK. Otherwise,
+ * If the statement is successfully recompiled, return 0. Otherwise,
  * if the statement cannot be recompiled because another connection has
  * locked the sql_master table, return SQL_LOCKED. If any other error
  * occurs, return SQL_SCHEMA.
@@ -238,7 +238,7 @@ sqlReprepare(Vdbe * p)
 	sqlTransferBindings(pNew, (sql_stmt *) p);
 	sqlVdbeResetStepResult((Vdbe *) pNew);
 	sqlVdbeFinalize((Vdbe *) pNew);
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -258,7 +258,7 @@ sql_prepare(sql * db,		/* Database handle. */
 {
 	int rc;
 	rc = sqlLockAndPrepare(db, zSql, nBytes, 0, 0, ppStmt, pzTail);
-	assert(rc == SQL_OK || ppStmt == 0 || *ppStmt == 0);	/* VERIFY: F13021 */
+	assert(rc == 0 || ppStmt == 0 || *ppStmt == 0);	/* VERIFY: F13021 */
 	return rc;
 }
 
@@ -272,7 +272,7 @@ sql_prepare_v2(sql * db,	/* Database handle. */
 {
 	int rc;
 	rc = sqlLockAndPrepare(db, zSql, nBytes, 1, 0, ppStmt, pzTail);
-	assert(rc == SQL_OK || ppStmt == 0 || *ppStmt == 0);	/* VERIFY: F13021 */
+	assert(rc == 0 || ppStmt == 0 || *ppStmt == 0);	/* VERIFY: F13021 */
 	return rc;
 }
 
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index b675293..6e22153 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -1821,7 +1821,7 @@ generateColumnNames(Parse * pParse,	/* Parser context */
  * Only the column names are computed.  Column.zType, Column.zColl,
  * and other fields of Column are zeroed.
  *
- * Return SQL_OK on success.  If a memory allocation error occurs,
+ * Return 0 on success.  If a memory allocation error occurs,
  * store NULL in *paCol and 0 in *pnCol and return SQL_NOMEM.
  */
 int
@@ -1925,8 +1925,8 @@ sqlColumnsFromExprList(Parse * parse, ExprList * expr_list,
 	}
 cleanup:
 	sqlHashClear(&ht);
-	int rc = db->mallocFailed ? SQL_NOMEM : SQL_OK;
-	if (rc != SQL_OK) {
+	int rc = db->mallocFailed ? SQL_NOMEM : 0;
+	if (rc != 0) {
 		/*
 		 * pTable->def could be not temporal in
 		 * sqlViewGetColumnNames so we need clean-up.
@@ -2567,7 +2567,7 @@ multiSelect(Parse * pParse,	/* Parsing context */
 	    Select * p,		/* The right-most of SELECTs to be coded */
 	    SelectDest * pDest)	/* What to do with query results */
 {
-	int rc = SQL_OK;	/* Success code from a subroutine */
+	int rc = 0;	/* Success code from a subroutine */
 	Select *pPrior;		/* Another SELECT immediately to our left */
 	Vdbe *v;		/* Generate code to this VDBE */
 	SelectDest dest;	/* Alternative data destination */
@@ -2682,7 +2682,7 @@ multiSelect(Parse * pParse,	/* Parsing context */
 				}
 				iSub2 = pParse->iNextSelectId;
 				rc = sqlSelect(pParse, p, &dest);
-				testcase(rc != SQL_OK);
+				testcase(rc != 0);
 				pDelete = p->pPrior;
 				p->pPrior = pPrior;
 				p->nSelectRow =
@@ -2769,7 +2769,7 @@ multiSelect(Parse * pParse,	/* Parsing context */
 				uniondest.eDest = op;
 				iSub2 = pParse->iNextSelectId;
 				rc = sqlSelect(pParse, p, &uniondest);
-				testcase(rc != SQL_OK);
+				testcase(rc != 0);
 				/* Query flattening in sqlSelect() might refill p->pOrderBy.
 				 * Be sure to delete p->pOrderBy, therefore, to avoid a memory leak.
 				 */
@@ -2883,7 +2883,7 @@ multiSelect(Parse * pParse,	/* Parsing context */
 				intersectdest.reg_eph = reg_eph2;
 				iSub2 = pParse->iNextSelectId;
 				rc = sqlSelect(pParse, p, &intersectdest);
-				testcase(rc != SQL_OK);
+				testcase(rc != 0);
 				pDelete = p->pPrior;
 				p->pPrior = pPrior;
 				if (p->nSelectRow > pPrior->nSelectRow)
@@ -4411,7 +4411,7 @@ is_simple_count(struct Select *select, struct AggInfo *agg_info)
  * INDEXED BY clause, then try to locate the specified index. If there
  * was such a clause and the named index cannot be found, return
  * SQL_ERROR and leave an error in pParse. Otherwise, populate
- * pFrom->pIndex and return SQL_OK.
+ * pFrom->pIndex and return 0.
  */
 int
 sqlIndexedByLookup(Parse * pParse, struct SrcList_item *pFrom)
@@ -4435,7 +4435,7 @@ sqlIndexedByLookup(Parse * pParse, struct SrcList_item *pFrom)
 		}
 		pFrom->pIBIndex = idx->def;
 	}
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -4589,9 +4589,9 @@ sqlWithPush(Parse * pParse, With * pWith, u8 bFree)
  * (pFrom->space!=0) to determine whether or not a successful match
  * was found.
  *
- * Whether or not a match is found, SQL_OK is returned if no error
+ * Whether or not a match is found, 0 is returned if no error
  * occurs. If an error does occur, an error message is stored in the
- * parser and some error code other than SQL_OK returned.
+ * parser and some error code other than 0 returned.
  */
 static int
 withExpand(Walker * pWalker, struct SrcList_item *pFrom)
@@ -4709,7 +4709,7 @@ withExpand(Walker * pWalker, struct SrcList_item *pFrom)
 		pParse->pWith = pSavedWith;
 	}
 
-	return SQL_OK;
+	return 0;
 }
 #endif
 
@@ -6415,7 +6415,7 @@ sqlSelect(Parse * pParse,		/* The parser context */
 
 	/* Identify column names if results of the SELECT are to be output.
 	 */
-	if (rc == SQL_OK && pDest->eDest == SRT_Output) {
+	if (rc == 0 && pDest->eDest == SRT_Output) {
 		generateColumnNames(pParse, pTabList, pEList);
 	}
 
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index d2e429e..93ec9ab 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -356,10 +356,8 @@ struct sql_vfs {
 #define SQL_LIMIT_WORKER_THREADS           10
 
 enum sql_ret_code {
-	/** Result of a routine is ok. */
-	SQL_OK = 0,
 	/** Common error code. */
-	SQL_ERROR,
+	SQL_ERROR = 1,
 	/** Access permission denied. */
 	SQL_PERM,
 	/** Callback routine requested an abort. */
@@ -590,7 +588,7 @@ sql_finalize(sql_stmt * pStmt);
  * it back to its starting state so that it can be reused.
  *
  * @param stmt VDBE program.
- * @retval SQL_OK On success.
+ * @retval 0 On success.
  * @retval sql_ret_code Error code on error.
  */
 int
@@ -3293,7 +3291,7 @@ sql_space_column_is_in_pk(struct space *space, uint32_t);
  * @param parse Parsing context.
  * @param expr_list  Expr list from which to derive column names.
  * @param space_def Destination space definition.
- * @retval sql_OK on success.
+ * @retval 0 on success.
  * @retval error codef on error.
  */
 int sqlColumnsFromExprList(Parse *parse, ExprList *expr_list,
diff --git a/src/box/sql/status.c b/src/box/sql/status.c
index bc170c8..2d4eae0 100644
--- a/src/box/sql/status.c
+++ b/src/box/sql/status.c
@@ -143,7 +143,7 @@ sql_status64(int op,
 	if (resetFlag) {
 		wsdStat.mxValue[op] = wsdStat.nowValue[op];
 	}
-	return SQL_OK;
+	return 0;
 }
 
 int
@@ -170,7 +170,7 @@ sql_db_status(sql * db,	/* The database connection whose status is desired */
 		  int resetFlag	/* Reset high-water mark if true */
     )
 {
-	int rc = SQL_OK;	/* Return code */
+	int rc = 0;	/* Return code */
 	switch (op) {
 	case SQL_DBSTATUS_LOOKASIDE_USED:{
 			*pCurrent = db->lookaside.nOut;
diff --git a/src/box/sql/tarantoolInt.h b/src/box/sql/tarantoolInt.h
index 375a8cc..71073ad 100644
--- a/src/box/sql/tarantoolInt.h
+++ b/src/box/sql/tarantoolInt.h
@@ -35,7 +35,7 @@ int tarantoolsqlDelete(BtCursor * pCur, u8 flags);
  * @param key Key of record to be deleted.
  * @param key_size Size of key.
  *
- * @retval SQL_OK on success, SQL_TARANTOOL_ERROR otherwise.
+ * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise.
  */
 int
 sql_delete_by_key(struct space *space, uint32_t iid, char *key,
@@ -82,7 +82,7 @@ sql_ephemeral_space_create(uint32_t filed_count, struct sql_key_info *key_info);
  * @param tuple Tuple to be inserted.
  * @param tuple_end End of tuple to be inserted.
  *
- * @retval SQL_OK on success, SQL_TARANTOOL_ERROR otherwise.
+ * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise.
  */
 int tarantoolsqlEphemeralInsert(struct space *space, const char *tuple,
 				    const char *tuple_end);
diff --git a/src/box/sql/trigger.c b/src/box/sql/trigger.c
index d52d8e3..89d54c8 100644
--- a/src/box/sql/trigger.c
+++ b/src/box/sql/trigger.c
@@ -785,7 +785,7 @@ sql_row_trigger_program(struct Parse *parser, struct sql_trigger *trigger,
 		 */
 		if (trigger->pWhen != NULL) {
 			pWhen = sqlExprDup(db, trigger->pWhen, 0);
-			if (SQL_OK == sqlResolveExprNames(&sNC, pWhen)
+			if (0 == sqlResolveExprNames(&sNC, pWhen)
 			    && db->mallocFailed == 0) {
 				iEndTrigger = sqlVdbeMakeLabel(v);
 				sqlExprIfFalse(pSubParse, pWhen,
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index efab62d..77c6fa5 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -247,7 +247,7 @@ allocateCursor(
 		sqlVdbeFreeCursor(p, p->apCsr[iCur]);
 		p->apCsr[iCur] = 0;
 	}
-	if (SQL_OK==sqlVdbeMemClearAndResize(pMem, nByte)) {
+	if (0==sqlVdbeMemClearAndResize(pMem, nByte)) {
 		p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
 		memset(pCx, 0, offsetof(VdbeCursor,uc));
 		pCx->eCurType = eCurType;
@@ -372,7 +372,7 @@ static u16 SQL_NOINLINE computeNumericType(Mem *pMem)
 	assert((pMem->flags & (MEM_Str|MEM_Blob))!=0);
 	if (sqlAtoF(pMem->z, &pMem->u.r, pMem->n)==0)
 		return 0;
-	if (sql_atoi64(pMem->z, (int64_t *)&pMem->u.i, pMem->n)==SQL_OK)
+	if (sql_atoi64(pMem->z, (int64_t *)&pMem->u.i, pMem->n)==0)
 		return MEM_Int;
 	return MEM_Real;
 }
@@ -634,7 +634,7 @@ vdbe_field_ref_fast_fetch(struct vdbe_field_ref *field_ref, uint32_t fieldno,
  * @param field_ref The initialized vdbe_field_ref instance to use.
  * @param fieldno The id of the field to fetch.
  * @param[out] dest_mem The memory variable to store result.
- * @retval SQL_OK Status code in case of success.
+ * @retval 0 Status code in case of success.
  * @retval sql_ret_code Error code otherwise.
  */
 static int
@@ -645,7 +645,7 @@ vdbe_field_ref_fetch(struct vdbe_field_ref *field_ref, uint32_t fieldno,
 	uint32_t *slots = field_ref->slots;
 	if (fieldno >= field_ref->field_count) {
 		UPDATE_MAX_BLOBSIZE(dest_mem);
-		return SQL_OK;
+		return 0;
 	}
 
 	const char *data;
@@ -713,7 +713,7 @@ vdbe_field_ref_fetch(struct vdbe_field_ref *field_ref, uint32_t fieldno,
 		dest_mem->flags |= MEM_Term;
 	}
 	UPDATE_MAX_BLOBSIZE(dest_mem);
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -730,7 +730,7 @@ int sqlVdbeExec(Vdbe *p)
 #ifdef SQL_DEBUG
 	int nExtraDelete = 0;      /* Verifies FORDELETE and AUXDELETE flags */
 #endif
-	int rc = SQL_OK;        /* Value to return */
+	int rc = 0;        /* Value to return */
 	sql *db = p->db;       /* The database */
 	int iCompare = 0;          /* Result of last comparison */
 	unsigned nVmStep = 0;      /* Number of virtual machine steps */
@@ -752,8 +752,8 @@ int sqlVdbeExec(Vdbe *p)
 		 */
 		goto no_mem;
 	}
-	assert(p->rc==SQL_OK || (p->rc&0xff)==SQL_BUSY);
-	p->rc = SQL_OK;
+	assert(p->rc==0 || (p->rc&0xff)==SQL_BUSY);
+	p->rc = 0;
 	p->iCurrentTime = 0;
 	assert(p->explain==0);
 	p->pResultSet = 0;
@@ -789,7 +789,7 @@ int sqlVdbeExec(Vdbe *p)
 		/* Errors are detected by individual opcodes, with an immediate
 		 * jumps to abort_due_to_error.
 		 */
-		assert(rc==SQL_OK);
+		assert(rc==0);
 
 		assert(pOp>=aOp && pOp<&aOp[p->nOp]);
 #ifdef VDBE_PROFILE
@@ -1036,7 +1036,7 @@ case OP_Halt: {
 	int pcx;
 
 	pcx = (int)(pOp - aOp);
-	if (pOp->p1==SQL_OK && p->pFrame) {
+	if (pOp->p1==0 && p->pFrame) {
 		/* Halt the sub-program. Return control to the parent frame. */
 		pFrame = p->pFrame;
 		p->pFrame = pFrame->pParent;
@@ -1068,11 +1068,11 @@ case OP_Halt: {
 		assert(! diag_is_empty(diag_get()));
 	}
 	rc = sqlVdbeHalt(p);
-	assert(rc==SQL_BUSY || rc==SQL_OK || rc==SQL_ERROR);
+	assert(rc==SQL_BUSY || rc==0 || rc==SQL_ERROR);
 	if (rc==SQL_BUSY) {
 		p->rc = SQL_BUSY;
 	} else {
-		assert(rc==SQL_OK || (p->rc&0xff)==SQL_CONSTRAINT);
+		assert(rc==0 || (p->rc&0xff)==SQL_CONSTRAINT);
 		rc = p->rc ? SQL_TARANTOOL_ERROR : SQL_DONE;
 	}
 	goto vdbe_return;
@@ -1145,7 +1145,7 @@ case OP_String8: {         /* same as TK_STRING, out2 */
 	if (pOp->p1>db->aLimit[SQL_LIMIT_LENGTH]) {
 		goto too_big;
 	}
-	assert(rc==SQL_OK);
+	assert(rc==0);
 	/* Fall through to the next case, OP_String */
 	FALLTHROUGH;
 }
@@ -1440,7 +1440,7 @@ case OP_ResultRow: {
 	 */
 	assert(p->iStatement == 0 || (p->sql_flags & SQL_CountRows) != 0);
 	rc = sqlVdbeCloseStatement(p, SAVEPOINT_RELEASE);
-	assert(rc==SQL_OK);
+	assert(rc==0);
 
 	/* Invalidate all ephemeral cursor row caches */
 	p->cacheCtr = (p->cacheCtr + 2)|1;
@@ -2630,7 +2630,7 @@ case OP_Column: {
 	struct Mem *default_val_mem =
 		pOp->p4type == P4_MEM ? pOp->p4.pMem : NULL;
 	rc = vdbe_field_ref_fetch(&pC->field_ref, p2, pDest);
-	if (rc != SQL_OK)
+	if (rc != 0)
 		goto abort_due_to_error;
 
 	if ((pDest->flags & MEM_Null) &&
@@ -2664,7 +2664,7 @@ case OP_Fetch: {
 	struct Mem *dest_mem = &aMem[pOp->p3];
 	memAboutToChange(p, dest_mem);
 	rc = vdbe_field_ref_fetch(field_ref, field_idx, dest_mem);
-	if (rc != SQL_OK)
+	if (rc != 0)
 		goto abort_due_to_error;
 	REGISTER_TRACE(p, pOp->p3, dest_mem);
 	break;
@@ -2883,7 +2883,7 @@ case OP_Savepoint: {
 			 */
 			int isTransaction = pSavepoint->pNext == 0;
 			if (isTransaction && p1==SAVEPOINT_RELEASE) {
-				if ((rc = sqlVdbeCheckFk(p, 1))!=SQL_OK) {
+				if ((rc = sqlVdbeCheckFk(p, 1))!=0) {
 					goto vdbe_return;
 				}
 				if (sqlVdbeHalt(p)==SQL_BUSY) {
@@ -3453,7 +3453,7 @@ case OP_SeekGT: {       /* jump, in3 */
 #endif
 	r.eqSeen = 0;
 	r.opcode = oc;
-	if (sqlCursorMovetoUnpacked(pC->uc.pCursor, &r, &res) != SQL_OK)
+	if (sqlCursorMovetoUnpacked(pC->uc.pCursor, &r, &res) != 0)
 		goto abort_due_to_error;
 	if (eqOnly && r.eqSeen==0) {
 		assert(res!=0);
@@ -3466,7 +3466,7 @@ case OP_SeekGT: {       /* jump, in3 */
 	if (oc>=OP_SeekGE) {  assert(oc==OP_SeekGE || oc==OP_SeekGT);
 		if (res<0 || (res==0 && oc==OP_SeekGT)) {
 			res = 0;
-			if (sqlCursorNext(pC->uc.pCursor, &res) != SQL_OK)
+			if (sqlCursorNext(pC->uc.pCursor, &res) != 0)
 				goto abort_due_to_error;
 		} else {
 			res = 0;
@@ -3475,7 +3475,7 @@ case OP_SeekGT: {       /* jump, in3 */
 		assert(oc==OP_SeekLT || oc==OP_SeekLE);
 		if (res>0 || (res==0 && oc==OP_SeekLT)) {
 			res = 0;
-			if (sqlCursorPrevious(pC->uc.pCursor, &res) != SQL_OK)
+			if (sqlCursorPrevious(pC->uc.pCursor, &res) != 0)
 				goto abort_due_to_error;
 		} else {
 			/* res might be negative because the table is empty.  Check to
@@ -3621,8 +3621,8 @@ case OP_Found: {        /* jump, in3 */
 	rc = sqlCursorMovetoUnpacked(pC->uc.pCursor, pIdxKey, &res);
 	if (pFree != NULL)
 		sqlDbFree(db, pFree);
-	assert(rc == SQL_OK || rc == SQL_TARANTOOL_ERROR);
-	if (rc != SQL_OK)
+	assert(rc == 0 || rc == SQL_TARANTOOL_ERROR);
+	if (rc != 0)
 		goto abort_due_to_error;
 	pC->seekResult = res;
 	alreadyExists = (res==0);
@@ -4282,7 +4282,7 @@ case OP_IdxInsert: {
 
 	if (pOp->p5 & OPFLAG_OE_IGNORE) {
 		/* Ignore any kind of failes and do not raise error message */
-		rc = SQL_OK;
+		rc = 0;
 		/* If we are in trigger, increment ignore raised counter */
 		if (p->pFrame)
 			p->ignoreRaised++;
@@ -4291,7 +4291,7 @@ case OP_IdxInsert: {
 	} else if (pOp->p5 & OPFLAG_OE_ROLLBACK) {
 		p->errorAction = ON_CONFLICT_ACTION_ROLLBACK;
 	}
-	assert(rc == SQL_OK || rc == SQL_TARANTOOL_ERROR);
+	assert(rc == 0 || rc == SQL_TARANTOOL_ERROR);
 	if (rc != 0)
 		goto abort_due_to_error;
 	break;
@@ -4368,7 +4368,7 @@ case OP_Update: {
 		goto abort_due_to_error;
 	}
 
-	assert(rc == SQL_OK);
+	assert(rc == 0);
 	if (box_update(space->def->id, 0, key_mem->z, key_mem->z + key_mem->n,
 		       ops, ops + ops_size, 0, NULL) != 0)
 		rc = SQL_TARANTOOL_ERROR;
@@ -4378,7 +4378,7 @@ case OP_Update: {
 		 * Ignore any kind of fails and do not raise
 		 * error message
 		 */
-		rc = SQL_OK;
+		rc = 0;
 		/*
 		 * If we are in trigger, increment ignore raised
 		 * counter.
@@ -4390,7 +4390,7 @@ case OP_Update: {
 	} else if (pOp->p5 & OPFLAG_OE_ROLLBACK) {
 		p->errorAction = ON_CONFLICT_ACTION_ROLLBACK;
 	}
-	assert(rc == SQL_OK || rc == SQL_TARANTOOL_ERROR);
+	assert(rc == 0 || rc == SQL_TARANTOOL_ERROR);
 	if (rc != 0)
 		goto abort_due_to_error;
 	break;
@@ -5291,10 +5291,10 @@ abort_due_to_error:
 vdbe_return:
 	testcase( nVmStep>0);
 	p->aCounter[SQL_STMTSTATUS_VM_STEP] += (int)nVmStep;
-	assert(rc!=SQL_OK || nExtraDelete==0
+	assert(rc!=0 || nExtraDelete==0
 		|| sql_strlike_ci("DELETE%", p->zSql, 0) != 0
 		);
-	assert(rc == SQL_OK || rc == SQL_BUSY || rc == SQL_TARANTOOL_ERROR ||
+	assert(rc == 0 || rc == SQL_BUSY || rc == SQL_TARANTOOL_ERROR ||
 	       rc == SQL_ROW || rc == SQL_DONE);
 	return rc;
 
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index d52fc21..97204cc 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -87,7 +87,7 @@ sql_finalize(sql_stmt * pStmt)
 		/* IMPLEMENTATION-OF: R-57228-12904 Invoking sql_finalize() on a NULL
 		 * pointer is a harmless no-op.
 		 */
-		rc = SQL_OK;
+		rc = 0;
 	} else {
 		Vdbe *v = (Vdbe *) pStmt;
 		sql *db = v->db;
@@ -119,7 +119,7 @@ int
 sql_clear_bindings(sql_stmt * pStmt)
 {
 	int i;
-	int rc = SQL_OK;
+	int rc = 0;
 	Vdbe *p = (Vdbe *) pStmt;
 	for (i = 0; i < p->nVar; i++) {
 		sqlVdbeMemRelease(&p->aVar[i]);
@@ -140,7 +140,7 @@ sql_value_blob(sql_value * pVal)
 {
 	Mem *p = (Mem *) pVal;
 	if (p->flags & (MEM_Blob | MEM_Str)) {
-		if (ExpandBlob(p) != SQL_OK) {
+		if (ExpandBlob(p) != 0) {
 			assert(p->flags == MEM_Null && p->z == 0);
 			return 0;
 		}
@@ -239,7 +239,7 @@ sql_value_dup(const sql_value * pOrig)
 	if (pNew->flags & (MEM_Str | MEM_Blob)) {
 		pNew->flags &= ~(MEM_Static | MEM_Dyn);
 		pNew->flags |= MEM_Ephem;
-		if (sqlVdbeMemMakeWriteable(pNew) != SQL_OK) {
+		if (sqlVdbeMemMakeWriteable(pNew) != 0) {
 			sqlValueFree(pNew);
 			pNew = 0;
 		}
@@ -398,7 +398,7 @@ sql_result_zeroblob64(sql_context * pCtx, u64 n)
 		return SQL_TOOBIG;
 	}
 	sqlVdbeMemSetZeroBlob(pCtx->pOut, (int)n);
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -517,7 +517,7 @@ sql_step(sql_stmt * pStmt)
 	       && cnt++ < SQL_MAX_SCHEMA_RETRY) {
 		int savedPc = v->pc;
 		rc = sqlReprepare(v);
-		if (rc != SQL_OK)
+		if (rc != 0)
 			break;
 		sql_reset(pStmt);
 		if (savedPc >= 0)
@@ -981,7 +981,7 @@ sql_column_origin_name(sql_stmt * pStmt, int N)
 /*
  * Unbind the value bound to variable i in virtual machine p. This is the
  * the same as binding a NULL value to the column. If the "i" parameter is
- * out of range, then SQL_RANGE is returned. Othewise SQL_OK.
+ * out of range, then SQL_RANGE is returned. Othewise 0.
  *
  * The error code stored in database p->db is overwritten with the return
  * value in any case.
@@ -1019,7 +1019,7 @@ vdbeUnbind(Vdbe * p, int i)
 	    ) {
 		p->expired = 1;
 	}
-	return SQL_OK;
+	return 0;
 }
 
 /**
@@ -1082,11 +1082,11 @@ bindText(sql_stmt * pStmt,	/* The statement to bind against */
 	int rc;
 
 	rc = vdbeUnbind(p, i);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		if (zData != 0) {
 			pVar = &p->aVar[i - 1];
 			rc = sqlVdbeMemSetStr(pVar, zData, nData, 1, xDel);
-			if (rc == SQL_OK)
+			if (rc == 0)
 				rc = sql_bind_type(p, i, "TEXT");
 			rc = sqlApiExit(p->db, rc);
 		}
@@ -1106,11 +1106,11 @@ sql_bind_blob(sql_stmt * pStmt,
 {
 	struct Vdbe *p = (Vdbe *) pStmt;
 	int rc = vdbeUnbind(p, i);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		if (zData != 0) {
 			struct Mem *var = &p->aVar[i - 1];
 			rc = sqlVdbeMemSetStr(var, zData, nData, 0, xDel);
-			if (rc == SQL_OK)
+			if (rc == 0)
 				rc = sql_bind_type(p, i, "BLOB");
 			rc = sqlApiExit(p->db, rc);
 		}
@@ -1141,7 +1141,7 @@ sql_bind_double(sql_stmt * pStmt, int i, double rValue)
 	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
 	rc = vdbeUnbind(p, i);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		rc = sql_bind_type(p, i, "NUMERIC");
 		sqlVdbeMemSetDouble(&p->aVar[i - 1], rValue);
 	}
@@ -1153,7 +1153,7 @@ sql_bind_boolean(struct sql_stmt *stmt, int i, bool value)
 {
 	struct Vdbe *p = (struct Vdbe *) stmt;
 	int rc = vdbeUnbind(p, i);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		rc = sql_bind_type(p, i, "BOOLEAN");
 		mem_set_bool(&p->aVar[i - 1], value);
 	}
@@ -1172,7 +1172,7 @@ sql_bind_int64(sql_stmt * pStmt, int i, sql_int64 iValue)
 	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
 	rc = vdbeUnbind(p, i);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		rc = sql_bind_type(p, i, "INTEGER");
 		sqlVdbeMemSetInt64(&p->aVar[i - 1], iValue);
 	}
@@ -1185,7 +1185,7 @@ sql_bind_null(sql_stmt * pStmt, int i)
 	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
 	rc = vdbeUnbind(p, i);
-	if (rc == SQL_OK)
+	if (rc == 0)
 		rc = sql_bind_type(p, i, "BOOLEAN");
 	return rc;
 }
@@ -1195,7 +1195,7 @@ sql_bind_ptr(struct sql_stmt *stmt, int i, void *ptr)
 {
 	struct Vdbe *p = (struct Vdbe *) stmt;
 	int rc = vdbeUnbind(p, i);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		rc = sql_bind_type(p, i, "BLOB");
 		mem_set_ptr(&p->aVar[i - 1], ptr);
 	}
@@ -1231,7 +1231,7 @@ sql_bind_zeroblob(sql_stmt * pStmt, int i, int n)
 	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
 	rc = vdbeUnbind(p, i);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		sqlVdbeMemSetZeroBlob(&p->aVar[i - 1], n);
 	}
 	return rc;
@@ -1319,7 +1319,7 @@ sqlTransferBindings(sql_stmt * pFromStmt, sql_stmt * pToStmt)
 	for (i = 0; i < pFrom->nVar; i++) {
 		sqlVdbeMemMove(&pTo->aVar[i], &pFrom->aVar[i]);
 	}
-	return SQL_OK;
+	return 0;
 }
 
 /*
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index fbe5338..7f81fad 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -196,7 +196,7 @@ growOpArray(Vdbe * v, int nOp)
 		p->nOpAlloc = p->szOpAlloc / sizeof(Op);
 		v->aOp = pNew;
 	}
-	return (pNew ? SQL_OK : SQL_NOMEM);
+	return (pNew ? 0 : SQL_NOMEM);
 }
 
 #ifdef SQL_DEBUG
@@ -1415,12 +1415,12 @@ sqlVdbeList(Vdbe * p)
 	Mem *pSub = 0;		/* Memory cell hold array of subprogs */
 	sql *db = p->db;	/* The database connection */
 	int i;			/* Loop counter */
-	int rc = SQL_OK;	/* Return code */
+	int rc = 0;	/* Return code */
 	Mem *pMem = &p->aMem[1];	/* First Mem of result set */
 
 	assert(p->explain);
 	assert(p->magic == VDBE_MAGIC_RUN);
-	assert(p->rc == SQL_OK || p->rc == SQL_BUSY
+	assert(p->rc == 0 || p->rc == SQL_BUSY
 	       || p->rc == SQL_NOMEM);
 
 	/* Even though this opcode does not use dynamic strings for
@@ -1470,7 +1470,7 @@ sqlVdbeList(Vdbe * p)
 		i = p->pc++;
 	} while (i < nRow && p->explain == 2 && p->aOp[i].opcode != OP_Explain);
 	if (i >= nRow) {
-		p->rc = SQL_OK;
+		p->rc = 0;
 		rc = SQL_DONE;
 	} else {
 		char *zP4;
@@ -1515,7 +1515,7 @@ sqlVdbeList(Vdbe * p)
 						break;
 				}
 				if (j == nSub
-				    && SQL_OK == sqlVdbeMemGrow(pSub,
+				    && 0 == sqlVdbeMemGrow(pSub,
 								       nByte,
 								       nSub !=
 								       0)) {
@@ -1579,7 +1579,7 @@ sqlVdbeList(Vdbe * p)
 
 		p->nResColumn = 8 - 4 * (p->explain - 1);
 		p->pResultSet = &p->aMem[1];
-		p->rc = SQL_OK;
+		p->rc = 0;
 		rc = SQL_ROW;
 	}
 	return rc;
@@ -1713,7 +1713,7 @@ sqlVdbeRewind(Vdbe * p)
 	}
 #endif
 	p->pc = -1;
-	p->rc = SQL_OK;
+	p->rc = 0;
 	p->ignoreRaised = 0;
 	p->errorAction = ON_CONFLICT_ACTION_ABORT;
 	p->nChange = 0;
@@ -2066,12 +2066,12 @@ checkActiveVdbeCnt(sql * db)
  * statement transaction is committed.
  *
  * If an IO error occurs, an SQL_IOERR_XXX error code is returned.
- * Otherwise SQL_OK.
+ * Otherwise 0.
  */
 int
 sqlVdbeCloseStatement(Vdbe * p, int eOp)
 {
-	int rc = SQL_OK;
+	int rc = 0;
 	const Savepoint *savepoint = p->anonymous_savepoint;
 	/*
 	 * If we have an anonymous transaction opened -> perform eOp.
@@ -2086,7 +2086,7 @@ sqlVdbeCloseStatement(Vdbe * p, int eOp)
  * This function is called when a transaction opened by the database
  * handle associated with the VM passed as an argument is about to be
  * committed. If there are outstanding deferred foreign key constraint
- * violations, return SQL_ERROR. Otherwise, SQL_OK.
+ * violations, return SQL_ERROR. Otherwise, 0.
  *
  * If there are outstanding FK violations and this function returns
  * SQL_ERROR, set the result of the VM to SQL_CONSTRAINT_FOREIGNKEY
@@ -2105,7 +2105,7 @@ sqlVdbeCheckFk(Vdbe * p, int deferred)
 			 "failed");
 		return SQL_TARANTOOL_ERROR;
 	}
-	return SQL_OK;
+	return 0;
 }
 
 int
@@ -2191,7 +2191,7 @@ sqlVdbeHalt(Vdbe * p)
 	}
 	closeTopFrameCursors(p);
 	if (p->magic != VDBE_MAGIC_RUN) {
-		return SQL_OK;
+		return 0;
 	}
 	checkActiveVdbeCnt(db);
 
@@ -2234,7 +2234,7 @@ sqlVdbeHalt(Vdbe * p)
 		}
 
 		/* Check for immediate foreign key violations. */
-		if (p->rc == SQL_OK) {
+		if (p->rc == 0) {
 			sqlVdbeCheckFk(p, 0);
 		}
 
@@ -2245,11 +2245,11 @@ sqlVdbeHalt(Vdbe * p)
 		 * above has occurred.
 		 */
 		if (p->auto_commit) {
-			if (p->rc == SQL_OK
+			if (p->rc == 0
 			    || (p->errorAction == ON_CONFLICT_ACTION_FAIL
 				&& !isSpecialError)) {
 				rc = sqlVdbeCheckFk(p, 1);
-				if (rc != SQL_OK) {
+				if (rc != 0) {
 					/* Close all opened cursors if
 					 * they exist and free all
 					 * VDBE frames.
@@ -2267,13 +2267,13 @@ sqlVdbeHalt(Vdbe * p)
 					 */
 					rc = (in_txn() == NULL ||
 					      txn_commit(in_txn()) == 0) ?
-					     SQL_OK : SQL_TARANTOOL_ERROR;
+					     0 : SQL_TARANTOOL_ERROR;
 					closeCursorsAndFree(p);
 				}
 				if (rc == SQL_BUSY && !p->pDelFrame) {
 					closeCursorsAndFree(p);
 					return SQL_BUSY;
-				} else if (rc != SQL_OK) {
+				} else if (rc != 0) {
 					p->rc = rc;
 					box_txn_rollback();
 					closeCursorsAndFree(p);
@@ -2288,7 +2288,7 @@ sqlVdbeHalt(Vdbe * p)
 			}
 			p->anonymous_savepoint = NULL;
 		} else if (eStatementOp == 0) {
-			if (p->rc == SQL_OK || p->errorAction == ON_CONFLICT_ACTION_FAIL) {
+			if (p->rc == 0 || p->errorAction == ON_CONFLICT_ACTION_FAIL) {
 				eStatementOp = SAVEPOINT_RELEASE;
 			} else if (p->errorAction == ON_CONFLICT_ACTION_ABORT) {
 				eStatementOp = SAVEPOINT_ROLLBACK;
@@ -2304,14 +2304,14 @@ sqlVdbeHalt(Vdbe * p)
 		/* If eStatementOp is non-zero, then a statement transaction needs to
 		 * be committed or rolled back. Call sqlVdbeCloseStatement() to
 		 * do so. If this operation returns an error, and the current statement
-		 * error code is SQL_OK or SQL_CONSTRAINT, then promote the
+		 * error code is 0 or SQL_CONSTRAINT, then promote the
 		 * current statement error code.
 		 */
 		if (eStatementOp) {
 			rc = sqlVdbeCloseStatement(p, eStatementOp);
 			if (rc) {
 				box_txn_rollback();
-				if (p->rc == SQL_OK
+				if (p->rc == 0
 				    || (p->rc & 0xff) == SQL_CONSTRAINT) {
 					p->rc = rc;
 				}
@@ -2350,17 +2350,17 @@ sqlVdbeHalt(Vdbe * p)
 
 	assert(db->nVdbeActive > 0 || box_txn() ||
 	       p->anonymous_savepoint == NULL);
-	return (p->rc == SQL_BUSY ? SQL_BUSY : SQL_OK);
+	return (p->rc == SQL_BUSY ? SQL_BUSY : 0);
 }
 
 /*
  * Each VDBE holds the result of the most recent sql_step() call
- * in p->rc.  This routine sets that result back to SQL_OK.
+ * in p->rc.  This routine sets that result back to 0.
  */
 void
 sqlVdbeResetStepResult(Vdbe * p)
 {
-	p->rc = SQL_OK;
+	p->rc = 0;
 }
 
 /*
@@ -2461,7 +2461,7 @@ sqlVdbeReset(Vdbe * p)
 int
 sqlVdbeFinalize(Vdbe * p)
 {
-	int rc = SQL_OK;
+	int rc = 0;
 	if (p->magic == VDBE_MAGIC_RUN || p->magic == VDBE_MAGIC_HALT) {
 		rc = sqlVdbeReset(p);
 		assert((rc & p->db->errMask) == rc);
@@ -2989,7 +2989,7 @@ sql_vdbe_mem_alloc_region(Mem *vdbe_mem, uint32_t size)
 		return SQL_NOMEM;
 	vdbe_mem->flags = MEM_Ephem | MEM_Blob;
 	assert(sqlVdbeCheckMemInvariants(vdbe_mem));
-	return SQL_OK;
+	return 0;
 }
 
 /*
diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
index 2bb9bd3..2f7fe4f 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -146,7 +146,7 @@ sqlVdbeMemGrow(Mem * pMem, int n, int bPreserve)
 
 	pMem->z = pMem->zMalloc;
 	pMem->flags &= ~(MEM_Dyn | MEM_Ephem | MEM_Static);
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -159,7 +159,7 @@ sqlVdbeMemGrow(Mem * pMem, int n, int bPreserve)
  * and MEM_Blob values may be discarded, MEM_Int, MEM_Real, and MEM_Null
  * values are preserved.
  *
- * Return SQL_OK on success or an error code (probably SQL_NOMEM)
+ * Return 0 on success or an error code (probably SQL_NOMEM)
  * if unable to complete the resizing.
  */
 int
@@ -173,14 +173,14 @@ sqlVdbeMemClearAndResize(Mem * pMem, int szNew)
 	assert((pMem->flags & MEM_Dyn) == 0);
 	pMem->z = pMem->zMalloc;
 	pMem->flags &= (MEM_Null | MEM_Int | MEM_Real);
-	return SQL_OK;
+	return 0;
 }
 
 /*
  * Change pMem so that its MEM_Str or MEM_Blob value is stored in
  * MEM.zMalloc, where it can be safely written.
  *
- * Return SQL_OK on success or SQL_NOMEM if malloc fails.
+ * Return 0 on success or SQL_NOMEM if malloc fails.
  */
 int
 sqlVdbeMemMakeWriteable(Mem * pMem)
@@ -202,7 +202,7 @@ sqlVdbeMemMakeWriteable(Mem * pMem)
 	pMem->pScopyFrom = 0;
 #endif
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -228,7 +228,7 @@ sqlVdbeMemExpandBlob(Mem * pMem)
 	memset(&pMem->z[pMem->n], 0, pMem->u.nZero);
 	pMem->n += pMem->u.nZero;
 	pMem->flags &= ~(MEM_Zero | MEM_Term);
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -244,7 +244,7 @@ vdbeMemAddTerminator(Mem * pMem)
 	pMem->z[pMem->n] = 0;
 	pMem->z[pMem->n + 1] = 0;
 	pMem->flags |= MEM_Term;
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -256,7 +256,7 @@ sqlVdbeMemNulTerminate(Mem * pMem)
 	testcase((pMem->flags & (MEM_Term | MEM_Str)) == (MEM_Term | MEM_Str));
 	testcase((pMem->flags & (MEM_Term | MEM_Str)) == 0);
 	if ((pMem->flags & (MEM_Term | MEM_Str)) != MEM_Str) {
-		return SQL_OK;	/* Nothing to do */
+		return 0;	/* Nothing to do */
 	} else {
 		return vdbeMemAddTerminator(pMem);
 	}
@@ -283,7 +283,7 @@ sqlVdbeMemStringify(Mem * pMem, u8 bForce)
 	const int nByte = 32;
 
 	if ((fg & (MEM_Null | MEM_Str | MEM_Blob)) != 0)
-		return SQL_OK;
+		return 0;
 
 	assert(!(fg & MEM_Zero));
 	assert(fg & (MEM_Int | MEM_Real | MEM_Bool));
@@ -304,7 +304,7 @@ sqlVdbeMemStringify(Mem * pMem, u8 bForce)
 	pMem->flags |= MEM_Str | MEM_Term;
 	if (bForce)
 		pMem->flags &= ~(MEM_Int | MEM_Real);
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -566,7 +566,7 @@ sqlVdbeMemRealify(Mem * pMem)
 
 	pMem->u.r = v;
 	MemSetTypeFlag(pMem, MEM_Real);
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -595,7 +595,7 @@ sqlVdbeMemNumerify(Mem * pMem)
 	}
 	assert((pMem->flags & (MEM_Int | MEM_Real | MEM_Null)) != 0);
 	pMem->flags &= ~(MEM_Str | MEM_Blob | MEM_Zero);
-	return SQL_OK;
+	return 0;
 }
 
 /**
@@ -645,7 +645,7 @@ sqlVdbeMemCast(Mem * pMem, enum field_type type)
 {
 	assert(type < field_type_MAX);
 	if (pMem->flags & MEM_Null)
-		return SQL_OK;
+		return 0;
 	if ((pMem->flags & MEM_Blob) != 0 && type == FIELD_TYPE_NUMBER) {
 		if (sql_atoi64(pMem->z, (int64_t *) &pMem->u.i, pMem->n) == 0) {
 			MemSetTypeFlag(pMem, MEM_Real);
@@ -705,7 +705,7 @@ sqlVdbeMemCast(Mem * pMem, enum field_type type)
 			sql_value_apply_type(pMem, FIELD_TYPE_STRING);
 		assert(pMem->flags & MEM_Str || pMem->db->mallocFailed);
 		pMem->flags &= ~(MEM_Int | MEM_Real | MEM_Blob | MEM_Zero);
-		return SQL_OK;
+		return 0;
 	}
 }
 
@@ -904,7 +904,7 @@ sqlVdbeMemShallowCopy(Mem * pTo, const Mem * pFrom, int srcType)
 int
 sqlVdbeMemCopy(Mem * pTo, const Mem * pFrom)
 {
-	int rc = SQL_OK;
+	int rc = 0;
 
 	if (VdbeMemDynamic(pTo))
 		vdbeMemClearExternAndSetNull(pTo);
@@ -967,7 +967,7 @@ sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
 	/* If z is a NULL pointer, set pMem to contain an SQL NULL. */
 	if (!z) {
 		sqlVdbeMemSetNull(pMem);
-		return SQL_OK;
+		return 0;
 	}
 
 	if (pMem->db) {
@@ -1021,7 +1021,7 @@ sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
 		return SQL_TOOBIG;
 	}
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -1048,9 +1048,9 @@ vdbeMemFromBtreeResize(BtCursor * pCur,	/* Cursor pointing at record to retrieve
 {
 	int rc;
 	pMem->flags = MEM_Null;
-	if (SQL_OK == (rc = sqlVdbeMemClearAndResize(pMem, amt + 2))) {
+	if (0 == (rc = sqlVdbeMemClearAndResize(pMem, amt + 2))) {
 		rc = sqlCursorPayload(pCur, offset, amt, pMem->z);
-		if (rc == SQL_OK) {
+		if (rc == 0) {
 			pMem->z[amt] = 0;
 			pMem->z[amt + 1] = 0;
 			pMem->flags = MEM_Blob | MEM_Term;
@@ -1071,7 +1071,7 @@ sqlVdbeMemFromBtree(BtCursor * pCur,	/* Cursor pointing at record to retrieve. *
 {
 	char *zData;		/* Data from the btree layer */
 	u32 available = 0;	/* Number of bytes available on the local btree page */
-	int rc = SQL_OK;	/* Return code */
+	int rc = 0;	/* Return code */
 
 	assert(sqlCursorIsValid(pCur));
 	assert(!VdbeMemDynamic(pMem));
@@ -1223,13 +1223,13 @@ valueNew(sql * db, struct ValueNewStat4Ctx *p)
  *
  * then this routine attempts to invoke the SQL function. Assuming no
  * error occurs, output parameter (*ppVal) is set to point to a value
- * object containing the result before returning SQL_OK.
+ * object containing the result before returning 0.
  *
  * Type @type is applied to the result of the function before returning.
  * If the result is a text value, the sql_value object uses encoding
  * enc.
  *
- * If the conditions above are not met, this function returns SQL_OK
+ * If the conditions above are not met, this function returns 0
  * and sets (*ppVal) to NULL. Or, if an error occurs, (*ppVal) is set to
  * NULL and an sql error code returned.
  */
@@ -1246,7 +1246,7 @@ valueFromFunction(sql * db,	/* The database connection */
 	int nVal = 0;		/* Size of apVal[] array */
 	FuncDef *pFunc = 0;	/* Function definition */
 	sql_value *pVal = 0;	/* New value */
-	int rc = SQL_OK;	/* Return code */
+	int rc = 0;	/* Return code */
 	ExprList *pList = 0;	/* Function arguments */
 	int i;			/* Iterator variable */
 
@@ -1260,7 +1260,7 @@ valueFromFunction(sql * db,	/* The database connection */
 	if ((pFunc->funcFlags & (SQL_FUNC_CONSTANT | SQL_FUNC_SLOCHNG)) ==
 	    0 || (pFunc->funcFlags & SQL_FUNC_NEEDCOLL)
 	    ) {
-		return SQL_OK;
+		return 0;
 	}
 
 	if (pList) {
@@ -1275,7 +1275,7 @@ valueFromFunction(sql * db,	/* The database connection */
 		for (i = 0; i < nVal; i++) {
 			rc = sqlValueFromExpr(db, pList->a[i].pExpr,
 						  type, &apVal[i]);
-			if (apVal[i] == 0 || rc != SQL_OK)
+			if (apVal[i] == 0 || rc != 0)
 				goto value_from_function_out;
 		}
 	}
@@ -1293,10 +1293,10 @@ valueFromFunction(sql * db,	/* The database connection */
 	pFunc->xSFunc(&ctx, nVal, apVal);
 	assert(!ctx.is_aborted);
 	sql_value_apply_type(pVal, type);
-	assert(rc == SQL_OK);
+	assert(rc == 0);
 
  value_from_function_out:
-	if (rc != SQL_OK) {
+	if (rc != 0) {
 		pVal = 0;
 	}
 	if (apVal) {
@@ -1333,7 +1333,7 @@ valueFromExpr(sql * db,	/* The database connection */
 	sql_value *pVal = 0;
 	int negInt = 1;
 	const char *zNeg = "";
-	int rc = SQL_OK;
+	int rc = 0;
 
 	assert(pExpr != 0);
 	while ((op = pExpr->op) == TK_UPLUS || op == TK_SPAN)
@@ -1350,7 +1350,7 @@ valueFromExpr(sql * db,	/* The database connection */
 
 	if (op == TK_CAST) {
 		rc = valueFromExpr(db, pExpr->pLeft, pExpr->type, ppVal, pCtx);
-		testcase(rc != SQL_OK);
+		testcase(rc != 0);
 		if (*ppVal) {
 			sqlVdbeMemCast(*ppVal, pExpr->type);
 			sql_value_apply_type(*ppVal, type);
@@ -1394,10 +1394,10 @@ valueFromExpr(sql * db,	/* The database connection */
 			pVal->flags &= ~MEM_Str;
 	} else if (op == TK_UMINUS) {
 		/* This branch happens for multiple negative signs.  Ex: -(-5) */
-		if (SQL_OK ==
+		if (0 ==
 		    sqlValueFromExpr(db, pExpr->pLeft, type, &pVal)
 		    && pVal != 0) {
-			if ((rc = sqlVdbeMemNumerify(pVal)) != SQL_OK)
+			if ((rc = sqlVdbeMemNumerify(pVal)) != 0)
 				return rc;
 			if (pVal->flags & MEM_Real) {
 				pVal->u.r = -pVal->u.r;
@@ -1413,7 +1413,7 @@ valueFromExpr(sql * db,	/* The database connection */
 		pVal = valueNew(db, pCtx);
 		if (pVal == 0)
 			goto no_mem;
-		if ((rc = sqlVdbeMemNumerify(pVal)) != SQL_OK)
+		if ((rc = sqlVdbeMemNumerify(pVal)) != 0)
 			return rc;
 	}
 #ifndef SQL_OMIT_BLOB_LITERAL
@@ -1545,7 +1545,7 @@ stat4ValueFromExpr(Parse * pParse,	/* Parse context */
 		   sql_value ** ppVal	/* OUT: New value object (or NULL) */
     )
 {
-	int rc = SQL_OK;
+	int rc = 0;
 	sql_value *pVal = 0;
 	sql *db = pParse->db;
 
@@ -1569,7 +1569,7 @@ stat4ValueFromExpr(Parse * pParse,	/* Parse context */
 			if (pVal) {
 				rc = sqlVdbeMemCopy((Mem *) pVal,
 							&v->aVar[iBindVar - 1]);
-				if (rc == SQL_OK) {
+				if (rc == 0) {
 					sql_value_apply_type(pVal, type);
 				}
 				pVal->db = pParse->db;
@@ -1614,7 +1614,7 @@ stat4ValueFromExpr(Parse * pParse,	/* Parse context */
  * is NULL and a value can be successfully extracted, a new UnpackedRecord
  * is allocated (and *ppRec set to point to it) before returning.
  *
- * Unless an error is encountered, SQL_OK is returned. It is not an
+ * Unless an error is encountered, 0 is returned. It is not an
  * error if a value cannot be extracted from pExpr. If an error does
  * occur, an sql error code is returned.
  */
@@ -1628,7 +1628,7 @@ sqlStat4ProbeSetValue(Parse * pParse,	/* Parse context */
 			  int *pnExtract	/* OUT: Values appended to the record */
     )
 {
-	int rc = SQL_OK;
+	int rc = 0;
 	int nExtract = 0;
 
 	if (pExpr == 0 || pExpr->op != TK_SELECT) {
@@ -1663,8 +1663,8 @@ sqlStat4ProbeSetValue(Parse * pParse,	/* Parse context */
  * as described for sqlStat4ProbeSetValue() above.
  *
  * If successful, set *ppVal to point to a new value object and return
- * SQL_OK. If no value can be extracted, but no other error occurs
- * (e.g. OOM), return SQL_OK and set *ppVal to NULL. Or, if an error
+ * 0. If no value can be extracted, but no other error occurs
+ * (e.g. OOM), return 0 and set *ppVal to NULL. Or, if an error
  * does occur, return an sql error code. The final value of *ppVal
  * is undefined in this case.
  */
diff --git a/src/box/sql/vdbesort.c b/src/box/sql/vdbesort.c
index da9ee3e..f7fc8e1 100644
--- a/src/box/sql/vdbesort.c
+++ b/src/box/sql/vdbesort.c
@@ -500,7 +500,7 @@ vdbePmaReaderClear(PmaReader * pReadr)
 /*
  * Read the next nByte bytes of data from the PMA p.
  * If successful, set *ppOut to point to a buffer containing the data
- * and return SQL_OK. Otherwise, if an error occurs, return an sql
+ * and return 0. Otherwise, if an error occurs, return an sql
  * error code.
  *
  * The buffer returned in *ppOut is only valid until the
@@ -518,7 +518,7 @@ vdbePmaReadBlob(PmaReader * p,	/* PmaReader from which to take the blob */
 	if (p->aMap) {
 		*ppOut = &p->aMap[p->iReadOff];
 		p->iReadOff += nByte;
-		return SQL_OK;
+		return 0;
 	}
 
 	assert(p->aBuffer);
@@ -543,7 +543,7 @@ vdbePmaReadBlob(PmaReader * p,	/* PmaReader from which to take the blob */
 		/* Readr data from the file. Return early if an error occurs. */
 		rc = sqlOsRead(p->pFd, p->aBuffer, nRead, p->iReadOff);
 		assert(rc != SQL_IOERR_SHORT_READ);
-		if (rc != SQL_OK)
+		if (rc != 0)
 			return rc;
 	}
 	nAvail = p->nBuffer - iBuf;
@@ -594,7 +594,7 @@ vdbePmaReadBlob(PmaReader * p,	/* PmaReader from which to take the blob */
 			if (nRem > p->nBuffer)
 				nCopy = p->nBuffer;
 			rc = vdbePmaReadBlob(p, nCopy, &aNext);
-			if (rc != SQL_OK)
+			if (rc != 0)
 				return rc;
 			assert(aNext != p->aAlloc);
 			memcpy(&p->aAlloc[nByte - nRem], aNext, nCopy);
@@ -604,7 +604,7 @@ vdbePmaReadBlob(PmaReader * p,	/* PmaReader from which to take the blob */
 		*ppOut = p->aAlloc;
 	}
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -636,14 +636,14 @@ vdbePmaReadVarint(PmaReader * p, u64 * pnOut)
 		}
 	}
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
  * Attempt to memory map file pFile. If successful, set *pp to point to the
- * new mapping and return SQL_OK. If the mapping is not attempted
+ * new mapping and return 0. If the mapping is not attempted
  * (because the file is too large or the VFS layer is configured not to use
- * mmap), return SQL_OK and set *pp to NULL.
+ * mmap), return 0 and set *pp to NULL.
  *
  * Or, if an error occurs, return an sql error code. The final value of
  * *pp is undefined in this case.
@@ -651,13 +651,13 @@ vdbePmaReadVarint(PmaReader * p, u64 * pnOut)
 static int
 vdbeSorterMapFile(SortSubtask * pTask, SorterFile * pFile, u8 ** pp)
 {
-	int rc = SQL_OK;
+	int rc = 0;
 	if (pFile->iEof <= (i64) (pTask->pSorter->db->nMaxSorterMmap)) {
 		sql_file *pFd = pFile->pFd;
 		if (pFd->pMethods->iVersion >= 3) {
 			rc = sqlOsFetch(pFd, 0, (int)pFile->iEof,
 					    (void **)pp);
-			testcase(rc != SQL_OK);
+			testcase(rc != 0);
 		}
 	}
 	return rc;
@@ -665,7 +665,7 @@ vdbeSorterMapFile(SortSubtask * pTask, SorterFile * pFile, u8 ** pp)
 
 /*
  * Attach PmaReader pReadr to file pFile (if it is not already attached to
- * that file) and seek it to offset iOff within the file.  Return SQL_OK
+ * that file) and seek it to offset iOff within the file.  Return 0
  * if successful, or an sql error code if an error occurs.
  */
 static int
@@ -675,7 +675,7 @@ vdbePmaReaderSeek(SortSubtask * pTask,	/* Task context */
 		  i64 iOff	/* Offset in pFile */
     )
 {
-	int rc = SQL_OK;
+	int rc = 0;
 
 	assert(pReadr->pIncr == 0 || pReadr->pIncr->bEof == 0);
 
@@ -688,7 +688,7 @@ vdbePmaReaderSeek(SortSubtask * pTask,	/* Task context */
 	pReadr->pFd = pFile->pFd;
 
 	rc = vdbeSorterMapFile(pTask, pFile, &pReadr->aMap);
-	if (rc == SQL_OK && pReadr->aMap == 0) {
+	if (rc == 0 && pReadr->aMap == 0) {
 		int pgsz = pTask->pSorter->pgsz;
 		int iBuf = pReadr->iReadOff % pgsz;
 		if (pReadr->aBuffer == 0) {
@@ -697,14 +697,14 @@ vdbePmaReaderSeek(SortSubtask * pTask,	/* Task context */
 				rc = SQL_NOMEM;
 			pReadr->nBuffer = pgsz;
 		}
-		if (rc == SQL_OK && iBuf) {
+		if (rc == 0 && iBuf) {
 			int nRead = pgsz - iBuf;
 			if ((pReadr->iReadOff + nRead) > pReadr->iEof) {
 				nRead = (int)(pReadr->iEof - pReadr->iReadOff);
 			}
 			rc = sqlOsRead(pReadr->pFd, &pReadr->aBuffer[iBuf],
 					   nRead, pReadr->iReadOff);
-			testcase(rc != SQL_OK);
+			testcase(rc != 0);
 		}
 	}
 
@@ -712,13 +712,13 @@ vdbePmaReaderSeek(SortSubtask * pTask,	/* Task context */
 }
 
 /*
- * Advance PmaReader pReadr to the next key in its PMA. Return SQL_OK if
+ * Advance PmaReader pReadr to the next key in its PMA. Return 0 if
  * no error occurs, or an sql error code if one does.
  */
 static int
 vdbePmaReaderNext(PmaReader * pReadr)
 {
-	int rc = SQL_OK;	/* Return Code */
+	int rc = 0;	/* Return Code */
 	u64 nRec = 0;		/* Size of record in bytes */
 
 	if (pReadr->iReadOff >= pReadr->iEof) {
@@ -726,7 +726,7 @@ vdbePmaReaderNext(PmaReader * pReadr)
 		int bEof = 1;
 		if (pIncr) {
 			rc = vdbeIncrSwap(pIncr);
-			if (rc == SQL_OK && pIncr->bEof == 0) {
+			if (rc == 0 && pIncr->bEof == 0) {
 				rc = vdbePmaReaderSeek(pIncr->pTask, pReadr,
 						       &pIncr->aFile[0],
 						       pIncr->iStartOff);
@@ -737,18 +737,18 @@ vdbePmaReaderNext(PmaReader * pReadr)
 		if (bEof) {
 			/* This is an EOF condition */
 			vdbePmaReaderClear(pReadr);
-			testcase(rc != SQL_OK);
+			testcase(rc != 0);
 			return rc;
 		}
 	}
 
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		rc = vdbePmaReadVarint(pReadr, &nRec);
 	}
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		pReadr->nKey = (int)nRec;
 		rc = vdbePmaReadBlob(pReadr, (int)nRec, &pReadr->aKey);
-		testcase(rc != SQL_OK);
+		testcase(rc != 0);
 	}
 
 	return rc;
@@ -779,14 +779,14 @@ vdbePmaReaderInit(SortSubtask * pTask,	/* Task context */
 	assert(pReadr->aMap == 0);
 
 	rc = vdbePmaReaderSeek(pTask, pReadr, pFile, iStart);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		u64 nByte = 0;	/* Size of PMA in bytes */
 		rc = vdbePmaReadVarint(pReadr, &nByte);
 		pReadr->iEof = pReadr->iReadOff + nByte;
 		*pnByte += nByte;
 	}
 
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		rc = vdbePmaReaderNext(pReadr);
 	}
 	return rc;
@@ -842,7 +842,7 @@ vdbeSorterCompare(struct SortSubtask *task, bool *key2_cached,
  * The sorter can guarantee a stable sort when running in single-threaded
  * mode, but not in multi-threaded mode.
  *
- * SQL_OK is returned if successful, or an sql error code otherwise.
+ * 0 is returned if successful, or an sql error code otherwise.
  */
 int
 sqlVdbeSorterInit(sql * db,	/* Database connection (for malloc()) */
@@ -852,7 +852,7 @@ sqlVdbeSorterInit(sql * db,	/* Database connection (for malloc()) */
 	int pgsz;		/* Page size of main database */
 	int i;			/* Used to iterate through aTask[] */
 	VdbeSorter *pSorter;	/* The new sorter */
-	int rc = SQL_OK;
+	int rc = 0;
 #if SQL_MAX_WORKER_THREADS==0
 #define nWorker 0
 #else
@@ -1022,7 +1022,7 @@ vdbeSorterBlockDebug(SortSubtask * pTask, int bBlocked, const char *zEvent)
 static int
 vdbeSorterJoinThread(SortSubtask * pTask)
 {
-	int rc = SQL_OK;
+	int rc = 0;
 	if (pTask->pThread) {
 #ifdef SQL_DEBUG_SORTER_THREADS
 		int bDone = pTask->bDone;
@@ -1073,14 +1073,14 @@ vdbeSorterJoinAll(VdbeSorter * pSorter, int rcin)
 	for (i = pSorter->nTask - 1; i >= 0; i--) {
 		SortSubtask *pTask = &pSorter->aTask[i];
 		int rc2 = vdbeSorterJoinThread(pTask);
-		if (rc == SQL_OK)
+		if (rc == 0)
 			rc = rc2;
 	}
 	return rc;
 }
 #else
 #define vdbeSorterJoinAll(x,rcin) (rcin)
-#define vdbeSorterJoinThread(pTask) SQL_OK
+#define vdbeSorterJoinThread(pTask) 0
 #endif
 
 /*
@@ -1157,7 +1157,7 @@ void
 sqlVdbeSorterReset(sql * db, VdbeSorter * pSorter)
 {
 	int i;
-	(void)vdbeSorterJoinAll(pSorter, SQL_OK);
+	(void)vdbeSorterJoinAll(pSorter, 0);
 	assert(pSorter->bUseThreads || pSorter->pReader == 0);
 #if SQL_MAX_WORKER_THREADS>0
 	if (pSorter->pReader) {
@@ -1231,7 +1231,7 @@ vdbeSorterExtendFile(sql * db, sql_file * pFd, i64 nByte)
 
 /*
  * Allocate space for a file-handle and open a temporary file. If successful,
- * set *ppFd to point to the malloc'd file-handle and return SQL_OK.
+ * set *ppFd to point to the malloc'd file-handle and return 0.
  * Otherwise, set *ppFd to 0 and return an sql error code.
  */
 static int
@@ -1244,7 +1244,7 @@ vdbeSorterOpenTempFile(sql * db,	/* Database handle doing sort */
 				 SQL_OPEN_READWRITE | SQL_OPEN_CREATE |
 				 SQL_OPEN_EXCLUSIVE |
 				 SQL_OPEN_DELETEONCLOSE, &rc);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		i64 max = SQL_MAX_MMAP_SIZE;
 		sqlOsFileControlHint(*ppFd, SQL_FCNTL_MMAP_SIZE,
 					 (void *)&max);
@@ -1257,7 +1257,7 @@ vdbeSorterOpenTempFile(sql * db,	/* Database handle doing sort */
 
 /*
  * If it has not already been allocated, allocate the UnpackedRecord
- * structure at pTask->pUnpacked. Return SQL_OK if successful (or
+ * structure at pTask->pUnpacked. Return 0 if successful (or
  * if no allocation was required), or SQL_NOMEM otherwise.
  */
 static int
@@ -1272,7 +1272,7 @@ vdbeSortAllocUnpacked(SortSubtask * pTask)
 		pTask->pUnpacked->nField = pTask->pSorter->key_def->part_count;
 		pTask->pUnpacked->errCode = 0;
 	}
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -1330,7 +1330,7 @@ vdbeSorterGetCompare(VdbeSorter * p)
 
 /*
  * Sort the linked list of records headed at pTask->pList. Return
- * SQL_OK if successful, or an sql error code (i.e. SQL_NOMEM) if
+ * 0 if successful, or an sql error code (i.e. SQL_NOMEM) if
  * an error occurs.
  */
 static int
@@ -1342,7 +1342,7 @@ vdbeSorterSort(SortSubtask * pTask, SorterList * pList)
 	int rc;
 
 	rc = vdbeSortAllocUnpacked(pTask);
-	if (rc != SQL_OK)
+	if (rc != 0)
 		return rc;
 
 	p = pList->pList;
@@ -1388,7 +1388,7 @@ vdbeSorterSort(SortSubtask * pTask, SorterList * pList)
 	pList->pList = p;
 
 	sql_free(aSlot);
-	assert(pTask->pUnpacked->errCode == SQL_OK
+	assert(pTask->pUnpacked->errCode == 0
 	       || pTask->pUnpacked->errCode == SQL_NOMEM);
 	return pTask->pUnpacked->errCode;
 }
@@ -1416,7 +1416,7 @@ vdbePmaWriterInit(sql_file * pFd,	/* File handle to write to */
 }
 
 /*
- * Write nData bytes of data to the PMA. Return SQL_OK
+ * Write nData bytes of data to the PMA. Return 0
  * if successful, or an sql error code if an error occurs.
  */
 static void
@@ -1448,7 +1448,7 @@ vdbePmaWriteBlob(PmaWriter * p, u8 * pData, int nData)
 /*
  * Flush any buffered data to disk and clean up the PMA-writer object.
  * The results of using the PMA-writer after this call are undefined.
- * Return SQL_OK if flushing the buffered data succeeds or is not
+ * Return 0 if flushing the buffered data succeeds or is not
  * required. Otherwise, return an sql error code.
  *
  * Before returning, set *piEof to the offset immediately following the
@@ -1473,7 +1473,7 @@ vdbePmaWriterFinish(PmaWriter * p, i64 * piEof)
 
 /*
  * Write value iVal encoded as a varint to the PMA. Return
- * SQL_OK if successful, or an sql error code if an error occurs.
+ * 0 if successful, or an sql error code if an error occurs.
  */
 static void
 vdbePmaWriteVarint(PmaWriter * p, u64 iVal)
@@ -1486,7 +1486,7 @@ vdbePmaWriteVarint(PmaWriter * p, u64 iVal)
 
 /*
  * Write the current contents of in-memory linked-list pList to a level-0
- * PMA in the temp file belonging to sub-task pTask. Return SQL_OK if
+ * PMA in the temp file belonging to sub-task pTask. Return 0 if
  * successful, or an sql error code otherwise.
  *
  * The format of a PMA is:
@@ -1502,7 +1502,7 @@ static int
 vdbeSorterListToPMA(SortSubtask * pTask, SorterList * pList)
 {
 	sql *db = pTask->pSorter->db;
-	int rc = SQL_OK;	/* Return code */
+	int rc = 0;	/* Return code */
 	PmaWriter writer;	/* Object used to write to the file */
 
 #ifdef SQL_DEBUG
@@ -1520,23 +1520,23 @@ vdbeSorterListToPMA(SortSubtask * pTask, SorterList * pList)
 	/* If the first temporary PMA file has not been opened, open it now. */
 	if (pTask->file.pFd == 0) {
 		rc = vdbeSorterOpenTempFile(db, 0, &pTask->file.pFd);
-		assert(rc != SQL_OK || pTask->file.pFd);
+		assert(rc != 0 || pTask->file.pFd);
 		assert(pTask->file.iEof == 0);
 		assert(pTask->nPMA == 0);
 	}
 
 	/* Try to get the file to memory map */
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		vdbeSorterExtendFile(db, pTask->file.pFd,
 				     pTask->file.iEof + pList->szPMA + 9);
 	}
 
 	/* Sort the list */
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		rc = vdbeSorterSort(pTask, pList);
 	}
 
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		SorterRecord *p;
 		SorterRecord *pNext = 0;
 
@@ -1556,8 +1556,8 @@ vdbeSorterListToPMA(SortSubtask * pTask, SorterList * pList)
 	}
 
 	vdbeSorterWorkDebug(pTask, "exit");
-	assert(rc != SQL_OK || pList->pList == 0);
-	assert(rc != SQL_OK || pTask->file.iEof == iSz);
+	assert(rc != 0 || pList->pList == 0);
+	assert(rc != 0 || pTask->file.iEof == iSz);
 	return rc;
 }
 
@@ -1566,7 +1566,7 @@ vdbeSorterListToPMA(SortSubtask * pTask, SorterList * pList)
  * Set *pbEof to true there is no next entry because
  * the MergeEngine has reached the end of all its inputs.
  *
- * Return SQL_OK if successful or an error code if an error occurs.
+ * Return 0 if successful or an error code if an error occurs.
  */
 static int
 vdbeMergeEngineStep(MergeEngine * pMerger,	/* The merge engine to advance to the next row */
@@ -1581,7 +1581,7 @@ vdbeMergeEngineStep(MergeEngine * pMerger,	/* The merge engine to advance to the
 	rc = vdbePmaReaderNext(&pMerger->aReadr[iPrev]);
 
 	/* Update contents of aTree[] */
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		int i;		/* Index of aTree[] to recalculate */
 		PmaReader *pReadr1;	/* First PmaReader to compare */
 		PmaReader *pReadr2;	/* Second PmaReader to compare */
@@ -1642,7 +1642,7 @@ vdbeMergeEngineStep(MergeEngine * pMerger,	/* The merge engine to advance to the
 		*pbEof = (pMerger->aReadr[pMerger->aTree[1]].pFd == 0);
 	}
 
-	return (rc == SQL_OK ? pTask->pUnpacked->errCode : rc);
+	return (rc == 0 ? pTask->pUnpacked->errCode : rc);
 }
 
 #if SQL_MAX_WORKER_THREADS>0
@@ -1672,7 +1672,7 @@ vdbeSorterFlushPMA(VdbeSorter * pSorter)
 	pSorter->bUsePMA = 1;
 	return vdbeSorterListToPMA(&pSorter->aTask[0], &pSorter->list);
 #else
-	int rc = SQL_OK;
+	int rc = 0;
 	int i;
 	SortSubtask *pTask = 0;	/* Thread context used to create new PMA */
 	int nWorker = (pSorter->nTask - 1);
@@ -1697,11 +1697,11 @@ vdbeSorterFlushPMA(VdbeSorter * pSorter)
 		if (pTask->bDone) {
 			rc = vdbeSorterJoinThread(pTask);
 		}
-		if (rc != SQL_OK || pTask->pThread == 0)
+		if (rc != 0 || pTask->pThread == 0)
 			break;
 	}
 
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		if (i == nWorker) {
 			/* Use the foreground thread for this operation */
 			rc = vdbeSorterListToPMA(&pSorter->aTask[nWorker],
@@ -1749,7 +1749,7 @@ sqlVdbeSorterWrite(const VdbeCursor * pCsr,	/* Sorter cursor */
     )
 {
 	VdbeSorter *pSorter;
-	int rc = SQL_OK;	/* Return Code */
+	int rc = 0;	/* Return Code */
 	SorterRecord *pNew;	/* New list element */
 	int bFlush;		/* True to flush contents of memory to PMA */
 	int nReq;		/* Bytes of memory required */
@@ -1801,7 +1801,7 @@ sqlVdbeSorterWrite(const VdbeCursor * pCsr,	/* Sorter cursor */
 			rc = vdbeSorterFlushPMA(pSorter);
 			pSorter->list.szPMA = 0;
 			pSorter->iMemory = 0;
-			assert(rc != SQL_OK || pSorter->list.pList == 0);
+			assert(rc != 0 || pSorter->list.pList == 0);
 		}
 	}
 
@@ -1864,7 +1864,7 @@ sqlVdbeSorterWrite(const VdbeCursor * pCsr,	/* Sorter cursor */
 static int
 vdbeIncrPopulate(IncrMerger * pIncr)
 {
-	int rc = SQL_OK;
+	int rc = 0;
 	int rc2;
 	i64 iStart = pIncr->iStartOff;
 	SorterFile *pOut = &pIncr->aFile[1];
@@ -1876,7 +1876,7 @@ vdbeIncrPopulate(IncrMerger * pIncr)
 	vdbeSorterPopulateDebug(pTask, "enter");
 
 	vdbePmaWriterInit(pOut->pFd, &writer, pTask->pSorter->pgsz, iStart);
-	while (rc == SQL_OK) {
+	while (rc == 0) {
 		int dummy;
 		PmaReader *pReader = &pMerger->aReadr[pMerger->aTree[1]];
 		int nKey = pReader->nKey;
@@ -1899,7 +1899,7 @@ vdbeIncrPopulate(IncrMerger * pIncr)
 	}
 
 	rc2 = vdbePmaWriterFinish(&writer, &pOut->iEof);
-	if (rc == SQL_OK)
+	if (rc == 0)
 		rc = rc2;
 	vdbeSorterPopulateDebug(pTask, "exit");
 	return rc;
@@ -1946,24 +1946,24 @@ vdbeIncrBgPopulate(IncrMerger * pIncr)
  * been exhausted, this function also launches a new background thread
  * to populate the new aFile[1].
  *
- * SQL_OK is returned on success, or an sql error code otherwise.
+ * 0 is returned on success, or an sql error code otherwise.
  */
 static int
 vdbeIncrSwap(IncrMerger * pIncr)
 {
-	int rc = SQL_OK;
+	int rc = 0;
 
 #if SQL_MAX_WORKER_THREADS>0
 	if (pIncr->bUseThread) {
 		rc = vdbeSorterJoinThread(pIncr->pTask);
 
-		if (rc == SQL_OK) {
+		if (rc == 0) {
 			SorterFile f0 = pIncr->aFile[0];
 			pIncr->aFile[0] = pIncr->aFile[1];
 			pIncr->aFile[1] = f0;
 		}
 
-		if (rc == SQL_OK) {
+		if (rc == 0) {
 			if (pIncr->aFile[0].iEof == pIncr->iStartOff) {
 				pIncr->bEof = 1;
 			} else {
@@ -1995,7 +1995,7 @@ vdbeIncrMergerNew(SortSubtask * pTask,	/* The thread that will be using the new
 		  IncrMerger ** ppOut	/* Write the new IncrMerger here */
     )
 {
-	int rc = SQL_OK;
+	int rc = 0;
 	IncrMerger *pIncr = *ppOut =
 		(IncrMerger *) sqlMallocZero(sizeof(*pIncr));
 	if (pIncr) {
@@ -2109,7 +2109,7 @@ static int vdbePmaReaderIncrInit(PmaReader * pReadr, int eMode);
  * vdbePmaReaderIncrMergeInit() to initialize each PmaReader that feeds data
  * to pMerger.
  *
- * SQL_OK is returned if successful, or an sql error code otherwise.
+ * 0 is returned if successful, or an sql error code otherwise.
  */
 static int
 vdbeMergeEngineInit(SortSubtask * pTask,	/* Thread that will run pMerger */
@@ -2117,7 +2117,7 @@ vdbeMergeEngineInit(SortSubtask * pTask,	/* Thread that will run pMerger */
 		    int eMode	/* One of the INCRINIT_XXX constants */
     )
 {
-	int rc = SQL_OK;	/* Return code */
+	int rc = 0;	/* Return code */
 	int i;			/* For looping over PmaReader objects */
 	int nTree = pMerger->nTree;
 
@@ -2143,7 +2143,7 @@ vdbeMergeEngineInit(SortSubtask * pTask,	/* Thread that will run pMerger */
 			rc = vdbePmaReaderIncrInit(&pMerger->aReadr[i],
 						   INCRINIT_NORMAL);
 		}
-		if (rc != SQL_OK)
+		if (rc != 0)
 			return rc;
 	}
 
@@ -2184,12 +2184,12 @@ vdbeMergeEngineInit(SortSubtask * pTask,	/* Thread that will run pMerger */
  * In this case vdbePmaReaderNext() is called on all child PmaReaders and
  * the current PmaReader set to point to the first key in its range.
  *
- * SQL_OK is returned if successful, or an sql error code otherwise.
+ * 0 is returned if successful, or an sql error code otherwise.
  */
 static int
 vdbePmaReaderIncrMergeInit(PmaReader * pReadr, int eMode)
 {
-	int rc = SQL_OK;
+	int rc = 0;
 	IncrMerger *pIncr = pReadr->pIncr;
 	SortSubtask *pTask = pIncr->pTask;
 	sql *db = pTask->pSorter->db;
@@ -2203,13 +2203,13 @@ vdbePmaReaderIncrMergeInit(PmaReader * pReadr, int eMode)
 	 * requires two temp files to itself, whereas a single-threaded object
 	 * only requires a region of pTask->file2.
 	 */
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		int mxSz = pIncr->mxSz;
 #if SQL_MAX_WORKER_THREADS>0
 		if (pIncr->bUseThread) {
 			rc = vdbeSorterOpenTempFile(db, mxSz,
 						    &pIncr->aFile[0].pFd);
-			if (rc == SQL_OK) {
+			if (rc == 0) {
 				rc = vdbeSorterOpenTempFile(db, mxSz,
 							    &pIncr->aFile[1].
 							    pFd);
@@ -2224,7 +2224,7 @@ vdbePmaReaderIncrMergeInit(PmaReader * pReadr, int eMode)
 							    &pTask->file2.pFd);
 				pTask->file2.iEof = 0;
 			}
-			if (rc == SQL_OK) {
+			if (rc == 0) {
 				pIncr->aFile[1].pFd = pTask->file2.pFd;
 				pIncr->iStartOff = pTask->file2.iEof;
 				pTask->file2.iEof += mxSz;
@@ -2232,7 +2232,7 @@ vdbePmaReaderIncrMergeInit(PmaReader * pReadr, int eMode)
 			}
 	}
 #if SQL_MAX_WORKER_THREADS>0
-	if (rc == SQL_OK && pIncr->bUseThread) {
+	if (rc == 0 && pIncr->bUseThread) {
 		/* Use the current thread to populate aFile[1], even though this
 		 * PmaReader is multi-threaded. If this is an INCRINIT_TASK object,
 		 * then this function is already running in background thread
@@ -2248,7 +2248,7 @@ vdbePmaReaderIncrMergeInit(PmaReader * pReadr, int eMode)
 	}
 #endif
 
-	if (rc == SQL_OK
+	if (rc == 0
 	    && (SQL_MAX_WORKER_THREADS == 0 || eMode != INCRINIT_TASK)) {
 		rc = vdbePmaReaderNext(pReadr);
 	}
@@ -2288,7 +2288,7 @@ static int
 vdbePmaReaderIncrInit(PmaReader * pReadr, int eMode)
 {
 	IncrMerger *pIncr = pReadr->pIncr;	/* Incremental merger */
-	int rc = SQL_OK;	/* Return code */
+	int rc = 0;	/* Return code */
 	if (pIncr) {
 #if SQL_MAX_WORKER_THREADS>0
 		assert(pIncr->bUseThread == 0 || eMode == INCRINIT_TASK);
@@ -2309,7 +2309,7 @@ vdbePmaReaderIncrInit(PmaReader * pReadr, int eMode)
 /*
  * Allocate a new MergeEngine object to merge the contents of nPMA level-0
  * PMAs from pTask->file. If no error occurs, set *ppOut to point to
- * the new object and return SQL_OK. Or, if an error does occur, set *ppOut
+ * the new object and return 0. Or, if an error does occur, set *ppOut
  * to NULL and return an sql error code.
  *
  * When this function is called, *piOffset is set to the offset of the
@@ -2328,13 +2328,13 @@ vdbeMergeEngineLevel0(SortSubtask * pTask,	/* Sorter task to read from */
 	MergeEngine *pNew;	/* Merge engine to return */
 	i64 iOff = *piOffset;
 	int i;
-	int rc = SQL_OK;
+	int rc = 0;
 
 	*ppOut = pNew = vdbeMergeEngineNew(nPMA);
 	if (pNew == 0)
 		rc = SQL_NOMEM;
 
-	for (i = 0; i < nPMA && rc == SQL_OK; i++) {
+	for (i = 0; i < nPMA && rc == 0; i++) {
 		i64 nDummy = 0;
 		PmaReader *pReadr = &pNew->aReadr[i];
 		rc = vdbePmaReaderInit(pTask, &pTask->file, iOff, pReadr,
@@ -2342,7 +2342,7 @@ vdbeMergeEngineLevel0(SortSubtask * pTask,	/* Sorter task to read from */
 		iOff = pReadr->iEof;
 	}
 
-	if (rc != SQL_OK) {
+	if (rc != 0) {
 		vdbeMergeEngineFree(pNew);
 		*ppOut = 0;
 	}
@@ -2377,7 +2377,7 @@ vdbeSorterTreeDepth(int nPMA)
  * to vdbeSorterTreeDepth()). pLeaf is the iSeq'th leaf to be added to the
  * tree, counting from zero. This function adds pLeaf to the tree.
  *
- * If successful, SQL_OK is returned. If an error occurs, an sql error
+ * If successful, 0 is returned. If an error occurs, an sql error
  * code is returned and pLeaf is freed.
  */
 static int
@@ -2388,7 +2388,7 @@ vdbeSorterAddToTree(SortSubtask * pTask,	/* Task context */
 		    MergeEngine * pLeaf	/* Leaf to add to tree */
     )
 {
-	int rc = SQL_OK;
+	int rc = 0;
 	int nDiv = 1;
 	int i;
 	MergeEngine *p = pRoot;
@@ -2400,7 +2400,7 @@ vdbeSorterAddToTree(SortSubtask * pTask,	/* Task context */
 		nDiv = nDiv * SORTER_MAX_MERGE_COUNT;
 	}
 
-	for (i = 1; i < nDepth && rc == SQL_OK; i++) {
+	for (i = 1; i < nDepth && rc == 0; i++) {
 		int iIter = (iSeq / nDiv) % SORTER_MAX_MERGE_COUNT;
 		PmaReader *pReadr = &p->aReadr[iIter];
 
@@ -2414,13 +2414,13 @@ vdbeSorterAddToTree(SortSubtask * pTask,	/* Task context */
 						       &pReadr->pIncr);
 			}
 		}
-		if (rc == SQL_OK) {
+		if (rc == 0) {
 			p = pReadr->pIncr->pMerger;
 			nDiv = nDiv / SORTER_MAX_MERGE_COUNT;
 		}
 	}
 
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		p->aReadr[iSeq % SORTER_MAX_MERGE_COUNT].pIncr = pIncr;
 	} else {
 		vdbeIncrFree(pIncr);
@@ -2434,7 +2434,7 @@ vdbeSorterAddToTree(SortSubtask * pTask,	/* Task context */
  * files. It builds a tree of MergeEngine/IncrMerger/PmaReader objects that
  * can be used to incrementally merge all PMAs on disk.
  *
- * If successful, SQL_OK is returned and *ppOut set to point to the
+ * If successful, 0 is returned and *ppOut set to point to the
  * MergeEngine object at the root of the tree before returning. Or, if an
  * error occurs, an sql error code is returned and the final value
  * of *ppOut is undefined.
@@ -2445,7 +2445,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter,	/* The VDBE cursor that implement
     )
 {
 	MergeEngine *pMain = 0;
-	int rc = SQL_OK;
+	int rc = 0;
 	int iTask;
 
 #if SQL_MAX_WORKER_THREADS>0
@@ -2461,7 +2461,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter,	/* The VDBE cursor that implement
 	}
 #endif
 
-	for (iTask = 0; rc == SQL_OK && iTask < pSorter->nTask; iTask++) {
+	for (iTask = 0; rc == 0 && iTask < pSorter->nTask; iTask++) {
 		SortSubtask *pTask = &pSorter->aTask[iTask];
 		assert(pTask->nPMA > 0 || SQL_MAX_WORKER_THREADS > 0);
 		if (SQL_MAX_WORKER_THREADS == 0 || pTask->nPMA) {
@@ -2479,7 +2479,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter,	/* The VDBE cursor that implement
 				    vdbeMergeEngineNew(SORTER_MAX_MERGE_COUNT);
 				if (pRoot == 0)
 					rc = SQL_NOMEM;
-				for (i = 0; i < pTask->nPMA && rc == SQL_OK;
+				for (i = 0; i < pTask->nPMA && rc == 0;
 				     i += SORTER_MAX_MERGE_COUNT) {
 					MergeEngine *pMerger = 0;	/* New level-0 PMA merger */
 					int nReader;	/* Number of level-0 PMAs to merge */
@@ -2491,7 +2491,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter,	/* The VDBE cursor that implement
 								   nReader,
 								   &iReadOff,
 								   &pMerger);
-					if (rc == SQL_OK) {
+					if (rc == 0) {
 						rc = vdbeSorterAddToTree(pTask,
 									 nDepth,
 									 iSeq++,
@@ -2501,7 +2501,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter,	/* The VDBE cursor that implement
 				}
 			}
 
-			if (rc == SQL_OK) {
+			if (rc == 0) {
 #if SQL_MAX_WORKER_THREADS>0
 				if (pMain != 0) {
 					rc = vdbeIncrMergerNew(pTask, pRoot,
@@ -2520,7 +2520,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter,	/* The VDBE cursor that implement
 		}
 	}
 
-	if (rc != SQL_OK) {
+	if (rc != 0) {
 		vdbeMergeEngineFree(pMain);
 		pMain = 0;
 	}
@@ -2535,7 +2535,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter,	/* The VDBE cursor that implement
  * (for multi-threaded sorters) so that it can be used to iterate through
  * all records stored in the sorter.
  *
- * SQL_OK is returned if successful, or an sql error code otherwise.
+ * 0 is returned if successful, or an sql error code otherwise.
  */
 static int
 vdbeSorterSetupMerge(VdbeSorter * pSorter)
@@ -2553,7 +2553,7 @@ vdbeSorterSetupMerge(VdbeSorter * pSorter)
 #endif
 
 	rc = vdbeSorterMergeTreeBuild(pSorter, &pMain);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 #if SQL_MAX_WORKER_THREADS
 		assert(pSorter->bUseThreads == 0 || pSorter->nTask > 1);
 		if (pSorter->bUseThreads) {
@@ -2562,7 +2562,7 @@ vdbeSorterSetupMerge(VdbeSorter * pSorter)
 			SortSubtask *pLast =
 			    &pSorter->aTask[pSorter->nTask - 1];
 			rc = vdbeSortAllocUnpacked(pLast);
-			if (rc == SQL_OK) {
+			if (rc == 0) {
 				pReadr =
 				    (PmaReader *) sqlDbMallocZero(db,
 								      sizeof
@@ -2571,10 +2571,10 @@ vdbeSorterSetupMerge(VdbeSorter * pSorter)
 				if (pReadr == 0)
 					rc = SQL_NOMEM;
 			}
-			if (rc == SQL_OK) {
+			if (rc == 0) {
 				rc = vdbeIncrMergerNew(pLast, pMain,
 						       &pReadr->pIncr);
-				if (rc == SQL_OK) {
+				if (rc == 0) {
 					vdbeIncrMergerSetThreads(pReadr->pIncr);
 					for (iTask = 0;
 					     iTask < (pSorter->nTask - 1);
@@ -2590,7 +2590,7 @@ vdbeSorterSetupMerge(VdbeSorter * pSorter)
 						}
 					}
 					for (iTask = 0;
-					     rc == SQL_OK
+					     rc == 0
 					     && iTask < pSorter->nTask;
 					     iTask++) {
 						/* Check that:
@@ -2613,7 +2613,7 @@ vdbeSorterSetupMerge(VdbeSorter * pSorter)
 				}
 				pMain = 0;
 			}
-			if (rc == SQL_OK) {
+			if (rc == 0) {
 				rc = vdbePmaReaderIncrMergeInit(pReadr,
 								INCRINIT_ROOT);
 			}
@@ -2627,7 +2627,7 @@ vdbeSorterSetupMerge(VdbeSorter * pSorter)
 		}
 	}
 
-	if (rc != SQL_OK) {
+	if (rc != 0) {
 		vdbeMergeEngineFree(pMain);
 	}
 	return rc;
@@ -2642,7 +2642,7 @@ int
 sqlVdbeSorterRewind(const VdbeCursor * pCsr, int *pbEof)
 {
 	VdbeSorter *pSorter;
-	int rc = SQL_OK;	/* Return code */
+	int rc = 0;	/* Return code */
 
 	assert(pCsr->eCurType == CURTYPE_SORTER);
 	pSorter = pCsr->uc.pSorter;
@@ -2679,7 +2679,7 @@ sqlVdbeSorterRewind(const VdbeCursor * pCsr, int *pbEof)
 	 * incrementally read and merge all remaining PMAs.
 	 */
 	assert(pSorter->pReader == 0);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		rc = vdbeSorterSetupMerge(pSorter);
 		*pbEof = 0;
 	}
@@ -2723,7 +2723,7 @@ sqlVdbeSorterNext(sql * db, const VdbeCursor * pCsr, int *pbEof)
 		if (pSorter->list.aMemory == 0)
 			vdbeSorterRecordFree(db, pFree);
 		*pbEof = !pSorter->list.pList;
-		rc = SQL_OK;
+		rc = 0;
 	}
 	return rc;
 }
@@ -2779,7 +2779,7 @@ sqlVdbeSorterRowkey(const VdbeCursor * pCsr, Mem * pOut)
 	MemSetTypeFlag(pOut, MEM_Blob);
 	memcpy(pOut->z, pKey, nKey);
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -2828,10 +2828,10 @@ sqlVdbeSorterCompare(const VdbeCursor * pCsr,	/* Sorter cursor */
 	for (i = 0; i < nKeyCol; i++) {
 		if (r2->aMem[i].flags & MEM_Null) {
 			*pRes = -1;
-			return SQL_OK;
+			return 0;
 		}
 	}
 
 	*pRes = sqlVdbeRecordCompareMsgpack(pVal->z, r2);
-	return SQL_OK;
+	return 0;
 }
diff --git a/src/box/sql/where.c b/src/box/sql/where.c
index edc2074..4d1759e 100644
--- a/src/box/sql/where.c
+++ b/src/box/sql/where.c
@@ -1175,7 +1175,7 @@ whereRangeAdjust(WhereTerm * pTerm, LogEst nNew)
  * is left as is.
  *
  * If an error occurs, an sql error code is returned. Otherwise,
- * SQL_OK.
+ * 0.
  */
 static int
 whereRangeSkipScanEst(Parse * pParse,		/* Parsing & code generating context */
@@ -1193,7 +1193,7 @@ whereRangeSkipScanEst(Parse * pParse,		/* Parsing & code generating context */
 	sql *db = pParse->db;
 	int nLower = -1;
 	int nUpper = index->def->opts.stat->sample_count + 1;
-	int rc = SQL_OK;
+	int rc = 0;
 	enum field_type type = p->key_def->parts[nEq].type;
 
 	sql_value *p1 = 0;	/* Value extracted from pLower */
@@ -1206,7 +1206,7 @@ whereRangeSkipScanEst(Parse * pParse,		/* Parsing & code generating context */
 					       type, &p1);
 		nLower = 0;
 	}
-	if (pUpper && rc == SQL_OK) {
+	if (pUpper && rc == 0) {
 		rc = sqlStat4ValueFromExpr(pParse, pUpper->pExpr->pRight,
 					       type, &p2);
 		nUpper = p2 ? 0 : index->def->opts.stat->sample_count;
@@ -1217,15 +1217,15 @@ whereRangeSkipScanEst(Parse * pParse,		/* Parsing & code generating context */
 		int nDiff;
 		struct index_sample *samples = index->def->opts.stat->samples;
 		uint32_t sample_count = index->def->opts.stat->sample_count;
-		for (i = 0; rc == SQL_OK && i < (int) sample_count; i++) {
+		for (i = 0; rc == 0 && i < (int) sample_count; i++) {
 			rc = sql_stat4_column(db, samples[i].sample_key, nEq,
 					      &pVal);
-			if (rc == SQL_OK && p1) {
+			if (rc == 0 && p1) {
 				int res = sqlMemCompare(p1, pVal, coll);
 				if (res >= 0)
 					nLower++;
 			}
-			if (rc == SQL_OK && p2) {
+			if (rc == 0 && p2) {
 				int res = sqlMemCompare(p2, pVal, coll);
 				if (res >= 0)
 					nUpper++;
@@ -1309,7 +1309,7 @@ whereRangeScanEst(Parse * pParse,	/* Parsing & code generating context */
 		  WhereTerm * pUpper,	/* Upper bound on the range. ex: "x<455" Might be NULL */
 		  WhereLoop * pLoop)	/* Modify the .nOut and maybe .rRun fields */
 {
-	int rc = SQL_OK;
+	int rc = 0;
 	int nOut = pLoop->nOut;
 	LogEst nNew;
 
@@ -1399,7 +1399,7 @@ whereRangeScanEst(Parse * pParse,	/* Parsing & code generating context */
 				rc = sqlStat4ProbeSetValue(pParse, p, &pRec,
 							       pExpr, nBtm, nEq,
 							       &n);
-				if (rc == SQL_OK && n) {
+				if (rc == 0 && n) {
 					tRowcnt iNew;
 					u16 mask = WO_GT | WO_LE;
 					if (sqlExprVectorSize(pExpr) > n)
@@ -1425,7 +1425,7 @@ whereRangeScanEst(Parse * pParse,	/* Parsing & code generating context */
 				rc = sqlStat4ProbeSetValue(pParse, p, &pRec,
 							       pExpr, nTop, nEq,
 							       &n);
-				if (rc == SQL_OK && n) {
+				if (rc == 0 && n) {
 					tRowcnt iNew;
 					u16 mask = WO_GT | WO_LE;
 					if (sqlExprVectorSize(pExpr) > n)
@@ -1445,7 +1445,7 @@ whereRangeScanEst(Parse * pParse,	/* Parsing & code generating context */
 			}
 
 			pBuilder->pRec = pRec;
-			if (rc == SQL_OK) {
+			if (rc == 0) {
 				if (iUpper > iLower) {
 					nNew = sqlLogEst(iUpper - iLower);
 					/* TUNING:  If both iUpper and iLower are derived from the same
@@ -1513,7 +1513,7 @@ whereRangeScanEst(Parse * pParse,	/* Parsing & code generating context */
  * for that index.  When pExpr==NULL that means the constraint is
  * "x IS NULL" instead of "x=VALUE".
  *
- * Write the estimated row count into *pnRow and return SQL_OK.
+ * Write the estimated row count into *pnRow and return 0.
  * If unable to make an estimate, leave *pnRow unchanged and return
  * non-zero.
  *
@@ -1548,7 +1548,7 @@ whereEqualScanEst(Parse * pParse,	/* Parsing & code generating context */
 	rc = sqlStat4ProbeSetValue(pParse, p, &pRec, pExpr, 1, nEq - 1,
 				       &bOk);
 	pBuilder->pRec = pRec;
-	if (rc != SQL_OK)
+	if (rc != 0)
 		return rc;
 	if (bOk == 0)
 		return SQL_NOTFOUND;
@@ -1569,7 +1569,7 @@ whereEqualScanEst(Parse * pParse,	/* Parsing & code generating context */
  *
  *        WHERE x IN (1,2,3,4)
  *
- * Write the estimated row count into *pnRow and return SQL_OK.
+ * Write the estimated row count into *pnRow and return 0.
  * If unable to make an estimate, leave *pnRow unchanged and return
  * non-zero.
  *
@@ -1586,12 +1586,12 @@ whereInScanEst(Parse * pParse,	/* Parsing & code generating context */
 	struct index_def *p = pBuilder->pNew->index_def;
 	i64 nRow0 = sqlLogEstToInt(index_field_tuple_est(p, 0));
 	int nRecValid = pBuilder->nRecValid;
-	int rc = SQL_OK;	/* Subfunction return code */
+	int rc = 0;	/* Subfunction return code */
 	tRowcnt nEst;		/* Number of rows for a single term */
 	tRowcnt nRowEst = 0;	/* New estimate of the number of rows */
 	int i;			/* Loop counter */
 
-	for (i = 0; rc == SQL_OK && i < pList->nExpr; i++) {
+	for (i = 0; rc == 0 && i < pList->nExpr; i++) {
 		nEst = nRow0;
 		rc = whereEqualScanEst(pParse, pBuilder, pList->a[i].pExpr,
 				       &nEst);
@@ -1599,7 +1599,7 @@ whereInScanEst(Parse * pParse,	/* Parsing & code generating context */
 		pBuilder->nRecValid = nRecValid;
 	}
 
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		if (nRowEst > nRow0)
 			nRowEst = nRow0;
 		*pnRow = nRowEst;
@@ -1755,7 +1755,7 @@ whereLoopResize(sql * db, WhereLoop * p, int n)
 {
 	WhereTerm **paNew;
 	if (p->nLSlot >= n)
-		return SQL_OK;
+		return 0;
 	n = (n + 7) & ~7;
 	paNew = sqlDbMallocRawNN(db, sizeof(p->aLTerm[0]) * n);
 	if (paNew == 0)
@@ -1765,7 +1765,7 @@ whereLoopResize(sql * db, WhereLoop * p, int n)
 		sqlDbFree(db, p->aLTerm);
 	p->aLTerm = paNew;
 	p->nLSlot = n;
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -1787,7 +1787,7 @@ whereLoopXfer(sql * db, WhereLoop * pTo, WhereLoop * pFrom)
 	       pTo->nLTerm * sizeof(pTo->aLTerm[0]));
 	if ((pFrom->wsFlags & WHERE_AUTO_INDEX) != 0)
 		pFrom->index_def = NULL;
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -2056,7 +2056,7 @@ whereLoopInsert(WhereLoopBuilder * pBuilder, WhereLoop * pTemplate)
 			}
 #endif
 		}
-		return SQL_OK;
+		return 0;
 	}
 
 	/* Look for an existing WhereLoop to replace with pTemplate
@@ -2074,7 +2074,7 @@ whereLoopInsert(WhereLoopBuilder * pBuilder, WhereLoop * pTemplate)
 			whereLoopPrint(pTemplate, pBuilder->pWC);
 		}
 #endif
-		return SQL_OK;
+		return 0;
 	} else {
 		p = *ppPrev;
 	}
@@ -2318,7 +2318,7 @@ whereLoopAddBtreeIndex(WhereLoopBuilder * pBuilder,	/* The WhereLoop factory */
 	u16 saved_nSkip;	/* Original value of pNew->nSkip */
 	u32 saved_wsFlags;	/* Original value of pNew->wsFlags */
 	LogEst saved_nOut;	/* Original value of pNew->nOut */
-	int rc = SQL_OK;	/* Return code */
+	int rc = 0;	/* Return code */
 	LogEst rSize;		/* Number of rows in the table */
 	LogEst rLogSize;	/* Logarithm of table size */
 	WhereTerm *pTop = 0, *pBtm = 0;	/* Top and bottom range constraints */
@@ -2370,7 +2370,7 @@ whereLoopAddBtreeIndex(WhereLoopBuilder * pBuilder,	/* The WhereLoop factory */
 	pNew->rSetup = 0;
 	rSize = index_field_tuple_est(probe, 0);
 	rLogSize = estLog(rSize);
-	for (; rc == SQL_OK && pTerm != 0; pTerm = whereScanNext(&scan)) {
+	for (; rc == 0 && pTerm != 0; pTerm = whereScanNext(&scan)) {
 		u16 eOp = pTerm->eOperator;	/* Shorthand for pTerm->eOperator */
 		LogEst rCostIdx;
 		LogEst nOutUnadjusted;	/* nOut before IN() and WHERE adjustments */
@@ -2552,8 +2552,8 @@ whereLoopAddBtreeIndex(WhereLoopBuilder * pBuilder,	/* The WhereLoop factory */
 								    &nOut);
 					}
 					if (rc == SQL_NOTFOUND)
-						rc = SQL_OK;
-					if (rc != SQL_OK)
+						rc = 0;
+					if (rc != 0)
 						break;	/* Jump out of the pTerm loop */
 					if (nOut) {
 						pNew->nOut =
@@ -2651,7 +2651,7 @@ whereLoopAddBtreeIndex(WhereLoopBuilder * pBuilder,	/* The WhereLoop factory */
 	    stat->skip_scan_enabled == true &&
 	    /* TUNING: Minimum for skip-scan */
 	    index_field_tuple_est(probe, saved_nEq + 1) >= 42 &&
-	    (rc = whereLoopResize(db, pNew, pNew->nLTerm + 1)) == SQL_OK) {
+	    (rc = whereLoopResize(db, pNew, pNew->nLTerm + 1)) == 0) {
 		LogEst nIter;
 		pNew->nEq++;
 		pNew->nSkip++;
@@ -2760,7 +2760,7 @@ whereLoopAddBtree(WhereLoopBuilder * pBuilder,	/* WHERE clause information */
 	SrcList *pTabList;	/* The FROM clause */
 	struct SrcList_item *pSrc;	/* The FROM clause btree term to add */
 	WhereLoop *pNew;	/* Template WhereLoop object */
-	int rc = SQL_OK;	/* Return code */
+	int rc = 0;	/* Return code */
 	int iSortIdx = 1;	/* Index number */
 	int b;			/* A boolean value */
 	LogEst rSize;		/* number of rows in the table */
@@ -2843,7 +2843,7 @@ tnt_error:
 		/* Generate auto-index WhereLoops */
 		WhereTerm *pTerm;
 		WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
-		for (pTerm = pWC->a; rc == SQL_OK && pTerm < pWCEnd; pTerm++) {
+		for (pTerm = pWC->a; rc == 0 && pTerm < pWCEnd; pTerm++) {
 			if (pTerm->prereqRight & pNew->maskSelf)
 				continue;
 			if (termCanDriveIndex(pTerm, pSrc, 0)) {
@@ -2958,7 +2958,7 @@ whereLoopAddOr(WhereLoopBuilder * pBuilder, Bitmask mPrereq, Bitmask mUnusable)
 	WhereClause *pWC;
 	WhereLoop *pNew;
 	WhereTerm *pTerm, *pWCEnd;
-	int rc = SQL_OK;
+	int rc = 0;
 	int iCur;
 	WhereClause tempWC;
 	WhereLoopBuilder sSubBuild;
@@ -2972,7 +2972,7 @@ whereLoopAddOr(WhereLoopBuilder * pBuilder, Bitmask mPrereq, Bitmask mUnusable)
 	pItem = pWInfo->pTabList->a + pNew->iTab;
 	iCur = pItem->iCursor;
 
-	for (pTerm = pWC->a; pTerm < pWCEnd && rc == SQL_OK; pTerm++) {
+	for (pTerm = pWC->a; pTerm < pWCEnd && rc == 0; pTerm++) {
 		if ((pTerm->eOperator & WO_OR) != 0
 		    && (pTerm->u.pOrInfo->indexable & pNew->maskSelf) != 0) {
 			WhereClause *const pOrWC = &pTerm->u.pOrInfo->wc;
@@ -3015,11 +3015,11 @@ whereLoopAddOr(WhereLoopBuilder * pBuilder, Bitmask mPrereq, Bitmask mUnusable)
 					rc = whereLoopAddBtree(&sSubBuild,
 							       mPrereq);
 				}
-				if (rc == SQL_OK) {
+				if (rc == 0) {
 					rc = whereLoopAddOr(&sSubBuild, mPrereq,
 							    mUnusable);
 				}
-				assert(rc == SQL_OK || sCur.n == 0);
+				assert(rc == 0 || sCur.n == 0);
 				if (sCur.n == 0) {
 					sSum.n = 0;
 					break;
@@ -3052,7 +3052,7 @@ whereLoopAddOr(WhereLoopBuilder * pBuilder, Bitmask mPrereq, Bitmask mUnusable)
 			pNew->nBtm = 0;
 			pNew->nTop = 0;
 			pNew->index_def = NULL;
-			for (i = 0; rc == SQL_OK && i < sSum.n; i++) {
+			for (i = 0; rc == 0 && i < sSum.n; i++) {
 				/* TUNING: Currently sSum.a[i].rRun is set to the sum of the costs
 				 * of all sub-scans required by the OR-scan. However, due to rounding
 				 * errors, it may be that the cost of the OR-scan is equal to its
@@ -3092,7 +3092,7 @@ whereLoopAddAll(WhereLoopBuilder * pBuilder)
 	struct SrcList_item *pItem;
 	struct SrcList_item *pEnd = &pTabList->a[pWInfo->nLevel];
 	sql *db = pWInfo->pParse->db;
-	int rc = SQL_OK;
+	int rc = 0;
 	WhereLoop *pNew;
 	u8 priorJointype = 0;
 
@@ -3115,7 +3115,7 @@ whereLoopAddAll(WhereLoopBuilder * pBuilder)
 		{
 			rc = whereLoopAddBtree(pBuilder, mPrereq);
 		}
-		if (rc == SQL_OK) {
+		if (rc == 0) {
 			rc = whereLoopAddOr(pBuilder, mPrereq, mUnusable);
 		}
 		mPrior |= pNew->maskSelf;
@@ -3566,7 +3566,7 @@ whereSortingCost(WhereInfo * pWInfo, LogEst nRow, int nOrderBy, int nSorted)
  * will be nRowEst (in the 10*log2 representation).  Or, ignore sorting
  * costs if nRowEst==0.
  *
- * Return SQL_OK on success or SQL_NOMEM of a memory allocation
+ * Return 0 on success or SQL_NOMEM of a memory allocation
  * error occurs.
  */
 static int
@@ -4001,7 +4001,7 @@ wherePathSolver(WhereInfo * pWInfo, LogEst nRowEst)
 
 	/* Free temporary memory and return success */
 	sqlDbFree(db, pSpace);
-	return SQL_OK;
+	return 0;
 }
 
 /**
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 08/28] sql: remove SQL_PERM, SQL_WARNING, SQL_ABORT errcodes
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (6 preceding siblings ...)
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 07/28] sql: remove SQL_OK error/status code imeevma
@ 2019-06-10 13:56 ` imeevma
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 09/28] sql: remove SQL_CANTOPEN errcode imeevma
                   ` (23 subsequent siblings)
  31 siblings, 0 replies; 56+ messages in thread
From: imeevma @ 2019-06-10 13:56 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Removing these error codes is part of getting rid of the SQL error
system.
---
 src/box/sql/legacy.c  |  4 ++--
 src/box/sql/os_unix.c | 47 -----------------------------------------------
 src/box/sql/sqlInt.h  |  6 ------
 src/box/sql/where.c   | 10 ----------
 4 files changed, 2 insertions(+), 65 deletions(-)

diff --git a/src/box/sql/legacy.c b/src/box/sql/legacy.c
index f7e069a..3101428 100644
--- a/src/box/sql/legacy.c
+++ b/src/box/sql/legacy.c
@@ -134,9 +134,9 @@ sql_exec(sql * db,	/* The database on which the SQL executes */
 				if (xCallback(pArg, nCol, azVals, azCols)) {
 					/* EVIDENCE-OF: R-38229-40159 If the callback function to
 					 * sql_exec() returns non-zero, then sql_exec() will
-					 * return SQL_ABORT.
+					 * return -1.
 					 */
-					rc = SQL_ABORT;
+					rc = -1;
 					sqlVdbeFinalize((Vdbe *) pStmt);
 					pStmt = 0;
 					goto exec_out;
diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index fd9576e..d9e5656 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -164,9 +164,6 @@ robust_open(const char *z, int f, mode_t m)
 		if (fd >= SQL_MINIMUM_FILE_DESCRIPTOR)
 			break;
 		close(fd);
-		sql_log(SQL_WARNING,
-			    "attempt to open \"%s\" as file descriptor %d", z,
-			    fd);
 		fd = -1;
 		if (open("/dev/null", f, m) < 0)
 			break;
@@ -502,48 +499,6 @@ fileHasMoved(unixFile * pFile)
 }
 
 /*
- * Check a unixFile that is a database.  Verify the following:
- *
- * (1) There is exactly one hard link on the file
- * (2) The file is not a symbolic link
- * (3) The file has not been renamed or unlinked
- *
- * Issue sql_log(SQL_WARNING,...) messages if anything is not right.
- */
-static void
-verifyDbFile(unixFile * pFile)
-{
-	struct stat buf;
-	int rc;
-
-	/* These verifications occurs for the main database only */
-	if (pFile->ctrlFlags & UNIXFILE_NOLOCK)
-		return;
-
-	rc = fstat(pFile->h, &buf);
-	if (rc != 0) {
-		sql_log(SQL_WARNING, "cannot fstat db file %s",
-			    pFile->zPath);
-		return;
-	}
-	if (buf.st_nlink == 0) {
-		sql_log(SQL_WARNING, "file unlinked while open: %s",
-			    pFile->zPath);
-		return;
-	}
-	if (buf.st_nlink > 1) {
-		sql_log(SQL_WARNING, "multiple links to file: %s",
-			    pFile->zPath);
-		return;
-	}
-	if (fileHasMoved(pFile)) {
-		sql_log(SQL_WARNING, "file renamed while open: %s",
-			    pFile->zPath);
-		return;
-	}
-}
-
-/*
  * Attempt to set a system-lock on the file pFile.  The lock is
  * described by pLock.
  *
@@ -766,7 +721,6 @@ unixClose(sql_file * id)
 {
 	int rc;
 	unixFile *pFile = (unixFile *) id;
-	verifyDbFile(pFile);
 	unixUnlock(id, NO_LOCK);
 
 	/* unixFile.pInode is always valid here. Otherwise, a different close
@@ -1528,7 +1482,6 @@ fillInUnixFile(sql_vfs * pVfs,	/* Pointer to vfs object */
 			robust_close(pNew, h, __LINE__);
 	} else {
 		pNew->pMethod = pLockingStyle;
-		verifyDbFile(pNew);
 	}
 	return rc;
 }
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 93ec9ab..4c97acf 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -358,10 +358,6 @@ struct sql_vfs {
 enum sql_ret_code {
 	/** Common error code. */
 	SQL_ERROR = 1,
-	/** Access permission denied. */
-	SQL_PERM,
-	/** Callback routine requested an abort. */
-	SQL_ABORT,
 	/** The database file is locked. */
 	SQL_BUSY,
 	/** A table in the database is locked. */
@@ -387,8 +383,6 @@ enum sql_ret_code {
 	/** 2nd parameter to sql_bind out of range. */
 	SQL_RANGE,
 	SQL_TARANTOOL_ERROR,
-	/** Warnings from sql_log(). */
-	SQL_WARNING,
 	/** sql_step() has another row ready. */
 	SQL_ROW,
 	/** sql_step() has finished executing. */
diff --git a/src/box/sql/where.c b/src/box/sql/where.c
index 4d1759e..ab277c5 100644
--- a/src/box/sql/where.c
+++ b/src/box/sql/where.c
@@ -741,7 +741,6 @@ constructAutomaticIndex(Parse * pParse,			/* The parsing context */
 	char *zNotUsed;		/* Extra space on the end of pIdx */
 	Bitmask idxCols;	/* Bitmap of columns used for indexing */
 	Bitmask extraCols;	/* Bitmap of additional columns */
-	u8 sentWarning = 0;	/* True if a warnning has been issued */
 	int iContinue = 0;	/* Jump here to skip excluded rows */
 	struct SrcList_item *pTabItem;	/* FROM clause term being indexed */
 	int addrCounter = 0;	/* Address where integer counter is initialized */
@@ -768,15 +767,6 @@ constructAutomaticIndex(Parse * pParse,			/* The parsing context */
 			int iCol = pTerm->u.leftColumn;
 			Bitmask cMask =
 			    iCol >= BMS ? MASKBIT(BMS - 1) : MASKBIT(iCol);
-			testcase(iCol == BMS);
-			testcase(iCol == BMS - 1);
-			if (!sentWarning) {
-				sql_log(SQL_WARNING_AUTOINDEX,
-					    "automatic index on %s(%s)",
-					    pTable->def->name,
-					    pTable->aCol[iCol].zName);
-				sentWarning = 1;
-			}
 			if ((idxCols & cMask) == 0) {
 				if (whereLoopResize
 				    (pParse->db, pLoop, nKeyCol + 1)) {
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 09/28] sql: remove SQL_CANTOPEN errcode
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (7 preceding siblings ...)
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 08/28] sql: remove SQL_PERM, SQL_WARNING, SQL_ABORT errcodes imeevma
@ 2019-06-10 13:56 ` imeevma
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 10/28] sql: remove SQL_NOTFOUND error/status code imeevma
                   ` (22 subsequent siblings)
  31 siblings, 0 replies; 56+ messages in thread
From: imeevma @ 2019-06-10 13:56 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql/os_unix.c | 89 +++++++--------------------------------------------
 src/box/sql/sqlInt.h  |  2 --
 2 files changed, 11 insertions(+), 80 deletions(-)

diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index d9e5656..18e42e5 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -318,66 +318,6 @@ struct unixInodeInfo {
 static unixInodeInfo *inodeList = 0;
 
 /*
- *
- * This function - unixLogErrorAtLine(), is only ever called via the macro
- * unixLogError().
- *
- * It is invoked after an error occurs in an OS function and errno has been
- * set. It logs a message using sql_log() containing the current value of
- * errno and, if possible, the human-readable equivalent from strerror() or
- * strerror_r().
- *
- * The first argument passed to the macro should be the error code that
- * will be returned to sql (e.g. SQL_IOERR_DELETE, SQL_CANTOPEN).
- * The two subsequent arguments should be the name of the OS function that
- * failed (e.g. "unlink", "open") and the associated file-system path,
- * if any.
- */
-#define unixLogError(a,b,c)     unixLogErrorAtLine(a,b,c,__LINE__)
-static int
-unixLogErrorAtLine(int errcode,	/* sql error code */
-		   const char *zFunc,	/* Name of OS function that failed */
-		   const char *zPath,	/* File path associated with error */
-		   int iLine	/* Source line number where error occurred */
-    )
-{
-	char *zErr;		/* Message from strerror() or equivalent */
-	int iErrno = errno;	/* Saved syscall error number */
-
-	zErr = strerror(iErrno);
-
-	if (zPath == 0)
-		zPath = "";
-	sql_log(errcode,
-		    "os_unix.c:%d: (%d) %s(%s) - %s",
-		    iLine, iErrno, zFunc, zPath, zErr);
-
-	return errcode;
-}
-
-/*
- * Close a file descriptor.
- *
- * We assume that close() almost always works, since it is only in a
- * very sick application or on a very sick platform that it might fail.
- * If it does fail, simply leak the file descriptor, but do log the
- * error.
- *
- * Note that it is not safe to retry close() after EINTR since the
- * file descriptor might have already been reused by another thread.
- * So we don't even try to recover from an EINTR.  Just log the error
- * and move on.
- */
-static void
-robust_close(unixFile * pFile, int h, int lineno)
-{
-	if (close(h) != 0) {
-		unixLogErrorAtLine(SQL_IOERR_CLOSE, "close",
-				   pFile ? pFile->zPath : 0, lineno);
-	}
-}
-
-/*
  * Set the pFile->lastErrno.  Do this in a subroutine as that provides
  * a convenient place to set a breakpoint.
  */
@@ -398,7 +338,7 @@ closePendingFds(unixFile * pFile)
 	UnixUnusedFd *pNext;
 	for (p = pInode->pUnused; p; p = pNext) {
 		pNext = p->pNext;
-		robust_close(pFile, p->fd, __LINE__);
+		close(p->fd);
 		sql_free(p);
 	}
 	pInode->pUnused = 0;
@@ -705,7 +645,7 @@ closeUnixFile(sql_file * id)
 	unixUnmapfile(pFile);
 #endif
 	if (pFile->h >= 0) {
-		robust_close(pFile, pFile->h, __LINE__);
+		close(pFile->h);
 		pFile->h = -1;
 	}
 	sql_free(pFile->pUnused);
@@ -946,8 +886,7 @@ unixWrite(sql_file * id, const void *pBuf, int amt, sql_int64 offset)
 /*
  * Open a file descriptor to the directory containing file zFilename.
  * If successful, *pFd is set to the opened file descriptor and
- * 0 is returned. If an error occurs, either SQL_NOMEM
- * or SQL_CANTOPEN is returned and *pFd is set to an undefined
+ * 0 is returned. If an error occurs, -1 is set to an undefined
  * value.
  *
  * The directory file descriptor is used for only one thing - to
@@ -987,7 +926,7 @@ openDirectory(const char *zFilename, int *pFd)
 	*pFd = fd;
 	if (fd >= 0)
 		return 0;
-	return unixLogError(SQL_CANTOPEN, "openDirectory", zDirname);
+	return -1;
 }
 
 /*
@@ -1032,8 +971,7 @@ fcntlSizeHint(unixFile * pFile, i64 nByte)
 		if (pFile->szChunk <= 0) {
 			if (robust_ftruncate(pFile->h, nByte)) {
 				storeLastErrno(pFile, errno);
-				return unixLogError(SQL_IOERR_TRUNCATE,
-						    "ftruncate", pFile->zPath);
+				return -1;
 			}
 		}
 
@@ -1147,7 +1085,6 @@ unixRemapfile(unixFile * pFd,	/* File descriptor object */
 	      i64 nNew		/* Required mapping size */
     )
 {
-	const char *zErr = "mmap";
 	int h = pFd->h;		/* File descriptor open on db file */
 	u8 *pOrig = (u8 *) pFd->pMapRegion;	/* Pointer to current file mapping */
 	i64 nOrig = pFd->mmapSizeActual;	/* Size of pOrig region in bytes */
@@ -1170,7 +1107,6 @@ unixRemapfile(unixFile * pFd,	/* File descriptor object */
 			munmap(pReq, nOrig - nReuse);
 		#if !defined(__APPLE__) && !defined(__FreeBSD__)
 		pNew = mremap(pOrig, nReuse, nNew, MREMAP_MAYMOVE);
-		zErr = "mremap";
 		#else
 		pNew = mmap(pReq, nNew - nReuse, flags, MAP_SHARED, h, nReuse);
 		if (pNew != MAP_FAILED) {
@@ -1195,7 +1131,6 @@ unixRemapfile(unixFile * pFd,	/* File descriptor object */
 	if (pNew == MAP_FAILED) {
 		pNew = 0;
 		nNew = 0;
-		unixLogError(0, zErr, pFd->zPath);
 
 		/* If the mmap() above failed, assume that all subsequent mmap() calls
 		 * will probably fail too. Fall back to using xRead/xWrite exclusively
@@ -1472,14 +1407,14 @@ fillInUnixFile(sql_vfs * pVfs,	/* Pointer to vfs object */
 			 * implicit assumption here is that if fstat() fails, things are in
 			 * such bad shape that dropping a lock or two doesn't matter much.
 			 */
-			robust_close(pNew, h, __LINE__);
+			close(h);
 			h = -1;
 		}
 	}
 	storeLastErrno(pNew, 0);
 	if (rc != 0) {
 		if (h >= 0)
-			robust_close(pNew, h, __LINE__);
+			close(h);
 	} else {
 		pNew->pMethod = pLockingStyle;
 	}
@@ -1830,7 +1765,7 @@ unixOpen(sql_vfs * pVfs,	/* The VFS for which this is the xOpen method */
 			fd = robust_open(zName, openFlags, openMode);
 		}
 		if (fd < 0) {
-			rc = unixLogError(SQL_CANTOPEN, "open", zName);
+			rc = -1;
 			goto open_finished;
 		}
 		
@@ -1886,7 +1821,7 @@ unixDelete(sql_vfs * NotUsed,	/* VFS containing this as the xDelete method */
 		if (errno == ENOENT) {
 			rc = SQL_IOERR_DELETE_NOENT;
 		} else {
-			rc = unixLogError(SQL_IOERR_DELETE, "unlink", zPath);
+			rc = -1;
 		}
 		return rc;
 	}
@@ -1897,12 +1832,10 @@ unixDelete(sql_vfs * NotUsed,	/* VFS containing this as the xDelete method */
 		if (rc == 0) {
 			struct stat buf;
 			if (fstat(fd, &buf)) {
-				rc = unixLogError(SQL_IOERR_DIR_FSYNC,
-						  "fsync", zPath);
+				rc = -1;
 			}
-			robust_close(0, fd, __LINE__);
+			close(fd);
 		} else {
-			assert(rc == SQL_CANTOPEN);
 			rc = 0;
 		}
 	}
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 4c97acf..17033eb 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -370,8 +370,6 @@ enum sql_ret_code {
 	SQL_NOTFOUND,
 	/** Insertion failed because database is full. */
 	SQL_FULL,
-	/** Unable to open the database file. */
-	SQL_CANTOPEN,
 	/** The database schema changed. */
 	SQL_SCHEMA,
 	/** String or BLOB exceeds size limit. */
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 10/28] sql: remove SQL_NOTFOUND error/status code
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (8 preceding siblings ...)
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 09/28] sql: remove SQL_CANTOPEN errcode imeevma
@ 2019-06-10 13:56 ` imeevma
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 11/28] sql: remove SQL_LOCKED errcode imeevma
                   ` (21 subsequent siblings)
  31 siblings, 0 replies; 56+ messages in thread
From: imeevma @ 2019-06-10 13:56 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Removing this error/status code is part of getting rid of the SQL
error system.
---
 src/box/sql/os_unix.c |  2 +-
 src/box/sql/sqlInt.h  |  2 --
 src/box/sql/where.c   | 14 ++------------
 3 files changed, 3 insertions(+), 15 deletions(-)

diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index 18e42e5..75263e3 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -1047,7 +1047,7 @@ unixFileControl(sql_file * id, int op, void *pArg)
 			return rc;
 		}
 	}
-	return SQL_NOTFOUND;
+	return -1;
 }
 
 /*
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 17033eb..5bdec67 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -366,8 +366,6 @@ enum sql_ret_code {
 	SQL_NOMEM,
 	/** Some kind of disk I/O error occurred. */
 	SQL_IOERR,
-	/** Unknown opcode in sql_file_control(). */
-	SQL_NOTFOUND,
 	/** Insertion failed because database is full. */
 	SQL_FULL,
 	/** The database schema changed. */
diff --git a/src/box/sql/where.c b/src/box/sql/where.c
index ab277c5..6781ab0 100644
--- a/src/box/sql/where.c
+++ b/src/box/sql/where.c
@@ -1526,22 +1526,14 @@ whereEqualScanEst(Parse * pParse,	/* Parsing & code generating context */
 
 	assert(nEq >= 1);
 	assert(nEq <= (int) p->key_def->part_count);
-	assert(pBuilder->nRecValid < nEq);
-
-	/* If values are not available for all fields of the index to the left
-	 * of this one, no estimate can be made. Return SQL_NOTFOUND.
-	 */
-	if (pBuilder->nRecValid < (nEq - 1)) {
-		return SQL_NOTFOUND;
-	}
+	assert(pBuilder->nRecValid == (nEq - 1));
 
 	rc = sqlStat4ProbeSetValue(pParse, p, &pRec, pExpr, 1, nEq - 1,
 				       &bOk);
 	pBuilder->pRec = pRec;
 	if (rc != 0)
 		return rc;
-	if (bOk == 0)
-		return SQL_NOTFOUND;
+	assert(bOk != 0);
 	pBuilder->nRecValid = nEq;
 
 	whereKeyStats(pParse, p, pRec, 0, a);
@@ -2541,8 +2533,6 @@ whereLoopAddBtreeIndex(WhereLoopBuilder * pBuilder,	/* The WhereLoop factory */
 								    pExpr->x.pList,
 								    &nOut);
 					}
-					if (rc == SQL_NOTFOUND)
-						rc = 0;
 					if (rc != 0)
 						break;	/* Jump out of the pTerm loop */
 					if (nOut) {
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 11/28] sql: remove SQL_LOCKED errcode
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (9 preceding siblings ...)
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 10/28] sql: remove SQL_NOTFOUND error/status code imeevma
@ 2019-06-10 13:56 ` imeevma
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 12/28] sql: remove SQL_FULL errcode imeevma
                   ` (20 subsequent siblings)
  31 siblings, 0 replies; 56+ messages in thread
From: imeevma @ 2019-06-10 13:56 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql/prepare.c |  5 -----
 src/box/sql/sqlInt.h  |  2 --
 src/box/sql/vdbeapi.c | 27 +--------------------------
 3 files changed, 1 insertion(+), 33 deletions(-)

diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index ecae5d4..57b78d9 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -207,11 +207,6 @@ sqlLockAndPrepare(sql * db,		/* Database handle. */
 
 /*
  * Rerun the compilation of a statement after a schema change.
- *
- * If the statement is successfully recompiled, return 0. Otherwise,
- * if the statement cannot be recompiled because another connection has
- * locked the sql_master table, return SQL_LOCKED. If any other error
- * occurs, return SQL_SCHEMA.
  */
 int
 sqlReprepare(Vdbe * p)
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 5bdec67..7af3961 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -360,8 +360,6 @@ enum sql_ret_code {
 	SQL_ERROR = 1,
 	/** The database file is locked. */
 	SQL_BUSY,
-	/** A table in the database is locked. */
-	SQL_LOCKED,
 	/** A malloc() failed. */
 	SQL_NOMEM,
 	/** Some kind of disk I/O error occurred. */
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 97204cc..f3f7f48 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -417,33 +417,8 @@ sqlStep(Vdbe * p)
 	int rc;
 
 	assert(p);
-	if (p->magic != VDBE_MAGIC_RUN) {
-		/* We used to require that sql_reset() be called before retrying
-		 * sql_step() after any error or after SQL_DONE.  But beginning
-		 * with version 3.7.0, we changed this so that sql_reset() would
-		 * be called automatically instead of throwing the SQL_MISUSE error.
-		 * This "automatic-reset" change is not technically an incompatibility,
-		 * since any application that receives an SQL_MISUSE is broken by
-		 * definition.
-		 *
-		 * Nevertheless, some published applications that were originally written
-		 * for version 3.6.23 or earlier do in fact depend on SQL_MISUSE
-		 * returns, and those were broken by the automatic-reset change.  As a
-		 * a work-around, the SQL_OMIT_AUTORESET compile-time restores the
-		 * legacy behavior of returning SQL_MISUSE for cases where the
-		 * previous sql_step() returned something other than a SQL_LOCKED
-		 * or SQL_BUSY error.
-		 */
-#ifdef SQL_OMIT_AUTORESET
-		if ((rc = p->rc & 0xff) == SQL_BUSY || rc == SQL_LOCKED) {
-			sql_reset((sql_stmt *) p);
-		} else {
-			return SQL_MISUSE;
-		}
-#else
+	if (p->magic != VDBE_MAGIC_RUN)
 		sql_reset((sql_stmt *) p);
-#endif
-	}
 
 	/* Check that malloc() has not failed. If it has, return early. */
 	db = p->db;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 12/28] sql: remove SQL_FULL errcode
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (10 preceding siblings ...)
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 11/28] sql: remove SQL_LOCKED errcode imeevma
@ 2019-06-10 13:56 ` imeevma
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 13/28] sql: remove SQL_MISUSE errcode imeevma
                   ` (19 subsequent siblings)
  31 siblings, 0 replies; 56+ messages in thread
From: imeevma @ 2019-06-10 13:56 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql/os_unix.c | 2 +-
 src/box/sql/sqlInt.h  | 2 --
 src/box/sql/vdbeaux.c | 6 ++----
 3 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index 75263e3..fa28c46 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -876,7 +876,7 @@ unixWrite(sql_file * id, const void *pBuf, int amt, sql_int64 offset)
 			return SQL_IOERR_WRITE;
 		} else {
 			storeLastErrno(pFile, 0);	/* not a system error */
-			return SQL_FULL;
+			return -1;
 		}
 	}
 
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 7af3961..345b0a4 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -364,8 +364,6 @@ enum sql_ret_code {
 	SQL_NOMEM,
 	/** Some kind of disk I/O error occurred. */
 	SQL_IOERR,
-	/** Insertion failed because database is full. */
-	SQL_FULL,
 	/** The database schema changed. */
 	SQL_SCHEMA,
 	/** String or BLOB exceeds size limit. */
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 7f81fad..efc5103 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -2179,7 +2179,6 @@ sqlVdbeHalt(Vdbe * p)
 	 *
 	 *     SQL_NOMEM
 	 *     SQL_IOERR
-	 *     SQL_FULL
 	 *
 	 * Then the internal cache might have been left in an inconsistent
 	 * state.  We need to rollback the statement transaction, if there is
@@ -2205,8 +2204,7 @@ sqlVdbeHalt(Vdbe * p)
 
 		/* Check for one of the special errors */
 		mrc = p->rc & 0xff;
-		isSpecialError = mrc == SQL_NOMEM || mrc == SQL_IOERR ||
-				 mrc == SQL_FULL;
+		isSpecialError = mrc == SQL_NOMEM || mrc == SQL_IOERR;
 		if (isSpecialError) {
 			/* At least a savepoint transaction must be rolled back
 			 * to restore the database to a consistent state.
@@ -2218,7 +2216,7 @@ sqlVdbeHalt(Vdbe * p)
 			 * pagerStress() in pager.c), the rollback is required to restore
 			 * the pager to a consistent state.
 			 */
-			if ((mrc == SQL_NOMEM || mrc == SQL_FULL)
+			if ((mrc == SQL_NOMEM)
 			    && box_txn()) {
 				eStatementOp = SAVEPOINT_ROLLBACK;
 			} else {
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 13/28] sql: remove SQL_MISUSE errcode
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (11 preceding siblings ...)
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 12/28] sql: remove SQL_FULL errcode imeevma
@ 2019-06-10 13:56 ` imeevma
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 14/28] sql: remove SQL_RANGE errcode imeevma
                   ` (18 subsequent siblings)
  31 siblings, 0 replies; 56+ messages in thread
From: imeevma @ 2019-06-10 13:56 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql/malloc.c  | 56 ---------------------------------------------------
 src/box/sql/sqlInt.h  | 13 ------------
 src/box/sql/status.c  | 33 ------------------------------
 src/box/sql/vdbeapi.c |  6 +-----
 4 files changed, 1 insertion(+), 107 deletions(-)

diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index a7549db..8830cc8 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -174,38 +174,6 @@ static SQL_WSD struct Mem0Global {
 
 #define mem0 GLOBAL(struct Mem0Global, mem0)
 
-
-/*
- * Set the soft heap-size limit for the library. Passing a zero or
- * negative value indicates no limit.
- */
-sql_int64
-sql_soft_heap_limit64(sql_int64 n)
-{
-	sql_int64 priorLimit;
-	sql_int64 excess;
-	sql_int64 nUsed;
-	priorLimit = mem0.alarmThreshold;
-	if (n < 0) {
-		return priorLimit;
-	}
-	mem0.alarmThreshold = n;
-	nUsed = sqlStatusValue(SQL_STATUS_MEMORY_USED);
-	mem0.nearlyFull = (n > 0 && n <= nUsed);
-	excess = sql_memory_used() - n;
-	if (excess > 0)
-		sql_release_memory((int)(excess & 0x7fffffff));
-	return priorLimit;
-}
-
-void
-sql_soft_heap_limit(int n)
-{
-	if (n < 0)
-		n = 0;
-	sql_soft_heap_limit64(n);
-}
-
 /*
  * Initialize the memory allocation subsystem.
  */
@@ -263,30 +231,6 @@ sqlMallocEnd(void)
 }
 
 /*
- * Return the amount of memory currently checked out.
- */
-sql_int64
-sql_memory_used(void)
-{
-	sql_int64 res, mx;
-	sql_status64(SQL_STATUS_MEMORY_USED, &res, &mx, 0);
-	return res;
-}
-
-/*
- * Return the maximum amount of memory that has ever been
- * checked out since either the beginning of this process
- * or since the most recent reset.
- */
-sql_int64
-sql_memory_highwater(int resetFlag)
-{
-	sql_int64 res, mx;
-	sql_status64(SQL_STATUS_MEMORY_USED, &res, &mx, resetFlag);
-	return mx;
-}
-
-/*
  * Trigger the alarm
  */
 static void
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 345b0a4..8b63c40 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -370,8 +370,6 @@ enum sql_ret_code {
 	SQL_TOOBIG,
 	/** Abort due to constraint violation. */
 	SQL_CONSTRAINT,
-	/** Library used incorrectly. */
-	SQL_MISUSE,
 	/** 2nd parameter to sql_bind out of range. */
 	SQL_RANGE,
 	SQL_TARANTOOL_ERROR,
@@ -700,9 +698,6 @@ sql_os_end(void);
 #define SQL_STATUS_SCRATCH_SIZE         8
 #define SQL_STATUS_MALLOC_COUNT         9
 
-sql_int64
-sql_memory_used(void);
-
 int
 sql_create_function_v2(sql * db,
 			   const char *zFunctionName,
@@ -761,11 +756,6 @@ sql_vfs_find(const char *zVfsName);
 #define SQL_TESTCTRL_SORTER_MMAP             24
 #define SQL_TESTCTRL_LAST                    24
 
-int
-sql_status64(int op, sql_int64 * pCurrent,
-		 sql_int64 * pHighwater,
-		 int resetFlag);
-
 
 typedef struct sql_io_methods sql_io_methods;
 struct sql_io_methods {
@@ -805,9 +795,6 @@ struct sql_io_methods {
 int
 sql_os_init(void);
 
-sql_int64
-sql_soft_heap_limit64(sql_int64 N);
-
 int
 sql_limit(sql *, int id, int newVal);
 
diff --git a/src/box/sql/status.c b/src/box/sql/status.c
index 2d4eae0..10be3d9 100644
--- a/src/box/sql/status.c
+++ b/src/box/sql/status.c
@@ -127,39 +127,6 @@ sqlStatusHighwater(int op, int X)
 }
 
 /*
- * Query status information.
- */
-int
-sql_status64(int op,
-		 sql_int64 * pCurrent,
-		 sql_int64 * pHighwater, int resetFlag)
-{
-	wsdStatInit;
-	if (op < 0 || op >= ArraySize(wsdStat.nowValue)) {
-		return SQL_MISUSE;
-	}
-	*pCurrent = wsdStat.nowValue[op];
-	*pHighwater = wsdStat.mxValue[op];
-	if (resetFlag) {
-		wsdStat.mxValue[op] = wsdStat.nowValue[op];
-	}
-	return 0;
-}
-
-int
-sql_status(int op, int *pCurrent, int *pHighwater, int resetFlag)
-{
-	sql_int64 iCur = 0, iHwtr = 0;
-	int rc;
-	rc = sql_status64(op, &iCur, &iHwtr, resetFlag);
-	if (rc == 0) {
-		*pCurrent = (int)iCur;
-		*pHighwater = (int)iHwtr;
-	}
-	return rc;
-}
-
-/*
  * Query status information for a single database connection
  */
 int
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index f3f7f48..7ac3211 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -966,11 +966,7 @@ vdbeUnbind(Vdbe * p, int i)
 {
 	Mem *pVar;
 	assert(p != NULL);
-	if (p->magic != VDBE_MAGIC_RUN || p->pc >= 0) {
-		sql_log(SQL_MISUSE,
-			    "bind on a busy prepared statement: [%s]", p->zSql);
-		return SQL_MISUSE;
-	}
+	assert(p->magic == VDBE_MAGIC_RUN && p->pc < 0);
 	if (i < 1 || i > p->nVar) {
 		return SQL_RANGE;
 	}
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 14/28] sql: remove SQL_RANGE errcode
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (12 preceding siblings ...)
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 13/28] sql: remove SQL_MISUSE errcode imeevma
@ 2019-06-10 13:56 ` imeevma
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 15/28] sql: remove SQL_SCHEMA errcode imeevma
                   ` (17 subsequent siblings)
  31 siblings, 0 replies; 56+ messages in thread
From: imeevma @ 2019-06-10 13:56 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/bind.c         |  37 ++++-----------
 src/box/sql/sqlInt.h   |   2 -
 src/box/sql/vdbeapi.c  | 122 +++++++++++++++++++++----------------------------
 test/sql/bind.result   |   8 ++++
 test/sql/bind.test.lua |   3 ++
 5 files changed, 72 insertions(+), 100 deletions(-)

diff --git a/src/box/bind.c b/src/box/bind.c
index 90d56d6..4888265 100644
--- a/src/box/bind.c
+++ b/src/box/bind.c
@@ -162,7 +162,6 @@ int
 sql_bind_column(struct sql_stmt *stmt, const struct sql_bind *p,
 		uint32_t pos)
 {
-	int rc;
 	if (p->name != NULL) {
 		pos = sql_bind_parameter_lindex(stmt, p->name, p->name_len);
 		if (pos == 0) {
@@ -174,15 +173,12 @@ sql_bind_column(struct sql_stmt *stmt, const struct sql_bind *p,
 	switch (p->type) {
 	case MP_INT:
 	case MP_UINT:
-		rc = sql_bind_int64(stmt, pos, p->i64);
-		break;
+		return sql_bind_int64(stmt, pos, p->i64);
 	case MP_BOOL:
-		rc = sql_bind_boolean(stmt, pos, p->b);
-		break;
+		return sql_bind_boolean(stmt, pos, p->b);
 	case MP_DOUBLE:
 	case MP_FLOAT:
-		rc = sql_bind_double(stmt, pos, p->d);
-		break;
+		return sql_bind_double(stmt, pos, p->d);
 	case MP_STR:
 		/*
 		 * Parameters are allocated within message pack,
@@ -192,31 +188,14 @@ sql_bind_column(struct sql_stmt *stmt, const struct sql_bind *p,
 		 * there is no need to copy the packet and we can
 		 * use SQL_STATIC.
 		 */
-		rc = sql_bind_text64(stmt, pos, p->s, p->bytes,
-					 SQL_STATIC);
-		break;
+		return sql_bind_text64(stmt, pos, p->s, p->bytes, SQL_STATIC);
 	case MP_NIL:
-		rc = sql_bind_null(stmt, pos);
-		break;
+		return sql_bind_null(stmt, pos);
 	case MP_BIN:
-		rc = sql_bind_blob64(stmt, pos, (const void *) p->s,
-					 p->bytes, SQL_STATIC);
-		break;
+		return sql_bind_blob64(stmt, pos, (const void *) p->s, p->bytes,
+				       SQL_STATIC);
 	default:
 		unreachable();
 	}
-	if (rc == 0)
-		return 0;
-
-	switch (rc) {
-	case SQL_NOMEM:
-		diag_set(OutOfMemory, p->bytes, "vdbe", "bind value");
-		break;
-	case SQL_TOOBIG:
-	default:
-		diag_set(ClientError, ER_SQL_BIND_VALUE, sql_bind_name(p),
-			 mp_type_strs[p->type]);
-		break;
-	}
-	return -1;
+	return 0;
 }
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 8b63c40..ceaca52 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -370,8 +370,6 @@ enum sql_ret_code {
 	SQL_TOOBIG,
 	/** Abort due to constraint violation. */
 	SQL_CONSTRAINT,
-	/** 2nd parameter to sql_bind out of range. */
-	SQL_RANGE,
 	SQL_TARANTOOL_ERROR,
 	/** sql_step() has another row ready. */
 	SQL_ROW,
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 7ac3211..a850d7f 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -955,11 +955,7 @@ sql_column_origin_name(sql_stmt * pStmt, int N)
  */
 /*
  * Unbind the value bound to variable i in virtual machine p. This is the
- * the same as binding a NULL value to the column. If the "i" parameter is
- * out of range, then SQL_RANGE is returned. Othewise 0.
- *
- * The error code stored in database p->db is overwritten with the return
- * value in any case.
+ * the same as binding a NULL value to the column.
  */
 static int
 vdbeUnbind(Vdbe * p, int i)
@@ -967,8 +963,11 @@ vdbeUnbind(Vdbe * p, int i)
 	Mem *pVar;
 	assert(p != NULL);
 	assert(p->magic == VDBE_MAGIC_RUN && p->pc < 0);
-	if (i < 1 || i > p->nVar) {
-		return SQL_RANGE;
+	assert(i > 0);
+	if(i > p->nVar) {
+		diag_set(ClientError, ER_SQL_EXECUTE, "The number of "\
+			 "parameters is too large");
+		return -1;
 	}
 	i--;
 	pVar = &p->aVar[i];
@@ -1019,19 +1018,19 @@ sql_bind_type(struct Vdbe *v, uint32_t position, const char *type)
 {
 	if (v->res_var_count < position)
 		return 0;
-	int rc = sqlVdbeSetColName(v, v->var_pos[position - 1],
-				       COLNAME_DECLTYPE, type,
-				       SQL_TRANSIENT);
+	int rc = 0;
+	if (sqlVdbeSetColName(v, v->var_pos[position - 1], COLNAME_DECLTYPE,
+			      type, SQL_TRANSIENT) != 0)
+		rc = -1;
 	const char *bind_name = v->aColName[position - 1].z;
 	if (strcmp(bind_name, "?") == 0)
 		return rc;
 	for (uint32_t i = position; i < v->res_var_count; ++i) {
 		if (strcmp(bind_name,  v->aColName[i].z) == 0) {
-			rc = sqlVdbeSetColName(v, v->var_pos[i],
-						   COLNAME_DECLTYPE, type,
-						   SQL_TRANSIENT);
-			if (rc != 0)
-				return rc;
+			if (sqlVdbeSetColName(v, v->var_pos[i],
+					      COLNAME_DECLTYPE, type,
+					      SQL_TRANSIENT) != 0)
+				return -1;
 		}
 	}
 	return 0;
@@ -1050,21 +1049,17 @@ bindText(sql_stmt * pStmt,	/* The statement to bind against */
 {
 	Vdbe *p = (Vdbe *) pStmt;
 	Mem *pVar;
-	int rc;
-
-	rc = vdbeUnbind(p, i);
-	if (rc == 0) {
-		if (zData != 0) {
-			pVar = &p->aVar[i - 1];
-			rc = sqlVdbeMemSetStr(pVar, zData, nData, 1, xDel);
-			if (rc == 0)
-				rc = sql_bind_type(p, i, "TEXT");
-			rc = sqlApiExit(p->db, rc);
-		}
-	} else if (xDel != SQL_STATIC && xDel != SQL_TRANSIENT) {
-		xDel((void *)zData);
+	if (vdbeUnbind(p, i) != 0) {
+		if (xDel != SQL_STATIC && xDel != SQL_TRANSIENT)
+			xDel((void *)zData);
+		return -1;
 	}
-	return rc;
+	if (zData == NULL)
+		return 0;
+	pVar = &p->aVar[i - 1];
+	if (sqlVdbeMemSetStr(pVar, zData, nData, 1, xDel) != 0)
+		return -1;
+	return sql_bind_type(p, i, "TEXT");
 }
 
 /*
@@ -1076,19 +1071,17 @@ sql_bind_blob(sql_stmt * pStmt,
     )
 {
 	struct Vdbe *p = (Vdbe *) pStmt;
-	int rc = vdbeUnbind(p, i);
-	if (rc == 0) {
-		if (zData != 0) {
-			struct Mem *var = &p->aVar[i - 1];
-			rc = sqlVdbeMemSetStr(var, zData, nData, 0, xDel);
-			if (rc == 0)
-				rc = sql_bind_type(p, i, "BLOB");
-			rc = sqlApiExit(p->db, rc);
-		}
-	} else if (xDel != SQL_STATIC && xDel != SQL_TRANSIENT) {
-		xDel((void *)zData);
+	if (vdbeUnbind(p, i) != 0) {
+		if (xDel != SQL_STATIC && xDel != SQL_TRANSIENT)
+			xDel((void *)zData);
+		return -1;
 	}
-	return rc;
+	if (zData == NULL)
+		return 0;
+	struct Mem *var = &p->aVar[i - 1];
+	if (sqlVdbeMemSetStr(var, zData, nData, 0, xDel) != 0)
+		return -1;
+	return sql_bind_type(p, i, "BLOB");
 }
 
 int
@@ -1109,13 +1102,11 @@ sql_bind_blob64(sql_stmt * pStmt,
 int
 sql_bind_double(sql_stmt * pStmt, int i, double rValue)
 {
-	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
-	rc = vdbeUnbind(p, i);
-	if (rc == 0) {
-		rc = sql_bind_type(p, i, "NUMERIC");
-		sqlVdbeMemSetDouble(&p->aVar[i - 1], rValue);
-	}
+	if (vdbeUnbind(p, i) != 0)
+		return -1;
+	int rc = sql_bind_type(p, i, "NUMERIC");
+	sqlVdbeMemSetDouble(&p->aVar[i - 1], rValue);
 	return rc;
 }
 
@@ -1123,11 +1114,10 @@ int
 sql_bind_boolean(struct sql_stmt *stmt, int i, bool value)
 {
 	struct Vdbe *p = (struct Vdbe *) stmt;
-	int rc = vdbeUnbind(p, i);
-	if (rc == 0) {
-		rc = sql_bind_type(p, i, "BOOLEAN");
-		mem_set_bool(&p->aVar[i - 1], value);
-	}
+	if (vdbeUnbind(p, i) != 0)
+		return -1;
+	int rc = sql_bind_type(p, i, "BOOLEAN");
+	mem_set_bool(&p->aVar[i - 1], value);
 	return rc;
 }
 
@@ -1140,25 +1130,21 @@ sql_bind_int(sql_stmt * p, int i, int iValue)
 int
 sql_bind_int64(sql_stmt * pStmt, int i, sql_int64 iValue)
 {
-	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
-	rc = vdbeUnbind(p, i);
-	if (rc == 0) {
-		rc = sql_bind_type(p, i, "INTEGER");
-		sqlVdbeMemSetInt64(&p->aVar[i - 1], iValue);
-	}
+	if (vdbeUnbind(p, i) != 0)
+		return -1;
+	int rc = sql_bind_type(p, i, "INTEGER");
+	sqlVdbeMemSetInt64(&p->aVar[i - 1], iValue);
 	return rc;
 }
 
 int
 sql_bind_null(sql_stmt * pStmt, int i)
 {
-	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
-	rc = vdbeUnbind(p, i);
-	if (rc == 0)
-		rc = sql_bind_type(p, i, "BOOLEAN");
-	return rc;
+	if (vdbeUnbind(p, i) != 0)
+		return -1;
+	return sql_bind_type(p, i, "BOOLEAN");
 }
 
 int
@@ -1199,13 +1185,11 @@ sql_bind_text64(sql_stmt * pStmt,
 int
 sql_bind_zeroblob(sql_stmt * pStmt, int i, int n)
 {
-	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
-	rc = vdbeUnbind(p, i);
-	if (rc == 0) {
-		sqlVdbeMemSetZeroBlob(&p->aVar[i - 1], n);
-	}
-	return rc;
+	if (vdbeUnbind(p, i) != 0)
+		return -1;
+	sqlVdbeMemSetZeroBlob(&p->aVar[i - 1], n);
+	return 0;
 }
 
 int
diff --git a/test/sql/bind.result b/test/sql/bind.result
index 076bf83..18d546a 100644
--- a/test/sql/bind.result
+++ b/test/sql/bind.result
@@ -294,3 +294,11 @@ box.execute('DROP TABLE test')
 ---
 - row_count: 1
 ...
+box.execute('SELECT ?', {1, 2})
+---
+- error: 'Failed to execute SQL statement: The number of parameters is too large'
+...
+box.execute('SELECT $2', {1, 2, 3})
+---
+- error: 'Failed to execute SQL statement: The number of parameters is too large'
+...
diff --git a/test/sql/bind.test.lua b/test/sql/bind.test.lua
index 229207d..9dac485 100644
--- a/test/sql/bind.test.lua
+++ b/test/sql/bind.test.lua
@@ -98,3 +98,6 @@ end;
 test_run:cmd("setopt delimiter ''");
 
 box.execute('DROP TABLE test')
+
+box.execute('SELECT ?', {1, 2})
+box.execute('SELECT $2', {1, 2, 3})
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 15/28] sql: remove SQL_SCHEMA errcode
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (13 preceding siblings ...)
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 14/28] sql: remove SQL_RANGE errcode imeevma
@ 2019-06-10 13:56 ` imeevma
  2019-06-13 22:24   ` [tarantool-patches] " Vladislav Shpilevoy
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 16/28] sql: remove SQL_TOOBIG errcode imeevma
                   ` (16 subsequent siblings)
  31 siblings, 1 reply; 56+ messages in thread
From: imeevma @ 2019-06-10 13:56 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql/prepare.c | 42 ++++++------------------------------------
 src/box/sql/sqlInt.h  |  2 --
 src/box/sql/vdbe.c    |  5 +----
 src/box/sql/vdbeInt.h |  8 --------
 src/box/sql/vdbeapi.c | 23 +++--------------------
 5 files changed, 10 insertions(+), 70 deletions(-)

diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index 57b78d9..4f072f1 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -56,7 +56,7 @@ sqlPrepare(sql * db,	/* Database handle. */
 	Parse sParse;		/* Parsing context */
 	sql_parser_create(&sParse, db, current_session()->sql_flags);
 	sParse.pReprepare = pReprepare;
-	assert(ppStmt && *ppStmt == 0);
+	*ppStmt = NULL;
 	/* assert( !db->mallocFailed ); // not true with SQL_USE_ALLOCA */
 
 	/* Check to verify that it is possible to get a read lock on all
@@ -181,37 +181,12 @@ sqlPrepare(sql * db,	/* Database handle. */
 	return rc;
 }
 
-static int
-sqlLockAndPrepare(sql * db,		/* Database handle. */
-		      const char *zSql,		/* UTF-8 encoded SQL statement. */
-		      int nBytes,		/* Length of zSql in bytes. */
-		      int saveSqlFlag,		/* True to copy SQL text into the sql_stmt */
-		      Vdbe * pOld,		/* VM being reprepared */
-		      sql_stmt ** ppStmt,	/* OUT: A pointer to the prepared statement */
-		      const char **pzTail)	/* OUT: End of parsed string */
-{
-	int rc;
-
-	*ppStmt = 0;
-	assert(zSql != NULL && db != NULL);
-	rc = sqlPrepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt,
-			    pzTail);
-	if (rc == SQL_SCHEMA) {
-		sql_finalize(*ppStmt);
-		rc = sqlPrepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt,
-				    pzTail);
-	}
-	assert(rc == 0 || *ppStmt == 0);
-	return rc;
-}
-
 /*
  * Rerun the compilation of a statement after a schema change.
  */
 int
 sqlReprepare(Vdbe * p)
 {
-	int rc;
 	sql_stmt *pNew;
 	const char *zSql;
 	sql *db;
@@ -219,16 +194,11 @@ sqlReprepare(Vdbe * p)
 	zSql = sql_sql((sql_stmt *) p);
 	assert(zSql != 0);	/* Reprepare only called for prepare_v2() statements */
 	db = sqlVdbeDb(p);
-	rc = sqlLockAndPrepare(db, zSql, -1, 0, p, &pNew, 0);
-	if (rc) {
-		if (rc == SQL_NOMEM) {
-			sqlOomFault(db);
-		}
+	if (sqlPrepare(db, zSql, -1, 0, p, &pNew, 0) != 0) {
 		assert(pNew == 0);
-		return rc;
-	} else {
-		assert(pNew != 0);
+		return -1;
 	}
+	assert(pNew != 0);
 	sqlVdbeSwap((Vdbe *) pNew, p);
 	sqlTransferBindings(pNew, (sql_stmt *) p);
 	sqlVdbeResetStepResult((Vdbe *) pNew);
@@ -252,7 +222,7 @@ sql_prepare(sql * db,		/* Database handle. */
 		const char **pzTail)	/* OUT: End of parsed string */
 {
 	int rc;
-	rc = sqlLockAndPrepare(db, zSql, nBytes, 0, 0, ppStmt, pzTail);
+	rc = sqlPrepare(db, zSql, nBytes, 0, 0, ppStmt, pzTail);
 	assert(rc == 0 || ppStmt == 0 || *ppStmt == 0);	/* VERIFY: F13021 */
 	return rc;
 }
@@ -266,7 +236,7 @@ sql_prepare_v2(sql * db,	/* Database handle. */
     )
 {
 	int rc;
-	rc = sqlLockAndPrepare(db, zSql, nBytes, 1, 0, ppStmt, pzTail);
+	rc = sqlPrepare(db, zSql, nBytes, 1, 0, ppStmt, pzTail);
 	assert(rc == 0 || ppStmt == 0 || *ppStmt == 0);	/* VERIFY: F13021 */
 	return rc;
 }
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index ceaca52..180859a 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -364,8 +364,6 @@ enum sql_ret_code {
 	SQL_NOMEM,
 	/** Some kind of disk I/O error occurred. */
 	SQL_IOERR,
-	/** The database schema changed. */
-	SQL_SCHEMA,
 	/** String or BLOB exceeds size limit. */
 	SQL_TOOBIG,
 	/** Abort due to constraint violation. */
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 77c6fa5..896585c 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -5122,10 +5122,7 @@ case OP_AggFinal: {
 
 /* Opcode: Expire P1 * * * *
  *
- * Cause precompiled statements to expire.  When an expired statement
- * is executed using sql_step() it will either automatically
- * reprepare itself (if it was originally created using sql_prepare_v2())
- * or it will fail with SQL_SCHEMA.
+ * Cause precompiled statements to expire.
  *
  * If P1 is 0, then all SQL statements become expired. If P1 is non-zero,
  * then only the currently executing statement is expired.
diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h
index 8da0c29..617f16f 100644
--- a/src/box/sql/vdbeInt.h
+++ b/src/box/sql/vdbeInt.h
@@ -40,14 +40,6 @@
 #define SQL_VDBEINT_H
 
 /*
- * The maximum number of times that a statement will try to reparse
- * itself before giving up and returning SQL_SCHEMA.
- */
-#ifndef SQL_MAX_SCHEMA_RETRY
-#define SQL_MAX_SCHEMA_RETRY 50
-#endif
-
-/*
  * SQL is translated into a sequence of instructions to be
  * executed by a virtual machine.  Each instruction is an instance
  * of the following structure.
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index a850d7f..cf1afe4 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -428,9 +428,8 @@ sqlStep(Vdbe * p)
 	}
 
 	if (p->pc <= 0 && p->expired) {
-		p->rc = SQL_SCHEMA;
-		rc = SQL_ERROR;
-		goto end_of_step;
+		p->rc = SQL_TARANTOOL_ERROR;
+		return SQL_TARANTOOL_ERROR;
 	}
 	if (p->pc < 0) {
 
@@ -463,7 +462,6 @@ sqlStep(Vdbe * p)
 	if (SQL_NOMEM == sqlApiExit(p->db, p->rc)) {
 		p->rc = SQL_NOMEM;
 	}
- end_of_step:
 	if (p->isPrepareV2 && rc != SQL_ROW && rc != SQL_DONE) {
 		/* If this statement was prepared using sql_prepare_v2(), and an
 		 * error has occurred, then return the error code in p->rc to the
@@ -482,24 +480,9 @@ sqlStep(Vdbe * p)
 int
 sql_step(sql_stmt * pStmt)
 {
-	int rc;			/* Result from sqlStep() */
 	Vdbe *v = (Vdbe *) pStmt;	/* the prepared statement */
-	int cnt = 0;		/* Counter to prevent infinite loop of reprepares */
-
 	assert(v != NULL);
-	v->doingRerun = 0;
-	while ((rc = sqlStep(v)) == SQL_SCHEMA
-	       && cnt++ < SQL_MAX_SCHEMA_RETRY) {
-		int savedPc = v->pc;
-		rc = sqlReprepare(v);
-		if (rc != 0)
-			break;
-		sql_reset(pStmt);
-		if (savedPc >= 0)
-			v->doingRerun = 1;
-		assert(v->expired == 0);
-	}
-	return rc;
+	return sqlStep(v);
 }
 
 /*
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 16/28] sql: remove SQL_TOOBIG errcode
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (14 preceding siblings ...)
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 15/28] sql: remove SQL_SCHEMA errcode imeevma
@ 2019-06-10 13:56 ` imeevma
  2019-06-13 22:24   ` [tarantool-patches] " Vladislav Shpilevoy
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 17/28] sql: remove SQL_BUSY errcode imeevma
                   ` (15 subsequent siblings)
  31 siblings, 1 reply; 56+ messages in thread
From: imeevma @ 2019-06-10 13:56 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql/sqlInt.h  |  2 --
 src/box/sql/vdbeapi.c | 25 +++++++++++++------------
 src/box/sql/vdbemem.c | 10 +++++++---
 3 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 180859a..f42b323 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -364,8 +364,6 @@ enum sql_ret_code {
 	SQL_NOMEM,
 	/** Some kind of disk I/O error occurred. */
 	SQL_IOERR,
-	/** String or BLOB exceeds size limit. */
-	SQL_TOOBIG,
 	/** Abort due to constraint violation. */
 	SQL_CONSTRAINT,
 	SQL_TARANTOOL_ERROR,
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index cf1afe4..ad8684d 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -262,7 +262,7 @@ sql_value_free(sql_value * pOld)
  *
  * The setStrOrError() function calls sqlVdbeMemSetStr() to store the
  * result as a string or blob but if the string or blob is too large, it
- * then sets the error code to SQL_TOOBIG
+ * then sets the error code.
  *
  * The invokeValueDestructor(P,X) routine invokes destructor function X()
  * on value P is not going to be used and need to be destroyed.
@@ -274,16 +274,14 @@ setResultStrOrError(sql_context * pCtx,	/* Function context */
 		    void (*xDel) (void *)	/* Destructor function */
     )
 {
-	if (sqlVdbeMemSetStr(pCtx->pOut, z, n,1, xDel) == SQL_TOOBIG) {
-		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob too big");
+	if (sqlVdbeMemSetStr(pCtx->pOut, z, n,1, xDel) != 0)
 		pCtx->is_aborted = true;
-	}
 }
 
 static int
 invokeValueDestructor(const void *p,	/* Value to destroy */
 		      void (*xDel) (void *),	/* The destructor */
-		      sql_context * pCtx	/* Set a SQL_TOOBIG error if no NULL */
+		      sql_context * pCtx	/* Set an error if no NULL */
     )
 {
 	assert(xDel != SQL_DYNAMIC);
@@ -295,10 +293,11 @@ invokeValueDestructor(const void *p,	/* Value to destroy */
 		xDel((void *)p);
 	}
 	if (pCtx) {
-		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob too big");
+		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob is too "\
+			 "big");
 		pCtx->is_aborted = true;
 	}
-	return SQL_TOOBIG;
+	return SQL_TARANTOOL_ERROR;
 }
 
 void
@@ -307,10 +306,8 @@ sql_result_blob(sql_context * pCtx,
     )
 {
 	assert(n >= 0);
-	if (sqlVdbeMemSetStr(pCtx->pOut, z, n,0, xDel) == SQL_TOOBIG) {
-		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob too big");
+	if (sqlVdbeMemSetStr(pCtx->pOut, z, n,0, xDel) != 0)
 		pCtx->is_aborted = true;
-	}
 }
 
 void
@@ -395,7 +392,9 @@ sql_result_zeroblob64(sql_context * pCtx, u64 n)
 {
 	Mem *pOut = pCtx->pOut;
 	if (n > (u64) pOut->db->aLimit[SQL_LIMIT_LENGTH]) {
-		return SQL_TOOBIG;
+		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob is too "\
+			 "big");
+		return SQL_TARANTOOL_ERROR;
 	}
 	sqlVdbeMemSetZeroBlob(pCtx->pOut, (int)n);
 	return 0;
@@ -1181,7 +1180,9 @@ sql_bind_zeroblob64(sql_stmt * pStmt, int i, sql_uint64 n)
 	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
 	if (n > (u64) p->db->aLimit[SQL_LIMIT_LENGTH]) {
-		rc = SQL_TOOBIG;
+		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob is too "\
+			 "big");
+		rc = SQL_TARANTOOL_ERROR;
 	} else {
 		assert((n & 0x7FFFFFFF) == n);
 		rc = sql_bind_zeroblob(pStmt, i, n);
diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
index 2f7fe4f..443bff0 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -950,7 +950,7 @@ sqlVdbeMemMove(Mem * pTo, Mem * pFrom)
  * size limit) then no memory allocation occurs.  If the string can be
  * stored without allocating memory, then it is.  If a memory allocation
  * is required to store the string, then value of pMem is unchanged.  In
- * either case, SQL_TOOBIG is returned.
+ * either case, error is returned.
  */
 int
 sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
@@ -994,7 +994,9 @@ sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
 			nAlloc += 1; //SQL_UTF8
 		}
 		if (nByte > iLimit) {
-			return SQL_TOOBIG;
+			diag_set(ClientError, ER_SQL_EXECUTE, "string or blob "\
+				 "is too big");
+			return SQL_TARANTOOL_ERROR;
 		}
 		testcase(nAlloc == 0);
 		testcase(nAlloc == 31);
@@ -1018,7 +1020,9 @@ sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
 	pMem->flags = flags;
 
 	if (nByte > iLimit) {
-		return SQL_TOOBIG;
+		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob is too "\
+			 "big");
+		return SQL_TARANTOOL_ERROR;
 	}
 
 	return 0;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 17/28] sql: remove SQL_BUSY errcode
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (15 preceding siblings ...)
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 16/28] sql: remove SQL_TOOBIG errcode imeevma
@ 2019-06-10 13:56 ` imeevma
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 18/28] sql: remove SQL_CONSTRAINT errcode imeevma
                   ` (14 subsequent siblings)
  31 siblings, 0 replies; 56+ messages in thread
From: imeevma @ 2019-06-10 13:56 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql/main.c    |  2 +-
 src/box/sql/os_unix.c |  4 +---
 src/box/sql/sqlInt.h  |  2 --
 src/box/sql/vdbe.c    | 20 ++++++--------------
 src/box/sql/vdbeaux.c | 14 ++++----------
 5 files changed, 12 insertions(+), 30 deletions(-)

diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index 65d8de5..052683e 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -266,7 +266,7 @@ sqlCreateFunc(sql * db,
 
 
 	/* Check if an existing function is being overridden or deleted. If so,
-	 * and there are active VMs, then return SQL_BUSY. If a function
+	 * and there are active VMs, then return an error. If a function
 	 * is being overridden/deleted but there are no active VMs, allow the
 	 * operation to continue but invalidate all precompiled statements.
 	 */
diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index fa28c46..69f6867 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -554,9 +554,7 @@ posixUnlock(sql_file * id, int eFileLock, int handleNFSUnlock)
 					/* In theory, the call to unixFileLock() cannot fail because another
 					 * process is holding an incompatible lock. If it does, this
 					 * indicates that the other process is not following the locking
-					 * protocol. If this happens, return SQL_IOERR_RDLOCK. Returning
-					 * SQL_BUSY would confuse the upper layer (in practice it causes
-					 * an assert to fail).
+					 * protocol. If this happens, return SQL_IOERR_RDLOCK.
 					 */
 					rc = SQL_IOERR_RDLOCK;
 					storeLastErrno(pFile, errno);
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index f42b323..9f15893 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -358,8 +358,6 @@ struct sql_vfs {
 enum sql_ret_code {
 	/** Common error code. */
 	SQL_ERROR = 1,
-	/** The database file is locked. */
-	SQL_BUSY,
 	/** A malloc() failed. */
 	SQL_NOMEM,
 	/** Some kind of disk I/O error occurred. */
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 896585c..c63f11c 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -752,7 +752,7 @@ int sqlVdbeExec(Vdbe *p)
 		 */
 		goto no_mem;
 	}
-	assert(p->rc==0 || (p->rc&0xff)==SQL_BUSY);
+	assert(p->rc == 0);
 	p->rc = 0;
 	p->iCurrentTime = 0;
 	assert(p->explain==0);
@@ -1068,13 +1068,9 @@ case OP_Halt: {
 		assert(! diag_is_empty(diag_get()));
 	}
 	rc = sqlVdbeHalt(p);
-	assert(rc==SQL_BUSY || rc==0 || rc==SQL_ERROR);
-	if (rc==SQL_BUSY) {
-		p->rc = SQL_BUSY;
-	} else {
-		assert(rc==0 || (p->rc&0xff)==SQL_CONSTRAINT);
-		rc = p->rc ? SQL_TARANTOOL_ERROR : SQL_DONE;
-	}
+	assert(rc == 0 || rc==SQL_ERROR);
+	assert(rc==0 || (p->rc&0xff)==SQL_CONSTRAINT);
+	rc = p->rc ? SQL_TARANTOOL_ERROR : SQL_DONE;
 	goto vdbe_return;
 }
 
@@ -2886,11 +2882,7 @@ case OP_Savepoint: {
 				if ((rc = sqlVdbeCheckFk(p, 1))!=0) {
 					goto vdbe_return;
 				}
-				if (sqlVdbeHalt(p)==SQL_BUSY) {
-					p->pc = (int)(pOp - aOp);
-					p->rc = rc = SQL_BUSY;
-					goto vdbe_return;
-				}
+				sqlVdbeHalt(p);
 				if (p->rc != 0)
 					goto abort_due_to_error;
 			} else {
@@ -5291,7 +5283,7 @@ vdbe_return:
 	assert(rc!=0 || nExtraDelete==0
 		|| sql_strlike_ci("DELETE%", p->zSql, 0) != 0
 		);
-	assert(rc == 0 || rc == SQL_BUSY || rc == SQL_TARANTOOL_ERROR ||
+	assert(rc == 0 || rc == SQL_TARANTOOL_ERROR ||
 	       rc == SQL_ROW || rc == SQL_DONE);
 	return rc;
 
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index efc5103..4f06369 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -1420,8 +1420,7 @@ sqlVdbeList(Vdbe * p)
 
 	assert(p->explain);
 	assert(p->magic == VDBE_MAGIC_RUN);
-	assert(p->rc == 0 || p->rc == SQL_BUSY
-	       || p->rc == SQL_NOMEM);
+	assert(p->rc == 0 || p->rc == SQL_NOMEM);
 
 	/* Even though this opcode does not use dynamic strings for
 	 * the result, result columns may become dynamic if the user calls
@@ -2161,9 +2160,7 @@ sql_savepoint(MAYBE_UNUSED Vdbe *p, const char *zName)
  * SQL_MAGIC_RUN to SQL_MAGIC_HALT.  It is harmless to
  * call this on a VM that is in the SQL_MAGIC_HALT state.
  *
- * Return an error code.  If the commit could not complete because of
- * lock contention, return SQL_BUSY.  If SQL_BUSY is returned, it
- * means the close did not happen and needs to be repeated.
+ * Return an error code.
  */
 int
 sqlVdbeHalt(Vdbe * p)
@@ -2268,10 +2265,7 @@ sqlVdbeHalt(Vdbe * p)
 					     0 : SQL_TARANTOOL_ERROR;
 					closeCursorsAndFree(p);
 				}
-				if (rc == SQL_BUSY && !p->pDelFrame) {
-					closeCursorsAndFree(p);
-					return SQL_BUSY;
-				} else if (rc != 0) {
+				if (rc != 0) {
 					p->rc = rc;
 					box_txn_rollback();
 					closeCursorsAndFree(p);
@@ -2348,7 +2342,7 @@ sqlVdbeHalt(Vdbe * p)
 
 	assert(db->nVdbeActive > 0 || box_txn() ||
 	       p->anonymous_savepoint == NULL);
-	return (p->rc == SQL_BUSY ? SQL_BUSY : 0);
+	return 0;
 }
 
 /*
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 18/28] sql: remove SQL_CONSTRAINT errcode
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (16 preceding siblings ...)
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 17/28] sql: remove SQL_BUSY errcode imeevma
@ 2019-06-10 13:56 ` imeevma
  2019-06-13 22:24   ` [tarantool-patches] " Vladislav Shpilevoy
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 19/28] sql: remove SQL_ERROR errcode imeevma
                   ` (13 subsequent siblings)
  31 siblings, 1 reply; 56+ messages in thread
From: imeevma @ 2019-06-10 13:56 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql/fk_constraint.c |  4 ++--
 src/box/sql/sqlInt.h        |  7 -------
 src/box/sql/vdbe.c          |  1 -
 src/box/sql/vdbeaux.c       | 10 +++-------
 4 files changed, 5 insertions(+), 17 deletions(-)

diff --git a/src/box/sql/fk_constraint.c b/src/box/sql/fk_constraint.c
index 08e7f62..6cb41f8 100644
--- a/src/box/sql/fk_constraint.c
+++ b/src/box/sql/fk_constraint.c
@@ -44,7 +44,7 @@
  *
  * Foreign keys in sql come in two flavours: deferred and immediate.
  * If an immediate foreign key constraint is violated,
- * SQL_CONSTRAINT_FOREIGNKEY is returned and the current
+ * -1 is returned and the current
  * statement transaction rolled back. If a
  * deferred foreign key constraint is violated, no action is taken
  * immediately. However if the application attempts to commit the
@@ -110,7 +110,7 @@
  * is that the counter used is stored as part of each individual statement
  * object (struct Vdbe). If, after the statement has run, its immediate
  * constraint counter is greater than zero,
- * it returns SQL_CONSTRAINT_FOREIGNKEY
+ * it returns -1.
  * and the statement transaction is rolled back. An exception is an INSERT
  * statement that inserts a single row only (no triggers). In this case,
  * instead of using a counter, an exception is thrown immediately if the
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 9f15893..ec4eb29 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -363,7 +363,6 @@ enum sql_ret_code {
 	/** Some kind of disk I/O error occurred. */
 	SQL_IOERR,
 	/** Abort due to constraint violation. */
-	SQL_CONSTRAINT,
 	SQL_TARANTOOL_ERROR,
 	/** sql_step() has another row ready. */
 	SQL_ROW,
@@ -604,12 +603,6 @@ sql_exec(sql *,	/* An open database */
 #define SQL_IOERR_GETTEMPPATH       (SQL_IOERR | (25<<8))
 #define SQL_IOERR_CONVPATH          (SQL_IOERR | (26<<8))
 #define SQL_IOERR_VNODE             (SQL_IOERR | (27<<8))
-#define SQL_CONSTRAINT_FOREIGNKEY   (SQL_CONSTRAINT | (3<<8))
-#define SQL_CONSTRAINT_FUNCTION     (SQL_CONSTRAINT | (4<<8))
-#define SQL_CONSTRAINT_NOTNULL      (SQL_CONSTRAINT | (5<<8))
-#define SQL_CONSTRAINT_PRIMARYKEY   (SQL_CONSTRAINT | (6<<8))
-#define SQL_CONSTRAINT_TRIGGER      (SQL_CONSTRAINT | (7<<8))
-#define SQL_CONSTRAINT_UNIQUE       (SQL_CONSTRAINT | (8<<8))
 
 /**
  * Subtype of a main type. Allows to do some subtype specific
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index c63f11c..57d6d60 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -1069,7 +1069,6 @@ case OP_Halt: {
 	}
 	rc = sqlVdbeHalt(p);
 	assert(rc == 0 || rc==SQL_ERROR);
-	assert(rc==0 || (p->rc&0xff)==SQL_CONSTRAINT);
 	rc = p->rc ? SQL_TARANTOOL_ERROR : SQL_DONE;
 	goto vdbe_return;
 }
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 4f06369..308373b 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -2088,8 +2088,7 @@ sqlVdbeCloseStatement(Vdbe * p, int eOp)
  * violations, return SQL_ERROR. Otherwise, 0.
  *
  * If there are outstanding FK violations and this function returns
- * SQL_ERROR, set the result of the VM to SQL_CONSTRAINT_FOREIGNKEY
- * and write an error message to it. Then return SQL_ERROR.
+ * SQL_TARANTOOL_ERROR and set an error.
  */
 int
 sqlVdbeCheckFk(Vdbe * p, int deferred)
@@ -2253,7 +2252,6 @@ sqlVdbeHalt(Vdbe * p)
 						closeCursorsAndFree(p);
 						return SQL_ERROR;
 					}
-					rc = SQL_CONSTRAINT_FOREIGNKEY;
 				} else {
 					/* The auto-commit flag is true, the vdbe program was successful
 					 * or hit an 'OR FAIL' constraint and there are no deferred foreign
@@ -2296,17 +2294,15 @@ sqlVdbeHalt(Vdbe * p)
 		/* If eStatementOp is non-zero, then a statement transaction needs to
 		 * be committed or rolled back. Call sqlVdbeCloseStatement() to
 		 * do so. If this operation returns an error, and the current statement
-		 * error code is 0 or SQL_CONSTRAINT, then promote the
+		 * error code is 0 or -1, then promote the
 		 * current statement error code.
 		 */
 		if (eStatementOp) {
 			rc = sqlVdbeCloseStatement(p, eStatementOp);
 			if (rc) {
 				box_txn_rollback();
-				if (p->rc == 0
-				    || (p->rc & 0xff) == SQL_CONSTRAINT) {
+				if (p->rc == 0)
 					p->rc = rc;
-				}
 				closeCursorsAndFree(p);
 				sqlRollbackAll(p);
 				sqlCloseSavepoints(p);
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 19/28] sql: remove SQL_ERROR errcode
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (17 preceding siblings ...)
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 18/28] sql: remove SQL_CONSTRAINT errcode imeevma
@ 2019-06-10 13:56 ` imeevma
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 20/28] sql: remove SQL_NOMEM errcode imeevma
                   ` (12 subsequent siblings)
  31 siblings, 0 replies; 56+ messages in thread
From: imeevma @ 2019-06-10 13:56 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql/date.c     |  4 ++--
 src/box/sql/main.c     |  2 +-
 src/box/sql/os_unix.c  |  5 ++---
 src/box/sql/select.c   | 12 ++++++------
 src/box/sql/sqlInt.h   |  4 +---
 src/box/sql/status.c   |  2 +-
 src/box/sql/vdbe.c     |  2 +-
 src/box/sql/vdbeapi.c  |  2 +-
 src/box/sql/vdbeaux.c  | 12 ++++++------
 src/box/sql/vdbemem.c  |  4 ++--
 src/box/sql/vdbesort.c |  2 +-
 11 files changed, 24 insertions(+), 27 deletions(-)

diff --git a/src/box/sql/date.c b/src/box/sql/date.c
index e193035..547932b 100644
--- a/src/box/sql/date.c
+++ b/src/box/sql/date.c
@@ -578,7 +578,7 @@ osLocaltime(time_t * t, struct tm *pTm)
  * (a.k.a. GMT) for the time value p where p is in UTC. If no error occurs,
  * return this value and set *pRc to 0.
  *
- * Or, if an error does occur, set *pRc to SQL_ERROR. The returned value
+ * Or, if an error does occur, set *pRc to -1. The returned value
  * is undefined in this case.
  */
 static sql_int64
@@ -619,7 +619,7 @@ localtimeOffset(DateTime * p,	/* Date at which to calculate offset */
 	if (osLocaltime(&t, &sLocal)) {
 		diag_set(ClientError, ER_SQL_EXECUTE, "local time unavailable");
 		pCtx->is_aborted = true;
-		*pRc = SQL_ERROR;
+		*pRc = -1;
 		return 0;
 	}
 	y.Y = sLocal.tm_year + 1900;
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index 052683e..8474836 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -320,7 +320,7 @@ sql_create_function_v2(sql * db,
 			   void (*xFinal) (sql_context *),
 			   void (*xDestroy) (void *))
 {
-	int rc = SQL_ERROR;
+	int rc = -1;
 	FuncDestructor *pArg = 0;
 
 	if (xDestroy) {
diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index 69f6867..8b3aec1 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -1482,7 +1482,7 @@ unixGetTempname(int nBuf, char *zBuf)
 				 "%s/" SQL_TEMP_FILE_PREFIX "%llx%c", zDir,
 				 r, 0);
 		if (zBuf[nBuf - 2] != 0 || (iLimit++) > 10)
-			return SQL_ERROR;
+			return -1;
 	} while (access(zBuf, 0) == 0);
 	return 0;
 }
@@ -1877,8 +1877,7 @@ int sql_current_time = 0;
  * epoch of noon in Greenwich on November 24, 4714 B.C according to the
  * proleptic Gregorian calendar.
  *
- * On success, return 0.  Return SQL_ERROR if the time and date
- * cannot be found.
+ * On success, return 0.
  */
 static int
 unixCurrentTimeInt64(sql_vfs * NotUsed, sql_int64 * piNow)
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index 6e22153..a1bed97 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -4410,7 +4410,7 @@ is_simple_count(struct Select *select, struct AggInfo *agg_info)
  * If the source-list item passed as an argument was augmented with an
  * INDEXED BY clause, then try to locate the specified index. If there
  * was such a clause and the named index cannot be found, return
- * SQL_ERROR and leave an error in pParse. Otherwise, populate
+ * -1 and set an error. Otherwise, populate
  * pFrom->pIndex and return 0.
  */
 int
@@ -4431,7 +4431,7 @@ sqlIndexedByLookup(Parse * pParse, struct SrcList_item *pFrom)
 			diag_set(ClientError, ER_NO_SUCH_INDEX_NAME,
 				 zIndexedBy, space->def->name);
 			pParse->is_aborted = true;
-			return SQL_ERROR;
+			return -1;
 		}
 		pFrom->pIBIndex = idx->def;
 	}
@@ -4620,14 +4620,14 @@ withExpand(Walker * pWalker, struct SrcList_item *pFrom)
 			diag_set(ClientError, ER_SQL_PARSER_GENERIC,
 				 tt_sprintf(pCte->zCteErr, pCte->zName));
 			pParse->is_aborted = true;
-			return SQL_ERROR;
+			return -1;
 		}
 		if (pFrom->fg.isTabFunc) {
 			const char *err = "'%s' is not a function";
 			diag_set(ClientError, ER_SQL_PARSER_GENERIC,
 				 tt_sprintf(err, pFrom->zName));
 			pParse->is_aborted = true;
-			return SQL_ERROR;
+			return -1;
 		}
 
 		assert(pFrom->space == NULL);
@@ -4665,7 +4665,7 @@ withExpand(Walker * pWalker, struct SrcList_item *pFrom)
 					   "table: %s", pCte->zName);
 			diag_set(ClientError, ER_SQL_PARSER_GENERIC, err_msg);
 			pParse->is_aborted = true;
-			return SQL_ERROR;
+			return -1;
 		}
 		assert(ref_counter == 0 ||
 			((pSel->selFlags & SF_Recursive) && ref_counter == 1));
@@ -4688,7 +4688,7 @@ withExpand(Walker * pWalker, struct SrcList_item *pFrom)
 				diag_set(ClientError, ER_SQL_PARSER_GENERIC, err_msg);
 				pParse->is_aborted = true;
 				pParse->pWith = pSavedWith;
-				return SQL_ERROR;
+				return -1;
 			}
 			pEList = pCte->pCols;
 		}
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index ec4eb29..3aabcb2 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -356,10 +356,8 @@ struct sql_vfs {
 #define SQL_LIMIT_WORKER_THREADS           10
 
 enum sql_ret_code {
-	/** Common error code. */
-	SQL_ERROR = 1,
 	/** A malloc() failed. */
-	SQL_NOMEM,
+	SQL_NOMEM = 2,
 	/** Some kind of disk I/O error occurred. */
 	SQL_IOERR,
 	/** Abort due to constraint violation. */
diff --git a/src/box/sql/status.c b/src/box/sql/status.c
index 10be3d9..d6de484 100644
--- a/src/box/sql/status.c
+++ b/src/box/sql/status.c
@@ -257,7 +257,7 @@ sql_db_status(sql * db,	/* The database connection whose status is desired */
 		}
 
 	default:{
-			rc = SQL_ERROR;
+			rc = -1;
 		}
 	}
 	return rc;
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 57d6d60..c8ca8c4 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -1068,7 +1068,7 @@ case OP_Halt: {
 		assert(! diag_is_empty(diag_get()));
 	}
 	rc = sqlVdbeHalt(p);
-	assert(rc == 0 || rc==SQL_ERROR);
+	assert(rc == 0 || rc == -1);
 	rc = p->rc ? SQL_TARANTOOL_ERROR : SQL_DONE;
 	goto vdbe_return;
 }
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index ad8684d..db8687b 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -708,7 +708,7 @@ columnMallocFailure(sql_stmt * pStmt)
 {
 	/* If malloc() failed during an encoding conversion within an
 	 * sql_column_XXX API, then set the return code of the statement to
-	 * SQL_NOMEM. The next call to _step() (if any) will return SQL_ERROR
+	 * SQL_NOMEM. The next call to _step() (if any) will return -1
 	 * and _finalize() will return NOMEM.
 	 */
 	Vdbe *p = (Vdbe *) pStmt;
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 308373b..e056c40 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -1434,7 +1434,7 @@ sqlVdbeList(Vdbe * p)
 		 * sql_column_text16() failed.
 		 */
 		sqlOomFault(db);
-		return SQL_ERROR;
+		return -1;
 	}
 
 	/* When the number of output rows reaches nRow, that means the
@@ -1540,7 +1540,7 @@ sqlVdbeList(Vdbe * p)
 
 		if (sqlVdbeMemClearAndResize(pMem, 256)) {
 			assert(p->db->mallocFailed);
-			return SQL_ERROR;
+			return -1;
 		}
 		pMem->flags = MEM_Str | MEM_Term;
 		zP4 = displayP4(pOp, pMem->z, pMem->szMalloc);
@@ -1557,7 +1557,7 @@ sqlVdbeList(Vdbe * p)
 		if (p->explain == 1) {
 			if (sqlVdbeMemClearAndResize(pMem, 4)) {
 				assert(p->db->mallocFailed);
-				return SQL_ERROR;
+				return -1;
 			}
 			pMem->flags = MEM_Str | MEM_Term;
 			pMem->n = 2;
@@ -1567,7 +1567,7 @@ sqlVdbeList(Vdbe * p)
 #ifdef SQL_ENABLE_EXPLAIN_COMMENTS
 			if (sqlVdbeMemClearAndResize(pMem, 500)) {
 				assert(p->db->mallocFailed);
-				return SQL_ERROR;
+				return -1;
 			}
 			pMem->flags = MEM_Str | MEM_Term;
 			pMem->n = displayComment(pOp, zP4, pMem->z, 500);
@@ -2085,7 +2085,7 @@ sqlVdbeCloseStatement(Vdbe * p, int eOp)
  * This function is called when a transaction opened by the database
  * handle associated with the VM passed as an argument is about to be
  * committed. If there are outstanding deferred foreign key constraint
- * violations, return SQL_ERROR. Otherwise, 0.
+ * violations, return -1. Otherwise, 0.
  *
  * If there are outstanding FK violations and this function returns
  * SQL_TARANTOOL_ERROR and set an error.
@@ -2250,7 +2250,7 @@ sqlVdbeHalt(Vdbe * p)
 					 */
 					if (NEVER(p->pDelFrame)) {
 						closeCursorsAndFree(p);
-						return SQL_ERROR;
+						return -1;
 					}
 				} else {
 					/* The auto-commit flag is true, the vdbe program was successful
diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
index 443bff0..933ad6f 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -562,7 +562,7 @@ sqlVdbeMemRealify(Mem * pMem)
 	assert(EIGHT_BYTE_ALIGNMENT(pMem));
 	double v;
 	if (sqlVdbeRealValue(pMem, &v))
-		return SQL_ERROR;
+		return -1;
 
 	pMem->u.r = v;
 	MemSetTypeFlag(pMem, MEM_Real);
@@ -587,7 +587,7 @@ sqlVdbeMemNumerify(Mem * pMem)
 		} else {
 			double v;
 			if (sqlVdbeRealValue(pMem, &v))
-				return SQL_ERROR;
+				return -1;
 			pMem->u.r = v;
 			MemSetTypeFlag(pMem, MEM_Real);
 			mem_apply_integer_type(pMem);
diff --git a/src/box/sql/vdbesort.c b/src/box/sql/vdbesort.c
index f7fc8e1..b6ae888 100644
--- a/src/box/sql/vdbesort.c
+++ b/src/box/sql/vdbesort.c
@@ -1027,7 +1027,7 @@ vdbeSorterJoinThread(SortSubtask * pTask)
 #ifdef SQL_DEBUG_SORTER_THREADS
 		int bDone = pTask->bDone;
 #endif
-		void *pRet = SQL_INT_TO_PTR(SQL_ERROR);
+		void *pRet = SQL_INT_TO_PTR(-1);
 		vdbeSorterBlockDebug(pTask, !bDone, "enter");
 		(void)sqlThreadJoin(pTask->pThread, &pRet);
 		vdbeSorterBlockDebug(pTask, !bDone, "exit");
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 20/28] sql: remove SQL_NOMEM errcode
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (18 preceding siblings ...)
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 19/28] sql: remove SQL_ERROR errcode imeevma
@ 2019-06-10 13:56 ` imeevma
  2019-06-13 22:24   ` [tarantool-patches] " Vladislav Shpilevoy
  2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 21/28] sql: remove SQL_IOERR errcode imeevma
                   ` (11 subsequent siblings)
  31 siblings, 1 reply; 56+ messages in thread
From: imeevma @ 2019-06-10 13:56 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql/fault.c    |  4 ++--
 src/box/sql/func.c     | 14 ++++----------
 src/box/sql/legacy.c   |  1 -
 src/box/sql/main.c     | 26 ++++++++++---------------
 src/box/sql/malloc.c   |  7 ++-----
 src/box/sql/os.c       |  4 ++--
 src/box/sql/os_unix.c  |  4 ++--
 src/box/sql/select.c   | 11 +++++------
 src/box/sql/sqlInt.h   |  4 +---
 src/box/sql/vdbe.c     | 14 +++-----------
 src/box/sql/vdbeapi.c  | 52 ++------------------------------------------------
 src/box/sql/vdbeaux.c  | 48 ++++++++++++++++------------------------------
 src/box/sql/vdbemem.c  | 25 ++++++++++++------------
 src/box/sql/vdbesort.c | 46 +++++++++++++++++++++-----------------------
 src/box/sql/where.c    | 12 ++++++------
 15 files changed, 89 insertions(+), 183 deletions(-)

diff --git a/src/box/sql/fault.c b/src/box/sql/fault.c
index 8ee774e..0e0978d 100644
--- a/src/box/sql/fault.c
+++ b/src/box/sql/fault.c
@@ -37,8 +37,8 @@
  * and returns 0).
  *
  * Most malloc failures are non-benign. After they occur, sql
- * abandons the current operation and returns an error code (usually
- * SQL_NOMEM) to the user. However, sometimes a fault is not necessarily
+ * abandons the current operation and returns an -1
+ * to the user. However, sometimes a fault is not necessarily
  * fatal. For example, if a malloc fails while resizing a hash table, this
  * is completely recoverable simply by not carrying out the resize. The
  * hash table will continue to function normally.  So a malloc failure
diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 29712e0..994d97e 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -1799,14 +1799,11 @@ static inline int
 sql_overload_function(sql * db, const char *zName,
 			  enum field_type type, int nArg)
 {
-	int rc = 0;
-
 	if (sqlFindFunction(db, zName, nArg, 0) == 0) {
-		rc = sqlCreateFunc(db, zName, type, nArg, 0, 0,
-				       sqlInvalidFunction, 0, 0, 0);
+		return sqlCreateFunc(db, zName, type, nArg, 0, 0,
+				     sqlInvalidFunction, 0, 0, 0);
 	}
-	rc = sqlApiExit(db, rc);
-	return rc;
+	return 0;
 }
 
 /*
@@ -1817,11 +1814,8 @@ sql_overload_function(sql * db, const char *zName,
 void
 sqlRegisterPerConnectionBuiltinFunctions(sql * db)
 {
-	int rc = sql_overload_function(db, "MATCH", FIELD_TYPE_SCALAR, 2);
-	assert(rc == SQL_NOMEM || rc == 0);
-	if (rc == SQL_NOMEM) {
+	if (sql_overload_function(db, "MATCH", FIELD_TYPE_SCALAR, 2) != 0)
 		sqlOomFault(db);
-	}
 }
 
 /*
diff --git a/src/box/sql/legacy.c b/src/box/sql/legacy.c
index 3101428..df40032 100644
--- a/src/box/sql/legacy.c
+++ b/src/box/sql/legacy.c
@@ -162,7 +162,6 @@ sql_exec(sql * db,	/* The database on which the SQL executes */
 		sqlVdbeFinalize((Vdbe *) pStmt);
 	sqlDbFree(db, azCols);
 
-	rc = sqlApiExit(db, rc);
 	assert(rc == 0);
 	assert((rc & db->errMask) == rc);
 	return rc;
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index 8474836..e6d3a3d 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -525,16 +525,16 @@ int
 sql_init_db(sql **out_db)
 {
 	sql *db;
-	int rc;			/* Return code */
 
-	rc = sql_initialize();
-	if (rc)
-		return rc;
+	if (sql_initialize())
+		return -1;
 
 	/* Allocate the sql data structure */
 	db = sqlMallocZero(sizeof(sql));
-	if (db == 0)
-		goto opendb_out;
+	if (db == NULL) {
+		*out_db = NULL;
+		return -1;
+	}
 	db->errMask = 0xff;
 	db->magic = SQL_MAGIC_BUSY;
 
@@ -549,7 +549,9 @@ sql_init_db(sql **out_db)
 
 	db->magic = SQL_MAGIC_OPEN;
 	if (db->mallocFailed) {
-		goto opendb_out;
+		sql_free(db);
+		*out_db = NULL;
+		return -1;
 	}
 
 	/* Register all built-in functions, but do not attempt to read the
@@ -558,16 +560,8 @@ sql_init_db(sql **out_db)
 	 */
 	sqlRegisterPerConnectionBuiltinFunctions(db);
 
-opendb_out:
-	assert(db != 0 || rc == SQL_NOMEM);
-	if (rc == SQL_NOMEM)
-		db = NULL;
-	else if (rc != 0)
-		db->magic = SQL_MAGIC_SICK;
-
 	*out_db = db;
-
-	return rc;
+	return 0;
 }
 
 /*
diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index 8830cc8..4b8ef8f 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -765,7 +765,7 @@ static SQL_NOINLINE int
 apiOomError(sql * db)
 {
 	sqlOomClear(db);
-	return SQL_NOMEM;
+	return -1;
 }
 
 /*
@@ -774,10 +774,7 @@ apiOomError(sql * db)
  * sql_realloc.
  *
  * The returned value is normally a copy of the second argument to this
- * function. However, if a malloc() failure has occurred since the previous
- * invocation SQL_NOMEM is returned instead.
- *
- * If an OOM as occurred, SQL_NOMEM is returned.
+ * function.
  */
 int
 sqlApiExit(sql * db, int rc)
diff --git a/src/box/sql/os.c b/src/box/sql/os.c
index 273aa6b..9f45eba 100644
--- a/src/box/sql/os.c
+++ b/src/box/sql/os.c
@@ -170,7 +170,7 @@ sqlOsOpenMalloc(sql_vfs * pVfs,
 			*ppFile = pFile;
 		}
 	} else {
-		rc = SQL_NOMEM;
+		rc = -1;
 	}
 	return rc;
 }
@@ -194,7 +194,7 @@ sqlOsInit(void)
 {
 	void *p = sql_malloc(10);
 	if (p == 0)
-		return SQL_NOMEM;
+		return -1;
 	sql_free(p);
 	return sql_os_init();
 }
diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index 8b3aec1..e2bda51 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -409,7 +409,7 @@ findInodeInfo(unixFile * pFile,	/* Unix file with file desc used in the key */
 	if (pInode == 0) {
 		pInode = sql_malloc64(sizeof(*pInode));
 		if (pInode == 0) {
-			return SQL_NOMEM;
+			return -1;
 		}
 		memset(pInode, 0, sizeof(*pInode));
 		memcpy(&pInode->fileId, &fileId, sizeof(fileId));
@@ -1697,7 +1697,7 @@ unixOpen(sql_vfs * pVfs,	/* The VFS for which this is the xOpen method */
 		} else {
 			pUnused = sql_malloc64(sizeof(*pUnused));
 			if (!pUnused) {
-				return SQL_NOMEM;
+				return -1;
 			}
 		}
 		p->pUnused = pUnused;
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index a1bed97..2ecad78 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -1822,7 +1822,7 @@ generateColumnNames(Parse * pParse,	/* Parser context */
  * and other fields of Column are zeroed.
  *
  * Return 0 on success.  If a memory allocation error occurs,
- * store NULL in *paCol and 0 in *pnCol and return SQL_NOMEM.
+ * store NULL in *paCol and 0 in *pnCol and return -1.
  */
 int
 sqlColumnsFromExprList(Parse * parse, ExprList * expr_list,
@@ -1925,17 +1925,16 @@ sqlColumnsFromExprList(Parse * parse, ExprList * expr_list,
 	}
 cleanup:
 	sqlHashClear(&ht);
-	int rc = db->mallocFailed ? SQL_NOMEM : 0;
-	if (rc != 0) {
+	if (db->mallocFailed) {
 		/*
 		 * pTable->def could be not temporal in
 		 * sqlViewGetColumnNames so we need clean-up.
 		 */
 		space_def->fields = NULL;
 		space_def->field_count = 0;
-		rc = SQL_NOMEM;
+		return -1;
 	}
-	return rc;
+	return 0;
 
 }
 
@@ -4636,7 +4635,7 @@ withExpand(Walker * pWalker, struct SrcList_item *pFrom)
 			return WRC_Abort;
 		pFrom->pSelect = sqlSelectDup(db, pCte->pSelect, 0);
 		if (db->mallocFailed)
-			return SQL_NOMEM;
+			return -1;
 		assert(pFrom->pSelect);
 
 		/* Check if this is a recursive CTE. */
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 3aabcb2..0743952 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -356,10 +356,8 @@ struct sql_vfs {
 #define SQL_LIMIT_WORKER_THREADS           10
 
 enum sql_ret_code {
-	/** A malloc() failed. */
-	SQL_NOMEM = 2,
 	/** Some kind of disk I/O error occurred. */
-	SQL_IOERR,
+	SQL_IOERR = 3,
 	/** Abort due to constraint violation. */
 	SQL_TARANTOOL_ERROR,
 	/** sql_step() has another row ready. */
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index c8ca8c4..c592518 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -703,7 +703,7 @@ vdbe_field_ref_fetch(struct vdbe_field_ref *field_ref, uint32_t fieldno,
 		int len = dest_mem->n;
 		if (dest_mem->szMalloc < len + 1) {
 			if (sqlVdbeMemGrow(dest_mem, len + 1, 1) != 0)
-				return SQL_NOMEM;
+				return SQL_TARANTOOL_ERROR;
 		} else {
 			dest_mem->z =
 				memcpy(dest_mem->zMalloc, dest_mem->z, len);
@@ -746,12 +746,6 @@ int sqlVdbeExec(Vdbe *p)
 	/*** INSERT STACK UNION HERE ***/
 
 	assert(p->magic==VDBE_MAGIC_RUN);  /* sql_step() verifies this */
-	if (p->rc==SQL_NOMEM) {
-		/* This happens if a malloc() inside a call to sql_column_text() or
-		 * sql_column_text16() failed.
-		 */
-		goto no_mem;
-	}
 	assert(p->rc == 0);
 	p->rc = 0;
 	p->iCurrentTime = 0;
@@ -2624,8 +2618,7 @@ case OP_Column: {
 	}
 	struct Mem *default_val_mem =
 		pOp->p4type == P4_MEM ? pOp->p4.pMem : NULL;
-	rc = vdbe_field_ref_fetch(&pC->field_ref, p2, pDest);
-	if (rc != 0)
+	if (vdbe_field_ref_fetch(&pC->field_ref, p2, pDest) != 0)
 		goto abort_due_to_error;
 
 	if ((pDest->flags & MEM_Null) &&
@@ -2658,8 +2651,7 @@ case OP_Fetch: {
 	uint32_t field_idx = pOp->p2;
 	struct Mem *dest_mem = &aMem[pOp->p3];
 	memAboutToChange(p, dest_mem);
-	rc = vdbe_field_ref_fetch(field_ref, field_idx, dest_mem);
-	if (rc != 0)
+	if (vdbe_field_ref_fetch(field_ref, field_idx, dest_mem) != 0)
 		goto abort_due_to_error;
 	REGISTER_TRACE(p, pOp->p3, dest_mem);
 	break;
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index db8687b..336dc3b 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -422,8 +422,8 @@ sqlStep(Vdbe * p)
 	/* Check that malloc() has not failed. If it has, return early. */
 	db = p->db;
 	if (db->mallocFailed) {
-		p->rc = SQL_NOMEM;
-		return SQL_NOMEM;
+		p->rc = -1;
+		return -1;
 	}
 
 	if (p->pc <= 0 && p->expired) {
@@ -458,9 +458,6 @@ sqlStep(Vdbe * p)
 		checkProfileCallback(db, p);
 #endif
 
-	if (SQL_NOMEM == sqlApiExit(p->db, p->rc)) {
-		p->rc = SQL_NOMEM;
-	}
 	if (p->isPrepareV2 && rc != SQL_ROW && rc != SQL_DONE) {
 		/* If this statement was prepared using sql_prepare_v2(), and an
 		 * error has occurred, then return the error code in p->rc to the
@@ -686,38 +683,6 @@ columnMem(sql_stmt * pStmt, int i)
 	return pOut;
 }
 
-/*
- * This function is called after invoking an sql_value_XXX function on a
- * column value (i.e. a value returned by evaluating an SQL expression in the
- * select list of a SELECT statement) that may cause a malloc() failure. If
- * malloc() has failed, the threads mallocFailed flag is cleared and the result
- * code of statement pStmt set to SQL_NOMEM.
- *
- * Specifically, this is called from within:
- *
- *     sql_column_int()
- *     sql_column_int64()
- *     sql_column_text()
- *     sql_column_real()
- *     sql_column_bytes()
- *     sql_column_bytes16()
- *     sqiite3_column_blob()
- */
-static void
-columnMallocFailure(sql_stmt * pStmt)
-{
-	/* If malloc() failed during an encoding conversion within an
-	 * sql_column_XXX API, then set the return code of the statement to
-	 * SQL_NOMEM. The next call to _step() (if any) will return -1
-	 * and _finalize() will return NOMEM.
-	 */
-	Vdbe *p = (Vdbe *) pStmt;
-	if (p) {
-		assert(p->db != 0);
-		p->rc = sqlApiExit(p->db, p->rc);
-	}
-}
-
 /**************************** sql_column_  ******************************
  * The following routines are used to access elements of the current row
  * in the result set.
@@ -727,11 +692,6 @@ sql_column_blob(sql_stmt * pStmt, int i)
 {
 	const void *val;
 	val = sql_value_blob(columnMem(pStmt, i));
-	/* Even though there is no encoding conversion, value_blob() might
-	 * need to call malloc() to expand the result of a zeroblob()
-	 * expression.
-	 */
-	columnMallocFailure(pStmt);
 	return val;
 }
 
@@ -739,7 +699,6 @@ int
 sql_column_bytes(sql_stmt * pStmt, int i)
 {
 	int val = sql_value_bytes(columnMem(pStmt, i));
-	columnMallocFailure(pStmt);
 	return val;
 }
 
@@ -747,7 +706,6 @@ double
 sql_column_double(sql_stmt * pStmt, int i)
 {
 	double val = sql_value_double(columnMem(pStmt, i));
-	columnMallocFailure(pStmt);
 	return val;
 }
 
@@ -755,7 +713,6 @@ int
 sql_column_int(sql_stmt * pStmt, int i)
 {
 	int val = sql_value_int(columnMem(pStmt, i));
-	columnMallocFailure(pStmt);
 	return val;
 }
 
@@ -763,7 +720,6 @@ bool
 sql_column_boolean(struct sql_stmt *stmt, int i)
 {
 	bool val = sql_value_boolean(columnMem(stmt, i));
-	columnMallocFailure(stmt);
 	return val;
 }
 
@@ -771,7 +727,6 @@ sql_int64
 sql_column_int64(sql_stmt * pStmt, int i)
 {
 	sql_int64 val = sql_value_int64(columnMem(pStmt, i));
-	columnMallocFailure(pStmt);
 	return val;
 }
 
@@ -779,7 +734,6 @@ const unsigned char *
 sql_column_text(sql_stmt * pStmt, int i)
 {
 	const unsigned char *val = sql_value_text(columnMem(pStmt, i));
-	columnMallocFailure(pStmt);
 	return val;
 }
 
@@ -791,7 +745,6 @@ sql_column_value(sql_stmt * pStmt, int i)
 		pOut->flags &= ~MEM_Static;
 		pOut->flags |= MEM_Ephem;
 	}
-	columnMallocFailure(pStmt);
 	return (sql_value *) pOut;
 }
 
@@ -799,7 +752,6 @@ enum mp_type
 sql_column_type(sql_stmt * pStmt, int i)
 {
 	enum mp_type type = sql_value_type(columnMem(pStmt, i));
-	columnMallocFailure(pStmt);
 	return type;
 }
 
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index e056c40..7408b9f 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -163,7 +163,7 @@ sqlVdbeSwap(Vdbe * pA, Vdbe * pB)
  * to 1024/sizeof(Op).
  *
  * If an out-of-memory error occurs while resizing the array, return
- * SQL_NOMEM. In this case Vdbe.aOp and Parse.nOpAlloc remain
+ * -1. In this case Vdbe.aOp and Parse.nOpAlloc remain
  * unchanged (this is so that any opcodes already allocated can be
  * correctly deallocated along with the rest of the Vdbe).
  */
@@ -195,8 +195,9 @@ growOpArray(Vdbe * v, int nOp)
 		p->szOpAlloc = sqlDbMallocSize(pNew);
 		p->nOpAlloc = p->szOpAlloc / sizeof(Op);
 		v->aOp = pNew;
+		return 0;
 	}
-	return (pNew ? 0 : SQL_NOMEM);
+	return -1;
 }
 
 #ifdef SQL_DEBUG
@@ -1413,14 +1414,12 @@ sqlVdbeList(Vdbe * p)
 	int nSub = 0;		/* Number of sub-vdbes seen so far */
 	SubProgram **apSub = 0;	/* Array of sub-vdbes */
 	Mem *pSub = 0;		/* Memory cell hold array of subprogs */
-	sql *db = p->db;	/* The database connection */
 	int i;			/* Loop counter */
 	int rc = 0;	/* Return code */
 	Mem *pMem = &p->aMem[1];	/* First Mem of result set */
 
 	assert(p->explain);
 	assert(p->magic == VDBE_MAGIC_RUN);
-	assert(p->rc == 0 || p->rc == SQL_NOMEM);
 
 	/* Even though this opcode does not use dynamic strings for
 	 * the result, result columns may become dynamic if the user calls
@@ -1429,14 +1428,6 @@ sqlVdbeList(Vdbe * p)
 	releaseMemArray(pMem, 8);
 	p->pResultSet = 0;
 
-	if (p->rc == SQL_NOMEM) {
-		/* This happens if a malloc() inside a call to sql_column_text() or
-		 * sql_column_text16() failed.
-		 */
-		sqlOomFault(db);
-		return -1;
-	}
-
 	/* When the number of output rows reaches nRow, that means the
 	 * listing has finished and sql_step() should return SQL_DONE.
 	 * nRow is the sum of the number of rows in the main program, plus
@@ -2019,7 +2010,7 @@ sqlVdbeSetColName(Vdbe * p,			/* Vdbe being configured */
 	assert(var < COLNAME_N);
 	if (p->db->mallocFailed) {
 		assert(!zName || xDel != SQL_DYNAMIC);
-		return SQL_NOMEM;
+		return -1;
 	}
 	assert(p->aColName != 0);
 	assert(var == COLNAME_NAME || var == COLNAME_DECLTYPE);
@@ -2173,7 +2164,6 @@ sqlVdbeHalt(Vdbe * p)
 	 *
 	 * If any of the following errors occur:
 	 *
-	 *     SQL_NOMEM
 	 *     SQL_IOERR
 	 *
 	 * Then the internal cache might have been left in an inconsistent
@@ -2182,7 +2172,7 @@ sqlVdbeHalt(Vdbe * p)
 	 */
 
 	if (db->mallocFailed) {
-		p->rc = SQL_NOMEM;
+		p->rc = -1;
 	}
 	closeTopFrameCursors(p);
 	if (p->magic != VDBE_MAGIC_RUN) {
@@ -2200,7 +2190,7 @@ sqlVdbeHalt(Vdbe * p)
 
 		/* Check for one of the special errors */
 		mrc = p->rc & 0xff;
-		isSpecialError = mrc == SQL_NOMEM || mrc == SQL_IOERR;
+		isSpecialError = mrc == SQL_IOERR;
 		if (isSpecialError) {
 			/* At least a savepoint transaction must be rolled back
 			 * to restore the database to a consistent state.
@@ -2211,20 +2201,14 @@ sqlVdbeHalt(Vdbe * p)
 			 * file as part of an effort to free up cache space (see function
 			 * pagerStress() in pager.c), the rollback is required to restore
 			 * the pager to a consistent state.
+			 * We are forced to roll back the active transaction. Before doing
+			 * so, abort any other statements this handle currently has active.
 			 */
-			if ((mrc == SQL_NOMEM)
-			    && box_txn()) {
-				eStatementOp = SAVEPOINT_ROLLBACK;
-			} else {
-				/* We are forced to roll back the active transaction. Before doing
-				 * so, abort any other statements this handle currently has active.
-				 */
-				box_txn_rollback();
-				closeCursorsAndFree(p);
-				sqlRollbackAll(p);
-				sqlCloseSavepoints(p);
-				p->nChange = 0;
-			}
+			box_txn_rollback();
+			closeCursorsAndFree(p);
+			sqlRollbackAll(p);
+			sqlCloseSavepoints(p);
+			p->nChange = 0;
 		}
 
 		/* Check for immediate foreign key violations. */
@@ -2333,7 +2317,7 @@ sqlVdbeHalt(Vdbe * p)
 	p->magic = VDBE_MAGIC_HALT;
 	checkActiveVdbeCnt(db);
 	if (db->mallocFailed) {
-		p->rc = SQL_NOMEM;
+		p->rc = -1;
 	}
 
 	assert(db->nVdbeActive > 0 || box_txn() ||
@@ -2974,7 +2958,7 @@ sql_vdbe_mem_alloc_region(Mem *vdbe_mem, uint32_t size)
 	vdbe_mem->n = size;
 	vdbe_mem->z = region_alloc(&fiber()->gc, size);
 	if (vdbe_mem->z == NULL)
-		return SQL_NOMEM;
+		return -1;
 	vdbe_mem->flags = MEM_Ephem | MEM_Blob;
 	assert(sqlVdbeCheckMemInvariants(vdbe_mem));
 	return 0;
@@ -2991,7 +2975,7 @@ sql_vdbe_mem_alloc_region(Mem *vdbe_mem, uint32_t size)
 static int
 vdbeCompareMemString(const Mem * pMem1, const Mem * pMem2,
 		     const struct coll * pColl,
-		     u8 * prcErr)	/* If an OOM occurs, set to SQL_NOMEM */
+		     u8 * prcErr)
 {
 	(void) prcErr;
 	return pColl->cmp(pMem1->z, (size_t)pMem1->n,
diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
index 933ad6f..da63193 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -129,7 +129,7 @@ sqlVdbeMemGrow(Mem * pMem, int n, int bPreserve)
 			sqlVdbeMemSetNull(pMem);
 			pMem->z = 0;
 			pMem->szMalloc = 0;
-			return SQL_NOMEM;
+			return -1;
 		} else {
 			pMem->szMalloc =
 			    sqlDbMallocSize(pMem->zMalloc);
@@ -159,8 +159,7 @@ sqlVdbeMemGrow(Mem * pMem, int n, int bPreserve)
  * and MEM_Blob values may be discarded, MEM_Int, MEM_Real, and MEM_Null
  * values are preserved.
  *
- * Return 0 on success or an error code (probably SQL_NOMEM)
- * if unable to complete the resizing.
+ * Return 0 on success or -1 if unable to complete the resizing.
  */
 int
 sqlVdbeMemClearAndResize(Mem * pMem, int szNew)
@@ -180,17 +179,17 @@ sqlVdbeMemClearAndResize(Mem * pMem, int szNew)
  * Change pMem so that its MEM_Str or MEM_Blob value is stored in
  * MEM.zMalloc, where it can be safely written.
  *
- * Return 0 on success or SQL_NOMEM if malloc fails.
+ * Return 0 on success or -1 if malloc fails.
  */
 int
 sqlVdbeMemMakeWriteable(Mem * pMem)
 {
 	if ((pMem->flags & (MEM_Str | MEM_Blob)) != 0) {
 		if (ExpandBlob(pMem))
-			return SQL_NOMEM;
+			return -1;
 		if (pMem->szMalloc == 0 || pMem->z != pMem->zMalloc) {
 			if (sqlVdbeMemGrow(pMem, pMem->n + 2, 1)) {
-				return SQL_NOMEM;
+				return -1;
 			}
 			pMem->z[pMem->n] = 0;
 			pMem->z[pMem->n + 1] = 0;
@@ -222,7 +221,7 @@ sqlVdbeMemExpandBlob(Mem * pMem)
 		nByte = 1;
 	}
 	if (sqlVdbeMemGrow(pMem, nByte, 1)) {
-		return SQL_NOMEM;
+		return -1;
 	}
 
 	memset(&pMem->z[pMem->n], 0, pMem->u.nZero);
@@ -239,7 +238,7 @@ static SQL_NOINLINE int
 vdbeMemAddTerminator(Mem * pMem)
 {
 	if (sqlVdbeMemGrow(pMem, pMem->n + 2, 1)) {
-		return SQL_NOMEM;
+		return -1;
 	}
 	pMem->z[pMem->n] = 0;
 	pMem->z[pMem->n + 1] = 0;
@@ -290,7 +289,7 @@ sqlVdbeMemStringify(Mem * pMem, u8 bForce)
 	assert(EIGHT_BYTE_ALIGNMENT(pMem));
 
 	if (sqlVdbeMemClearAndResize(pMem, nByte)) {
-		return SQL_NOMEM;
+		return -1;
 	}
 	if (fg & MEM_Int) {
 		sql_snprintf(nByte, pMem->z, "%lld", pMem->u.i);
@@ -1002,7 +1001,7 @@ sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
 		testcase(nAlloc == 31);
 		testcase(nAlloc == 32);
 		if (sqlVdbeMemClearAndResize(pMem, MAX(nAlloc, 32))) {
-			return SQL_NOMEM;
+			return -1;
 		}
 		memcpy(pMem->z, z, nAlloc);
 	} else if (xDel == SQL_DYNAMIC) {
@@ -1273,7 +1272,7 @@ valueFromFunction(sql * db,	/* The database connection */
 							   sizeof(apVal[0]) *
 							   nVal);
 		if (apVal == 0) {
-			rc = SQL_NOMEM;
+			rc = -1;
 			goto value_from_function_out;
 		}
 		for (i = 0; i < nVal; i++) {
@@ -1286,7 +1285,7 @@ valueFromFunction(sql * db,	/* The database connection */
 
 	pVal = valueNew(db, pCtx);
 	if (pVal == 0) {
-		rc = SQL_NOMEM;
+		rc = -1;
 		goto value_from_function_out;
 	}
 
@@ -1450,7 +1449,7 @@ valueFromExpr(sql * db,	/* The database connection */
 	if (pCtx == 0)
 		sqlValueFree(pVal);
 
-	return SQL_NOMEM;
+	return -1;
 }
 
 /*
diff --git a/src/box/sql/vdbesort.c b/src/box/sql/vdbesort.c
index b6ae888..3ff6807 100644
--- a/src/box/sql/vdbesort.c
+++ b/src/box/sql/vdbesort.c
@@ -570,7 +570,7 @@ vdbePmaReadBlob(PmaReader * p,	/* PmaReader from which to take the blob */
 				nNew = nNew * 2;
 			aNew = sqlRealloc(p->aAlloc, nNew);
 			if (!aNew)
-				return SQL_NOMEM;
+				return -1;
 			p->nAlloc = nNew;
 			p->aAlloc = aNew;
 		}
@@ -694,7 +694,7 @@ vdbePmaReaderSeek(SortSubtask * pTask,	/* Task context */
 		if (pReadr->aBuffer == 0) {
 			pReadr->aBuffer = (u8 *) sqlMalloc(pgsz);
 			if (pReadr->aBuffer == 0)
-				rc = SQL_NOMEM;
+				rc = -1;
 			pReadr->nBuffer = pgsz;
 		}
 		if (rc == 0 && iBuf) {
@@ -803,7 +803,7 @@ vdbePmaReaderInit(SortSubtask * pTask,	/* Task context */
  * version of key2 and *pbKey2Cached set to true before returning.
  *
  * If an OOM error is encountered, (pTask->pUnpacked->error_rc) is set
- * to SQL_NOMEM.
+ * to -1.
  *
  * @param task Subtask context (for key_def).
  * @param key2_cached True if pTask->pUnpacked is key2.
@@ -879,7 +879,7 @@ sqlVdbeSorterInit(sql * db,	/* Database connection (for malloc()) */
 	pSorter = (VdbeSorter *) sqlDbMallocZero(db, sizeof(VdbeSorter));
 	pCsr->uc.pSorter = pSorter;
 	if (pSorter == 0) {
-		rc = SQL_NOMEM;
+		rc = -1;
 	} else {
 		pSorter->key_def = pCsr->key_def;
 		pSorter->pgsz = pgsz = 1024;
@@ -913,7 +913,7 @@ sqlVdbeSorterInit(sql * db,	/* Database connection (for malloc()) */
 				pSorter->list.aMemory =
 				    (u8 *) sqlMalloc(pgsz);
 				if (!pSorter->list.aMemory)
-					rc = SQL_NOMEM;
+					rc = -1;
 			}
 		}
 
@@ -1258,7 +1258,7 @@ vdbeSorterOpenTempFile(sql * db,	/* Database handle doing sort */
 /*
  * If it has not already been allocated, allocate the UnpackedRecord
  * structure at pTask->pUnpacked. Return 0 if successful (or
- * if no allocation was required), or SQL_NOMEM otherwise.
+ * if no allocation was required), or -1 otherwise.
  */
 static int
 vdbeSortAllocUnpacked(SortSubtask * pTask)
@@ -1268,7 +1268,7 @@ vdbeSortAllocUnpacked(SortSubtask * pTask)
 			sqlVdbeAllocUnpackedRecord(pTask->pSorter->db,
 						       pTask->pSorter->key_def);
 		if (pTask->pUnpacked == 0)
-			return SQL_NOMEM;
+			return -1;
 		pTask->pUnpacked->nField = pTask->pSorter->key_def->part_count;
 		pTask->pUnpacked->errCode = 0;
 	}
@@ -1330,7 +1330,7 @@ vdbeSorterGetCompare(VdbeSorter * p)
 
 /*
  * Sort the linked list of records headed at pTask->pList. Return
- * 0 if successful, or an sql error code (i.e. SQL_NOMEM) if
+ * 0 if successful, or an sql error code (i.e. -1) if
  * an error occurs.
  */
 static int
@@ -1351,7 +1351,7 @@ vdbeSorterSort(SortSubtask * pTask, SorterList * pList)
 	aSlot =
 	    (SorterRecord **) sqlMallocZero(64 * sizeof(SorterRecord *));
 	if (!aSlot) {
-		return SQL_NOMEM;
+		return -1;
 	}
 
 	while (p) {
@@ -1388,8 +1388,6 @@ vdbeSorterSort(SortSubtask * pTask, SorterList * pList)
 	pList->pList = p;
 
 	sql_free(aSlot);
-	assert(pTask->pUnpacked->errCode == 0
-	       || pTask->pUnpacked->errCode == SQL_NOMEM);
 	return pTask->pUnpacked->errCode;
 }
 
@@ -1406,7 +1404,7 @@ vdbePmaWriterInit(sql_file * pFd,	/* File handle to write to */
 	memset(p, 0, sizeof(PmaWriter));
 	p->aBuffer = (u8 *) sqlMalloc(nBuf);
 	if (!p->aBuffer) {
-		p->eFWErr = SQL_NOMEM;
+		p->eFWErr = -1;
 	} else {
 		p->iBufEnd = p->iBufStart = (iStart % nBuf);
 		p->iWriteOff = iStart - p->iBufStart;
@@ -1727,7 +1725,7 @@ vdbeSorterFlushPMA(VdbeSorter * pSorter)
 				pSorter->list.aMemory =
 				    sqlMalloc(pSorter->nMemory);
 				if (!pSorter->list.aMemory)
-					return SQL_NOMEM;
+					return -1;
 			}
 
 			rc = vdbeSorterCreateThread(pTask,
@@ -1827,7 +1825,7 @@ sqlVdbeSorterWrite(const VdbeCursor * pCsr,	/* Sorter cursor */
 
 			aNew = sqlRealloc(pSorter->list.aMemory, nNew);
 			if (!aNew)
-				return SQL_NOMEM;
+				return -1;
 			pSorter->list.pList = (SorterRecord *) & aNew[iListOff];
 			pSorter->list.aMemory = aNew;
 			pSorter->nMemory = nNew;
@@ -1844,7 +1842,7 @@ sqlVdbeSorterWrite(const VdbeCursor * pCsr,	/* Sorter cursor */
 	} else {
 		pNew = (SorterRecord *) sqlMalloc(nReq);
 		if (pNew == 0) {
-			return SQL_NOMEM;
+			return -1;
 		}
 		pNew->u.pNext = pSorter->list.pList;
 	}
@@ -2007,7 +2005,7 @@ vdbeIncrMergerNew(SortSubtask * pTask,	/* The thread that will be using the new
 		pTask->file2.iEof += pIncr->mxSz;
 	} else {
 		vdbeMergeEngineFree(pMerger);
-		rc = SQL_NOMEM;
+		rc = -1;
 	}
 	return rc;
 }
@@ -2332,7 +2330,7 @@ vdbeMergeEngineLevel0(SortSubtask * pTask,	/* Sorter task to read from */
 
 	*ppOut = pNew = vdbeMergeEngineNew(nPMA);
 	if (pNew == 0)
-		rc = SQL_NOMEM;
+		rc = -1;
 
 	for (i = 0; i < nPMA && rc == 0; i++) {
 		i64 nDummy = 0;
@@ -2408,7 +2406,7 @@ vdbeSorterAddToTree(SortSubtask * pTask,	/* Task context */
 			MergeEngine *pNew =
 			    vdbeMergeEngineNew(SORTER_MAX_MERGE_COUNT);
 			if (pNew == 0) {
-				rc = SQL_NOMEM;
+				rc = -1;
 			} else {
 				rc = vdbeIncrMergerNew(pTask, pNew,
 						       &pReadr->pIncr);
@@ -2457,7 +2455,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter,	/* The VDBE cursor that implement
 	if (pSorter->nTask > 1) {
 		pMain = vdbeMergeEngineNew(pSorter->nTask);
 		if (pMain == 0)
-			rc = SQL_NOMEM;
+			rc = -1;
 	}
 #endif
 
@@ -2478,7 +2476,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter,	/* The VDBE cursor that implement
 				pRoot =
 				    vdbeMergeEngineNew(SORTER_MAX_MERGE_COUNT);
 				if (pRoot == 0)
-					rc = SQL_NOMEM;
+					rc = -1;
 				for (i = 0; i < pTask->nPMA && rc == 0;
 				     i += SORTER_MAX_MERGE_COUNT) {
 					MergeEngine *pMerger = 0;	/* New level-0 PMA merger */
@@ -2569,7 +2567,7 @@ vdbeSorterSetupMerge(VdbeSorter * pSorter)
 								      (PmaReader));
 				pSorter->pReader = pReadr;
 				if (pReadr == 0)
-					rc = SQL_NOMEM;
+					rc = -1;
 			}
 			if (rc == 0) {
 				rc = vdbeIncrMergerNew(pLast, pMain,
@@ -2773,7 +2771,7 @@ sqlVdbeSorterRowkey(const VdbeCursor * pCsr, Mem * pOut)
 	pSorter = pCsr->uc.pSorter;
 	pKey = vdbeSorterRowkey(pSorter, &nKey);
 	if (sqlVdbeMemClearAndResize(pOut, nKey)) {
-		return SQL_NOMEM;
+		return -1;
 	}
 	pOut->n = nKey;
 	MemSetTypeFlag(pOut, MEM_Blob);
@@ -2790,7 +2788,7 @@ sqlVdbeSorterRowkey(const VdbeCursor * pCsr, Mem * pOut)
  * If the sorter cursor key contains any NULL values, consider it to be
  * less than pVal. Even if pVal also contains NULL values.
  *
- * If an error occurs, return an sql error code (i.e. SQL_NOMEM).
+ * If an error occurs, return -1.
  * Otherwise, set *pRes to a negative, zero or positive value if the
  * key in pVal is smaller than, equal to or larger than the current sorter
  * key.
@@ -2818,7 +2816,7 @@ sqlVdbeSorterCompare(const VdbeCursor * pCsr,	/* Sorter cursor */
 		r2 = pSorter->pUnpacked =
 			sqlVdbeAllocUnpackedRecord(pSorter->db,  pCsr->key_def);
 		if (r2 == 0)
-			return SQL_NOMEM;
+			return -1;
 		r2->nField = nKeyCol;
 	}
 	assert(r2->nField == nKeyCol);
diff --git a/src/box/sql/where.c b/src/box/sql/where.c
index 6781ab0..9739268 100644
--- a/src/box/sql/where.c
+++ b/src/box/sql/where.c
@@ -1741,7 +1741,7 @@ whereLoopResize(sql * db, WhereLoop * p, int n)
 	n = (n + 7) & ~7;
 	paNew = sqlDbMallocRawNN(db, sizeof(p->aLTerm[0]) * n);
 	if (paNew == 0)
-		return SQL_NOMEM;
+		return -1;
 	memcpy(paNew, p->aLTerm, sizeof(p->aLTerm[0]) * p->nLSlot);
 	if (p->aLTerm != p->aLTermSpace)
 		sqlDbFree(db, p->aLTerm);
@@ -1762,7 +1762,7 @@ whereLoopXfer(sql * db, WhereLoop * pTo, WhereLoop * pFrom)
 		pTo->nBtm = 0;
 		pTo->nTop = 0;
 		pTo->index_def = NULL;
-		return SQL_NOMEM;
+		return -1;
 	}
 	memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
 	memcpy(pTo->aLTerm, pFrom->aLTerm,
@@ -2079,7 +2079,7 @@ whereLoopInsert(WhereLoopBuilder * pBuilder, WhereLoop * pTemplate)
 		/* Allocate a new WhereLoop to add to the end of the list */
 		*ppPrev = p = sqlDbMallocRawNN(db, sizeof(WhereLoop));
 		if (p == 0)
-			return SQL_NOMEM;
+			return -1;
 		whereLoopInit(p);
 		p->pNextLoop = 0;
 	} else {
@@ -2308,7 +2308,7 @@ whereLoopAddBtreeIndex(WhereLoopBuilder * pBuilder,	/* The WhereLoop factory */
 
 	pNew = pBuilder->pNew;
 	if (db->mallocFailed)
-		return SQL_NOMEM;
+		return -1;
 	WHERETRACE(0x800, ("BEGIN addBtreeIdx(%s), nEq=%d\n",
 			   probe->name, pNew->nEq));
 
@@ -3546,7 +3546,7 @@ whereSortingCost(WhereInfo * pWInfo, LogEst nRow, int nOrderBy, int nSorted)
  * will be nRowEst (in the 10*log2 representation).  Or, ignore sorting
  * costs if nRowEst==0.
  *
- * Return 0 on success or SQL_NOMEM of a memory allocation
+ * Return 0 on success or -1 of a memory allocation
  * error occurs.
  */
 static int
@@ -3602,7 +3602,7 @@ wherePathSolver(WhereInfo * pWInfo, LogEst nRowEst)
 	nSpace += sizeof(LogEst) * nOrderBy;
 	pSpace = sqlDbMallocRawNN(db, nSpace);
 	if (pSpace == 0)
-		return SQL_NOMEM;
+		return -1;
 	aTo = (WherePath *) pSpace;
 	aFrom = aTo + mxChoice;
 	memset(aFrom, 0, sizeof(aFrom[0]));
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 21/28] sql: remove SQL_IOERR errcode
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (19 preceding siblings ...)
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 20/28] sql: remove SQL_NOMEM errcode imeevma
@ 2019-06-10 13:57 ` imeevma
  2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 22/28] sql: remove SQL_TARANTOOL_ERROR errcode imeevma
                   ` (10 subsequent siblings)
  31 siblings, 0 replies; 56+ messages in thread
From: imeevma @ 2019-06-10 13:57 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql/malloc.c   |  2 +-
 src/box/sql/os_unix.c  | 35 +++++++++++++++--------------------
 src/box/sql/sqlInt.h   | 31 +------------------------------
 src/box/sql/vdbeaux.c  | 38 ++------------------------------------
 src/box/sql/vdbesort.c |  1 -
 5 files changed, 19 insertions(+), 88 deletions(-)

diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index 4b8ef8f..64873f2 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -780,7 +780,7 @@ int
 sqlApiExit(sql * db, int rc)
 {
 	assert(db != 0);
-	if (db->mallocFailed || rc == SQL_IOERR_NOMEM) {
+	if (db->mallocFailed) {
 		return apiOomError(db);
 	}
 	return rc & db->errMask;
diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index e2bda51..f0cf4ac 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -396,7 +396,7 @@ findInodeInfo(unixFile * pFile,	/* Unix file with file desc used in the key */
 	rc = fstat(fd, &statbuf);
 	if (rc != 0) {
 		storeLastErrno(pFile, errno);
-		return SQL_IOERR;
+		return -1;
 	}
 
 	memset(&fileId, 0, sizeof(fileId));
@@ -554,9 +554,9 @@ posixUnlock(sql_file * id, int eFileLock, int handleNFSUnlock)
 					/* In theory, the call to unixFileLock() cannot fail because another
 					 * process is holding an incompatible lock. If it does, this
 					 * indicates that the other process is not following the locking
-					 * protocol. If this happens, return SQL_IOERR_RDLOCK.
+					 * protocol. If this happens, return -1.
 					 */
-					rc = SQL_IOERR_RDLOCK;
+					rc = -1;
 					storeLastErrno(pFile, errno);
 					goto end_unlock;
 				}
@@ -570,7 +570,7 @@ posixUnlock(sql_file * id, int eFileLock, int handleNFSUnlock)
 		if (unixFileLock(pFile, &lock) == 0) {
 			pInode->eFileLock = SHARED_LOCK;
 		} else {
-			rc = SQL_IOERR_UNLOCK;
+			rc = -1;
 			storeLastErrno(pFile, errno);
 			goto end_unlock;
 		}
@@ -588,7 +588,7 @@ posixUnlock(sql_file * id, int eFileLock, int handleNFSUnlock)
 			if (unixFileLock(pFile, &lock) == 0) {
 				pInode->eFileLock = NO_LOCK;
 			} else {
-				rc = SQL_IOERR_UNLOCK;
+				rc = -1;
 				storeLastErrno(pFile, errno);
 				pInode->eFileLock = NO_LOCK;
 				pFile->eFileLock = NO_LOCK;
@@ -755,7 +755,7 @@ seekAndRead(unixFile * id, sql_int64 offset, void *pBuf, int cnt)
 
 /*
  * Read data from a file into a buffer.  Return 0 if all
- * bytes were read successfully and SQL_IOERR if anything goes
+ * bytes were read successfully and -1 if anything goes
  * wrong.
  */
 static int
@@ -792,12 +792,12 @@ unixRead(sql_file * id, void *pBuf, int amt, sql_int64 offset)
 		return 0;
 	} else if (got < 0) {
 		/* lastErrno set by seekAndRead */
-		return SQL_IOERR_READ;
+		return -1;
 	} else {
 		storeLastErrno(pFile, 0);	/* not a system error */
 		/* Unread parts of the buffer must be zero-filled */
 		memset(&((char *)pBuf)[got], 0, amt - got);
-		return SQL_IOERR_SHORT_READ;
+		return -1;
 	}
 }
 
@@ -871,7 +871,7 @@ unixWrite(sql_file * id, const void *pBuf, int amt, sql_int64 offset)
 	if (amt > wrote) {
 		if (wrote < 0 && pFile->lastErrno != ENOSPC) {
 			/* lastErrno set by seekAndWrite */
-			return SQL_IOERR_WRITE;
+			return -1;
 		} else {
 			storeLastErrno(pFile, 0);	/* not a system error */
 			return -1;
@@ -941,7 +941,7 @@ fcntlSizeHint(unixFile * pFile, i64 nByte)
 		struct stat buf;	/* Used to hold return values of fstat() */
 
 		if (fstat(pFile->h, &buf))
-			return SQL_IOERR_FSTAT;
+			return -1;
 
 		nSize =
 		    ((nByte + pFile->szChunk -
@@ -960,7 +960,7 @@ fcntlSizeHint(unixFile * pFile, i64 nByte)
 					iWrite = nSize - 1;
 				nWrite = seekAndWrite(pFile, iWrite, "", 1);
 				if (nWrite != 1)
-					return SQL_IOERR_WRITE;
+					return -1;
 			}
 		}
 	}
@@ -1167,7 +1167,7 @@ unixMapfile(unixFile * pFd, i64 nMap)
 	if (nMap < 0) {
 		struct stat statbuf;	/* Low-level file information */
 		if (fstat(pFd->h, &statbuf))
-			return SQL_IOERR_FSTAT;
+			return -1;
 		nMap = statbuf.st_size;
 	}
 	if (nMap > pFd->mmapSizeMax) {
@@ -1472,7 +1472,7 @@ unixGetTempname(int nBuf, char *zBuf)
 
 	zDir = unixTempFileDir();
 	if (zDir == 0)
-		return SQL_IOERR_GETTEMPPATH;
+		return -1;
 	do {
 		u64 r;
 		sql_randomness(sizeof(r), &r);
@@ -1559,7 +1559,7 @@ getFileMode(const char *zFile,	/* File name */
 		*pUid = sStat.st_uid;
 		*pGid = sStat.st_gid;
 	} else {
-		rc = SQL_IOERR_FSTAT;
+		rc = -1;
 	}
 	return rc;
 }
@@ -1816,12 +1816,7 @@ unixDelete(sql_vfs * NotUsed,	/* VFS containing this as the xDelete method */
 	int rc = 0;
 	UNUSED_PARAMETER(NotUsed);
 	if (unlink(zPath) == (-1)) {
-		if (errno == ENOENT) {
-			rc = SQL_IOERR_DELETE_NOENT;
-		} else {
-			rc = -1;
-		}
-		return rc;
+		return -1;
 	}
 #ifndef SQL_DISABLE_DIRSYNC
 	if ((dirSync & 1) != 0) {
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 0743952..cff8ef5 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -356,10 +356,8 @@ struct sql_vfs {
 #define SQL_LIMIT_WORKER_THREADS           10
 
 enum sql_ret_code {
-	/** Some kind of disk I/O error occurred. */
-	SQL_IOERR = 3,
 	/** Abort due to constraint violation. */
-	SQL_TARANTOOL_ERROR,
+	SQL_TARANTOOL_ERROR = 4,
 	/** sql_step() has another row ready. */
 	SQL_ROW,
 	/** sql_step() has finished executing. */
@@ -572,33 +570,6 @@ sql_exec(sql *,	/* An open database */
 	     void *,	/* 1st argument to callback */
 	     char **errmsg	/* Error msg written here */
 	);
-#define SQL_IOERR_READ              (SQL_IOERR | (1<<8))
-#define SQL_IOERR_SHORT_READ        (SQL_IOERR | (2<<8))
-#define SQL_IOERR_WRITE             (SQL_IOERR | (3<<8))
-#define SQL_IOERR_FSYNC             (SQL_IOERR | (4<<8))
-#define SQL_IOERR_DIR_FSYNC         (SQL_IOERR | (5<<8))
-#define SQL_IOERR_TRUNCATE          (SQL_IOERR | (6<<8))
-#define SQL_IOERR_FSTAT             (SQL_IOERR | (7<<8))
-#define SQL_IOERR_UNLOCK            (SQL_IOERR | (8<<8))
-#define SQL_IOERR_RDLOCK            (SQL_IOERR | (9<<8))
-#define SQL_IOERR_DELETE            (SQL_IOERR | (10<<8))
-#define SQL_IOERR_BLOCKED           (SQL_IOERR | (11<<8))
-#define SQL_IOERR_NOMEM             (SQL_IOERR | (12<<8))
-#define SQL_IOERR_ACCESS            (SQL_IOERR | (13<<8))
-#define SQL_IOERR_CHECKRESERVEDLOCK (SQL_IOERR | (14<<8))
-#define SQL_IOERR_LOCK              (SQL_IOERR | (15<<8))
-#define SQL_IOERR_CLOSE             (SQL_IOERR | (16<<8))
-#define SQL_IOERR_DIR_CLOSE         (SQL_IOERR | (17<<8))
-#define SQL_IOERR_SHMOPEN           (SQL_IOERR | (18<<8))
-#define SQL_IOERR_SHMSIZE           (SQL_IOERR | (19<<8))
-#define SQL_IOERR_SHMLOCK           (SQL_IOERR | (20<<8))
-#define SQL_IOERR_SHMMAP            (SQL_IOERR | (21<<8))
-#define SQL_IOERR_SEEK              (SQL_IOERR | (22<<8))
-#define SQL_IOERR_DELETE_NOENT      (SQL_IOERR | (23<<8))
-#define SQL_IOERR_MMAP              (SQL_IOERR | (24<<8))
-#define SQL_IOERR_GETTEMPPATH       (SQL_IOERR | (25<<8))
-#define SQL_IOERR_CONVPATH          (SQL_IOERR | (26<<8))
-#define SQL_IOERR_VNODE             (SQL_IOERR | (27<<8))
 
 /**
  * Subtype of a main type. Allows to do some subtype specific
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 7408b9f..8e2ca35 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -2055,7 +2055,7 @@ checkActiveVdbeCnt(sql * db)
  * transaction is rolled back. If eOp is SAVEPOINT_RELEASE, then the
  * statement transaction is committed.
  *
- * If an IO error occurs, an SQL_IOERR_XXX error code is returned.
+ * If an IO error occurs, -1 is returned.
  * Otherwise 0.
  */
 int
@@ -2161,14 +2161,6 @@ sqlVdbeHalt(Vdbe * p)
 	/* This function contains the logic that determines if a statement or
 	 * transaction will be committed or rolled back as a result of the
 	 * execution of this virtual machine.
-	 *
-	 * If any of the following errors occur:
-	 *
-	 *     SQL_IOERR
-	 *
-	 * Then the internal cache might have been left in an inconsistent
-	 * state.  We need to rollback the statement transaction, if there is
-	 * one, or the complete transaction if there is no statement transaction.
 	 */
 
 	if (db->mallocFailed) {
@@ -2184,32 +2176,7 @@ sqlVdbeHalt(Vdbe * p)
 	 * SQL statement does not read or write a database file.
 	 */
 	if (p->pc >= 0) {
-		int mrc;	/* Primary error code from p->rc */
 		int eStatementOp = 0;
-		int isSpecialError;	/* Set to true if a 'special' error */
-
-		/* Check for one of the special errors */
-		mrc = p->rc & 0xff;
-		isSpecialError = mrc == SQL_IOERR;
-		if (isSpecialError) {
-			/* At least a savepoint transaction must be rolled back
-			 * to restore the database to a consistent state.
-			 *
-			 * Even if the statement is read-only, it is important to perform
-			 * a statement or transaction rollback operation. If the error
-			 * occurred while writing to the journal, sub-journal or database
-			 * file as part of an effort to free up cache space (see function
-			 * pagerStress() in pager.c), the rollback is required to restore
-			 * the pager to a consistent state.
-			 * We are forced to roll back the active transaction. Before doing
-			 * so, abort any other statements this handle currently has active.
-			 */
-			box_txn_rollback();
-			closeCursorsAndFree(p);
-			sqlRollbackAll(p);
-			sqlCloseSavepoints(p);
-			p->nChange = 0;
-		}
 
 		/* Check for immediate foreign key violations. */
 		if (p->rc == 0) {
@@ -2224,8 +2191,7 @@ sqlVdbeHalt(Vdbe * p)
 		 */
 		if (p->auto_commit) {
 			if (p->rc == 0
-			    || (p->errorAction == ON_CONFLICT_ACTION_FAIL
-				&& !isSpecialError)) {
+			    || (p->errorAction == ON_CONFLICT_ACTION_FAIL)) {
 				rc = sqlVdbeCheckFk(p, 1);
 				if (rc != 0) {
 					/* Close all opened cursors if
diff --git a/src/box/sql/vdbesort.c b/src/box/sql/vdbesort.c
index 3ff6807..7caf13b 100644
--- a/src/box/sql/vdbesort.c
+++ b/src/box/sql/vdbesort.c
@@ -542,7 +542,6 @@ vdbePmaReadBlob(PmaReader * p,	/* PmaReader from which to take the blob */
 
 		/* Readr data from the file. Return early if an error occurs. */
 		rc = sqlOsRead(p->pFd, p->aBuffer, nRead, p->iReadOff);
-		assert(rc != SQL_IOERR_SHORT_READ);
 		if (rc != 0)
 			return rc;
 	}
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 22/28] sql: remove SQL_TARANTOOL_ERROR errcode
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (20 preceding siblings ...)
  2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 21/28] sql: remove SQL_IOERR errcode imeevma
@ 2019-06-10 13:57 ` imeevma
  2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 23/28] sql: remove field errMask from struct sql imeevma
                   ` (9 subsequent siblings)
  31 siblings, 0 replies; 56+ messages in thread
From: imeevma @ 2019-06-10 13:57 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql.c               | 72 +++++++++++++++++++--------------------------
 src/box/sql/build.c         |  6 ++--
 src/box/sql/expr.c          |  5 ++--
 src/box/sql/fk_constraint.c |  4 +--
 src/box/sql/insert.c        |  7 ++---
 src/box/sql/main.c          |  6 ++--
 src/box/sql/prepare.c       |  4 +--
 src/box/sql/select.c        | 16 +++++-----
 src/box/sql/sqlInt.h        |  6 ++--
 src/box/sql/tarantoolInt.h  |  4 +--
 src/box/sql/vdbe.c          | 29 +++++++-----------
 src/box/sql/vdbeapi.c       | 10 +++----
 src/box/sql/vdbeaux.c       |  8 ++---
 src/box/sql/vdbemem.c       |  4 +--
 src/box/sql/where.c         |  2 +-
 15 files changed, 79 insertions(+), 104 deletions(-)

diff --git a/src/box/sql.c b/src/box/sql.c
index 51f7b77..d8c7d91 100644
--- a/src/box/sql.c
+++ b/src/box/sql.c
@@ -172,7 +172,7 @@ const void *tarantoolsqlPayloadFetch(BtCursor *pCur, u32 *pAmt)
 int tarantoolsqlFirst(BtCursor *pCur, int *pRes)
 {
 	if (key_alloc(pCur, sizeof(nil_key)) != 0)
-		return SQL_TARANTOOL_ERROR;
+		return -1;
 	memcpy(pCur->key, nil_key, sizeof(nil_key));
 	pCur->iter_type = ITER_GE;
 	return cursor_seek(pCur, pRes);
@@ -182,7 +182,7 @@ int tarantoolsqlFirst(BtCursor *pCur, int *pRes)
 int tarantoolsqlLast(BtCursor *pCur, int *pRes)
 {
 	if (key_alloc(pCur, sizeof(nil_key)) != 0)
-		return SQL_TARANTOOL_ERROR;
+		return -1;
 	memcpy(pCur->key, nil_key, sizeof(nil_key));
 	pCur->iter_type = ITER_LE;
 	return cursor_seek(pCur, pRes);
@@ -230,9 +230,9 @@ int tarantoolsqlMovetoUnpacked(BtCursor *pCur, UnpackedRecord *pIdxKey,
 		sql_vdbe_mem_encode_tuple(pIdxKey->aMem, pIdxKey->nField,
 					  &tuple_size, region);
 	if (tuple == NULL)
-		return SQL_TARANTOOL_ERROR;
+		return -1;
 	if (key_alloc(pCur, tuple_size) != 0)
-		return SQL_TARANTOOL_ERROR;
+		return -1;
 	memcpy(pCur->key, tuple, tuple_size);
 	region_truncate(region, used);
 
@@ -382,9 +382,7 @@ int tarantoolsqlEphemeralInsert(struct space *space, const char *tuple,
 {
 	assert(space != NULL);
 	mp_tuple_assert(tuple, tuple_end);
-	if (space_ephemeral_replace(space, tuple, tuple_end) != 0)
-		return SQL_TARANTOOL_ERROR;
-	return 0;
+	return space_ephemeral_replace(space, tuple, tuple_end);
 }
 
 /* Simply delete ephemeral space by calling space_delete(). */
@@ -409,8 +407,7 @@ insertOrReplace(struct space *space, const char *tuple, const char *tuple_end,
 	request.space_id = space->def->id;
 	request.type = type;
 	mp_tuple_assert(request.tuple, request.tuple_end);
-	int rc = box_process_rw(&request, space, NULL);
-	return rc == 0 ? 0 : SQL_TARANTOOL_ERROR;
+	return box_process_rw(&request, space, NULL);
 }
 
 int tarantoolsqlInsert(struct space *space, const char *tuple,
@@ -431,7 +428,7 @@ int tarantoolsqlReplace(struct space *space, const char *tuple,
  *
  * @param pCur Cursor pointing to ephemeral space.
  *
- * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise.
+ * @retval 0 on success, -1 otherwise.
  */
 int tarantoolsqlEphemeralDelete(BtCursor *pCur)
 {
@@ -445,12 +442,12 @@ int tarantoolsqlEphemeralDelete(BtCursor *pCur)
 				pCur->iter->index->def->key_def,
 				MULTIKEY_NONE, &key_size);
 	if (key == NULL)
-		return SQL_TARANTOOL_ERROR;
+		return -1;
 
 	int rc = space_ephemeral_delete(pCur->space, key);
 	if (rc != 0) {
 		diag_log();
-		return SQL_TARANTOOL_ERROR;
+		return -1;
 	}
 	return 0;
 }
@@ -465,17 +462,14 @@ int tarantoolsqlDelete(BtCursor *pCur, u8 flags)
 
 	char *key;
 	uint32_t key_size;
-	int rc;
 
 	key = tuple_extract_key(pCur->last_tuple,
 				pCur->iter->index->def->key_def,
 				MULTIKEY_NONE, &key_size);
 	if (key == NULL)
-		return SQL_TARANTOOL_ERROR;
-	rc = sql_delete_by_key(pCur->space, pCur->index->def->iid, key,
-			       key_size);
-
-	return rc == 0 ? 0 : SQL_TARANTOOL_ERROR;
+		return -1;
+	return sql_delete_by_key(pCur->space, pCur->index->def->iid, key,
+				 key_size);
 }
 
 int
@@ -491,9 +485,7 @@ sql_delete_by_key(struct space *space, uint32_t iid, char *key,
 	request.space_id = space->def->id;
 	request.index_id = iid;
 	assert(space_index(space, iid)->def->opts.is_unique);
-	int rc = box_process_rw(&request, space, &unused);
-
-	return rc == 0 ? 0 : SQL_TARANTOOL_ERROR;
+	return box_process_rw(&request, space, &unused);
 }
 
 /*
@@ -503,7 +495,7 @@ sql_delete_by_key(struct space *space, uint32_t iid, char *key,
  *
  * @param pCur Cursor pointing to ephemeral space.
  *
- * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise.
+ * @retval 0 on success, -1 otherwise.
  */
 int tarantoolsqlEphemeralClearTable(BtCursor *pCur)
 {
@@ -515,7 +507,7 @@ int tarantoolsqlEphemeralClearTable(BtCursor *pCur)
 						    0 /* part_count */);
 	if (it == NULL) {
 		pCur->eState = CURSOR_INVALID;
-		return SQL_TARANTOOL_ERROR;
+		return -1;
 	}
 
 	struct tuple *tuple;
@@ -527,7 +519,7 @@ int tarantoolsqlEphemeralClearTable(BtCursor *pCur)
 					MULTIKEY_NONE, &key_size);
 		if (space_ephemeral_delete(pCur->space, key) != 0) {
 			iterator_delete(it);
-			return SQL_TARANTOOL_ERROR;
+			return -1;
 		}
 	}
 	iterator_delete(it);
@@ -554,7 +546,7 @@ int tarantoolsqlClearTable(struct space *space, uint32_t *tuple_count)
 	struct index *pk = space_index(space, 0 /* PK */);
 	struct iterator *iter = index_create_iterator(pk, ITER_ALL, nil_key, 0);
 	if (iter == NULL)
-		return SQL_TARANTOOL_ERROR;
+		return -1;
 	while (iterator_next(iter, &tuple) == 0 && tuple != NULL) {
 		request.key = tuple_extract_key(tuple, pk->def->key_def,
 						MULTIKEY_NONE, &key_size);
@@ -562,7 +554,7 @@ int tarantoolsqlClearTable(struct space *space, uint32_t *tuple_count)
 		rc = box_process_rw(&request, space, &unused);
 		if (rc != 0) {
 			iterator_delete(iter);
-			return SQL_TARANTOOL_ERROR;
+			return -1;
 		}
 		(*tuple_count)++;
 	}
@@ -607,8 +599,11 @@ int tarantoolsqlRenameTrigger(const char *trig_name,
 	assert(mp_typeof(*field) == MP_MAP);
 	mp_decode_map(&field);
 	const char *sql_str = mp_decode_str(&field, &key_len);
-	if (sqlStrNICmp(sql_str, "sql", 3) != 0)
-		goto rename_fail;
+	if (sqlStrNICmp(sql_str, "sql", 3) != 0) {
+		diag_set(ClientError, ER_SQL_EXECUTE, "can't modify name of "\
+			 "space created not via SQL facilities");
+		return -1;
+	}
 	uint32_t trigger_stmt_len;
 	const char *trigger_stmt_old = mp_decode_str(&field, &trigger_stmt_len);
 	char *trigger_stmt = (char*)region_alloc(&fiber()->gc,
@@ -644,11 +639,6 @@ int tarantoolsqlRenameTrigger(const char *trig_name,
 				      trigger_stmt_new_len);
 
 	return box_replace(BOX_TRIGGER_ID, new_tuple, new_tuple_end, NULL);
-
-rename_fail:
-	diag_set(ClientError, ER_SQL_EXECUTE, "can't modify name of space "
-		"created not via SQL facilities");
-	return -1;
 }
 
 int
@@ -676,9 +666,7 @@ sql_rename_table(uint32_t space_id, const char *new_name)
 	pos = mp_encode_str(pos, "=", 1);
 	pos = mp_encode_uint(pos, BOX_SPACE_FIELD_NAME);
 	pos = mp_encode_str(pos, new_name, name_len);
-	if (box_update(BOX_SPACE_ID, 0, raw, ops, ops, pos, 0, NULL) != 0)
-		return -1;
-	return 0;
+	return box_update(BOX_SPACE_ID, 0, raw, ops, ops, pos, 0, NULL);
 }
 
 int
@@ -848,7 +836,7 @@ key_alloc(BtCursor *cur, size_t key_size)
  * @param key Start of buffer containing key.
  * @param key_end End of buffer containing key.
  *
- * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise.
+ * @retval 0 on success, -1 otherwise.
  */
 static int
 cursor_seek(BtCursor *pCur, int *pRes)
@@ -862,13 +850,13 @@ cursor_seek(BtCursor *pCur, int *pRes)
 	uint32_t part_count = mp_decode_array(&key);
 	if (key_validate(pCur->index->def, pCur->iter_type, key, part_count)) {
 		diag_log();
-		return SQL_TARANTOOL_ERROR;
+		return -1;
 	}
 
 	struct space *space = pCur->space;
 	struct txn *txn = NULL;
 	if (space->def->id != 0 && txn_begin_ro_stmt(space, &txn) != 0)
-		return SQL_TARANTOOL_ERROR;
+		return -1;
 	struct iterator *it =
 		index_create_iterator(pCur->index, pCur->iter_type, key,
 				      part_count);
@@ -876,7 +864,7 @@ cursor_seek(BtCursor *pCur, int *pRes)
 		if (txn != NULL)
 			txn_rollback_stmt();
 		pCur->eState = CURSOR_INVALID;
-		return SQL_TARANTOOL_ERROR;
+		return -1;
 	}
 	if (txn != NULL)
 		txn_commit_ro_stmt(txn);
@@ -894,7 +882,7 @@ cursor_seek(BtCursor *pCur, int *pRes)
  * @param pCur Cursor which contains space and tuple.
  * @param[out] pRes Flag which is 0 if reached end of space, 1 otherwise.
  *
- * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise.
+ * @retval 0 on success, -1 otherwise.
  */
 static int
 cursor_advance(BtCursor *pCur, int *pRes)
@@ -903,7 +891,7 @@ cursor_advance(BtCursor *pCur, int *pRes)
 
 	struct tuple *tuple;
 	if (iterator_next(pCur->iter, &tuple) != 0)
-		return SQL_TARANTOOL_ERROR;
+		return -1;
 	if (pCur->last_tuple)
 		box_tuple_unref(pCur->last_tuple);
 	if (tuple) {
diff --git a/src/box/sql/build.c b/src/box/sql/build.c
index b6cec65..38a6cae 100644
--- a/src/box/sql/build.c
+++ b/src/box/sql/build.c
@@ -141,7 +141,7 @@ sql_finish_coding(struct Parse *parse_context)
 			sqlVdbeChangeP2(v, record->insertion_opcode,
 					    v->nOp);
 		}
-		sqlVdbeAddOp1(v, OP_Halt, SQL_TARANTOOL_ERROR);
+		sqlVdbeAddOp1(v, OP_Halt, -1);
 		VdbeComment((v,
 			     "Exit with an error if CREATE statement fails"));
 	}
@@ -3286,8 +3286,8 @@ vdbe_emit_halt_with_presence_test(struct Parse *parser, int space_id,
 	if (no_error) {
 		sqlVdbeAddOp0(v, OP_Halt);
 	} else {
-		sqlVdbeAddOp4(v, OP_Halt, SQL_TARANTOOL_ERROR, 0,
-			      tarantool_error_code, error, P4_DYNAMIC);
+		sqlVdbeAddOp4(v, OP_Halt, -1, 0, tarantool_error_code, error,
+			      P4_DYNAMIC);
 	}
 	sqlVdbeAddOp1(v, OP_Close, cursor);
 	return 0;
diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c
index 054c516..2395c64 100644
--- a/src/box/sql/expr.c
+++ b/src/box/sql/expr.c
@@ -4394,9 +4394,8 @@ sqlExprCodeTarget(Parse * pParse, Expr * pExpr, int target)
 			const char *err =
 				tt_sprintf(tnt_errcode_desc(ER_SQL_EXECUTE),
 					   pExpr->u.zToken);
-			sqlVdbeAddOp4(v, OP_Halt, SQL_TARANTOOL_ERROR,
-				      pExpr->on_conflict_action, ER_SQL_EXECUTE,
-				      err, 0);
+			sqlVdbeAddOp4(v, OP_Halt, -1, pExpr->on_conflict_action,
+				      ER_SQL_EXECUTE, err, 0);
 		}
 		break;
 	}
diff --git a/src/box/sql/fk_constraint.c b/src/box/sql/fk_constraint.c
index 6cb41f8..06c863a 100644
--- a/src/box/sql/fk_constraint.c
+++ b/src/box/sql/fk_constraint.c
@@ -287,8 +287,8 @@ fk_constraint_lookup_parent(struct Parse *parse_context, struct space *parent,
 		assert(incr_count == 1);
 		const char *err = tt_sprintf(tnt_errcode_desc(ER_SQL_EXECUTE),
 					     "FOREIGN KEY constraint failed");
-		sqlVdbeAddOp4(v, OP_Halt, SQL_TARANTOOL_ERROR, 0,
-			      ER_SQL_EXECUTE, err, P4_STATIC);
+		sqlVdbeAddOp4(v, OP_Halt, -1, 0, ER_SQL_EXECUTE, err,
+			      P4_STATIC);
 	} else {
 		sqlVdbeAddOp2(v, OP_FkCounter, fk_def->is_deferred,
 				  incr_count);
diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c
index 3309753..43931c0 100644
--- a/src/box/sql/insert.c
+++ b/src/box/sql/insert.c
@@ -812,7 +812,7 @@ vdbe_emit_ck_constraint(struct Parse *parser, struct Expr *expr,
 	sqlExprIfTrue(parser, expr, check_is_passed, SQL_JUMPIFNULL);
 	const char *fmt = tnt_errcode_desc(ER_CK_CONSTRAINT_FAILED);
 	const char *error_msg = tt_sprintf(fmt, ck_constraint_name, expr_str);
-	sqlVdbeAddOp4(v, OP_Halt, SQL_TARANTOOL_ERROR, ON_CONFLICT_ACTION_ABORT,
+	sqlVdbeAddOp4(v, OP_Halt, -1, ON_CONFLICT_ACTION_ABORT,
 		      0, sqlDbStrDup(parser->db, error_msg), P4_DYNAMIC);
 	sqlVdbeChangeP5(v, ER_CK_CONSTRAINT_FAILED);
 	VdbeNoopComment((v, "END: ck constraint %s test", ck_constraint_name));
@@ -865,9 +865,8 @@ vdbe_emit_constraint_checks(struct Parse *parse_context, struct space *space,
 						    "failed: %s.%s", def->name,
 						    def->fields[i].name));
 			addr = sqlVdbeAddOp1(v, OP_NotNull, new_tuple_reg + i);
-			sqlVdbeAddOp4(v, OP_Halt, SQL_TARANTOOL_ERROR,
-				      on_conflict_nullable, ER_SQL_EXECUTE,
-				      err, P4_STATIC);
+			sqlVdbeAddOp4(v, OP_Halt, -1, on_conflict_nullable,
+				      ER_SQL_EXECUTE, err, P4_STATIC);
 			sqlVdbeJumpHere(v, addr);
 			break;
 		case ON_CONFLICT_ACTION_IGNORE:
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index e6d3a3d..76d464f 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -258,7 +258,7 @@ sqlCreateFunc(sql * db,
 	    (255 < (sqlStrlen30(zFunctionName)))) {
 		diag_set(ClientError, ER_CREATE_FUNCTION, zFunctionName,
 			 "wrong function definition");
-		return SQL_TARANTOOL_ERROR;
+		return -1;
 	}
 
 	assert(SQL_FUNC_CONSTANT == SQL_DETERMINISTIC);
@@ -276,7 +276,7 @@ sqlCreateFunc(sql * db,
 			diag_set(ClientError, ER_CREATE_FUNCTION, zFunctionName,
 				 "unable to create function due to active "\
 				 "statements");
-			return SQL_TARANTOOL_ERROR;
+			return -1;
 		} else {
 			sqlExpirePreparedStatements(db);
 		}
@@ -285,7 +285,7 @@ sqlCreateFunc(sql * db,
 	p = sqlFindFunction(db, zFunctionName, nArg, 1);
 	assert(p || db->mallocFailed);
 	if (p == NULL)
-		return SQL_TARANTOOL_ERROR;
+		return -1;
 
 	/* If an older version of the function with a configured destructor is
 	 * being replaced invoke the destructor function here.
diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index 4f072f1..0aa744f 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -83,7 +83,7 @@ sqlPrepare(sql * db,	/* Database handle. */
 		if (nBytes > mxLen) {
 			diag_set(ClientError, ER_SQL_PARSER_LIMIT,
 				 "SQL command length", nBytes, mxLen);
-			rc = SQL_TARANTOOL_ERROR;
+			rc = -1;
 			goto end_prepare;
 		}
 		zSqlCopy = sqlDbStrNDup(db, zSql, nBytes);
@@ -105,7 +105,7 @@ sqlPrepare(sql * db,	/* Database handle. */
 		*pzTail = sParse.zTail;
 	}
 	if (sParse.is_aborted)
-		rc = SQL_TARANTOOL_ERROR;
+		rc = -1;
 
 	if (rc == 0 && sParse.pVdbe && sParse.explain) {
 		static const char *const azColName[] = {
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index 2ecad78..a92fa8a 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -2105,8 +2105,8 @@ computeLimitRegisters(Parse * pParse, Select * p, int iBreak)
 					     "Only positive integers are "\
 					     "allowed in the LIMIT clause");
 		sqlVdbeResolveLabel(v, halt_label);
-		sqlVdbeAddOp4(v, OP_Halt, SQL_TARANTOOL_ERROR, 0,
-			      ER_SQL_EXECUTE, err, P4_STATIC);
+		sqlVdbeAddOp4(v, OP_Halt, -1, 0, ER_SQL_EXECUTE, err,
+			      P4_STATIC);
 
 		sqlVdbeResolveLabel(v, positive_limit_label);
 		VdbeCoverage(v);
@@ -2137,9 +2137,8 @@ computeLimitRegisters(Parse * pParse, Select * p, int iBreak)
 				err = tt_sprintf(err, "Expression subquery "\
 						 "could be limited only "\
 						 "with 1");
-				sqlVdbeAddOp4(v, OP_Halt, SQL_TARANTOOL_ERROR,
-					      0, ER_SQL_EXECUTE, err,
-					      P4_STATIC);
+				sqlVdbeAddOp4(v, OP_Halt, -1, 0, ER_SQL_EXECUTE,
+					      err, P4_STATIC);
 				sqlVdbeResolveLabel(v, no_err);
 				sqlReleaseTempReg(pParse, r1);
 
@@ -2164,8 +2163,8 @@ computeLimitRegisters(Parse * pParse, Select * p, int iBreak)
 					 "Only positive integers are allowed "\
 					 "in the OFFSET clause");
 			sqlVdbeResolveLabel(v, offset_error_label);
-			sqlVdbeAddOp4(v, OP_Halt, SQL_TARANTOOL_ERROR, 0,
-				      ER_SQL_EXECUTE, err, P4_STATIC);
+			sqlVdbeAddOp4(v, OP_Halt, -1, 0, ER_SQL_EXECUTE, err,
+				      P4_STATIC);
 
 			sqlVdbeResolveLabel(v, positive_offset_label);
             		sqlReleaseTempReg(pParse, r1);
@@ -5436,8 +5435,7 @@ vdbe_code_raise_on_multiple_rows(struct Parse *parser, int limit_reg, int end_ma
 	const char *error = tt_sprintf(tnt_errcode_desc(ER_SQL_EXECUTE),
 				       "Expression subquery returned more "\
 				       "than 1 row");
-	sqlVdbeAddOp4(v, OP_Halt, SQL_TARANTOOL_ERROR, 0, ER_SQL_EXECUTE, error,
-		      P4_STATIC);
+	sqlVdbeAddOp4(v, OP_Halt, -1, 0, ER_SQL_EXECUTE, error, P4_STATIC);
 	sqlReleaseTempReg(parser, r1);
 }
 
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index cff8ef5..d5a1a9a 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -356,12 +356,10 @@ struct sql_vfs {
 #define SQL_LIMIT_WORKER_THREADS           10
 
 enum sql_ret_code {
-	/** Abort due to constraint violation. */
-	SQL_TARANTOOL_ERROR = 4,
 	/** sql_step() has another row ready. */
-	SQL_ROW,
+	SQL_ROW = 1,
 	/** sql_step() has finished executing. */
-	SQL_DONE,
+	SQL_DONE = 2,
 };
 
 void *
diff --git a/src/box/sql/tarantoolInt.h b/src/box/sql/tarantoolInt.h
index 71073ad..e166045 100644
--- a/src/box/sql/tarantoolInt.h
+++ b/src/box/sql/tarantoolInt.h
@@ -35,7 +35,7 @@ int tarantoolsqlDelete(BtCursor * pCur, u8 flags);
  * @param key Key of record to be deleted.
  * @param key_size Size of key.
  *
- * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise.
+ * @retval 0 on success, -1 otherwise.
  */
 int
 sql_delete_by_key(struct space *space, uint32_t iid, char *key,
@@ -82,7 +82,7 @@ sql_ephemeral_space_create(uint32_t filed_count, struct sql_key_info *key_info);
  * @param tuple Tuple to be inserted.
  * @param tuple_end End of tuple to be inserted.
  *
- * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise.
+ * @retval 0 on success, -1 otherwise.
  */
 int tarantoolsqlEphemeralInsert(struct space *space, const char *tuple,
 				    const char *tuple_end);
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index c592518..68edbc0 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -682,7 +682,7 @@ vdbe_field_ref_fetch(struct vdbe_field_ref *field_ref, uint32_t fieldno,
 	uint32_t dummy;
 	data = field_ref->data + slots[fieldno];
 	if (vdbe_decode_msgpack_into_mem(data, dest_mem, &dummy) != 0)
-		return SQL_TARANTOOL_ERROR;
+		return -1;
 
 	/*
 	 * MsgPack map, array or extension (unsupported in sql).
@@ -703,7 +703,7 @@ vdbe_field_ref_fetch(struct vdbe_field_ref *field_ref, uint32_t fieldno,
 		int len = dest_mem->n;
 		if (dest_mem->szMalloc < len + 1) {
 			if (sqlVdbeMemGrow(dest_mem, len + 1, 1) != 0)
-				return SQL_TARANTOOL_ERROR;
+				return -1;
 		} else {
 			dest_mem->z =
 				memcpy(dest_mem->zMalloc, dest_mem->z, len);
@@ -1018,8 +1018,8 @@ case OP_Yield: {            /* in1, jump */
  *
  * If P4 is not null then it is an error message string.
  *
- * If P1 is SQL_TARANTOOL_ERROR then P3 is a ClientError code and
- * P4 is error message to set.
+ * If P1 is -1 then P3 is a ClientError code and  P4 is error
+ * message to set.
  *
  * There is an implied "Halt 0 0 0" instruction inserted at the
  * very end of every program.  So a jump past the last instruction
@@ -1056,14 +1056,12 @@ case OP_Halt: {
 	p->errorAction = (u8)pOp->p2;
 	p->pc = pcx;
 	if (p->rc) {
-		assert(p->rc == SQL_TARANTOOL_ERROR);
 		if (pOp->p4.z != NULL)
 			box_error_set(__FILE__, __LINE__, pOp->p3, pOp->p4.z);
 		assert(! diag_is_empty(diag_get()));
 	}
-	rc = sqlVdbeHalt(p);
-	assert(rc == 0 || rc == -1);
-	rc = p->rc ? SQL_TARANTOOL_ERROR : SQL_DONE;
+	sqlVdbeHalt(p);
+	rc = p->rc ? -1 : SQL_DONE;
 	goto vdbe_return;
 }
 
@@ -3604,7 +3602,6 @@ case OP_Found: {        /* jump, in3 */
 	rc = sqlCursorMovetoUnpacked(pC->uc.pCursor, pIdxKey, &res);
 	if (pFree != NULL)
 		sqlDbFree(db, pFree);
-	assert(rc == 0 || rc == SQL_TARANTOOL_ERROR);
 	if (rc != 0)
 		goto abort_due_to_error;
 	pC->seekResult = res;
@@ -4274,7 +4271,6 @@ case OP_IdxInsert: {
 	} else if (pOp->p5 & OPFLAG_OE_ROLLBACK) {
 		p->errorAction = ON_CONFLICT_ACTION_ROLLBACK;
 	}
-	assert(rc == 0 || rc == SQL_TARANTOOL_ERROR);
 	if (rc != 0)
 		goto abort_due_to_error;
 	break;
@@ -4352,9 +4348,8 @@ case OP_Update: {
 	}
 
 	assert(rc == 0);
-	if (box_update(space->def->id, 0, key_mem->z, key_mem->z + key_mem->n,
-		       ops, ops + ops_size, 0, NULL) != 0)
-		rc = SQL_TARANTOOL_ERROR;
+	rc = box_update(space->def->id, 0, key_mem->z, key_mem->z + key_mem->n,
+			ops, ops + ops_size, 0, NULL);
 
 	if (pOp->p5 & OPFLAG_OE_IGNORE) {
 		/*
@@ -4373,7 +4368,6 @@ case OP_Update: {
 	} else if (pOp->p5 & OPFLAG_OE_ROLLBACK) {
 		p->errorAction = ON_CONFLICT_ACTION_ROLLBACK;
 	}
-	assert(rc == 0 || rc == SQL_TARANTOOL_ERROR);
 	if (rc != 0)
 		goto abort_due_to_error;
 	break;
@@ -5159,7 +5153,7 @@ case OP_Init: {          /* jump */
 	 */
 	if (p->pFrame == NULL && sql_vdbe_prepare(p) != 0) {
 		sqlDbFree(db, p);
-		rc = SQL_TARANTOOL_ERROR;
+		rc = -1;
 		break;
 	}
 
@@ -5264,7 +5258,7 @@ default: {          /* This is really OP_Noop and OP_Explain */
 	 * an error of some kind.
 	 */
 abort_due_to_error:
-	rc = SQL_TARANTOOL_ERROR;
+	rc = -1;
 	p->rc = rc;
 
 	/* This is the only way out of this procedure. */
@@ -5274,8 +5268,7 @@ vdbe_return:
 	assert(rc!=0 || nExtraDelete==0
 		|| sql_strlike_ci("DELETE%", p->zSql, 0) != 0
 		);
-	assert(rc == 0 || rc == SQL_TARANTOOL_ERROR ||
-	       rc == SQL_ROW || rc == SQL_DONE);
+	assert(rc == 0 || rc == -1 || rc == SQL_ROW || rc == SQL_DONE);
 	return rc;
 
 	/* Jump to here if a string or blob larger than SQL_MAX_LENGTH
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 336dc3b..268aff6 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -297,7 +297,7 @@ invokeValueDestructor(const void *p,	/* Value to destroy */
 			 "big");
 		pCtx->is_aborted = true;
 	}
-	return SQL_TARANTOOL_ERROR;
+	return -1;
 }
 
 void
@@ -394,7 +394,7 @@ sql_result_zeroblob64(sql_context * pCtx, u64 n)
 	if (n > (u64) pOut->db->aLimit[SQL_LIMIT_LENGTH]) {
 		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob is too "\
 			 "big");
-		return SQL_TARANTOOL_ERROR;
+		return -1;
 	}
 	sqlVdbeMemSetZeroBlob(pCtx->pOut, (int)n);
 	return 0;
@@ -427,8 +427,8 @@ sqlStep(Vdbe * p)
 	}
 
 	if (p->pc <= 0 && p->expired) {
-		p->rc = SQL_TARANTOOL_ERROR;
-		return SQL_TARANTOOL_ERROR;
+		p->rc = -1;
+		return -1;
 	}
 	if (p->pc < 0) {
 
@@ -1134,7 +1134,7 @@ sql_bind_zeroblob64(sql_stmt * pStmt, int i, sql_uint64 n)
 	if (n > (u64) p->db->aLimit[SQL_LIMIT_LENGTH]) {
 		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob is too "\
 			 "big");
-		rc = SQL_TARANTOOL_ERROR;
+		rc = -1;
 	} else {
 		assert((n & 0x7FFFFFFF) == n);
 		rc = sql_bind_zeroblob(pStmt, i, n);
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 8e2ca35..d4ba3a3 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -2079,7 +2079,7 @@ sqlVdbeCloseStatement(Vdbe * p, int eOp)
  * violations, return -1. Otherwise, 0.
  *
  * If there are outstanding FK violations and this function returns
- * SQL_TARANTOOL_ERROR and set an error.
+ * -1 and set an error.
  */
 int
 sqlVdbeCheckFk(Vdbe * p, int deferred)
@@ -2088,11 +2088,11 @@ sqlVdbeCheckFk(Vdbe * p, int deferred)
 	if ((deferred && txn != NULL && txn->psql_txn != NULL &&
 	     txn->psql_txn->fk_deferred_count > 0) ||
 	    (!deferred && p->nFkConstraint > 0)) {
-		p->rc = SQL_TARANTOOL_ERROR;
+		p->rc = -1;
 		p->errorAction = ON_CONFLICT_ACTION_ABORT;
 		diag_set(ClientError, ER_SQL_EXECUTE, "FOREIGN KEY constraint "\
 			 "failed");
-		return SQL_TARANTOOL_ERROR;
+		return -1;
 	}
 	return 0;
 }
@@ -2210,7 +2210,7 @@ sqlVdbeHalt(Vdbe * p)
 					 */
 					rc = (in_txn() == NULL ||
 					      txn_commit(in_txn()) == 0) ?
-					     0 : SQL_TARANTOOL_ERROR;
+					      0 : -1;
 					closeCursorsAndFree(p);
 				}
 				if (rc != 0) {
diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
index da63193..c3db534 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -995,7 +995,7 @@ sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
 		if (nByte > iLimit) {
 			diag_set(ClientError, ER_SQL_EXECUTE, "string or blob "\
 				 "is too big");
-			return SQL_TARANTOOL_ERROR;
+			return -1;
 		}
 		testcase(nAlloc == 0);
 		testcase(nAlloc == 31);
@@ -1021,7 +1021,7 @@ sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
 	if (nByte > iLimit) {
 		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob is too "\
 			 "big");
-		return SQL_TARANTOOL_ERROR;
+		return -1;
 	}
 
 	return 0;
diff --git a/src/box/sql/where.c b/src/box/sql/where.c
index 9739268..d2bfbfc 100644
--- a/src/box/sql/where.c
+++ b/src/box/sql/where.c
@@ -2779,7 +2779,7 @@ whereLoopAddBtree(WhereLoopBuilder * pBuilder,	/* WHERE clause information */
 		if (key_def == NULL) {
 tnt_error:
 			pWInfo->pParse->is_aborted = true;
-			return SQL_TARANTOOL_ERROR;
+			return -1;
 		}
 
 		struct index_opts opts;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 23/28] sql: remove field errMask from struct sql
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (21 preceding siblings ...)
  2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 22/28] sql: remove SQL_TARANTOOL_ERROR errcode imeevma
@ 2019-06-10 13:57 ` imeevma
  2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 24/28] sql: replace rc by is_aborted in struct VDBE imeevma
                   ` (8 subsequent siblings)
  31 siblings, 0 replies; 56+ messages in thread
From: imeevma @ 2019-06-10 13:57 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

This field has become unused and should be removed.
---
 src/box/sql/legacy.c  | 1 -
 src/box/sql/main.c    | 1 -
 src/box/sql/malloc.c  | 2 +-
 src/box/sql/prepare.c | 2 --
 src/box/sql/sqlInt.h  | 1 -
 src/box/sql/vdbeapi.c | 3 +--
 src/box/sql/vdbeaux.c | 9 ++-------
 7 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/src/box/sql/legacy.c b/src/box/sql/legacy.c
index df40032..2f69007 100644
--- a/src/box/sql/legacy.c
+++ b/src/box/sql/legacy.c
@@ -163,6 +163,5 @@ sql_exec(sql * db,	/* The database on which the SQL executes */
 	sqlDbFree(db, azCols);
 
 	assert(rc == 0);
-	assert((rc & db->errMask) == rc);
 	return rc;
 }
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index 76d464f..145964f 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -535,7 +535,6 @@ sql_init_db(sql **out_db)
 		*out_db = NULL;
 		return -1;
 	}
-	db->errMask = 0xff;
 	db->magic = SQL_MAGIC_BUSY;
 
 	db->pVfs = sql_vfs_find(0);
diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index 64873f2..f5612bf 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -783,5 +783,5 @@ sqlApiExit(sql * db, int rc)
 	if (db->mallocFailed) {
 		return apiOomError(db);
 	}
-	return rc & db->errMask;
+	return rc;
 }
diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index 0aa744f..f840d2f 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -176,8 +176,6 @@ sqlPrepare(sql * db,	/* Database handle. */
  end_prepare:
 
 	sql_parser_destroy(&sParse);
-	rc = sqlApiExit(db, rc);
-	assert((rc & db->errMask) == rc);
 	return rc;
 }
 
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index d5a1a9a..fbf5f72 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -1355,7 +1355,6 @@ struct sql {
 	struct Vdbe *pVdbe;	/* List of active virtual machines */
 	struct coll *pDfltColl;	/* The default collating sequence (BINARY) */
 	i64 szMmap;		/* Default mmap_size setting */
-	int errMask;		/* & result codes with this before returning */
 	u16 dbOptFlags;		/* Flags to enable/disable optimizations */
 	u8 enc;			/* Text encoding */
 	u8 temp_store;		/* 1: file 2: memory 0: default */
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 268aff6..9380155 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -108,7 +108,6 @@ sql_reset(sql_stmt * pStmt)
 	checkProfileCallback(db, v);
 	int rc = sqlVdbeReset(v);
 	sqlVdbeRewind(v);
-	assert((rc & (db->errMask)) == rc);
 	return sqlApiExit(db, rc);
 }
 
@@ -465,7 +464,7 @@ sqlStep(Vdbe * p)
 		 */
 		rc = p->rc;
 	}
-	return (rc & db->errMask);
+	return rc;
 }
 
 /*
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index d4ba3a3..28b423d 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -2315,9 +2315,6 @@ sqlVdbeResetStepResult(Vdbe * p)
 int
 sqlVdbeReset(Vdbe * p)
 {
-	sql *db;
-	db = p->db;
-
 	/* If the VM did not run to completion or if it encountered an
 	 * error, then it might not have been halted properly.  So halt
 	 * it now.
@@ -2389,7 +2386,7 @@ sqlVdbeReset(Vdbe * p)
 #endif
 	p->iCurrentTime = 0;
 	p->magic = VDBE_MAGIC_RESET;
-	return p->rc & db->errMask;
+	return p->rc;
 }
 
 /*
@@ -2400,10 +2397,8 @@ int
 sqlVdbeFinalize(Vdbe * p)
 {
 	int rc = 0;
-	if (p->magic == VDBE_MAGIC_RUN || p->magic == VDBE_MAGIC_HALT) {
+	if (p->magic == VDBE_MAGIC_RUN || p->magic == VDBE_MAGIC_HALT)
 		rc = sqlVdbeReset(p);
-		assert((rc & p->db->errMask) == rc);
-	}
 	sqlVdbeDelete(p);
 	return rc;
 }
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 24/28] sql: replace rc by is_aborted in struct VDBE
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (22 preceding siblings ...)
  2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 23/28] sql: remove field errMask from struct sql imeevma
@ 2019-06-10 13:57 ` imeevma
  2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 25/28] sql: remove sql_log() imeevma
                   ` (7 subsequent siblings)
  31 siblings, 0 replies; 56+ messages in thread
From: imeevma @ 2019-06-10 13:57 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Currently, the rc field of the VDBE structure is either 0 or -1.
Due to this, it is better to replace this integer field with the
boolean field is_aborted.
---
 src/box/sql/vdbe.c    | 14 +++++++-------
 src/box/sql/vdbeInt.h |  3 ++-
 src/box/sql/vdbeapi.c | 10 +++++-----
 src/box/sql/vdbeaux.c | 34 +++++++++++++++-------------------
 4 files changed, 29 insertions(+), 32 deletions(-)

diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 68edbc0..4204637 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -746,8 +746,7 @@ int sqlVdbeExec(Vdbe *p)
 	/*** INSERT STACK UNION HERE ***/
 
 	assert(p->magic==VDBE_MAGIC_RUN);  /* sql_step() verifies this */
-	assert(p->rc == 0);
-	p->rc = 0;
+	assert(!p->is_aborted);
 	p->iCurrentTime = 0;
 	assert(p->explain==0);
 	p->pResultSet = 0;
@@ -1052,16 +1051,17 @@ case OP_Halt: {
 		pOp = &aOp[pcx];
 		break;
 	}
-	p->rc = pOp->p1;
+	if (pOp->p1 != 0)
+		p->is_aborted = true;
 	p->errorAction = (u8)pOp->p2;
 	p->pc = pcx;
-	if (p->rc) {
+	if (p->is_aborted) {
 		if (pOp->p4.z != NULL)
 			box_error_set(__FILE__, __LINE__, pOp->p3, pOp->p4.z);
 		assert(! diag_is_empty(diag_get()));
 	}
 	sqlVdbeHalt(p);
-	rc = p->rc ? -1 : SQL_DONE;
+	rc = p->is_aborted ? -1 : SQL_DONE;
 	goto vdbe_return;
 }
 
@@ -2872,7 +2872,7 @@ case OP_Savepoint: {
 					goto vdbe_return;
 				}
 				sqlVdbeHalt(p);
-				if (p->rc != 0)
+				if (p->is_aborted)
 					goto abort_due_to_error;
 			} else {
 				if (p1==SAVEPOINT_ROLLBACK)
@@ -5259,7 +5259,7 @@ default: {          /* This is really OP_Noop and OP_Explain */
 	 */
 abort_due_to_error:
 	rc = -1;
-	p->rc = rc;
+	p->is_aborted = true;
 
 	/* This is the only way out of this procedure. */
 vdbe_return:
diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h
index 617f16f..a1467c9 100644
--- a/src/box/sql/vdbeInt.h
+++ b/src/box/sql/vdbeInt.h
@@ -344,7 +344,8 @@ struct Vdbe {
 	int nCursor;		/* Number of slots in apCsr[] */
 	u32 cacheCtr;		/* VdbeCursor row cache generation counter */
 	int pc;			/* The program counter */
-	int rc;			/* Value to return */
+	/** True, if error occured during VDBE execution. */
+	bool is_aborted;
 	int nChange;		/* Number of db changes made since last reset */
 	int iStatement;		/* Statement number (or 0 if has not opened stmt) */
 	i64 iCurrentTime;	/* Value of julianday('now') for this statement */
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 9380155..03f5069 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -421,12 +421,12 @@ sqlStep(Vdbe * p)
 	/* Check that malloc() has not failed. If it has, return early. */
 	db = p->db;
 	if (db->mallocFailed) {
-		p->rc = -1;
+		p->is_aborted = true;
 		return -1;
 	}
 
 	if (p->pc <= 0 && p->expired) {
-		p->rc = -1;
+		p->is_aborted = true;
 		return -1;
 	}
 	if (p->pc < 0) {
@@ -459,10 +459,10 @@ sqlStep(Vdbe * p)
 
 	if (p->isPrepareV2 && rc != SQL_ROW && rc != SQL_DONE) {
 		/* If this statement was prepared using sql_prepare_v2(), and an
-		 * error has occurred, then return the error code in p->rc to the
-		 * caller. Set the error code in the database handle to the same value.
+		 * error has occurred, then return an error.
 		 */
-		rc = p->rc;
+		if (p->is_aborted)
+			rc = -1;
 	}
 	return rc;
 }
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 28b423d..ec303c7 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -1460,7 +1460,6 @@ sqlVdbeList(Vdbe * p)
 		i = p->pc++;
 	} while (i < nRow && p->explain == 2 && p->aOp[i].opcode != OP_Explain);
 	if (i >= nRow) {
-		p->rc = 0;
 		rc = SQL_DONE;
 	} else {
 		char *zP4;
@@ -1569,7 +1568,6 @@ sqlVdbeList(Vdbe * p)
 
 		p->nResColumn = 8 - 4 * (p->explain - 1);
 		p->pResultSet = &p->aMem[1];
-		p->rc = 0;
 		rc = SQL_ROW;
 	}
 	return rc;
@@ -1703,7 +1701,7 @@ sqlVdbeRewind(Vdbe * p)
 	}
 #endif
 	p->pc = -1;
-	p->rc = 0;
+	p->is_aborted = false;
 	p->ignoreRaised = 0;
 	p->errorAction = ON_CONFLICT_ACTION_ABORT;
 	p->nChange = 0;
@@ -2088,7 +2086,7 @@ sqlVdbeCheckFk(Vdbe * p, int deferred)
 	if ((deferred && txn != NULL && txn->psql_txn != NULL &&
 	     txn->psql_txn->fk_deferred_count > 0) ||
 	    (!deferred && p->nFkConstraint > 0)) {
-		p->rc = -1;
+		p->is_aborted = true;
 		p->errorAction = ON_CONFLICT_ACTION_ABORT;
 		diag_set(ClientError, ER_SQL_EXECUTE, "FOREIGN KEY constraint "\
 			 "failed");
@@ -2164,7 +2162,7 @@ sqlVdbeHalt(Vdbe * p)
 	 */
 
 	if (db->mallocFailed) {
-		p->rc = -1;
+		p->is_aborted = true;
 	}
 	closeTopFrameCursors(p);
 	if (p->magic != VDBE_MAGIC_RUN) {
@@ -2179,7 +2177,7 @@ sqlVdbeHalt(Vdbe * p)
 		int eStatementOp = 0;
 
 		/* Check for immediate foreign key violations. */
-		if (p->rc == 0) {
+		if (!p->is_aborted) {
 			sqlVdbeCheckFk(p, 0);
 		}
 
@@ -2190,7 +2188,7 @@ sqlVdbeHalt(Vdbe * p)
 		 * above has occurred.
 		 */
 		if (p->auto_commit) {
-			if (p->rc == 0
+			if (!p->is_aborted
 			    || (p->errorAction == ON_CONFLICT_ACTION_FAIL)) {
 				rc = sqlVdbeCheckFk(p, 1);
 				if (rc != 0) {
@@ -2214,7 +2212,7 @@ sqlVdbeHalt(Vdbe * p)
 					closeCursorsAndFree(p);
 				}
 				if (rc != 0) {
-					p->rc = rc;
+					p->is_aborted = true;
 					box_txn_rollback();
 					closeCursorsAndFree(p);
 					sqlRollbackAll(p);
@@ -2228,7 +2226,8 @@ sqlVdbeHalt(Vdbe * p)
 			}
 			p->anonymous_savepoint = NULL;
 		} else if (eStatementOp == 0) {
-			if (p->rc == 0 || p->errorAction == ON_CONFLICT_ACTION_FAIL) {
+			if (!p->is_aborted ||
+			    p->errorAction == ON_CONFLICT_ACTION_FAIL) {
 				eStatementOp = SAVEPOINT_RELEASE;
 			} else if (p->errorAction == ON_CONFLICT_ACTION_ABORT) {
 				eStatementOp = SAVEPOINT_ROLLBACK;
@@ -2251,8 +2250,7 @@ sqlVdbeHalt(Vdbe * p)
 			rc = sqlVdbeCloseStatement(p, eStatementOp);
 			if (rc) {
 				box_txn_rollback();
-				if (p->rc == 0)
-					p->rc = rc;
+				p->is_aborted = true;
 				closeCursorsAndFree(p);
 				sqlRollbackAll(p);
 				sqlCloseSavepoints(p);
@@ -2282,9 +2280,8 @@ sqlVdbeHalt(Vdbe * p)
 	}
 	p->magic = VDBE_MAGIC_HALT;
 	checkActiveVdbeCnt(db);
-	if (db->mallocFailed) {
-		p->rc = -1;
-	}
+	if (db->mallocFailed)
+		p->is_aborted = true;
 
 	assert(db->nVdbeActive > 0 || box_txn() ||
 	       p->anonymous_savepoint == NULL);
@@ -2292,13 +2289,12 @@ sqlVdbeHalt(Vdbe * p)
 }
 
 /*
- * Each VDBE holds the result of the most recent sql_step() call
- * in p->rc.  This routine sets that result back to 0.
+ * This routine sets is_aborted of VDBE to false.
  */
 void
 sqlVdbeResetStepResult(Vdbe * p)
 {
-	p->rc = 0;
+	p->is_aborted = false;
 }
 
 /*
@@ -2337,7 +2333,7 @@ sqlVdbeReset(Vdbe * p)
 		 * is currently disabled, so this error has been
 		 * replaced with assert.
 		 */
-		assert(p->rc == 0 || p->expired == 0);
+		assert(!p->is_aborted || p->expired == 0);
 	}
 
 	/* Reclaim all memory used by the VDBE
@@ -2386,7 +2382,7 @@ sqlVdbeReset(Vdbe * p)
 #endif
 	p->iCurrentTime = 0;
 	p->magic = VDBE_MAGIC_RESET;
-	return p->rc;
+	return p->is_aborted ? -1 : 0;
 }
 
 /*
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 25/28] sql: remove sql_log()
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (23 preceding siblings ...)
  2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 24/28] sql: replace rc by is_aborted in struct VDBE imeevma
@ 2019-06-10 13:57 ` imeevma
  2019-06-13 22:24   ` [tarantool-patches] " Vladislav Shpilevoy
  2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 26/28] sql: cleanup of legacy memory management system imeevma
                   ` (6 subsequent siblings)
  31 siblings, 1 reply; 56+ messages in thread
From: imeevma @ 2019-06-10 13:57 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

This function is not used in Tarantool and should be removed.
---
 src/box/sql/os_unix.c |  7 +++----
 src/box/sql/printf.c  | 34 ----------------------------------
 src/box/sql/resolve.c |  3 +--
 src/box/sql/sqlInt.h  |  3 ---
 4 files changed, 4 insertions(+), 43 deletions(-)

diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index f0cf4ac..b161580 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -1073,10 +1073,9 @@ unixUnmapfile(unixFile * pFd)
  *       unixFile.mmapSize
  *       unixFile.mmapSizeActual
  *
- * If unsuccessful, an error message is logged via sql_log() and
- * the three variables above are zeroed. In this case sql should
- * continue accessing the database using the xRead() and xWrite()
- * methods.
+ * If unsuccessful,the three variables above are zeroed. In this
+ * case sql should continue accessing the database using the
+ * xRead() and xWrite() methods.
  */
 static void
 unixRemapfile(unixFile * pFd,	/* File descriptor object */
diff --git a/src/box/sql/printf.c b/src/box/sql/printf.c
index c364055..ed41ae9 100644
--- a/src/box/sql/printf.c
+++ b/src/box/sql/printf.c
@@ -1125,40 +1125,6 @@ sql_snprintf(int n, char *zBuf, const char *zFormat, ...)
 	return z;
 }
 
-/*
- * This is the routine that actually formats the sql_log() message.
- * We house it in a separate routine from sql_log() to avoid using
- * stack space on small-stack systems when logging is disabled.
- *
- * sqlVXPrintf() might ask for *temporary* memory allocations for
- * certain format characters (%q) or for very large precisions or widths.
- */
-static void
-renderLogMsg(int iErrCode, const char *zFormat, va_list ap)
-{
-	StrAccum acc;		/* String accumulator */
-	char zMsg[SQL_PRINT_BUF_SIZE * 3];	/* Complete log message */
-
-	sqlStrAccumInit(&acc, 0, zMsg, sizeof(zMsg), 0);
-	sqlVXPrintf(&acc, zFormat, ap);
-	sqlGlobalConfig.xLog(sqlGlobalConfig.pLogArg, iErrCode,
-				 sqlStrAccumFinish(&acc));
-}
-
-/*
- * Format and write a message to the log if logging is enabled.
- */
-void
-sql_log(int iErrCode, const char *zFormat, ...)
-{
-	va_list ap;		/* Vararg list */
-	if (sqlGlobalConfig.xLog) {
-		va_start(ap, zFormat);
-		renderLogMsg(iErrCode, zFormat, ap);
-		va_end(ap);
-	}
-}
-
 #if defined(SQL_DEBUG)
 /*
  * A version of printf() that understands %lld.  Used for debugging.
diff --git a/src/box/sql/resolve.c b/src/box/sql/resolve.c
index 087e9dd..7252348 100644
--- a/src/box/sql/resolve.c
+++ b/src/box/sql/resolve.c
@@ -363,8 +363,7 @@ lookupName(Parse * pParse,	/* The parsing context */
 		 * The ability to use an output result-set column in the WHERE, GROUP BY,
 		 * or HAVING clauses, or as part of a larger expression in the ORDER BY
 		 * clause is not standard SQL.  This is a (goofy) sql extension, that
-		 * is supported for backwards compatibility only. Hence, we issue a warning
-		 * on sql_log() whenever the capability is used.
+		 * is supported for backwards compatibility only.
 		 */
 		if ((pEList = pNC->pEList) != 0 && zTab == 0 && cnt == 0) {
 			for (j = 0; j < pEList->nExpr; j++) {
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index fbf5f72..3825a2b 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -591,9 +591,6 @@ sql_row_count(struct sql_context *context, MAYBE_UNUSED int unused1,
 void *
 sql_user_data(sql_context *);
 
-void
-sql_log(int iErrCode, const char *zFormat, ...);
-
 void *
 sql_aggregate_context(sql_context *,
 			  int nBytes);
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 26/28] sql: cleanup of legacy memory management system
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (24 preceding siblings ...)
  2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 25/28] sql: remove sql_log() imeevma
@ 2019-06-10 13:57 ` imeevma
  2019-06-13 22:24   ` [tarantool-patches] " Vladislav Shpilevoy
  2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 27/28] sql: make function return void instead of int imeevma
                   ` (5 subsequent siblings)
  31 siblings, 1 reply; 56+ messages in thread
From: imeevma @ 2019-06-10 13:57 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Follow-up for #4074
---
 src/box/sql/malloc.c   | 246 +------------------------------------------------
 src/box/sql/sqlInt.h   |  16 ----
 src/box/sql/status.c   | 149 ------------------------------
 src/box/sql/tokenize.c |   5 -
 src/box/sql/vdbe.c     |   4 -
 src/box/sql/vdbesort.c |   8 +-
 6 files changed, 4 insertions(+), 424 deletions(-)

diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index f5612bf..c3fc50b 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -121,26 +121,6 @@ sql_sized_realloc(void *pPrior, int nByte)
 }
 
 /*
- * Attempt to release up to n bytes of non-essential memory currently
- * held by sql. An example of non-essential memory is memory used to
- * cache database pages that are not currently in use.
- */
-int
-sql_release_memory(int n)
-{
-#ifdef SQL_ENABLE_MEMORY_MANAGEMENT
-	return sqlPcacheReleaseMemory(n);
-#else
-	/* IMPLEMENTATION-OF: R-34391-24921 The sql_release_memory() routine
-	 * is a no-op returning zero if sql is not compiled with
-	 * SQL_ENABLE_MEMORY_MANAGEMENT.
-	 */
-	UNUSED_PARAMETER(n);
-	return 0;
-#endif
-}
-
-/*
  * An instance of the following object records the location of
  * each unused scratch buffer.
  */
@@ -149,38 +129,11 @@ typedef struct ScratchFreeslot {
 } ScratchFreeslot;
 
 /*
- * State information local to the memory allocation subsystem.
- */
-static SQL_WSD struct Mem0Global {
-	sql_int64 alarmThreshold;	/* The soft heap limit */
-
-	/*
-	 * Pointers to the end of sqlGlobalConfig.pScratch memory
-	 * (so that a range test can be used to determine if an allocation
-	 * being freed came from pScratch) and a pointer to the list of
-	 * unused scratch allocations.
-	 */
-	void *pScratchEnd;
-	ScratchFreeslot *pScratchFree;
-	u32 nScratchFree;
-
-	/*
-	 * True if heap is nearly "full" where "full" is defined by the
-	 * sql_soft_heap_limit() setting.
-	 */
-	int nearlyFull;
-} mem0 = {
-0, 0, 0, 0, 0};
-
-#define mem0 GLOBAL(struct Mem0Global, mem0)
-
-/*
  * Initialize the memory allocation subsystem.
  */
 void
 sqlMallocInit(void)
 {
-	memset(&mem0, 0, sizeof(mem0));
 	if (sqlGlobalConfig.pScratch && sqlGlobalConfig.szScratch >= 100
 	    && sqlGlobalConfig.nScratch > 0) {
 		int i, n, sz;
@@ -189,16 +142,12 @@ sqlMallocInit(void)
 		sqlGlobalConfig.szScratch = sz;
 		pSlot = (ScratchFreeslot *) sqlGlobalConfig.pScratch;
 		n = sqlGlobalConfig.nScratch;
-		mem0.pScratchFree = pSlot;
-		mem0.nScratchFree = n;
 		for (i = 0; i < n - 1; i++) {
 			pSlot->pNext = (ScratchFreeslot *) (sz + (char *)pSlot);
 			pSlot = pSlot->pNext;
 		}
 		pSlot->pNext = 0;
-		mem0.pScratchEnd = (void *)&pSlot[1];
 	} else {
-		mem0.pScratchEnd = 0;
 		sqlGlobalConfig.pScratch = 0;
 		sqlGlobalConfig.szScratch = 0;
 		sqlGlobalConfig.nScratch = 0;
@@ -211,37 +160,6 @@ sqlMallocInit(void)
 }
 
 /*
- * Return true if the heap is currently under memory pressure - in other
- * words if the amount of heap used is close to the limit set by
- * sql_soft_heap_limit().
- */
-int
-sqlHeapNearlyFull(void)
-{
-	return mem0.nearlyFull;
-}
-
-/*
- * Deinitialize the memory allocation subsystem.
- */
-void
-sqlMallocEnd(void)
-{
-	memset(&mem0, 0, sizeof(mem0));
-}
-
-/*
- * Trigger the alarm
- */
-static void
-sqlMallocAlarm(int nByte)
-{
-	if (mem0.alarmThreshold <= 0)
-		return;
-	sql_release_memory(nByte);
-}
-
-/*
  * Do a memory allocation with statistics and alarms.  Assume the
  * lock is already held.
  */
@@ -252,23 +170,7 @@ mallocWithAlarm(int n, void **pp)
 	void *p;
 	nFull = ROUND8(n);
 	sqlStatusHighwater(SQL_STATUS_MALLOC_SIZE, n);
-	if (mem0.alarmThreshold > 0) {
-		sql_int64 nUsed =
-		    sqlStatusValue(SQL_STATUS_MEMORY_USED);
-		if (nUsed >= mem0.alarmThreshold - nFull) {
-			mem0.nearlyFull = 1;
-			sqlMallocAlarm(nFull);
-		} else {
-			mem0.nearlyFull = 0;
-		}
-	}
 	p = sql_sized_malloc(nFull);
-#ifdef SQL_ENABLE_MEMORY_MANAGEMENT
-	if (p == 0 && mem0.alarmThreshold > 0) {
-		sqlMallocAlarm(nFull);
-		p = sql_sized_malloc(nFull);
-	}
-#endif
 	if (p) {
 		nFull = sqlMallocSize(p);
 		sqlStatusUp(SQL_STATUS_MEMORY_USED, nFull);
@@ -321,101 +223,6 @@ sql_malloc64(sql_uint64 n)
 }
 
 /*
- * Each thread may only have a single outstanding allocation from
- * xScratchMalloc().  We verify this constraint in the single-threaded
- * case by setting scratchAllocOut to 1 when an allocation
- * is outstanding clearing it when the allocation is freed.
- */
-#if !defined(NDEBUG)
-static int scratchAllocOut = 0;
-#endif
-
-/*
- * Allocate memory that is to be used and released right away.
- * This routine is similar to alloca() in that it is not intended
- * for situations where the memory might be held long-term.  This
- * routine is intended to get memory to old large transient data
- * structures that would not normally fit on the stack of an
- * embedded processor.
- */
-void *
-sqlScratchMalloc(int n)
-{
-	void *p;
-	assert(n > 0);
-
-	sqlStatusHighwater(SQL_STATUS_SCRATCH_SIZE, n);
-	if (mem0.nScratchFree && sqlGlobalConfig.szScratch >= n) {
-		p = mem0.pScratchFree;
-		mem0.pScratchFree = mem0.pScratchFree->pNext;
-		mem0.nScratchFree--;
-		sqlStatusUp(SQL_STATUS_SCRATCH_USED, 1);
-	} else {
-		p = sqlMalloc(n);
-		if (sqlGlobalConfig.bMemstat && p) {
-			sqlStatusUp(SQL_STATUS_SCRATCH_OVERFLOW,
-					sqlMallocSize(p));
-		}
-	}
-
-#if !defined(NDEBUG)
-	/* EVIDENCE-OF: R-12970-05880 sql will not use more than one scratch
-	 * buffers per thread.
-	 *
-	 * This can only be checked in single-threaded mode.
-	 */
-	assert(scratchAllocOut == 0);
-	if (p)
-		scratchAllocOut++;
-#endif
-
-	return p;
-}
-
-void
-sqlScratchFree(void *p)
-{
-	if (p) {
-
-#if !defined(NDEBUG)
-		/* Verify that no more than two scratch allocation per thread
-		 * is outstanding at one time.  (This is only checked in the
-		 * single-threaded case since checking in the multi-threaded case
-		 * would be much more complicated.)
-		 */
-		assert(scratchAllocOut >= 1 && scratchAllocOut <= 2);
-		scratchAllocOut--;
-#endif
-
-		if (SQL_WITHIN
-		    (p, sqlGlobalConfig.pScratch, mem0.pScratchEnd)) {
-			/* Release memory from the SQL_CONFIG_SCRATCH allocation */
-			ScratchFreeslot *pSlot;
-			pSlot = (ScratchFreeslot *) p;
-			pSlot->pNext = mem0.pScratchFree;
-			mem0.pScratchFree = pSlot;
-			mem0.nScratchFree++;
-			assert(mem0.nScratchFree <=
-			       (u32) sqlGlobalConfig.nScratch);
-			sqlStatusDown(SQL_STATUS_SCRATCH_USED, 1);
-		} else {
-			/* Release memory back to the heap */
-			if (sqlGlobalConfig.bMemstat) {
-				int iSize = sqlMallocSize(p);
-				sqlStatusDown
-				    (SQL_STATUS_SCRATCH_OVERFLOW, iSize);
-				sqlStatusDown(SQL_STATUS_MEMORY_USED,
-						  iSize);
-				sqlStatusDown(SQL_STATUS_MALLOC_COUNT,
-						  1);
-				sql_sized_free(p);
-			} else
-				sql_sized_free(p);
-		}
-	}
-}
-
-/*
  * Return the size of a memory allocation previously obtained from
  * sqlMalloc() or sql_malloc().
  */
@@ -432,12 +239,6 @@ sqlDbMallocSize(void *p)
 	return sql_sized_sizeof(p);
 }
 
-sql_uint64
-sql_msize(void *p)
-{
-	return p ? sql_sized_sizeof(p) : 0;
-}
-
 /*
  * Free memory previously obtained from sqlMalloc().
  */
@@ -489,7 +290,7 @@ sqlDbFree(sql * db, void *p)
 void *
 sqlRealloc(void *pOld, u64 nBytes)
 {
-	int nOld, nNew, nDiff;
+	int nOld, nNew;
 	void *pNew;
 	if (pOld == 0) {
 		return sqlMalloc(nBytes);	/* IMP: R-04300-56712 */
@@ -508,17 +309,7 @@ sqlRealloc(void *pOld, u64 nBytes)
 		pNew = pOld;
 	} else if (sqlGlobalConfig.bMemstat) {
 		sqlStatusHighwater(SQL_STATUS_MALLOC_SIZE, (int)nBytes);
-		nDiff = nNew - nOld;
-		if (nDiff > 0
-		    && sqlStatusValue(SQL_STATUS_MEMORY_USED) >=
-		    mem0.alarmThreshold - nDiff) {
-			sqlMallocAlarm(nDiff);
-		}
 		pNew = sql_sized_realloc(pOld, nNew);
-		if (pNew == 0 && mem0.alarmThreshold > 0) {
-			sqlMallocAlarm((int)nBytes);
-			pNew = sql_sized_realloc(pOld, nNew);
-		}
 		if (pNew) {
 			nNew = sqlMallocSize(pNew);
 			sqlStatusUp(SQL_STATUS_MEMORY_USED, nNew - nOld);
@@ -530,18 +321,6 @@ sqlRealloc(void *pOld, u64 nBytes)
 	return pNew;
 }
 
-/*
- * The public interface to sqlRealloc.  Make sure that the memory
- * subsystem is initialized prior to invoking sqlRealloc.
- */
-void *
-sql_realloc(void *pOld, int n)
-{
-	if (n < 0)
-		n = 0;		/* IMP: R-26507-47431 */
-	return sqlRealloc(pOld, n);
-}
-
 void *
 sql_realloc64(void *pOld, sql_uint64 n)
 {
@@ -717,16 +496,6 @@ sqlDbStrNDup(sql * db, const char *z, u64 n)
 }
 
 /*
- * Free any prior content in *pz and replace it with a copy of zNew.
- */
-void
-sqlSetString(char **pz, sql * db, const char *zNew)
-{
-	sqlDbFree(db, *pz);
-	*pz = sqlDbStrDup(db, zNew);
-}
-
-/*
  * Call this routine to record the fact that an OOM (out-of-memory) error
  * has happened.  This routine will set db->mallocFailed, and also
  * temporarily disable the lookaside memory allocator and interrupt
@@ -759,16 +528,6 @@ sqlOomClear(sql * db)
 }
 
 /*
- * Take actions at the end of an API call to indicate an OOM error
- */
-static SQL_NOINLINE int
-apiOomError(sql * db)
-{
-	sqlOomClear(db);
-	return -1;
-}
-
-/*
  * This function must be called before exiting any API function (i.e.
  * returning control to the user) that has called sql_malloc or
  * sql_realloc.
@@ -781,7 +540,8 @@ sqlApiExit(sql * db, int rc)
 {
 	assert(db != 0);
 	if (db->mallocFailed) {
-		return apiOomError(db);
+		sqlOomClear(db);
+		return -1;
 	}
 	return rc;
 }
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 3825a2b..27e57cc 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -369,17 +369,11 @@ void *
 sql_malloc64(sql_uint64);
 
 void *
-sql_realloc(void *, int);
-
-void *
 sql_realloc64(void *, sql_uint64);
 
 void
 sql_free(void *);
 
-sql_uint64
-sql_msize(void *);
-
 int
 sql_stricmp(const char *, const char *);
 
@@ -1447,11 +1441,7 @@ struct sql {
  * than being distinct from one another.
  */
 #define SQL_MAGIC_OPEN     0xa029a697	/* Database is open */
-#define SQL_MAGIC_CLOSED   0x9f3c2d33	/* Database is closed */
-#define SQL_MAGIC_SICK     0x4b771290	/* Error and awaiting close */
 #define SQL_MAGIC_BUSY     0xf03b7906	/* Database currently in use */
-#define SQL_MAGIC_ERROR    0xb5357930	/* An sql_MISUSE error occurred */
-#define SQL_MAGIC_ZOMBIE   0x64cffc7f	/* Close with last statement close */
 
 /**
  * SQL type definition. Now it is an alias to type, but in
@@ -2925,7 +2915,6 @@ unsigned sqlStrlen30(const char *);
 #define sqlStrNICmp sql_strnicmp
 
 void sqlMallocInit(void);
-void sqlMallocEnd(void);
 void *sqlMalloc(u64);
 void *sqlMallocZero(u64);
 void *sqlDbMallocZero(sql *, u64);
@@ -2939,15 +2928,12 @@ void *sqlDbRealloc(sql *, void *, u64);
 void sqlDbFree(sql *, void *);
 int sqlMallocSize(void *);
 int sqlDbMallocSize(void *);
-void *sqlScratchMalloc(int);
-void sqlScratchFree(void *);
 void *sqlPageMalloc(int);
 void sqlPageFree(void *);
 void sqlMemSetDefault(void);
 #ifndef SQL_UNTESTABLE
 void sqlBenignMallocHooks(void (*)(void), void (*)(void));
 #endif
-int sqlHeapNearlyFull(void);
 
 /*
  * On systems with ample stack space and that support alloca(), make
@@ -2967,7 +2953,6 @@ int sqlHeapNearlyFull(void);
 #define sqlStackFree(D,P)       sqlDbFree(D,P)
 #endif
 
-sql_int64 sqlStatusValue(int);
 void sqlStatusUp(int, int);
 void sqlStatusDown(int, int);
 void sqlStatusHighwater(int, int);
@@ -3003,7 +2988,6 @@ void sqlTreeViewSelect(TreeView *, const Select *, u8);
 void sqlTreeViewWith(TreeView *, const With *);
 #endif
 
-void sqlSetString(char **, sql *, const char *);
 void sqlDequote(char *);
 
 /**
diff --git a/src/box/sql/status.c b/src/box/sql/status.c
index d6de484..9e56836 100644
--- a/src/box/sql/status.c
+++ b/src/box/sql/status.c
@@ -62,18 +62,6 @@ static SQL_WSD struct sqlStatType {
 #define wsdStat sqlStat
 
 /*
- * Return the current value of a status parameter.
- */
-sql_int64
-sqlStatusValue(int op)
-{
-	wsdStatInit;
-	assert(op >= 0 && op < ArraySize(wsdStat.nowValue));
-
-	return wsdStat.nowValue[op];
-}
-
-/*
  * Add N to the value of a status record.
  *
  * The StatusUp() routine can accept positive or negative values for N.
@@ -125,140 +113,3 @@ sqlStatusHighwater(int op, int X)
 		wsdStat.mxValue[op] = newValue;
 	}
 }
-
-/*
- * Query status information for a single database connection
- */
-int
-sql_db_status(sql * db,	/* The database connection whose status is desired */
-		  int op,	/* Status verb */
-		  int *pCurrent,	/* Write current value here */
-		  int *pHighwater,	/* Write high-water mark here */
-		  int resetFlag	/* Reset high-water mark if true */
-    )
-{
-	int rc = 0;	/* Return code */
-	switch (op) {
-	case SQL_DBSTATUS_LOOKASIDE_USED:{
-			*pCurrent = db->lookaside.nOut;
-			*pHighwater = db->lookaside.mxOut;
-			if (resetFlag) {
-				db->lookaside.mxOut = db->lookaside.nOut;
-			}
-			break;
-		}
-
-	case SQL_DBSTATUS_LOOKASIDE_HIT:
-	case SQL_DBSTATUS_LOOKASIDE_MISS_SIZE:
-	case SQL_DBSTATUS_LOOKASIDE_MISS_FULL:{
-			testcase(op == SQL_DBSTATUS_LOOKASIDE_HIT);
-			testcase(op == SQL_DBSTATUS_LOOKASIDE_MISS_SIZE);
-			testcase(op == SQL_DBSTATUS_LOOKASIDE_MISS_FULL);
-			assert((op - SQL_DBSTATUS_LOOKASIDE_HIT) >= 0);
-			assert((op - SQL_DBSTATUS_LOOKASIDE_HIT) < 3);
-			*pCurrent = 0;
-			*pHighwater =
-			    db->lookaside.anStat[op -
-						 SQL_DBSTATUS_LOOKASIDE_HIT];
-			if (resetFlag) {
-				db->lookaside.anStat[op -
-						     SQL_DBSTATUS_LOOKASIDE_HIT]
-				    = 0;
-			}
-			break;
-		}
-
-		/*
-		 * Return an approximation for the amount of memory currently used
-		 * by all pagers associated with the given database connection.  The
-		 * highwater mark is meaningless and is returned as zero.
-		 */
-	case SQL_DBSTATUS_CACHE_USED_SHARED:
-	case SQL_DBSTATUS_CACHE_USED:{
-			int totalUsed = 0;
-			*pCurrent = totalUsed;
-			*pHighwater = 0;
-			break;
-		}
-
-		/*
-		 * *pCurrent gets an accurate estimate of the amount of memory used
-		 * to store the schema for database. *pHighwater is set to zero.
-		 */
-	case SQL_DBSTATUS_SCHEMA_USED:{
-			int nByte = 0;	/* Used to accumulate return value */
-
-			*pHighwater = 0;
-			*pCurrent = nByte;
-			break;
-		}
-
-		/*
-		 * *pCurrent gets an accurate estimate of the amount of memory used
-		 * to store all prepared statements.
-		 * *pHighwater is set to zero.
-		 */
-	case SQL_DBSTATUS_STMT_USED:{
-			struct Vdbe *pVdbe;	/* Used to iterate through VMs */
-			int nByte = 0;	/* Used to accumulate return value */
-
-			db->pnBytesFreed = &nByte;
-			for (pVdbe = db->pVdbe; pVdbe; pVdbe = pVdbe->pNext) {
-				sqlVdbeClearObject(db, pVdbe);
-				sqlDbFree(db, pVdbe);
-			}
-			db->pnBytesFreed = 0;
-
-			*pHighwater = 0;	/* IMP: R-64479-57858
-			*/
-			*pCurrent = nByte;
-
-			break;
-		}
-
-		/*
-		 * Set *pCurrent to the total cache hits or misses encountered by all
-		 * pagers the database handle is connected to. *pHighwater is always set
-		 * to zero.
-		 */
-	case SQL_DBSTATUS_CACHE_HIT:
-	case SQL_DBSTATUS_CACHE_MISS:
-	case SQL_DBSTATUS_CACHE_WRITE:{
-			int nRet = 0;
-			assert(SQL_DBSTATUS_CACHE_MISS ==
-			       SQL_DBSTATUS_CACHE_HIT + 1);
-			assert(SQL_DBSTATUS_CACHE_WRITE ==
-			       SQL_DBSTATUS_CACHE_HIT + 2);
-
-			*pHighwater = 0;	/* IMP: R-42420-56072
-			*/
-			/* IMP: R-54100-20147 */
-			/* IMP: R-29431-39229 */
-			*pCurrent = nRet;
-			break;
-		}
-
-		/* Set *pCurrent to non-zero if there are unresolved deferred foreign
-		 * key constraints.  Set *pCurrent to zero if all foreign key constraints
-		 * have been satisfied.  The *pHighwater is always set to zero.
-		 */
-	case SQL_DBSTATUS_DEFERRED_FKS:{
-			*pHighwater = 0;	/* IMP: R-11967-56545
-			*/
-			const struct txn *ptxn = in_txn();
-
-			if (!ptxn || !ptxn->psql_txn) {
-				*pCurrent = 0;
-				break;
-			}
-			const struct sql_txn *psql_txn = ptxn->psql_txn;
-			*pCurrent = psql_txn->fk_deferred_count > 0;
-			break;
-		}
-
-	default:{
-			rc = -1;
-		}
-	}
-	return rc;
-}
diff --git a/src/box/sql/tokenize.c b/src/box/sql/tokenize.c
index ea364de..32e4fd6 100644
--- a/src/box/sql/tokenize.c
+++ b/src/box/sql/tokenize.c
@@ -514,11 +514,6 @@ sqlRunParser(Parse * pParse, const char *zSql)
 		}
 	}
 	pParse->zTail = &zSql[i];
-#ifdef YYTRACKMAXSTACKDEPTH
-	sqlStatusHighwater(SQL_STATUS_PARSER_STACK,
-			       sqlParserStackPeak(pEngine)
-	    );
-#endif				/* YYDEBUG */
 	sqlParserFree(pEngine, sql_free);
 	if (db->mallocFailed)
 		pParse->is_aborted = true;
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 4204637..1534026 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -226,10 +226,6 @@ allocateCursor(
 	 *     different sized allocations. Memory cells provide growable
 	 *     allocations.
 	 *
-	 *   * When using ENABLE_MEMORY_MANAGEMENT, memory cell buffers can
-	 *     be freed lazily via the sql_release_memory() API. This
-	 *     minimizes the number of malloc calls made by the system.
-	 *
 	 * The memory cell for cursor 0 is aMem[0]. The rest are allocated from
 	 * the top of the register space.  Cursor 1 is at Mem[p->nMem-1].
 	 * Cursor 2 is at Mem[p->nMem-2]. And so forth.
diff --git a/src/box/sql/vdbesort.c b/src/box/sql/vdbesort.c
index 7caf13b..0af9d0c 100644
--- a/src/box/sql/vdbesort.c
+++ b/src/box/sql/vdbesort.c
@@ -1778,9 +1778,6 @@ sqlVdbeSorterWrite(const VdbeCursor * pCsr,	/* Sorter cursor */
 	 *
 	 *   * The total memory allocated for the in-memory list is greater
 	 *     than (page-size * cache-size), or
-	 *
-	 *   * The total memory allocated for the in-memory list is greater
-	 *     than (page-size * 10) and sqlHeapNearlyFull() returns true.
 	 */
 	nReq = pVal->n + sizeof(SorterRecord);
 	nPMA = pVal->n + sqlVarintLen(pVal->n);
@@ -1789,10 +1786,7 @@ sqlVdbeSorterWrite(const VdbeCursor * pCsr,	/* Sorter cursor */
 			bFlush = pSorter->iMemory
 			    && (pSorter->iMemory + nReq) > pSorter->mxPmaSize;
 		} else {
-			bFlush = ((pSorter->list.szPMA > pSorter->mxPmaSize)
-				  || (pSorter->list.szPMA > pSorter->mnPmaSize
-				      && sqlHeapNearlyFull())
-			    );
+			bFlush = ((pSorter->list.szPMA > pSorter->mxPmaSize));
 		}
 		if (bFlush) {
 			rc = vdbeSorterFlushPMA(pSorter);
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 27/28] sql: make function return void instead of int
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (25 preceding siblings ...)
  2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 26/28] sql: cleanup of legacy memory management system imeevma
@ 2019-06-10 13:57 ` imeevma
  2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 28/28] sql: remove function sqlApiExit() imeevma
                   ` (4 subsequent siblings)
  31 siblings, 0 replies; 56+ messages in thread
From: imeevma @ 2019-06-10 13:57 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

Function tarantoolsqlEphemeralDrop() always returns 0. Let's make
it return void to make code clean.
---
 src/box/sql.c              | 4 ++--
 src/box/sql/tarantoolInt.h | 4 +++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/box/sql.c b/src/box/sql.c
index d8c7d91..a0350da 100644
--- a/src/box/sql.c
+++ b/src/box/sql.c
@@ -386,13 +386,13 @@ int tarantoolsqlEphemeralInsert(struct space *space, const char *tuple,
 }
 
 /* Simply delete ephemeral space by calling space_delete(). */
-int tarantoolsqlEphemeralDrop(BtCursor *pCur)
+void
+tarantoolsqlEphemeralDrop(BtCursor *pCur)
 {
 	assert(pCur);
 	assert(pCur->curFlags & BTCF_TEphemCursor);
 	space_delete(pCur->space);
 	pCur->space = NULL;
-	return 0;
 }
 
 static inline int
diff --git a/src/box/sql/tarantoolInt.h b/src/box/sql/tarantoolInt.h
index e166045..1ded6c7 100644
--- a/src/box/sql/tarantoolInt.h
+++ b/src/box/sql/tarantoolInt.h
@@ -89,7 +89,9 @@ int tarantoolsqlEphemeralInsert(struct space *space, const char *tuple,
 int tarantoolsqlEphemeralDelete(BtCursor * pCur);
 int64_t
 tarantoolsqlEphemeralCount(struct BtCursor *pCur);
-int tarantoolsqlEphemeralDrop(BtCursor * pCur);
+void
+tarantoolsqlEphemeralDrop(BtCursor * pCur);
+
 int tarantoolsqlEphemeralClearTable(BtCursor * pCur);
 
 /**
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] [PATCH v1 28/28] sql: remove function sqlApiExit()
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (26 preceding siblings ...)
  2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 27/28] sql: make function return void instead of int imeevma
@ 2019-06-10 13:57 ` imeevma
  2019-06-11 10:00 ` [tarantool-patches] Re: [PATCH v1 00/28] sql: Remove SQL error system Imeev Mergen
                   ` (3 subsequent siblings)
  31 siblings, 0 replies; 56+ messages in thread
From: imeevma @ 2019-06-10 13:57 UTC (permalink / raw)
  To: v.shpilevoy; +Cc: tarantool-patches

This function is useless in Tarantool and should be removed.
---
 src/box/sql/main.c    |  8 ++------
 src/box/sql/malloc.c  | 19 -------------------
 src/box/sql/sqlInt.h  |  1 -
 src/box/sql/vdbeapi.c | 34 +++++++++++-----------------------
 4 files changed, 13 insertions(+), 49 deletions(-)

diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index 145964f..d280d8d 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -320,7 +320,6 @@ sql_create_function_v2(sql * db,
 			   void (*xFinal) (sql_context *),
 			   void (*xDestroy) (void *))
 {
-	int rc = -1;
 	FuncDestructor *pArg = 0;
 
 	if (xDestroy) {
@@ -330,21 +329,18 @@ sql_create_function_v2(sql * db,
 							   (FuncDestructor));
 		if (!pArg) {
 			xDestroy(p);
-			goto out;
+			return -1;
 		}
 		pArg->xDestroy = xDestroy;
 		pArg->pUserData = p;
 	}
-	rc = sqlCreateFunc(db, zFunc, type, nArg, flags, p, xSFunc, xStep,
+	int rc = sqlCreateFunc(db, zFunc, type, nArg, flags, p, xSFunc, xStep,
 			       xFinal, pArg);
 	if (pArg && pArg->nRef == 0) {
 		assert(rc != 0);
 		xDestroy(p);
 		sqlDbFree(db, pArg);
 	}
-
- out:
-	rc = sqlApiExit(db, rc);
 	return rc;
 }
 
diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index c3fc50b..a31f915 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -526,22 +526,3 @@ sqlOomClear(sql * db)
 		db->lookaside.bDisable--;
 	}
 }
-
-/*
- * This function must be called before exiting any API function (i.e.
- * returning control to the user) that has called sql_malloc or
- * sql_realloc.
- *
- * The returned value is normally a copy of the second argument to this
- * function.
- */
-int
-sqlApiExit(sql * db, int rc)
-{
-	assert(db != 0);
-	if (db->mallocFailed) {
-		sqlOomClear(db);
-		return -1;
-	}
-	return rc;
-}
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 27e57cc..a309290 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -4595,7 +4595,6 @@ int sqlCreateFunc(sql *, const char *, enum field_type,
 		      FuncDestructor * pDestructor);
 void sqlOomFault(sql *);
 void sqlOomClear(sql *);
-int sqlApiExit(sql * db, int);
 
 void sqlStrAccumInit(StrAccum *, sql *, char *, int, int);
 void sqlStrAccumAppend(StrAccum *, const char *, int);
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 03f5069..03f9e84 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -82,21 +82,13 @@ invokeProfileCallback(sql * db, Vdbe * p)
 int
 sql_finalize(sql_stmt * pStmt)
 {
-	int rc;
-	if (pStmt == 0) {
-		/* IMPLEMENTATION-OF: R-57228-12904 Invoking sql_finalize() on a NULL
-		 * pointer is a harmless no-op.
-		 */
-		rc = 0;
-	} else {
-		Vdbe *v = (Vdbe *) pStmt;
-		sql *db = v->db;
-		assert(db != NULL);
-		checkProfileCallback(db, v);
-		rc = sqlVdbeFinalize(v);
-		rc = sqlApiExit(db, rc);
-	}
-	return rc;
+	if (pStmt == NULL)
+		return 0;
+	Vdbe *v = (Vdbe *) pStmt;
+	sql *db = v->db;
+	assert(db != NULL);
+	checkProfileCallback(db, v);
+	return sqlVdbeFinalize(v);
 }
 
 int
@@ -108,7 +100,7 @@ sql_reset(sql_stmt * pStmt)
 	checkProfileCallback(db, v);
 	int rc = sqlVdbeReset(v);
 	sqlVdbeRewind(v);
-	return sqlApiExit(db, rc);
+	return rc;
 }
 
 /*
@@ -1128,18 +1120,14 @@ sql_bind_zeroblob(sql_stmt * pStmt, int i, int n)
 int
 sql_bind_zeroblob64(sql_stmt * pStmt, int i, sql_uint64 n)
 {
-	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
 	if (n > (u64) p->db->aLimit[SQL_LIMIT_LENGTH]) {
 		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob is too "\
 			 "big");
-		rc = -1;
-	} else {
-		assert((n & 0x7FFFFFFF) == n);
-		rc = sql_bind_zeroblob(pStmt, i, n);
+		return -1;
 	}
-	rc = sqlApiExit(p->db, rc);
-	return rc;
+	assert((n & 0x7FFFFFFF) == n);
+	return sql_bind_zeroblob(pStmt, i, n);
 }
 
 /*
-- 
2.7.4

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 00/28] sql: Remove SQL error system
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (27 preceding siblings ...)
  2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 28/28] sql: remove function sqlApiExit() imeevma
@ 2019-06-11 10:00 ` Imeev Mergen
  2019-06-13 22:24 ` Vladislav Shpilevoy
                   ` (2 subsequent siblings)
  31 siblings, 0 replies; 56+ messages in thread
From: Imeev Mergen @ 2019-06-11 10:00 UTC (permalink / raw)
  To: tarantool-patches

Sorry, I did not include the links in the original letter:
https://github.com/tarantool/tarantool/issues/4074
https://github.com/tarantool/tarantool/tree/imeevma/gh-4074-follow-ups

On 6/10/19 4:56 PM, imeevma@tarantool.org wrote:
> This patch-set removes unused and unnecessary code of SQL error
> system.
>
> Mergen Imeev (26):
>    sql: remove field zErrMsg from struct Vdbe
>    sql: remove field pErr from struct sql
>    sql: remove field errCode from struct sql
>    sql: remove sqlError() and remove sqlErrorWithMsg()
>    sql: remove unused functions of SQL error system
>    sql: disable lookaside system
>    sql: remove SQL_OK error/status code
>    sql: remove SQL_PERM, SQL_WARNING, SQL_ABORT errcodes
>    sql: remove SQL_CANTOPEN errcode
>    sql: remove SQL_NOTFOUND error/status code
>    sql: remove SQL_LOCKED errcode
>    sql: remove SQL_FULL errcode
>    sql: remove SQL_MISUSE errcode
>    sql: remove SQL_RANGE errcode
>    sql: remove SQL_SCHEMA errcode
>    sql: remove SQL_TOOBIG errcode
>    sql: remove SQL_BUSY errcode
>    sql: remove SQL_CONSTRAINT errcode
>    sql: remove SQL_ERROR errcode
>    sql: remove SQL_NOMEM errcode
>    sql: remove SQL_IOERR errcode
>    sql: remove SQL_TARANTOOL_ERROR errcode
>    sql: remove field errMask from struct sql
>    sql: replace rc by is_aborted in struct VDBE
>    sql: remove sql_log()
>    sql: remove function sqlApiExit()
>
> Nikita Pettik (2):
>    sql: cleanup of legacy memory management system
>    sql: make function return void instead of int
>
>   src/box/bind.c                |  37 +---
>   src/box/ck_constraint.c       |   4 +-
>   src/box/execute.c             |   6 +-
>   src/box/lua/lua_sql.c         |   2 +-
>   src/box/sql.c                 | 104 ++++------
>   src/box/sql/analyze.c         |   2 +-
>   src/box/sql/build.c           |   6 +-
>   src/box/sql/cursor.c          |   4 +-
>   src/box/sql/date.c            |  14 +-
>   src/box/sql/expr.c            |   7 +-
>   src/box/sql/fault.c           |   4 +-
>   src/box/sql/fk_constraint.c   |   8 +-
>   src/box/sql/func.c            |  16 +-
>   src/box/sql/global.c          |   3 -
>   src/box/sql/insert.c          |   9 +-
>   src/box/sql/legacy.c          |  21 +-
>   src/box/sql/main.c            | 266 ++++---------------------
>   src/box/sql/malloc.c          | 445 +-----------------------------------------
>   src/box/sql/os.c              |  14 +-
>   src/box/sql/os_unix.c         | 281 ++++++++------------------
>   src/box/sql/prepare.c         |  73 ++-----
>   src/box/sql/printf.c          |  36 +---
>   src/box/sql/resolve.c         |   3 +-
>   src/box/sql/select.c          |  61 +++---
>   src/box/sql/sqlInt.h          | 173 +---------------
>   src/box/sql/status.c          | 182 -----------------
>   src/box/sql/tarantoolInt.h    |  11 +-
>   src/box/sql/tokenize.c        |   5 -
>   src/box/sql/trigger.c         |   2 +-
>   src/box/sql/util.c            | 162 ---------------
>   src/box/sql/vdbe.c            | 111 ++++-------
>   src/box/sql/vdbeInt.h         |  13 +-
>   src/box/sql/vdbeapi.c         | 357 +++++++++------------------------
>   src/box/sql/vdbeaux.c         | 217 ++++++--------------
>   src/box/sql/vdbemem.c         | 120 ++++++------
>   src/box/sql/vdbesort.c        | 274 ++++++++++++--------------
>   src/box/sql/where.c           | 108 +++++-----
>   src/box/sql/whereexpr.c       |   3 +-
>   test/sql/bind.result          |   8 +
>   test/sql/bind.test.lua        |   3 +
>   test/sql/func-recreate.result |   3 +-
>   41 files changed, 726 insertions(+), 2452 deletions(-)
>

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 00/28] sql: Remove SQL error system
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (28 preceding siblings ...)
  2019-06-11 10:00 ` [tarantool-patches] Re: [PATCH v1 00/28] sql: Remove SQL error system Imeev Mergen
@ 2019-06-13 22:24 ` Vladislav Shpilevoy
  2019-06-15 10:08   ` Mergen Imeev
  2019-06-19 19:11 ` Vladislav Shpilevoy
  2019-06-20 16:08 ` Kirill Yukhin
  31 siblings, 1 reply; 56+ messages in thread
From: Vladislav Shpilevoy @ 2019-06-13 22:24 UTC (permalink / raw)
  To: tarantool-patches, imeevma

Hi! Thanks for the patchset!

Please, consider my review comments and fixes for some of
the patches in responses to them.

Also I've pushed on top of the branch a new commit removing
a couple of another error codes. It is not for squash - just
a new commit.

On 10/06/2019 16:56, imeevma@tarantool.org wrote:
> This patch-set removes unused and unnecessary code of SQL error
> system.
> 
> Mergen Imeev (26):
>   sql: remove field zErrMsg from struct Vdbe
>   sql: remove field pErr from struct sql
>   sql: remove field errCode from struct sql
>   sql: remove sqlError() and remove sqlErrorWithMsg()
>   sql: remove unused functions of SQL error system
>   sql: disable lookaside system
>   sql: remove SQL_OK error/status code
>   sql: remove SQL_PERM, SQL_WARNING, SQL_ABORT errcodes
>   sql: remove SQL_CANTOPEN errcode
>   sql: remove SQL_NOTFOUND error/status code
>   sql: remove SQL_LOCKED errcode
>   sql: remove SQL_FULL errcode
>   sql: remove SQL_MISUSE errcode
>   sql: remove SQL_RANGE errcode
>   sql: remove SQL_SCHEMA errcode
>   sql: remove SQL_TOOBIG errcode
>   sql: remove SQL_BUSY errcode
>   sql: remove SQL_CONSTRAINT errcode
>   sql: remove SQL_ERROR errcode
>   sql: remove SQL_NOMEM errcode
>   sql: remove SQL_IOERR errcode
>   sql: remove SQL_TARANTOOL_ERROR errcode
>   sql: remove field errMask from struct sql
>   sql: replace rc by is_aborted in struct VDBE
>   sql: remove sql_log()
>   sql: remove function sqlApiExit()
> 
> Nikita Pettik (2):
>   sql: cleanup of legacy memory management system
>   sql: make function return void instead of int
> 
>  src/box/bind.c                |  37 +---
>  src/box/ck_constraint.c       |   4 +-
>  src/box/execute.c             |   6 +-
>  src/box/lua/lua_sql.c         |   2 +-
>  src/box/sql.c                 | 104 ++++------
>  src/box/sql/analyze.c         |   2 +-
>  src/box/sql/build.c           |   6 +-
>  src/box/sql/cursor.c          |   4 +-
>  src/box/sql/date.c            |  14 +-
>  src/box/sql/expr.c            |   7 +-
>  src/box/sql/fault.c           |   4 +-
>  src/box/sql/fk_constraint.c   |   8 +-
>  src/box/sql/func.c            |  16 +-
>  src/box/sql/global.c          |   3 -
>  src/box/sql/insert.c          |   9 +-
>  src/box/sql/legacy.c          |  21 +-
>  src/box/sql/main.c            | 266 ++++---------------------
>  src/box/sql/malloc.c          | 445 +-----------------------------------------
>  src/box/sql/os.c              |  14 +-
>  src/box/sql/os_unix.c         | 281 ++++++++------------------
>  src/box/sql/prepare.c         |  73 ++-----
>  src/box/sql/printf.c          |  36 +---
>  src/box/sql/resolve.c         |   3 +-
>  src/box/sql/select.c          |  61 +++---
>  src/box/sql/sqlInt.h          | 173 +---------------
>  src/box/sql/status.c          | 182 -----------------
>  src/box/sql/tarantoolInt.h    |  11 +-
>  src/box/sql/tokenize.c        |   5 -
>  src/box/sql/trigger.c         |   2 +-
>  src/box/sql/util.c            | 162 ---------------
>  src/box/sql/vdbe.c            | 111 ++++-------
>  src/box/sql/vdbeInt.h         |  13 +-
>  src/box/sql/vdbeapi.c         | 357 +++++++++------------------------
>  src/box/sql/vdbeaux.c         | 217 ++++++--------------
>  src/box/sql/vdbemem.c         | 120 ++++++------
>  src/box/sql/vdbesort.c        | 274 ++++++++++++--------------
>  src/box/sql/where.c           | 108 +++++-----
>  src/box/sql/whereexpr.c       |   3 +-
>  test/sql/bind.result          |   8 +
>  test/sql/bind.test.lua        |   3 +
>  test/sql/func-recreate.result |   3 +-
>  41 files changed, 726 insertions(+), 2452 deletions(-)
> 

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 26/28] sql: cleanup of legacy memory management system
  2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 26/28] sql: cleanup of legacy memory management system imeevma
@ 2019-06-13 22:24   ` Vladislav Shpilevoy
  2019-06-15 10:04     ` Mergen Imeev
  0 siblings, 1 reply; 56+ messages in thread
From: Vladislav Shpilevoy @ 2019-06-13 22:24 UTC (permalink / raw)
  To: tarantool-patches, imeevma

Thanks for the patch!

Consider my review fixes below and on the branch
in a separate commit.

======================================================

diff --git a/src/box/sql/CMakeLists.txt b/src/box/sql/CMakeLists.txt
index b9dbe141a..91a371157 100644
--- a/src/box/sql/CMakeLists.txt
+++ b/src/box/sql/CMakeLists.txt
@@ -50,7 +50,6 @@ add_library(sql STATIC
     random.c
     resolve.c
     select.c
-    status.c
     tokenize.c
     treeview.c
     trigger.c
diff --git a/src/box/sql/date.c b/src/box/sql/date.c
index 547932b2c..2e2a71ad2 100644
--- a/src/box/sql/date.c
+++ b/src/box/sql/date.c
@@ -536,9 +536,6 @@ clearYMD_HMS_TZ(DateTime * p)
  * is available.  This routine returns 0 on success and
  * non-zero on any kind of error.
  *
- * If the sqlGlobalConfig.bLocaltimeFault variable is true then this
- * routine will always fail.
- *
  * EVIDENCE-OF: R-62172-00036 In this implementation, the standard C
  * library function localtime_r() is used to assist in the calculation of
  * local time.
@@ -550,18 +547,10 @@ osLocaltime(time_t * t, struct tm *pTm)
 #if !HAVE_LOCALTIME_R && !HAVE_LOCALTIME_S
 	struct tm *pX;
 	pX = localtime(t);
-#ifndef SQL_UNTESTABLE
-	if (sqlGlobalConfig.bLocaltimeFault)
-		pX = 0;
-#endif
 	if (pX)
 		*pTm = *pX;
 	rc = pX == 0;
 #else
-#ifndef SQL_UNTESTABLE
-	if (sqlGlobalConfig.bLocaltimeFault)
-		return 1;
-#endif
 #if HAVE_LOCALTIME_R
 	rc = localtime_r(t, pTm) == 0;
 #else
diff --git a/src/box/sql/global.c b/src/box/sql/global.c
index c3c7e945c..ac692be19 100644
--- a/src/box/sql/global.c
+++ b/src/box/sql/global.c
@@ -137,29 +137,6 @@ const unsigned char sqlCtypeMap[256] = {
 	0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40	/* f8..ff    ........ */
 };
 
-/* EVIDENCE-OF: R-02982-34736 In order to maintain full backwards
- * compatibility for legacy applications, the URI filename capability is
- * disabled by default.
- *
- * EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled
- * using the SQL_USE_URI=1 or SQL_USE_URI=0 compile-time options.
- *
- * EVIDENCE-OF: R-43642-56306 By default, URI handling is globally
- * disabled. The default value may be changed by compiling with the
- * SQL_USE_URI symbol defined.
- */
-#ifndef SQL_USE_URI
-#define  SQL_USE_URI 0
-#endif
-
-/* EVIDENCE-OF: R-38720-18127 The default setting is determined by the
- * SQL_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if
- * that compile-time option is omitted.
- */
-#ifndef SQL_ALLOW_COVERING_INDEX_SCAN
-#define SQL_ALLOW_COVERING_INDEX_SCAN 1
-#endif
-
 /* The minimum PMA size is set to this value multiplied by the database
  * page size in bytes.
  */
@@ -172,35 +149,16 @@ const unsigned char sqlCtypeMap[256] = {
  * the sql library.
  */
 SQL_WSD struct sqlConfig sqlConfig = {
-	SQL_DEFAULT_MEMSTATUS,	/* bMemstat */
-	SQL_USE_URI,		/* bOpenUri */
-	SQL_ALLOW_COVERING_INDEX_SCAN,	/* bUseCis */
-	0x7ffffffe,		/* mxStrlen */
-	0,			/* neverCorrupt */
-	0,			/* nStmtSpill */
-	(void *)0,		/* pHeap */
-	0,			/* nHeap */
-	0, 0,			/* mnHeap, mxHeap */
 	SQL_DEFAULT_MMAP_SIZE,	/* szMmap */
 	SQL_MAX_MMAP_SIZE,	/* mxMmap */
-	(void *)0,		/* pScratch */
-	0,			/* szScratch */
-	0,			/* nScratch */
-	(void *)0,		/* pPage */
-	0,			/* szPage */
-	SQL_DEFAULT_PCACHE_INITSZ,	/* nPage */
-	0,			/* mxParserStack */
-	0,			/* sharedCacheEnabled */
 	SQL_SORTER_PMASZ,	/* szPma */
 	/* All the rest should always be initialized to zero */
 	0,			/* isInit */
 	0,			/* inProgress */
-	0,			/* isMallocInit */
 #ifdef SQL_VDBE_COVERAGE
 	0,			/* xVdbeBranch */
 	0,			/* pVbeBranchArg */
 #endif
-	0,			/* bLocaltimeFault */
 	0x7ffffffe		/* iOnceResetThreshold */
 };
 
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index 138eb5ac0..912c3bf3b 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -115,11 +115,6 @@ sql_initialize(void)
 	if (sqlGlobalConfig.isInit)
 		return 0;
 
-	if (!sqlGlobalConfig.isMallocInit)
-		sqlMallocInit();
-	if (rc == 0)
-		sqlGlobalConfig.isMallocInit = 1;
-
 	/* If rc is not 0 at this point, then the malloc
 	 * subsystem could not be initialized.
 	 */
diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index 85693cd0c..f19b7d027 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -61,23 +61,6 @@ sql_sized_malloc(int nByte)
 	return (void *)p;
 }
 
-/*
- * Like free() but works for allocations obtained from sql_sized_malloc()
- * or sql_sized_realloc().
- *
- * For this low-level routine, we already know that pPrior!=0 since
- * cases where pPrior==0 will have been intecepted and dealt with
- * by higher-level routines.
- */
-static void
-sql_sized_free(void *pPrior)
-{
-	sql_int64 *p = (sql_int64 *) pPrior;
-	assert(pPrior != 0);
-	p--;
-	free(p);
-}
-
 /*
  * Report the allocated size of a prior return from sql_sized_malloc()
  * or sql_sized_realloc().
@@ -120,66 +103,6 @@ sql_sized_realloc(void *pPrior, int nByte)
 	return (void *)p;
 }
 
-/*
- * An instance of the following object records the location of
- * each unused scratch buffer.
- */
-typedef struct ScratchFreeslot {
-	struct ScratchFreeslot *pNext;	/* Next unused scratch buffer */
-} ScratchFreeslot;
-
-/*
- * Initialize the memory allocation subsystem.
- */
-void
-sqlMallocInit(void)
-{
-	if (sqlGlobalConfig.pScratch && sqlGlobalConfig.szScratch >= 100
-	    && sqlGlobalConfig.nScratch > 0) {
-		int i, n, sz;
-		ScratchFreeslot *pSlot;
-		sz = ROUNDDOWN8(sqlGlobalConfig.szScratch);
-		sqlGlobalConfig.szScratch = sz;
-		pSlot = (ScratchFreeslot *) sqlGlobalConfig.pScratch;
-		n = sqlGlobalConfig.nScratch;
-		for (i = 0; i < n - 1; i++) {
-			pSlot->pNext = (ScratchFreeslot *) (sz + (char *)pSlot);
-			pSlot = pSlot->pNext;
-		}
-		pSlot->pNext = 0;
-	} else {
-		sqlGlobalConfig.pScratch = 0;
-		sqlGlobalConfig.szScratch = 0;
-		sqlGlobalConfig.nScratch = 0;
-	}
-	if (sqlGlobalConfig.pPage == 0 || sqlGlobalConfig.szPage < 512
-	    || sqlGlobalConfig.nPage <= 0) {
-		sqlGlobalConfig.pPage = 0;
-		sqlGlobalConfig.szPage = 0;
-	}
-}
-
-/*
- * Do a memory allocation with statistics and alarms.  Assume the
- * lock is already held.
- */
-static int
-mallocWithAlarm(int n, void **pp)
-{
-	int nFull;
-	void *p;
-	nFull = ROUND8(n);
-	sqlStatusHighwater(SQL_STATUS_MALLOC_SIZE, n);
-	p = sql_sized_malloc(nFull);
-	if (p) {
-		nFull = sqlMallocSize(p);
-		sqlStatusUp(SQL_STATUS_MEMORY_USED, nFull);
-		sqlStatusUp(SQL_STATUS_MALLOC_COUNT, 1);
-	}
-	*pp = p;
-	return nFull;
-}
-
 /*
  * Allocate memory.  This routine is like sql_malloc() except that it
  * assumes the memory subsystem has already been initialized.
@@ -196,8 +119,6 @@ sqlMalloc(u64 n)
 		 * this amount.  The only way to reach the limit is with sql_malloc()
 		 */
 		p = 0;
-	} else if (sqlGlobalConfig.bMemstat) {
-		mallocWithAlarm((int)n, &p);
 	} else {
 		p = sql_sized_malloc((int)n);
 	}
@@ -238,25 +159,11 @@ sqlMallocSize(void *p)
 void
 sql_free(void *p)
 {
-	if (p == 0)
-		return;		/* IMP: R-49053-54554 */
-	if (sqlGlobalConfig.bMemstat) {
-		sqlStatusDown(SQL_STATUS_MEMORY_USED,
-				  sqlMallocSize(p));
-		sqlStatusDown(SQL_STATUS_MALLOC_COUNT, 1);
-		sql_sized_free(p);
-	} else
-		sql_sized_free(p);
-}
-
-/*
- * Add the size of memory allocation "p" to the count in
- * *db->pnBytesFreed.
- */
-static SQL_NOINLINE void
-measureAllocationSize(sql * db, void *p)
-{
-	*db->pnBytesFreed += sqlMallocSize(p);
+	if (p == NULL)
+		return;
+	sql_int64 *raw_p = (sql_int64 *) p;
+	raw_p--;
+	free(raw_p);
 }
 
 /*
@@ -266,14 +173,7 @@ measureAllocationSize(sql * db, void *p)
 void
 sqlDbFree(sql * db, void *p)
 {
-	if (p == 0)
-		return;
-	if (db) {
-		if (db->pnBytesFreed) {
-			measureAllocationSize(db, p);
-			return;
-		}
-	}
+	(void) db;
 	sql_free(p);
 }
 
@@ -298,18 +198,10 @@ sqlRealloc(void *pOld, u64 nBytes)
 	}
 	nOld = sqlMallocSize(pOld);
 	nNew = ROUND8((int)nBytes);
-	if (nOld == nNew) {
+	if (nOld == nNew)
 		pNew = pOld;
-	} else if (sqlGlobalConfig.bMemstat) {
-		sqlStatusHighwater(SQL_STATUS_MALLOC_SIZE, (int)nBytes);
+	else
 		pNew = sql_sized_realloc(pOld, nNew);
-		if (pNew) {
-			nNew = sqlMallocSize(pNew);
-			sqlStatusUp(SQL_STATUS_MEMORY_USED, nNew - nOld);
-		}
-	} else {
-		pNew = sql_sized_realloc(pOld, nNew);
-	}
 	assert(EIGHT_BYTE_ALIGNMENT(pNew));	/* IMP: R-11148-40995 */
 	return pNew;
 }
@@ -382,7 +274,7 @@ sqlDbMallocRaw(sql * db, u64 n)
 void *
 sqlDbMallocRawNN(sql * db, u64 n)
 {
-	assert(db != NULL && db->pnBytesFreed == NULL);
+	assert(db != NULL);
 	if (db->mallocFailed)
 		return NULL;
 	void *p = sqlMalloc(n);
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index fd0241440..21dd69b29 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -176,15 +176,6 @@
 #define SQL_POWERSAFE_OVERWRITE 1
 #endif
 
-/*
- * EVIDENCE-OF: R-25715-37072 Memory allocation statistics are enabled by
- * default unless sql is compiled with sql_DEFAULT_MEMSTATUS=0 in
- * which case memory allocation statistics are disabled by default.
- */
-#if !defined(SQL_DEFAULT_MEMSTATUS)
-#define SQL_DEFAULT_MEMSTATUS 1
-#endif
-
 #if defined(SQL_SYSTEM_MALLOC) \
   + defined(SQL_ZERO_MALLOC) > 1
 #error "Two or more of the following compile-time configuration options\
@@ -598,7 +589,6 @@ sql_column_datatype(sql_stmt *, int N);
 int
 sql_initialize(void);
 
-#define SQL_CONFIG_SCRATCH       6	/* void*, int sz, int N */
 #define SQL_CONFIG_MEMSTATUS     9	/* boolean */
 #define SQL_CONFIG_LOG          16	/* xFunc, void* */
 #define SQL_CONFIG_URI          17	/* int */
@@ -619,17 +609,6 @@ sql_initialize(void);
 
 #define SQL_DETERMINISTIC    0x800
 
-#define SQL_STATUS_MEMORY_USED          0
-#define SQL_STATUS_PAGECACHE_USED       1
-#define SQL_STATUS_PAGECACHE_OVERFLOW   2
-#define SQL_STATUS_SCRATCH_USED         3
-#define SQL_STATUS_SCRATCH_OVERFLOW     4
-#define SQL_STATUS_MALLOC_SIZE          5
-#define SQL_STATUS_PARSER_STACK         6
-#define SQL_STATUS_PAGECACHE_SIZE       7
-#define SQL_STATUS_SCRATCH_SIZE         8
-#define SQL_STATUS_MALLOC_COUNT         9
-
 int
 sql_create_function_v2(sql * db,
 			   const char *zFunctionName,
@@ -677,7 +656,6 @@ sql_vfs_find(const char *zVfsName);
 #define SQL_TESTCTRL_RESERVE                 14
 #define SQL_TESTCTRL_OPTIMIZATIONS           15
 #define SQL_TESTCTRL_ISKEYWORD               16
-#define SQL_TESTCTRL_SCRATCHMALLOC           17
 #define SQL_TESTCTRL_LOCALTIME_FAULT         18
 #define SQL_TESTCTRL_EXPLAIN_STMT            19	/* NOT USED */
 #define SQL_TESTCTRL_ONCE_RESET_THRESHOLD    19
@@ -902,16 +880,6 @@ sql_bind_parameter_lindex(sql_stmt * pStmt, const char *zName,
 #define SQL_DEFAULT_COMPOUND_SELECT 30
 #endif
 
-/*
- * The default initial allocation for the pagecache when using separate
- * pagecaches for each database connection.  A positive number is the
- * number of pages.  A negative number N translations means that a buffer
- * of -1024*N bytes is allocated and used for as many pages as it will hold.
- */
-#ifndef SQL_DEFAULT_PCACHE_INITSZ
-#define SQL_DEFAULT_PCACHE_INITSZ 100
-#endif
-
 /*
  * GCC does not define the offsetof() macro so we'll have to do it
  * ourselves.
@@ -1319,7 +1287,6 @@ struct sql {
 	void (*xUpdateCallback) (void *, int, const char *, const char *,
 				 sql_int64);
 	Hash aFunc;		/* Hash table of connection functions */
-	int *pnBytesFreed;	/* If not NULL, increment this in DbFree() */
 };
 
 /*
@@ -2716,32 +2683,14 @@ struct StrAccum {
  * This structure also contains some state information.
  */
 struct sqlConfig {
-	int bMemstat;		/* True to enable memory status */
-	int bOpenUri;		/* True to interpret filenames as URIs */
-	int bUseCis;		/* Use covering indices for full-scans */
-	int mxStrlen;		/* Maximum string length */
-	int neverCorrupt;	/* Database is always well-formed */
-	int nStmtSpill;		/* Stmt-journal spill-to-disk threshold */
-	void *pHeap;		/* Heap storage space */
-	int nHeap;		/* Size of pHeap[] */
-	int mnReq, mxReq;	/* Min and max heap requests sizes */
 	sql_int64 szMmap;	/* mmap() space per open file */
 	sql_int64 mxMmap;	/* Maximum value for szMmap */
-	void *pScratch;		/* Scratch memory */
-	int szScratch;		/* Size of each scratch buffer */
-	int nScratch;		/* Number of scratch buffers */
-	void *pPage;		/* Page cache memory */
-	int szPage;		/* Size of each page in pPage[] */
-	int nPage;		/* Number of pages in pPage[] */
-	int mxParserStack;	/* maximum depth of the parser stack */
-	int sharedCacheEnabled;	/* true if shared-cache mode enabled */
 	u32 szPma;		/* Maximum Sorter PMA size */
 	/* The above might be initialized to non-zero.  The following need to always
 	 * initially be zero, however.
 	 */
 	int isInit;		/* True after initialization has finished */
 	int inProgress;		/* True while initialization in progress */
-	int isMallocInit;	/* True after malloc is initialized */
 #ifdef SQL_VDBE_COVERAGE
 	/* The following callback (if not NULL) is invoked on every VDBE branch
 	 * operation.  Set the callback using sql_TESTCTRL_VDBE_COVERAGE.
@@ -2749,7 +2698,6 @@ struct sqlConfig {
 	void (*xVdbeBranch) (void *, int iSrcLine, u8 eThis, u8 eMx);	/* Callback */
 	void *pVdbeBranchArg;	/* 1st argument */
 #endif
-	int bLocaltimeFault;	/* True to fail localtime() calls */
 	int iOnceResetThreshold;	/* When to reset OP_Once counters */
 };
 
@@ -2848,7 +2796,6 @@ int sqlStrICmp(const char *, const char *);
 unsigned sqlStrlen30(const char *);
 #define sqlStrNICmp sql_strnicmp
 
-void sqlMallocInit(void);
 void *sqlMalloc(u64);
 void *sqlMallocZero(u64);
 void *sqlDbMallocZero(sql *, u64);
@@ -2886,10 +2833,6 @@ void sqlBenignMallocHooks(void (*)(void), void (*)(void));
 #define sqlStackFree(D,P)       sqlDbFree(D,P)
 #endif
 
-void sqlStatusUp(int, int);
-void sqlStatusDown(int, int);
-void sqlStatusHighwater(int, int);
-
 int sqlIsNaN(double);
 
 /*
diff --git a/src/box/sql/status.c b/src/box/sql/status.c
deleted file mode 100644
index 9e56836c1..000000000
--- a/src/box/sql/status.c
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright 2010-2017, Tarantool AUTHORS, please see AUTHORS file.
- *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * 1. Redistributions of source code must retain the above
- *    copyright notice, this list of conditions and the
- *    following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above
- *    copyright notice, this list of conditions and the following
- *    disclaimer in the documentation and/or other materials
- *    provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- *
- * This module implements the sql_status() interface and related
- * functionality.
- */
-#include "sqlInt.h"
-#include "vdbeInt.h"
-/*
- * Variables in which to record status information.
- */
-#if SQL_PTRSIZE>4
-typedef sql_int64 sqlStatValueType;
-#else
-typedef u32 sqlStatValueType;
-#endif
-typedef struct sqlStatType sqlStatType;
-static SQL_WSD struct sqlStatType {
-	sqlStatValueType nowValue[10];	/* Current value */
-	sqlStatValueType mxValue[10];	/* Maximum value */
-} sqlStat = { {
-0,}, {
-0,}};
-
-
-/* The "wsdStat" macro will resolve to the status information
- * state vector. In the common case where writable static data is
- * supported, wsdStat can refer directly  to the "sqlStat" state
- * vector declared above.
- */
-#define wsdStatInit
-#define wsdStat sqlStat
-
-/*
- * Add N to the value of a status record.
- *
- * The StatusUp() routine can accept positive or negative values for N.
- * The value of N is added to the current status value and the high-water
- * mark is adjusted if necessary.
- *
- * The StatusDown() routine lowers the current value by N.  The highwater
- * mark is unchanged.  N must be non-negative for StatusDown().
- */
-void
-sqlStatusUp(int op, int N)
-{
-	wsdStatInit;
-	assert(op >= 0 && op < ArraySize(wsdStat.nowValue));
-
-	wsdStat.nowValue[op] += N;
-	if (wsdStat.nowValue[op] > wsdStat.mxValue[op]) {
-		wsdStat.mxValue[op] = wsdStat.nowValue[op];
-	}
-}
-
-void
-sqlStatusDown(int op, int N)
-{
-	wsdStatInit;
-	assert(N >= 0);
-
-	assert(op >= 0 && op < ArraySize(wsdStat.nowValue));
-	wsdStat.nowValue[op] -= N;
-}
-
-/*
- * Adjust the highwater mark if necessary.
- */
-void
-sqlStatusHighwater(int op, int X)
-{
-	sqlStatValueType newValue;
-	wsdStatInit;
-	assert(X >= 0);
-	newValue = (sqlStatValueType) X;
-	assert(op >= 0 && op < ArraySize(wsdStat.nowValue));
-
-	assert(op == SQL_STATUS_MALLOC_SIZE
-	       || op == SQL_STATUS_PAGECACHE_SIZE
-	       || op == SQL_STATUS_SCRATCH_SIZE
-	       || op == SQL_STATUS_PARSER_STACK);
-	if (newValue > wsdStat.mxValue[op]) {
-		wsdStat.mxValue[op] = newValue;
-	}
-}
diff --git a/src/box/sql/tokenize.c b/src/box/sql/tokenize.c
index 32e4fd6d2..9fa069d09 100644
--- a/src/box/sql/tokenize.c
+++ b/src/box/sql/tokenize.c
@@ -430,7 +430,7 @@ sql_token(const char *z, int *type, bool *is_reserved)
 static void
 parser_space_delete(struct sql *db, struct space *space)
 {
-	if (space == NULL || db == NULL || db->pnBytesFreed == 0)
+	if (space == NULL || db == NULL)
 		return;
 	assert(space->def->opts.is_ephemeral);
 	for (uint32_t i = 0; i < space->index_count; ++i)
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 677860350..64bd7c94b 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -695,17 +695,6 @@ freeEphemeralFunction(sql * db, FuncDef * pDef)
 
 static void vdbeFreeOpArray(sql *, Op *, int);
 
-/*
- * Delete a P4 value if necessary.
- */
-static SQL_NOINLINE void
-freeP4Mem(sql * db, Mem * p)
-{
-	if (p->szMalloc)
-		sqlDbFree(db, p->zMalloc);
-	sqlDbFree(db, p);
-}
-
 static SQL_NOINLINE void
 freeP4FuncCtx(sql * db, sql_context * p)
 {
@@ -736,14 +725,9 @@ freeP4(sql * db, int p4type, void *p4)
 			freeEphemeralFunction(db, (FuncDef *) p4);
 			break;
 		}
-	case P4_MEM:{
-			if (db->pnBytesFreed == 0) {
-				sqlValueFree((sql_value *) p4);
-			} else {
-				freeP4Mem(db, (Mem *) p4);
-			}
-			break;
-		}
+	case P4_MEM:
+		sqlValueFree((sql_value *) p4);
+		break;
 	}
 }
 
@@ -1336,13 +1320,6 @@ releaseMemArray(Mem * p, int N)
 	if (p && N) {
 		Mem *pEnd = &p[N];
 		sql *db = p->db;
-		if (db->pnBytesFreed) {
-			do {
-				if (p->szMalloc)
-					sqlDbFree(db, p->zMalloc);
-			} while ((++p) < pEnd);
-			return;
-		}
 		do {
 			assert((&p[1]) == pEnd || p[0].db == p[1].db);
 			assert(sqlVdbeCheckMemInvariants(p));
diff --git a/src/box/sql/vdbesort.c b/src/box/sql/vdbesort.c
index ac1c02ece..6fcaafb85 100644
--- a/src/box/sql/vdbesort.c
+++ b/src/box/sql/vdbesort.c
@@ -899,19 +899,11 @@ sqlVdbeSorterInit(sql * db,	/* Database connection (for malloc()) */
 			mxCache = MIN(mxCache, SQL_MAX_PMASZ);
 			pSorter->mxPmaSize =
 			    MAX(pSorter->mnPmaSize, (int)mxCache);
-
-			/* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
-			 * scratch memory using SQL_CONFIG_SCRATCH, sql avoids unnecessary
-			 * large heap allocations.
-			 */
-			if (sqlGlobalConfig.pScratch == 0) {
-				assert(pSorter->iMemory == 0);
-				pSorter->nMemory = pgsz;
-				pSorter->list.aMemory =
-				    (u8 *) sqlMalloc(pgsz);
-				if (!pSorter->list.aMemory)
-					rc = -1;
-			}
+			assert(pSorter->iMemory == 0);
+			pSorter->nMemory = pgsz;
+			pSorter->list.aMemory = (u8 *) sqlMalloc(pgsz);
+			if (!pSorter->list.aMemory)
+				rc = -1;
 		}
 
 		if (pCsr->key_def->part_count < 13

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 07/28] sql: remove SQL_OK error/status code
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 07/28] sql: remove SQL_OK error/status code imeevma
@ 2019-06-13 22:24   ` Vladislav Shpilevoy
  2019-06-15  9:52     ` Mergen Imeev
  0 siblings, 1 reply; 56+ messages in thread
From: Vladislav Shpilevoy @ 2019-06-13 22:24 UTC (permalink / raw)
  To: tarantool-patches, imeevma

Thanks for the patch!

Consider my review fixes below and on the branch
in a separate commit.

======================================================

diff --git a/src/box/ck_constraint.c b/src/box/ck_constraint.c
index c54c87069..1cde27022 100644
--- a/src/box/ck_constraint.c
+++ b/src/box/ck_constraint.c
@@ -172,9 +172,7 @@ ck_constraint_program_run(struct ck_constraint *ck_constraint,
 	 * Get VDBE execution state and reset VM to run it
 	 * next time.
 	 */
-	if (sql_reset(ck_constraint->stmt) != 0)
-		return -1;
-	return 0;
+	return sql_reset(ck_constraint->stmt);
 }
 
 void
diff --git a/src/box/sql/cursor.c b/src/box/sql/cursor.c
index f4b19db96..bb2dae898 100644
--- a/src/box/sql/cursor.c
+++ b/src/box/sql/cursor.c
@@ -93,12 +93,8 @@ sqlCursorIsValidNN(BtCursor *pCur)
  *
  * For sqlCursorPayload(), the caller must ensure that pCur is pointing
  * to a valid row in the table.
- *
- * Return 0 on success or an error code if anything goes
- * wrong.  An error is returned if "offset+amt" is larger than
- * the available payload.
  */
-int
+void
 sqlCursorPayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf)
 {
 	assert(pCur->eState == CURSOR_VALID);
@@ -110,7 +106,6 @@ sqlCursorPayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf)
 	pPayload = tarantoolsqlPayloadFetch(pCur, &sz);
 	assert((uptr) (offset + amt) <= sz);
 	memcpy(pBuf, pPayload + offset, amt);
-	return 0;
 }
 
 /* Move the cursor so that it points to an entry near the key
diff --git a/src/box/sql/cursor.h b/src/box/sql/cursor.h
index 237411613..2628f86a3 100644
--- a/src/box/sql/cursor.h
+++ b/src/box/sql/cursor.h
@@ -64,7 +64,8 @@ int sqlCursorMovetoUnpacked(BtCursor *, UnpackedRecord * pUnKey, int *pRes);
 
 int sqlCursorNext(BtCursor *, int *pRes);
 int sqlCursorPrevious(BtCursor *, int *pRes);
-int sqlCursorPayload(BtCursor *, u32 offset, u32 amt, void *);
+void
+sqlCursorPayload(BtCursor *, u32 offset, u32 amt, void *);
 
 /**
  * Release tuple, free iterator, invalidate cursor's state.
diff --git a/src/box/sql/legacy.c b/src/box/sql/legacy.c
index f7e069ad9..42fd3d1a4 100644
--- a/src/box/sql/legacy.c
+++ b/src/box/sql/legacy.c
@@ -68,16 +68,15 @@ sql_exec(sql * db,	/* The database on which the SQL executes */
 	if (zSql == 0)
 		zSql = "";
 
-	while (rc == 0 && zSql[0]) {
+	while (rc == 0 && zSql[0] != 0) {
 		int nCol;
 		char **azVals = 0;
 
 		pStmt = 0;
 		rc = sql_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
-		assert(rc == 0 || pStmt == 0);
-		if (rc != 0) {
+		assert(rc == 0 || pStmt == NULL);
+		if (rc != 0)
 			continue;
-		}
 		if (!pStmt) {
 			/* this happens for a comment or white-space */
 			zSql = zLeftover;
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index 65d8de529..c97c25ada 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -144,12 +144,8 @@ sql_initialize(void)
 		memset(&sqlBuiltinFunctions, 0,
 		       sizeof(sqlBuiltinFunctions));
 		sqlRegisterBuiltinFunctions();
-		if (rc == 0) {
-			rc = sqlOsInit();
-		}
-		if (rc == 0) {
-			sqlGlobalConfig.isInit = 1;
-		}
+		sql_os_init();
+		sqlGlobalConfig.isInit = 1;
 		sqlGlobalConfig.inProgress = 0;
 	}
 
@@ -160,17 +156,14 @@ sql_initialize(void)
 	 */
 #ifndef NDEBUG
 	/* This section of code's only "output" is via assert() statements. */
-	if (rc == 0) {
-		u64 x = (((u64) 1) << 63) - 1;
-		double y;
-		assert(sizeof(x) == 8);
-		assert(sizeof(x) == sizeof(y));
-		memcpy(&y, &x, 8);
-		assert(sqlIsNaN(y));
-	}
+	u64 x = (((u64) 1) << 63) - 1;
+	double y;
+	assert(sizeof(x) == 8);
+	assert(sizeof(x) == sizeof(y));
+	memcpy(&y, &x, 8);
+	assert(sqlIsNaN(y));
 #endif
-
-	return rc;
+	return 0;
 }
 
 void
@@ -348,27 +341,6 @@ sql_create_function_v2(sql * db,
 	return rc;
 }
 
-#ifndef SQL_OMIT_TRACE
-/* Register a trace callback using the version-2 interface.
- */
-int
-sql_trace_v2(sql * db,		/* Trace this connection */
-		 unsigned mTrace,	/* Mask of events to be traced */
-		 int (*xTrace) (unsigned, void *, void *, void *),	/* Callback to invoke */
-		 void *pArg)		/* Context */
-{
-	if (mTrace == 0)
-		xTrace = 0;
-	if (xTrace == 0)
-		mTrace = 0;
-	db->mTrace = mTrace;
-	db->xTrace = xTrace;
-	db->pTraceArg = pArg;
-	return 0;
-}
-
-#endif				/* SQL_OMIT_TRACE */
-
 /*
  * This function returns true if main-memory should be used instead of
  * a temporary file for transient pager files and statement journals.
diff --git a/src/box/sql/os.c b/src/box/sql/os.c
index 5804e9aa4..10b68c8d9 100644
--- a/src/box/sql/os.c
+++ b/src/box/sql/os.c
@@ -177,22 +177,6 @@ sqlOsCloseFree(sql_file * pFile)
 	sql_free(pFile);
 }
 
-/*
- * This function is a wrapper around the OS specific implementation of
- * sql_os_init(). The purpose of the wrapper is to provide the
- * ability to simulate a malloc failure, so that the handling of an
- * error in sql_os_init() by the upper layers can be tested.
- */
-int
-sqlOsInit(void)
-{
-	void *p = sql_malloc(10);
-	if (p == 0)
-		return SQL_NOMEM;
-	sql_free(p);
-	return sql_os_init();
-}
-
 /*
  * The list of all registered VFS implementations.
  */
diff --git a/src/box/sql/os.h b/src/box/sql/os.h
index 9122e9cb7..3c891f3ee 100644
--- a/src/box/sql/os.h
+++ b/src/box/sql/os.h
@@ -126,11 +126,6 @@
 #define SHARED_FIRST      (PENDING_BYTE+2)
 #define SHARED_SIZE       510
 
-/*
- * Wrapper around OS specific sql_os_init() function.
- */
-int sqlOsInit(void);
-
 /*
  * Functions for accessing sql_file methods
  */
diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index 41098df17..bf3ba0eb1 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -1827,9 +1827,8 @@ unixOpen(sql_vfs * pVfs,	/* The VFS for which this is the xOpen method */
 		/* If zName is NULL, the upper layer is requesting a temp file. */
 		assert(isDelete);
 		rc = unixGetTempname(pVfs->mxPathname, zTmpname);
-		if (rc != 0) {
+		if (rc != 0)
 			return rc;
-		}
 		zName = zTmpname;
 
 		/* Generated temporary filenames are always double-zero terminated
@@ -1911,9 +1910,8 @@ unixOpen(sql_vfs * pVfs,	/* The VFS for which this is the xOpen method */
 	rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
 
  open_finished:
-	if (rc != 0) {
+	if (rc != 0)
 		sql_free(p->pUnused);
-	}
 	return rc;
 }
 
@@ -1993,15 +1991,13 @@ int sql_current_time = 0;
  * epoch of noon in Greenwich on November 24, 4714 B.C according to the
  * proleptic Gregorian calendar.
  *
- * On success, return 0.  Return SQL_ERROR if the time and date
- * cannot be found.
+ * Always returns 0.
  */
 static int
 unixCurrentTimeInt64(sql_vfs * NotUsed, sql_int64 * piNow)
 {
 	static const sql_int64 unixEpoch =
 	    24405875 * (sql_int64) 8640000;
-	int rc = 0;
 	struct timeval sNow;
 	(void)gettimeofday(&sNow, 0);	/* Cannot fail given valid arguments */
 	*piNow =
@@ -2015,7 +2011,7 @@ unixCurrentTimeInt64(sql_vfs * NotUsed, sql_int64 * piNow)
 	}
 #endif
 	UNUSED_PARAMETER(NotUsed);
-	return rc;
+	return 0;
 }
 
 /*
@@ -2049,16 +2045,15 @@ unixCurrentTimeInt64(sql_vfs * NotUsed, sql_int64 * piNow)
  * Initialize the operating system interface.
  *
  * This routine registers all VFS implementations for unix-like operating
- * systems.  This routine, and the sql_os_end() routine that follows,
- * should be the only routines in this file that are visible from other
- * files.
+ * systems.  This routine should be the only one in this file that
+ * are visible from other files.
  *
  * This routine is called once during sql initialization and by a
  * single thread.  The memory allocation subsystem have not
  * necessarily been initialized when this routine \is called, and so they
  * should not be used.
  */
-int
+void
 sql_os_init(void)
 {
 	/*
@@ -2076,18 +2071,4 @@ sql_os_init(void)
 	/* Register all VFSes defined in the aVfs[] array. */
 	for (unsigned int i = 0; i < (sizeof(aVfs) / sizeof(sql_vfs)); i++)
 		sql_vfs_register(&aVfs[i], i == 0);
-	return 0;
-}
-
-/*
- * Shutdown the operating system interface.
- *
- * Some operating systems might need to do some cleanup in this routine,
- * to release dynamically allocated objects.  But not on unix.
- * This routine is a no-op for unix.
- */
-int
-sql_os_end(void)
-{
-	return 0;
 }
diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index 5b0be3e37..7a8a2d810 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -107,7 +107,7 @@ sqlPrepare(sql * db,	/* Database handle. */
 	if (sParse.is_aborted)
 		rc = SQL_TARANTOOL_ERROR;
 
-	if (rc == 0 && sParse.pVdbe && sParse.explain) {
+	if (rc == 0 && sParse.pVdbe != NULL && sParse.explain) {
 		static const char *const azColName[] = {
 			/*  0 */ "addr",
 			/*  1 */ "INTEGER",
@@ -159,7 +159,7 @@ sqlPrepare(sql * db,	/* Database handle. */
 		sqlVdbeSetSql(pVdbe, zSql, (int)(sParse.zTail - zSql),
 				  saveSqlFlag);
 	}
-	if (sParse.pVdbe && (rc != 0 || db->mallocFailed)) {
+	if (sParse.pVdbe != NULL && (rc != 0 || db->mallocFailed)) {
 		sqlVdbeFinalize(sParse.pVdbe);
 		assert(!(*ppStmt));
 	} else {
@@ -201,7 +201,7 @@ sqlLockAndPrepare(sql * db,		/* Database handle. */
 		rc = sqlPrepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt,
 				    pzTail);
 	}
-	assert(rc == 0 || *ppStmt == 0);
+	assert(rc == 0 || *ppStmt == NULL);
 	return rc;
 }
 
@@ -258,7 +258,7 @@ sql_prepare(sql * db,		/* Database handle. */
 {
 	int rc;
 	rc = sqlLockAndPrepare(db, zSql, nBytes, 0, 0, ppStmt, pzTail);
-	assert(rc == 0 || ppStmt == 0 || *ppStmt == 0);	/* VERIFY: F13021 */
+	assert(rc == 0 || ppStmt == NULL || *ppStmt == NULL);	/* VERIFY: F13021 */
 	return rc;
 }
 
@@ -272,7 +272,7 @@ sql_prepare_v2(sql * db,	/* Database handle. */
 {
 	int rc;
 	rc = sqlLockAndPrepare(db, zSql, nBytes, 1, 0, ppStmt, pzTail);
-	assert(rc == 0 || ppStmt == 0 || *ppStmt == 0);	/* VERIFY: F13021 */
+	assert(rc == 0 || ppStmt == NULL || *ppStmt == NULL);	/* VERIFY: F13021 */
 	return rc;
 }
 
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 316810a11..42a29ad4f 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -673,9 +673,6 @@ sql_column_datatype(sql_stmt *, int N);
 int
 sql_initialize(void);
 
-int
-sql_os_end(void);
-
 #define SQL_CONFIG_SCRATCH       6	/* void*, int sz, int N */
 #define SQL_CONFIG_MEMSTATUS     9	/* boolean */
 #define SQL_CONFIG_LOG          16	/* xFunc, void* */
@@ -810,7 +807,7 @@ struct sql_io_methods {
 #define SQL_FCNTL_HAS_MOVED              18
 #define SQL_FCNTL_SYNC                   19
 
-int
+void
 sql_os_init(void);
 
 sql_int64
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 77c6fa5b8..e11d29203 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -247,7 +247,7 @@ allocateCursor(
 		sqlVdbeFreeCursor(p, p->apCsr[iCur]);
 		p->apCsr[iCur] = 0;
 	}
-	if (0==sqlVdbeMemClearAndResize(pMem, nByte)) {
+	if (sqlVdbeMemClearAndResize(pMem, nByte) == 0) {
 		p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
 		memset(pCx, 0, offsetof(VdbeCursor,uc));
 		pCx->eCurType = eCurType;
@@ -372,7 +372,7 @@ static u16 SQL_NOINLINE computeNumericType(Mem *pMem)
 	assert((pMem->flags & (MEM_Str|MEM_Blob))!=0);
 	if (sqlAtoF(pMem->z, &pMem->u.r, pMem->n)==0)
 		return 0;
-	if (sql_atoi64(pMem->z, (int64_t *)&pMem->u.i, pMem->n)==0)
+	if (sql_atoi64(pMem->z, &pMem->u.i, pMem->n) == 0)
 		return MEM_Int;
 	return MEM_Real;
 }
@@ -752,7 +752,7 @@ int sqlVdbeExec(Vdbe *p)
 		 */
 		goto no_mem;
 	}
-	assert(p->rc==0 || (p->rc&0xff)==SQL_BUSY);
+	assert(p->rc == 0 || (p->rc & 0xff) == SQL_BUSY);
 	p->rc = 0;
 	p->iCurrentTime = 0;
 	assert(p->explain==0);
@@ -789,7 +789,7 @@ int sqlVdbeExec(Vdbe *p)
 		/* Errors are detected by individual opcodes, with an immediate
 		 * jumps to abort_due_to_error.
 		 */
-		assert(rc==0);
+		assert(rc == 0);
 
 		assert(pOp>=aOp && pOp<&aOp[p->nOp]);
 #ifdef VDBE_PROFILE
@@ -1036,7 +1036,7 @@ case OP_Halt: {
 	int pcx;
 
 	pcx = (int)(pOp - aOp);
-	if (pOp->p1==0 && p->pFrame) {
+	if (pOp->p1 == 0 && p->pFrame != NULL) {
 		/* Halt the sub-program. Return control to the parent frame. */
 		pFrame = p->pFrame;
 		p->pFrame = pFrame->pParent;
@@ -1068,11 +1068,11 @@ case OP_Halt: {
 		assert(! diag_is_empty(diag_get()));
 	}
 	rc = sqlVdbeHalt(p);
-	assert(rc==SQL_BUSY || rc==0 || rc==SQL_ERROR);
+	assert(rc == SQL_BUSY || rc == 0 || rc == SQL_ERROR);
 	if (rc==SQL_BUSY) {
 		p->rc = SQL_BUSY;
 	} else {
-		assert(rc==0 || (p->rc&0xff)==SQL_CONSTRAINT);
+		assert(rc == 0 || (p->rc & 0xff) == SQL_CONSTRAINT);
 		rc = p->rc ? SQL_TARANTOOL_ERROR : SQL_DONE;
 	}
 	goto vdbe_return;
@@ -1145,7 +1145,7 @@ case OP_String8: {         /* same as TK_STRING, out2 */
 	if (pOp->p1>db->aLimit[SQL_LIMIT_LENGTH]) {
 		goto too_big;
 	}
-	assert(rc==0);
+	assert(rc == 0);
 	/* Fall through to the next case, OP_String */
 	FALLTHROUGH;
 }
@@ -2883,9 +2883,8 @@ case OP_Savepoint: {
 			 */
 			int isTransaction = pSavepoint->pNext == 0;
 			if (isTransaction && p1==SAVEPOINT_RELEASE) {
-				if ((rc = sqlVdbeCheckFk(p, 1))!=0) {
+				if ((rc = sqlVdbeCheckFk(p, 1)) != 0)
 					goto vdbe_return;
-				}
 				if (sqlVdbeHalt(p)==SQL_BUSY) {
 					p->pc = (int)(pOp - aOp);
 					p->rc = rc = SQL_BUSY;
@@ -3933,9 +3932,9 @@ case OP_RowData: {
 	testcase( n==0);
 
 	sqlVdbeMemRelease(pOut);
-	if (sql_vdbe_mem_alloc_region(pOut, n) != 0 ||
-	    sqlCursorPayload(pCrsr, 0, n, pOut->z) != 0)
+	if (sql_vdbe_mem_alloc_region(pOut, n) != 0)
 		goto abort_due_to_error;
+	sqlCursorPayload(pCrsr, 0, n, pOut->z);
 	UPDATE_MAX_BLOBSIZE(pOut);
 	REGISTER_TRACE(p, pOp->p2, pOut);
 	break;
@@ -5291,7 +5290,7 @@ abort_due_to_error:
 vdbe_return:
 	testcase( nVmStep>0);
 	p->aCounter[SQL_STMTSTATUS_VM_STEP] += (int)nVmStep;
-	assert(rc!=0 || nExtraDelete==0
+	assert(rc != 0 || nExtraDelete == 0
 		|| sql_strlike_ci("DELETE%", p->zSql, 0) != 0
 		);
 	assert(rc == 0 || rc == SQL_BUSY || rc == SQL_TARANTOOL_ERROR ||
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 483fced50..bda7a8af8 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -195,8 +195,9 @@ growOpArray(Vdbe * v, int nOp)
 		p->szOpAlloc = sqlMallocSize(pNew);
 		p->nOpAlloc = p->szOpAlloc / sizeof(Op);
 		v->aOp = pNew;
+		return 0;
 	}
-	return (pNew ? 0 : SQL_NOMEM);
+	return SQL_NOMEM;
 }
 
 #ifdef SQL_DEBUG
@@ -1514,11 +1515,9 @@ sqlVdbeList(Vdbe * p)
 					if (apSub[j] == pOp->p4.pProgram)
 						break;
 				}
-				if (j == nSub
-				    && 0 == sqlVdbeMemGrow(pSub,
-								       nByte,
-								       nSub !=
-								       0)) {
+				if (j == nSub &&
+				    sqlVdbeMemGrow(pSub, nByte,
+						   nSub != 0) == 0) {
 					apSub = (SubProgram **) pSub->z;
 					apSub[nSub++] = pOp->p4.pProgram;
 					pSub->flags |= MEM_Blob;
@@ -2234,9 +2233,8 @@ sqlVdbeHalt(Vdbe * p)
 		}
 
 		/* Check for immediate foreign key violations. */
-		if (p->rc == 0) {
+		if (p->rc == 0)
 			sqlVdbeCheckFk(p, 0);
-		}
 
 		/* If the auto-commit flag is set and this is the only active writer
 		 * VM, then we do either a commit or rollback of the current transaction.
@@ -2350,7 +2348,7 @@ sqlVdbeHalt(Vdbe * p)
 
 	assert(db->nVdbeActive > 0 || box_txn() ||
 	       p->anonymous_savepoint == NULL);
-	return (p->rc == SQL_BUSY ? SQL_BUSY : 0);
+	return p->rc == SQL_BUSY ? SQL_BUSY : 0;
 }
 
 /*
diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
index df8206eb4..3052bece1 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -1048,15 +1048,11 @@ vdbeMemFromBtreeResize(BtCursor * pCur,	/* Cursor pointing at record to retrieve
 	int rc;
 	pMem->flags = MEM_Null;
 	if (0 == (rc = sqlVdbeMemClearAndResize(pMem, amt + 2))) {
-		rc = sqlCursorPayload(pCur, offset, amt, pMem->z);
-		if (rc == 0) {
-			pMem->z[amt] = 0;
-			pMem->z[amt + 1] = 0;
-			pMem->flags = MEM_Blob | MEM_Term;
-			pMem->n = (int)amt;
-		} else {
-			sqlVdbeMemRelease(pMem);
-		}
+		sqlCursorPayload(pCur, offset, amt, pMem->z);
+		pMem->z[amt] = 0;
+		pMem->z[amt + 1] = 0;
+		pMem->flags = MEM_Blob | MEM_Term;
+		pMem->n = (int) amt;
 	}
 	return rc;
 }
@@ -1295,9 +1291,8 @@ valueFromFunction(sql * db,	/* The database connection */
 	assert(rc == 0);
 
  value_from_function_out:
-	if (rc != 0) {
+	if (rc != 0)
 		pVal = 0;
-	}
 	if (apVal) {
 		for (i = 0; i < nVal; i++) {
 			sqlValueFree(apVal[i]);
@@ -1568,9 +1563,8 @@ stat4ValueFromExpr(Parse * pParse,	/* Parse context */
 			if (pVal) {
 				rc = sqlVdbeMemCopy((Mem *) pVal,
 							&v->aVar[iBindVar - 1]);
-				if (rc == 0) {
+				if (rc == 0)
 					sql_value_apply_type(pVal, type);
-				}
 				pVal->db = pParse->db;
 			}
 		}
diff --git a/src/box/sql/vdbesort.c b/src/box/sql/vdbesort.c
index f7fc8e1cc..646f8fe33 100644
--- a/src/box/sql/vdbesort.c
+++ b/src/box/sql/vdbesort.c
@@ -688,7 +688,7 @@ vdbePmaReaderSeek(SortSubtask * pTask,	/* Task context */
 	pReadr->pFd = pFile->pFd;
 
 	rc = vdbeSorterMapFile(pTask, pFile, &pReadr->aMap);
-	if (rc == 0 && pReadr->aMap == 0) {
+	if (rc == 0 && pReadr->aMap == NULL) {
 		int pgsz = pTask->pSorter->pgsz;
 		int iBuf = pReadr->iReadOff % pgsz;
 		if (pReadr->aBuffer == 0) {
@@ -697,7 +697,7 @@ vdbePmaReaderSeek(SortSubtask * pTask,	/* Task context */
 				rc = SQL_NOMEM;
 			pReadr->nBuffer = pgsz;
 		}
-		if (rc == 0 && iBuf) {
+		if (rc == 0 && iBuf != 0) {
 			int nRead = pgsz - iBuf;
 			if ((pReadr->iReadOff + nRead) > pReadr->iEof) {
 				nRead = (int)(pReadr->iEof - pReadr->iReadOff);
@@ -742,9 +742,8 @@ vdbePmaReaderNext(PmaReader * pReadr)
 		}
 	}
 
-	if (rc == 0) {
+	if (rc == 0)
 		rc = vdbePmaReadVarint(pReadr, &nRec);
-	}
 	if (rc == 0) {
 		pReadr->nKey = (int)nRec;
 		rc = vdbePmaReadBlob(pReadr, (int)nRec, &pReadr->aKey);
@@ -786,9 +785,8 @@ vdbePmaReaderInit(SortSubtask * pTask,	/* Task context */
 		*pnByte += nByte;
 	}
 
-	if (rc == 0) {
+	if (rc == 0)
 		rc = vdbePmaReaderNext(pReadr);
-	}
 	return rc;
 }
 
@@ -1532,9 +1530,8 @@ vdbeSorterListToPMA(SortSubtask * pTask, SorterList * pList)
 	}
 
 	/* Sort the list */
-	if (rc == 0) {
+	if (rc == 0)
 		rc = vdbeSorterSort(pTask, pList);
-	}
 
 	if (rc == 0) {
 		SorterRecord *p;
@@ -1556,7 +1553,7 @@ vdbeSorterListToPMA(SortSubtask * pTask, SorterList * pList)
 	}
 
 	vdbeSorterWorkDebug(pTask, "exit");
-	assert(rc != 0 || pList->pList == 0);
+	assert(rc != 0 || pList->pList == NULL);
 	assert(rc != 0 || pTask->file.iEof == iSz);
 	return rc;
 }
@@ -1642,7 +1639,7 @@ vdbeMergeEngineStep(MergeEngine * pMerger,	/* The merge engine to advance to the
 		*pbEof = (pMerger->aReadr[pMerger->aTree[1]].pFd == 0);
 	}
 
-	return (rc == 0 ? pTask->pUnpacked->errCode : rc);
+	return rc == 0 ? pTask->pUnpacked->errCode : rc;
 }
 
 #if SQL_MAX_WORKER_THREADS>0
@@ -1697,7 +1694,7 @@ vdbeSorterFlushPMA(VdbeSorter * pSorter)
 		if (pTask->bDone) {
 			rc = vdbeSorterJoinThread(pTask);
 		}
-		if (rc != 0 || pTask->pThread == 0)
+		if (rc != 0 || pTask->pThread == NULL)
 			break;
 	}
 
@@ -1801,7 +1798,7 @@ sqlVdbeSorterWrite(const VdbeCursor * pCsr,	/* Sorter cursor */
 			rc = vdbeSorterFlushPMA(pSorter);
 			pSorter->list.szPMA = 0;
 			pSorter->iMemory = 0;
-			assert(rc != 0 || pSorter->list.pList == 0);
+			assert(rc != 0 || pSorter->list.pList == NULL);
 		}
 	}
 
@@ -2627,9 +2624,8 @@ vdbeSorterSetupMerge(VdbeSorter * pSorter)
 		}
 	}
 
-	if (rc != 0) {
+	if (rc != 0)
 		vdbeMergeEngineFree(pMain);
-	}
 	return rc;
 }
 
diff --git a/src/box/sql/where.c b/src/box/sql/where.c
index 4d1759e53..c3a2cc623 100644
--- a/src/box/sql/where.c
+++ b/src/box/sql/where.c
@@ -1206,7 +1206,7 @@ whereRangeSkipScanEst(Parse * pParse,		/* Parsing & code generating context */
 					       type, &p1);
 		nLower = 0;
 	}
-	if (pUpper && rc == 0) {
+	if (pUpper != NULL && rc == 0) {
 		rc = sqlStat4ValueFromExpr(pParse, pUpper->pExpr->pRight,
 					       type, &p2);
 		nUpper = p2 ? 0 : index->def->opts.stat->sample_count;
@@ -1220,12 +1220,12 @@ whereRangeSkipScanEst(Parse * pParse,		/* Parsing & code generating context */
 		for (i = 0; rc == 0 && i < (int) sample_count; i++) {
 			rc = sql_stat4_column(db, samples[i].sample_key, nEq,
 					      &pVal);
-			if (rc == 0 && p1) {
+			if (rc == 0 && p1 != NULL) {
 				int res = sqlMemCompare(p1, pVal, coll);
 				if (res >= 0)
 					nLower++;
 			}
-			if (rc == 0 && p2) {
+			if (rc == 0 && p2 != NULL) {
 				int res = sqlMemCompare(p2, pVal, coll);
 				if (res >= 0)
 					nUpper++;
@@ -1399,7 +1399,7 @@ whereRangeScanEst(Parse * pParse,	/* Parsing & code generating context */
 				rc = sqlStat4ProbeSetValue(pParse, p, &pRec,
 							       pExpr, nBtm, nEq,
 							       &n);
-				if (rc == 0 && n) {
+				if (rc == 0 && n != 0) {
 					tRowcnt iNew;
 					u16 mask = WO_GT | WO_LE;
 					if (sqlExprVectorSize(pExpr) > n)
@@ -1425,7 +1425,7 @@ whereRangeScanEst(Parse * pParse,	/* Parsing & code generating context */
 				rc = sqlStat4ProbeSetValue(pParse, p, &pRec,
 							       pExpr, nTop, nEq,
 							       &n);
-				if (rc == 0 && n) {
+				if (rc == 0 && n != 0) {
 					tRowcnt iNew;
 					u16 mask = WO_GT | WO_LE;
 					if (sqlExprVectorSize(pExpr) > n)
@@ -2370,7 +2370,7 @@ whereLoopAddBtreeIndex(WhereLoopBuilder * pBuilder,	/* The WhereLoop factory */
 	pNew->rSetup = 0;
 	rSize = index_field_tuple_est(probe, 0);
 	rLogSize = estLog(rSize);
-	for (; rc == 0 && pTerm != 0; pTerm = whereScanNext(&scan)) {
+	for (; rc == 0 && pTerm != NULL; pTerm = whereScanNext(&scan)) {
 		u16 eOp = pTerm->eOperator;	/* Shorthand for pTerm->eOperator */
 		LogEst rCostIdx;
 		LogEst nOutUnadjusted;	/* nOut before IN() and WHERE adjustments */
@@ -3115,9 +3115,8 @@ whereLoopAddAll(WhereLoopBuilder * pBuilder)
 		{
 			rc = whereLoopAddBtree(pBuilder, mPrereq);
 		}
-		if (rc == 0) {
+		if (rc == 0)
 			rc = whereLoopAddOr(pBuilder, mPrereq, mUnusable);
-		}
 		mPrior |= pNew->maskSelf;
 		if (rc || db->mallocFailed)
 			break;

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 20/28] sql: remove SQL_NOMEM errcode
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 20/28] sql: remove SQL_NOMEM errcode imeevma
@ 2019-06-13 22:24   ` Vladislav Shpilevoy
  2019-06-15 10:01     ` Mergen Imeev
  0 siblings, 1 reply; 56+ messages in thread
From: Vladislav Shpilevoy @ 2019-06-13 22:24 UTC (permalink / raw)
  To: tarantool-patches, imeevma

Thanks for the patch!

Consider my review fixes below and on the branch
in a separate commit.

======================================================

diff --git a/src/box/sql/fault.c b/src/box/sql/fault.c
index 0e0978d20..544515a4b 100644
--- a/src/box/sql/fault.c
+++ b/src/box/sql/fault.c
@@ -37,7 +37,7 @@
  * and returns 0).
  *
  * Most malloc failures are non-benign. After they occur, sql
- * abandons the current operation and returns an -1
+ * abandons the current operation and returns an error
  * to the user. However, sometimes a fault is not necessarily
  * fatal. For example, if a malloc fails while resizing a hash table, this
  * is completely recoverable simply by not carrying out the resize. The
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index 34fd8c876..2d39323fa 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -494,7 +494,7 @@ sql_init_db(sql **out_db)
 {
 	sql *db;
 
-	if (sql_initialize())
+	if (sql_initialize() != 0)
 		return -1;
 
 	/* Allocate the sql data structure */
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 32f8b43e9..f5268d40f 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -689,43 +689,37 @@ sql_column_blob(sql_stmt * pStmt, int i)
 int
 sql_column_bytes(sql_stmt * pStmt, int i)
 {
-	int val = sql_value_bytes(columnMem(pStmt, i));
-	return val;
+	return sql_value_bytes(columnMem(pStmt, i));
 }
 
 double
 sql_column_double(sql_stmt * pStmt, int i)
 {
-	double val = sql_value_double(columnMem(pStmt, i));
-	return val;
+	return sql_value_double(columnMem(pStmt, i));
 }
 
 int
 sql_column_int(sql_stmt * pStmt, int i)
 {
-	int val = sql_value_int(columnMem(pStmt, i));
-	return val;
+	return sql_value_int(columnMem(pStmt, i));
 }
 
 bool
 sql_column_boolean(struct sql_stmt *stmt, int i)
 {
-	bool val = sql_value_boolean(columnMem(stmt, i));
-	return val;
+	return sql_value_boolean(columnMem(stmt, i));
 }
 
 sql_int64
 sql_column_int64(sql_stmt * pStmt, int i)
 {
-	sql_int64 val = sql_value_int64(columnMem(pStmt, i));
-	return val;
+	return sql_value_int64(columnMem(pStmt, i));
 }
 
 const unsigned char *
 sql_column_text(sql_stmt * pStmt, int i)
 {
-	const unsigned char *val = sql_value_text(columnMem(pStmt, i));
-	return val;
+	return sql_value_text(columnMem(pStmt, i));
 }
 
 sql_value *
@@ -742,8 +736,7 @@ sql_column_value(sql_stmt * pStmt, int i)
 enum mp_type
 sql_column_type(sql_stmt * pStmt, int i)
 {
-	enum mp_type type = sql_value_type(columnMem(pStmt, i));
-	return type;
+	return sql_value_type(columnMem(pStmt, i));
 }
 
 enum sql_subtype

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 16/28] sql: remove SQL_TOOBIG errcode
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 16/28] sql: remove SQL_TOOBIG errcode imeevma
@ 2019-06-13 22:24   ` Vladislav Shpilevoy
  2019-06-15  9:57     ` Mergen Imeev
  0 siblings, 1 reply; 56+ messages in thread
From: Vladislav Shpilevoy @ 2019-06-13 22:24 UTC (permalink / raw)
  To: tarantool-patches, imeevma

Thanks for the patch!

Consider my review fixes below and on the branch
in a separate commit.

======================================================

diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index ad8684dda..e41621049 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -274,14 +274,14 @@ setResultStrOrError(sql_context * pCtx,	/* Function context */
 		    void (*xDel) (void *)	/* Destructor function */
     )
 {
-	if (sqlVdbeMemSetStr(pCtx->pOut, z, n,1, xDel) != 0)
+	if (sqlVdbeMemSetStr(pCtx->pOut, z, n, 1, xDel) != 0)
 		pCtx->is_aborted = true;
 }
 
 static int
 invokeValueDestructor(const void *p,	/* Value to destroy */
 		      void (*xDel) (void *),	/* The destructor */
-		      sql_context * pCtx	/* Set an error if no NULL */
+		      sql_context *pCtx	/* Set an error if no NULL */
     )
 {
 	assert(xDel != SQL_DYNAMIC);
@@ -306,7 +306,7 @@ sql_result_blob(sql_context * pCtx,
     )
 {
 	assert(n >= 0);
-	if (sqlVdbeMemSetStr(pCtx->pOut, z, n,0, xDel) != 0)
+	if (sqlVdbeMemSetStr(pCtx->pOut, z, n, 0, xDel) != 0)
 		pCtx->is_aborted = true;
 }
 

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 25/28] sql: remove sql_log()
  2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 25/28] sql: remove sql_log() imeevma
@ 2019-06-13 22:24   ` Vladislav Shpilevoy
  2019-06-15 10:02     ` Mergen Imeev
  0 siblings, 1 reply; 56+ messages in thread
From: Vladislav Shpilevoy @ 2019-06-13 22:24 UTC (permalink / raw)
  To: tarantool-patches, imeevma

Thanks for the patch!

Consider my review fixes below and on the branch
in a separate commit.

======================================================

diff --git a/src/box/sql/global.c b/src/box/sql/global.c
index 0bbd8c2fd..c3c7e945c 100644
--- a/src/box/sql/global.c
+++ b/src/box/sql/global.c
@@ -196,8 +196,6 @@ SQL_WSD struct sqlConfig sqlConfig = {
 	0,			/* isInit */
 	0,			/* inProgress */
 	0,			/* isMallocInit */
-	0,			/* xLog */
-	0,			/* pLogArg */
 #ifdef SQL_VDBE_COVERAGE
 	0,			/* xVdbeBranch */
 	0,			/* pVbeBranchArg */
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 097f9730a..9b0928d0a 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -2752,8 +2752,6 @@ struct sqlConfig {
 	int isInit;		/* True after initialization has finished */
 	int inProgress;		/* True while initialization in progress */
 	int isMallocInit;	/* True after malloc is initialized */
-	void (*xLog) (void *, int, const char *);	/* Function for logging */
-	void *pLogArg;		/* First argument to xLog() */
 #ifdef SQL_VDBE_COVERAGE
 	/* The following callback (if not NULL) is invoked on every VDBE branch
 	 * operation.  Set the callback using sql_TESTCTRL_VDBE_COVERAGE.

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 18/28] sql: remove SQL_CONSTRAINT errcode
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 18/28] sql: remove SQL_CONSTRAINT errcode imeevma
@ 2019-06-13 22:24   ` Vladislav Shpilevoy
  2019-06-15 10:00     ` Mergen Imeev
  0 siblings, 1 reply; 56+ messages in thread
From: Vladislav Shpilevoy @ 2019-06-13 22:24 UTC (permalink / raw)
  To: tarantool-patches, imeevma

Thanks for the patch!

I've found 'sql_CONSTRAINT_UNIQUE' in sql-tap/unique.test.lua
on line 229. These tests are disabled by 'if 0 > 0', but another
comment says, that the issue #2495 fix should have enabled them
back. We need to either resurrect these tests, or drop them.

Consider my review fixes below and on the branch
in a separate commit.

======================================================

diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index acfeea588..128f5747d 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -3719,17 +3719,16 @@ sql_generate_index_key(struct Parse *parse, struct index *index, int cursor,
  * ----------  ----------  --------------------------------------
  *    any       ROLLBACK   The current transaction is rolled
  *                         back and VDBE stops immediately
- *                         with return code of sql_CONSTRAINT.
+ *                         with an error.
  *
  *    any        ABORT     Back out changes from the current
  *                         command only (do not do a complete
  *                         rollback) then cause VDBE to return
- *                         immediately with sql_CONSTRAINT.
+ *                         immediately with an error.
  *
- *    any        FAIL      VDBE returns immediately with a
- *                         return code of sql_CONSTRAINT. The
- *                         transaction is not rolled back and any
- *                         changes to prior rows are retained.
+ *    any        FAIL      VDBE returns immediately with an error.
+ *                         The transaction is not rolled back and
+ *                         any changes to prior rows are retained.
  *
  *    any       IGNORE     The attempt in insert or update the
  *                         current row is skipped, without
diff --git a/test/sql-tap/trigger1.test.lua b/test/sql-tap/trigger1.test.lua
index 38d7c5525..bc02d6236 100755
--- a/test/sql-tap/trigger1.test.lua
+++ b/test/sql-tap/trigger1.test.lua
@@ -511,7 +511,7 @@ test:do_catchsql_test(
         -- </trigger1-6.3>
     })
 
--- verify_ex_errcode trigger1-6.3b sql_CONSTRAINT_TRIGGER
+-- Verify the previous test has not deleted anything.
 test:do_execsql_test(
     "trigger1-6.4",
     [[
diff --git a/test/sql-tap/unique.test.lua b/test/sql-tap/unique.test.lua
index fbd73a650..358a06f40 100755
--- a/test/sql-tap/unique.test.lua
+++ b/test/sql-tap/unique.test.lua
@@ -74,7 +74,7 @@ test:do_catchsql_test(
         -- </unique-1.3>
     })
 
--- verify_ex_errcode unique-1.3b sql_CONSTRAINT_PRIMARYKEY
+-- Verify the previous test has not inserted anything.
 test:do_execsql_test(
     "unique-1.4",
     [[
@@ -95,7 +95,7 @@ test:do_catchsql_test(
         -- </unique-1.5>
     })
 
--- verify_ex_errcode unique-1.5b sql_CONSTRAINT_UNIQUE
+-- Verify the previous test has not inserted anything.
 test:do_execsql_test(
     "unique-1.6",
     [[
@@ -171,7 +171,7 @@ test:do_catchsql_test(
         -- </unique-2.3>
     })
 
--- verify_ex_errcode unique-2.3b sql_CONSTRAINT_UNIQUE
+-- Verify the previous test has not inserted anything.
 test:do_catchsql_test(
     "unique-2.4",
     [[
@@ -291,7 +291,6 @@ test:do_catchsql_test(
         -- </unique-3.4>
     })
 
--- verify_ex_errcode unique-3.4b sql_CONSTRAINT_UNIQUE
 --integrity_check unique-3.5
 -- Make sure NULLs are distinct as far as the UNIQUE tests are
 -- concerned.
@@ -405,7 +404,6 @@ test:do_catchsql_test(
     })
 end
 
--- verify_ex_errcode unique-4.10b sql_CONSTRAINT_UNIQUE
 --integrity_check unique-4.99
 -- Test the error message generation logic.  In particular, make sure we
 -- do not overflow the static buffer used to generate the error message.
@@ -448,7 +446,4 @@ test:do_catchsql_test(
         -- </unique-5.2>
     })
 
--- verify_ex_errcode unique-5.2b sql_CONSTRAINT_UNIQUE
-
-
 test:finish_test()

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 15/28] sql: remove SQL_SCHEMA errcode
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 15/28] sql: remove SQL_SCHEMA errcode imeevma
@ 2019-06-13 22:24   ` Vladislav Shpilevoy
  2019-06-15  9:55     ` Mergen Imeev
  0 siblings, 1 reply; 56+ messages in thread
From: Vladislav Shpilevoy @ 2019-06-13 22:24 UTC (permalink / raw)
  To: tarantool-patches, imeevma

Thanks for the patch!

Consider my review fix below and on the branch
in a separate commit.

======================================================

diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index 827828a1a..d909c8bf1 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -209,7 +209,7 @@ sqlReprepare(Vdbe * p)
 /*
  * Two versions of the official API.  Legacy and new use.  In the legacy
  * version, the original SQL text is not saved in the prepared statement
- * and so if a schema change occurs, SQL_SCHEMA is returned by
+ * and so if a schema change occurs, an error is returned by
  * sql_step().  In the new version, the original SQL text is retained
  * and the statement is automatically recompiled if an schema change
  * occurs.

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 06/28] sql: disable lookaside system
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 06/28] sql: disable lookaside system imeevma
@ 2019-06-13 22:25   ` Vladislav Shpilevoy
  2019-06-15  9:47     ` Mergen Imeev
  0 siblings, 1 reply; 56+ messages in thread
From: Vladislav Shpilevoy @ 2019-06-13 22:25 UTC (permalink / raw)
  To: tarantool-patches, imeevma

Thanks for the patch!

You removed it, not disabled. You have removed its core part, but
left a pile of surroundings.

Consider my review fixes below and on the branch
in a separate commit.

======================================================

diff --git a/src/box/sql/global.c b/src/box/sql/global.c
index e394db8d0..0bbd8c2fd 100644
--- a/src/box/sql/global.c
+++ b/src/box/sql/global.c
@@ -177,8 +177,6 @@ SQL_WSD struct sqlConfig sqlConfig = {
 	SQL_ALLOW_COVERING_INDEX_SCAN,	/* bUseCis */
 	0x7ffffffe,		/* mxStrlen */
 	0,			/* neverCorrupt */
-	512,			/* szLookaside */
-	125,			/* nLookaside */
 	0,			/* nStmtSpill */
 	(void *)0,		/* pHeap */
 	0,			/* nHeap */
diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index a7549db48..3ccb36e5e 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -481,13 +481,6 @@ sqlMallocSize(void *p)
 	return sql_sized_sizeof(p);
 }
 
-int
-sqlDbMallocSize(void *p)
-{
-	assert(p != 0);
-	return sql_sized_sizeof(p);
-}
-
 sql_uint64
 sql_msize(void *p)
 {
@@ -518,7 +511,7 @@ sql_free(void *p)
 static SQL_NOINLINE void
 measureAllocationSize(sql * db, void *p)
 {
-	*db->pnBytesFreed += sqlDbMallocSize(p);
+	*db->pnBytesFreed += sqlMallocSize(p);
 }
 
 /*
@@ -632,24 +625,9 @@ sqlDbMallocZero(sql * db, u64 n)
 	return p;
 }
 
-/* Finish the work of sqlDbMallocRawNN for the unusual and
- * slower case when the allocation cannot be fulfilled using lookaside.
- */
-static SQL_NOINLINE void *
-dbMallocRawFinish(sql * db, u64 n)
-{
-	void *p;
-	assert(db != 0);
-	p = sqlMalloc(n);
-	if (!p)
-		sqlOomFault(db);
-	return p;
-}
-
 /*
- * Allocate memory, either lookaside (if possible) or heap.
- * If the allocation fails, set the mallocFailed flag in
- * the connection pointer.
+ * Allocate heap memory. If the allocation fails, set the
+ * mallocFailed flag in the connection pointer.
  *
  * If db!=0 and db->mallocFailed is true (indicating a prior malloc
  * failure on the same database connection) then always return 0.
@@ -684,7 +662,10 @@ sqlDbMallocRawNN(sql * db, u64 n)
 	assert(db != NULL && db->pnBytesFreed == NULL);
 	if (db->mallocFailed)
 		return NULL;
-	return dbMallocRawFinish(db, n);
+	void *p = sqlMalloc(n);
+	if (p == NULL)
+		sqlOomFault(db);
+	return p;
 }
 
 /* Forward declaration */
@@ -784,17 +765,13 @@ sqlSetString(char **pz, sql * db, const char *zNew)
 
 /*
  * Call this routine to record the fact that an OOM (out-of-memory) error
- * has happened.  This routine will set db->mallocFailed, and also
- * temporarily disable the lookaside memory allocator and interrupt
- * any running VDBEs.
+ * has happened.  This routine will set db->mallocFailed.
  */
 void
 sqlOomFault(sql * db)
 {
-	if (db->mallocFailed == 0 && db->bBenignMalloc == 0) {
+	if (db->mallocFailed == 0 && db->bBenignMalloc == 0)
 		db->mallocFailed = 1;
-		db->lookaside.bDisable++;
-	}
 }
 
 /*
@@ -807,11 +784,8 @@ sqlOomFault(sql * db)
 void
 sqlOomClear(sql * db)
 {
-	if (db->mallocFailed && db->nVdbeExec == 0) {
+	if (db->mallocFailed && db->nVdbeExec == 0)
 		db->mallocFailed = 0;
-		assert(db->lookaside.bDisable > 0);
-		db->lookaside.bDisable--;
-	}
 }
 
 /*
diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y
index bc577a580..3ccb4f8ea 100644
--- a/src/box/sql/parse.y
+++ b/src/box/sql/parse.y
@@ -106,15 +106,6 @@ struct LimitVal {
 */
 struct TrigEvent { int a; IdList * b; };
 
-/*
-** Disable lookaside memory allocation for objects that might be
-** shared across database connections.
-*/
-static void disableLookaside(Parse *pParse){
-  pParse->disableLookaside++;
-  pParse->db->lookaside.bDisable++;
-}
-
 } // end %include
 
 // Input is a single SQL command
@@ -178,11 +169,10 @@ cmd ::= ROLLBACK TO savepoint_opt nm(X). {
 ///////////////////// The CREATE TABLE statement ////////////////////////////
 //
 cmd ::= create_table create_table_args.
-create_table ::= createkw TABLE ifnotexists(E) nm(Y). {
+create_table ::= CREATE TABLE ifnotexists(E) nm(Y). {
   create_table_def_init(&pParse->create_table_def, &Y, E);
   pParse->create_table_def.new_space = sqlStartTable(pParse, &Y);
 }
-createkw(A) ::= CREATE(A).  {disableLookaside(pParse);}
 
 %type ifnotexists {int}
 ifnotexists(A) ::= .              {A = 0;}
@@ -408,7 +398,7 @@ ifexists(A) ::= .            {A = 0;}
 
 ///////////////////// The CREATE VIEW statement /////////////////////////////
 //
-cmd ::= createkw(X) VIEW ifnotexists(E) nm(Y) eidlist_opt(C)
+cmd ::= CREATE(X) VIEW ifnotexists(E) nm(Y) eidlist_opt(C)
           AS select(S). {
   if (!pParse->parse_only) {
     create_view_def_init(&pParse->create_view_def, &Y, &X, C, S, E);
@@ -1409,7 +1399,7 @@ paren_exprlist(A) ::= LP exprlist(X) RP.  {A = X;}
 
 ///////////////////////////// The CREATE INDEX command ///////////////////////
 //
-cmd ::= createkw uniqueflag(U) INDEX ifnotexists(NE) nm(X)
+cmd ::= CREATE uniqueflag(U) INDEX ifnotexists(NE) nm(X)
         ON nm(Y) LP sortlist(Z) RP. {
   struct SrcList *src_list = sql_src_list_append(pParse->db,0,&Y);
   if (src_list == NULL) {
@@ -1512,7 +1502,7 @@ plus_num(A) ::= number(A).
 minus_num(A) ::= MINUS number(X).     {A = X;}
 //////////////////////////// The CREATE TRIGGER command /////////////////////
 
-cmd ::= createkw trigger_decl(A) BEGIN trigger_cmd_list(S) END(Z). {
+cmd ::= CREATE trigger_decl(A) BEGIN trigger_cmd_list(S) END(Z). {
   Token all;
   all.z = A.z;
   all.n = (int)(Z.z - A.z) + Z.n;
diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index 2b3ac29ae..4ac8698ec 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -295,12 +295,6 @@ sql_parser_destroy(Parse *parser)
 	sqlDbFree(db, parser->aLabel);
 	sql_expr_list_delete(db, parser->pConstExpr);
 	create_table_def_destroy(&parser->create_table_def);
-	if (db != NULL) {
-		assert(db->lookaside.bDisable >=
-		       parser->disableLookaside);
-		db->lookaside.bDisable -= parser->disableLookaside;
-	}
-	parser->disableLookaside = 0;
 	switch (parser->parsed_ast_type) {
 	case AST_TYPE_SELECT:
 		sql_select_delete(db, parser->parsed_ast.select);
diff --git a/src/box/sql/printf.c b/src/box/sql/printf.c
index c364055c1..add0be474 100644
--- a/src/box/sql/printf.c
+++ b/src/box/sql/printf.c
@@ -874,7 +874,7 @@ sqlStrAccumEnlarge(StrAccum * p, int N)
 			if (!isMalloced(p) && p->nChar > 0)
 				memcpy(zNew, p->zText, p->nChar);
 			p->zText = zNew;
-			p->nAlloc = sqlDbMallocSize(zNew);
+			p->nAlloc = sqlMallocSize(zNew);
 			p->printfFlags |= SQL_PRINTF_MALLOCED;
 		} else {
 			sqlStrAccumReset(p);
@@ -999,9 +999,8 @@ sqlStrAccumReset(StrAccum * p)
  * Initialize a string accumulator.
  *
  * p:     The accumulator to be initialized.
- * db:    Pointer to a database connection.  May be NULL.  Lookaside
- *        memory is used if not NULL. db->mallocFailed is set appropriately
- *        when not NULL.
+ * db:    Pointer to a database connection.  May be NULL.
+ *        db->mallocFailed is set appropriately when not NULL.
  * zBase: An initial buffer.  May be NULL in which case the initial buffer
  *        is malloced.
  * n:     Size of zBase in bytes.  If total space requirements never exceed
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index b6752930b..d58ae8573 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -2003,10 +2003,6 @@ sqlResultSetOfSelect(Parse * pParse, Select * pSelect)
 	struct space *space = sql_ephemeral_space_new(pParse, NULL);
 	if (space == NULL)
 		return NULL;
-	/* The sqlResultSetOfSelect() is only used in contexts where lookaside
-	 * is disabled
-	 */
-	assert(db->lookaside.bDisable);
 	sqlColumnsFromExprList(pParse, pSelect->pEList, space->def);
 	sqlSelectAddColumnTypeAndCollation(pParse, space->def, pSelect);
 	if (db->mallocFailed)
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 544b61aa8..54e9ae931 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -186,16 +186,13 @@
 #endif
 
 #if defined(SQL_SYSTEM_MALLOC) \
-  + defined(SQL_ZERO_MALLOC) \
-  + defined(SQL_MEMDEBUG)>1
+  + defined(SQL_ZERO_MALLOC) > 1
 #error "Two or more of the following compile-time configuration options\
  are defined but at most one is allowed:\
- SQL_SYSTEM_MALLOC, SQL_MEMDEBUG,\
- SQL_ZERO_MALLOC"
+ SQL_SYSTEM_MALLOC, SQL_ZERO_MALLOC"
 #endif
 #if defined(SQL_SYSTEM_MALLOC) \
-  + defined(SQL_ZERO_MALLOC) \
-  + defined(SQL_MEMDEBUG)==0
+  + defined(SQL_ZERO_MALLOC) == 0
 #define SQL_SYSTEM_MALLOC 1
 #endif
 
@@ -683,7 +680,6 @@ sql_os_end(void);
 
 #define SQL_CONFIG_SCRATCH       6	/* void*, int sz, int N */
 #define SQL_CONFIG_MEMSTATUS     9	/* boolean */
-#define SQL_CONFIG_LOOKASIDE    13	/* int int */
 #define SQL_CONFIG_LOG          16	/* xFunc, void* */
 #define SQL_CONFIG_URI          17	/* int */
 #define SQL_CONFIG_COVERING_INDEX_SCAN 20	/* int */
@@ -692,7 +688,6 @@ sql_os_end(void);
 #define SQL_CONFIG_PMASZ               24	/* unsigned int szPma */
 #define SQL_CONFIG_STMTJRNL_SPILL      25	/* int nByte */
 
-#define SQL_DBCONFIG_LOOKASIDE             1001	/* void* int int */
 #define SQL_DBCONFIG_ENABLE_FKEY           1002	/* int int* */
 #define SQL_DBCONFIG_ENABLE_TRIGGER        1003	/* int int* */
 #define SQL_DBCONFIG_NO_CKPT_ON_CLOSE      1006	/* int int* */
@@ -841,20 +836,6 @@ sql_uri_parameter(const char *zFilename,
 #define SQL_ACCESS_READWRITE 1	/* Used by PRAGMA temp_store_directory */
 #define SQL_ACCESS_READ      2	/* Unused */
 
-#define SQL_DBSTATUS_LOOKASIDE_USED       0
-#define SQL_DBSTATUS_CACHE_USED           1
-#define SQL_DBSTATUS_SCHEMA_USED          2
-#define SQL_DBSTATUS_STMT_USED            3
-#define SQL_DBSTATUS_LOOKASIDE_HIT        4
-#define SQL_DBSTATUS_LOOKASIDE_MISS_SIZE  5
-#define SQL_DBSTATUS_LOOKASIDE_MISS_FULL  6
-#define SQL_DBSTATUS_CACHE_HIT            7
-#define SQL_DBSTATUS_CACHE_MISS           8
-#define SQL_DBSTATUS_CACHE_WRITE          9
-#define SQL_DBSTATUS_DEFERRED_FKS        10
-#define SQL_DBSTATUS_CACHE_USED_SHARED   11
-#define SQL_DBSTATUS_MAX                 11	/* Largest defined DBSTATUS */
-
 const char *
 sql_sql(sql_stmt * pStmt);
 
@@ -1334,8 +1315,6 @@ typedef struct FuncDef FuncDef;
 typedef struct FuncDefHash FuncDefHash;
 typedef struct IdList IdList;
 typedef struct KeyClass KeyClass;
-typedef struct Lookaside Lookaside;
-typedef struct LookasideSlot LookasideSlot;
 typedef struct NameContext NameContext;
 typedef struct Parse Parse;
 typedef struct PrintfArguments PrintfArguments;
@@ -1378,41 +1357,6 @@ typedef int VList;
  */
 #define SQL_N_LIMIT (SQL_LIMIT_WORKER_THREADS+1)
 
-/*
- * Lookaside malloc is a set of fixed-size buffers that can be used
- * to satisfy small transient memory allocation requests for objects
- * associated with a particular database connection.  The use of
- * lookaside malloc provides a significant performance enhancement
- * (approx 10%) by avoiding numerous malloc/free requests while parsing
- * SQL statements.
- *
- * The Lookaside structure holds configuration information about the
- * lookaside malloc subsystem.  Each available memory allocation in
- * the lookaside subsystem is stored on a linked list of LookasideSlot
- * objects.
- *
- * Lookaside allocations are only allowed for objects that are associated
- * with a particular database connection.  Hence, schema information cannot
- * be stored in lookaside because in shared cache mode the schema information
- * is shared by multiple database connections.  Therefore, while parsing
- * schema information, the Lookaside.bEnabled flag is cleared so that
- * lookaside allocations are not used to construct the schema objects.
- */
-struct Lookaside {
-	u32 bDisable;		/* Only operate the lookaside when zero */
-	u16 sz;			/* Size of each buffer in bytes */
-	u8 bMalloced;		/* True if pStart obtained from sql_malloc() */
-	int nOut;		/* Number of buffers currently checked out */
-	int mxOut;		/* Highwater mark for nOut */
-	int anStat[3];		/* 0: hits.  1: size misses.  2: full misses */
-	LookasideSlot *pFree;	/* List of available buffers */
-	void *pStart;		/* First byte of available memory space */
-	void *pEnd;		/* First byte past end of available space */
-};
-struct LookasideSlot {
-	LookasideSlot *pNext;	/* Next buffer in the list of free buffers */
-};
-
 /*
  * A hash table for built-in function definitions.  (Application-defined
  * functions use a regular table table from hash.h.)
@@ -1466,7 +1410,6 @@ struct sql {
 	void *pUpdateArg;
 	void (*xUpdateCallback) (void *, int, const char *, const char *,
 				 sql_int64);
-	Lookaside lookaside;	/* Lookaside malloc configuration */
 	Hash aFunc;		/* Hash table of connection functions */
 	int *pnBytesFreed;	/* If not NULL, increment this in DbFree() */
 };
@@ -2572,7 +2515,6 @@ struct Parse {
 	u8 isMultiWrite;	/* True if statement may modify/insert multiple rows */
 	u8 hasCompound;		/* Need to invoke convertCompoundSelectToSubquery() */
 	u8 okConstFactor;	/* OK to factor out constants */
-	u8 disableLookaside;	/* Number of times lookaside has been disabled */
 	u8 nColCache;		/* Number of entries in aColCache[] */
 	int nRangeReg;		/* Size of the temporary register block */
 	int iRangeReg;		/* First register in temporary register block */
@@ -2847,7 +2789,7 @@ struct TriggerStep {
  * do not necessarily know how big the string will be in the end.
  */
 struct StrAccum {
-	sql *db;		/* Optional database for lookaside.  Can be NULL */
+	sql *db;		/* Database for temporary buffers. */
 	char *zBase;		/* A base allocation.  Not from malloc. */
 	char *zText;		/* The string collected so far */
 	u32 nChar;		/* Length of the string so far */
@@ -2875,8 +2817,6 @@ struct sqlConfig {
 	int bUseCis;		/* Use covering indices for full-scans */
 	int mxStrlen;		/* Maximum string length */
 	int neverCorrupt;	/* Database is always well-formed */
-	int szLookaside;	/* Default lookaside buffer size */
-	int nLookaside;		/* Default lookaside buffer count */
 	int nStmtSpill;		/* Stmt-journal spill-to-disk threshold */
 	void *pHeap;		/* Heap storage space */
 	int nHeap;		/* Size of pHeap[] */
@@ -3020,7 +2960,6 @@ void *sqlDbReallocOrFree(sql *, void *, u64);
 void *sqlDbRealloc(sql *, void *, u64);
 void sqlDbFree(sql *, void *);
 int sqlMallocSize(void *);
-int sqlDbMallocSize(void *);
 void *sqlScratchMalloc(int);
 void sqlScratchFree(void *);
 void *sqlPageMalloc(int);
diff --git a/src/box/sql/status.c b/src/box/sql/status.c
index bc170c8e5..950d5f409 100644
--- a/src/box/sql/status.c
+++ b/src/box/sql/status.c
@@ -158,140 +158,3 @@ sql_status(int op, int *pCurrent, int *pHighwater, int resetFlag)
 	}
 	return rc;
 }
-
-/*
- * Query status information for a single database connection
- */
-int
-sql_db_status(sql * db,	/* The database connection whose status is desired */
-		  int op,	/* Status verb */
-		  int *pCurrent,	/* Write current value here */
-		  int *pHighwater,	/* Write high-water mark here */
-		  int resetFlag	/* Reset high-water mark if true */
-    )
-{
-	int rc = SQL_OK;	/* Return code */
-	switch (op) {
-	case SQL_DBSTATUS_LOOKASIDE_USED:{
-			*pCurrent = db->lookaside.nOut;
-			*pHighwater = db->lookaside.mxOut;
-			if (resetFlag) {
-				db->lookaside.mxOut = db->lookaside.nOut;
-			}
-			break;
-		}
-
-	case SQL_DBSTATUS_LOOKASIDE_HIT:
-	case SQL_DBSTATUS_LOOKASIDE_MISS_SIZE:
-	case SQL_DBSTATUS_LOOKASIDE_MISS_FULL:{
-			testcase(op == SQL_DBSTATUS_LOOKASIDE_HIT);
-			testcase(op == SQL_DBSTATUS_LOOKASIDE_MISS_SIZE);
-			testcase(op == SQL_DBSTATUS_LOOKASIDE_MISS_FULL);
-			assert((op - SQL_DBSTATUS_LOOKASIDE_HIT) >= 0);
-			assert((op - SQL_DBSTATUS_LOOKASIDE_HIT) < 3);
-			*pCurrent = 0;
-			*pHighwater =
-			    db->lookaside.anStat[op -
-						 SQL_DBSTATUS_LOOKASIDE_HIT];
-			if (resetFlag) {
-				db->lookaside.anStat[op -
-						     SQL_DBSTATUS_LOOKASIDE_HIT]
-				    = 0;
-			}
-			break;
-		}
-
-		/*
-		 * Return an approximation for the amount of memory currently used
-		 * by all pagers associated with the given database connection.  The
-		 * highwater mark is meaningless and is returned as zero.
-		 */
-	case SQL_DBSTATUS_CACHE_USED_SHARED:
-	case SQL_DBSTATUS_CACHE_USED:{
-			int totalUsed = 0;
-			*pCurrent = totalUsed;
-			*pHighwater = 0;
-			break;
-		}
-
-		/*
-		 * *pCurrent gets an accurate estimate of the amount of memory used
-		 * to store the schema for database. *pHighwater is set to zero.
-		 */
-	case SQL_DBSTATUS_SCHEMA_USED:{
-			int nByte = 0;	/* Used to accumulate return value */
-
-			*pHighwater = 0;
-			*pCurrent = nByte;
-			break;
-		}
-
-		/*
-		 * *pCurrent gets an accurate estimate of the amount of memory used
-		 * to store all prepared statements.
-		 * *pHighwater is set to zero.
-		 */
-	case SQL_DBSTATUS_STMT_USED:{
-			struct Vdbe *pVdbe;	/* Used to iterate through VMs */
-			int nByte = 0;	/* Used to accumulate return value */
-
-			db->pnBytesFreed = &nByte;
-			for (pVdbe = db->pVdbe; pVdbe; pVdbe = pVdbe->pNext) {
-				sqlVdbeClearObject(db, pVdbe);
-				sqlDbFree(db, pVdbe);
-			}
-			db->pnBytesFreed = 0;
-
-			*pHighwater = 0;	/* IMP: R-64479-57858
-			*/
-			*pCurrent = nByte;
-
-			break;
-		}
-
-		/*
-		 * Set *pCurrent to the total cache hits or misses encountered by all
-		 * pagers the database handle is connected to. *pHighwater is always set
-		 * to zero.
-		 */
-	case SQL_DBSTATUS_CACHE_HIT:
-	case SQL_DBSTATUS_CACHE_MISS:
-	case SQL_DBSTATUS_CACHE_WRITE:{
-			int nRet = 0;
-			assert(SQL_DBSTATUS_CACHE_MISS ==
-			       SQL_DBSTATUS_CACHE_HIT + 1);
-			assert(SQL_DBSTATUS_CACHE_WRITE ==
-			       SQL_DBSTATUS_CACHE_HIT + 2);
-
-			*pHighwater = 0;	/* IMP: R-42420-56072
-			*/
-			/* IMP: R-54100-20147 */
-			/* IMP: R-29431-39229 */
-			*pCurrent = nRet;
-			break;
-		}
-
-		/* Set *pCurrent to non-zero if there are unresolved deferred foreign
-		 * key constraints.  Set *pCurrent to zero if all foreign key constraints
-		 * have been satisfied.  The *pHighwater is always set to zero.
-		 */
-	case SQL_DBSTATUS_DEFERRED_FKS:{
-			*pHighwater = 0;	/* IMP: R-11967-56545
-			*/
-			const struct txn *ptxn = in_txn();
-
-			if (!ptxn || !ptxn->psql_txn) {
-				*pCurrent = 0;
-				break;
-			}
-			const struct sql_txn *psql_txn = ptxn->psql_txn;
-			*pCurrent = psql_txn->fk_deferred_count > 0;
-			break;
-		}
-
-	default:{
-			rc = SQL_ERROR;
-		}
-	}
-	return rc;
-}
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index fbe5338f9..44a3812f0 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -192,7 +192,7 @@ growOpArray(Vdbe * v, int nOp)
 	assert(nNew >= (p->nOpAlloc + nOp));
 	pNew = sqlDbRealloc(p->db, v->aOp, nNew * sizeof(Op));
 	if (pNew) {
-		p->szOpAlloc = sqlDbMallocSize(pNew);
+		p->szOpAlloc = sqlMallocSize(pNew);
 		p->nOpAlloc = p->szOpAlloc / sizeof(Op);
 		v->aOp = pNew;
 	}
diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
index 2bb9bd3e4..366933695 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -70,7 +70,7 @@ sqlVdbeCheckMemInvariants(Mem * p)
 
 	/* The szMalloc field holds the correct memory allocation size */
 	assert(p->szMalloc == 0
-	       || p->szMalloc == sqlDbMallocSize(p->zMalloc));
+	       || p->szMalloc == sqlMallocSize(p->zMalloc));
 
 	/* If p holds a string or blob, the Mem.z must point to exactly
 	 * one of the following:
@@ -112,7 +112,7 @@ sqlVdbeMemGrow(Mem * pMem, int n, int bPreserve)
 	testcase(bPreserve && pMem->z == 0);
 
 	assert(pMem->szMalloc == 0
-	       || pMem->szMalloc == sqlDbMallocSize(pMem->zMalloc));
+	       || pMem->szMalloc == sqlMallocSize(pMem->zMalloc));
 	if (pMem->szMalloc < n) {
 		if (n < 32)
 			n = 32;
@@ -131,8 +131,7 @@ sqlVdbeMemGrow(Mem * pMem, int n, int bPreserve)
 			pMem->szMalloc = 0;
 			return SQL_NOMEM;
 		} else {
-			pMem->szMalloc =
-			    sqlDbMallocSize(pMem->zMalloc);
+			pMem->szMalloc = sqlMallocSize(pMem->zMalloc);
 		}
 	}
 
@@ -1006,7 +1005,7 @@ sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
 	} else if (xDel == SQL_DYNAMIC) {
 		sqlVdbeMemRelease(pMem);
 		pMem->zMalloc = pMem->z = (char *)z;
-		pMem->szMalloc = sqlDbMallocSize(pMem->zMalloc);
+		pMem->szMalloc = sqlMallocSize(pMem->zMalloc);
 	} else {
 		sqlVdbeMemRelease(pMem);
 		pMem->z = (char *)z;
diff --git a/src/box/sql/whereexpr.c b/src/box/sql/whereexpr.c
index a954b17f1..faff37bb9 100644
--- a/src/box/sql/whereexpr.c
+++ b/src/box/sql/whereexpr.c
@@ -107,7 +107,7 @@ whereClauseInsert(WhereClause * pWC, Expr * p, u16 wtFlags)
 		if (pOld != pWC->aStatic) {
 			sqlDbFree(db, pOld);
 		}
-		pWC->nSlot = sqlDbMallocSize(pWC->a) / sizeof(pWC->a[0]);
+		pWC->nSlot = sqlMallocSize(pWC->a) / sizeof(pWC->a[0]);
 	}
 	pTerm = &pWC->a[idx = pWC->nTerm++];
 	if (p && ExprHasProperty(p, EP_Unlikely)) {
diff --git a/test/sql-tap/join.test.lua b/test/sql-tap/join.test.lua
index ef6060927..f0ab16ad2 100755
--- a/test/sql-tap/join.test.lua
+++ b/test/sql-tap/join.test.lua
@@ -1072,13 +1072,6 @@ jointest("join-12.6", 66, {1, 'The number of tables in a join 66 exceeds the lim
 jointest("join-12.7", 127, {1, 'The number of tables in a join 127 exceeds the limit (64)'})
 jointest("join-12.8", 128, {1, 'The number of tables in a join 128 exceeds the limit (64)'})
 jointest("join-12.9", 1000, {1, 'The number of tables in a join 1000 exceeds the limit (64)'})
--- If sql is built with sql_MEMDEBUG, then the huge number of realloc()
--- calls made by the following test cases are too time consuming to run.
--- Without sql_MEMDEBUG, realloc() is fast enough that these are not
--- a problem.
---if X(0, "X!capable", [["pragma&&compileoption_diags"]]) then
---    if X(703, "X!cmd", [=[["expr","[lsearch [db eval {PRAGMA compile_options}] MEMDEBUG]<0"]]=])
--- then
 jointest("join-12.10", 65534, {1, 'The number of tables in a join 65534 exceeds the limit (64)'})
 jointest("join-12.11", 65535, {1, 'The number of tables in a join 65535 exceeds the limit (64)'})
 jointest("join-12.12", 65536, {1, 'The number of tables in a join 65536 exceeds the limit (64)'})
diff --git a/test/sql-tap/triggerA.test.lua b/test/sql-tap/triggerA.test.lua
index aa4771b31..fac51ca14 100755
--- a/test/sql-tap/triggerA.test.lua
+++ b/test/sql-tap/triggerA.test.lua
@@ -326,35 +326,4 @@ test:do_test(
         -- </triggerA-2.11>
     })
 
--- # Only run the reamining tests if memory debugging is turned on.
--- #
--- ifcapable !memdebug {
---    puts "Skipping triggerA malloc tests: not compiled with -Dsql_MEMDEBUG..."
---    finish_test
---    return
--- }
--- source $testdir/malloc_common.tcl
--- # Save a copy of the current database configuration.
--- #
--- db close
--- forcedelete test.db-triggerA
--- copy_file test.db test.db-triggerA
--- sql db test.db
--- # Run malloc tests on the INSTEAD OF trigger firing.
--- #
--- do_malloc_test triggerA-3 -tclprep {
---   db close
---   forcedelete test.db test.db-journal
---   forcecopy test.db-triggerA test.db
---   sql db test.db
---   sql_extended_result_codes db 1
---   db eval {SELECT * FROM v5; -- warm up the cache}
--- } -sqlbody {
---    DELETE FROM v5 WHERE x=5;
---    UPDATE v5 SET b=b+9900000 WHERE x BETWEEN 3 AND 5;
--- }
--- # Clean up the saved database copy.
--- #
--- forcedelete test.db-triggerA
 test:finish_test()
-

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 04/28] sql: remove sqlError() and remove sqlErrorWithMsg()
  2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 04/28] sql: remove sqlError() and remove sqlErrorWithMsg() imeevma
@ 2019-06-13 22:25   ` Vladislav Shpilevoy
  2019-06-15  9:45     ` Mergen Imeev
  0 siblings, 1 reply; 56+ messages in thread
From: Vladislav Shpilevoy @ 2019-06-13 22:25 UTC (permalink / raw)
  To: tarantool-patches, imeevma

Thanks for the patch!

Consider my review fixes below and on the branch
in a separate commit.

======================================================

diff --git a/src/box/sql/os.c b/src/box/sql/os.c
index eb7450b23..a06067583 100644
--- a/src/box/sql/os.c
+++ b/src/box/sql/os.c
@@ -128,12 +128,6 @@ sqlOsRandomness(sql_vfs * pVfs, int nByte, char *zBufOut)
 	return pVfs->xRandomness(pVfs, nByte, zBufOut);
 }
 
-int
-sqlOsGetLastError(sql_vfs * pVfs)
-{
-	return pVfs->xGetLastError ? pVfs->xGetLastError(pVfs, 0, 0) : 0;
-}
-
 int
 sqlOsCurrentTimeInt64(sql_vfs * pVfs, sql_int64 * pTimeOut)
 {
diff --git a/src/box/sql/os.h b/src/box/sql/os.h
index 1514f0d8a..9122e9cb7 100644
--- a/src/box/sql/os.h
+++ b/src/box/sql/os.h
@@ -146,7 +146,6 @@ int sqlOsUnfetch(sql_file *, i64, void *);
  */
 int sqlOsOpen(sql_vfs *, const char *, sql_file *, int, int *);
 int sqlOsRandomness(sql_vfs *, int, char *);
-int sqlOsGetLastError(sql_vfs *);
 int sqlOsCurrentTimeInt64(sql_vfs *, sql_int64 *);
 
 /*
diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index 615d539b5..486f9ce7c 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -2018,21 +2018,6 @@ unixCurrentTimeInt64(sql_vfs * NotUsed, sql_int64 * piNow)
 	return rc;
 }
 
-/*
- * The xGetLastError() method is designed to return a better
- * low-level error message when operating-system problems come up
- * during sql operation.  Only the integer return code is currently
- * used.
- */
-static int
-unixGetLastError(sql_vfs * NotUsed, int NotUsed2, char *NotUsed3)
-{
-	UNUSED_PARAMETER(NotUsed);
-	UNUSED_PARAMETER(NotUsed2);
-	UNUSED_PARAMETER(NotUsed3);
-	return errno;
-}
-
 /*
  *********************** End of sql_vfs methods ***************************
  *****************************************************************************/
@@ -2057,7 +2042,6 @@ unixGetLastError(sql_vfs * NotUsed, int NotUsed2, char *NotUsed3)
     unixDelete,           /* xDelete */                     \
     unixRandomness,       /* xRandomness */                 \
     NULL,                 /* xCurrentTime */                \
-    unixGetLastError,     /* xGetLastError */               \
     unixCurrentTimeInt64, /* xCurrentTimeInt64 */           \
   }
 
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 2b7aa8bc8..a87c5748d 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -330,7 +330,6 @@ struct sql_vfs {
 	int (*xDelete) (sql_vfs *, const char *zName, int syncDir);
 	int (*xRandomness) (sql_vfs *, int nByte, char *zOut);
 	int (*xCurrentTime) (sql_vfs *, double *);
-	int (*xGetLastError) (sql_vfs *, int, char *);
 	/*
 	** The methods above are in version 1 of the sql_vfs object
 	** definition.  Those that follow are added in version 2 or later

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 04/28] sql: remove sqlError() and remove sqlErrorWithMsg()
  2019-06-13 22:25   ` [tarantool-patches] " Vladislav Shpilevoy
@ 2019-06-15  9:45     ` Mergen Imeev
  0 siblings, 0 replies; 56+ messages in thread
From: Mergen Imeev @ 2019-06-15  9:45 UTC (permalink / raw)
  To: Vladislav Shpilevoy; +Cc: tarantool-patches

On Fri, Jun 14, 2019 at 12:25:06AM +0200, Vladislav Shpilevoy wrote:
> Thanks for the patch!
> 
> Consider my review fixes below and on the branch
> in a separate commit.
> 

Thank you! New patch:

From 0199a43b36b51c43333e47fa240328072741214c Mon Sep 17 00:00:00 2001
Date: Sat, 27 Apr 2019 15:18:15 +0300
Subject: [PATCH] sql: remove sqlError() and remove sqlErrorWithMsg()

These functions are part of the SQL error system, which is
replaced by the Tarantool error system. They are not needed now,
so they will be deleted.

diff --git a/src/box/lua/lua_sql.c b/src/box/lua/lua_sql.c
index 529ee59..4d90a53 100644
--- a/src/box/lua/lua_sql.c
+++ b/src/box/lua/lua_sql.c
@@ -199,6 +199,6 @@ lbox_sql_create_function(struct lua_State *L)
 					   func_info, lua_sql_call, NULL, NULL,
 					   lua_sql_destroy);
 	if (rc != 0)
-		return luaL_error(L, sqlErrStr(rc));
+		return luaT_error(L);
 	return 0;
 }
diff --git a/src/box/sql/legacy.c b/src/box/sql/legacy.c
index a57677e..d519991 100644
--- a/src/box/sql/legacy.c
+++ b/src/box/sql/legacy.c
@@ -69,7 +69,6 @@ sql_exec(sql * db,	/* The database on which the SQL executes */
 	if (zSql == 0)
 		zSql = "";
 
-	sqlError(db, SQL_OK);
 	while (rc == SQL_OK && zSql[0]) {
 		int nCol;
 		char **azVals = 0;
@@ -141,7 +140,6 @@ sql_exec(sql * db,	/* The database on which the SQL executes */
 					rc = SQL_ABORT;
 					sqlVdbeFinalize((Vdbe *) pStmt);
 					pStmt = 0;
-					sqlError(db, SQL_ABORT);
 					goto exec_out;
 				}
 			}
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index 17ddf5a..0811b2e 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -272,61 +272,6 @@ functionDestroy(sql * db, FuncDef * p)
 }
 
 /*
- * Return TRUE if database connection db has unfinalized prepared
- * statement.
- */
-static int
-connectionIsBusy(sql * db)
-{
-	if (db->pVdbe)
-		return 1;
-	return 0;
-}
-
-/*
- * Close an existing sql database
- */
-static int
-sqlClose(sql * db, int forceZombie)
-{
-	assert(db);
-	if (!sqlSafetyCheckSickOrOk(db)) {
-		return SQL_MISUSE;
-	}
-	if (db->mTrace & SQL_TRACE_CLOSE) {
-		db->xTrace(SQL_TRACE_CLOSE, db->pTraceArg, db, 0);
-	}
-
-	/* Legacy behavior (sql_close() behavior) is to return
-	 * SQL_BUSY if the connection can not be closed immediately.
-	 */
-	if (!forceZombie && connectionIsBusy(db)) {
-		sqlErrorWithMsg(db, SQL_BUSY,
-				    "unable to close due to unfinalized "
-				    "statements");
-		return SQL_BUSY;
-	}
-
-	/* Convert the connection into a zombie and then close it.
-	 */
-	db->magic = SQL_MAGIC_ZOMBIE;
-
-	return SQL_OK;
-}
-
-/*
- * Two variations on the public interface for closing a database
- * connection. The sql_close() version returns SQL_BUSY and
- * leaves the connection option if there are unfinalized prepared
- * statements.
- */
-int
-sql_close(sql * db)
-{
-	return sqlClose(db, 0);
-}
-
-/*
  * Rollback all database files.  If tripCode is not SQL_OK, then
  * any write cursors are invalidated ("tripped" - as in "tripping a circuit
  * breaker") and made to return tripCode if there are any further
@@ -405,7 +350,9 @@ sqlCreateFunc(sql * db,
 	    (!xSFunc && (!xFinal && xStep)) ||
 	    (nArg < -1 || nArg > SQL_MAX_FUNCTION_ARG) ||
 	    (255 < (sqlStrlen30(zFunctionName)))) {
-		return SQL_MISUSE;
+		diag_set(ClientError, ER_CREATE_FUNCTION, zFunctionName,
+			 "wrong function definition");
+		return SQL_TARANTOOL_ERROR;
 	}
 
 	assert(SQL_FUNC_CONSTANT == SQL_DETERMINISTIC);
@@ -420,10 +367,10 @@ sqlCreateFunc(sql * db,
 	p = sqlFindFunction(db, zFunctionName, nArg, 0);
 	if (p && p->nArg == nArg) {
 		if (db->nVdbeActive) {
-			sqlErrorWithMsg(db, SQL_BUSY,
-					    "unable to delete/modify user-function due to active statements");
-			assert(!db->mallocFailed);
-			return SQL_BUSY;
+			diag_set(ClientError, ER_CREATE_FUNCTION, zFunctionName,
+				 "unable to create function due to active "\
+				 "statements");
+			return SQL_TARANTOOL_ERROR;
 		} else {
 			sqlExpirePreparedStatements(db);
 		}
@@ -431,9 +378,8 @@ sqlCreateFunc(sql * db,
 
 	p = sqlFindFunction(db, zFunctionName, nArg, 1);
 	assert(p || db->mallocFailed);
-	if (!p) {
-		return SQL_NOMEM;
-	}
+	if (p == NULL)
+		return SQL_TARANTOOL_ERROR;
 
 	/* If an older version of the function with a configured destructor is
 	 * being replaced invoke the destructor function here.
@@ -637,22 +583,17 @@ sql_init_db(sql **out_db)
 	 * database schema yet. This is delayed until the first time the database
 	 * is accessed.
 	 */
-	sqlError(db, SQL_OK);
 	sqlRegisterPerConnectionBuiltinFunctions(db);
 
-	if (rc)
-		sqlError(db, rc);
-
 	/* Enable the lookaside-malloc subsystem */
 	setupLookaside(db, 0, sqlGlobalConfig.szLookaside,
 		       sqlGlobalConfig.nLookaside);
 
 opendb_out:
 	assert(db != 0 || rc == SQL_NOMEM);
-	if (rc == SQL_NOMEM) {
-		sql_close(db);
-		db = 0;
-	} else if (rc != SQL_OK)
+	if (rc == SQL_NOMEM)
+		db = NULL;
+	else if (rc != SQL_OK)
 		db->magic = SQL_MAGIC_SICK;
 
 	*out_db = db;
diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index 45667fe..5df4606 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -756,7 +756,6 @@ static SQL_NOINLINE int
 apiOomError(sql * db)
 {
 	sqlOomClear(db);
-	sqlError(db, SQL_NOMEM);
 	return SQL_NOMEM;
 }
 
diff --git a/src/box/sql/os.c b/src/box/sql/os.c
index eb7450b..a060675 100644
--- a/src/box/sql/os.c
+++ b/src/box/sql/os.c
@@ -129,12 +129,6 @@ sqlOsRandomness(sql_vfs * pVfs, int nByte, char *zBufOut)
 }
 
 int
-sqlOsGetLastError(sql_vfs * pVfs)
-{
-	return pVfs->xGetLastError ? pVfs->xGetLastError(pVfs, 0, 0) : 0;
-}
-
-int
 sqlOsCurrentTimeInt64(sql_vfs * pVfs, sql_int64 * pTimeOut)
 {
 	int rc;
diff --git a/src/box/sql/os.h b/src/box/sql/os.h
index 1514f0d..9122e9c 100644
--- a/src/box/sql/os.h
+++ b/src/box/sql/os.h
@@ -146,7 +146,6 @@ int sqlOsUnfetch(sql_file *, i64, void *);
  */
 int sqlOsOpen(sql_vfs *, const char *, sql_file *, int, int *);
 int sqlOsRandomness(sql_vfs *, int, char *);
-int sqlOsGetLastError(sql_vfs *);
 int sqlOsCurrentTimeInt64(sql_vfs *, sql_int64 *);
 
 /*
diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index f9969b4..e0a2805 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -2017,21 +2017,6 @@ unixCurrentTimeInt64(sql_vfs * NotUsed, sql_int64 * piNow)
 }
 
 /*
- * The xGetLastError() method is designed to return a better
- * low-level error message when operating-system problems come up
- * during sql operation.  Only the integer return code is currently
- * used.
- */
-static int
-unixGetLastError(sql_vfs * NotUsed, int NotUsed2, char *NotUsed3)
-{
-	UNUSED_PARAMETER(NotUsed);
-	UNUSED_PARAMETER(NotUsed2);
-	UNUSED_PARAMETER(NotUsed3);
-	return errno;
-}
-
-/*
  *********************** End of sql_vfs methods ***************************
  *****************************************************************************/
 
@@ -2055,7 +2040,6 @@ unixGetLastError(sql_vfs * NotUsed, int NotUsed2, char *NotUsed3)
     unixDelete,           /* xDelete */                     \
     unixRandomness,       /* xRandomness */                 \
     NULL,                 /* xCurrentTime */                \
-    unixGetLastError,     /* xGetLastError */               \
     unixCurrentTimeInt64, /* xCurrentTimeInt64 */           \
   }
 
diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index e2f8c0b..e692be0 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -81,9 +81,9 @@ sqlPrepare(sql * db,	/* Database handle. */
 		testcase(nBytes == mxLen);
 		testcase(nBytes == mxLen + 1);
 		if (nBytes > mxLen) {
-			sqlErrorWithMsg(db, SQL_TOOBIG,
-					    "statement too long");
-			rc = sqlApiExit(db, SQL_TOOBIG);
+			diag_set(ClientError, ER_SQL_PARSER_LIMIT,
+				 "SQL command length", nBytes, mxLen);
+			rc = SQL_TARANTOOL_ERROR;
 			goto end_prepare;
 		}
 		zSqlCopy = sqlDbStrNDup(db, zSql, nBytes);
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 4862794..7051aa9 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -304,7 +304,6 @@ struct sql_vfs {
 	int (*xDelete) (sql_vfs *, const char *zName, int syncDir);
 	int (*xRandomness) (sql_vfs *, int nByte, char *zOut);
 	int (*xCurrentTime) (sql_vfs *, double *);
-	int (*xGetLastError) (sql_vfs *, int, char *);
 	/*
 	** The methods above are in version 1 of the sql_vfs object
 	** definition.  Those that follow are added in version 2 or later
@@ -816,8 +815,6 @@ sql_stmt_busy(sql_stmt *);
 int
 sql_init_db(sql **db);
 
-int
-sql_close(sql *);
 
 /**
  * Get number of the named parameter in the prepared sql
@@ -1258,7 +1255,6 @@ struct sql {
 	struct coll *pDfltColl;	/* The default collating sequence (BINARY) */
 	i64 szMmap;		/* Default mmap_size setting */
 	int errMask;		/* & result codes with this before returning */
-	int iSysErrno;		/* Errno value from last system error */
 	u16 dbOptFlags;		/* Flags to enable/disable optimizations */
 	u8 enc;			/* Text encoding */
 	u8 mallocFailed;	/* True if we have seen a malloc failure */
@@ -4247,9 +4243,6 @@ sql_atoi64(const char *z, int64_t *val, int length);
 int
 sql_dec_or_hex_to_i64(const char *z, int64_t *val);
 
-void sqlErrorWithMsg(sql *, int, const char *, ...);
-void sqlError(sql *, int);
-void sqlSystemError(sql *, int);
 void *sqlHexToBlob(sql *, const char *z, int n);
 u8 sqlHexToInt(int h);
 
diff --git a/src/box/sql/util.c b/src/box/sql/util.c
index 7596c6c..3de157e 100644
--- a/src/box/sql/util.c
+++ b/src/box/sql/util.c
@@ -92,75 +92,6 @@ sqlStrlen30(const char *z)
 }
 
 /*
- * Helper function for sqlError() - called rarely.  Broken out into
- * a separate routine to avoid unnecessary register saves on entry to
- * sqlError().
- */
-static SQL_NOINLINE void
-sqlErrorFinish(sql * db, int err_code)
-{
-	sqlSystemError(db, err_code);
-}
-
-/*
- * Set the current error code to err_code and clear any prior error message.
- * Also set iSysErrno (by calling sqlSystem) if the err_code indicates
- * that would be appropriate.
- */
-void
-sqlError(sql * db, int err_code)
-{
-	assert(db != 0);
-	if (err_code)
-		sqlErrorFinish(db, err_code);
-}
-
-/*
- * Load the sql.iSysErrno field if that is an appropriate thing
- * to do based on the sql error code in rc.
- */
-void
-sqlSystemError(sql * db, int rc)
-{
-	if (rc == SQL_IOERR_NOMEM)
-		return;
-	rc &= 0xff;
-	if (rc == SQL_CANTOPEN || rc == SQL_IOERR) {
-		db->iSysErrno = sqlOsGetLastError(db->pVfs);
-	}
-}
-
-/*
- * Set the most recent error code and error string for the sql
- * handle "db". The error code is set to "err_code".
- *
- * If it is not NULL, string zFormat specifies the format of the
- * error string in the style of the printf functions: The following
- * format characters are allowed:
- *
- *      %s      Insert a string
- *      %z      A string that should be freed after use
- *      %d      Insert an integer
- *      %T      Insert a token
- *      %S      Insert the first element of a SrcList
- *
- * zFormat and any string tokens that follow it are assumed to be
- * encoded in UTF-8.
- *
- * To clear the most recent error for sql handle "db", sqlError
- * should be called with err_code set to SQL_OK and zFormat set
- * to NULL.
- */
-void
-sqlErrorWithMsg(sql * db, int err_code, const char *zFormat, ...)
-{
-	assert(db != 0);
-	sqlSystemError(db, err_code);
-	if (zFormat == 0)
-		sqlError(db, err_code);
-}
-
-/*
  * Convert an SQL-style quoted string into a normal string by removing
  * the quote characters.  The conversion is done in-place.  If the
  * input does not begin with a quote character, then this routine
diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h
index 09a1b13..064eb46 100644
--- a/src/box/sql/vdbeInt.h
+++ b/src/box/sql/vdbeInt.h
@@ -497,7 +497,6 @@ int sqlVdbeMemClearAndResize(Mem * pMem, int n);
 int sqlVdbeCloseStatement(Vdbe *, int);
 void sqlVdbeFrameDelete(VdbeFrame *);
 int sqlVdbeFrameRestore(VdbeFrame *);
-int sqlVdbeTransferError(Vdbe * p);
 
 int sqlVdbeSorterInit(struct sql *db, struct VdbeCursor *cursor);
 void sqlVdbeSorterReset(sql *, VdbeSorter *);
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 98d708a..7d519ce 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -504,7 +504,7 @@ sqlStep(Vdbe * p)
 		 * error has occurred, then return the error code in p->rc to the
 		 * caller. Set the error code in the database handle to the same value.
 		 */
-		rc = sqlVdbeTransferError(p);
+		rc = p->rc;
 	}
 	return (rc & db->errMask);
 }
@@ -736,7 +736,6 @@ columnMem(sql_stmt * pStmt, int i)
 	if (pVm->pResultSet != 0 && i < pVm->nResColumn && i >= 0) {
 		pOut = &pVm->pResultSet[i];
 	} else {
-		sqlError(pVm->db, SQL_RANGE);
 		pOut = (Mem *) columnNullValue();
 	}
 	return pOut;
@@ -958,20 +957,17 @@ vdbeUnbind(Vdbe * p, int i)
 		return SQL_MISUSE;
 	}
 	if (p->magic != VDBE_MAGIC_RUN || p->pc >= 0) {
-		sqlError(p->db, SQL_MISUSE);
 		sql_log(SQL_MISUSE,
 			    "bind on a busy prepared statement: [%s]", p->zSql);
 		return SQL_MISUSE;
 	}
 	if (i < 1 || i > p->nVar) {
-		sqlError(p->db, SQL_RANGE);
 		return SQL_RANGE;
 	}
 	i--;
 	pVar = &p->aVar[i];
 	sqlVdbeMemRelease(pVar);
 	pVar->flags = MEM_Null;
-	sqlError(p->db, SQL_OK);
 
 	/* If the bit corresponding to this variable in Vdbe.expmask is set, then
 	 * binding a new value to this variable invalidates the current query plan.
@@ -1057,7 +1053,6 @@ bindText(sql_stmt * pStmt,	/* The statement to bind against */
 			rc = sqlVdbeMemSetStr(pVar, zData, nData, 1, xDel);
 			if (rc == SQL_OK)
 				rc = sql_bind_type(p, i, "TEXT");
-			sqlError(p->db, rc);
 			rc = sqlApiExit(p->db, rc);
 		}
 	} else if (xDel != SQL_STATIC && xDel != SQL_TRANSIENT) {
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index e3f9289..042e8eb 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -2290,23 +2290,6 @@ sqlVdbeResetStepResult(Vdbe * p)
 }
 
 /*
- * Copy the error code and error message belonging to the VDBE passed
- * as the first argument to its database handle (so that they will be
- * returned by calls to sql_errcode() and sql_errmsg()).
- *
- * This function does not clear the VDBE error code or message, just
- * copies them to the database handle.
- */
-int
-sqlVdbeTransferError(Vdbe * p)
-{
-	sql *db = p->db;
-	int rc = p->rc;
-	sqlError(db, rc);
-	return rc;
-}
-
-/*
  * Clean up a VDBE after execution but do not delete the VDBE just yet.
  * Return the result code.
  *
@@ -2335,15 +2318,17 @@ sqlVdbeReset(Vdbe * p)
 	 * instructions yet, leave the main database error information unchanged.
 	 */
 	if (p->pc >= 0) {
-		sqlVdbeTransferError(p);
 		if (p->runOnlyOnce)
 			p->expired = 1;
-	} else if (p->rc && p->expired) {
-		/* The expired flag was set on the VDBE before the first call
-		 * to sql_step(). For consistency (since sql_step() was
-		 * called), set the database error in this case as well.
+	} else {
+		/*
+		 * An error should be thrown here if the expired
+		 * flag is set on the VDBE flag with the first
+		 * call to sql_step(). However, the expired flag
+		 * is currently disabled, so this error has been
+		 * replaced with assert.
 		 */
-		sqlErrorWithMsg(db, p->rc, NULL);
+		assert(p->rc == 0 || p->expired == 0);
 	}
 
 	/* Reclaim all memory used by the VDBE
diff --git a/test/sql/func-recreate.result b/test/sql/func-recreate.result
index d713292..73fb03c 100644
--- a/test/sql/func-recreate.result
+++ b/test/sql/func-recreate.result
@@ -26,7 +26,8 @@ fiber.sleep(0.1)
 ...
 box.internal.sql_create_function('WAITFOR', 'INT', function (n) require('fiber').sleep(n) return n end)
 ---
-- error: database is locked
+- error: 'Failed to create function ''WAITFOR'': unable to create function due to
+    active statements'
 ...
 ch:get()
 ---

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 06/28] sql: disable lookaside system
  2019-06-13 22:25   ` [tarantool-patches] " Vladislav Shpilevoy
@ 2019-06-15  9:47     ` Mergen Imeev
  0 siblings, 0 replies; 56+ messages in thread
From: Mergen Imeev @ 2019-06-15  9:47 UTC (permalink / raw)
  To: Vladislav Shpilevoy; +Cc: tarantool-patches

On Fri, Jun 14, 2019 at 12:25:04AM +0200, Vladislav Shpilevoy wrote:
> Thanks for the patch!
> 
> You removed it, not disabled. You have removed its core part, but
> left a pile of surroundings.
> 
> Consider my review fixes below and on the branch
> in a separate commit.
> 
Thank you! I squashed your fixes and fixed commit-message.
New patch:

From e4b3735016c860d2db9b0c5686ceaad2a9a2d8d5 Mon Sep 17 00:00:00 2001
Date: Wed, 22 May 2019 17:17:27 +0300
Subject: [PATCH] sql: remove lookaside system

Since the lookaside system is not currently in use, it must be
completely removed.

diff --git a/src/box/sql/global.c b/src/box/sql/global.c
index 064f7cf..13e9c67 100644
--- a/src/box/sql/global.c
+++ b/src/box/sql/global.c
@@ -177,8 +177,6 @@ SQL_WSD struct sqlConfig sqlConfig = {
 	SQL_ALLOW_COVERING_INDEX_SCAN,	/* bUseCis */
 	0x7ffffffe,		/* mxStrlen */
 	0,			/* neverCorrupt */
-	512,			/* szLookaside */
-	125,			/* nLookaside */
 	0,			/* nStmtSpill */
 	(void *)0,		/* pHeap */
 	0,			/* nHeap */
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index 9fdcdde..3004ae7 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -163,76 +163,6 @@ sql_initialize(void)
 	return rc;
 }
 
-/*
- * Set up the lookaside buffers for a database connection.
- * Return SQL_OK on success.
- * If lookaside is already active, return SQL_BUSY.
- *
- * The sz parameter is the number of bytes in each lookaside slot.
- * The cnt parameter is the number of slots.  If pStart is NULL the
- * space for the lookaside memory is obtained from sql_malloc().
- * If pStart is not NULL then it is sz*cnt bytes of memory to use for
- * the lookaside memory.
- */
-static int
-setupLookaside(sql * db, void *pBuf, int sz, int cnt)
-{
-	void *pStart;
-	if (db->lookaside.nOut) {
-		return SQL_BUSY;
-	}
-	/* Free any existing lookaside buffer for this handle before
-	 * allocating a new one so we don't have to have space for
-	 * both at the same time.
-	 */
-	if (db->lookaside.bMalloced) {
-		sql_free(db->lookaside.pStart);
-	}
-	/* The size of a lookaside slot after ROUNDDOWN8 needs to be larger
-	 * than a pointer to be useful.
-	 */
-	sz = ROUNDDOWN8(sz);	/* IMP: R-33038-09382 */
-	if (sz <= (int)sizeof(LookasideSlot *))
-		sz = 0;
-	if (cnt < 0)
-		cnt = 0;
-	if (sz == 0 || cnt == 0) {
-		sz = 0;
-		pStart = 0;
-	} else if (pBuf == 0) {
-		sqlBeginBenignMalloc();
-		pStart = sqlMalloc(sz * cnt);	/* IMP: R-61949-35727 */
-		sqlEndBenignMalloc();
-		if (pStart)
-			cnt = sqlMallocSize(pStart) / sz;
-	} else {
-		pStart = pBuf;
-	}
-	db->lookaside.pStart = pStart;
-	db->lookaside.pFree = 0;
-	db->lookaside.sz = (u16) sz;
-	if (pStart) {
-		int i;
-		LookasideSlot *p;
-		assert(sz > (int)sizeof(LookasideSlot *));
-		p = (LookasideSlot *) pStart;
-		for (i = cnt - 1; i >= 0; i--) {
-			p->pNext = db->lookaside.pFree;
-			db->lookaside.pFree = p;
-			p = (LookasideSlot *) & ((u8 *) p)[sz];
-		}
-		db->lookaside.pEnd = p;
-		db->lookaside.bDisable = 0;
-		db->lookaside.bMalloced = pBuf == 0 ? 1 : 0;
-	} else {
-		db->lookaside.pStart = db;
-		db->lookaside.pEnd = db;
-		db->lookaside.bDisable = 1;
-		db->lookaside.bMalloced = 0;
-	}
-	return SQL_OK;
-}
-
 void
 sql_row_count(struct sql_context *context, MAYBE_UNUSED int unused1,
 	      MAYBE_UNUSED sql_value **unused2)
@@ -551,10 +481,6 @@ sql_init_db(sql **out_db)
 	 */
 	sqlRegisterPerConnectionBuiltinFunctions(db);
 
-	/* Enable the lookaside-malloc subsystem */
-	setupLookaside(db, 0, sqlGlobalConfig.szLookaside,
-		       sqlGlobalConfig.nLookaside);
-
 opendb_out:
 	assert(db != 0 || rc == SQL_NOMEM);
 	if (rc == SQL_NOMEM)
diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index 5df4606..0a76b50 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -345,44 +345,19 @@ sql_malloc64(sql_uint64 n)
 }
 
 /*
- * TRUE if p is a lookaside memory allocation from db
- */
-static int
-isLookaside(sql * db, void *p)
-{
-	return SQL_WITHIN(p, db->lookaside.pStart, db->lookaside.pEnd);
-}
-
-/*
  * Return the size of a memory allocation previously obtained from
  * sqlMalloc() or sql_malloc().
  */
 int
 sqlMallocSize(void *p)
 {
-	assert(sqlMemdebugHasType(p, MEMTYPE_HEAP));
 	return sql_sized_sizeof(p);
 }
 
-int
-sqlDbMallocSize(sql * db, void *p)
+sql_uint64
+sql_msize(void *p)
 {
-	assert(p != 0);
-	if (db == 0 || !isLookaside(db, p)) {
-#if SQL_DEBUG
-		if (db == 0) {
-			assert(sqlMemdebugNoType(p, (u8) ~ MEMTYPE_HEAP));
-			assert(sqlMemdebugHasType(p, MEMTYPE_HEAP));
-		} else {
-			assert(sqlMemdebugHasType
-			       (p, (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP)));
-			assert(sqlMemdebugNoType
-			       (p, (u8) ~ (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP)));
-		}
-#endif
-		return sql_sized_sizeof(p);
-	} else
-		return db->lookaside.sz;
+	return p ? sql_sized_sizeof(p) : 0;
 }
 
 /*
@@ -393,8 +368,6 @@ sql_free(void *p)
 {
 	if (p == 0)
 		return;		/* IMP: R-49053-54554 */
-	assert(sqlMemdebugHasType(p, MEMTYPE_HEAP));
-	assert(sqlMemdebugNoType(p, (u8) ~ MEMTYPE_HEAP));
 	if (sqlGlobalConfig.bMemstat) {
 		sqlStatusDown(SQL_STATUS_MEMORY_USED,
 				  sqlMallocSize(p));
@@ -411,7 +384,7 @@ sql_free(void *p)
 static SQL_NOINLINE void
 measureAllocationSize(sql * db, void *p)
 {
-	*db->pnBytesFreed += sqlDbMallocSize(db, p);
+	*db->pnBytesFreed += sqlMallocSize(p);
 }
 
 /*
@@ -428,23 +401,7 @@ sqlDbFree(sql * db, void *p)
 			measureAllocationSize(db, p);
 			return;
 		}
-		if (isLookaside(db, p)) {
-			LookasideSlot *pBuf = (LookasideSlot *) p;
-#if SQL_DEBUG
-			/* Trash all content in the buffer being freed */
-			memset(p, 0xaa, db->lookaside.sz);
-#endif
-			pBuf->pNext = db->lookaside.pFree;
-			db->lookaside.pFree = pBuf;
-			db->lookaside.nOut--;
-			return;
-		}
 	}
-	assert(sqlMemdebugHasType(p, (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP)));
-	assert(sqlMemdebugNoType
-	       (p, (u8) ~ (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP)));
-	assert(db != 0 || sqlMemdebugNoType(p, MEMTYPE_LOOKASIDE));
-	sqlMemdebugSetType(p, MEMTYPE_HEAP);
 	sql_free(p);
 }
 
@@ -456,8 +413,6 @@ sqlRealloc(void *pOld, u64 nBytes)
 {
 	int nOld, nNew, nDiff;
 	void *pNew;
-	assert(sqlMemdebugHasType(pOld, MEMTYPE_HEAP));
-	assert(sqlMemdebugNoType(pOld, (u8) ~ MEMTYPE_HEAP));
 	if (pOld == 0) {
 		return sqlMalloc(nBytes);	/* IMP: R-04300-56712 */
 	}
@@ -535,27 +490,9 @@ sqlDbMallocZero(sql * db, u64 n)
 	return p;
 }
 
-/* Finish the work of sqlDbMallocRawNN for the unusual and
- * slower case when the allocation cannot be fulfilled using lookaside.
- */
-static SQL_NOINLINE void *
-dbMallocRawFinish(sql * db, u64 n)
-{
-	void *p;
-	assert(db != 0);
-	p = sqlMalloc(n);
-	if (!p)
-		sqlOomFault(db);
-	sqlMemdebugSetType(p,
-			       (db->lookaside.bDisable ==
-				0) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP);
-	return p;
-}
-
 /*
- * Allocate memory, either lookaside (if possible) or heap.
- * If the allocation fails, set the mallocFailed flag in
- * the connection pointer.
+ * Allocate heap memory. If the allocation fails, set the
+ * mallocFailed flag in the connection pointer.
  *
  * If db!=0 and db->mallocFailed is true (indicating a prior malloc
  * failure on the same database connection) then always return 0.
@@ -581,35 +518,19 @@ sqlDbMallocRaw(sql * db, u64 n)
 	if (db)
 		return sqlDbMallocRawNN(db, n);
 	p = sqlMalloc(n);
-	sqlMemdebugSetType(p, MEMTYPE_HEAP);
 	return p;
 }
 
 void *
 sqlDbMallocRawNN(sql * db, u64 n)
 {
-	LookasideSlot *pBuf;
-	assert(db != 0);
-	assert(db->pnBytesFreed == 0);
-	if (db->lookaside.bDisable == 0) {
-		assert(db->mallocFailed == 0);
-		if (n > db->lookaside.sz) {
-			db->lookaside.anStat[1]++;
-		} else if ((pBuf = db->lookaside.pFree) == 0) {
-			db->lookaside.anStat[2]++;
-		} else {
-			db->lookaside.pFree = pBuf->pNext;
-			db->lookaside.nOut++;
-			db->lookaside.anStat[0]++;
-			if (db->lookaside.nOut > db->lookaside.mxOut) {
-				db->lookaside.mxOut = db->lookaside.nOut;
-			}
-			return (void *)pBuf;
-		}
-	} else if (db->mallocFailed) {
-		return 0;
-	}
-	return dbMallocRawFinish(db, n);
+	assert(db != NULL && db->pnBytesFreed == NULL);
+	if (db->mallocFailed)
+		return NULL;
+	void *p = sqlMalloc(n);
+	if (p == NULL)
+		sqlOomFault(db);
+	return p;
 }
 
 /* Forward declaration */
@@ -625,8 +546,6 @@ sqlDbRealloc(sql * db, void *p, u64 n)
 	assert(db != 0);
 	if (p == 0)
 		return sqlDbMallocRawNN(db, n);
-	if (isLookaside(db, p) && n <= db->lookaside.sz)
-		return p;
 	return dbReallocFinish(db, p, n);
 }
 
@@ -637,27 +556,9 @@ dbReallocFinish(sql * db, void *p, u64 n)
 	assert(db != 0);
 	assert(p != 0);
 	if (db->mallocFailed == 0) {
-		if (isLookaside(db, p)) {
-			pNew = sqlDbMallocRawNN(db, n);
-			if (pNew) {
-				memcpy(pNew, p, db->lookaside.sz);
-				sqlDbFree(db, p);
-			}
-		} else {
-			assert(sqlMemdebugHasType
-			       (p, (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP)));
-			assert(sqlMemdebugNoType
-			       (p, (u8) ~ (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP)));
-			sqlMemdebugSetType(p, MEMTYPE_HEAP);
-			pNew = sql_realloc64(p, n);
-			if (!pNew) {
-				sqlOomFault(db);
-			}
-			sqlMemdebugSetType(pNew,
-					       (db->lookaside.bDisable ==
-						0 ? MEMTYPE_LOOKASIDE :
-						MEMTYPE_HEAP));
-		}
+		pNew = sql_realloc64(p, n);
+		if (!pNew)
+			sqlOomFault(db);
 	}
 	return pNew;
 }
@@ -719,17 +620,13 @@ sqlDbStrNDup(sql * db, const char *z, u64 n)
 
 /*
  * Call this routine to record the fact that an OOM (out-of-memory) error
- * has happened.  This routine will set db->mallocFailed, and also
- * temporarily disable the lookaside memory allocator and interrupt
- * any running VDBEs.
+ * has happened.  This routine will set db->mallocFailed.
  */
 void
 sqlOomFault(sql * db)
 {
-	if (db->mallocFailed == 0 && db->bBenignMalloc == 0) {
+	if (db->mallocFailed == 0 && db->bBenignMalloc == 0)
 		db->mallocFailed = 1;
-		db->lookaside.bDisable++;
-	}
 }
 
 /*
@@ -742,11 +639,8 @@ sqlOomFault(sql * db)
 void
 sqlOomClear(sql * db)
 {
-	if (db->mallocFailed && db->nVdbeExec == 0) {
+	if (db->mallocFailed && db->nVdbeExec == 0)
 		db->mallocFailed = 0;
-		assert(db->lookaside.bDisable > 0);
-		db->lookaside.bDisable--;
-	}
 }
 
 /*
diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y
index 7af5e7d..010feff 100644
--- a/src/box/sql/parse.y
+++ b/src/box/sql/parse.y
@@ -106,15 +106,6 @@ struct LimitVal {
 */
 struct TrigEvent { int a; IdList * b; };
 
-/*
-** Disable lookaside memory allocation for objects that might be
-** shared across database connections.
-*/
-static void disableLookaside(Parse *pParse){
-  pParse->disableLookaside++;
-  pParse->db->lookaside.bDisable++;
-}
-
 } // end %include
 
 // Input is a single SQL command
@@ -178,11 +169,10 @@ cmd ::= ROLLBACK TO savepoint_opt nm(X). {
 ///////////////////// The CREATE TABLE statement ////////////////////////////
 //
 cmd ::= create_table create_table_args.
-create_table ::= createkw TABLE ifnotexists(E) nm(Y). {
+create_table ::= CREATE TABLE ifnotexists(E) nm(Y). {
   create_table_def_init(&pParse->create_table_def, &Y, E);
   pParse->create_table_def.new_space = sqlStartTable(pParse, &Y);
 }
-createkw(A) ::= CREATE(A).  {disableLookaside(pParse);}
 
 %type ifnotexists {int}
 ifnotexists(A) ::= .              {A = 0;}
@@ -405,7 +395,7 @@ ifexists(A) ::= .            {A = 0;}
 
 ///////////////////// The CREATE VIEW statement /////////////////////////////
 //
-cmd ::= createkw(X) VIEW ifnotexists(E) nm(Y) eidlist_opt(C)
+cmd ::= CREATE(X) VIEW ifnotexists(E) nm(Y) eidlist_opt(C)
           AS select(S). {
   if (!pParse->parse_only) {
     create_view_def_init(&pParse->create_view_def, &Y, &X, C, S, E);
@@ -1405,7 +1395,7 @@ paren_exprlist(A) ::= LP exprlist(X) RP.  {A = X;}
 
 ///////////////////////////// The CREATE INDEX command ///////////////////////
 //
-cmd ::= createkw uniqueflag(U) INDEX ifnotexists(NE) nm(X)
+cmd ::= CREATE uniqueflag(U) INDEX ifnotexists(NE) nm(X)
         ON nm(Y) LP sortlist(Z) RP. {
   struct SrcList *src_list = sql_src_list_append(pParse->db,0,&Y);
   if (src_list == NULL) {
@@ -1508,7 +1498,7 @@ plus_num(A) ::= number(A).
 minus_num(A) ::= MINUS number(X).     {A = X;}
 //////////////////////////// The CREATE TRIGGER command /////////////////////
 
-cmd ::= createkw trigger_decl(A) BEGIN trigger_cmd_list(S) END(Z). {
+cmd ::= CREATE trigger_decl(A) BEGIN trigger_cmd_list(S) END(Z). {
   Token all;
   all.z = A.z;
   all.n = (int)(Z.z - A.z) + Z.n;
diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index 2b3ac29..4ac8698 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -295,12 +295,6 @@ sql_parser_destroy(Parse *parser)
 	sqlDbFree(db, parser->aLabel);
 	sql_expr_list_delete(db, parser->pConstExpr);
 	create_table_def_destroy(&parser->create_table_def);
-	if (db != NULL) {
-		assert(db->lookaside.bDisable >=
-		       parser->disableLookaside);
-		db->lookaside.bDisable -= parser->disableLookaside;
-	}
-	parser->disableLookaside = 0;
 	switch (parser->parsed_ast_type) {
 	case AST_TYPE_SELECT:
 		sql_select_delete(db, parser->parsed_ast.select);
diff --git a/src/box/sql/printf.c b/src/box/sql/printf.c
index a397b90..8abb673 100644
--- a/src/box/sql/printf.c
+++ b/src/box/sql/printf.c
@@ -864,7 +864,7 @@ sqlStrAccumEnlarge(StrAccum * p, int N)
 			if (!isMalloced(p) && p->nChar > 0)
 				memcpy(zNew, p->zText, p->nChar);
 			p->zText = zNew;
-			p->nAlloc = sqlDbMallocSize(p->db, zNew);
+			p->nAlloc = sqlMallocSize(zNew);
 			p->printfFlags |= SQL_PRINTF_MALLOCED;
 		} else {
 			sqlStrAccumReset(p);
@@ -989,9 +989,8 @@ sqlStrAccumReset(StrAccum * p)
  * Initialize a string accumulator.
  *
  * p:     The accumulator to be initialized.
- * db:    Pointer to a database connection.  May be NULL.  Lookaside
- *        memory is used if not NULL. db->mallocFailed is set appropriately
- *        when not NULL.
+ * db:    Pointer to a database connection.  May be NULL.
+ *        db->mallocFailed is set appropriately when not NULL.
  * zBase: An initial buffer.  May be NULL in which case the initial buffer
  *        is malloced.
  * n:     Size of zBase in bytes.  If total space requirements never exceed
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index 16a51ee..3b6b4b6 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -1994,10 +1994,6 @@ sqlResultSetOfSelect(Parse * pParse, Select * pSelect)
 	struct space *space = sql_ephemeral_space_new(pParse, NULL);
 	if (space == NULL)
 		return NULL;
-	/* The sqlResultSetOfSelect() is only used in contexts where lookaside
-	 * is disabled
-	 */
-	assert(db->lookaside.bDisable);
 	sqlColumnsFromExprList(pParse, pSelect->pEList, space->def);
 	sqlSelectAddColumnTypeAndCollation(pParse, space->def, pSelect);
 	if (db->mallocFailed)
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index ef0c566..559bcd9 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -178,16 +178,13 @@
 #endif
 
 #if defined(SQL_SYSTEM_MALLOC) \
-  + defined(SQL_ZERO_MALLOC) \
-  + defined(SQL_MEMDEBUG)>1
+  + defined(SQL_ZERO_MALLOC) > 1
 #error "Two or more of the following compile-time configuration options\
  are defined but at most one is allowed:\
- SQL_SYSTEM_MALLOC, SQL_MEMDEBUG,\
- SQL_ZERO_MALLOC"
+ SQL_SYSTEM_MALLOC, SQL_ZERO_MALLOC"
 #endif
 #if defined(SQL_SYSTEM_MALLOC) \
-  + defined(SQL_ZERO_MALLOC) \
-  + defined(SQL_MEMDEBUG)==0
+  + defined(SQL_ZERO_MALLOC) == 0
 #define SQL_SYSTEM_MALLOC 1
 #endif
 
@@ -726,20 +723,6 @@ const char *
 sql_uri_parameter(const char *zFilename,
 		      const char *zParam);
 
-#define SQL_DBSTATUS_LOOKASIDE_USED       0
-#define SQL_DBSTATUS_CACHE_USED           1
-#define SQL_DBSTATUS_SCHEMA_USED          2
-#define SQL_DBSTATUS_STMT_USED            3
-#define SQL_DBSTATUS_LOOKASIDE_HIT        4
-#define SQL_DBSTATUS_LOOKASIDE_MISS_SIZE  5
-#define SQL_DBSTATUS_LOOKASIDE_MISS_FULL  6
-#define SQL_DBSTATUS_CACHE_HIT            7
-#define SQL_DBSTATUS_CACHE_MISS           8
-#define SQL_DBSTATUS_CACHE_WRITE          9
-#define SQL_DBSTATUS_DEFERRED_FKS        10
-#define SQL_DBSTATUS_CACHE_USED_SHARED   11
-#define SQL_DBSTATUS_MAX                 11	/* Largest defined DBSTATUS */
-
 const char *
 sql_sql(sql_stmt * pStmt);
 
@@ -1155,8 +1138,6 @@ typedef struct FuncDef FuncDef;
 typedef struct FuncDefHash FuncDefHash;
 typedef struct IdList IdList;
 typedef struct KeyClass KeyClass;
-typedef struct Lookaside Lookaside;
-typedef struct LookasideSlot LookasideSlot;
 typedef struct NameContext NameContext;
 typedef struct Parse Parse;
 typedef struct PrintfArguments PrintfArguments;
@@ -1200,41 +1181,6 @@ typedef int VList;
 #define SQL_N_LIMIT (SQL_LIMIT_TRIGGER_DEPTH+1)
 
 /*
- * Lookaside malloc is a set of fixed-size buffers that can be used
- * to satisfy small transient memory allocation requests for objects
- * associated with a particular database connection.  The use of
- * lookaside malloc provides a significant performance enhancement
- * (approx 10%) by avoiding numerous malloc/free requests while parsing
- * SQL statements.
- *
- * The Lookaside structure holds configuration information about the
- * lookaside malloc subsystem.  Each available memory allocation in
- * the lookaside subsystem is stored on a linked list of LookasideSlot
- * objects.
- *
- * Lookaside allocations are only allowed for objects that are associated
- * with a particular database connection.  Hence, schema information cannot
- * be stored in lookaside because in shared cache mode the schema information
- * is shared by multiple database connections.  Therefore, while parsing
- * schema information, the Lookaside.bEnabled flag is cleared so that
- * lookaside allocations are not used to construct the schema objects.
- */
-struct Lookaside {
-	u32 bDisable;		/* Only operate the lookaside when zero */
-	u16 sz;			/* Size of each buffer in bytes */
-	u8 bMalloced;		/* True if pStart obtained from sql_malloc() */
-	int nOut;		/* Number of buffers currently checked out */
-	int mxOut;		/* Highwater mark for nOut */
-	int anStat[3];		/* 0: hits.  1: size misses.  2: full misses */
-	LookasideSlot *pFree;	/* List of available buffers */
-	void *pStart;		/* First byte of available memory space */
-	void *pEnd;		/* First byte past end of available space */
-};
-struct LookasideSlot {
-	LookasideSlot *pNext;	/* Next buffer in the list of free buffers */
-};
-
-/*
  * A hash table for built-in function definitions.  (Application-defined
  * functions use a regular table table from hash.h.)
  *
@@ -1286,7 +1232,6 @@ struct sql {
 	void *pUpdateArg;
 	void (*xUpdateCallback) (void *, int, const char *, const char *,
 				 sql_int64);
-	Lookaside lookaside;	/* Lookaside malloc configuration */
 	Hash aFunc;		/* Hash table of connection functions */
 	int *pnBytesFreed;	/* If not NULL, increment this in DbFree() */
 };
@@ -2392,7 +2337,6 @@ struct Parse {
 	u8 isMultiWrite;	/* True if statement may modify/insert multiple rows */
 	u8 hasCompound;		/* Need to invoke convertCompoundSelectToSubquery() */
 	u8 okConstFactor;	/* OK to factor out constants */
-	u8 disableLookaside;	/* Number of times lookaside has been disabled */
 	u8 nColCache;		/* Number of entries in aColCache[] */
 	int nRangeReg;		/* Size of the temporary register block */
 	int iRangeReg;		/* First register in temporary register block */
@@ -2667,7 +2611,7 @@ struct TriggerStep {
  * do not necessarily know how big the string will be in the end.
  */
 struct StrAccum {
-	sql *db;		/* Optional database for lookaside.  Can be NULL */
+	sql *db;		/* Database for temporary buffers. */
 	char *zBase;		/* A base allocation.  Not from malloc. */
 	char *zText;		/* The string collected so far */
 	u32 nChar;		/* Length of the string so far */
@@ -2695,8 +2639,6 @@ struct sqlConfig {
 	int bUseCis;		/* Use covering indices for full-scans */
 	int mxStrlen;		/* Maximum string length */
 	int neverCorrupt;	/* Database is always well-formed */
-	int szLookaside;	/* Default lookaside buffer size */
-	int nLookaside;		/* Default lookaside buffer count */
 	int nStmtSpill;		/* Stmt-journal spill-to-disk threshold */
 	void *pHeap;		/* Heap storage space */
 	int nHeap;		/* Size of pHeap[] */
@@ -2829,7 +2771,6 @@ void *sqlDbReallocOrFree(sql *, void *, u64);
 void *sqlDbRealloc(sql *, void *, u64);
 void sqlDbFree(sql *, void *);
 int sqlMallocSize(void *);
-int sqlDbMallocSize(sql *, void *);
 void sqlBenignMallocHooks(void (*)(void), void (*)(void));
 int sqlHeapNearlyFull(void);
 
@@ -4698,47 +4639,6 @@ int sqlExprCheckHeight(Parse *, int);
 void sqlParserTrace(FILE *, char *);
 #endif
 
-/*
- * These routines are available for the mem2.c debugging memory allocator
- * only.  They are used to verify that different "types" of memory
- * allocations are properly tracked by the system.
- *
- * sqlMemdebugSetType() sets the "type" of an allocation to one of
- * the MEMTYPE_* macros defined below.  The type must be a bitmask with
- * a single bit set.
- *
- * sqlMemdebugHasType() returns true if any of the bits in its second
- * argument match the type set by the previous sqlMemdebugSetType().
- * sqlMemdebugHasType() is intended for use inside assert() statements.
- *
- * sqlMemdebugNoType() returns true if none of the bits in its second
- * argument match the type set by the previous sqlMemdebugSetType().
- *
- * Perhaps the most important point is the difference between MEMTYPE_HEAP
- * and MEMTYPE_LOOKASIDE.  If an allocation is MEMTYPE_LOOKASIDE, that means
- * it might have been allocated by lookaside, except the allocation was
- * too large or lookaside was already full.  It is important to verify
- * that allocations that might have been satisfied by lookaside are not
- * passed back to non-lookaside free() routines.  Asserts such as the
- * example above are placed on the non-lookaside free() routines to verify
- * this constraint.
- *
- * All of this is no-op for a production build.  It only comes into
- * play when the sql_MEMDEBUG compile-time option is used.
- */
-#ifdef SQL_MEMDEBUG
-void sqlMemdebugSetType(void *, u8);
-int sqlMemdebugHasType(void *, u8);
-int sqlMemdebugNoType(void *, u8);
-#else
-#define sqlMemdebugSetType(X,Y)	/* no-op */
-#define sqlMemdebugHasType(X,Y)  1
-#define sqlMemdebugNoType(X,Y)   1
-#endif
-#define MEMTYPE_HEAP       0x01	/* General heap allocations */
-#define MEMTYPE_LOOKASIDE  0x02	/* Heap that might have been lookaside */
-
-
 int sqlExprVectorSize(Expr * pExpr);
 int sqlExprIsVector(Expr * pExpr);
 Expr *sqlVectorFieldSubexpr(Expr *, int);
diff --git a/src/box/sql/status.c b/src/box/sql/status.c
index bc170c8..950d5f4 100644
--- a/src/box/sql/status.c
+++ b/src/box/sql/status.c
@@ -158,140 +158,3 @@ sql_status(int op, int *pCurrent, int *pHighwater, int resetFlag)
 	}
 	return rc;
 }
-
-/*
- * Query status information for a single database connection
- */
-int
-sql_db_status(sql * db,	/* The database connection whose status is desired */
-		  int op,	/* Status verb */
-		  int *pCurrent,	/* Write current value here */
-		  int *pHighwater,	/* Write high-water mark here */
-		  int resetFlag	/* Reset high-water mark if true */
-    )
-{
-	int rc = SQL_OK;	/* Return code */
-	switch (op) {
-	case SQL_DBSTATUS_LOOKASIDE_USED:{
-			*pCurrent = db->lookaside.nOut;
-			*pHighwater = db->lookaside.mxOut;
-			if (resetFlag) {
-				db->lookaside.mxOut = db->lookaside.nOut;
-			}
-			break;
-		}
-
-	case SQL_DBSTATUS_LOOKASIDE_HIT:
-	case SQL_DBSTATUS_LOOKASIDE_MISS_SIZE:
-	case SQL_DBSTATUS_LOOKASIDE_MISS_FULL:{
-			testcase(op == SQL_DBSTATUS_LOOKASIDE_HIT);
-			testcase(op == SQL_DBSTATUS_LOOKASIDE_MISS_SIZE);
-			testcase(op == SQL_DBSTATUS_LOOKASIDE_MISS_FULL);
-			assert((op - SQL_DBSTATUS_LOOKASIDE_HIT) >= 0);
-			assert((op - SQL_DBSTATUS_LOOKASIDE_HIT) < 3);
-			*pCurrent = 0;
-			*pHighwater =
-			    db->lookaside.anStat[op -
-						 SQL_DBSTATUS_LOOKASIDE_HIT];
-			if (resetFlag) {
-				db->lookaside.anStat[op -
-						     SQL_DBSTATUS_LOOKASIDE_HIT]
-				    = 0;
-			}
-			break;
-		}
-
-		/*
-		 * Return an approximation for the amount of memory currently used
-		 * by all pagers associated with the given database connection.  The
-		 * highwater mark is meaningless and is returned as zero.
-		 */
-	case SQL_DBSTATUS_CACHE_USED_SHARED:
-	case SQL_DBSTATUS_CACHE_USED:{
-			int totalUsed = 0;
-			*pCurrent = totalUsed;
-			*pHighwater = 0;
-			break;
-		}
-
-		/*
-		 * *pCurrent gets an accurate estimate of the amount of memory used
-		 * to store the schema for database. *pHighwater is set to zero.
-		 */
-	case SQL_DBSTATUS_SCHEMA_USED:{
-			int nByte = 0;	/* Used to accumulate return value */
-
-			*pHighwater = 0;
-			*pCurrent = nByte;
-			break;
-		}
-
-		/*
-		 * *pCurrent gets an accurate estimate of the amount of memory used
-		 * to store all prepared statements.
-		 * *pHighwater is set to zero.
-		 */
-	case SQL_DBSTATUS_STMT_USED:{
-			struct Vdbe *pVdbe;	/* Used to iterate through VMs */
-			int nByte = 0;	/* Used to accumulate return value */
-
-			db->pnBytesFreed = &nByte;
-			for (pVdbe = db->pVdbe; pVdbe; pVdbe = pVdbe->pNext) {
-				sqlVdbeClearObject(db, pVdbe);
-				sqlDbFree(db, pVdbe);
-			}
-			db->pnBytesFreed = 0;
-
-			*pHighwater = 0;	/* IMP: R-64479-57858
-			*/
-			*pCurrent = nByte;
-
-			break;
-		}
-
-		/*
-		 * Set *pCurrent to the total cache hits or misses encountered by all
-		 * pagers the database handle is connected to. *pHighwater is always set
-		 * to zero.
-		 */
-	case SQL_DBSTATUS_CACHE_HIT:
-	case SQL_DBSTATUS_CACHE_MISS:
-	case SQL_DBSTATUS_CACHE_WRITE:{
-			int nRet = 0;
-			assert(SQL_DBSTATUS_CACHE_MISS ==
-			       SQL_DBSTATUS_CACHE_HIT + 1);
-			assert(SQL_DBSTATUS_CACHE_WRITE ==
-			       SQL_DBSTATUS_CACHE_HIT + 2);
-
-			*pHighwater = 0;	/* IMP: R-42420-56072
-			*/
-			/* IMP: R-54100-20147 */
-			/* IMP: R-29431-39229 */
-			*pCurrent = nRet;
-			break;
-		}
-
-		/* Set *pCurrent to non-zero if there are unresolved deferred foreign
-		 * key constraints.  Set *pCurrent to zero if all foreign key constraints
-		 * have been satisfied.  The *pHighwater is always set to zero.
-		 */
-	case SQL_DBSTATUS_DEFERRED_FKS:{
-			*pHighwater = 0;	/* IMP: R-11967-56545
-			*/
-			const struct txn *ptxn = in_txn();
-
-			if (!ptxn || !ptxn->psql_txn) {
-				*pCurrent = 0;
-				break;
-			}
-			const struct sql_txn *psql_txn = ptxn->psql_txn;
-			*pCurrent = psql_txn->fk_deferred_count > 0;
-			break;
-		}
-
-	default:{
-			rc = SQL_ERROR;
-		}
-	}
-	return rc;
-}
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 042e8eb..5f7e772 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -188,7 +188,7 @@ growOpArray(Vdbe * v, int nOp)
 	assert(nNew >= (p->nOpAlloc + nOp));
 	pNew = sqlDbRealloc(p->db, v->aOp, nNew * sizeof(Op));
 	if (pNew) {
-		p->szOpAlloc = sqlDbMallocSize(p->db, pNew);
+		p->szOpAlloc = sqlMallocSize(pNew);
 		p->nOpAlloc = p->szOpAlloc / sizeof(Op);
 		v->aOp = pNew;
 	}
diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
index 248f80b..3669336 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -70,7 +70,7 @@ sqlVdbeCheckMemInvariants(Mem * p)
 
 	/* The szMalloc field holds the correct memory allocation size */
 	assert(p->szMalloc == 0
-	       || p->szMalloc == sqlDbMallocSize(p->db, p->zMalloc));
+	       || p->szMalloc == sqlMallocSize(p->zMalloc));
 
 	/* If p holds a string or blob, the Mem.z must point to exactly
 	 * one of the following:
@@ -112,8 +112,7 @@ sqlVdbeMemGrow(Mem * pMem, int n, int bPreserve)
 	testcase(bPreserve && pMem->z == 0);
 
 	assert(pMem->szMalloc == 0
-	       || pMem->szMalloc == sqlDbMallocSize(pMem->db,
-							pMem->zMalloc));
+	       || pMem->szMalloc == sqlMallocSize(pMem->zMalloc));
 	if (pMem->szMalloc < n) {
 		if (n < 32)
 			n = 32;
@@ -132,8 +131,7 @@ sqlVdbeMemGrow(Mem * pMem, int n, int bPreserve)
 			pMem->szMalloc = 0;
 			return SQL_NOMEM;
 		} else {
-			pMem->szMalloc =
-			    sqlDbMallocSize(pMem->db, pMem->zMalloc);
+			pMem->szMalloc = sqlMallocSize(pMem->zMalloc);
 		}
 	}
 
@@ -1007,7 +1005,7 @@ sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
 	} else if (xDel == SQL_DYNAMIC) {
 		sqlVdbeMemRelease(pMem);
 		pMem->zMalloc = pMem->z = (char *)z;
-		pMem->szMalloc = sqlDbMallocSize(pMem->db, pMem->zMalloc);
+		pMem->szMalloc = sqlMallocSize(pMem->zMalloc);
 	} else {
 		sqlVdbeMemRelease(pMem);
 		pMem->z = (char *)z;
diff --git a/src/box/sql/whereexpr.c b/src/box/sql/whereexpr.c
index d30a710..a88f964 100644
--- a/src/box/sql/whereexpr.c
+++ b/src/box/sql/whereexpr.c
@@ -107,8 +107,7 @@ whereClauseInsert(WhereClause * pWC, Expr * p, u16 wtFlags)
 		if (pOld != pWC->aStatic) {
 			sqlDbFree(db, pOld);
 		}
-		pWC->nSlot =
-		    sqlDbMallocSize(db, pWC->a) / sizeof(pWC->a[0]);
+		pWC->nSlot = sqlMallocSize(pWC->a) / sizeof(pWC->a[0]);
 	}
 	pTerm = &pWC->a[idx = pWC->nTerm++];
 	if (p && ExprHasProperty(p, EP_Unlikely)) {
diff --git a/test/sql-tap/join.test.lua b/test/sql-tap/join.test.lua
index ef60609..f0ab16a 100755
--- a/test/sql-tap/join.test.lua
+++ b/test/sql-tap/join.test.lua
@@ -1072,13 +1072,6 @@ jointest("join-12.6", 66, {1, 'The number of tables in a join 66 exceeds the lim
 jointest("join-12.7", 127, {1, 'The number of tables in a join 127 exceeds the limit (64)'})
 jointest("join-12.8", 128, {1, 'The number of tables in a join 128 exceeds the limit (64)'})
 jointest("join-12.9", 1000, {1, 'The number of tables in a join 1000 exceeds the limit (64)'})
--- If sql is built with sql_MEMDEBUG, then the huge number of realloc()
--- calls made by the following test cases are too time consuming to run.
--- Without sql_MEMDEBUG, realloc() is fast enough that these are not
--- a problem.
---if X(0, "X!capable", [["pragma&&compileoption_diags"]]) then
---    if X(703, "X!cmd", [=[["expr","[lsearch [db eval {PRAGMA compile_options}] MEMDEBUG]<0"]]=])
--- then
 jointest("join-12.10", 65534, {1, 'The number of tables in a join 65534 exceeds the limit (64)'})
 jointest("join-12.11", 65535, {1, 'The number of tables in a join 65535 exceeds the limit (64)'})
 jointest("join-12.12", 65536, {1, 'The number of tables in a join 65536 exceeds the limit (64)'})
diff --git a/test/sql-tap/triggerA.test.lua b/test/sql-tap/triggerA.test.lua
index aa4771b..fac51ca 100755
--- a/test/sql-tap/triggerA.test.lua
+++ b/test/sql-tap/triggerA.test.lua
@@ -326,35 +326,4 @@ test:do_test(
         -- </triggerA-2.11>
     })
 
--- # Only run the reamining tests if memory debugging is turned on.
--- #
--- ifcapable !memdebug {
---    puts "Skipping triggerA malloc tests: not compiled with -Dsql_MEMDEBUG..."
---    finish_test
---    return
--- }
--- source $testdir/malloc_common.tcl
--- # Save a copy of the current database configuration.
--- #
--- db close
--- forcedelete test.db-triggerA
--- copy_file test.db test.db-triggerA
--- sql db test.db
--- # Run malloc tests on the INSTEAD OF trigger firing.
--- #
--- do_malloc_test triggerA-3 -tclprep {
---   db close
---   forcedelete test.db test.db-journal
---   forcecopy test.db-triggerA test.db
---   sql db test.db
---   sql_extended_result_codes db 1
---   db eval {SELECT * FROM v5; -- warm up the cache}
--- } -sqlbody {
---    DELETE FROM v5 WHERE x=5;
---    UPDATE v5 SET b=b+9900000 WHERE x BETWEEN 3 AND 5;
--- }
--- # Clean up the saved database copy.
--- #
--- forcedelete test.db-triggerA
 test:finish_test()
-

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 07/28] sql: remove SQL_OK error/status code
  2019-06-13 22:24   ` [tarantool-patches] " Vladislav Shpilevoy
@ 2019-06-15  9:52     ` Mergen Imeev
  0 siblings, 0 replies; 56+ messages in thread
From: Mergen Imeev @ 2019-06-15  9:52 UTC (permalink / raw)
  To: Vladislav Shpilevoy; +Cc: tarantool-patches

On Fri, Jun 14, 2019 at 12:24:47AM +0200, Vladislav Shpilevoy wrote:
> Thanks for the patch!
> 
> Consider my review fixes below and on the branch
> in a separate commit.
> 
Thank you! After rebase, he became a little shorter.
New patch:

From 58399d0aa831ad23385988ba6ddcc5e03bec50e3 Mon Sep 17 00:00:00 2001
Date: Tue, 21 May 2019 16:31:37 +0300
Subject: [PATCH] sql: remove SQL_OK error/status code

Removing this error/status code is part of getting rid of the SQL
error system.

diff --git a/src/box/bind.c b/src/box/bind.c
index f159153..90d56d6 100644
--- a/src/box/bind.c
+++ b/src/box/bind.c
@@ -205,7 +205,7 @@ sql_bind_column(struct sql_stmt *stmt, const struct sql_bind *p,
 	default:
 		unreachable();
 	}
-	if (rc == SQL_OK)
+	if (rc == 0)
 		return 0;
 
 	switch (rc) {
diff --git a/src/box/ck_constraint.c b/src/box/ck_constraint.c
index 543c8b3..1cde270 100644
--- a/src/box/ck_constraint.c
+++ b/src/box/ck_constraint.c
@@ -172,7 +172,7 @@ ck_constraint_program_run(struct ck_constraint *ck_constraint,
 	 * Get VDBE execution state and reset VM to run it
 	 * next time.
 	 */
-	return sql_reset(ck_constraint->stmt) != SQL_OK ? -1 : 0;
+	return sql_reset(ck_constraint->stmt);
 }
 
 void
diff --git a/src/box/execute.c b/src/box/execute.c
index e81cc32..64ed3d4 100644
--- a/src/box/execute.c
+++ b/src/box/execute.c
@@ -420,11 +420,11 @@ sql_execute(struct sql_stmt *stmt, struct port *port, struct region *region)
 					    port) != 0)
 				return -1;
 		}
-		assert(rc == SQL_DONE || rc != SQL_OK);
+		assert(rc == SQL_DONE || rc != 0);
 	} else {
 		/* No rows. Either DONE or ERROR. */
 		rc = sql_step(stmt);
-		assert(rc != SQL_ROW && rc != SQL_OK);
+		assert(rc != SQL_ROW && rc != 0);
 	}
 	if (rc != SQL_DONE)
 		return -1;
@@ -438,7 +438,7 @@ sql_prepare_and_execute(const char *sql, int len, const struct sql_bind *bind,
 {
 	struct sql_stmt *stmt;
 	struct sql *db = sql_get();
-	if (sql_prepare_v2(db, sql, len, &stmt, NULL) != SQL_OK)
+	if (sql_prepare_v2(db, sql, len, &stmt, NULL) != 0)
 		return -1;
 	assert(stmt != NULL);
 	port_sql_create(port, stmt);
diff --git a/src/box/sql.c b/src/box/sql.c
index ae92ba0..51f7b77 100644
--- a/src/box/sql.c
+++ b/src/box/sql.c
@@ -71,7 +71,7 @@ sql_init()
 
 	current_session()->sql_flags |= default_sql_flags;
 
-	if (sql_init_db(&db) != SQL_OK)
+	if (sql_init_db(&db) != 0)
 		panic("failed to initialize SQL subsystem");
 
 	assert(db != NULL);
@@ -86,7 +86,7 @@ sql_load_schema()
 	if (stat->def->field_count == 0)
 		return;
 	db->init.busy = 1;
-	if (sql_analysis_load(db) != SQL_OK) {
+	if (sql_analysis_load(db) != 0) {
 		if(!diag_is_empty(&fiber()->diag)) {
 			diag_log();
 		}
@@ -199,7 +199,7 @@ int tarantoolsqlNext(BtCursor *pCur, int *pRes)
 {
 	if (pCur->eState == CURSOR_INVALID) {
 		*pRes = 1;
-		return SQL_OK;
+		return 0;
 	}
 	assert(iterator_direction(pCur->iter_type) > 0);
 	return cursor_advance(pCur, pRes);
@@ -214,7 +214,7 @@ int tarantoolsqlPrevious(BtCursor *pCur, int *pRes)
 {
 	if (pCur->eState == CURSOR_INVALID) {
 		*pRes = 1;
-		return SQL_OK;
+		return 0;
 	}
 	assert(iterator_direction(pCur->iter_type) < 0);
 	return cursor_advance(pCur, pRes);
@@ -292,12 +292,11 @@ int tarantoolsqlMovetoUnpacked(BtCursor *pCur, UnpackedRecord *pIdxKey,
 }
 
 /*
- * Count number of tuples in ephemeral space and write it to pnEntry.
+ * Count number of tuples in ephemeral space.
  *
  * @param pCur Cursor which will point to ephemeral space.
- * @param[out] pnEntry Number of tuples in ephemeral space.
  *
- * @retval SQL_OK
+ * @retval Number of tuples in ephemeral space.
  */
 int64_t
 tarantoolsqlEphemeralCount(struct BtCursor *pCur)
@@ -385,7 +384,7 @@ int tarantoolsqlEphemeralInsert(struct space *space, const char *tuple,
 	mp_tuple_assert(tuple, tuple_end);
 	if (space_ephemeral_replace(space, tuple, tuple_end) != 0)
 		return SQL_TARANTOOL_ERROR;
-	return SQL_OK;
+	return 0;
 }
 
 /* Simply delete ephemeral space by calling space_delete(). */
@@ -395,7 +394,7 @@ int tarantoolsqlEphemeralDrop(BtCursor *pCur)
 	assert(pCur->curFlags & BTCF_TEphemCursor);
 	space_delete(pCur->space);
 	pCur->space = NULL;
-	return SQL_OK;
+	return 0;
 }
 
 static inline int
@@ -411,7 +410,7 @@ insertOrReplace(struct space *space, const char *tuple, const char *tuple_end,
 	request.type = type;
 	mp_tuple_assert(request.tuple, request.tuple_end);
 	int rc = box_process_rw(&request, space, NULL);
-	return rc == 0 ? SQL_OK : SQL_TARANTOOL_ERROR;
+	return rc == 0 ? 0 : SQL_TARANTOOL_ERROR;
 }
 
 int tarantoolsqlInsert(struct space *space, const char *tuple,
@@ -432,7 +431,7 @@ int tarantoolsqlReplace(struct space *space, const char *tuple,
  *
  * @param pCur Cursor pointing to ephemeral space.
  *
- * @retval SQL_OK on success, SQL_TARANTOOL_ERROR otherwise.
+ * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise.
  */
 int tarantoolsqlEphemeralDelete(BtCursor *pCur)
 {
@@ -453,7 +452,7 @@ int tarantoolsqlEphemeralDelete(BtCursor *pCur)
 		diag_log();
 		return SQL_TARANTOOL_ERROR;
 	}
-	return SQL_OK;
+	return 0;
 }
 
 int tarantoolsqlDelete(BtCursor *pCur, u8 flags)
@@ -476,7 +475,7 @@ int tarantoolsqlDelete(BtCursor *pCur, u8 flags)
 	rc = sql_delete_by_key(pCur->space, pCur->index->def->iid, key,
 			       key_size);
 
-	return rc == 0 ? SQL_OK : SQL_TARANTOOL_ERROR;
+	return rc == 0 ? 0 : SQL_TARANTOOL_ERROR;
 }
 
 int
@@ -494,7 +493,7 @@ sql_delete_by_key(struct space *space, uint32_t iid, char *key,
 	assert(space_index(space, iid)->def->opts.is_unique);
 	int rc = box_process_rw(&request, space, &unused);
 
-	return rc == 0 ? SQL_OK : SQL_TARANTOOL_ERROR;
+	return rc == 0 ? 0 : SQL_TARANTOOL_ERROR;
 }
 
 /*
@@ -504,7 +503,7 @@ sql_delete_by_key(struct space *space, uint32_t iid, char *key,
  *
  * @param pCur Cursor pointing to ephemeral space.
  *
- * @retval SQL_OK on success, SQL_TARANTOOL_ERROR otherwise.
+ * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise.
  */
 int tarantoolsqlEphemeralClearTable(BtCursor *pCur)
 {
@@ -533,7 +532,7 @@ int tarantoolsqlEphemeralClearTable(BtCursor *pCur)
 	}
 	iterator_delete(it);
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -569,7 +568,7 @@ int tarantoolsqlClearTable(struct space *space, uint32_t *tuple_count)
 	}
 	iterator_delete(iter);
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -849,7 +848,7 @@ key_alloc(BtCursor *cur, size_t key_size)
  * @param key Start of buffer containing key.
  * @param key_end End of buffer containing key.
  *
- * @retval SQL_OK on success, SQL_TARANTOOL_ERROR otherwise.
+ * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise.
  */
 static int
 cursor_seek(BtCursor *pCur, int *pRes)
@@ -895,7 +894,7 @@ cursor_seek(BtCursor *pCur, int *pRes)
  * @param pCur Cursor which contains space and tuple.
  * @param[out] pRes Flag which is 0 if reached end of space, 1 otherwise.
  *
- * @retval SQL_OK on success, SQL_TARANTOOL_ERROR otherwise.
+ * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise.
  */
 static int
 cursor_advance(BtCursor *pCur, int *pRes)
@@ -915,7 +914,7 @@ cursor_advance(BtCursor *pCur, int *pRes)
 		*pRes = 1;
 	}
 	pCur->last_tuple = tuple;
-	return SQL_OK;
+	return 0;
 }
 
 /*********************************************************************
diff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c
index 4106bce..410d9e8 100644
--- a/src/box/sql/analyze.c
+++ b/src/box/sql/analyze.c
@@ -1518,7 +1518,7 @@ load_stat_from_space(struct sql *db, const char *sql_select_prepare,
 		stats[current_idx_count].sample_count++;
 	}
 	rc = sql_finalize(stmt);
-	if (rc == SQL_OK && prev_index != NULL)
+	if (rc == 0 && prev_index != NULL)
 		init_avg_eq(prev_index, &stats[current_idx_count]);
 	assert(current_idx_count <= index_count);
 	for (uint32_t i = 0; i < current_idx_count; ++i) {
diff --git a/src/box/sql/cursor.c b/src/box/sql/cursor.c
index 2187b90..bb2dae8 100644
--- a/src/box/sql/cursor.c
+++ b/src/box/sql/cursor.c
@@ -93,12 +93,8 @@ sqlCursorIsValidNN(BtCursor *pCur)
  *
  * For sqlCursorPayload(), the caller must ensure that pCur is pointing
  * to a valid row in the table.
- *
- * Return SQL_OK on success or an error code if anything goes
- * wrong.  An error is returned if "offset+amt" is larger than
- * the available payload.
  */
-int
+void
 sqlCursorPayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf)
 {
 	assert(pCur->eState == CURSOR_VALID);
@@ -110,7 +106,6 @@ sqlCursorPayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf)
 	pPayload = tarantoolsqlPayloadFetch(pCur, &sz);
 	assert((uptr) (offset + amt) <= sz);
 	memcpy(pBuf, pPayload + offset, amt);
-	return SQL_OK;
 }
 
 /* Move the cursor so that it points to an entry near the key
diff --git a/src/box/sql/cursor.h b/src/box/sql/cursor.h
index e5c49d7..88e5441 100644
--- a/src/box/sql/cursor.h
+++ b/src/box/sql/cursor.h
@@ -64,7 +64,8 @@ int sqlCursorMovetoUnpacked(BtCursor *, UnpackedRecord * pUnKey, int *pRes);
 
 int sqlCursorNext(BtCursor *, int *pRes);
 int sqlCursorPrevious(BtCursor *, int *pRes);
-int sqlCursorPayload(BtCursor *, u32 offset, u32 amt, void *);
+void
+sqlCursorPayload(BtCursor *, u32 offset, u32 amt, void *);
 
 /**
  * Release tuple, free iterator, invalidate cursor's state.
diff --git a/src/box/sql/date.c b/src/box/sql/date.c
index f2a2c16..4812a0a 100644
--- a/src/box/sql/date.c
+++ b/src/box/sql/date.c
@@ -576,7 +576,7 @@ osLocaltime(time_t * t, struct tm *pTm)
 /*
  * Compute the difference (in milliseconds) between localtime and UTC
  * (a.k.a. GMT) for the time value p where p is in UTC. If no error occurs,
- * return this value and set *pRc to SQL_OK.
+ * return this value and set *pRc to 0.
  *
  * Or, if an error does occur, set *pRc to SQL_ERROR. The returned value
  * is undefined in this case.
@@ -584,7 +584,7 @@ osLocaltime(time_t * t, struct tm *pTm)
 static sql_int64
 localtimeOffset(DateTime * p,	/* Date at which to calculate offset */
 		sql_context * pCtx,	/* Write error here if one occurs */
-		int *pRc	/* OUT: Error code. SQL_OK or ERROR */
+		int *pRc	/* OUT: Error code. 0 or ERROR */
     )
 {
 	DateTime x, y;
@@ -635,7 +635,7 @@ localtimeOffset(DateTime * p,	/* Date at which to calculate offset */
 	y.validTZ = 0;
 	y.isError = 0;
 	computeJD(&y);
-	*pRc = SQL_OK;
+	*pRc = 0;
 	return y.iJD - x.iJD;
 }
 #endif				/* SQL_OMIT_LOCALTIME */
@@ -736,7 +736,7 @@ parseModifier(sql_context * pCtx,	/* Function context */
 					sql_int64 c1;
 					computeJD(p);
 					c1 = localtimeOffset(p, pCtx, &rc);
-					if (rc == SQL_OK) {
+					if (rc == 0) {
 						p->iJD -= c1;
 						clearYMD_HMS_TZ(p);
 						p->iJD +=
@@ -746,7 +746,7 @@ parseModifier(sql_context * pCtx,	/* Function context */
 					}
 					p->tzSet = 1;
 				} else {
-					rc = SQL_OK;
+					rc = 0;
 				}
 			}
 #endif
diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c
index 3263cb2..4a49ec6 100644
--- a/src/box/sql/expr.c
+++ b/src/box/sql/expr.c
@@ -4340,7 +4340,7 @@ sqlExprCodeTarget(Parse * pParse, Expr * pExpr, int target)
 		}
 		assert(!ExprHasProperty(pExpr, EP_IntValue));
 		if (pExpr->on_conflict_action == ON_CONFLICT_ACTION_IGNORE) {
-			sqlVdbeAddOp4(v, OP_Halt, SQL_OK,
+			sqlVdbeAddOp4(v, OP_Halt, 0,
 					  ON_CONFLICT_ACTION_IGNORE, 0,
 					  pExpr->u.zToken, 0);
 		} else {
diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index ec4f76d..7b3c20e 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -1181,7 +1181,7 @@ zeroblobFunc(sql_context * context, int argc, sql_value ** argv)
 	n = sql_value_int64(argv[0]);
 	if (n < 0)
 		n = 0;
-	if (sql_result_zeroblob64(context, n) != SQL_OK) {
+	if (sql_result_zeroblob64(context, n) != 0) {
 		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob too big");
 		context->is_aborted = true;
 	}
@@ -1772,7 +1772,7 @@ static inline int
 sql_overload_function(sql * db, const char *zName,
 			  enum field_type type, int nArg)
 {
-	int rc = SQL_OK;
+	int rc = 0;
 
 	if (sqlFindFunction(db, zName, nArg, 0) == 0) {
 		rc = sqlCreateFunc(db, zName, type, nArg, 0, 0,
@@ -1791,7 +1791,7 @@ void
 sqlRegisterPerConnectionBuiltinFunctions(sql * db)
 {
 	int rc = sql_overload_function(db, "MATCH", FIELD_TYPE_SCALAR, 2);
-	assert(rc == SQL_NOMEM || rc == SQL_OK);
+	assert(rc == SQL_NOMEM || rc == 0);
 	if (rc == SQL_NOMEM) {
 		sqlOomFault(db);
 	}
diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c
index 3ea12dd..f0a2e3d 100644
--- a/src/box/sql/insert.c
+++ b/src/box/sql/insert.c
@@ -1246,7 +1246,7 @@ xferOptimization(Parse * pParse,	/* Parser context */
 	sqlReleaseTempReg(pParse, regTupleid);
 	sqlReleaseTempReg(pParse, regData);
 	if (emptyDestTest) {
-		sqlVdbeAddOp2(v, OP_Halt, SQL_OK, 0);
+		sqlVdbeAddOp2(v, OP_Halt, 0, 0);
 		sqlVdbeJumpHere(v, emptyDestTest);
 		sqlVdbeAddOp2(v, OP_Close, iDest, 0);
 		return 0;
diff --git a/src/box/sql/legacy.c b/src/box/sql/legacy.c
index 1a3804e..42fd3d1 100644
--- a/src/box/sql/legacy.c
+++ b/src/box/sql/legacy.c
@@ -58,7 +58,7 @@ sql_exec(sql * db,	/* The database on which the SQL executes */
     )
 {
 	(void)pzErrMsg;
-	int rc = SQL_OK;	/* Return code */
+	int rc = 0;	/* Return code */
 	const char *zLeftover;	/* Tail of unprocessed SQL */
 	sql_stmt *pStmt = 0;	/* The current SQL statement */
 	char **azCols = 0;	/* Names of result columns */
@@ -68,16 +68,15 @@ sql_exec(sql * db,	/* The database on which the SQL executes */
 	if (zSql == 0)
 		zSql = "";
 
-	while (rc == SQL_OK && zSql[0]) {
+	while (rc == 0 && zSql[0] != 0) {
 		int nCol;
 		char **azVals = 0;
 
 		pStmt = 0;
 		rc = sql_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
-		assert(rc == SQL_OK || pStmt == 0);
-		if (rc != SQL_OK) {
+		assert(rc == 0 || pStmt == NULL);
+		if (rc != 0)
 			continue;
-		}
 		if (!pStmt) {
 			/* this happens for a comment or white-space */
 			zSql = zLeftover;
@@ -163,7 +162,7 @@ sql_exec(sql * db,	/* The database on which the SQL executes */
 	sqlDbFree(db, azCols);
 
 	rc = sqlApiExit(db, rc);
-	assert(rc == SQL_OK);
+	assert(rc == 0);
 	assert((rc & db->errMask) == rc);
 	return rc;
 }
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index 3004ae7..1a25dde 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -89,7 +89,7 @@ char *sql_data_directory = 0;
 int
 sql_initialize(void)
 {
-	int rc = SQL_OK;
+	int rc = 0;
 
 	/* If the following assert() fails on some obscure processor/compiler
 	 * combination, the work-around is to set the correct pointer
@@ -103,17 +103,17 @@ sql_initialize(void)
 	 * of this routine.
 	 */
 	if (sqlGlobalConfig.isInit)
-		return SQL_OK;
+		return 0;
 
 	if (!sqlGlobalConfig.isMallocInit)
 		sqlMallocInit();
-	if (rc == SQL_OK)
+	if (rc == 0)
 		sqlGlobalConfig.isMallocInit = 1;
 
-	/* If rc is not SQL_OK at this point, then the malloc
+	/* If rc is not 0 at this point, then the malloc
 	 * subsystem could not be initialized.
 	 */
-	if (rc != SQL_OK)
+	if (rc != 0)
 		return rc;
 
 	/* Do the rest of the initialization
@@ -134,12 +134,8 @@ sql_initialize(void)
 		memset(&sqlBuiltinFunctions, 0,
 		       sizeof(sqlBuiltinFunctions));
 		sqlRegisterBuiltinFunctions();
-		if (rc == SQL_OK) {
-			rc = sqlOsInit();
-		}
-		if (rc == SQL_OK) {
-			sqlGlobalConfig.isInit = 1;
-		}
+		sql_os_init();
+		sqlGlobalConfig.isInit = 1;
 		sqlGlobalConfig.inProgress = 0;
 	}
 
@@ -150,17 +146,14 @@ sql_initialize(void)
 	 */
 #ifndef NDEBUG
 	/* This section of code's only "output" is via assert() statements. */
-	if (rc == SQL_OK) {
-		u64 x = (((u64) 1) << 63) - 1;
-		double y;
-		assert(sizeof(x) == 8);
-		assert(sizeof(x) == sizeof(y));
-		memcpy(&y, &x, 8);
-		assert(sqlIsNaN(y));
-	}
+	u64 x = (((u64) 1) << 63) - 1;
+	double y;
+	assert(sizeof(x) == 8);
+	assert(sizeof(x) == sizeof(y));
+	memcpy(&y, &x, 8);
+	assert(sqlIsNaN(y));
 #endif
-
-	return rc;
+	return 0;
 }
 
 void
@@ -202,7 +195,7 @@ functionDestroy(sql * db, FuncDef * p)
 }
 
 /*
- * Rollback all database files.  If tripCode is not SQL_OK, then
+ * Rollback all database files.  If tripCode is not 0, then
  * any write cursors are invalidated ("tripped" - as in "tripping a circuit
  * breaker") and made to return tripCode if there are any further
  * attempts to use that cursor.  Read cursors remain open and valid
@@ -293,7 +286,7 @@ sqlCreateFunc(sql * db,
 	p->pUserData = pUserData;
 	p->nArg = (u16) nArg;
 	p->ret_type = type;
-	return SQL_OK;
+	return 0;
 }
 
 int
@@ -328,7 +321,7 @@ sql_create_function_v2(sql * db,
 	rc = sqlCreateFunc(db, zFunc, type, nArg, flags, p, xSFunc, xStep,
 			       xFinal, pArg);
 	if (pArg && pArg->nRef == 0) {
-		assert(rc != SQL_OK);
+		assert(rc != 0);
 		xDestroy(p);
 		sqlDbFree(db, pArg);
 	}
@@ -485,7 +478,7 @@ opendb_out:
 	assert(db != 0 || rc == SQL_NOMEM);
 	if (rc == SQL_NOMEM)
 		db = NULL;
-	else if (rc != SQL_OK)
+	else if (rc != 0)
 		db->magic = SQL_MAGIC_SICK;
 
 	*out_db = db;
diff --git a/src/box/sql/os.c b/src/box/sql/os.c
index a060675..10b68c8 100644
--- a/src/box/sql/os.c
+++ b/src/box/sql/os.c
@@ -90,7 +90,7 @@ sqlOsFetch(MAYBE_UNUSED sql_file * id,
 	       MAYBE_UNUSED int iAmt, void **pp)
 {
 	*pp = 0;
-	return SQL_OK;
+	return 0;
 }
 
 int
@@ -98,7 +98,7 @@ sqlOsUnfetch(MAYBE_UNUSED sql_file * id,
 		 MAYBE_UNUSED i64 iOff,
 		 MAYBE_UNUSED void *p)
 {
-	return SQL_OK;
+	return 0;
 }
 #endif
 
@@ -118,7 +118,7 @@ sqlOsOpen(sql_vfs * pVfs,
 	 * reaching the VFS.
 	 */
 	rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x87f7f, pFlagsOut);
-	assert(rc == SQL_OK || pFile->pMethods == 0);
+	assert(rc == 0 || pFile->pMethods == 0);
 	return rc;
 }
 
@@ -158,7 +158,7 @@ sqlOsOpenMalloc(sql_vfs * pVfs,
 	pFile = (sql_file *) sqlMallocZero(pVfs->szOsFile);
 	if (pFile) {
 		rc = sqlOsOpen(pVfs, zFile, pFile, flags, pOutFlags);
-		if (rc != SQL_OK) {
+		if (rc != 0) {
 			sql_free(pFile);
 		} else {
 			*ppFile = pFile;
@@ -178,22 +178,6 @@ sqlOsCloseFree(sql_file * pFile)
 }
 
 /*
- * This function is a wrapper around the OS specific implementation of
- * sql_os_init(). The purpose of the wrapper is to provide the
- * ability to simulate a malloc failure, so that the handling of an
- * error in sql_os_init() by the upper layers can be tested.
- */
-int
-sqlOsInit(void)
-{
-	void *p = sql_malloc(10);
-	if (p == 0)
-		return SQL_NOMEM;
-	sql_free(p);
-	return sql_os_init();
-}
-
-/*
  * The list of all registered VFS implementations.
  */
 static sql_vfs *SQL_WSD vfsList = 0;
@@ -255,5 +239,5 @@ sql_vfs_register(sql_vfs * pVfs, int makeDflt)
 		vfsList->pNext = pVfs;
 	}
 	assert(vfsList);
-	return SQL_OK;
+	return 0;
 }
diff --git a/src/box/sql/os.h b/src/box/sql/os.h
index 9122e9c..3c891f3 100644
--- a/src/box/sql/os.h
+++ b/src/box/sql/os.h
@@ -127,11 +127,6 @@
 #define SHARED_SIZE       510
 
 /*
- * Wrapper around OS specific sql_os_init() function.
- */
-int sqlOsInit(void);
-
-/*
  * Functions for accessing sql_file methods
  */
 void sqlOsClose(sql_file *);
diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index e0a2805..ccc8d35 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -486,7 +486,7 @@ findInodeInfo(unixFile * pFile,	/* Unix file with file desc used in the key */
 		pInode->nRef++;
 	}
 	*ppInode = pInode;
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -625,13 +625,13 @@ posixUnlock(sql_file * id, int eFileLock, int handleNFSUnlock)
 	unixFile *pFile = (unixFile *) id;
 	unixInodeInfo *pInode;
 	struct flock lock;
-	int rc = SQL_OK;
+	int rc = 0;
 
 	assert(pFile);
 
 	assert(eFileLock <= SHARED_LOCK);
 	if (pFile->eFileLock <= eFileLock) {
-		return SQL_OK;
+		return 0;
 	}
 	pInode = pFile->pInode;
 	assert(pInode->nShared != 0);
@@ -714,7 +714,7 @@ posixUnlock(sql_file * id, int eFileLock, int handleNFSUnlock)
 	}
 
  end_unlock:
-	if (rc == SQL_OK)
+	if (rc == 0)
 		pFile->eFileLock = eFileLock;
 	return rc;
 }
@@ -755,7 +755,7 @@ closeUnixFile(sql_file * id)
 	}
 	sql_free(pFile->pUnused);
 	memset(pFile, 0, sizeof(unixFile));
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -862,7 +862,7 @@ seekAndRead(unixFile * id, sql_int64 offset, void *pBuf, int cnt)
 }
 
 /*
- * Read data from a file into a buffer.  Return SQL_OK if all
+ * Read data from a file into a buffer.  Return 0 if all
  * bytes were read successfully and SQL_IOERR if anything goes
  * wrong.
  */
@@ -883,7 +883,7 @@ unixRead(sql_file * id, void *pBuf, int amt, sql_int64 offset)
 		if (offset + amt <= pFile->mmapSize) {
 			memcpy(pBuf, &((u8 *) (pFile->pMapRegion))[offset],
 			       amt);
-			return SQL_OK;
+			return 0;
 		} else {
 			int nCopy = pFile->mmapSize - offset;
 			memcpy(pBuf, &((u8 *) (pFile->pMapRegion))[offset],
@@ -897,7 +897,7 @@ unixRead(sql_file * id, void *pBuf, int amt, sql_int64 offset)
 
 	got = seekAndRead(pFile, offset, pBuf, amt);
 	if (got == amt) {
-		return SQL_OK;
+		return 0;
 	} else if (got < 0) {
 		/* lastErrno set by seekAndRead */
 		return SQL_IOERR_READ;
@@ -958,7 +958,7 @@ seekAndWrite(unixFile * id, i64 offset, const void *pBuf, int cnt)
 }
 
 /*
- * Write data from a buffer into a file.  Return SQL_OK on success
+ * Write data from a buffer into a file.  Return 0 on success
  * or some other error code on failure.
  */
 static int
@@ -986,13 +986,13 @@ unixWrite(sql_file * id, const void *pBuf, int amt, sql_int64 offset)
 		}
 	}
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
  * Open a file descriptor to the directory containing file zFilename.
  * If successful, *pFd is set to the opened file descriptor and
- * SQL_OK is returned. If an error occurs, either SQL_NOMEM
+ * 0 is returned. If an error occurs, either SQL_NOMEM
  * or SQL_CANTOPEN is returned and *pFd is set to an undefined
  * value.
  *
@@ -1006,10 +1006,10 @@ unixWrite(sql_file * id, const void *pBuf, int amt, sql_int64 offset)
  * chromium sandbox.  Opening a directory is a security risk (we are
  * told) so making it overrideable allows the chromium sandbox to
  * replace this routine with a harmless no-op.  To make this routine
- * a no-op, replace it with a stub that returns SQL_OK but leaves
+ * a no-op, replace it with a stub that returns 0 but leaves
  * *pFd set to a negative number.
  *
- * If SQL_OK is returned, the caller is responsible for closing
+ * If 0 is returned, the caller is responsible for closing
  * the file descriptor *pFd using close().
  */
 static int
@@ -1032,7 +1032,7 @@ openDirectory(const char *zFilename, int *pFd)
 
 	*pFd = fd;
 	if (fd >= 0)
-		return SQL_OK;
+		return 0;
 	return unixLogError(SQL_CANTOPEN, "openDirectory", zDirname);
 }
 
@@ -1087,7 +1087,7 @@ fcntlSizeHint(unixFile * pFile, i64 nByte)
 		return rc;
 	}
 
-	return SQL_OK;
+	return 0;
 }
 
 /* Forward declaration */
@@ -1103,15 +1103,15 @@ unixFileControl(sql_file * id, int op, void *pArg)
 	switch (op) {
 	case SQL_FCNTL_LOCKSTATE:{
 			*(int *)pArg = pFile->eFileLock;
-			return SQL_OK;
+			return 0;
 		}
 	case SQL_FCNTL_LAST_ERRNO:{
 			*(int *)pArg = pFile->lastErrno;
-			return SQL_OK;
+			return 0;
 		}
 	case SQL_FCNTL_CHUNK_SIZE:{
 			pFile->szChunk = *(int *)pArg;
-			return SQL_OK;
+			return 0;
 		}
 	case SQL_FCNTL_SIZE_HINT:{
 			int rc;
@@ -1121,7 +1121,7 @@ unixFileControl(sql_file * id, int op, void *pArg)
 	case SQL_FCNTL_VFSNAME:{
 			*(char **)pArg =
 			    sql_mprintf("%s", pFile->pVfs->zName);
-			return SQL_OK;
+			return 0;
 		}
 	case SQL_FCNTL_TEMPFILENAME:{
 			char *zTFile =
@@ -1131,15 +1131,15 @@ unixFileControl(sql_file * id, int op, void *pArg)
 						zTFile);
 				*(char **)pArg = zTFile;
 			}
-			return SQL_OK;
+			return 0;
 		}
 	case SQL_FCNTL_HAS_MOVED:{
 			*(int *)pArg = fileHasMoved(pFile);
-			return SQL_OK;
+			return 0;
 		}
 	case SQL_FCNTL_MMAP_SIZE:{
 			i64 newLimit = *(i64 *) pArg;
-			int rc = SQL_OK;
+			int rc = 0;
 			if (newLimit > sqlGlobalConfig.mxMmap) {
 				newLimit = sqlGlobalConfig.mxMmap;
 			}
@@ -1241,7 +1241,7 @@ unixRemapfile(unixFile * pFd,	/* File descriptor object */
 	if (pNew == MAP_FAILED) {
 		pNew = 0;
 		nNew = 0;
-		unixLogError(SQL_OK, zErr, pFd->zPath);
+		unixLogError(0, zErr, pFd->zPath);
 
 		/* If the mmap() above failed, assume that all subsequent mmap() calls
 		 * will probably fail too. Fall back to using xRead/xWrite exclusively
@@ -1265,7 +1265,7 @@ unixRemapfile(unixFile * pFd,	/* File descriptor object */
  * created mapping is either the requested size or the value configured
  * using SQL_FCNTL_MMAP_LIMIT, whichever is smaller.
  *
- * SQL_OK is returned if no error occurs (even if the mapping is not
+ * 0 is returned if no error occurs (even if the mapping is not
  * recreated as a result of outstanding references) or an sql error
  * code otherwise.
  */
@@ -1275,7 +1275,7 @@ unixMapfile(unixFile * pFd, i64 nMap)
 	assert(nMap >= 0 || pFd->nFetchOut == 0);
 	assert(nMap > 0 || (pFd->mmapSize == 0 && pFd->pMapRegion == 0));
 	if (pFd->nFetchOut > 0)
-		return SQL_OK;
+		return 0;
 
 	if (nMap < 0) {
 		struct stat statbuf;	/* Low-level file information */
@@ -1292,15 +1292,15 @@ unixMapfile(unixFile * pFd, i64 nMap)
 		unixRemapfile(pFd, nMap);
 	}
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
  * If possible, return a pointer to a mapping of file fd starting at offset
  * iOff. The mapping must be valid for at least nAmt bytes.
  *
- * If such a pointer can be obtained, store it in *pp and return SQL_OK.
- * Or, if one cannot but no error occurs, set *pp to 0 and return SQL_OK.
+ * If such a pointer can be obtained, store it in *pp and return 0.
+ * Or, if one cannot but no error occurs, set *pp to 0 and return 0.
  * Finally, if an error does occur, return an sql error code. The final
  * value of *pp is undefined in this case.
  *
@@ -1321,7 +1321,7 @@ unixFetch(sql_file * fd MAYBE_UNUSED,
 	if (pFd->mmapSizeMax > 0) {
 		if (pFd->pMapRegion == 0) {
 			int rc = unixMapfile(pFd, -1);
-			if (rc != SQL_OK)
+			if (rc != 0)
 				return rc;
 		}
 		if (pFd->mmapSize >= iOff + nAmt) {
@@ -1330,7 +1330,7 @@ unixFetch(sql_file * fd MAYBE_UNUSED,
 		}
 	}
 #endif
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -1365,7 +1365,7 @@ unixUnfetch(sql_file * fd, i64 iOff, void *p)
 	}
 
 	assert(pFd->nFetchOut >= 0);
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -1466,7 +1466,7 @@ fillInUnixFile(sql_vfs * pVfs,	/* Pointer to vfs object */
 {
 	const sql_io_methods *pLockingStyle;
 	unixFile *pNew = (unixFile *) pId;
-	int rc = SQL_OK;
+	int rc = 0;
 
 	assert(pNew->pInode == NULL);
 
@@ -1499,7 +1499,7 @@ fillInUnixFile(sql_vfs * pVfs,	/* Pointer to vfs object */
 
 	if (pLockingStyle == &posixIoMethods) {
 		rc = findInodeInfo(pNew, &pNew->pInode);
-		if (rc != SQL_OK) {
+		if (rc != 0) {
 			/* If an error occurred in findInodeInfo(), close the file descriptor
 			 * immediately. findInodeInfo() may fail
 			 * in two scenarios:
@@ -1523,7 +1523,7 @@ fillInUnixFile(sql_vfs * pVfs,	/* Pointer to vfs object */
 		}
 	}
 	storeLastErrno(pNew, 0);
-	if (rc != SQL_OK) {
+	if (rc != 0) {
 		if (h >= 0)
 			robust_close(pNew, h, __LINE__);
 	} else {
@@ -1598,7 +1598,7 @@ unixGetTempname(int nBuf, char *zBuf)
 		if (zBuf[nBuf - 2] != 0 || (iLimit++) > 10)
 			return SQL_ERROR;
 	} while (access(zBuf, 0) == 0);
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -1667,7 +1667,7 @@ getFileMode(const char *zFile,	/* File name */
     )
 {
 	struct stat sStat;	/* Output of stat() on database file */
-	int rc = SQL_OK;
+	int rc = 0;
 	if (0 == stat(zFile, &sStat)) {
 		*pMode = sStat.st_mode & 0777;
 		*pUid = sStat.st_uid;
@@ -1680,7 +1680,7 @@ getFileMode(const char *zFile,	/* File name */
 
 /*
  * This function is called by unixOpen() to determine the unix permissions
- * to create new files with. If no error occurs, then SQL_OK is returned
+ * to create new files with. If no error occurs, then 0 is returned
  * and a value suitable for passing as the third argument to open(2) is
  * written to *pMode. If an IO error occurs, an sql error code is
  * returned and the value of *pMode is not modified.
@@ -1702,7 +1702,7 @@ findCreateFileMode(const char *zPath,	/* Path of file (possibly) being created *
 		   gid_t * pGid	/* OUT: gid to set on the file */
     )
 {
-	int rc = SQL_OK;	/* Return Code */
+	int rc = 0;	/* Return Code */
 	*pMode = 0;
 	*pUid = 0;
 	*pGid = 0;
@@ -1827,9 +1827,8 @@ unixOpen(sql_vfs * pVfs,	/* The VFS for which this is the xOpen method */
 		/* If zName is NULL, the upper layer is requesting a temp file. */
 		assert(isDelete);
 		rc = unixGetTempname(pVfs->mxPathname, zTmpname);
-		if (rc != SQL_OK) {
+		if (rc != 0)
 			return rc;
-		}
 		zName = zTmpname;
 
 		/* Generated temporary filenames are always double-zero terminated
@@ -1861,7 +1860,7 @@ unixOpen(sql_vfs * pVfs,	/* The VFS for which this is the xOpen method */
 		uid_t uid;	/* Userid for the file */
 		gid_t gid;	/* Groupid for the file */
 		rc = findCreateFileMode(zName, flags, &openMode, &uid, &gid);
-		if (rc != SQL_OK) {
+		if (rc != 0) {
 			assert(!p->pUnused);
 			return rc;
 		}
@@ -1911,9 +1910,8 @@ unixOpen(sql_vfs * pVfs,	/* The VFS for which this is the xOpen method */
 	rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
 
  open_finished:
-	if (rc != SQL_OK) {
+	if (rc != 0)
 		sql_free(p->pUnused);
-	}
 	return rc;
 }
 
@@ -1927,7 +1925,7 @@ unixDelete(sql_vfs * NotUsed,	/* VFS containing this as the xDelete method */
 	   int dirSync		/* If true, fsync() directory after deleting file */
     )
 {
-	int rc = SQL_OK;
+	int rc = 0;
 	UNUSED_PARAMETER(NotUsed);
 	if (unlink(zPath) == (-1)) {
 		if (errno == ENOENT) {
@@ -1940,7 +1938,7 @@ unixDelete(sql_vfs * NotUsed,	/* VFS containing this as the xDelete method */
 	if ((dirSync & 1) != 0) {
 		int fd;
 		rc = openDirectory(zPath, &fd);
-		if (rc == SQL_OK) {
+		if (rc == 0) {
 			struct stat buf;
 			if (fstat(fd, &buf)) {
 				rc = unixLogError(SQL_IOERR_DIR_FSYNC,
@@ -1949,7 +1947,7 @@ unixDelete(sql_vfs * NotUsed,	/* VFS containing this as the xDelete method */
 			robust_close(0, fd, __LINE__);
 		} else {
 			assert(rc == SQL_CANTOPEN);
-			rc = SQL_OK;
+			rc = 0;
 		}
 	}
 	return rc;
@@ -1991,15 +1989,13 @@ int sql_current_time = 0;
  * epoch of noon in Greenwich on November 24, 4714 B.C according to the
  * proleptic Gregorian calendar.
  *
- * On success, return SQL_OK.  Return SQL_ERROR if the time and date
- * cannot be found.
+ * Always returns 0.
  */
 static int
 unixCurrentTimeInt64(sql_vfs * NotUsed, sql_int64 * piNow)
 {
 	static const sql_int64 unixEpoch =
 	    24405875 * (sql_int64) 8640000;
-	int rc = SQL_OK;
 	struct timeval sNow;
 	(void)gettimeofday(&sNow, 0);	/* Cannot fail given valid arguments */
 	*piNow =
@@ -2013,7 +2009,7 @@ unixCurrentTimeInt64(sql_vfs * NotUsed, sql_int64 * piNow)
 	}
 #endif
 	UNUSED_PARAMETER(NotUsed);
-	return rc;
+	return 0;
 }
 
 /*
@@ -2047,16 +2043,15 @@ unixCurrentTimeInt64(sql_vfs * NotUsed, sql_int64 * piNow)
  * Initialize the operating system interface.
  *
  * This routine registers all VFS implementations for unix-like operating
- * systems.  This routine, and the sql_os_end() routine that follows,
- * should be the only routines in this file that are visible from other
- * files.
+ * systems.  This routine should be the only one in this file that
+ * are visible from other files.
  *
  * This routine is called once during sql initialization and by a
  * single thread.  The memory allocation subsystem have not
  * necessarily been initialized when this routine \is called, and so they
  * should not be used.
  */
-int
+void
 sql_os_init(void)
 {
 	/*
@@ -2074,18 +2069,4 @@ sql_os_init(void)
 	/* Register all VFSes defined in the aVfs[] array. */
 	for (unsigned int i = 0; i < (sizeof(aVfs) / sizeof(sql_vfs)); i++)
 		sql_vfs_register(&aVfs[i], i == 0);
-	return SQL_OK;
-}
-
-/*
- * Shutdown the operating system interface.
- *
- * Some operating systems might need to do some cleanup in this routine,
- * to release dynamically allocated objects.  But not on unix.
- * This routine is a no-op for unix.
- */
-int
-sql_os_end(void)
-{
-	return SQL_OK;
 }
diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index 4ac8698..7a8a2d8 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -52,7 +52,7 @@ sqlPrepare(sql * db,	/* Database handle. */
 	       const char **pzTail	/* OUT: End of parsed string */
     )
 {
-	int rc = SQL_OK;	/* Result code */
+	int rc = 0;	/* Result code */
 	Parse sParse;		/* Parsing context */
 	sql_parser_create(&sParse, db, current_session()->sql_flags);
 	sParse.pReprepare = pReprepare;
@@ -107,7 +107,7 @@ sqlPrepare(sql * db,	/* Database handle. */
 	if (sParse.is_aborted)
 		rc = SQL_TARANTOOL_ERROR;
 
-	if (rc == SQL_OK && sParse.pVdbe && sParse.explain) {
+	if (rc == 0 && sParse.pVdbe != NULL && sParse.explain) {
 		static const char *const azColName[] = {
 			/*  0 */ "addr",
 			/*  1 */ "INTEGER",
@@ -159,7 +159,7 @@ sqlPrepare(sql * db,	/* Database handle. */
 		sqlVdbeSetSql(pVdbe, zSql, (int)(sParse.zTail - zSql),
 				  saveSqlFlag);
 	}
-	if (sParse.pVdbe && (rc != SQL_OK || db->mallocFailed)) {
+	if (sParse.pVdbe != NULL && (rc != 0 || db->mallocFailed)) {
 		sqlVdbeFinalize(sParse.pVdbe);
 		assert(!(*ppStmt));
 	} else {
@@ -201,14 +201,14 @@ sqlLockAndPrepare(sql * db,		/* Database handle. */
 		rc = sqlPrepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt,
 				    pzTail);
 	}
-	assert(rc == SQL_OK || *ppStmt == 0);
+	assert(rc == 0 || *ppStmt == NULL);
 	return rc;
 }
 
 /*
  * Rerun the compilation of a statement after a schema change.
  *
- * If the statement is successfully recompiled, return SQL_OK. Otherwise,
+ * If the statement is successfully recompiled, return 0. Otherwise,
  * if the statement cannot be recompiled because another connection has
  * locked the sql_master table, return SQL_LOCKED. If any other error
  * occurs, return SQL_SCHEMA.
@@ -238,7 +238,7 @@ sqlReprepare(Vdbe * p)
 	sqlTransferBindings(pNew, (sql_stmt *) p);
 	sqlVdbeResetStepResult((Vdbe *) pNew);
 	sqlVdbeFinalize((Vdbe *) pNew);
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -258,7 +258,7 @@ sql_prepare(sql * db,		/* Database handle. */
 {
 	int rc;
 	rc = sqlLockAndPrepare(db, zSql, nBytes, 0, 0, ppStmt, pzTail);
-	assert(rc == SQL_OK || ppStmt == 0 || *ppStmt == 0);	/* VERIFY: F13021 */
+	assert(rc == 0 || ppStmt == NULL || *ppStmt == NULL);	/* VERIFY: F13021 */
 	return rc;
 }
 
@@ -272,7 +272,7 @@ sql_prepare_v2(sql * db,	/* Database handle. */
 {
 	int rc;
 	rc = sqlLockAndPrepare(db, zSql, nBytes, 1, 0, ppStmt, pzTail);
-	assert(rc == SQL_OK || ppStmt == 0 || *ppStmt == 0);	/* VERIFY: F13021 */
+	assert(rc == 0 || ppStmt == NULL || *ppStmt == NULL);	/* VERIFY: F13021 */
 	return rc;
 }
 
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index 3b6b4b6..c60a280 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -1812,7 +1812,7 @@ generateColumnNames(Parse * pParse,	/* Parser context */
  * Only the column names are computed.  Column.zType, Column.zColl,
  * and other fields of Column are zeroed.
  *
- * Return SQL_OK on success.  If a memory allocation error occurs,
+ * Return 0 on success.  If a memory allocation error occurs,
  * store NULL in *paCol and 0 in *pnCol and return SQL_NOMEM.
  */
 int
@@ -1916,8 +1916,8 @@ sqlColumnsFromExprList(Parse * parse, ExprList * expr_list,
 	}
 cleanup:
 	sqlHashClear(&ht);
-	int rc = db->mallocFailed ? SQL_NOMEM : SQL_OK;
-	if (rc != SQL_OK) {
+	int rc = db->mallocFailed ? SQL_NOMEM : 0;
+	if (rc != 0) {
 		/*
 		 * pTable->def could be not temporal in
 		 * sqlViewGetColumnNames so we need clean-up.
@@ -2551,7 +2551,7 @@ multiSelect(Parse * pParse,	/* Parsing context */
 	    Select * p,		/* The right-most of SELECTs to be coded */
 	    SelectDest * pDest)	/* What to do with query results */
 {
-	int rc = SQL_OK;	/* Success code from a subroutine */
+	int rc = 0;	/* Success code from a subroutine */
 	Select *pPrior;		/* Another SELECT immediately to our left */
 	Vdbe *v;		/* Generate code to this VDBE */
 	SelectDest dest;	/* Alternative data destination */
@@ -2664,7 +2664,7 @@ multiSelect(Parse * pParse,	/* Parsing context */
 				}
 				iSub2 = pParse->iNextSelectId;
 				rc = sqlSelect(pParse, p, &dest);
-				testcase(rc != SQL_OK);
+				testcase(rc != 0);
 				pDelete = p->pPrior;
 				p->pPrior = pPrior;
 				p->nSelectRow =
@@ -2751,7 +2751,7 @@ multiSelect(Parse * pParse,	/* Parsing context */
 				uniondest.eDest = op;
 				iSub2 = pParse->iNextSelectId;
 				rc = sqlSelect(pParse, p, &uniondest);
-				testcase(rc != SQL_OK);
+				testcase(rc != 0);
 				/* Query flattening in sqlSelect() might refill p->pOrderBy.
 				 * Be sure to delete p->pOrderBy, therefore, to avoid a memory leak.
 				 */
@@ -2865,7 +2865,7 @@ multiSelect(Parse * pParse,	/* Parsing context */
 				intersectdest.reg_eph = reg_eph2;
 				iSub2 = pParse->iNextSelectId;
 				rc = sqlSelect(pParse, p, &intersectdest);
-				testcase(rc != SQL_OK);
+				testcase(rc != 0);
 				pDelete = p->pPrior;
 				p->pPrior = pPrior;
 				if (p->nSelectRow > pPrior->nSelectRow)
@@ -4390,7 +4390,7 @@ is_simple_count(struct Select *select, struct AggInfo *agg_info)
  * INDEXED BY clause, then try to locate the specified index. If there
  * was such a clause and the named index cannot be found, return
  * SQL_ERROR and leave an error in pParse. Otherwise, populate
- * pFrom->pIndex and return SQL_OK.
+ * pFrom->pIndex and return 0.
  */
 int
 sqlIndexedByLookup(Parse * pParse, struct SrcList_item *pFrom)
@@ -4414,7 +4414,7 @@ sqlIndexedByLookup(Parse * pParse, struct SrcList_item *pFrom)
 		}
 		pFrom->pIBIndex = idx->def;
 	}
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -4567,9 +4567,9 @@ sqlWithPush(Parse * pParse, With * pWith, u8 bFree)
  * (pFrom->space!=0) to determine whether or not a successful match
  * was found.
  *
- * Whether or not a match is found, SQL_OK is returned if no error
+ * Whether or not a match is found, 0 is returned if no error
  * occurs. If an error does occur, an error message is stored in the
- * parser and some error code other than SQL_OK returned.
+ * parser and some error code other than 0 returned.
  */
 static int
 withExpand(Walker * pWalker, struct SrcList_item *pFrom)
@@ -4687,7 +4687,7 @@ withExpand(Walker * pWalker, struct SrcList_item *pFrom)
 		pParse->pWith = pSavedWith;
 	}
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -6386,7 +6386,7 @@ sqlSelect(Parse * pParse,		/* The parser context */
 
 	/* Identify column names if results of the SELECT are to be output.
 	 */
-	if (rc == SQL_OK && pDest->eDest == SRT_Output) {
+	if (rc == 0 && pDest->eDest == SRT_Output) {
 		generateColumnNames(pParse, pTabList, pEList);
 	}
 
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 559bcd9..5f08ed1 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -325,10 +325,8 @@ struct sql_vfs {
 #define SQL_LIMIT_TRIGGER_DEPTH             9
 
 enum sql_ret_code {
-	/** Result of a routine is ok. */
-	SQL_OK = 0,
 	/** Common error code. */
-	SQL_ERROR,
+	SQL_ERROR = 1,
 	/** Access permission denied. */
 	SQL_PERM,
 	/** Callback routine requested an abort. */
@@ -553,7 +551,7 @@ sql_finalize(sql_stmt * pStmt);
  * it back to its starting state so that it can be reused.
  *
  * @param stmt VDBE program.
- * @retval SQL_OK On success.
+ * @retval 0 On success.
  * @retval sql_ret_code Error code on error.
  */
 int
@@ -626,9 +624,6 @@ sql_column_datatype(sql_stmt *, int N);
 int
 sql_initialize(void);
 
-int
-sql_os_end(void);
-
 #define SQL_TRACE_STMT       0x01
 #define SQL_TRACE_PROFILE    0x02
 #define SQL_TRACE_ROW        0x04
@@ -707,7 +702,7 @@ struct sql_io_methods {
 #define SQL_FCNTL_MMAP_SIZE              16
 #define SQL_FCNTL_HAS_MOVED              18
 
-int
+void
 sql_os_init(void);
 
 sql_int64
@@ -3031,7 +3026,7 @@ sql_space_column_is_in_pk(struct space *space, uint32_t);
  * @param parse Parsing context.
  * @param expr_list  Expr list from which to derive column names.
  * @param space_def Destination space definition.
- * @retval sql_OK on success.
+ * @retval 0 on success.
  * @retval error codef on error.
  */
 int sqlColumnsFromExprList(Parse *parse, ExprList *expr_list,
diff --git a/src/box/sql/status.c b/src/box/sql/status.c
index 950d5f4..d7ecc9d 100644
--- a/src/box/sql/status.c
+++ b/src/box/sql/status.c
@@ -143,7 +143,7 @@ sql_status64(int op,
 	if (resetFlag) {
 		wsdStat.mxValue[op] = wsdStat.nowValue[op];
 	}
-	return SQL_OK;
+	return 0;
 }
 
 int
diff --git a/src/box/sql/tarantoolInt.h b/src/box/sql/tarantoolInt.h
index 375a8cc..71073ad 100644
--- a/src/box/sql/tarantoolInt.h
+++ b/src/box/sql/tarantoolInt.h
@@ -35,7 +35,7 @@ int tarantoolsqlDelete(BtCursor * pCur, u8 flags);
  * @param key Key of record to be deleted.
  * @param key_size Size of key.
  *
- * @retval SQL_OK on success, SQL_TARANTOOL_ERROR otherwise.
+ * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise.
  */
 int
 sql_delete_by_key(struct space *space, uint32_t iid, char *key,
@@ -82,7 +82,7 @@ sql_ephemeral_space_create(uint32_t filed_count, struct sql_key_info *key_info);
  * @param tuple Tuple to be inserted.
  * @param tuple_end End of tuple to be inserted.
  *
- * @retval SQL_OK on success, SQL_TARANTOOL_ERROR otherwise.
+ * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise.
  */
 int tarantoolsqlEphemeralInsert(struct space *space, const char *tuple,
 				    const char *tuple_end);
diff --git a/src/box/sql/trigger.c b/src/box/sql/trigger.c
index bfc6c10..d746ef8 100644
--- a/src/box/sql/trigger.c
+++ b/src/box/sql/trigger.c
@@ -783,7 +783,7 @@ sql_row_trigger_program(struct Parse *parser, struct sql_trigger *trigger,
 		 */
 		if (trigger->pWhen != NULL) {
 			pWhen = sqlExprDup(db, trigger->pWhen, 0);
-			if (SQL_OK == sqlResolveExprNames(&sNC, pWhen)
+			if (0 == sqlResolveExprNames(&sNC, pWhen)
 			    && db->mallocFailed == 0) {
 				iEndTrigger = sqlVdbeMakeLabel(v);
 				sqlExprIfFalse(pSubParse, pWhen,
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 0914fda..37e0892 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -247,7 +247,7 @@ allocateCursor(
 		sqlVdbeFreeCursor(p, p->apCsr[iCur]);
 		p->apCsr[iCur] = 0;
 	}
-	if (SQL_OK==sqlVdbeMemClearAndResize(pMem, nByte)) {
+	if (sqlVdbeMemClearAndResize(pMem, nByte) == 0) {
 		p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
 		memset(pCx, 0, offsetof(VdbeCursor,uc));
 		pCx->eCurType = eCurType;
@@ -372,7 +372,7 @@ static u16 SQL_NOINLINE computeNumericType(Mem *pMem)
 	assert((pMem->flags & (MEM_Str|MEM_Blob))!=0);
 	if (sqlAtoF(pMem->z, &pMem->u.r, pMem->n)==0)
 		return 0;
-	if (sql_atoi64(pMem->z, (int64_t *)&pMem->u.i, pMem->n)==SQL_OK)
+	if (sql_atoi64(pMem->z, (int64_t *)&pMem->u.i, pMem->n) == 0)
 		return MEM_Int;
 	return MEM_Real;
 }
@@ -634,7 +634,7 @@ vdbe_field_ref_fast_fetch(struct vdbe_field_ref *field_ref, uint32_t fieldno,
  * @param field_ref The initialized vdbe_field_ref instance to use.
  * @param fieldno The id of the field to fetch.
  * @param[out] dest_mem The memory variable to store result.
- * @retval SQL_OK Status code in case of success.
+ * @retval 0 Status code in case of success.
  * @retval sql_ret_code Error code otherwise.
  */
 static int
@@ -645,7 +645,7 @@ vdbe_field_ref_fetch(struct vdbe_field_ref *field_ref, uint32_t fieldno,
 	uint32_t *slots = field_ref->slots;
 	if (fieldno >= field_ref->field_count) {
 		UPDATE_MAX_BLOBSIZE(dest_mem);
-		return SQL_OK;
+		return 0;
 	}
 
 	const char *data;
@@ -713,7 +713,7 @@ vdbe_field_ref_fetch(struct vdbe_field_ref *field_ref, uint32_t fieldno,
 		dest_mem->flags |= MEM_Term;
 	}
 	UPDATE_MAX_BLOBSIZE(dest_mem);
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -730,7 +730,7 @@ int sqlVdbeExec(Vdbe *p)
 #ifdef SQL_DEBUG
 	int nExtraDelete = 0;      /* Verifies FORDELETE and AUXDELETE flags */
 #endif
-	int rc = SQL_OK;        /* Value to return */
+	int rc = 0;        /* Value to return */
 	sql *db = p->db;       /* The database */
 	int iCompare = 0;          /* Result of last comparison */
 	unsigned nVmStep = 0;      /* Number of virtual machine steps */
@@ -752,8 +752,8 @@ int sqlVdbeExec(Vdbe *p)
 		 */
 		goto no_mem;
 	}
-	assert(p->rc==SQL_OK || (p->rc&0xff)==SQL_BUSY);
-	p->rc = SQL_OK;
+	assert(p->rc == 0 || (p->rc & 0xff) == SQL_BUSY);
+	p->rc = 0;
 	p->iCurrentTime = 0;
 	assert(p->explain==0);
 	p->pResultSet = 0;
@@ -788,7 +788,7 @@ int sqlVdbeExec(Vdbe *p)
 		/* Errors are detected by individual opcodes, with an immediate
 		 * jumps to abort_due_to_error.
 		 */
-		assert(rc==SQL_OK);
+		assert(rc == 0);
 
 		assert(pOp>=aOp && pOp<&aOp[p->nOp]);
 #ifdef VDBE_PROFILE
@@ -1032,7 +1032,7 @@ case OP_Halt: {
 	int pcx;
 
 	pcx = (int)(pOp - aOp);
-	if (pOp->p1==SQL_OK && p->pFrame) {
+	if (pOp->p1 == 0 && p->pFrame != NULL) {
 		/* Halt the sub-program. Return control to the parent frame. */
 		pFrame = p->pFrame;
 		p->pFrame = pFrame->pParent;
@@ -1064,11 +1064,11 @@ case OP_Halt: {
 		assert(! diag_is_empty(diag_get()));
 	}
 	rc = sqlVdbeHalt(p);
-	assert(rc==SQL_BUSY || rc==SQL_OK || rc==SQL_ERROR);
+	assert(rc == SQL_BUSY || rc == 0 || rc == SQL_ERROR);
 	if (rc==SQL_BUSY) {
 		p->rc = SQL_BUSY;
 	} else {
-		assert(rc==SQL_OK || (p->rc&0xff)==SQL_CONSTRAINT);
+		assert(rc == 0 || (p->rc & 0xff) == SQL_CONSTRAINT);
 		rc = p->rc ? SQL_TARANTOOL_ERROR : SQL_DONE;
 	}
 	goto vdbe_return;
@@ -1141,7 +1141,7 @@ case OP_String8: {         /* same as TK_STRING, out2 */
 	if (pOp->p1>db->aLimit[SQL_LIMIT_LENGTH]) {
 		goto too_big;
 	}
-	assert(rc==SQL_OK);
+	assert(rc == 0);
 	/* Fall through to the next case, OP_String */
 	FALLTHROUGH;
 }
@@ -1436,7 +1436,7 @@ case OP_ResultRow: {
 	 */
 	assert(p->iStatement == 0 || (p->sql_flags & SQL_CountRows) != 0);
 	rc = sqlVdbeCloseStatement(p, SAVEPOINT_RELEASE);
-	assert(rc==SQL_OK);
+	assert(rc==0);
 
 	/* Invalidate all ephemeral cursor row caches */
 	p->cacheCtr = (p->cacheCtr + 2)|1;
@@ -2624,7 +2624,7 @@ case OP_Column: {
 	struct Mem *default_val_mem =
 		pOp->p4type == P4_MEM ? pOp->p4.pMem : NULL;
 	rc = vdbe_field_ref_fetch(&pC->field_ref, p2, pDest);
-	if (rc != SQL_OK)
+	if (rc != 0)
 		goto abort_due_to_error;
 
 	if ((pDest->flags & MEM_Null) &&
@@ -2658,7 +2658,7 @@ case OP_Fetch: {
 	struct Mem *dest_mem = &aMem[pOp->p3];
 	memAboutToChange(p, dest_mem);
 	rc = vdbe_field_ref_fetch(field_ref, field_idx, dest_mem);
-	if (rc != SQL_OK)
+	if (rc != 0)
 		goto abort_due_to_error;
 	REGISTER_TRACE(p, pOp->p3, dest_mem);
 	break;
@@ -2877,9 +2877,8 @@ case OP_Savepoint: {
 			 */
 			int isTransaction = pSavepoint->pNext == 0;
 			if (isTransaction && p1==SAVEPOINT_RELEASE) {
-				if ((rc = sqlVdbeCheckFk(p, 1))!=SQL_OK) {
+				if ((rc = sqlVdbeCheckFk(p, 1)) != 0)
 					goto vdbe_return;
-				}
 				if (sqlVdbeHalt(p)==SQL_BUSY) {
 					p->pc = (int)(pOp - aOp);
 					p->rc = rc = SQL_BUSY;
@@ -3427,7 +3426,7 @@ case OP_SeekGT: {       /* jump, in3 */
 #endif
 	r.eqSeen = 0;
 	r.opcode = oc;
-	if (sqlCursorMovetoUnpacked(pC->uc.pCursor, &r, &res) != SQL_OK)
+	if (sqlCursorMovetoUnpacked(pC->uc.pCursor, &r, &res) != 0)
 		goto abort_due_to_error;
 	if (eqOnly && r.eqSeen==0) {
 		assert(res!=0);
@@ -3440,7 +3439,7 @@ case OP_SeekGT: {       /* jump, in3 */
 	if (oc>=OP_SeekGE) {  assert(oc==OP_SeekGE || oc==OP_SeekGT);
 		if (res<0 || (res==0 && oc==OP_SeekGT)) {
 			res = 0;
-			if (sqlCursorNext(pC->uc.pCursor, &res) != SQL_OK)
+			if (sqlCursorNext(pC->uc.pCursor, &res) != 0)
 				goto abort_due_to_error;
 		} else {
 			res = 0;
@@ -3449,7 +3448,7 @@ case OP_SeekGT: {       /* jump, in3 */
 		assert(oc==OP_SeekLT || oc==OP_SeekLE);
 		if (res>0 || (res==0 && oc==OP_SeekLT)) {
 			res = 0;
-			if (sqlCursorPrevious(pC->uc.pCursor, &res) != SQL_OK)
+			if (sqlCursorPrevious(pC->uc.pCursor, &res) != 0)
 				goto abort_due_to_error;
 		} else {
 			/* res might be negative because the table is empty.  Check to
@@ -3595,8 +3594,8 @@ case OP_Found: {        /* jump, in3 */
 	rc = sqlCursorMovetoUnpacked(pC->uc.pCursor, pIdxKey, &res);
 	if (pFree != NULL)
 		sqlDbFree(db, pFree);
-	assert(rc == SQL_OK || rc == SQL_TARANTOOL_ERROR);
-	if (rc != SQL_OK)
+	assert(rc == 0 || rc == SQL_TARANTOOL_ERROR);
+	if (rc != 0)
 		goto abort_due_to_error;
 	pC->seekResult = res;
 	alreadyExists = (res==0);
@@ -3907,9 +3906,9 @@ case OP_RowData: {
 	testcase( n==0);
 
 	sqlVdbeMemRelease(pOut);
-	if (sql_vdbe_mem_alloc_region(pOut, n) != 0 ||
-	    sqlCursorPayload(pCrsr, 0, n, pOut->z) != 0)
+	if (sql_vdbe_mem_alloc_region(pOut, n) != 0)
 		goto abort_due_to_error;
+	sqlCursorPayload(pCrsr, 0, n, pOut->z);
 	UPDATE_MAX_BLOBSIZE(pOut);
 	REGISTER_TRACE(p, pOp->p2, pOut);
 	break;
@@ -4256,7 +4255,7 @@ case OP_IdxInsert: {
 
 	if (pOp->p5 & OPFLAG_OE_IGNORE) {
 		/* Ignore any kind of failes and do not raise error message */
-		rc = SQL_OK;
+		rc = 0;
 		/* If we are in trigger, increment ignore raised counter */
 		if (p->pFrame)
 			p->ignoreRaised++;
@@ -4265,7 +4264,7 @@ case OP_IdxInsert: {
 	} else if (pOp->p5 & OPFLAG_OE_ROLLBACK) {
 		p->errorAction = ON_CONFLICT_ACTION_ROLLBACK;
 	}
-	assert(rc == SQL_OK || rc == SQL_TARANTOOL_ERROR);
+	assert(rc == 0 || rc == SQL_TARANTOOL_ERROR);
 	if (rc != 0)
 		goto abort_due_to_error;
 	break;
@@ -4342,7 +4341,7 @@ case OP_Update: {
 		goto abort_due_to_error;
 	}
 
-	assert(rc == SQL_OK);
+	assert(rc == 0);
 	if (box_update(space->def->id, 0, key_mem->z, key_mem->z + key_mem->n,
 		       ops, ops + ops_size, 0, NULL) != 0)
 		rc = SQL_TARANTOOL_ERROR;
@@ -4352,7 +4351,7 @@ case OP_Update: {
 		 * Ignore any kind of fails and do not raise
 		 * error message
 		 */
-		rc = SQL_OK;
+		rc = 0;
 		/*
 		 * If we are in trigger, increment ignore raised
 		 * counter.
@@ -4364,7 +4363,7 @@ case OP_Update: {
 	} else if (pOp->p5 & OPFLAG_OE_ROLLBACK) {
 		p->errorAction = ON_CONFLICT_ACTION_ROLLBACK;
 	}
-	assert(rc == SQL_OK || rc == SQL_TARANTOOL_ERROR);
+	assert(rc == 0 || rc == SQL_TARANTOOL_ERROR);
 	if (rc != 0)
 		goto abort_due_to_error;
 	break;
@@ -5257,10 +5256,10 @@ abort_due_to_error:
 vdbe_return:
 	testcase( nVmStep>0);
 	p->aCounter[SQL_STMTSTATUS_VM_STEP] += (int)nVmStep;
-	assert(rc!=SQL_OK || nExtraDelete==0
+	assert(rc != 0 || nExtraDelete == 0
 		|| sql_strlike_ci("DELETE%", p->zSql, 0) != 0
 		);
-	assert(rc == SQL_OK || rc == SQL_BUSY || rc == SQL_TARANTOOL_ERROR ||
+	assert(rc == 0 || rc == SQL_BUSY || rc == SQL_TARANTOOL_ERROR ||
 	       rc == SQL_ROW || rc == SQL_DONE);
 	return rc;
 
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index a4e9d27..fc34722 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -83,7 +83,7 @@ sql_finalize(sql_stmt * pStmt)
 		/* IMPLEMENTATION-OF: R-57228-12904 Invoking sql_finalize() on a NULL
 		 * pointer is a harmless no-op.
 		 */
-		rc = SQL_OK;
+		rc = 0;
 	} else {
 		Vdbe *v = (Vdbe *) pStmt;
 		sql *db = v->db;
@@ -115,7 +115,7 @@ int
 sql_clear_bindings(sql_stmt * pStmt)
 {
 	int i;
-	int rc = SQL_OK;
+	int rc = 0;
 	Vdbe *p = (Vdbe *) pStmt;
 	for (i = 0; i < p->nVar; i++) {
 		sqlVdbeMemRelease(&p->aVar[i]);
@@ -136,7 +136,7 @@ sql_value_blob(sql_value * pVal)
 {
 	Mem *p = (Mem *) pVal;
 	if (p->flags & (MEM_Blob | MEM_Str)) {
-		if (ExpandBlob(p) != SQL_OK) {
+		if (ExpandBlob(p) != 0) {
 			assert(p->flags == MEM_Null && p->z == 0);
 			return 0;
 		}
@@ -235,7 +235,7 @@ sql_value_dup(const sql_value * pOrig)
 	if (pNew->flags & (MEM_Str | MEM_Blob)) {
 		pNew->flags &= ~(MEM_Static | MEM_Dyn);
 		pNew->flags |= MEM_Ephem;
-		if (sqlVdbeMemMakeWriteable(pNew) != SQL_OK) {
+		if (sqlVdbeMemMakeWriteable(pNew) != 0) {
 			sqlValueFree(pNew);
 			pNew = 0;
 		}
@@ -394,7 +394,7 @@ sql_result_zeroblob64(sql_context * pCtx, u64 n)
 		return SQL_TOOBIG;
 	}
 	sqlVdbeMemSetZeroBlob(pCtx->pOut, (int)n);
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -497,7 +497,7 @@ sql_step(sql_stmt * pStmt)
 	       && cnt++ < SQL_MAX_SCHEMA_RETRY) {
 		int savedPc = v->pc;
 		rc = sqlReprepare(v);
-		if (rc != SQL_OK)
+		if (rc != 0)
 			break;
 		sql_reset(pStmt);
 		if (savedPc >= 0)
@@ -912,7 +912,7 @@ sql_column_decltype(sql_stmt * pStmt, int N)
 /*
  * Unbind the value bound to variable i in virtual machine p. This is the
  * the same as binding a NULL value to the column. If the "i" parameter is
- * out of range, then SQL_RANGE is returned. Othewise SQL_OK.
+ * out of range, then SQL_RANGE is returned. Othewise 0.
  *
  * The error code stored in database p->db is overwritten with the return
  * value in any case.
@@ -950,7 +950,7 @@ vdbeUnbind(Vdbe * p, int i)
 	    ) {
 		p->expired = 1;
 	}
-	return SQL_OK;
+	return 0;
 }
 
 /**
@@ -1013,11 +1013,11 @@ bindText(sql_stmt * pStmt,	/* The statement to bind against */
 	int rc;
 
 	rc = vdbeUnbind(p, i);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		if (zData != 0) {
 			pVar = &p->aVar[i - 1];
 			rc = sqlVdbeMemSetStr(pVar, zData, nData, 1, xDel);
-			if (rc == SQL_OK)
+			if (rc == 0)
 				rc = sql_bind_type(p, i, "TEXT");
 			rc = sqlApiExit(p->db, rc);
 		}
@@ -1037,11 +1037,11 @@ sql_bind_blob(sql_stmt * pStmt,
 {
 	struct Vdbe *p = (Vdbe *) pStmt;
 	int rc = vdbeUnbind(p, i);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		if (zData != 0) {
 			struct Mem *var = &p->aVar[i - 1];
 			rc = sqlVdbeMemSetStr(var, zData, nData, 0, xDel);
-			if (rc == SQL_OK)
+			if (rc == 0)
 				rc = sql_bind_type(p, i, "BLOB");
 			rc = sqlApiExit(p->db, rc);
 		}
@@ -1072,7 +1072,7 @@ sql_bind_double(sql_stmt * pStmt, int i, double rValue)
 	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
 	rc = vdbeUnbind(p, i);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		rc = sql_bind_type(p, i, "NUMERIC");
 		sqlVdbeMemSetDouble(&p->aVar[i - 1], rValue);
 	}
@@ -1084,7 +1084,7 @@ sql_bind_boolean(struct sql_stmt *stmt, int i, bool value)
 {
 	struct Vdbe *p = (struct Vdbe *) stmt;
 	int rc = vdbeUnbind(p, i);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		rc = sql_bind_type(p, i, "BOOLEAN");
 		mem_set_bool(&p->aVar[i - 1], value);
 	}
@@ -1103,7 +1103,7 @@ sql_bind_int64(sql_stmt * pStmt, int i, sql_int64 iValue)
 	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
 	rc = vdbeUnbind(p, i);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		rc = sql_bind_type(p, i, "INTEGER");
 		sqlVdbeMemSetInt64(&p->aVar[i - 1], iValue);
 	}
@@ -1116,7 +1116,7 @@ sql_bind_null(sql_stmt * pStmt, int i)
 	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
 	rc = vdbeUnbind(p, i);
-	if (rc == SQL_OK)
+	if (rc == 0)
 		rc = sql_bind_type(p, i, "BOOLEAN");
 	return rc;
 }
@@ -1126,7 +1126,7 @@ sql_bind_ptr(struct sql_stmt *stmt, int i, void *ptr)
 {
 	struct Vdbe *p = (struct Vdbe *) stmt;
 	int rc = vdbeUnbind(p, i);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		rc = sql_bind_type(p, i, "BLOB");
 		mem_set_ptr(&p->aVar[i - 1], ptr);
 	}
@@ -1162,7 +1162,7 @@ sql_bind_zeroblob(sql_stmt * pStmt, int i, int n)
 	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
 	rc = vdbeUnbind(p, i);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		sqlVdbeMemSetZeroBlob(&p->aVar[i - 1], n);
 	}
 	return rc;
@@ -1250,7 +1250,7 @@ sqlTransferBindings(sql_stmt * pFromStmt, sql_stmt * pToStmt)
 	for (i = 0; i < pFrom->nVar; i++) {
 		sqlVdbeMemMove(&pTo->aVar[i], &pFrom->aVar[i]);
 	}
-	return SQL_OK;
+	return 0;
 }
 
 /*
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 5f7e772..4835781 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -191,8 +191,9 @@ growOpArray(Vdbe * v, int nOp)
 		p->szOpAlloc = sqlMallocSize(pNew);
 		p->nOpAlloc = p->szOpAlloc / sizeof(Op);
 		v->aOp = pNew;
+		return 0;
 	}
-	return (pNew ? SQL_OK : SQL_NOMEM);
+	return SQL_NOMEM;
 }
 
 #ifdef SQL_DEBUG
@@ -1384,12 +1385,12 @@ sqlVdbeList(Vdbe * p)
 	Mem *pSub = 0;		/* Memory cell hold array of subprogs */
 	sql *db = p->db;	/* The database connection */
 	int i;			/* Loop counter */
-	int rc = SQL_OK;	/* Return code */
+	int rc = 0;	/* Return code */
 	Mem *pMem = &p->aMem[1];	/* First Mem of result set */
 
 	assert(p->explain);
 	assert(p->magic == VDBE_MAGIC_RUN);
-	assert(p->rc == SQL_OK || p->rc == SQL_BUSY
+	assert(p->rc == 0 || p->rc == SQL_BUSY
 	       || p->rc == SQL_NOMEM);
 
 	/* Even though this opcode does not use dynamic strings for
@@ -1439,7 +1440,7 @@ sqlVdbeList(Vdbe * p)
 		i = p->pc++;
 	} while (i < nRow && p->explain == 2 && p->aOp[i].opcode != OP_Explain);
 	if (i >= nRow) {
-		p->rc = SQL_OK;
+		p->rc = 0;
 		rc = SQL_DONE;
 	} else {
 		char *zP4;
@@ -1483,11 +1484,9 @@ sqlVdbeList(Vdbe * p)
 					if (apSub[j] == pOp->p4.pProgram)
 						break;
 				}
-				if (j == nSub
-				    && SQL_OK == sqlVdbeMemGrow(pSub,
-								       nByte,
-								       nSub !=
-								       0)) {
+				if (j == nSub &&
+				    sqlVdbeMemGrow(pSub, nByte,
+						   nSub != 0) == 0) {
 					apSub = (SubProgram **) pSub->z;
 					apSub[nSub++] = pOp->p4.pProgram;
 					pSub->flags |= MEM_Blob;
@@ -1548,7 +1547,7 @@ sqlVdbeList(Vdbe * p)
 
 		p->nResColumn = 8 - 4 * (p->explain - 1);
 		p->pResultSet = &p->aMem[1];
-		p->rc = SQL_OK;
+		p->rc = 0;
 		rc = SQL_ROW;
 	}
 	return rc;
@@ -1648,7 +1647,7 @@ sqlVdbeRewind(Vdbe * p)
 	}
 #endif
 	p->pc = -1;
-	p->rc = SQL_OK;
+	p->rc = 0;
 	p->ignoreRaised = 0;
 	p->errorAction = ON_CONFLICT_ACTION_ABORT;
 	p->nChange = 0;
@@ -1992,12 +1991,12 @@ checkActiveVdbeCnt(sql * db)
  * statement transaction is committed.
  *
  * If an IO error occurs, an SQL_IOERR_XXX error code is returned.
- * Otherwise SQL_OK.
+ * Otherwise 0.
  */
 int
 sqlVdbeCloseStatement(Vdbe * p, int eOp)
 {
-	int rc = SQL_OK;
+	int rc = 0;
 	const Savepoint *savepoint = p->anonymous_savepoint;
 	/*
 	 * If we have an anonymous transaction opened -> perform eOp.
@@ -2012,7 +2011,7 @@ sqlVdbeCloseStatement(Vdbe * p, int eOp)
  * This function is called when a transaction opened by the database
  * handle associated with the VM passed as an argument is about to be
  * committed. If there are outstanding deferred foreign key constraint
- * violations, return SQL_ERROR. Otherwise, SQL_OK.
+ * violations, return SQL_ERROR. Otherwise, 0.
  *
  * If there are outstanding FK violations and this function returns
  * SQL_ERROR, set the result of the VM to SQL_CONSTRAINT_FOREIGNKEY
@@ -2031,7 +2030,7 @@ sqlVdbeCheckFk(Vdbe * p, int deferred)
 			 "failed");
 		return SQL_TARANTOOL_ERROR;
 	}
-	return SQL_OK;
+	return 0;
 }
 
 int
@@ -2117,7 +2116,7 @@ sqlVdbeHalt(Vdbe * p)
 	}
 	closeTopFrameCursors(p);
 	if (p->magic != VDBE_MAGIC_RUN) {
-		return SQL_OK;
+		return 0;
 	}
 	checkActiveVdbeCnt(db);
 
@@ -2160,9 +2159,8 @@ sqlVdbeHalt(Vdbe * p)
 		}
 
 		/* Check for immediate foreign key violations. */
-		if (p->rc == SQL_OK) {
+		if (p->rc == 0)
 			sqlVdbeCheckFk(p, 0);
-		}
 
 		/* If the auto-commit flag is set and this is the only active writer
 		 * VM, then we do either a commit or rollback of the current transaction.
@@ -2171,11 +2169,11 @@ sqlVdbeHalt(Vdbe * p)
 		 * above has occurred.
 		 */
 		if (p->auto_commit) {
-			if (p->rc == SQL_OK
+			if (p->rc == 0
 			    || (p->errorAction == ON_CONFLICT_ACTION_FAIL
 				&& !isSpecialError)) {
 				rc = sqlVdbeCheckFk(p, 1);
-				if (rc != SQL_OK) {
+				if (rc != 0) {
 					/* Close all opened cursors if
 					 * they exist and free all
 					 * VDBE frames.
@@ -2193,13 +2191,13 @@ sqlVdbeHalt(Vdbe * p)
 					 */
 					rc = (in_txn() == NULL ||
 					      txn_commit(in_txn()) == 0) ?
-					     SQL_OK : SQL_TARANTOOL_ERROR;
+					     0 : SQL_TARANTOOL_ERROR;
 					closeCursorsAndFree(p);
 				}
 				if (rc == SQL_BUSY && !p->pDelFrame) {
 					closeCursorsAndFree(p);
 					return SQL_BUSY;
-				} else if (rc != SQL_OK) {
+				} else if (rc != 0) {
 					p->rc = rc;
 					box_txn_rollback();
 					closeCursorsAndFree(p);
@@ -2214,7 +2212,7 @@ sqlVdbeHalt(Vdbe * p)
 			}
 			p->anonymous_savepoint = NULL;
 		} else if (eStatementOp == 0) {
-			if (p->rc == SQL_OK || p->errorAction == ON_CONFLICT_ACTION_FAIL) {
+			if (p->rc == 0 || p->errorAction == ON_CONFLICT_ACTION_FAIL) {
 				eStatementOp = SAVEPOINT_RELEASE;
 			} else if (p->errorAction == ON_CONFLICT_ACTION_ABORT) {
 				eStatementOp = SAVEPOINT_ROLLBACK;
@@ -2230,14 +2228,14 @@ sqlVdbeHalt(Vdbe * p)
 		/* If eStatementOp is non-zero, then a statement transaction needs to
 		 * be committed or rolled back. Call sqlVdbeCloseStatement() to
 		 * do so. If this operation returns an error, and the current statement
-		 * error code is SQL_OK or SQL_CONSTRAINT, then promote the
+		 * error code is 0 or SQL_CONSTRAINT, then promote the
 		 * current statement error code.
 		 */
 		if (eStatementOp) {
 			rc = sqlVdbeCloseStatement(p, eStatementOp);
 			if (rc) {
 				box_txn_rollback();
-				if (p->rc == SQL_OK
+				if (p->rc == 0
 				    || (p->rc & 0xff) == SQL_CONSTRAINT) {
 					p->rc = rc;
 				}
@@ -2276,17 +2274,17 @@ sqlVdbeHalt(Vdbe * p)
 
 	assert(db->nVdbeActive > 0 || box_txn() ||
 	       p->anonymous_savepoint == NULL);
-	return (p->rc == SQL_BUSY ? SQL_BUSY : SQL_OK);
+	return p->rc == SQL_BUSY ? SQL_BUSY : 0;
 }
 
 /*
  * Each VDBE holds the result of the most recent sql_step() call
- * in p->rc.  This routine sets that result back to SQL_OK.
+ * in p->rc.  This routine sets that result back to 0.
  */
 void
 sqlVdbeResetStepResult(Vdbe * p)
 {
-	p->rc = SQL_OK;
+	p->rc = 0;
 }
 
 /*
@@ -2387,7 +2385,7 @@ sqlVdbeReset(Vdbe * p)
 int
 sqlVdbeFinalize(Vdbe * p)
 {
-	int rc = SQL_OK;
+	int rc = 0;
 	if (p->magic == VDBE_MAGIC_RUN || p->magic == VDBE_MAGIC_HALT) {
 		rc = sqlVdbeReset(p);
 		assert((rc & p->db->errMask) == rc);
@@ -2906,7 +2904,7 @@ sql_vdbe_mem_alloc_region(Mem *vdbe_mem, uint32_t size)
 		return SQL_NOMEM;
 	vdbe_mem->flags = MEM_Ephem | MEM_Blob;
 	assert(sqlVdbeCheckMemInvariants(vdbe_mem));
-	return SQL_OK;
+	return 0;
 }
 
 /*
diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
index 3669336..3052bec 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -145,7 +145,7 @@ sqlVdbeMemGrow(Mem * pMem, int n, int bPreserve)
 
 	pMem->z = pMem->zMalloc;
 	pMem->flags &= ~(MEM_Dyn | MEM_Ephem | MEM_Static);
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -158,7 +158,7 @@ sqlVdbeMemGrow(Mem * pMem, int n, int bPreserve)
  * and MEM_Blob values may be discarded, MEM_Int, MEM_Real, and MEM_Null
  * values are preserved.
  *
- * Return SQL_OK on success or an error code (probably SQL_NOMEM)
+ * Return 0 on success or an error code (probably SQL_NOMEM)
  * if unable to complete the resizing.
  */
 int
@@ -172,14 +172,14 @@ sqlVdbeMemClearAndResize(Mem * pMem, int szNew)
 	assert((pMem->flags & MEM_Dyn) == 0);
 	pMem->z = pMem->zMalloc;
 	pMem->flags &= (MEM_Null | MEM_Int | MEM_Real);
-	return SQL_OK;
+	return 0;
 }
 
 /*
  * Change pMem so that its MEM_Str or MEM_Blob value is stored in
  * MEM.zMalloc, where it can be safely written.
  *
- * Return SQL_OK on success or SQL_NOMEM if malloc fails.
+ * Return 0 on success or SQL_NOMEM if malloc fails.
  */
 int
 sqlVdbeMemMakeWriteable(Mem * pMem)
@@ -201,7 +201,7 @@ sqlVdbeMemMakeWriteable(Mem * pMem)
 	pMem->pScopyFrom = 0;
 #endif
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -227,7 +227,7 @@ sqlVdbeMemExpandBlob(Mem * pMem)
 	memset(&pMem->z[pMem->n], 0, pMem->u.nZero);
 	pMem->n += pMem->u.nZero;
 	pMem->flags &= ~(MEM_Zero | MEM_Term);
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -243,7 +243,7 @@ vdbeMemAddTerminator(Mem * pMem)
 	pMem->z[pMem->n] = 0;
 	pMem->z[pMem->n + 1] = 0;
 	pMem->flags |= MEM_Term;
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -255,7 +255,7 @@ sqlVdbeMemNulTerminate(Mem * pMem)
 	testcase((pMem->flags & (MEM_Term | MEM_Str)) == (MEM_Term | MEM_Str));
 	testcase((pMem->flags & (MEM_Term | MEM_Str)) == 0);
 	if ((pMem->flags & (MEM_Term | MEM_Str)) != MEM_Str) {
-		return SQL_OK;	/* Nothing to do */
+		return 0;	/* Nothing to do */
 	} else {
 		return vdbeMemAddTerminator(pMem);
 	}
@@ -282,7 +282,7 @@ sqlVdbeMemStringify(Mem * pMem, u8 bForce)
 	const int nByte = 32;
 
 	if ((fg & (MEM_Null | MEM_Str | MEM_Blob)) != 0)
-		return SQL_OK;
+		return 0;
 
 	assert(!(fg & MEM_Zero));
 	assert(fg & (MEM_Int | MEM_Real | MEM_Bool));
@@ -303,7 +303,7 @@ sqlVdbeMemStringify(Mem * pMem, u8 bForce)
 	pMem->flags |= MEM_Str | MEM_Term;
 	if (bForce)
 		pMem->flags &= ~(MEM_Int | MEM_Real);
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -565,7 +565,7 @@ sqlVdbeMemRealify(Mem * pMem)
 
 	pMem->u.r = v;
 	MemSetTypeFlag(pMem, MEM_Real);
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -594,7 +594,7 @@ sqlVdbeMemNumerify(Mem * pMem)
 	}
 	assert((pMem->flags & (MEM_Int | MEM_Real | MEM_Null)) != 0);
 	pMem->flags &= ~(MEM_Str | MEM_Blob | MEM_Zero);
-	return SQL_OK;
+	return 0;
 }
 
 /**
@@ -644,7 +644,7 @@ sqlVdbeMemCast(Mem * pMem, enum field_type type)
 {
 	assert(type < field_type_MAX);
 	if (pMem->flags & MEM_Null)
-		return SQL_OK;
+		return 0;
 	if ((pMem->flags & MEM_Blob) != 0 && type == FIELD_TYPE_NUMBER) {
 		if (sql_atoi64(pMem->z, (int64_t *) &pMem->u.i, pMem->n) == 0) {
 			MemSetTypeFlag(pMem, MEM_Real);
@@ -704,7 +704,7 @@ sqlVdbeMemCast(Mem * pMem, enum field_type type)
 			sql_value_apply_type(pMem, FIELD_TYPE_STRING);
 		assert(pMem->flags & MEM_Str || pMem->db->mallocFailed);
 		pMem->flags &= ~(MEM_Int | MEM_Real | MEM_Blob | MEM_Zero);
-		return SQL_OK;
+		return 0;
 	}
 }
 
@@ -903,7 +903,7 @@ sqlVdbeMemShallowCopy(Mem * pTo, const Mem * pFrom, int srcType)
 int
 sqlVdbeMemCopy(Mem * pTo, const Mem * pFrom)
 {
-	int rc = SQL_OK;
+	int rc = 0;
 
 	if (VdbeMemDynamic(pTo))
 		vdbeMemClearExternAndSetNull(pTo);
@@ -966,7 +966,7 @@ sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
 	/* If z is a NULL pointer, set pMem to contain an SQL NULL. */
 	if (!z) {
 		sqlVdbeMemSetNull(pMem);
-		return SQL_OK;
+		return 0;
 	}
 
 	if (pMem->db) {
@@ -1020,7 +1020,7 @@ sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
 		return SQL_TOOBIG;
 	}
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -1047,16 +1047,12 @@ vdbeMemFromBtreeResize(BtCursor * pCur,	/* Cursor pointing at record to retrieve
 {
 	int rc;
 	pMem->flags = MEM_Null;
-	if (SQL_OK == (rc = sqlVdbeMemClearAndResize(pMem, amt + 2))) {
-		rc = sqlCursorPayload(pCur, offset, amt, pMem->z);
-		if (rc == SQL_OK) {
-			pMem->z[amt] = 0;
-			pMem->z[amt + 1] = 0;
-			pMem->flags = MEM_Blob | MEM_Term;
-			pMem->n = (int)amt;
-		} else {
-			sqlVdbeMemRelease(pMem);
-		}
+	if (0 == (rc = sqlVdbeMemClearAndResize(pMem, amt + 2))) {
+		sqlCursorPayload(pCur, offset, amt, pMem->z);
+		pMem->z[amt] = 0;
+		pMem->z[amt + 1] = 0;
+		pMem->flags = MEM_Blob | MEM_Term;
+		pMem->n = (int) amt;
 	}
 	return rc;
 }
@@ -1070,7 +1066,7 @@ sqlVdbeMemFromBtree(BtCursor * pCur,	/* Cursor pointing at record to retrieve. *
 {
 	char *zData;		/* Data from the btree layer */
 	u32 available = 0;	/* Number of bytes available on the local btree page */
-	int rc = SQL_OK;	/* Return code */
+	int rc = 0;	/* Return code */
 
 	assert(sqlCursorIsValid(pCur));
 	assert(!VdbeMemDynamic(pMem));
@@ -1222,13 +1218,13 @@ valueNew(sql * db, struct ValueNewStat4Ctx *p)
  *
  * then this routine attempts to invoke the SQL function. Assuming no
  * error occurs, output parameter (*ppVal) is set to point to a value
- * object containing the result before returning SQL_OK.
+ * object containing the result before returning 0.
  *
  * Type @type is applied to the result of the function before returning.
  * If the result is a text value, the sql_value object uses encoding
  * enc.
  *
- * If the conditions above are not met, this function returns SQL_OK
+ * If the conditions above are not met, this function returns 0
  * and sets (*ppVal) to NULL. Or, if an error occurs, (*ppVal) is set to
  * NULL and an sql error code returned.
  */
@@ -1245,7 +1241,7 @@ valueFromFunction(sql * db,	/* The database connection */
 	int nVal = 0;		/* Size of apVal[] array */
 	FuncDef *pFunc = 0;	/* Function definition */
 	sql_value *pVal = 0;	/* New value */
-	int rc = SQL_OK;	/* Return code */
+	int rc = 0;	/* Return code */
 	ExprList *pList = 0;	/* Function arguments */
 	int i;			/* Iterator variable */
 
@@ -1259,7 +1255,7 @@ valueFromFunction(sql * db,	/* The database connection */
 	if ((pFunc->funcFlags & (SQL_FUNC_CONSTANT | SQL_FUNC_SLOCHNG)) ==
 	    0 || (pFunc->funcFlags & SQL_FUNC_NEEDCOLL)
 	    ) {
-		return SQL_OK;
+		return 0;
 	}
 
 	if (pList) {
@@ -1274,7 +1270,7 @@ valueFromFunction(sql * db,	/* The database connection */
 		for (i = 0; i < nVal; i++) {
 			rc = sqlValueFromExpr(db, pList->a[i].pExpr,
 						  type, &apVal[i]);
-			if (apVal[i] == 0 || rc != SQL_OK)
+			if (apVal[i] == 0 || rc != 0)
 				goto value_from_function_out;
 		}
 	}
@@ -1292,12 +1288,11 @@ valueFromFunction(sql * db,	/* The database connection */
 	pFunc->xSFunc(&ctx, nVal, apVal);
 	assert(!ctx.is_aborted);
 	sql_value_apply_type(pVal, type);
-	assert(rc == SQL_OK);
+	assert(rc == 0);
 
  value_from_function_out:
-	if (rc != SQL_OK) {
+	if (rc != 0)
 		pVal = 0;
-	}
 	if (apVal) {
 		for (i = 0; i < nVal; i++) {
 			sqlValueFree(apVal[i]);
@@ -1332,7 +1327,7 @@ valueFromExpr(sql * db,	/* The database connection */
 	sql_value *pVal = 0;
 	int negInt = 1;
 	const char *zNeg = "";
-	int rc = SQL_OK;
+	int rc = 0;
 
 	assert(pExpr != 0);
 	while ((op = pExpr->op) == TK_UPLUS || op == TK_SPAN)
@@ -1349,7 +1344,7 @@ valueFromExpr(sql * db,	/* The database connection */
 
 	if (op == TK_CAST) {
 		rc = valueFromExpr(db, pExpr->pLeft, pExpr->type, ppVal, pCtx);
-		testcase(rc != SQL_OK);
+		testcase(rc != 0);
 		if (*ppVal) {
 			sqlVdbeMemCast(*ppVal, pExpr->type);
 			sql_value_apply_type(*ppVal, type);
@@ -1393,10 +1388,10 @@ valueFromExpr(sql * db,	/* The database connection */
 			pVal->flags &= ~MEM_Str;
 	} else if (op == TK_UMINUS) {
 		/* This branch happens for multiple negative signs.  Ex: -(-5) */
-		if (SQL_OK ==
+		if (0 ==
 		    sqlValueFromExpr(db, pExpr->pLeft, type, &pVal)
 		    && pVal != 0) {
-			if ((rc = sqlVdbeMemNumerify(pVal)) != SQL_OK)
+			if ((rc = sqlVdbeMemNumerify(pVal)) != 0)
 				return rc;
 			if (pVal->flags & MEM_Real) {
 				pVal->u.r = -pVal->u.r;
@@ -1412,7 +1407,7 @@ valueFromExpr(sql * db,	/* The database connection */
 		pVal = valueNew(db, pCtx);
 		if (pVal == 0)
 			goto no_mem;
-		if ((rc = sqlVdbeMemNumerify(pVal)) != SQL_OK)
+		if ((rc = sqlVdbeMemNumerify(pVal)) != 0)
 			return rc;
 	}
 #ifndef SQL_OMIT_BLOB_LITERAL
@@ -1544,7 +1539,7 @@ stat4ValueFromExpr(Parse * pParse,	/* Parse context */
 		   sql_value ** ppVal	/* OUT: New value object (or NULL) */
     )
 {
-	int rc = SQL_OK;
+	int rc = 0;
 	sql_value *pVal = 0;
 	sql *db = pParse->db;
 
@@ -1568,9 +1563,8 @@ stat4ValueFromExpr(Parse * pParse,	/* Parse context */
 			if (pVal) {
 				rc = sqlVdbeMemCopy((Mem *) pVal,
 							&v->aVar[iBindVar - 1]);
-				if (rc == SQL_OK) {
+				if (rc == 0)
 					sql_value_apply_type(pVal, type);
-				}
 				pVal->db = pParse->db;
 			}
 		}
@@ -1613,7 +1607,7 @@ stat4ValueFromExpr(Parse * pParse,	/* Parse context */
  * is NULL and a value can be successfully extracted, a new UnpackedRecord
  * is allocated (and *ppRec set to point to it) before returning.
  *
- * Unless an error is encountered, SQL_OK is returned. It is not an
+ * Unless an error is encountered, 0 is returned. It is not an
  * error if a value cannot be extracted from pExpr. If an error does
  * occur, an sql error code is returned.
  */
@@ -1627,7 +1621,7 @@ sqlStat4ProbeSetValue(Parse * pParse,	/* Parse context */
 			  int *pnExtract	/* OUT: Values appended to the record */
     )
 {
-	int rc = SQL_OK;
+	int rc = 0;
 	int nExtract = 0;
 
 	if (pExpr == 0 || pExpr->op != TK_SELECT) {
@@ -1662,8 +1656,8 @@ sqlStat4ProbeSetValue(Parse * pParse,	/* Parse context */
  * as described for sqlStat4ProbeSetValue() above.
  *
  * If successful, set *ppVal to point to a new value object and return
- * SQL_OK. If no value can be extracted, but no other error occurs
- * (e.g. OOM), return SQL_OK and set *ppVal to NULL. Or, if an error
+ * 0. If no value can be extracted, but no other error occurs
+ * (e.g. OOM), return 0 and set *ppVal to NULL. Or, if an error
  * does occur, return an sql error code. The final value of *ppVal
  * is undefined in this case.
  */
diff --git a/src/box/sql/vdbesort.c b/src/box/sql/vdbesort.c
index 4034a34..230bb0c 100644
--- a/src/box/sql/vdbesort.c
+++ b/src/box/sql/vdbesort.c
@@ -464,7 +464,7 @@ vdbePmaReaderClear(PmaReader * pReadr)
 /*
  * Read the next nByte bytes of data from the PMA p.
  * If successful, set *ppOut to point to a buffer containing the data
- * and return SQL_OK. Otherwise, if an error occurs, return an sql
+ * and return 0. Otherwise, if an error occurs, return an sql
  * error code.
  *
  * The buffer returned in *ppOut is only valid until the
@@ -482,7 +482,7 @@ vdbePmaReadBlob(PmaReader * p,	/* PmaReader from which to take the blob */
 	if (p->aMap) {
 		*ppOut = &p->aMap[p->iReadOff];
 		p->iReadOff += nByte;
-		return SQL_OK;
+		return 0;
 	}
 
 	assert(p->aBuffer);
@@ -507,7 +507,7 @@ vdbePmaReadBlob(PmaReader * p,	/* PmaReader from which to take the blob */
 		/* Readr data from the file. Return early if an error occurs. */
 		rc = sqlOsRead(p->pFd, p->aBuffer, nRead, p->iReadOff);
 		assert(rc != SQL_IOERR_SHORT_READ);
-		if (rc != SQL_OK)
+		if (rc != 0)
 			return rc;
 	}
 	nAvail = p->nBuffer - iBuf;
@@ -558,7 +558,7 @@ vdbePmaReadBlob(PmaReader * p,	/* PmaReader from which to take the blob */
 			if (nRem > p->nBuffer)
 				nCopy = p->nBuffer;
 			rc = vdbePmaReadBlob(p, nCopy, &aNext);
-			if (rc != SQL_OK)
+			if (rc != 0)
 				return rc;
 			assert(aNext != p->aAlloc);
 			memcpy(&p->aAlloc[nByte - nRem], aNext, nCopy);
@@ -568,7 +568,7 @@ vdbePmaReadBlob(PmaReader * p,	/* PmaReader from which to take the blob */
 		*ppOut = p->aAlloc;
 	}
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -600,14 +600,14 @@ vdbePmaReadVarint(PmaReader * p, u64 * pnOut)
 		}
 	}
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
  * Attempt to memory map file pFile. If successful, set *pp to point to the
- * new mapping and return SQL_OK. If the mapping is not attempted
+ * new mapping and return 0. If the mapping is not attempted
  * (because the file is too large or the VFS layer is configured not to use
- * mmap), return SQL_OK and set *pp to NULL.
+ * mmap), return 0 and set *pp to NULL.
  *
  * Or, if an error occurs, return an sql error code. The final value of
  * *pp is undefined in this case.
@@ -615,13 +615,13 @@ vdbePmaReadVarint(PmaReader * p, u64 * pnOut)
 static int
 vdbeSorterMapFile(SortSubtask * pTask, SorterFile * pFile, u8 ** pp)
 {
-	int rc = SQL_OK;
+	int rc = 0;
 	if (pFile->iEof <= (i64) (pTask->pSorter->db->nMaxSorterMmap)) {
 		sql_file *pFd = pFile->pFd;
 		if (pFd->pMethods->iVersion >= 3) {
 			rc = sqlOsFetch(pFd, 0, (int)pFile->iEof,
 					    (void **)pp);
-			testcase(rc != SQL_OK);
+			testcase(rc != 0);
 		}
 	}
 	return rc;
@@ -629,7 +629,7 @@ vdbeSorterMapFile(SortSubtask * pTask, SorterFile * pFile, u8 ** pp)
 
 /*
  * Attach PmaReader pReadr to file pFile (if it is not already attached to
- * that file) and seek it to offset iOff within the file.  Return SQL_OK
+ * that file) and seek it to offset iOff within the file.  Return 0
  * if successful, or an sql error code if an error occurs.
  */
 static int
@@ -639,7 +639,7 @@ vdbePmaReaderSeek(SortSubtask * pTask,	/* Task context */
 		  i64 iOff	/* Offset in pFile */
     )
 {
-	int rc = SQL_OK;
+	int rc = 0;
 
 	assert(pReadr->pIncr == 0 || pReadr->pIncr->bEof == 0);
 
@@ -652,7 +652,7 @@ vdbePmaReaderSeek(SortSubtask * pTask,	/* Task context */
 	pReadr->pFd = pFile->pFd;
 
 	rc = vdbeSorterMapFile(pTask, pFile, &pReadr->aMap);
-	if (rc == SQL_OK && pReadr->aMap == 0) {
+	if (rc == 0 && pReadr->aMap == NULL) {
 		int pgsz = pTask->pSorter->pgsz;
 		int iBuf = pReadr->iReadOff % pgsz;
 		if (pReadr->aBuffer == 0) {
@@ -661,14 +661,14 @@ vdbePmaReaderSeek(SortSubtask * pTask,	/* Task context */
 				rc = SQL_NOMEM;
 			pReadr->nBuffer = pgsz;
 		}
-		if (rc == SQL_OK && iBuf) {
+		if (rc == 0 && iBuf != 0) {
 			int nRead = pgsz - iBuf;
 			if ((pReadr->iReadOff + nRead) > pReadr->iEof) {
 				nRead = (int)(pReadr->iEof - pReadr->iReadOff);
 			}
 			rc = sqlOsRead(pReadr->pFd, &pReadr->aBuffer[iBuf],
 					   nRead, pReadr->iReadOff);
-			testcase(rc != SQL_OK);
+			testcase(rc != 0);
 		}
 	}
 
@@ -676,13 +676,13 @@ vdbePmaReaderSeek(SortSubtask * pTask,	/* Task context */
 }
 
 /*
- * Advance PmaReader pReadr to the next key in its PMA. Return SQL_OK if
+ * Advance PmaReader pReadr to the next key in its PMA. Return 0 if
  * no error occurs, or an sql error code if one does.
  */
 static int
 vdbePmaReaderNext(PmaReader * pReadr)
 {
-	int rc = SQL_OK;	/* Return Code */
+	int rc = 0;	/* Return Code */
 	u64 nRec = 0;		/* Size of record in bytes */
 
 	if (pReadr->iReadOff >= pReadr->iEof) {
@@ -690,7 +690,7 @@ vdbePmaReaderNext(PmaReader * pReadr)
 		int bEof = 1;
 		if (pIncr) {
 			rc = vdbeIncrSwap(pIncr);
-			if (rc == SQL_OK && pIncr->bEof == 0) {
+			if (rc == 0 && pIncr->bEof == 0) {
 				rc = vdbePmaReaderSeek(pIncr->pTask, pReadr,
 						       &pIncr->aFile[0],
 						       pIncr->iStartOff);
@@ -701,18 +701,17 @@ vdbePmaReaderNext(PmaReader * pReadr)
 		if (bEof) {
 			/* This is an EOF condition */
 			vdbePmaReaderClear(pReadr);
-			testcase(rc != SQL_OK);
+			testcase(rc != 0);
 			return rc;
 		}
 	}
 
-	if (rc == SQL_OK) {
+	if (rc == 0)
 		rc = vdbePmaReadVarint(pReadr, &nRec);
-	}
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		pReadr->nKey = (int)nRec;
 		rc = vdbePmaReadBlob(pReadr, (int)nRec, &pReadr->aKey);
-		testcase(rc != SQL_OK);
+		testcase(rc != 0);
 	}
 
 	return rc;
@@ -743,16 +742,15 @@ vdbePmaReaderInit(SortSubtask * pTask,	/* Task context */
 	assert(pReadr->aMap == 0);
 
 	rc = vdbePmaReaderSeek(pTask, pReadr, pFile, iStart);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		u64 nByte = 0;	/* Size of PMA in bytes */
 		rc = vdbePmaReadVarint(pReadr, &nByte);
 		pReadr->iEof = pReadr->iReadOff + nByte;
 		*pnByte += nByte;
 	}
 
-	if (rc == SQL_OK) {
+	if (rc == 0)
 		rc = vdbePmaReaderNext(pReadr);
-	}
 	return rc;
 }
 
@@ -806,7 +804,7 @@ vdbeSorterCompare(struct SortSubtask *task, bool *key2_cached,
  * The sorter can guarantee a stable sort when running in single-threaded
  * mode, but not in multi-threaded mode.
  *
- * SQL_OK is returned if successful, or an sql error code otherwise.
+ * 0 is returned if successful, or an sql error code otherwise.
  */
 int
 sqlVdbeSorterInit(sql * db,	/* Database connection (for malloc()) */
@@ -815,7 +813,7 @@ sqlVdbeSorterInit(sql * db,	/* Database connection (for malloc()) */
 {
 	int pgsz;		/* Page size of main database */
 	VdbeSorter *pSorter;	/* The new sorter */
-	int rc = SQL_OK;
+	int rc = 0;
 
 	assert(pCsr->key_def != NULL);
 	assert(pCsr->eCurType == CURTYPE_SORTER);
@@ -964,7 +962,7 @@ vdbeIncrFree(IncrMerger * pIncr)
 void
 sqlVdbeSorterReset(sql * db, VdbeSorter * pSorter)
 {
-	(void)vdbeSorterJoinAll(pSorter, SQL_OK);
+	(void)vdbeSorterJoinAll(pSorter, 0);
 	assert(pSorter->pReader == 0);
 	vdbeMergeEngineFree(pSorter->pMerger);
 	pSorter->pMerger = 0;
@@ -1028,7 +1026,7 @@ vdbeSorterExtendFile(sql * db, sql_file * pFd, i64 nByte)
 
 /*
  * Allocate space for a file-handle and open a temporary file. If successful,
- * set *ppFd to point to the malloc'd file-handle and return SQL_OK.
+ * set *ppFd to point to the malloc'd file-handle and return 0.
  * Otherwise, set *ppFd to 0 and return an sql error code.
  */
 static int
@@ -1041,7 +1039,7 @@ vdbeSorterOpenTempFile(sql * db,	/* Database handle doing sort */
 				 SQL_OPEN_READWRITE | SQL_OPEN_CREATE |
 				 SQL_OPEN_EXCLUSIVE |
 				 SQL_OPEN_DELETEONCLOSE, &rc);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		i64 max = SQL_MAX_MMAP_SIZE;
 		sqlOsFileControlHint(*ppFd, SQL_FCNTL_MMAP_SIZE,
 					 (void *)&max);
@@ -1054,7 +1052,7 @@ vdbeSorterOpenTempFile(sql * db,	/* Database handle doing sort */
 
 /*
  * If it has not already been allocated, allocate the UnpackedRecord
- * structure at pTask->pUnpacked. Return SQL_OK if successful (or
+ * structure at pTask->pUnpacked. Return 0 if successful (or
  * if no allocation was required), or SQL_NOMEM otherwise.
  */
 static int
@@ -1069,7 +1067,7 @@ vdbeSortAllocUnpacked(SortSubtask * pTask)
 		pTask->pUnpacked->nField = pTask->pSorter->key_def->part_count;
 		pTask->pUnpacked->errCode = 0;
 	}
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -1127,7 +1125,7 @@ vdbeSorterGetCompare(VdbeSorter * p)
 
 /*
  * Sort the linked list of records headed at pTask->pList. Return
- * SQL_OK if successful, or an sql error code (i.e. SQL_NOMEM) if
+ * 0 if successful, or an sql error code (i.e. SQL_NOMEM) if
  * an error occurs.
  */
 static int
@@ -1139,7 +1137,7 @@ vdbeSorterSort(SortSubtask * pTask, SorterList * pList)
 	int rc;
 
 	rc = vdbeSortAllocUnpacked(pTask);
-	if (rc != SQL_OK)
+	if (rc != 0)
 		return rc;
 
 	p = pList->pList;
@@ -1185,7 +1183,7 @@ vdbeSorterSort(SortSubtask * pTask, SorterList * pList)
 	pList->pList = p;
 
 	sql_free(aSlot);
-	assert(pTask->pUnpacked->errCode == SQL_OK
+	assert(pTask->pUnpacked->errCode == 0
 	       || pTask->pUnpacked->errCode == SQL_NOMEM);
 	return pTask->pUnpacked->errCode;
 }
@@ -1213,7 +1211,7 @@ vdbePmaWriterInit(sql_file * pFd,	/* File handle to write to */
 }
 
 /*
- * Write nData bytes of data to the PMA. Return SQL_OK
+ * Write nData bytes of data to the PMA. Return 0
  * if successful, or an sql error code if an error occurs.
  */
 static void
@@ -1245,7 +1243,7 @@ vdbePmaWriteBlob(PmaWriter * p, u8 * pData, int nData)
 /*
  * Flush any buffered data to disk and clean up the PMA-writer object.
  * The results of using the PMA-writer after this call are undefined.
- * Return SQL_OK if flushing the buffered data succeeds or is not
+ * Return 0 if flushing the buffered data succeeds or is not
  * required. Otherwise, return an sql error code.
  *
  * Before returning, set *piEof to the offset immediately following the
@@ -1270,7 +1268,7 @@ vdbePmaWriterFinish(PmaWriter * p, i64 * piEof)
 
 /*
  * Write value iVal encoded as a varint to the PMA. Return
- * SQL_OK if successful, or an sql error code if an error occurs.
+ * 0 if successful, or an sql error code if an error occurs.
  */
 static void
 vdbePmaWriteVarint(PmaWriter * p, u64 iVal)
@@ -1283,7 +1281,7 @@ vdbePmaWriteVarint(PmaWriter * p, u64 iVal)
 
 /*
  * Write the current contents of in-memory linked-list pList to a level-0
- * PMA in the temp file belonging to sub-task pTask. Return SQL_OK if
+ * PMA in the temp file belonging to sub-task pTask. Return 0 if
  * successful, or an sql error code otherwise.
  *
  * The format of a PMA is:
@@ -1299,7 +1297,7 @@ static int
 vdbeSorterListToPMA(SortSubtask * pTask, SorterList * pList)
 {
 	sql *db = pTask->pSorter->db;
-	int rc = SQL_OK;	/* Return code */
+	int rc = 0;	/* Return code */
 	PmaWriter writer;	/* Object used to write to the file */
 
 #ifdef SQL_DEBUG
@@ -1316,23 +1314,22 @@ vdbeSorterListToPMA(SortSubtask * pTask, SorterList * pList)
 	/* If the first temporary PMA file has not been opened, open it now. */
 	if (pTask->file.pFd == 0) {
 		rc = vdbeSorterOpenTempFile(db, 0, &pTask->file.pFd);
-		assert(rc != SQL_OK || pTask->file.pFd);
+		assert(rc != 0 || pTask->file.pFd);
 		assert(pTask->file.iEof == 0);
 		assert(pTask->nPMA == 0);
 	}
 
 	/* Try to get the file to memory map */
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		vdbeSorterExtendFile(db, pTask->file.pFd,
 				     pTask->file.iEof + pList->szPMA + 9);
 	}
 
 	/* Sort the list */
-	if (rc == SQL_OK) {
+	if (rc == 0)
 		rc = vdbeSorterSort(pTask, pList);
-	}
 
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		SorterRecord *p;
 		SorterRecord *pNext = 0;
 
@@ -1351,8 +1348,8 @@ vdbeSorterListToPMA(SortSubtask * pTask, SorterList * pList)
 		rc = vdbePmaWriterFinish(&writer, &pTask->file.iEof);
 	}
 
-	assert(rc != SQL_OK || pList->pList == 0);
-	assert(rc != SQL_OK || pTask->file.iEof == iSz);
+	assert(rc != 0 || pList->pList == NULL);
+	assert(rc != 0 || pTask->file.iEof == iSz);
 	return rc;
 }
 
@@ -1361,7 +1358,7 @@ vdbeSorterListToPMA(SortSubtask * pTask, SorterList * pList)
  * Set *pbEof to true there is no next entry because
  * the MergeEngine has reached the end of all its inputs.
  *
- * Return SQL_OK if successful or an error code if an error occurs.
+ * Return 0 if successful or an error code if an error occurs.
  */
 static int
 vdbeMergeEngineStep(MergeEngine * pMerger,	/* The merge engine to advance to the next row */
@@ -1376,7 +1373,7 @@ vdbeMergeEngineStep(MergeEngine * pMerger,	/* The merge engine to advance to the
 	rc = vdbePmaReaderNext(&pMerger->aReadr[iPrev]);
 
 	/* Update contents of aTree[] */
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		int i;		/* Index of aTree[] to recalculate */
 		PmaReader *pReadr1;	/* First PmaReader to compare */
 		PmaReader *pReadr2;	/* Second PmaReader to compare */
@@ -1437,7 +1434,7 @@ vdbeMergeEngineStep(MergeEngine * pMerger,	/* The merge engine to advance to the
 		*pbEof = (pMerger->aReadr[pMerger->aTree[1]].pFd == 0);
 	}
 
-	return (rc == SQL_OK ? pTask->pUnpacked->errCode : rc);
+	return rc == 0 ? pTask->pUnpacked->errCode : rc;
 }
 
 /*
@@ -1460,7 +1457,7 @@ sqlVdbeSorterWrite(const VdbeCursor * pCsr,	/* Sorter cursor */
     )
 {
 	VdbeSorter *pSorter;
-	int rc = SQL_OK;	/* Return Code */
+	int rc = 0;	/* Return Code */
 	SorterRecord *pNew;	/* New list element */
 	int bFlush;		/* True to flush contents of memory to PMA */
 	int nReq;		/* Bytes of memory required */
@@ -1512,7 +1509,7 @@ sqlVdbeSorterWrite(const VdbeCursor * pCsr,	/* Sorter cursor */
 			rc = vdbeSorterFlushPMA(pSorter);
 			pSorter->list.szPMA = 0;
 			pSorter->iMemory = 0;
-			assert(rc != SQL_OK || pSorter->list.pList == 0);
+			assert(rc != 0 || pSorter->list.pList == NULL);
 		}
 	}
 
@@ -1575,7 +1572,7 @@ sqlVdbeSorterWrite(const VdbeCursor * pCsr,	/* Sorter cursor */
 static int
 vdbeIncrPopulate(IncrMerger * pIncr)
 {
-	int rc = SQL_OK;
+	int rc = 0;
 	int rc2;
 	i64 iStart = pIncr->iStartOff;
 	SorterFile *pOut = &pIncr->aFile[1];
@@ -1585,7 +1582,7 @@ vdbeIncrPopulate(IncrMerger * pIncr)
 	assert(pIncr->bEof == 0);
 
 	vdbePmaWriterInit(pOut->pFd, &writer, pTask->pSorter->pgsz, iStart);
-	while (rc == SQL_OK) {
+	while (rc == 0) {
 		int dummy;
 		PmaReader *pReader = &pMerger->aReadr[pMerger->aTree[1]];
 		int nKey = pReader->nKey;
@@ -1608,7 +1605,7 @@ vdbeIncrPopulate(IncrMerger * pIncr)
 	}
 
 	rc2 = vdbePmaWriterFinish(&writer, &pOut->iEof);
-	if (rc == SQL_OK)
+	if (rc == 0)
 		rc = rc2;
 	return rc;
 }
@@ -1628,7 +1625,7 @@ vdbeIncrPopulate(IncrMerger * pIncr)
  * been exhausted, this function also launches a new background thread
  * to populate the new aFile[1].
  *
- * SQL_OK is returned on success, or an sql error code otherwise.
+ * 0 is returned on success, or an sql error code otherwise.
  */
 static int
 vdbeIncrSwap(IncrMerger * pIncr)
@@ -1654,7 +1651,7 @@ vdbeIncrMergerNew(SortSubtask * pTask,	/* The thread that will be using the new
 		  IncrMerger ** ppOut	/* Write the new IncrMerger here */
     )
 {
-	int rc = SQL_OK;
+	int rc = 0;
 	IncrMerger *pIncr = *ppOut =
 		(IncrMerger *) sqlMallocZero(sizeof(*pIncr));
 	if (pIncr) {
@@ -1738,14 +1735,14 @@ static int vdbePmaReaderIncrInit(PmaReader * pReader);
  * vdbePmaReaderIncrMergeInit() to initialize each PmaReader that feeds data
  * to pMerger.
  *
- * SQL_OK is returned if successful, or an sql error code otherwise.
+ * 0 is returned if successful, or an sql error code otherwise.
  */
 static int
 vdbeMergeEngineInit(SortSubtask * pTask,	/* Thread that will run pMerger */
 		    MergeEngine * pMerger 	/* MergeEngine to initialize */
     )
 {
-	int rc = SQL_OK;	/* Return code */
+	int rc = 0;	/* Return code */
 	int i;			/* For looping over PmaReader objects */
 	int nTree = pMerger->nTree;
 
@@ -1755,7 +1752,7 @@ vdbeMergeEngineInit(SortSubtask * pTask,	/* Thread that will run pMerger */
 
 	for (i = 0; i < nTree; i++) {
 		rc = vdbePmaReaderIncrInit(&pMerger->aReadr[i]);
-		if (rc != SQL_OK)
+		if (rc != 0)
 			return rc;
 	}
 
@@ -1776,12 +1773,12 @@ vdbeMergeEngineInit(SortSubtask * pTask,	/* Thread that will run pMerger */
  * loaded into the buffers belonging to pReadr and it is set to point to
  * the first key in its range.
  *
- * SQL_OK is returned if successful, or an sql error code otherwise.
+ * 0 is returned if successful, or an sql error code otherwise.
  */
 static int
 vdbePmaReaderIncrMergeInit(PmaReader * pReadr)
 {
-	int rc = SQL_OK;
+	int rc = 0;
 	IncrMerger *pIncr = pReadr->pIncr;
 	SortSubtask *pTask = pIncr->pTask;
 	sql *db = pTask->pSorter->db;
@@ -1792,7 +1789,7 @@ vdbePmaReaderIncrMergeInit(PmaReader * pReadr)
 	 * requires two temp files to itself, whereas a single-threaded object
 	 * only requires a region of pTask->file2.
 	 */
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		int mxSz = pIncr->mxSz;
 		if (pTask->file2.pFd == 0) {
 			assert(pTask->file2.iEof > 0);
@@ -1801,14 +1798,14 @@ vdbePmaReaderIncrMergeInit(PmaReader * pReadr)
 						    &pTask->file2.pFd);
 			pTask->file2.iEof = 0;
 		}
-		if (rc == SQL_OK) {
+		if (rc == 0) {
 			pIncr->aFile[1].pFd = pTask->file2.pFd;
 			pIncr->iStartOff = pTask->file2.iEof;
 			pTask->file2.iEof += mxSz;
 		}
 	}
 
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		rc = vdbePmaReaderNext(pReadr);
 	}
 
@@ -1830,7 +1827,7 @@ static int
 vdbePmaReaderIncrInit(PmaReader * pReadr)
 {
 	IncrMerger *pIncr = pReadr->pIncr;	/* Incremental merger */
-	int rc = SQL_OK;	/* Return code */
+	int rc = 0;	/* Return code */
 	if (pIncr) {
 		rc = vdbePmaReaderIncrMergeInit(pReadr);
 	}
@@ -1840,7 +1837,7 @@ vdbePmaReaderIncrInit(PmaReader * pReadr)
 /*
  * Allocate a new MergeEngine object to merge the contents of nPMA level-0
  * PMAs from pTask->file. If no error occurs, set *ppOut to point to
- * the new object and return SQL_OK. Or, if an error does occur, set *ppOut
+ * the new object and return 0. Or, if an error does occur, set *ppOut
  * to NULL and return an sql error code.
  *
  * When this function is called, *piOffset is set to the offset of the
@@ -1859,13 +1856,13 @@ vdbeMergeEngineLevel0(SortSubtask * pTask,	/* Sorter task to read from */
 	MergeEngine *pNew;	/* Merge engine to return */
 	i64 iOff = *piOffset;
 	int i;
-	int rc = SQL_OK;
+	int rc = 0;
 
 	*ppOut = pNew = vdbeMergeEngineNew(nPMA);
 	if (pNew == 0)
 		rc = SQL_NOMEM;
 
-	for (i = 0; i < nPMA && rc == SQL_OK; i++) {
+	for (i = 0; i < nPMA && rc == 0; i++) {
 		i64 nDummy = 0;
 		PmaReader *pReadr = &pNew->aReadr[i];
 		rc = vdbePmaReaderInit(pTask, &pTask->file, iOff, pReadr,
@@ -1873,7 +1870,7 @@ vdbeMergeEngineLevel0(SortSubtask * pTask,	/* Sorter task to read from */
 		iOff = pReadr->iEof;
 	}
 
-	if (rc != SQL_OK) {
+	if (rc != 0) {
 		vdbeMergeEngineFree(pNew);
 		*ppOut = 0;
 	}
@@ -1908,7 +1905,7 @@ vdbeSorterTreeDepth(int nPMA)
  * to vdbeSorterTreeDepth()). pLeaf is the iSeq'th leaf to be added to the
  * tree, counting from zero. This function adds pLeaf to the tree.
  *
- * If successful, SQL_OK is returned. If an error occurs, an sql error
+ * If successful, 0 is returned. If an error occurs, an sql error
  * code is returned and pLeaf is freed.
  */
 static int
@@ -1919,7 +1916,7 @@ vdbeSorterAddToTree(SortSubtask * pTask,	/* Task context */
 		    MergeEngine * pLeaf	/* Leaf to add to tree */
     )
 {
-	int rc = SQL_OK;
+	int rc = 0;
 	int nDiv = 1;
 	int i;
 	MergeEngine *p = pRoot;
@@ -1931,7 +1928,7 @@ vdbeSorterAddToTree(SortSubtask * pTask,	/* Task context */
 		nDiv = nDiv * SORTER_MAX_MERGE_COUNT;
 	}
 
-	for (i = 1; i < nDepth && rc == SQL_OK; i++) {
+	for (i = 1; i < nDepth && rc == 0; i++) {
 		int iIter = (iSeq / nDiv) % SORTER_MAX_MERGE_COUNT;
 		PmaReader *pReadr = &p->aReadr[iIter];
 
@@ -1945,13 +1942,13 @@ vdbeSorterAddToTree(SortSubtask * pTask,	/* Task context */
 						       &pReadr->pIncr);
 			}
 		}
-		if (rc == SQL_OK) {
+		if (rc == 0) {
 			p = pReadr->pIncr->pMerger;
 			nDiv = nDiv / SORTER_MAX_MERGE_COUNT;
 		}
 	}
 
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		p->aReadr[iSeq % SORTER_MAX_MERGE_COUNT].pIncr = pIncr;
 	} else {
 		vdbeIncrFree(pIncr);
@@ -1965,7 +1962,7 @@ vdbeSorterAddToTree(SortSubtask * pTask,	/* Task context */
  * files. It builds a tree of MergeEngine/IncrMerger/PmaReader objects that
  * can be used to incrementally merge all PMAs on disk.
  *
- * If successful, SQL_OK is returned and *ppOut set to point to the
+ * If successful, 0 is returned and *ppOut set to point to the
  * MergeEngine object at the root of the tree before returning. Or, if an
  * error occurs, an sql error code is returned and the final value
  * of *ppOut is undefined.
@@ -1976,7 +1973,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter,	/* The VDBE cursor that implement
     )
 {
 	MergeEngine *pMain = 0;
-	int rc = SQL_OK;
+	int rc = 0;
 
 	SortSubtask *pTask = &pSorter->aTask;
 	assert(pTask->nPMA > 0);
@@ -1995,7 +1992,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter,	/* The VDBE cursor that implement
 			    vdbeMergeEngineNew(SORTER_MAX_MERGE_COUNT);
 			if (pRoot == 0)
 				rc = SQL_NOMEM;
-			for (i = 0; i < pTask->nPMA && rc == SQL_OK;
+			for (i = 0; i < pTask->nPMA && rc == 0;
 			     i += SORTER_MAX_MERGE_COUNT) {
 				MergeEngine *pMerger = 0;	/* New level-0 PMA merger */
 				int nReader;	/* Number of level-0 PMAs to merge */
@@ -2007,7 +2004,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter,	/* The VDBE cursor that implement
 							   nReader,
 							   &iReadOff,
 							   &pMerger);
-				if (rc == SQL_OK) {
+				if (rc == 0) {
 					rc = vdbeSorterAddToTree(pTask,
 								 nDepth,
 								 iSeq++,
@@ -2017,7 +2014,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter,	/* The VDBE cursor that implement
 			}
 		}
 
-		if (rc == SQL_OK) {
+		if (rc == 0) {
 			assert(pMain == 0);
 			pMain = pRoot;
 		} else {
@@ -2025,7 +2022,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter,	/* The VDBE cursor that implement
 		}
 	}
 
-	if (rc != SQL_OK) {
+	if (rc != 0) {
 		vdbeMergeEngineFree(pMain);
 		pMain = 0;
 	}
@@ -2040,7 +2037,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter,	/* The VDBE cursor that implement
  * (for multi-threaded sorters) so that it can be used to iterate through
  * all records stored in the sorter.
  *
- * SQL_OK is returned if successful, or an sql error code otherwise.
+ * 0 is returned if successful, or an sql error code otherwise.
  */
 static int
 vdbeSorterSetupMerge(VdbeSorter * pSorter)
@@ -2049,15 +2046,14 @@ vdbeSorterSetupMerge(VdbeSorter * pSorter)
 	MergeEngine *pMain = 0;
 
 	rc = vdbeSorterMergeTreeBuild(pSorter, &pMain);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		rc = vdbeMergeEngineInit(&pSorter->aTask, pMain);
 		pSorter->pMerger = pMain;
 		pMain = 0;
 	}
 
-	if (rc != SQL_OK) {
+	if (rc != 0)
 		vdbeMergeEngineFree(pMain);
-	}
 	return rc;
 }
 
@@ -2070,7 +2066,7 @@ int
 sqlVdbeSorterRewind(const VdbeCursor * pCsr, int *pbEof)
 {
 	VdbeSorter *pSorter;
-	int rc = SQL_OK;	/* Return code */
+	int rc = 0;	/* Return code */
 
 	assert(pCsr->eCurType == CURTYPE_SORTER);
 	pSorter = pCsr->uc.pSorter;
@@ -2105,7 +2101,7 @@ sqlVdbeSorterRewind(const VdbeCursor * pCsr, int *pbEof)
 	 * incrementally read and merge all remaining PMAs.
 	 */
 	assert(pSorter->pReader == 0);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		rc = vdbeSorterSetupMerge(pSorter);
 		*pbEof = 0;
 	}
@@ -2138,7 +2134,7 @@ sqlVdbeSorterNext(sql * db, const VdbeCursor * pCsr, int *pbEof)
 		if (pSorter->list.aMemory == 0)
 			vdbeSorterRecordFree(db, pFree);
 		*pbEof = !pSorter->list.pList;
-		rc = SQL_OK;
+		rc = 0;
 	}
 	return rc;
 }
@@ -2189,7 +2185,7 @@ sqlVdbeSorterRowkey(const VdbeCursor * pCsr, Mem * pOut)
 	MemSetTypeFlag(pOut, MEM_Blob);
 	memcpy(pOut->z, pKey, nKey);
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -2238,10 +2234,10 @@ sqlVdbeSorterCompare(const VdbeCursor * pCsr,	/* Sorter cursor */
 	for (i = 0; i < nKeyCol; i++) {
 		if (r2->aMem[i].flags & MEM_Null) {
 			*pRes = -1;
-			return SQL_OK;
+			return 0;
 		}
 	}
 
 	*pRes = sqlVdbeRecordCompareMsgpack(pVal->z, r2);
-	return SQL_OK;
+	return 0;
 }
diff --git a/src/box/sql/where.c b/src/box/sql/where.c
index b1eca58..a2f8934 100644
--- a/src/box/sql/where.c
+++ b/src/box/sql/where.c
@@ -1175,7 +1175,7 @@ whereRangeAdjust(WhereTerm * pTerm, LogEst nNew)
  * is left as is.
  *
  * If an error occurs, an sql error code is returned. Otherwise,
- * SQL_OK.
+ * 0.
  */
 static int
 whereRangeSkipScanEst(Parse * pParse,		/* Parsing & code generating context */
@@ -1193,7 +1193,7 @@ whereRangeSkipScanEst(Parse * pParse,		/* Parsing & code generating context */
 	sql *db = pParse->db;
 	int nLower = -1;
 	int nUpper = index->def->opts.stat->sample_count + 1;
-	int rc = SQL_OK;
+	int rc = 0;
 	enum field_type type = p->key_def->parts[nEq].type;
 
 	sql_value *p1 = 0;	/* Value extracted from pLower */
@@ -1206,7 +1206,7 @@ whereRangeSkipScanEst(Parse * pParse,		/* Parsing & code generating context */
 					       type, &p1);
 		nLower = 0;
 	}
-	if (pUpper && rc == SQL_OK) {
+	if (pUpper != NULL && rc == 0) {
 		rc = sqlStat4ValueFromExpr(pParse, pUpper->pExpr->pRight,
 					       type, &p2);
 		nUpper = p2 ? 0 : index->def->opts.stat->sample_count;
@@ -1217,15 +1217,15 @@ whereRangeSkipScanEst(Parse * pParse,		/* Parsing & code generating context */
 		int nDiff;
 		struct index_sample *samples = index->def->opts.stat->samples;
 		uint32_t sample_count = index->def->opts.stat->sample_count;
-		for (i = 0; rc == SQL_OK && i < (int) sample_count; i++) {
+		for (i = 0; rc == 0 && i < (int) sample_count; i++) {
 			rc = sql_stat4_column(db, samples[i].sample_key, nEq,
 					      &pVal);
-			if (rc == SQL_OK && p1) {
+			if (rc == 0 && p1 != NULL) {
 				int res = sqlMemCompare(p1, pVal, coll);
 				if (res >= 0)
 					nLower++;
 			}
-			if (rc == SQL_OK && p2) {
+			if (rc == 0 && p2 != NULL) {
 				int res = sqlMemCompare(p2, pVal, coll);
 				if (res >= 0)
 					nUpper++;
@@ -1309,7 +1309,7 @@ whereRangeScanEst(Parse * pParse,	/* Parsing & code generating context */
 		  WhereTerm * pUpper,	/* Upper bound on the range. ex: "x<455" Might be NULL */
 		  WhereLoop * pLoop)	/* Modify the .nOut and maybe .rRun fields */
 {
-	int rc = SQL_OK;
+	int rc = 0;
 	int nOut = pLoop->nOut;
 	LogEst nNew;
 
@@ -1399,7 +1399,7 @@ whereRangeScanEst(Parse * pParse,	/* Parsing & code generating context */
 				rc = sqlStat4ProbeSetValue(pParse, p, &pRec,
 							       pExpr, nBtm, nEq,
 							       &n);
-				if (rc == SQL_OK && n) {
+				if (rc == 0 && n != 0) {
 					tRowcnt iNew;
 					u16 mask = WO_GT | WO_LE;
 					if (sqlExprVectorSize(pExpr) > n)
@@ -1425,7 +1425,7 @@ whereRangeScanEst(Parse * pParse,	/* Parsing & code generating context */
 				rc = sqlStat4ProbeSetValue(pParse, p, &pRec,
 							       pExpr, nTop, nEq,
 							       &n);
-				if (rc == SQL_OK && n) {
+				if (rc == 0 && n != 0) {
 					tRowcnt iNew;
 					u16 mask = WO_GT | WO_LE;
 					if (sqlExprVectorSize(pExpr) > n)
@@ -1445,7 +1445,7 @@ whereRangeScanEst(Parse * pParse,	/* Parsing & code generating context */
 			}
 
 			pBuilder->pRec = pRec;
-			if (rc == SQL_OK) {
+			if (rc == 0) {
 				if (iUpper > iLower) {
 					nNew = sqlLogEst(iUpper - iLower);
 					/* TUNING:  If both iUpper and iLower are derived from the same
@@ -1513,7 +1513,7 @@ whereRangeScanEst(Parse * pParse,	/* Parsing & code generating context */
  * for that index.  When pExpr==NULL that means the constraint is
  * "x IS NULL" instead of "x=VALUE".
  *
- * Write the estimated row count into *pnRow and return SQL_OK.
+ * Write the estimated row count into *pnRow and return 0.
  * If unable to make an estimate, leave *pnRow unchanged and return
  * non-zero.
  *
@@ -1548,7 +1548,7 @@ whereEqualScanEst(Parse * pParse,	/* Parsing & code generating context */
 	rc = sqlStat4ProbeSetValue(pParse, p, &pRec, pExpr, 1, nEq - 1,
 				       &bOk);
 	pBuilder->pRec = pRec;
-	if (rc != SQL_OK)
+	if (rc != 0)
 		return rc;
 	if (bOk == 0)
 		return SQL_NOTFOUND;
@@ -1569,7 +1569,7 @@ whereEqualScanEst(Parse * pParse,	/* Parsing & code generating context */
  *
  *        WHERE x IN (1,2,3,4)
  *
- * Write the estimated row count into *pnRow and return SQL_OK.
+ * Write the estimated row count into *pnRow and return 0.
  * If unable to make an estimate, leave *pnRow unchanged and return
  * non-zero.
  *
@@ -1586,12 +1586,12 @@ whereInScanEst(Parse * pParse,	/* Parsing & code generating context */
 	struct index_def *p = pBuilder->pNew->index_def;
 	i64 nRow0 = sqlLogEstToInt(index_field_tuple_est(p, 0));
 	int nRecValid = pBuilder->nRecValid;
-	int rc = SQL_OK;	/* Subfunction return code */
+	int rc = 0;	/* Subfunction return code */
 	tRowcnt nEst;		/* Number of rows for a single term */
 	tRowcnt nRowEst = 0;	/* New estimate of the number of rows */
 	int i;			/* Loop counter */
 
-	for (i = 0; rc == SQL_OK && i < pList->nExpr; i++) {
+	for (i = 0; rc == 0 && i < pList->nExpr; i++) {
 		nEst = nRow0;
 		rc = whereEqualScanEst(pParse, pBuilder, pList->a[i].pExpr,
 				       &nEst);
@@ -1599,7 +1599,7 @@ whereInScanEst(Parse * pParse,	/* Parsing & code generating context */
 		pBuilder->nRecValid = nRecValid;
 	}
 
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		if (nRowEst > nRow0)
 			nRowEst = nRow0;
 		*pnRow = nRowEst;
@@ -1755,7 +1755,7 @@ whereLoopResize(sql * db, WhereLoop * p, int n)
 {
 	WhereTerm **paNew;
 	if (p->nLSlot >= n)
-		return SQL_OK;
+		return 0;
 	n = (n + 7) & ~7;
 	paNew = sqlDbMallocRawNN(db, sizeof(p->aLTerm[0]) * n);
 	if (paNew == 0)
@@ -1765,7 +1765,7 @@ whereLoopResize(sql * db, WhereLoop * p, int n)
 		sqlDbFree(db, p->aLTerm);
 	p->aLTerm = paNew;
 	p->nLSlot = n;
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -1787,7 +1787,7 @@ whereLoopXfer(sql * db, WhereLoop * pTo, WhereLoop * pFrom)
 	       pTo->nLTerm * sizeof(pTo->aLTerm[0]));
 	if ((pFrom->wsFlags & WHERE_AUTO_INDEX) != 0)
 		pFrom->index_def = NULL;
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -2056,7 +2056,7 @@ whereLoopInsert(WhereLoopBuilder * pBuilder, WhereLoop * pTemplate)
 			}
 #endif
 		}
-		return SQL_OK;
+		return 0;
 	}
 
 	/* Look for an existing WhereLoop to replace with pTemplate
@@ -2074,7 +2074,7 @@ whereLoopInsert(WhereLoopBuilder * pBuilder, WhereLoop * pTemplate)
 			whereLoopPrint(pTemplate, pBuilder->pWC);
 		}
 #endif
-		return SQL_OK;
+		return 0;
 	} else {
 		p = *ppPrev;
 	}
@@ -2318,7 +2318,7 @@ whereLoopAddBtreeIndex(WhereLoopBuilder * pBuilder,	/* The WhereLoop factory */
 	u16 saved_nSkip;	/* Original value of pNew->nSkip */
 	u32 saved_wsFlags;	/* Original value of pNew->wsFlags */
 	LogEst saved_nOut;	/* Original value of pNew->nOut */
-	int rc = SQL_OK;	/* Return code */
+	int rc = 0;	/* Return code */
 	LogEst rSize;		/* Number of rows in the table */
 	LogEst rLogSize;	/* Logarithm of table size */
 	WhereTerm *pTop = 0, *pBtm = 0;	/* Top and bottom range constraints */
@@ -2370,7 +2370,7 @@ whereLoopAddBtreeIndex(WhereLoopBuilder * pBuilder,	/* The WhereLoop factory */
 	pNew->rSetup = 0;
 	rSize = index_field_tuple_est(probe, 0);
 	rLogSize = estLog(rSize);
-	for (; rc == SQL_OK && pTerm != 0; pTerm = whereScanNext(&scan)) {
+	for (; rc == 0 && pTerm != NULL; pTerm = whereScanNext(&scan)) {
 		u16 eOp = pTerm->eOperator;	/* Shorthand for pTerm->eOperator */
 		LogEst rCostIdx;
 		LogEst nOutUnadjusted;	/* nOut before IN() and WHERE adjustments */
@@ -2552,8 +2552,8 @@ whereLoopAddBtreeIndex(WhereLoopBuilder * pBuilder,	/* The WhereLoop factory */
 								    &nOut);
 					}
 					if (rc == SQL_NOTFOUND)
-						rc = SQL_OK;
-					if (rc != SQL_OK)
+						rc = 0;
+					if (rc != 0)
 						break;	/* Jump out of the pTerm loop */
 					if (nOut) {
 						pNew->nOut =
@@ -2651,7 +2651,7 @@ whereLoopAddBtreeIndex(WhereLoopBuilder * pBuilder,	/* The WhereLoop factory */
 	    stat->skip_scan_enabled == true &&
 	    /* TUNING: Minimum for skip-scan */
 	    index_field_tuple_est(probe, saved_nEq + 1) >= 42 &&
-	    (rc = whereLoopResize(db, pNew, pNew->nLTerm + 1)) == SQL_OK) {
+	    (rc = whereLoopResize(db, pNew, pNew->nLTerm + 1)) == 0) {
 		LogEst nIter;
 		pNew->nEq++;
 		pNew->nSkip++;
@@ -2760,7 +2760,7 @@ whereLoopAddBtree(WhereLoopBuilder * pBuilder,	/* WHERE clause information */
 	SrcList *pTabList;	/* The FROM clause */
 	struct SrcList_item *pSrc;	/* The FROM clause btree term to add */
 	WhereLoop *pNew;	/* Template WhereLoop object */
-	int rc = SQL_OK;	/* Return code */
+	int rc = 0;	/* Return code */
 	int iSortIdx = 1;	/* Index number */
 	int b;			/* A boolean value */
 	LogEst rSize;		/* number of rows in the table */
@@ -2843,7 +2843,7 @@ tnt_error:
 		/* Generate auto-index WhereLoops */
 		WhereTerm *pTerm;
 		WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
-		for (pTerm = pWC->a; rc == SQL_OK && pTerm < pWCEnd; pTerm++) {
+		for (pTerm = pWC->a; rc == 0 && pTerm < pWCEnd; pTerm++) {
 			if (pTerm->prereqRight & pNew->maskSelf)
 				continue;
 			if (termCanDriveIndex(pTerm, pSrc, 0)) {
@@ -2958,7 +2958,7 @@ whereLoopAddOr(WhereLoopBuilder * pBuilder, Bitmask mPrereq, Bitmask mUnusable)
 	WhereClause *pWC;
 	WhereLoop *pNew;
 	WhereTerm *pTerm, *pWCEnd;
-	int rc = SQL_OK;
+	int rc = 0;
 	int iCur;
 	WhereClause tempWC;
 	WhereLoopBuilder sSubBuild;
@@ -2972,7 +2972,7 @@ whereLoopAddOr(WhereLoopBuilder * pBuilder, Bitmask mPrereq, Bitmask mUnusable)
 	pItem = pWInfo->pTabList->a + pNew->iTab;
 	iCur = pItem->iCursor;
 
-	for (pTerm = pWC->a; pTerm < pWCEnd && rc == SQL_OK; pTerm++) {
+	for (pTerm = pWC->a; pTerm < pWCEnd && rc == 0; pTerm++) {
 		if ((pTerm->eOperator & WO_OR) != 0
 		    && (pTerm->u.pOrInfo->indexable & pNew->maskSelf) != 0) {
 			WhereClause *const pOrWC = &pTerm->u.pOrInfo->wc;
@@ -3015,11 +3015,11 @@ whereLoopAddOr(WhereLoopBuilder * pBuilder, Bitmask mPrereq, Bitmask mUnusable)
 					rc = whereLoopAddBtree(&sSubBuild,
 							       mPrereq);
 				}
-				if (rc == SQL_OK) {
+				if (rc == 0) {
 					rc = whereLoopAddOr(&sSubBuild, mPrereq,
 							    mUnusable);
 				}
-				assert(rc == SQL_OK || sCur.n == 0);
+				assert(rc == 0 || sCur.n == 0);
 				if (sCur.n == 0) {
 					sSum.n = 0;
 					break;
@@ -3052,7 +3052,7 @@ whereLoopAddOr(WhereLoopBuilder * pBuilder, Bitmask mPrereq, Bitmask mUnusable)
 			pNew->nBtm = 0;
 			pNew->nTop = 0;
 			pNew->index_def = NULL;
-			for (i = 0; rc == SQL_OK && i < sSum.n; i++) {
+			for (i = 0; rc == 0 && i < sSum.n; i++) {
 				/* TUNING: Currently sSum.a[i].rRun is set to the sum of the costs
 				 * of all sub-scans required by the OR-scan. However, due to rounding
 				 * errors, it may be that the cost of the OR-scan is equal to its
@@ -3092,7 +3092,7 @@ whereLoopAddAll(WhereLoopBuilder * pBuilder)
 	struct SrcList_item *pItem;
 	struct SrcList_item *pEnd = &pTabList->a[pWInfo->nLevel];
 	sql *db = pWInfo->pParse->db;
-	int rc = SQL_OK;
+	int rc = 0;
 	WhereLoop *pNew;
 	u8 priorJointype = 0;
 
@@ -3115,9 +3115,8 @@ whereLoopAddAll(WhereLoopBuilder * pBuilder)
 		{
 			rc = whereLoopAddBtree(pBuilder, mPrereq);
 		}
-		if (rc == SQL_OK) {
+		if (rc == 0)
 			rc = whereLoopAddOr(pBuilder, mPrereq, mUnusable);
-		}
 		mPrior |= pNew->maskSelf;
 		if (rc || db->mallocFailed)
 			break;
@@ -3566,7 +3565,7 @@ whereSortingCost(WhereInfo * pWInfo, LogEst nRow, int nOrderBy, int nSorted)
  * will be nRowEst (in the 10*log2 representation).  Or, ignore sorting
  * costs if nRowEst==0.
  *
- * Return SQL_OK on success or SQL_NOMEM of a memory allocation
+ * Return 0 on success or SQL_NOMEM of a memory allocation
  * error occurs.
  */
 static int
@@ -4001,7 +4000,7 @@ wherePathSolver(WhereInfo * pWInfo, LogEst nRowEst)
 
 	/* Free temporary memory and return success */
 	sqlDbFree(db, pSpace);
-	return SQL_OK;
+	return 0;
 }
 
 /**

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 15/28] sql: remove SQL_SCHEMA errcode
  2019-06-13 22:24   ` [tarantool-patches] " Vladislav Shpilevoy
@ 2019-06-15  9:55     ` Mergen Imeev
  0 siblings, 0 replies; 56+ messages in thread
From: Mergen Imeev @ 2019-06-15  9:55 UTC (permalink / raw)
  To: Vladislav Shpilevoy; +Cc: tarantool-patches

On Fri, Jun 14, 2019 at 12:24:57AM +0200, Vladislav Shpilevoy wrote:
> Thanks for the patch!
> 
> Consider my review fix below and on the branch
> in a separate commit.
> 
> ======================================================
>
Thank you! New patch:

From 3ee6578d0c3400b991d8cceabe572b52c7c8cd85 Mon Sep 17 00:00:00 2001
Date: Tue, 21 May 2019 17:34:13 +0300
Subject: [PATCH] sql: remove SQL_SCHEMA errcode

Removing this error code is part of getting rid of the SQL error
system.

diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index 3ed1269..d909c8b 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -56,7 +56,7 @@ sqlPrepare(sql * db,	/* Database handle. */
 	Parse sParse;		/* Parsing context */
 	sql_parser_create(&sParse, db, current_session()->sql_flags);
 	sParse.pReprepare = pReprepare;
-	assert(ppStmt && *ppStmt == 0);
+	*ppStmt = NULL;
 	/* assert( !db->mallocFailed ); // not true with SQL_USE_ALLOCA */
 
 	/* Check to verify that it is possible to get a read lock on all
@@ -181,37 +181,12 @@ sqlPrepare(sql * db,	/* Database handle. */
 	return rc;
 }
 
-static int
-sqlLockAndPrepare(sql * db,		/* Database handle. */
-		      const char *zSql,		/* UTF-8 encoded SQL statement. */
-		      int nBytes,		/* Length of zSql in bytes. */
-		      int saveSqlFlag,		/* True to copy SQL text into the sql_stmt */
-		      Vdbe * pOld,		/* VM being reprepared */
-		      sql_stmt ** ppStmt,	/* OUT: A pointer to the prepared statement */
-		      const char **pzTail)	/* OUT: End of parsed string */
-{
-	int rc;
-
-	*ppStmt = 0;
-	assert(zSql != NULL && db != NULL);
-	rc = sqlPrepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt,
-			    pzTail);
-	if (rc == SQL_SCHEMA) {
-		sql_finalize(*ppStmt);
-		rc = sqlPrepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt,
-				    pzTail);
-	}
-	assert(rc == 0 || *ppStmt == NULL);
-	return rc;
-}
-
 /*
  * Rerun the compilation of a statement after a schema change.
  */
 int
 sqlReprepare(Vdbe * p)
 {
-	int rc;
 	sql_stmt *pNew;
 	const char *zSql;
 	sql *db;
@@ -219,16 +194,11 @@ sqlReprepare(Vdbe * p)
 	zSql = sql_sql((sql_stmt *) p);
 	assert(zSql != 0);	/* Reprepare only called for prepare_v2() statements */
 	db = sqlVdbeDb(p);
-	rc = sqlLockAndPrepare(db, zSql, -1, 0, p, &pNew, 0);
-	if (rc) {
-		if (rc == SQL_NOMEM) {
-			sqlOomFault(db);
-		}
+	if (sqlPrepare(db, zSql, -1, 0, p, &pNew, 0) != 0) {
 		assert(pNew == 0);
-		return rc;
-	} else {
-		assert(pNew != 0);
+		return -1;
 	}
+	assert(pNew != 0);
 	sqlVdbeSwap((Vdbe *) pNew, p);
 	sqlTransferBindings(pNew, (sql_stmt *) p);
 	sqlVdbeResetStepResult((Vdbe *) pNew);
@@ -239,7 +209,7 @@ sqlReprepare(Vdbe * p)
 /*
  * Two versions of the official API.  Legacy and new use.  In the legacy
  * version, the original SQL text is not saved in the prepared statement
- * and so if a schema change occurs, SQL_SCHEMA is returned by
+ * and so if a schema change occurs, an error is returned by
  * sql_step().  In the new version, the original SQL text is retained
  * and the statement is automatically recompiled if an schema change
  * occurs.
@@ -251,8 +221,7 @@ sql_prepare(sql * db,		/* Database handle. */
 		sql_stmt ** ppStmt,	/* OUT: A pointer to the prepared statement */
 		const char **pzTail)	/* OUT: End of parsed string */
 {
-	int rc;
-	rc = sqlLockAndPrepare(db, zSql, nBytes, 0, 0, ppStmt, pzTail);
+	int rc = sqlPrepare(db, zSql, nBytes, 0, 0, ppStmt, pzTail);
 	assert(rc == 0 || ppStmt == NULL || *ppStmt == NULL);	/* VERIFY: F13021 */
 	return rc;
 }
@@ -265,8 +234,7 @@ sql_prepare_v2(sql * db,	/* Database handle. */
 		   const char **pzTail	/* OUT: End of parsed string */
     )
 {
-	int rc;
-	rc = sqlLockAndPrepare(db, zSql, nBytes, 1, 0, ppStmt, pzTail);
+	int rc = sqlPrepare(db, zSql, nBytes, 1, 0, ppStmt, pzTail);
 	assert(rc == 0 || ppStmt == NULL || *ppStmt == NULL);	/* VERIFY: F13021 */
 	return rc;
 }
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index beae49c..9dfecb7 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -333,8 +333,6 @@ enum sql_ret_code {
 	SQL_NOMEM,
 	/** Some kind of disk I/O error occurred. */
 	SQL_IOERR,
-	/** The database schema changed. */
-	SQL_SCHEMA,
 	/** String or BLOB exceeds size limit. */
 	SQL_TOOBIG,
 	/** Abort due to constraint violation. */
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 37e0892..bc13eb2 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -5089,10 +5089,7 @@ case OP_AggFinal: {
 
 /* Opcode: Expire P1 * * * *
  *
- * Cause precompiled statements to expire.  When an expired statement
- * is executed using sql_step() it will either automatically
- * reprepare itself (if it was originally created using sql_prepare_v2())
- * or it will fail with SQL_SCHEMA.
+ * Cause precompiled statements to expire.
  *
  * If P1 is 0, then all SQL statements become expired. If P1 is non-zero,
  * then only the currently executing statement is expired.
diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h
index 064eb46..2b53aaf 100644
--- a/src/box/sql/vdbeInt.h
+++ b/src/box/sql/vdbeInt.h
@@ -40,14 +40,6 @@
 #define SQL_VDBEINT_H
 
 /*
- * The maximum number of times that a statement will try to reparse
- * itself before giving up and returning SQL_SCHEMA.
- */
-#ifndef SQL_MAX_SCHEMA_RETRY
-#define SQL_MAX_SCHEMA_RETRY 50
-#endif
-
-/*
  * SQL is translated into a sequence of instructions to be
  * executed by a virtual machine.  Each instruction is an instance
  * of the following structure.
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 2f69853..46ca499 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -424,9 +424,8 @@ sqlStep(Vdbe * p)
 	}
 
 	if (p->pc <= 0 && p->expired) {
-		p->rc = SQL_SCHEMA;
-		rc = SQL_ERROR;
-		goto end_of_step;
+		p->rc = SQL_TARANTOOL_ERROR;
+		return SQL_TARANTOOL_ERROR;
 	}
 	if (p->pc < 0) {
 
@@ -455,7 +454,6 @@ sqlStep(Vdbe * p)
 	if (SQL_NOMEM == sqlApiExit(p->db, p->rc)) {
 		p->rc = SQL_NOMEM;
 	}
- end_of_step:
 	if (p->isPrepareV2 && rc != SQL_ROW && rc != SQL_DONE) {
 		/* If this statement was prepared using sql_prepare_v2(), and an
 		 * error has occurred, then return the error code in p->rc to the
@@ -474,24 +472,9 @@ sqlStep(Vdbe * p)
 int
 sql_step(sql_stmt * pStmt)
 {
-	int rc;			/* Result from sqlStep() */
 	Vdbe *v = (Vdbe *) pStmt;	/* the prepared statement */
-	int cnt = 0;		/* Counter to prevent infinite loop of reprepares */
-
 	assert(v != NULL);
-	v->doingRerun = 0;
-	while ((rc = sqlStep(v)) == SQL_SCHEMA
-	       && cnt++ < SQL_MAX_SCHEMA_RETRY) {
-		int savedPc = v->pc;
-		rc = sqlReprepare(v);
-		if (rc != 0)
-			break;
-		sql_reset(pStmt);
-		if (savedPc >= 0)
-			v->doingRerun = 1;
-		assert(v->expired == 0);
-	}
-	return rc;
+	return sqlStep(v);
 }
 
 /*

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 16/28] sql: remove SQL_TOOBIG errcode
  2019-06-13 22:24   ` [tarantool-patches] " Vladislav Shpilevoy
@ 2019-06-15  9:57     ` Mergen Imeev
  0 siblings, 0 replies; 56+ messages in thread
From: Mergen Imeev @ 2019-06-15  9:57 UTC (permalink / raw)
  To: Vladislav Shpilevoy; +Cc: tarantool-patches

On Fri, Jun 14, 2019 at 12:24:51AM +0200, Vladislav Shpilevoy wrote:
> Thanks for the patch!
> 
> Consider my review fixes below and on the branch
> in a separate commit.
> 
Thank you! New patch:


m 2d50f8d28fb991190358a2ef49367909390d8fd1 Mon Sep 17 00:00:00 2001
Date: Tue, 21 May 2019 17:44:59 +0300
Subject: [PATCH] sql: remove SQL_TOOBIG errcode

Removing this error code is part of getting rid of the SQL error
system.

diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 9dfecb7..1056411 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -333,8 +333,6 @@ enum sql_ret_code {
 	SQL_NOMEM,
 	/** Some kind of disk I/O error occurred. */
 	SQL_IOERR,
-	/** String or BLOB exceeds size limit. */
-	SQL_TOOBIG,
 	/** Abort due to constraint violation. */
 	SQL_CONSTRAINT,
 	SQL_TARANTOOL_ERROR,
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 46ca499..1ffb93e 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -258,7 +258,7 @@ sql_value_free(sql_value * pOld)
  *
  * The setStrOrError() function calls sqlVdbeMemSetStr() to store the
  * result as a string or blob but if the string or blob is too large, it
- * then sets the error code to SQL_TOOBIG
+ * then sets the error code.
  *
  * The invokeValueDestructor(P,X) routine invokes destructor function X()
  * on value P is not going to be used and need to be destroyed.
@@ -270,16 +270,14 @@ setResultStrOrError(sql_context * pCtx,	/* Function context */
 		    void (*xDel) (void *)	/* Destructor function */
     )
 {
-	if (sqlVdbeMemSetStr(pCtx->pOut, z, n,1, xDel) == SQL_TOOBIG) {
-		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob too big");
+	if (sqlVdbeMemSetStr(pCtx->pOut, z, n, 1, xDel) != 0)
 		pCtx->is_aborted = true;
-	}
 }
 
 static int
 invokeValueDestructor(const void *p,	/* Value to destroy */
 		      void (*xDel) (void *),	/* The destructor */
-		      sql_context * pCtx	/* Set a SQL_TOOBIG error if no NULL */
+		      sql_context *pCtx	/* Set an error if no NULL */
     )
 {
 	assert(xDel != SQL_DYNAMIC);
@@ -291,10 +289,11 @@ invokeValueDestructor(const void *p,	/* Value to destroy */
 		xDel((void *)p);
 	}
 	if (pCtx) {
-		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob too big");
+		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob is too "\
+			 "big");
 		pCtx->is_aborted = true;
 	}
-	return SQL_TOOBIG;
+	return SQL_TARANTOOL_ERROR;
 }
 
 void
@@ -303,10 +302,8 @@ sql_result_blob(sql_context * pCtx,
     )
 {
 	assert(n >= 0);
-	if (sqlVdbeMemSetStr(pCtx->pOut, z, n,0, xDel) == SQL_TOOBIG) {
-		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob too big");
+	if (sqlVdbeMemSetStr(pCtx->pOut, z, n, 0, xDel) != 0)
 		pCtx->is_aborted = true;
-	}
 }
 
 void
@@ -391,7 +388,9 @@ sql_result_zeroblob64(sql_context * pCtx, u64 n)
 {
 	Mem *pOut = pCtx->pOut;
 	if (n > (u64) pOut->db->aLimit[SQL_LIMIT_LENGTH]) {
-		return SQL_TOOBIG;
+		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob is too "\
+			 "big");
+		return SQL_TARANTOOL_ERROR;
 	}
 	sqlVdbeMemSetZeroBlob(pCtx->pOut, (int)n);
 	return 0;
@@ -1124,7 +1123,9 @@ sql_bind_zeroblob64(sql_stmt * pStmt, int i, sql_uint64 n)
 	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
 	if (n > (u64) p->db->aLimit[SQL_LIMIT_LENGTH]) {
-		rc = SQL_TOOBIG;
+		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob is too "\
+			 "big");
+		rc = SQL_TARANTOOL_ERROR;
 	} else {
 		assert((n & 0x7FFFFFFF) == n);
 		rc = sql_bind_zeroblob(pStmt, i, n);
diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
index 3052bec..2a29b9e 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -949,7 +949,7 @@ sqlVdbeMemMove(Mem * pTo, Mem * pFrom)
  * size limit) then no memory allocation occurs.  If the string can be
  * stored without allocating memory, then it is.  If a memory allocation
  * is required to store the string, then value of pMem is unchanged.  In
- * either case, SQL_TOOBIG is returned.
+ * either case, error is returned.
  */
 int
 sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
@@ -993,7 +993,9 @@ sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
 			nAlloc += 1; //SQL_UTF8
 		}
 		if (nByte > iLimit) {
-			return SQL_TOOBIG;
+			diag_set(ClientError, ER_SQL_EXECUTE, "string or blob "\
+				 "is too big");
+			return SQL_TARANTOOL_ERROR;
 		}
 		testcase(nAlloc == 0);
 		testcase(nAlloc == 31);
@@ -1017,7 +1019,9 @@ sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
 	pMem->flags = flags;
 
 	if (nByte > iLimit) {
-		return SQL_TOOBIG;
+		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob is too "\
+			 "big");
+		return SQL_TARANTOOL_ERROR;
 	}
 
 	return 0;

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 18/28] sql: remove SQL_CONSTRAINT errcode
  2019-06-13 22:24   ` [tarantool-patches] " Vladislav Shpilevoy
@ 2019-06-15 10:00     ` Mergen Imeev
  2019-06-18 20:40       ` Vladislav Shpilevoy
  0 siblings, 1 reply; 56+ messages in thread
From: Mergen Imeev @ 2019-06-15 10:00 UTC (permalink / raw)
  To: Vladislav Shpilevoy; +Cc: tarantool-patches

On Fri, Jun 14, 2019 at 12:24:55AM +0200, Vladislav Shpilevoy wrote:
> Thanks for the patch!
> 
> I've found 'sql_CONSTRAINT_UNIQUE' in sql-tap/unique.test.lua
> on line 229. These tests are disabled by 'if 0 > 0', but another
> comment says, that the issue #2495 fix should have enabled them
> back. We need to either resurrect these tests, or drop them.
> 
> Consider my review fixes below and on the branch
> in a separate commit.
> 
Thank you! New patch:


m f7b4f7871f6d63e75b4951a2141b218a2d86c336 Mon Sep 17 00:00:00 2001
Date: Wed, 22 May 2019 17:42:11 +0300
Subject: [PATCH] sql: remove SQL_CONSTRAINT errcode

Removing this error code is part of getting rid of the SQL error
system.

diff --git a/src/box/sql/fk_constraint.c b/src/box/sql/fk_constraint.c
index 08e7f62..6cb41f8 100644
--- a/src/box/sql/fk_constraint.c
+++ b/src/box/sql/fk_constraint.c
@@ -44,7 +44,7 @@
  *
  * Foreign keys in sql come in two flavours: deferred and immediate.
  * If an immediate foreign key constraint is violated,
- * SQL_CONSTRAINT_FOREIGNKEY is returned and the current
+ * -1 is returned and the current
  * statement transaction rolled back. If a
  * deferred foreign key constraint is violated, no action is taken
  * immediately. However if the application attempts to commit the
@@ -110,7 +110,7 @@
  * is that the counter used is stored as part of each individual statement
  * object (struct Vdbe). If, after the statement has run, its immediate
  * constraint counter is greater than zero,
- * it returns SQL_CONSTRAINT_FOREIGNKEY
+ * it returns -1.
  * and the statement transaction is rolled back. An exception is an INSERT
  * statement that inserts a single row only (no triggers). In this case,
  * instead of using a counter, an exception is thrown immediately if the
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 4af65b0..f9f19bf 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -332,7 +332,6 @@ enum sql_ret_code {
 	/** Some kind of disk I/O error occurred. */
 	SQL_IOERR,
 	/** Abort due to constraint violation. */
-	SQL_CONSTRAINT,
 	SQL_TARANTOOL_ERROR,
 	/** sql_step() has another row ready. */
 	SQL_ROW,
@@ -554,9 +553,6 @@ sql_exec(sql *,	/* An open database */
 #define SQL_IOERR_CLOSE             (SQL_IOERR | (16<<8))
 #define SQL_IOERR_DELETE_NOENT      (SQL_IOERR | (23<<8))
 #define SQL_IOERR_GETTEMPPATH       (SQL_IOERR | (25<<8))
-#define SQL_CONSTRAINT_FOREIGNKEY   (SQL_CONSTRAINT | (3<<8))
-#define SQL_CONSTRAINT_NOTNULL      (SQL_CONSTRAINT | (5<<8))
-#define SQL_CONSTRAINT_TRIGGER      (SQL_CONSTRAINT | (7<<8))
 
 /**
  * Subtype of a main type. Allows to do some subtype specific
@@ -3520,17 +3516,16 @@ sql_generate_index_key(struct Parse *parse, struct index *index, int cursor,
  * ----------  ----------  --------------------------------------
  *    any       ROLLBACK   The current transaction is rolled
  *                         back and VDBE stops immediately
- *                         with return code of sql_CONSTRAINT.
+ *                         with an error.
  *
  *    any        ABORT     Back out changes from the current
  *                         command only (do not do a complete
  *                         rollback) then cause VDBE to return
- *                         immediately with sql_CONSTRAINT.
+ *                         immediately with an error.
  *
- *    any        FAIL      VDBE returns immediately with a
- *                         return code of sql_CONSTRAINT. The
- *                         transaction is not rolled back and any
- *                         changes to prior rows are retained.
+ *    any        FAIL      VDBE returns immediately with an error.
+ *                         The transaction is not rolled back and
+ *                         any changes to prior rows are retained.
  *
  *    any       IGNORE     The attempt in insert or update the
  *                         current row is skipped, without
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 918e73c..878724b 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -1065,7 +1065,6 @@ case OP_Halt: {
 	}
 	rc = sqlVdbeHalt(p);
 	assert(rc == 0 || rc == SQL_ERROR);
-	assert(rc == 0 || (p->rc & 0xff) == SQL_CONSTRAINT);
 	rc = p->rc ? SQL_TARANTOOL_ERROR : SQL_DONE;
 	goto vdbe_return;
 }
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 2a9e39b..53e9463 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -2013,8 +2013,7 @@ sqlVdbeCloseStatement(Vdbe * p, int eOp)
  * violations, return SQL_ERROR. Otherwise, 0.
  *
  * If there are outstanding FK violations and this function returns
- * SQL_ERROR, set the result of the VM to SQL_CONSTRAINT_FOREIGNKEY
- * and write an error message to it. Then return SQL_ERROR.
+ * SQL_TARANTOOL_ERROR and set an error.
  */
 int
 sqlVdbeCheckFk(Vdbe * p, int deferred)
@@ -2177,7 +2176,6 @@ sqlVdbeHalt(Vdbe * p)
 						closeCursorsAndFree(p);
 						return SQL_ERROR;
 					}
-					rc = SQL_CONSTRAINT_FOREIGNKEY;
 				} else {
 					/* The auto-commit flag is true, the vdbe program was successful
 					 * or hit an 'OR FAIL' constraint and there are no deferred foreign
@@ -2220,17 +2218,15 @@ sqlVdbeHalt(Vdbe * p)
 		/* If eStatementOp is non-zero, then a statement transaction needs to
 		 * be committed or rolled back. Call sqlVdbeCloseStatement() to
 		 * do so. If this operation returns an error, and the current statement
-		 * error code is 0 or SQL_CONSTRAINT, then promote the
+		 * error code is 0 or -1, then promote the
 		 * current statement error code.
 		 */
 		if (eStatementOp) {
 			rc = sqlVdbeCloseStatement(p, eStatementOp);
 			if (rc) {
 				box_txn_rollback();
-				if (p->rc == 0
-				    || (p->rc & 0xff) == SQL_CONSTRAINT) {
+				if (p->rc == 0)
 					p->rc = rc;
-				}
 				closeCursorsAndFree(p);
 				sqlRollbackAll(p);
 				sqlCloseSavepoints(p);
diff --git a/test/sql-tap/trigger1.test.lua b/test/sql-tap/trigger1.test.lua
index 38d7c55..bc02d62 100755
--- a/test/sql-tap/trigger1.test.lua
+++ b/test/sql-tap/trigger1.test.lua
@@ -511,7 +511,7 @@ test:do_catchsql_test(
         -- </trigger1-6.3>
     })
 
--- verify_ex_errcode trigger1-6.3b sql_CONSTRAINT_TRIGGER
+-- Verify the previous test has not deleted anything.
 test:do_execsql_test(
     "trigger1-6.4",
     [[
diff --git a/test/sql-tap/unique.test.lua b/test/sql-tap/unique.test.lua
index fbd73a6..358a06f 100755
--- a/test/sql-tap/unique.test.lua
+++ b/test/sql-tap/unique.test.lua
@@ -74,7 +74,7 @@ test:do_catchsql_test(
         -- </unique-1.3>
     })
 
--- verify_ex_errcode unique-1.3b sql_CONSTRAINT_PRIMARYKEY
+-- Verify the previous test has not inserted anything.
 test:do_execsql_test(
     "unique-1.4",
     [[
@@ -95,7 +95,7 @@ test:do_catchsql_test(
         -- </unique-1.5>
     })
 
--- verify_ex_errcode unique-1.5b sql_CONSTRAINT_UNIQUE
+-- Verify the previous test has not inserted anything.
 test:do_execsql_test(
     "unique-1.6",
     [[
@@ -171,7 +171,7 @@ test:do_catchsql_test(
         -- </unique-2.3>
     })
 
--- verify_ex_errcode unique-2.3b sql_CONSTRAINT_UNIQUE
+-- Verify the previous test has not inserted anything.
 test:do_catchsql_test(
     "unique-2.4",
     [[
@@ -291,7 +291,6 @@ test:do_catchsql_test(
         -- </unique-3.4>
     })
 
--- verify_ex_errcode unique-3.4b sql_CONSTRAINT_UNIQUE
 --integrity_check unique-3.5
 -- Make sure NULLs are distinct as far as the UNIQUE tests are
 -- concerned.
@@ -405,7 +404,6 @@ test:do_catchsql_test(
     })
 end
 
--- verify_ex_errcode unique-4.10b sql_CONSTRAINT_UNIQUE
 --integrity_check unique-4.99
 -- Test the error message generation logic.  In particular, make sure we
 -- do not overflow the static buffer used to generate the error message.
@@ -448,7 +446,4 @@ test:do_catchsql_test(
         -- </unique-5.2>
     })
 
--- verify_ex_errcode unique-5.2b sql_CONSTRAINT_UNIQUE
-
-
 test:finish_test()

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 20/28] sql: remove SQL_NOMEM errcode
  2019-06-13 22:24   ` [tarantool-patches] " Vladislav Shpilevoy
@ 2019-06-15 10:01     ` Mergen Imeev
  0 siblings, 0 replies; 56+ messages in thread
From: Mergen Imeev @ 2019-06-15 10:01 UTC (permalink / raw)
  To: Vladislav Shpilevoy; +Cc: tarantool-patches

On Fri, Jun 14, 2019 at 12:24:49AM +0200, Vladislav Shpilevoy wrote:
> Thanks for the patch!
> 
> Consider my review fixes below and on the branch
> in a separate commit.
> 
Thank you! New patch:

From ba2dd4105b288a6ede3c947a1ee6f425ad41e19c Mon Sep 17 00:00:00 2001
Date: Fri, 24 May 2019 17:20:30 +0300
Subject: [PATCH] sql: remove SQL_NOMEM errcode

Removing this error code is part of getting rid of the SQL error
system.

diff --git a/src/box/sql/fault.c b/src/box/sql/fault.c
index 26eeaee..62e9924 100644
--- a/src/box/sql/fault.c
+++ b/src/box/sql/fault.c
@@ -37,8 +37,8 @@
  * and returns 0).
  *
  * Most malloc failures are non-benign. After they occur, sql
- * abandons the current operation and returns an error code (usually
- * SQL_NOMEM) to the user. However, sometimes a fault is not necessarily
+ * abandons the current operation and returns an error
+ * to the user. However, sometimes a fault is not necessarily
  * fatal. For example, if a malloc fails while resizing a hash table, this
  * is completely recoverable simply by not carrying out the resize. The
  * hash table will continue to function normally.  So a malloc failure
diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 7b3c20e..761a3ab 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -1772,14 +1772,11 @@ static inline int
 sql_overload_function(sql * db, const char *zName,
 			  enum field_type type, int nArg)
 {
-	int rc = 0;
-
 	if (sqlFindFunction(db, zName, nArg, 0) == 0) {
-		rc = sqlCreateFunc(db, zName, type, nArg, 0, 0,
-				       sqlInvalidFunction, 0, 0, 0);
+		return sqlCreateFunc(db, zName, type, nArg, 0, 0,
+				     sqlInvalidFunction, 0, 0, 0);
 	}
-	rc = sqlApiExit(db, rc);
-	return rc;
+	return 0;
 }
 
 /*
@@ -1790,11 +1787,8 @@ sql_overload_function(sql * db, const char *zName,
 void
 sqlRegisterPerConnectionBuiltinFunctions(sql * db)
 {
-	int rc = sql_overload_function(db, "MATCH", FIELD_TYPE_SCALAR, 2);
-	assert(rc == SQL_NOMEM || rc == 0);
-	if (rc == SQL_NOMEM) {
+	if (sql_overload_function(db, "MATCH", FIELD_TYPE_SCALAR, 2) != 0)
 		sqlOomFault(db);
-	}
 }
 
 /*
diff --git a/src/box/sql/legacy.c b/src/box/sql/legacy.c
index 2947abe..7335266 100644
--- a/src/box/sql/legacy.c
+++ b/src/box/sql/legacy.c
@@ -161,7 +161,6 @@ sql_exec(sql * db,	/* The database on which the SQL executes */
 		sqlVdbeFinalize((Vdbe *) pStmt);
 	sqlDbFree(db, azCols);
 
-	rc = sqlApiExit(db, rc);
 	assert(rc == 0);
 	assert((rc & db->errMask) == rc);
 	return rc;
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index d4129a5..495a87e 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -442,16 +442,16 @@ int
 sql_init_db(sql **out_db)
 {
 	sql *db;
-	int rc;			/* Return code */
 
-	rc = sql_initialize();
-	if (rc)
-		return rc;
+	if (sql_initialize() != 0)
+		return -1;
 
 	/* Allocate the sql data structure */
 	db = sqlMallocZero(sizeof(sql));
-	if (db == 0)
-		goto opendb_out;
+	if (db == NULL) {
+		*out_db = NULL;
+		return -1;
+	}
 	db->errMask = 0xff;
 	db->magic = SQL_MAGIC_BUSY;
 
@@ -465,7 +465,9 @@ sql_init_db(sql **out_db)
 
 	db->magic = SQL_MAGIC_OPEN;
 	if (db->mallocFailed) {
-		goto opendb_out;
+		sql_free(db);
+		*out_db = NULL;
+		return -1;
 	}
 
 	/* Register all built-in functions, but do not attempt to read the
@@ -474,16 +476,8 @@ sql_init_db(sql **out_db)
 	 */
 	sqlRegisterPerConnectionBuiltinFunctions(db);
 
-opendb_out:
-	assert(db != 0 || rc == SQL_NOMEM);
-	if (rc == SQL_NOMEM)
-		db = NULL;
-	else if (rc != 0)
-		db->magic = SQL_MAGIC_SICK;
-
 	*out_db = db;
-
-	return rc;
+	return 0;
 }
 
 /*
diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index 4e10380..c97d371 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -607,7 +607,7 @@ static SQL_NOINLINE int
 apiOomError(sql * db)
 {
 	sqlOomClear(db);
-	return SQL_NOMEM;
+	return -1;
 }
 
 /*
@@ -616,10 +616,7 @@ apiOomError(sql * db)
  * sql_realloc.
  *
  * The returned value is normally a copy of the second argument to this
- * function. However, if a malloc() failure has occurred since the previous
- * invocation SQL_NOMEM is returned instead.
- *
- * If an OOM as occurred, SQL_NOMEM is returned.
+ * function.
  */
 int
 sqlApiExit(sql * db, int rc)
diff --git a/src/box/sql/os.c b/src/box/sql/os.c
index 10b68c8..b7d6b2a 100644
--- a/src/box/sql/os.c
+++ b/src/box/sql/os.c
@@ -164,7 +164,7 @@ sqlOsOpenMalloc(sql_vfs * pVfs,
 			*ppFile = pFile;
 		}
 	} else {
-		rc = SQL_NOMEM;
+		rc = -1;
 	}
 	return rc;
 }
diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index 4bf1463..5170dd2 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -409,7 +409,7 @@ findInodeInfo(unixFile * pFile,	/* Unix file with file desc used in the key */
 	if (pInode == 0) {
 		pInode = sql_malloc64(sizeof(*pInode));
 		if (pInode == 0) {
-			return SQL_NOMEM;
+			return -1;
 		}
 		memset(pInode, 0, sizeof(*pInode));
 		memcpy(&pInode->fileId, &fileId, sizeof(fileId));
@@ -1697,7 +1697,7 @@ unixOpen(sql_vfs * pVfs,	/* The VFS for which this is the xOpen method */
 		} else {
 			pUnused = sql_malloc64(sizeof(*pUnused));
 			if (!pUnused) {
-				return SQL_NOMEM;
+				return -1;
 			}
 		}
 		p->pUnused = pUnused;
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index 236b077..736c6ab 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -1813,7 +1813,7 @@ generateColumnNames(Parse * pParse,	/* Parser context */
  * and other fields of Column are zeroed.
  *
  * Return 0 on success.  If a memory allocation error occurs,
- * store NULL in *paCol and 0 in *pnCol and return SQL_NOMEM.
+ * store NULL in *paCol and 0 in *pnCol and return -1.
  */
 int
 sqlColumnsFromExprList(Parse * parse, ExprList * expr_list,
@@ -1916,17 +1916,16 @@ sqlColumnsFromExprList(Parse * parse, ExprList * expr_list,
 	}
 cleanup:
 	sqlHashClear(&ht);
-	int rc = db->mallocFailed ? SQL_NOMEM : 0;
-	if (rc != 0) {
+	if (db->mallocFailed) {
 		/*
 		 * pTable->def could be not temporal in
 		 * sqlViewGetColumnNames so we need clean-up.
 		 */
 		space_def->fields = NULL;
 		space_def->field_count = 0;
-		rc = SQL_NOMEM;
+		return -1;
 	}
-	return rc;
+	return 0;
 
 }
 
@@ -4614,7 +4613,7 @@ withExpand(Walker * pWalker, struct SrcList_item *pFrom)
 			return WRC_Abort;
 		pFrom->pSelect = sqlSelectDup(db, pCte->pSelect, 0);
 		if (db->mallocFailed)
-			return SQL_NOMEM;
+			return -1;
 		assert(pFrom->pSelect);
 
 		/* Check if this is a recursive CTE. */
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 5b93b7d..b7b85cf 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -325,10 +325,8 @@ struct sql_vfs {
 #define SQL_LIMIT_TRIGGER_DEPTH             9
 
 enum sql_ret_code {
-	/** A malloc() failed. */
-	SQL_NOMEM = 2,
 	/** Some kind of disk I/O error occurred. */
-	SQL_IOERR,
+	SQL_IOERR = 3,
 	/** Abort due to constraint violation. */
 	SQL_TARANTOOL_ERROR,
 	/** sql_step() has another row ready. */
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 9dc2659..c617540 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -703,7 +703,7 @@ vdbe_field_ref_fetch(struct vdbe_field_ref *field_ref, uint32_t fieldno,
 		int len = dest_mem->n;
 		if (dest_mem->szMalloc < len + 1) {
 			if (sqlVdbeMemGrow(dest_mem, len + 1, 1) != 0)
-				return SQL_NOMEM;
+				return SQL_TARANTOOL_ERROR;
 		} else {
 			dest_mem->z =
 				memcpy(dest_mem->zMalloc, dest_mem->z, len);
@@ -746,12 +746,6 @@ int sqlVdbeExec(Vdbe *p)
 	/*** INSERT STACK UNION HERE ***/
 
 	assert(p->magic==VDBE_MAGIC_RUN);  /* sql_step() verifies this */
-	if (p->rc==SQL_NOMEM) {
-		/* This happens if a malloc() inside a call to sql_column_text() or
-		 * sql_column_text16() failed.
-		 */
-		goto no_mem;
-	}
 	assert(p->rc == 0);
 	p->rc = 0;
 	p->iCurrentTime = 0;
@@ -2618,8 +2612,7 @@ case OP_Column: {
 	}
 	struct Mem *default_val_mem =
 		pOp->p4type == P4_MEM ? pOp->p4.pMem : NULL;
-	rc = vdbe_field_ref_fetch(&pC->field_ref, p2, pDest);
-	if (rc != 0)
+	if (vdbe_field_ref_fetch(&pC->field_ref, p2, pDest) != 0)
 		goto abort_due_to_error;
 
 	if ((pDest->flags & MEM_Null) &&
@@ -2652,8 +2645,7 @@ case OP_Fetch: {
 	uint32_t field_idx = pOp->p2;
 	struct Mem *dest_mem = &aMem[pOp->p3];
 	memAboutToChange(p, dest_mem);
-	rc = vdbe_field_ref_fetch(field_ref, field_idx, dest_mem);
-	if (rc != 0)
+	if (vdbe_field_ref_fetch(field_ref, field_idx, dest_mem) != 0)
 		goto abort_due_to_error;
 	REGISTER_TRACE(p, pOp->p3, dest_mem);
 	break;
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index a0465e6..69036ee 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -418,8 +418,8 @@ sqlStep(Vdbe * p)
 	/* Check that malloc() has not failed. If it has, return early. */
 	db = p->db;
 	if (db->mallocFailed) {
-		p->rc = SQL_NOMEM;
-		return SQL_NOMEM;
+		p->rc = -1;
+		return -1;
 	}
 
 	if (p->pc <= 0 && p->expired) {
@@ -450,9 +450,6 @@ sqlStep(Vdbe * p)
 	if (rc != SQL_ROW)
 		checkProfileCallback(db, p);
 
-	if (SQL_NOMEM == sqlApiExit(p->db, p->rc)) {
-		p->rc = SQL_NOMEM;
-	}
 	if (p->isPrepareV2 && rc != SQL_ROW && rc != SQL_DONE) {
 		/* If this statement was prepared using sql_prepare_v2(), and an
 		 * error has occurred, then return the error code in p->rc to the
@@ -678,38 +675,6 @@ columnMem(sql_stmt * pStmt, int i)
 	return pOut;
 }
 
-/*
- * This function is called after invoking an sql_value_XXX function on a
- * column value (i.e. a value returned by evaluating an SQL expression in the
- * select list of a SELECT statement) that may cause a malloc() failure. If
- * malloc() has failed, the threads mallocFailed flag is cleared and the result
- * code of statement pStmt set to SQL_NOMEM.
- *
- * Specifically, this is called from within:
- *
- *     sql_column_int()
- *     sql_column_int64()
- *     sql_column_text()
- *     sql_column_real()
- *     sql_column_bytes()
- *     sql_column_bytes16()
- *     sqiite3_column_blob()
- */
-static void
-columnMallocFailure(sql_stmt * pStmt)
-{
-	/* If malloc() failed during an encoding conversion within an
-	 * sql_column_XXX API, then set the return code of the statement to
-	 * SQL_NOMEM. The next call to _step() (if any) will return -1
-	 * and _finalize() will return NOMEM.
-	 */
-	Vdbe *p = (Vdbe *) pStmt;
-	if (p) {
-		assert(p->db != 0);
-		p->rc = sqlApiExit(p->db, p->rc);
-	}
-}
-
 /**************************** sql_column_  ******************************
  * The following routines are used to access elements of the current row
  * in the result set.
@@ -719,60 +684,43 @@ sql_column_blob(sql_stmt * pStmt, int i)
 {
 	const void *val;
 	val = sql_value_blob(columnMem(pStmt, i));
-	/* Even though there is no encoding conversion, value_blob() might
-	 * need to call malloc() to expand the result of a zeroblob()
-	 * expression.
-	 */
-	columnMallocFailure(pStmt);
 	return val;
 }
 
 int
 sql_column_bytes(sql_stmt * pStmt, int i)
 {
-	int val = sql_value_bytes(columnMem(pStmt, i));
-	columnMallocFailure(pStmt);
-	return val;
+	return sql_value_bytes(columnMem(pStmt, i));
 }
 
 double
 sql_column_double(sql_stmt * pStmt, int i)
 {
-	double val = sql_value_double(columnMem(pStmt, i));
-	columnMallocFailure(pStmt);
-	return val;
+	return sql_value_double(columnMem(pStmt, i));
 }
 
 int
 sql_column_int(sql_stmt * pStmt, int i)
 {
-	int val = sql_value_int(columnMem(pStmt, i));
-	columnMallocFailure(pStmt);
-	return val;
+	return sql_value_int(columnMem(pStmt, i));
 }
 
 bool
 sql_column_boolean(struct sql_stmt *stmt, int i)
 {
-	bool val = sql_value_boolean(columnMem(stmt, i));
-	columnMallocFailure(stmt);
-	return val;
+	return sql_value_boolean(columnMem(stmt, i));
 }
 
 sql_int64
 sql_column_int64(sql_stmt * pStmt, int i)
 {
-	sql_int64 val = sql_value_int64(columnMem(pStmt, i));
-	columnMallocFailure(pStmt);
-	return val;
+	return sql_value_int64(columnMem(pStmt, i));
 }
 
 const unsigned char *
 sql_column_text(sql_stmt * pStmt, int i)
 {
-	const unsigned char *val = sql_value_text(columnMem(pStmt, i));
-	columnMallocFailure(pStmt);
-	return val;
+	return sql_value_text(columnMem(pStmt, i));
 }
 
 sql_value *
@@ -783,16 +731,13 @@ sql_column_value(sql_stmt * pStmt, int i)
 		pOut->flags &= ~MEM_Static;
 		pOut->flags |= MEM_Ephem;
 	}
-	columnMallocFailure(pStmt);
 	return (sql_value *) pOut;
 }
 
 enum mp_type
 sql_column_type(sql_stmt * pStmt, int i)
 {
-	enum mp_type type = sql_value_type(columnMem(pStmt, i));
-	columnMallocFailure(pStmt);
-	return type;
+	return sql_value_type(columnMem(pStmt, i));
 }
 
 enum sql_subtype
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index e4ddeda..a592f2e 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -159,7 +159,7 @@ sqlVdbeSwap(Vdbe * pA, Vdbe * pB)
  * to 1024/sizeof(Op).
  *
  * If an out-of-memory error occurs while resizing the array, return
- * SQL_NOMEM. In this case Vdbe.aOp and Parse.nOpAlloc remain
+ * -1. In this case Vdbe.aOp and Parse.nOpAlloc remain
  * unchanged (this is so that any opcodes already allocated can be
  * correctly deallocated along with the rest of the Vdbe).
  */
@@ -193,7 +193,7 @@ growOpArray(Vdbe * v, int nOp)
 		v->aOp = pNew;
 		return 0;
 	}
-	return SQL_NOMEM;
+	return -1;
 }
 
 #ifdef SQL_DEBUG
@@ -1383,14 +1383,12 @@ sqlVdbeList(Vdbe * p)
 	int nSub = 0;		/* Number of sub-vdbes seen so far */
 	SubProgram **apSub = 0;	/* Array of sub-vdbes */
 	Mem *pSub = 0;		/* Memory cell hold array of subprogs */
-	sql *db = p->db;	/* The database connection */
 	int i;			/* Loop counter */
 	int rc = 0;	/* Return code */
 	Mem *pMem = &p->aMem[1];	/* First Mem of result set */
 
 	assert(p->explain);
 	assert(p->magic == VDBE_MAGIC_RUN);
-	assert(p->rc == 0 || p->rc == SQL_NOMEM);
 
 	/* Even though this opcode does not use dynamic strings for
 	 * the result, result columns may become dynamic if the user calls
@@ -1399,14 +1397,6 @@ sqlVdbeList(Vdbe * p)
 	releaseMemArray(pMem, 8);
 	p->pResultSet = 0;
 
-	if (p->rc == SQL_NOMEM) {
-		/* This happens if a malloc() inside a call to sql_column_text() or
-		 * sql_column_text16() failed.
-		 */
-		sqlOomFault(db);
-		return -1;
-	}
-
 	/* When the number of output rows reaches nRow, that means the
 	 * listing has finished and sql_step() should return SQL_DONE.
 	 * nRow is the sum of the number of rows in the main program, plus
@@ -1944,7 +1934,7 @@ sqlVdbeSetColName(Vdbe * p,			/* Vdbe being configured */
 	assert(var < COLNAME_N);
 	if (p->db->mallocFailed) {
 		assert(!zName || xDel != SQL_DYNAMIC);
-		return SQL_NOMEM;
+		return -1;
 	}
 	assert(p->aColName != 0);
 	assert(var == COLNAME_NAME || var == COLNAME_DECLTYPE);
@@ -2098,7 +2088,6 @@ sqlVdbeHalt(Vdbe * p)
 	 *
 	 * If any of the following errors occur:
 	 *
-	 *     SQL_NOMEM
 	 *     SQL_IOERR
 	 *
 	 * Then the internal cache might have been left in an inconsistent
@@ -2107,7 +2096,7 @@ sqlVdbeHalt(Vdbe * p)
 	 */
 
 	if (db->mallocFailed) {
-		p->rc = SQL_NOMEM;
+		p->rc = -1;
 	}
 	closeTopFrameCursors(p);
 	if (p->magic != VDBE_MAGIC_RUN) {
@@ -2125,7 +2114,7 @@ sqlVdbeHalt(Vdbe * p)
 
 		/* Check for one of the special errors */
 		mrc = p->rc & 0xff;
-		isSpecialError = mrc == SQL_NOMEM || mrc == SQL_IOERR;
+		isSpecialError = mrc == SQL_IOERR;
 		if (isSpecialError) {
 			/* At least a savepoint transaction must be rolled back
 			 * to restore the database to a consistent state.
@@ -2136,20 +2125,14 @@ sqlVdbeHalt(Vdbe * p)
 			 * file as part of an effort to free up cache space (see function
 			 * pagerStress() in pager.c), the rollback is required to restore
 			 * the pager to a consistent state.
+			 * We are forced to roll back the active transaction. Before doing
+			 * so, abort any other statements this handle currently has active.
 			 */
-			if ((mrc == SQL_NOMEM)
-			    && box_txn()) {
-				eStatementOp = SAVEPOINT_ROLLBACK;
-			} else {
-				/* We are forced to roll back the active transaction. Before doing
-				 * so, abort any other statements this handle currently has active.
-				 */
-				box_txn_rollback();
-				closeCursorsAndFree(p);
-				sqlRollbackAll(p);
-				sqlCloseSavepoints(p);
-				p->nChange = 0;
-			}
+			box_txn_rollback();
+			closeCursorsAndFree(p);
+			sqlRollbackAll(p);
+			sqlCloseSavepoints(p);
+			p->nChange = 0;
 		}
 
 		/* Check for immediate foreign key violations. */
@@ -2257,7 +2240,7 @@ sqlVdbeHalt(Vdbe * p)
 	p->magic = VDBE_MAGIC_HALT;
 	checkActiveVdbeCnt(db);
 	if (db->mallocFailed) {
-		p->rc = SQL_NOMEM;
+		p->rc = -1;
 	}
 
 	assert(db->nVdbeActive > 0 || box_txn() ||
@@ -2889,7 +2872,7 @@ sql_vdbe_mem_alloc_region(Mem *vdbe_mem, uint32_t size)
 	vdbe_mem->n = size;
 	vdbe_mem->z = region_alloc(&fiber()->gc, size);
 	if (vdbe_mem->z == NULL)
-		return SQL_NOMEM;
+		return -1;
 	vdbe_mem->flags = MEM_Ephem | MEM_Blob;
 	assert(sqlVdbeCheckMemInvariants(vdbe_mem));
 	return 0;
@@ -2906,7 +2889,7 @@ sql_vdbe_mem_alloc_region(Mem *vdbe_mem, uint32_t size)
 static int
 vdbeCompareMemString(const Mem * pMem1, const Mem * pMem2,
 		     const struct coll * pColl,
-		     u8 * prcErr)	/* If an OOM occurs, set to SQL_NOMEM */
+		     u8 * prcErr)
 {
 	(void) prcErr;
 	return pColl->cmp(pMem1->z, (size_t)pMem1->n,
diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
index 0586b11..3275c49 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -129,7 +129,7 @@ sqlVdbeMemGrow(Mem * pMem, int n, int bPreserve)
 			sqlVdbeMemSetNull(pMem);
 			pMem->z = 0;
 			pMem->szMalloc = 0;
-			return SQL_NOMEM;
+			return -1;
 		} else {
 			pMem->szMalloc = sqlMallocSize(pMem->zMalloc);
 		}
@@ -158,8 +158,7 @@ sqlVdbeMemGrow(Mem * pMem, int n, int bPreserve)
  * and MEM_Blob values may be discarded, MEM_Int, MEM_Real, and MEM_Null
  * values are preserved.
  *
- * Return 0 on success or an error code (probably SQL_NOMEM)
- * if unable to complete the resizing.
+ * Return 0 on success or -1 if unable to complete the resizing.
  */
 int
 sqlVdbeMemClearAndResize(Mem * pMem, int szNew)
@@ -179,17 +178,17 @@ sqlVdbeMemClearAndResize(Mem * pMem, int szNew)
  * Change pMem so that its MEM_Str or MEM_Blob value is stored in
  * MEM.zMalloc, where it can be safely written.
  *
- * Return 0 on success or SQL_NOMEM if malloc fails.
+ * Return 0 on success or -1 if malloc fails.
  */
 int
 sqlVdbeMemMakeWriteable(Mem * pMem)
 {
 	if ((pMem->flags & (MEM_Str | MEM_Blob)) != 0) {
 		if (ExpandBlob(pMem))
-			return SQL_NOMEM;
+			return -1;
 		if (pMem->szMalloc == 0 || pMem->z != pMem->zMalloc) {
 			if (sqlVdbeMemGrow(pMem, pMem->n + 2, 1)) {
-				return SQL_NOMEM;
+				return -1;
 			}
 			pMem->z[pMem->n] = 0;
 			pMem->z[pMem->n + 1] = 0;
@@ -221,7 +220,7 @@ sqlVdbeMemExpandBlob(Mem * pMem)
 		nByte = 1;
 	}
 	if (sqlVdbeMemGrow(pMem, nByte, 1)) {
-		return SQL_NOMEM;
+		return -1;
 	}
 
 	memset(&pMem->z[pMem->n], 0, pMem->u.nZero);
@@ -238,7 +237,7 @@ static SQL_NOINLINE int
 vdbeMemAddTerminator(Mem * pMem)
 {
 	if (sqlVdbeMemGrow(pMem, pMem->n + 2, 1)) {
-		return SQL_NOMEM;
+		return -1;
 	}
 	pMem->z[pMem->n] = 0;
 	pMem->z[pMem->n + 1] = 0;
@@ -289,7 +288,7 @@ sqlVdbeMemStringify(Mem * pMem, u8 bForce)
 	assert(EIGHT_BYTE_ALIGNMENT(pMem));
 
 	if (sqlVdbeMemClearAndResize(pMem, nByte)) {
-		return SQL_NOMEM;
+		return -1;
 	}
 	if (fg & MEM_Int) {
 		sql_snprintf(nByte, pMem->z, "%lld", pMem->u.i);
@@ -1001,7 +1000,7 @@ sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
 		testcase(nAlloc == 31);
 		testcase(nAlloc == 32);
 		if (sqlVdbeMemClearAndResize(pMem, MAX(nAlloc, 32))) {
-			return SQL_NOMEM;
+			return -1;
 		}
 		memcpy(pMem->z, z, nAlloc);
 	} else if (xDel == SQL_DYNAMIC) {
@@ -1268,7 +1267,7 @@ valueFromFunction(sql * db,	/* The database connection */
 							   sizeof(apVal[0]) *
 							   nVal);
 		if (apVal == 0) {
-			rc = SQL_NOMEM;
+			rc = -1;
 			goto value_from_function_out;
 		}
 		for (i = 0; i < nVal; i++) {
@@ -1281,7 +1280,7 @@ valueFromFunction(sql * db,	/* The database connection */
 
 	pVal = valueNew(db, pCtx);
 	if (pVal == 0) {
-		rc = SQL_NOMEM;
+		rc = -1;
 		goto value_from_function_out;
 	}
 
@@ -1444,7 +1443,7 @@ valueFromExpr(sql * db,	/* The database connection */
 	if (pCtx == 0)
 		sqlValueFree(pVal);
 
-	return SQL_NOMEM;
+	return -1;
 }
 
 /*
diff --git a/src/box/sql/vdbesort.c b/src/box/sql/vdbesort.c
index 230bb0c..e87c885 100644
--- a/src/box/sql/vdbesort.c
+++ b/src/box/sql/vdbesort.c
@@ -534,7 +534,7 @@ vdbePmaReadBlob(PmaReader * p,	/* PmaReader from which to take the blob */
 				nNew = nNew * 2;
 			aNew = sqlRealloc(p->aAlloc, nNew);
 			if (!aNew)
-				return SQL_NOMEM;
+				return -1;
 			p->nAlloc = nNew;
 			p->aAlloc = aNew;
 		}
@@ -658,7 +658,7 @@ vdbePmaReaderSeek(SortSubtask * pTask,	/* Task context */
 		if (pReadr->aBuffer == 0) {
 			pReadr->aBuffer = (u8 *) sqlMalloc(pgsz);
 			if (pReadr->aBuffer == 0)
-				rc = SQL_NOMEM;
+				rc = -1;
 			pReadr->nBuffer = pgsz;
 		}
 		if (rc == 0 && iBuf != 0) {
@@ -765,7 +765,7 @@ vdbePmaReaderInit(SortSubtask * pTask,	/* Task context */
  * version of key2 and *pbKey2Cached set to true before returning.
  *
  * If an OOM error is encountered, (pTask->pUnpacked->error_rc) is set
- * to SQL_NOMEM.
+ * to -1.
  *
  * @param task Subtask context (for key_def).
  * @param key2_cached True if pTask->pUnpacked is key2.
@@ -821,7 +821,7 @@ sqlVdbeSorterInit(sql * db,	/* Database connection (for malloc()) */
 	pSorter = (VdbeSorter *) sqlDbMallocZero(db, sizeof(VdbeSorter));
 	pCsr->uc.pSorter = pSorter;
 	if (pSorter == 0) {
-		rc = SQL_NOMEM;
+		rc = -1;
 	} else {
 		pSorter->key_def = pCsr->key_def;
 		pSorter->pgsz = pgsz = 1024;
@@ -848,7 +848,7 @@ sqlVdbeSorterInit(sql * db,	/* Database connection (for malloc()) */
 			pSorter->list.aMemory =
 			    (u8 *) sqlMalloc(pgsz);
 			if (!pSorter->list.aMemory)
-				rc = SQL_NOMEM;
+				rc = -1;
 		}
 
 		if (pCsr->key_def->part_count < 13
@@ -1053,7 +1053,7 @@ vdbeSorterOpenTempFile(sql * db,	/* Database handle doing sort */
 /*
  * If it has not already been allocated, allocate the UnpackedRecord
  * structure at pTask->pUnpacked. Return 0 if successful (or
- * if no allocation was required), or SQL_NOMEM otherwise.
+ * if no allocation was required), or -1 otherwise.
  */
 static int
 vdbeSortAllocUnpacked(SortSubtask * pTask)
@@ -1063,7 +1063,7 @@ vdbeSortAllocUnpacked(SortSubtask * pTask)
 			sqlVdbeAllocUnpackedRecord(pTask->pSorter->db,
 						       pTask->pSorter->key_def);
 		if (pTask->pUnpacked == 0)
-			return SQL_NOMEM;
+			return -1;
 		pTask->pUnpacked->nField = pTask->pSorter->key_def->part_count;
 		pTask->pUnpacked->errCode = 0;
 	}
@@ -1125,7 +1125,7 @@ vdbeSorterGetCompare(VdbeSorter * p)
 
 /*
  * Sort the linked list of records headed at pTask->pList. Return
- * 0 if successful, or an sql error code (i.e. SQL_NOMEM) if
+ * 0 if successful, or an sql error code (i.e. -1) if
  * an error occurs.
  */
 static int
@@ -1146,7 +1146,7 @@ vdbeSorterSort(SortSubtask * pTask, SorterList * pList)
 	aSlot =
 	    (SorterRecord **) sqlMallocZero(64 * sizeof(SorterRecord *));
 	if (!aSlot) {
-		return SQL_NOMEM;
+		return -1;
 	}
 
 	while (p) {
@@ -1183,8 +1183,6 @@ vdbeSorterSort(SortSubtask * pTask, SorterList * pList)
 	pList->pList = p;
 
 	sql_free(aSlot);
-	assert(pTask->pUnpacked->errCode == 0
-	       || pTask->pUnpacked->errCode == SQL_NOMEM);
 	return pTask->pUnpacked->errCode;
 }
 
@@ -1201,7 +1199,7 @@ vdbePmaWriterInit(sql_file * pFd,	/* File handle to write to */
 	memset(p, 0, sizeof(PmaWriter));
 	p->aBuffer = (u8 *) sqlMalloc(nBuf);
 	if (!p->aBuffer) {
-		p->eFWErr = SQL_NOMEM;
+		p->eFWErr = -1;
 	} else {
 		p->iBufEnd = p->iBufStart = (iStart % nBuf);
 		p->iWriteOff = iStart - p->iBufStart;
@@ -1535,7 +1533,7 @@ sqlVdbeSorterWrite(const VdbeCursor * pCsr,	/* Sorter cursor */
 
 			aNew = sqlRealloc(pSorter->list.aMemory, nNew);
 			if (!aNew)
-				return SQL_NOMEM;
+				return -1;
 			pSorter->list.pList = (SorterRecord *) & aNew[iListOff];
 			pSorter->list.aMemory = aNew;
 			pSorter->nMemory = nNew;
@@ -1552,7 +1550,7 @@ sqlVdbeSorterWrite(const VdbeCursor * pCsr,	/* Sorter cursor */
 	} else {
 		pNew = (SorterRecord *) sqlMalloc(nReq);
 		if (pNew == 0) {
-			return SQL_NOMEM;
+			return -1;
 		}
 		pNew->u.pNext = pSorter->list.pList;
 	}
@@ -1663,7 +1661,7 @@ vdbeIncrMergerNew(SortSubtask * pTask,	/* The thread that will be using the new
 		pTask->file2.iEof += pIncr->mxSz;
 	} else {
 		vdbeMergeEngineFree(pMerger);
-		rc = SQL_NOMEM;
+		rc = -1;
 	}
 	return rc;
 }
@@ -1860,7 +1858,7 @@ vdbeMergeEngineLevel0(SortSubtask * pTask,	/* Sorter task to read from */
 
 	*ppOut = pNew = vdbeMergeEngineNew(nPMA);
 	if (pNew == 0)
-		rc = SQL_NOMEM;
+		rc = -1;
 
 	for (i = 0; i < nPMA && rc == 0; i++) {
 		i64 nDummy = 0;
@@ -1936,7 +1934,7 @@ vdbeSorterAddToTree(SortSubtask * pTask,	/* Task context */
 			MergeEngine *pNew =
 			    vdbeMergeEngineNew(SORTER_MAX_MERGE_COUNT);
 			if (pNew == 0) {
-				rc = SQL_NOMEM;
+				rc = -1;
 			} else {
 				rc = vdbeIncrMergerNew(pTask, pNew,
 						       &pReadr->pIncr);
@@ -1991,7 +1989,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter,	/* The VDBE cursor that implement
 			pRoot =
 			    vdbeMergeEngineNew(SORTER_MAX_MERGE_COUNT);
 			if (pRoot == 0)
-				rc = SQL_NOMEM;
+				rc = -1;
 			for (i = 0; i < pTask->nPMA && rc == 0;
 			     i += SORTER_MAX_MERGE_COUNT) {
 				MergeEngine *pMerger = 0;	/* New level-0 PMA merger */
@@ -2179,7 +2177,7 @@ sqlVdbeSorterRowkey(const VdbeCursor * pCsr, Mem * pOut)
 	pSorter = pCsr->uc.pSorter;
 	pKey = vdbeSorterRowkey(pSorter, &nKey);
 	if (sqlVdbeMemClearAndResize(pOut, nKey)) {
-		return SQL_NOMEM;
+		return -1;
 	}
 	pOut->n = nKey;
 	MemSetTypeFlag(pOut, MEM_Blob);
@@ -2196,7 +2194,7 @@ sqlVdbeSorterRowkey(const VdbeCursor * pCsr, Mem * pOut)
  * If the sorter cursor key contains any NULL values, consider it to be
  * less than pVal. Even if pVal also contains NULL values.
  *
- * If an error occurs, return an sql error code (i.e. SQL_NOMEM).
+ * If an error occurs, return -1.
  * Otherwise, set *pRes to a negative, zero or positive value if the
  * key in pVal is smaller than, equal to or larger than the current sorter
  * key.
@@ -2224,7 +2222,7 @@ sqlVdbeSorterCompare(const VdbeCursor * pCsr,	/* Sorter cursor */
 		r2 = pSorter->pUnpacked =
 			sqlVdbeAllocUnpackedRecord(pSorter->db,  pCsr->key_def);
 		if (r2 == 0)
-			return SQL_NOMEM;
+			return -1;
 		r2->nField = nKeyCol;
 	}
 	assert(r2->nField == nKeyCol);
diff --git a/src/box/sql/where.c b/src/box/sql/where.c
index 6c91ffb..565e2db 100644
--- a/src/box/sql/where.c
+++ b/src/box/sql/where.c
@@ -1741,7 +1741,7 @@ whereLoopResize(sql * db, WhereLoop * p, int n)
 	n = (n + 7) & ~7;
 	paNew = sqlDbMallocRawNN(db, sizeof(p->aLTerm[0]) * n);
 	if (paNew == 0)
-		return SQL_NOMEM;
+		return -1;
 	memcpy(paNew, p->aLTerm, sizeof(p->aLTerm[0]) * p->nLSlot);
 	if (p->aLTerm != p->aLTermSpace)
 		sqlDbFree(db, p->aLTerm);
@@ -1762,7 +1762,7 @@ whereLoopXfer(sql * db, WhereLoop * pTo, WhereLoop * pFrom)
 		pTo->nBtm = 0;
 		pTo->nTop = 0;
 		pTo->index_def = NULL;
-		return SQL_NOMEM;
+		return -1;
 	}
 	memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
 	memcpy(pTo->aLTerm, pFrom->aLTerm,
@@ -2079,7 +2079,7 @@ whereLoopInsert(WhereLoopBuilder * pBuilder, WhereLoop * pTemplate)
 		/* Allocate a new WhereLoop to add to the end of the list */
 		*ppPrev = p = sqlDbMallocRawNN(db, sizeof(WhereLoop));
 		if (p == 0)
-			return SQL_NOMEM;
+			return -1;
 		whereLoopInit(p);
 		p->pNextLoop = 0;
 	} else {
@@ -2308,7 +2308,7 @@ whereLoopAddBtreeIndex(WhereLoopBuilder * pBuilder,	/* The WhereLoop factory */
 
 	pNew = pBuilder->pNew;
 	if (db->mallocFailed)
-		return SQL_NOMEM;
+		return -1;
 	WHERETRACE(0x800, ("BEGIN addBtreeIdx(%s), nEq=%d\n",
 			   probe->name, pNew->nEq));
 
@@ -3545,7 +3545,7 @@ whereSortingCost(WhereInfo * pWInfo, LogEst nRow, int nOrderBy, int nSorted)
  * will be nRowEst (in the 10*log2 representation).  Or, ignore sorting
  * costs if nRowEst==0.
  *
- * Return 0 on success or SQL_NOMEM of a memory allocation
+ * Return 0 on success or -1 of a memory allocation
  * error occurs.
  */
 static int
@@ -3601,7 +3601,7 @@ wherePathSolver(WhereInfo * pWInfo, LogEst nRowEst)
 	nSpace += sizeof(LogEst) * nOrderBy;
 	pSpace = sqlDbMallocRawNN(db, nSpace);
 	if (pSpace == 0)
-		return SQL_NOMEM;
+		return -1;
 	aTo = (WherePath *) pSpace;
 	aFrom = aTo + mxChoice;
 	memset(aFrom, 0, sizeof(aFrom[0]));

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 25/28] sql: remove sql_log()
  2019-06-13 22:24   ` [tarantool-patches] " Vladislav Shpilevoy
@ 2019-06-15 10:02     ` Mergen Imeev
  0 siblings, 0 replies; 56+ messages in thread
From: Mergen Imeev @ 2019-06-15 10:02 UTC (permalink / raw)
  To: Vladislav Shpilevoy; +Cc: tarantool-patches

On Fri, Jun 14, 2019 at 12:24:53AM +0200, Vladislav Shpilevoy wrote:
> Thanks for the patch!
> 
> Consider my review fixes below and on the branch
> in a separate commit.
> 
Thank you! New patch:

From 59aeab3a41c3107bccbcb31f9f9b1bc7f8f9ed81 Mon Sep 17 00:00:00 2001
Date: Sat, 25 May 2019 11:56:19 +0300
Subject: [PATCH] sql: remove sql_log()

This function is not used in Tarantool and should be removed.

diff --git a/src/box/sql/global.c b/src/box/sql/global.c
index 13e9c67..2d937d7 100644
--- a/src/box/sql/global.c
+++ b/src/box/sql/global.c
@@ -196,8 +196,6 @@ SQL_WSD struct sqlConfig sqlConfig = {
 	0,			/* isInit */
 	0,			/* inProgress */
 	0,			/* isMallocInit */
-	0,			/* xLog */
-	0,			/* pLogArg */
 #ifdef SQL_VDBE_COVERAGE
 	0,			/* xVdbeBranch */
 	0,			/* pVbeBranchArg */
diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index ad8f289..683a71d 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -1073,10 +1073,9 @@ unixUnmapfile(unixFile * pFd)
  *       unixFile.mmapSize
  *       unixFile.mmapSizeActual
  *
- * If unsuccessful, an error message is logged via sql_log() and
- * the three variables above are zeroed. In this case sql should
- * continue accessing the database using the xRead() and xWrite()
- * methods.
+ * If unsuccessful,the three variables above are zeroed. In this
+ * case sql should continue accessing the database using the
+ * xRead() and xWrite() methods.
  */
 static void
 unixRemapfile(unixFile * pFd,	/* File descriptor object */
diff --git a/src/box/sql/printf.c b/src/box/sql/printf.c
index 8abb673..98372f0 100644
--- a/src/box/sql/printf.c
+++ b/src/box/sql/printf.c
@@ -1114,40 +1114,6 @@ sql_snprintf(int n, char *zBuf, const char *zFormat, ...)
 	return z;
 }
 
-/*
- * This is the routine that actually formats the sql_log() message.
- * We house it in a separate routine from sql_log() to avoid using
- * stack space on small-stack systems when logging is disabled.
- *
- * sqlVXPrintf() might ask for *temporary* memory allocations for
- * certain format characters (%q) or for very large precisions or widths.
- */
-static void
-renderLogMsg(int iErrCode, const char *zFormat, va_list ap)
-{
-	StrAccum acc;		/* String accumulator */
-	char zMsg[SQL_PRINT_BUF_SIZE * 3];	/* Complete log message */
-
-	sqlStrAccumInit(&acc, 0, zMsg, sizeof(zMsg), 0);
-	sqlVXPrintf(&acc, zFormat, ap);
-	sqlGlobalConfig.xLog(sqlGlobalConfig.pLogArg, iErrCode,
-				 sqlStrAccumFinish(&acc));
-}
-
-/*
- * Format and write a message to the log if logging is enabled.
- */
-void
-sql_log(int iErrCode, const char *zFormat, ...)
-{
-	va_list ap;		/* Vararg list */
-	if (sqlGlobalConfig.xLog) {
-		va_start(ap, zFormat);
-		renderLogMsg(iErrCode, zFormat, ap);
-		va_end(ap);
-	}
-}
-
 #if defined(SQL_DEBUG)
 /*
  * A version of printf() that understands %lld.  Used for debugging.
diff --git a/src/box/sql/resolve.c b/src/box/sql/resolve.c
index be8cc25..fdf3703 100644
--- a/src/box/sql/resolve.c
+++ b/src/box/sql/resolve.c
@@ -363,8 +363,7 @@ lookupName(Parse * pParse,	/* The parsing context */
 		 * The ability to use an output result-set column in the WHERE, GROUP BY,
 		 * or HAVING clauses, or as part of a larger expression in the ORDER BY
 		 * clause is not standard SQL.  This is a (goofy) sql extension, that
-		 * is supported for backwards compatibility only. Hence, we issue a warning
-		 * on sql_log() whenever the capability is used.
+		 * is supported for backwards compatibility only.
 		 */
 		if ((pEList = pNC->pEList) != 0 && zTab == 0 && cnt == 0) {
 			for (j = 0; j < pEList->nExpr; j++) {
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index c7a1a81..434a5bd 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -554,9 +554,6 @@ sql_row_count(struct sql_context *context, MAYBE_UNUSED int unused1,
 void *
 sql_user_data(sql_context *);
 
-void
-sql_log(int iErrCode, const char *zFormat, ...);
-
 void *
 sql_aggregate_context(sql_context *,
 			  int nBytes);
@@ -2592,8 +2589,6 @@ struct sqlConfig {
 	int isInit;		/* True after initialization has finished */
 	int inProgress;		/* True while initialization in progress */
 	int isMallocInit;	/* True after malloc is initialized */
-	void (*xLog) (void *, int, const char *);	/* Function for logging */
-	void *pLogArg;		/* First argument to xLog() */
 #ifdef SQL_VDBE_COVERAGE
 	/* The following callback (if not NULL) is invoked on every VDBE branch
 	 * operation.  Set the callback using sql_TESTCTRL_VDBE_COVERAGE.

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 26/28] sql: cleanup of legacy memory management system
  2019-06-13 22:24   ` [tarantool-patches] " Vladislav Shpilevoy
@ 2019-06-15 10:04     ` Mergen Imeev
  2019-06-18 20:40       ` Vladislav Shpilevoy
  0 siblings, 1 reply; 56+ messages in thread
From: Mergen Imeev @ 2019-06-15 10:04 UTC (permalink / raw)
  To: Vladislav Shpilevoy; +Cc: tarantool-patches

On Fri, Jun 14, 2019 at 12:24:45AM +0200, Vladislav Shpilevoy wrote:
> Thanks for the patch!
> 
> Consider my review fixes below and on the branch
> in a separate commit.
>
Thank you! After rebase, the patch became a little shorter.
New patch:

From 6157214a59995e0b46f394474c7111166459e137 Mon Sep 17 00:00:00 2001
Date: Sat, 25 May 2019 18:50:33 +0300
Subject: [PATCH] sql: cleanup of legacy memory management system

Follow-up for #4074

diff --git a/src/box/sql/CMakeLists.txt b/src/box/sql/CMakeLists.txt
index 7059b57..f0b2e78 100644
--- a/src/box/sql/CMakeLists.txt
+++ b/src/box/sql/CMakeLists.txt
@@ -49,7 +49,6 @@ add_library(sql STATIC
     random.c
     resolve.c
     select.c
-    status.c
     tokenize.c
     treeview.c
     trigger.c
diff --git a/src/box/sql/date.c b/src/box/sql/date.c
index 5cb7c85..2e2a71a 100644
--- a/src/box/sql/date.c
+++ b/src/box/sql/date.c
@@ -536,9 +536,6 @@ clearYMD_HMS_TZ(DateTime * p)
  * is available.  This routine returns 0 on success and
  * non-zero on any kind of error.
  *
- * If the sqlGlobalConfig.bLocaltimeFault variable is true then this
- * routine will always fail.
- *
  * EVIDENCE-OF: R-62172-00036 In this implementation, the standard C
  * library function localtime_r() is used to assist in the calculation of
  * local time.
@@ -550,18 +547,10 @@ osLocaltime(time_t * t, struct tm *pTm)
 #if !HAVE_LOCALTIME_R && !HAVE_LOCALTIME_S
 	struct tm *pX;
 	pX = localtime(t);
-
-	if (sqlGlobalConfig.bLocaltimeFault)
-		pX = 0;
-
 	if (pX)
 		*pTm = *pX;
 	rc = pX == 0;
 #else
-
-	if (sqlGlobalConfig.bLocaltimeFault)
-		return 1;
-
 #if HAVE_LOCALTIME_R
 	rc = localtime_r(t, pTm) == 0;
 #else
diff --git a/src/box/sql/fault.c b/src/box/sql/fault.c
index 62e9924..ee3a4ea 100644
--- a/src/box/sql/fault.c
+++ b/src/box/sql/fault.c
@@ -67,19 +67,6 @@ static SQL_WSD struct BenignMallocHooks {
 #define wsdHooks sqlHooks
 
 /*
- * Register hooks to call when sqlBeginBenignMalloc() and
- * sqlEndBenignMalloc() are called, respectively.
- */
-void
-sqlBenignMallocHooks(void (*xBenignBegin) (void), void (*xBenignEnd) (void)
-    )
-{
-	wsdHooksInit;
-	wsdHooks.xBenignBegin = xBenignBegin;
-	wsdHooks.xBenignEnd = xBenignEnd;
-}
-
-/*
  * This (sqlEndBenignMalloc()) is called by sql code to indicate that
  * subsequent malloc failures are benign. A call to sqlEndBenignMalloc()
  * indicates that subsequent malloc failures are non-benign.
diff --git a/src/box/sql/global.c b/src/box/sql/global.c
index 2d937d7..6cadef8 100644
--- a/src/box/sql/global.c
+++ b/src/box/sql/global.c
@@ -137,29 +137,6 @@ const unsigned char sqlCtypeMap[256] = {
 	0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40	/* f8..ff    ........ */
 };
 
-/* EVIDENCE-OF: R-02982-34736 In order to maintain full backwards
- * compatibility for legacy applications, the URI filename capability is
- * disabled by default.
- *
- * EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled
- * using the SQL_USE_URI=1 or SQL_USE_URI=0 compile-time options.
- *
- * EVIDENCE-OF: R-43642-56306 By default, URI handling is globally
- * disabled. The default value may be changed by compiling with the
- * SQL_USE_URI symbol defined.
- */
-#ifndef SQL_USE_URI
-#define  SQL_USE_URI 0
-#endif
-
-/* EVIDENCE-OF: R-38720-18127 The default setting is determined by the
- * SQL_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if
- * that compile-time option is omitted.
- */
-#ifndef SQL_ALLOW_COVERING_INDEX_SCAN
-#define SQL_ALLOW_COVERING_INDEX_SCAN 1
-#endif
-
 /* The minimum PMA size is set to this value multiplied by the database
  * page size in bytes.
  */
@@ -172,35 +149,16 @@ const unsigned char sqlCtypeMap[256] = {
  * the sql library.
  */
 SQL_WSD struct sqlConfig sqlConfig = {
-	SQL_DEFAULT_MEMSTATUS,	/* bMemstat */
-	SQL_USE_URI,		/* bOpenUri */
-	SQL_ALLOW_COVERING_INDEX_SCAN,	/* bUseCis */
-	0x7ffffffe,		/* mxStrlen */
-	0,			/* neverCorrupt */
-	0,			/* nStmtSpill */
-	(void *)0,		/* pHeap */
-	0,			/* nHeap */
-	0, 0,			/* mnHeap, mxHeap */
 	SQL_DEFAULT_MMAP_SIZE,	/* szMmap */
 	SQL_MAX_MMAP_SIZE,	/* mxMmap */
-	(void *)0,		/* pScratch */
-	0,			/* szScratch */
-	0,			/* nScratch */
-	(void *)0,		/* pPage */
-	0,			/* szPage */
-	SQL_DEFAULT_PCACHE_INITSZ,	/* nPage */
-	0,			/* mxParserStack */
-	0,			/* sharedCacheEnabled */
 	SQL_SORTER_PMASZ,	/* szPma */
 	/* All the rest should always be initialized to zero */
 	0,			/* isInit */
 	0,			/* inProgress */
-	0,			/* isMallocInit */
 #ifdef SQL_VDBE_COVERAGE
 	0,			/* xVdbeBranch */
 	0,			/* pVbeBranchArg */
 #endif
-	0,			/* bLocaltimeFault */
 	0x7ffffffe		/* iOnceResetThreshold */
 };
 
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index d2688e7..59c8315 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -105,11 +105,6 @@ sql_initialize(void)
 	if (sqlGlobalConfig.isInit)
 		return 0;
 
-	if (!sqlGlobalConfig.isMallocInit)
-		sqlMallocInit();
-	if (rc == 0)
-		sqlGlobalConfig.isMallocInit = 1;
-
 	/* If rc is not 0 at this point, then the malloc
 	 * subsystem could not be initialized.
 	 */
diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index 62184f4..f19b7d0 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -62,23 +62,6 @@ sql_sized_malloc(int nByte)
 }
 
 /*
- * Like free() but works for allocations obtained from sql_sized_malloc()
- * or sql_sized_realloc().
- *
- * For this low-level routine, we already know that pPrior!=0 since
- * cases where pPrior==0 will have been intecepted and dealt with
- * by higher-level routines.
- */
-static void
-sql_sized_free(void *pPrior)
-{
-	sql_int64 *p = (sql_int64 *) pPrior;
-	assert(pPrior != 0);
-	p--;
-	free(p);
-}
-
-/*
  * Report the allocated size of a prior return from sql_sized_malloc()
  * or sql_sized_realloc().
  */
@@ -121,145 +104,6 @@ sql_sized_realloc(void *pPrior, int nByte)
 }
 
 /*
- * Attempt to release up to n bytes of non-essential memory currently
- * held by sql. An example of non-essential memory is memory used to
- * cache database pages that are not currently in use.
- */
-int
-sql_release_memory(int n)
-{
-	/* IMPLEMENTATION-OF: R-34391-24921 The sql_release_memory() routine
-	 * is a no-op returning zero if sql is not compiled with
-	 * SQL_ENABLE_MEMORY_MANAGEMENT.
-	 */
-	UNUSED_PARAMETER(n);
-	return 0;
-}
-
-/*
- * An instance of the following object records the location of
- * each unused scratch buffer.
- */
-typedef struct ScratchFreeslot {
-	struct ScratchFreeslot *pNext;	/* Next unused scratch buffer */
-} ScratchFreeslot;
-
-/*
- * State information local to the memory allocation subsystem.
- */
-static SQL_WSD struct Mem0Global {
-	sql_int64 alarmThreshold;	/* The soft heap limit */
-
-	/*
-	 * Pointers to the end of sqlGlobalConfig.pScratch memory
-	 * (so that a range test can be used to determine if an allocation
-	 * being freed came from pScratch) and a pointer to the list of
-	 * unused scratch allocations.
-	 */
-	void *pScratchEnd;
-	ScratchFreeslot *pScratchFree;
-	u32 nScratchFree;
-
-	/*
-	 * True if heap is nearly "full" where "full" is defined by the
-	 * sql_soft_heap_limit() setting.
-	 */
-	int nearlyFull;
-} mem0 = {
-0, 0, 0, 0, 0};
-
-#define mem0 GLOBAL(struct Mem0Global, mem0)
-
-/*
- * Initialize the memory allocation subsystem.
- */
-void
-sqlMallocInit(void)
-{
-	memset(&mem0, 0, sizeof(mem0));
-	if (sqlGlobalConfig.pScratch && sqlGlobalConfig.szScratch >= 100
-	    && sqlGlobalConfig.nScratch > 0) {
-		int i, n, sz;
-		ScratchFreeslot *pSlot;
-		sz = ROUNDDOWN8(sqlGlobalConfig.szScratch);
-		sqlGlobalConfig.szScratch = sz;
-		pSlot = (ScratchFreeslot *) sqlGlobalConfig.pScratch;
-		n = sqlGlobalConfig.nScratch;
-		mem0.pScratchFree = pSlot;
-		mem0.nScratchFree = n;
-		for (i = 0; i < n - 1; i++) {
-			pSlot->pNext = (ScratchFreeslot *) (sz + (char *)pSlot);
-			pSlot = pSlot->pNext;
-		}
-		pSlot->pNext = 0;
-		mem0.pScratchEnd = (void *)&pSlot[1];
-	} else {
-		mem0.pScratchEnd = 0;
-		sqlGlobalConfig.pScratch = 0;
-		sqlGlobalConfig.szScratch = 0;
-		sqlGlobalConfig.nScratch = 0;
-	}
-	if (sqlGlobalConfig.pPage == 0 || sqlGlobalConfig.szPage < 512
-	    || sqlGlobalConfig.nPage <= 0) {
-		sqlGlobalConfig.pPage = 0;
-		sqlGlobalConfig.szPage = 0;
-	}
-}
-
-/*
- * Return true if the heap is currently under memory pressure - in other
- * words if the amount of heap used is close to the limit set by
- * sql_soft_heap_limit().
- */
-int
-sqlHeapNearlyFull(void)
-{
-	return mem0.nearlyFull;
-}
-
-/*
- * Trigger the alarm
- */
-static void
-sqlMallocAlarm(int nByte)
-{
-	if (mem0.alarmThreshold <= 0)
-		return;
-	sql_release_memory(nByte);
-}
-
-/*
- * Do a memory allocation with statistics and alarms.  Assume the
- * lock is already held.
- */
-static int
-mallocWithAlarm(int n, void **pp)
-{
-	int nFull;
-	void *p;
-	nFull = ROUND8(n);
-	sqlStatusHighwater(SQL_STATUS_MALLOC_SIZE, n);
-	if (mem0.alarmThreshold > 0) {
-		sql_int64 nUsed =
-		    sqlStatusValue(SQL_STATUS_MEMORY_USED);
-		if (nUsed >= mem0.alarmThreshold - nFull) {
-			mem0.nearlyFull = 1;
-			sqlMallocAlarm(nFull);
-		} else {
-			mem0.nearlyFull = 0;
-		}
-	}
-	p = sql_sized_malloc(nFull);
-	if (p) {
-		nFull = sqlMallocSize(p);
-		sqlStatusUp(SQL_STATUS_MEMORY_USED, nFull);
-		sqlStatusUp(SQL_STATUS_MALLOC_COUNT, 1);
-	}
-	*pp = p;
-	return nFull;
-}
-
-/*
  * Allocate memory.  This routine is like sql_malloc() except that it
  * assumes the memory subsystem has already been initialized.
  */
@@ -275,8 +119,6 @@ sqlMalloc(u64 n)
 		 * this amount.  The only way to reach the limit is with sql_malloc()
 		 */
 		p = 0;
-	} else if (sqlGlobalConfig.bMemstat) {
-		mallocWithAlarm((int)n, &p);
 	} else {
 		p = sql_sized_malloc((int)n);
 	}
@@ -311,37 +153,17 @@ sqlMallocSize(void *p)
 	return sql_sized_sizeof(p);
 }
 
-sql_uint64
-sql_msize(void *p)
-{
-	return p ? sql_sized_sizeof(p) : 0;
-}
-
 /*
  * Free memory previously obtained from sqlMalloc().
  */
 void
 sql_free(void *p)
 {
-	if (p == 0)
-		return;		/* IMP: R-49053-54554 */
-	if (sqlGlobalConfig.bMemstat) {
-		sqlStatusDown(SQL_STATUS_MEMORY_USED,
-				  sqlMallocSize(p));
-		sqlStatusDown(SQL_STATUS_MALLOC_COUNT, 1);
-		sql_sized_free(p);
-	} else
-		sql_sized_free(p);
-}
-
-/*
- * Add the size of memory allocation "p" to the count in
- * *db->pnBytesFreed.
- */
-static SQL_NOINLINE void
-measureAllocationSize(sql * db, void *p)
-{
-	*db->pnBytesFreed += sqlMallocSize(p);
+	if (p == NULL)
+		return;
+	sql_int64 *raw_p = (sql_int64 *) p;
+	raw_p--;
+	free(raw_p);
 }
 
 /*
@@ -351,14 +173,7 @@ measureAllocationSize(sql * db, void *p)
 void
 sqlDbFree(sql * db, void *p)
 {
-	if (p == 0)
-		return;
-	if (db) {
-		if (db->pnBytesFreed) {
-			measureAllocationSize(db, p);
-			return;
-		}
-	}
+	(void) db;
 	sql_free(p);
 }
 
@@ -368,7 +183,7 @@ sqlDbFree(sql * db, void *p)
 void *
 sqlRealloc(void *pOld, u64 nBytes)
 {
-	int nOld, nNew, nDiff;
+	int nOld, nNew;
 	void *pNew;
 	if (pOld == 0) {
 		return sqlMalloc(nBytes);	/* IMP: R-04300-56712 */
@@ -383,36 +198,14 @@ sqlRealloc(void *pOld, u64 nBytes)
 	}
 	nOld = sqlMallocSize(pOld);
 	nNew = ROUND8((int)nBytes);
-	if (nOld == nNew) {
+	if (nOld == nNew)
 		pNew = pOld;
-	} else if (sqlGlobalConfig.bMemstat) {
-		sqlStatusHighwater(SQL_STATUS_MALLOC_SIZE, (int)nBytes);
-		nDiff = nNew - nOld;
-		if (nDiff > 0
-		    && sqlStatusValue(SQL_STATUS_MEMORY_USED) >=
-		    mem0.alarmThreshold - nDiff) {
-			sqlMallocAlarm(nDiff);
-		}
+	else
 		pNew = sql_sized_realloc(pOld, nNew);
-		if (pNew == 0 && mem0.alarmThreshold > 0) {
-			sqlMallocAlarm((int)nBytes);
-			pNew = sql_sized_realloc(pOld, nNew);
-		}
-		if (pNew) {
-			nNew = sqlMallocSize(pNew);
-			sqlStatusUp(SQL_STATUS_MEMORY_USED, nNew - nOld);
-		}
-	} else {
-		pNew = sql_sized_realloc(pOld, nNew);
-	}
 	assert(EIGHT_BYTE_ALIGNMENT(pNew));	/* IMP: R-11148-40995 */
 	return pNew;
 }
 
-/*
- * The public interface to sqlRealloc.  Make sure that the memory
- * subsystem is initialized prior to invoking sqlRealloc.
- */
 void *
 sql_realloc64(void *pOld, sql_uint64 n)
 {
@@ -481,7 +274,7 @@ sqlDbMallocRaw(sql * db, u64 n)
 void *
 sqlDbMallocRawNN(sql * db, u64 n)
 {
-	assert(db != NULL && db->pnBytesFreed == NULL);
+	assert(db != NULL);
 	if (db->mallocFailed)
 		return NULL;
 	void *p = sqlMalloc(n);
@@ -601,16 +394,6 @@ sqlOomClear(sql * db)
 }
 
 /*
- * Take actions at the end of an API call to indicate an OOM error
- */
-static SQL_NOINLINE int
-apiOomError(sql * db)
-{
-	sqlOomClear(db);
-	return -1;
-}
-
-/*
  * This function must be called before exiting any API function (i.e.
  * returning control to the user) that has called sql_malloc or
  * sql_realloc.
@@ -623,7 +406,8 @@ sqlApiExit(sql * db, int rc)
 {
 	assert(db != 0);
 	if (db->mallocFailed) {
-		return apiOomError(db);
+		sqlOomClear(db);
+		return -1;
 	}
 	return rc;
 }
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 434a5bd..2e7bf33 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -168,15 +168,6 @@
 #define SQL_NOINLINE
 #endif
 
-/*
- * EVIDENCE-OF: R-25715-37072 Memory allocation statistics are enabled by
- * default unless sql is compiled with sql_DEFAULT_MEMSTATUS=0 in
- * which case memory allocation statistics are disabled by default.
- */
-#if !defined(SQL_DEFAULT_MEMSTATUS)
-#define SQL_DEFAULT_MEMSTATUS 1
-#endif
-
 #if defined(SQL_SYSTEM_MALLOC) \
   + defined(SQL_ZERO_MALLOC) > 1
 #error "Two or more of the following compile-time configuration options\
@@ -578,13 +569,6 @@ sql_initialize(void);
 
 #define SQL_DETERMINISTIC    0x800
 
-#define SQL_STATUS_MEMORY_USED          0
-#define SQL_STATUS_MALLOC_SIZE          5
-#define SQL_STATUS_PARSER_STACK         6
-#define SQL_STATUS_PAGECACHE_SIZE       7
-#define SQL_STATUS_SCRATCH_SIZE         8
-#define SQL_STATUS_MALLOC_COUNT         9
-
 int
 sql_create_function_v2(sql * db,
 			   const char *zFunctionName,
@@ -782,16 +766,6 @@ sql_bind_parameter_lindex(sql_stmt * pStmt, const char *zName,
 #endif
 
 /*
- * The default initial allocation for the pagecache when using separate
- * pagecaches for each database connection.  A positive number is the
- * number of pages.  A negative number N translations means that a buffer
- * of -1024*N bytes is allocated and used for as many pages as it will hold.
- */
-#ifndef SQL_DEFAULT_PCACHE_INITSZ
-#define SQL_DEFAULT_PCACHE_INITSZ 100
-#endif
-
-/*
  * GCC does not define the offsetof() macro so we'll have to do it
  * ourselves.
  */
@@ -1162,7 +1136,6 @@ struct sql {
 	void (*xUpdateCallback) (void *, int, const char *, const char *,
 				 sql_int64);
 	Hash aFunc;		/* Hash table of connection functions */
-	int *pnBytesFreed;	/* If not NULL, increment this in DbFree() */
 };
 
 /*
@@ -1223,11 +1196,7 @@ struct sql {
  * than being distinct from one another.
  */
 #define SQL_MAGIC_OPEN     0xa029a697	/* Database is open */
-#define SQL_MAGIC_CLOSED   0x9f3c2d33	/* Database is closed */
-#define SQL_MAGIC_SICK     0x4b771290	/* Error and awaiting close */
 #define SQL_MAGIC_BUSY     0xf03b7906	/* Database currently in use */
-#define SQL_MAGIC_ERROR    0xb5357930	/* An sql_MISUSE error occurred */
-#define SQL_MAGIC_ZOMBIE   0x64cffc7f	/* Close with last statement close */
 
 /**
  * SQL type definition. Now it is an alias to type, but in
@@ -2563,32 +2532,14 @@ struct StrAccum {
  * This structure also contains some state information.
  */
 struct sqlConfig {
-	int bMemstat;		/* True to enable memory status */
-	int bOpenUri;		/* True to interpret filenames as URIs */
-	int bUseCis;		/* Use covering indices for full-scans */
-	int mxStrlen;		/* Maximum string length */
-	int neverCorrupt;	/* Database is always well-formed */
-	int nStmtSpill;		/* Stmt-journal spill-to-disk threshold */
-	void *pHeap;		/* Heap storage space */
-	int nHeap;		/* Size of pHeap[] */
-	int mnReq, mxReq;	/* Min and max heap requests sizes */
 	sql_int64 szMmap;	/* mmap() space per open file */
 	sql_int64 mxMmap;	/* Maximum value for szMmap */
-	void *pScratch;		/* Scratch memory */
-	int szScratch;		/* Size of each scratch buffer */
-	int nScratch;		/* Number of scratch buffers */
-	void *pPage;		/* Page cache memory */
-	int szPage;		/* Size of each page in pPage[] */
-	int nPage;		/* Number of pages in pPage[] */
-	int mxParserStack;	/* maximum depth of the parser stack */
-	int sharedCacheEnabled;	/* true if shared-cache mode enabled */
 	u32 szPma;		/* Maximum Sorter PMA size */
 	/* The above might be initialized to non-zero.  The following need to always
 	 * initially be zero, however.
 	 */
 	int isInit;		/* True after initialization has finished */
 	int inProgress;		/* True while initialization in progress */
-	int isMallocInit;	/* True after malloc is initialized */
 #ifdef SQL_VDBE_COVERAGE
 	/* The following callback (if not NULL) is invoked on every VDBE branch
 	 * operation.  Set the callback using sql_TESTCTRL_VDBE_COVERAGE.
@@ -2596,7 +2547,6 @@ struct sqlConfig {
 	void (*xVdbeBranch) (void *, int iSrcLine, u8 eThis, u8 eMx);	/* Callback */
 	void *pVdbeBranchArg;	/* 1st argument */
 #endif
-	int bLocaltimeFault;	/* True to fail localtime() calls */
 	int iOnceResetThreshold;	/* When to reset OP_Once counters */
 };
 
@@ -2685,7 +2635,6 @@ int sqlStrICmp(const char *, const char *);
 unsigned sqlStrlen30(const char *);
 #define sqlStrNICmp sql_strnicmp
 
-void sqlMallocInit(void);
 void *sqlMalloc(u64);
 void *sqlMallocZero(u64);
 void *sqlDbMallocZero(sql *, u64);
@@ -2698,8 +2647,6 @@ void *sqlDbReallocOrFree(sql *, void *, u64);
 void *sqlDbRealloc(sql *, void *, u64);
 void sqlDbFree(sql *, void *);
 int sqlMallocSize(void *);
-void sqlBenignMallocHooks(void (*)(void), void (*)(void));
-int sqlHeapNearlyFull(void);
 
 /*
  * On systems with ample stack space and that support alloca(), make
@@ -2719,11 +2666,6 @@ int sqlHeapNearlyFull(void);
 #define sqlStackFree(D,P)       sqlDbFree(D,P)
 #endif
 
-sql_int64 sqlStatusValue(int);
-void sqlStatusUp(int, int);
-void sqlStatusDown(int, int);
-void sqlStatusHighwater(int, int);
-
 int sqlIsNaN(double);
 
 /*
diff --git a/src/box/sql/status.c b/src/box/sql/status.c
deleted file mode 100644
index 515274a..0000000
--- a/src/box/sql/status.c
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright 2010-2017, Tarantool AUTHORS, please see AUTHORS file.
- *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * 1. Redistributions of source code must retain the above
- *    copyright notice, this list of conditions and the
- *    following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above
- *    copyright notice, this list of conditions and the following
- *    disclaimer in the documentation and/or other materials
- *    provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- *
- * This module implements the sql_status() interface and related
- * functionality.
- */
-#include "sqlInt.h"
-#include "vdbeInt.h"
-/*
- * Variables in which to record status information.
- */
-#if SQL_PTRSIZE>4
-typedef sql_int64 sqlStatValueType;
-#else
-typedef u32 sqlStatValueType;
-#endif
-typedef struct sqlStatType sqlStatType;
-static SQL_WSD struct sqlStatType {
-	sqlStatValueType nowValue[10];	/* Current value */
-	sqlStatValueType mxValue[10];	/* Maximum value */
-} sqlStat = { {
-0,}, {
-0,}};
-
-
-/* The "wsdStat" macro will resolve to the status information
- * state vector. In the common case where writable static data is
- * supported, wsdStat can refer directly  to the "sqlStat" state
- * vector declared above.
- */
-#define wsdStatInit
-#define wsdStat sqlStat
-
-/*
- * Return the current value of a status parameter.
- */
-sql_int64
-sqlStatusValue(int op)
-{
-	wsdStatInit;
-	assert(op >= 0 && op < ArraySize(wsdStat.nowValue));
-
-	return wsdStat.nowValue[op];
-}
-
-/*
- * Add N to the value of a status record.
- *
- * The StatusUp() routine can accept positive or negative values for N.
- * The value of N is added to the current status value and the high-water
- * mark is adjusted if necessary.
- *
- * The StatusDown() routine lowers the current value by N.  The highwater
- * mark is unchanged.  N must be non-negative for StatusDown().
- */
-void
-sqlStatusUp(int op, int N)
-{
-	wsdStatInit;
-	assert(op >= 0 && op < ArraySize(wsdStat.nowValue));
-
-	wsdStat.nowValue[op] += N;
-	if (wsdStat.nowValue[op] > wsdStat.mxValue[op]) {
-		wsdStat.mxValue[op] = wsdStat.nowValue[op];
-	}
-}
-
-void
-sqlStatusDown(int op, int N)
-{
-	wsdStatInit;
-	assert(N >= 0);
-
-	assert(op >= 0 && op < ArraySize(wsdStat.nowValue));
-	wsdStat.nowValue[op] -= N;
-}
-
-/*
- * Adjust the highwater mark if necessary.
- */
-void
-sqlStatusHighwater(int op, int X)
-{
-	sqlStatValueType newValue;
-	wsdStatInit;
-	assert(X >= 0);
-	newValue = (sqlStatValueType) X;
-	assert(op >= 0 && op < ArraySize(wsdStat.nowValue));
-
-	assert(op == SQL_STATUS_MALLOC_SIZE
-	       || op == SQL_STATUS_PAGECACHE_SIZE
-	       || op == SQL_STATUS_SCRATCH_SIZE
-	       || op == SQL_STATUS_PARSER_STACK);
-	if (newValue > wsdStat.mxValue[op]) {
-		wsdStat.mxValue[op] = newValue;
-	}
-}
diff --git a/src/box/sql/tokenize.c b/src/box/sql/tokenize.c
index ea364de..9fa069d 100644
--- a/src/box/sql/tokenize.c
+++ b/src/box/sql/tokenize.c
@@ -430,7 +430,7 @@ sql_token(const char *z, int *type, bool *is_reserved)
 static void
 parser_space_delete(struct sql *db, struct space *space)
 {
-	if (space == NULL || db == NULL || db->pnBytesFreed == 0)
+	if (space == NULL || db == NULL)
 		return;
 	assert(space->def->opts.is_ephemeral);
 	for (uint32_t i = 0; i < space->index_count; ++i)
@@ -514,11 +514,6 @@ sqlRunParser(Parse * pParse, const char *zSql)
 		}
 	}
 	pParse->zTail = &zSql[i];
-#ifdef YYTRACKMAXSTACKDEPTH
-	sqlStatusHighwater(SQL_STATUS_PARSER_STACK,
-			       sqlParserStackPeak(pEngine)
-	    );
-#endif				/* YYDEBUG */
 	sqlParserFree(pEngine, sql_free);
 	if (db->mallocFailed)
 		pParse->is_aborted = true;
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 8d512d3..579b200 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -226,10 +226,6 @@ allocateCursor(
 	 *     different sized allocations. Memory cells provide growable
 	 *     allocations.
 	 *
-	 *   * When using ENABLE_MEMORY_MANAGEMENT, memory cell buffers can
-	 *     be freed lazily via the sql_release_memory() API. This
-	 *     minimizes the number of malloc calls made by the system.
-	 *
 	 * The memory cell for cursor 0 is aMem[0]. The rest are allocated from
 	 * the top of the register space.  Cursor 1 is at Mem[p->nMem-1].
 	 * Cursor 2 is at Mem[p->nMem-2]. And so forth.
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index bc5a14a..364f7ed 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -664,17 +664,6 @@ freeEphemeralFunction(sql * db, FuncDef * pDef)
 
 static void vdbeFreeOpArray(sql *, Op *, int);
 
-/*
- * Delete a P4 value if necessary.
- */
-static SQL_NOINLINE void
-freeP4Mem(sql * db, Mem * p)
-{
-	if (p->szMalloc)
-		sqlDbFree(db, p->zMalloc);
-	sqlDbFree(db, p);
-}
-
 static SQL_NOINLINE void
 freeP4FuncCtx(sql * db, sql_context * p)
 {
@@ -705,14 +694,9 @@ freeP4(sql * db, int p4type, void *p4)
 			freeEphemeralFunction(db, (FuncDef *) p4);
 			break;
 		}
-	case P4_MEM:{
-			if (db->pnBytesFreed == 0) {
-				sqlValueFree((sql_value *) p4);
-			} else {
-				freeP4Mem(db, (Mem *) p4);
-			}
-			break;
-		}
+	case P4_MEM:
+		sqlValueFree((sql_value *) p4);
+		break;
 	}
 }
 
@@ -1305,13 +1289,6 @@ releaseMemArray(Mem * p, int N)
 	if (p && N) {
 		Mem *pEnd = &p[N];
 		sql *db = p->db;
-		if (db->pnBytesFreed) {
-			do {
-				if (p->szMalloc)
-					sqlDbFree(db, p->zMalloc);
-			} while ((++p) < pEnd);
-			return;
-		}
 		do {
 			assert((&p[1]) == pEnd || p[0].db == p[1].db);
 			assert(sqlVdbeCheckMemInvariants(p));
diff --git a/src/box/sql/vdbesort.c b/src/box/sql/vdbesort.c
index 5873fab..7091a99 100644
--- a/src/box/sql/vdbesort.c
+++ b/src/box/sql/vdbesort.c
@@ -819,43 +819,32 @@ sqlVdbeSorterInit(sql * db,	/* Database connection (for malloc()) */
 
 	pSorter = (VdbeSorter *) sqlDbMallocZero(db, sizeof(VdbeSorter));
 	pCsr->uc.pSorter = pSorter;
-	if (pSorter == 0) {
+	if (pSorter == 0)
+		return -1;
+
+	pSorter->key_def = pCsr->key_def;
+	pSorter->pgsz = pgsz = 1024;
+	pSorter->db = db;
+	pSorter->aTask.pSorter = pSorter;
+
+	/* Cache size in bytes */
+	i64 mxCache;
+	u32 szPma = sqlGlobalConfig.szPma;
+	pSorter->mnPmaSize = szPma * pgsz;
+
+	mxCache = SQL_DEFAULT_CACHE_SIZE;
+	mxCache = mxCache * -1024;
+	mxCache = MIN(mxCache, SQL_MAX_PMASZ);
+	pSorter->mxPmaSize = MAX(pSorter->mnPmaSize, (int)mxCache);
+	assert(pSorter->iMemory == 0);
+	pSorter->nMemory = pgsz;
+	pSorter->list.aMemory = (u8 *) sqlMalloc(pgsz);
+	if (!pSorter->list.aMemory)
 		rc = -1;
-	} else {
-		pSorter->key_def = pCsr->key_def;
-		pSorter->pgsz = pgsz = 1024;
-		pSorter->db = db;
-		pSorter->aTask.pSorter = pSorter;
-
-		i64 mxCache;	/* Cache size in bytes */
-		u32 szPma = sqlGlobalConfig.szPma;
-		pSorter->mnPmaSize = szPma * pgsz;
-
-		mxCache = SQL_DEFAULT_CACHE_SIZE;
-		mxCache = mxCache * -1024;
-		mxCache = MIN(mxCache, SQL_MAX_PMASZ);
-		pSorter->mxPmaSize =
-		    MAX(pSorter->mnPmaSize, (int)mxCache);
-
-		/* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
-		 * scratch memory using SQL_CONFIG_SCRATCH, sql avoids unnecessary
-		 * large heap allocations.
-		 */
-		if (sqlGlobalConfig.pScratch == 0) {
-			assert(pSorter->iMemory == 0);
-			pSorter->nMemory = pgsz;
-			pSorter->list.aMemory =
-			    (u8 *) sqlMalloc(pgsz);
-			if (!pSorter->list.aMemory)
-				rc = -1;
-		}
 
-		if (pCsr->key_def->part_count < 13
-		    && (pCsr->key_def->parts[0].coll == NULL)) {
-			pSorter->typeMask =
-			    SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT;
-		}
-	}
+	if (pCsr->key_def->part_count < 13 &&
+	    pCsr->key_def->parts[0].coll == NULL)
+		pSorter->typeMask = SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT;
 
 	return rc;
 }
@@ -1486,9 +1475,6 @@ sqlVdbeSorterWrite(const VdbeCursor * pCsr,	/* Sorter cursor */
 	 *
 	 *   * The total memory allocated for the in-memory list is greater
 	 *     than (page-size * cache-size), or
-	 *
-	 *   * The total memory allocated for the in-memory list is greater
-	 *     than (page-size * 10) and sqlHeapNearlyFull() returns true.
 	 */
 	nReq = pVal->n + sizeof(SorterRecord);
 	nPMA = pVal->n + sqlVarintLen(pVal->n);
@@ -1497,10 +1483,7 @@ sqlVdbeSorterWrite(const VdbeCursor * pCsr,	/* Sorter cursor */
 			bFlush = pSorter->iMemory
 			    && (pSorter->iMemory + nReq) > pSorter->mxPmaSize;
 		} else {
-			bFlush = ((pSorter->list.szPMA > pSorter->mxPmaSize)
-				  || (pSorter->list.szPMA > pSorter->mnPmaSize
-				      && sqlHeapNearlyFull())
-			    );
+			bFlush = ((pSorter->list.szPMA > pSorter->mxPmaSize));
 		}
 		if (bFlush) {
 			rc = vdbeSorterFlushPMA(pSorter);

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 00/28] sql: Remove SQL error system
  2019-06-13 22:24 ` Vladislav Shpilevoy
@ 2019-06-15 10:08   ` Mergen Imeev
  0 siblings, 0 replies; 56+ messages in thread
From: Mergen Imeev @ 2019-06-15 10:08 UTC (permalink / raw)
  To: Vladislav Shpilevoy; +Cc: tarantool-patches

Hi! Thank you for review! I squashed all commits with the title
"Review fix". I also rebased the branch to the current master.
There have been some changes due to issue 3978 (commit
"sql: cleanup code from outdated macros"). However, I am not sure
that these changes are enough to send a new version. Instead,
I just answered patches with a review. Since both issues usually
simply remove part of the unused code, in most cases the patches
get shorter after the rebase.


On Fri, Jun 14, 2019 at 12:24:43AM +0200, Vladislav Shpilevoy wrote:
> Hi! Thanks for the patchset!
> 
> Please, consider my review comments and fixes for some of
> the patches in responses to them.
> 
> Also I've pushed on top of the branch a new commit removing
> a couple of another error codes. It is not for squash - just
> a new commit.
> 
> On 10/06/2019 16:56, imeevma@tarantool.org wrote:
> > This patch-set removes unused and unnecessary code of SQL error
> > system.
> > 
> > Mergen Imeev (26):
> >   sql: remove field zErrMsg from struct Vdbe
> >   sql: remove field pErr from struct sql
> >   sql: remove field errCode from struct sql
> >   sql: remove sqlError() and remove sqlErrorWithMsg()
> >   sql: remove unused functions of SQL error system
> >   sql: disable lookaside system
> >   sql: remove SQL_OK error/status code
> >   sql: remove SQL_PERM, SQL_WARNING, SQL_ABORT errcodes
> >   sql: remove SQL_CANTOPEN errcode
> >   sql: remove SQL_NOTFOUND error/status code
> >   sql: remove SQL_LOCKED errcode
> >   sql: remove SQL_FULL errcode
> >   sql: remove SQL_MISUSE errcode
> >   sql: remove SQL_RANGE errcode
> >   sql: remove SQL_SCHEMA errcode
> >   sql: remove SQL_TOOBIG errcode
> >   sql: remove SQL_BUSY errcode
> >   sql: remove SQL_CONSTRAINT errcode
> >   sql: remove SQL_ERROR errcode
> >   sql: remove SQL_NOMEM errcode
> >   sql: remove SQL_IOERR errcode
> >   sql: remove SQL_TARANTOOL_ERROR errcode
> >   sql: remove field errMask from struct sql
> >   sql: replace rc by is_aborted in struct VDBE
> >   sql: remove sql_log()
> >   sql: remove function sqlApiExit()
> > 
> > Nikita Pettik (2):
> >   sql: cleanup of legacy memory management system
> >   sql: make function return void instead of int
> > 
> >  src/box/bind.c                |  37 +---
> >  src/box/ck_constraint.c       |   4 +-
> >  src/box/execute.c             |   6 +-
> >  src/box/lua/lua_sql.c         |   2 +-
> >  src/box/sql.c                 | 104 ++++------
> >  src/box/sql/analyze.c         |   2 +-
> >  src/box/sql/build.c           |   6 +-
> >  src/box/sql/cursor.c          |   4 +-
> >  src/box/sql/date.c            |  14 +-
> >  src/box/sql/expr.c            |   7 +-
> >  src/box/sql/fault.c           |   4 +-
> >  src/box/sql/fk_constraint.c   |   8 +-
> >  src/box/sql/func.c            |  16 +-
> >  src/box/sql/global.c          |   3 -
> >  src/box/sql/insert.c          |   9 +-
> >  src/box/sql/legacy.c          |  21 +-
> >  src/box/sql/main.c            | 266 ++++---------------------
> >  src/box/sql/malloc.c          | 445 +-----------------------------------------
> >  src/box/sql/os.c              |  14 +-
> >  src/box/sql/os_unix.c         | 281 ++++++++------------------
> >  src/box/sql/prepare.c         |  73 ++-----
> >  src/box/sql/printf.c          |  36 +---
> >  src/box/sql/resolve.c         |   3 +-
> >  src/box/sql/select.c          |  61 +++---
> >  src/box/sql/sqlInt.h          | 173 +---------------
> >  src/box/sql/status.c          | 182 -----------------
> >  src/box/sql/tarantoolInt.h    |  11 +-
> >  src/box/sql/tokenize.c        |   5 -
> >  src/box/sql/trigger.c         |   2 +-
> >  src/box/sql/util.c            | 162 ---------------
> >  src/box/sql/vdbe.c            | 111 ++++-------
> >  src/box/sql/vdbeInt.h         |  13 +-
> >  src/box/sql/vdbeapi.c         | 357 +++++++++------------------------
> >  src/box/sql/vdbeaux.c         | 217 ++++++--------------
> >  src/box/sql/vdbemem.c         | 120 ++++++------
> >  src/box/sql/vdbesort.c        | 274 ++++++++++++--------------
> >  src/box/sql/where.c           | 108 +++++-----
> >  src/box/sql/whereexpr.c       |   3 +-
> >  test/sql/bind.result          |   8 +
> >  test/sql/bind.test.lua        |   3 +
> >  test/sql/func-recreate.result |   3 +-
> >  41 files changed, 726 insertions(+), 2452 deletions(-)
> > 

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 18/28] sql: remove SQL_CONSTRAINT errcode
  2019-06-15 10:00     ` Mergen Imeev
@ 2019-06-18 20:40       ` Vladislav Shpilevoy
  2019-06-19  8:02         ` Mergen Imeev
  0 siblings, 1 reply; 56+ messages in thread
From: Vladislav Shpilevoy @ 2019-06-18 20:40 UTC (permalink / raw)
  To: Mergen Imeev; +Cc: tarantool-patches

Hi! Thanks for the patch!

On 15/06/2019 12:00, Mergen Imeev wrote:
> On Fri, Jun 14, 2019 at 12:24:55AM +0200, Vladislav Shpilevoy wrote:
>> Thanks for the patch!
>>
>> I've found 'sql_CONSTRAINT_UNIQUE' in sql-tap/unique.test.lua

It is still here. Please, fix.

>> on line 229. These tests are disabled by 'if 0 > 0', but another
>> comment says, that the issue #2495 fix should have enabled them
>> back. We need to either resurrect these tests, or drop them.
>>
>> Consider my review fixes below and on the branch
>> in a separate commit.
>>

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 26/28] sql: cleanup of legacy memory management system
  2019-06-15 10:04     ` Mergen Imeev
@ 2019-06-18 20:40       ` Vladislav Shpilevoy
  2019-06-19  8:04         ` Mergen Imeev
  0 siblings, 1 reply; 56+ messages in thread
From: Vladislav Shpilevoy @ 2019-06-18 20:40 UTC (permalink / raw)
  To: Mergen Imeev; +Cc: tarantool-patches

Thanks for the squash. I've found one another part of
SQL memory subsystem that can be removed. Please, consider
my review fixes here and on the branch in a separate commit.

======================================================

diff --git a/src/box/sql/CMakeLists.txt b/src/box/sql/CMakeLists.txt
index f0b2e78de..1f2a6640f 100644
--- a/src/box/sql/CMakeLists.txt
+++ b/src/box/sql/CMakeLists.txt
@@ -31,7 +31,6 @@ add_library(sql STATIC
     date.c
     delete.c
     expr.c
-    fault.c
     fk_constraint.c
     func.c
     global.c
diff --git a/src/box/sql/fault.c b/src/box/sql/fault.c
deleted file mode 100644
index ee3a4ea6d..000000000
--- a/src/box/sql/fault.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright 2010-2017, Tarantool AUTHORS, please see AUTHORS file.
- *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * 1. Redistributions of source code must retain the above
- *    copyright notice, this list of conditions and the
- *    following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above
- *    copyright notice, this list of conditions and the following
- *    disclaimer in the documentation and/or other materials
- *    provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- *
- * This file contains code to support the concept of "benign"
- * malloc failures (when the xMalloc() or xRealloc() method of the
- * sql_mem_methods structure fails to allocate a block of memory
- * and returns 0).
- *
- * Most malloc failures are non-benign. After they occur, sql
- * abandons the current operation and returns an error
- * to the user. However, sometimes a fault is not necessarily
- * fatal. For example, if a malloc fails while resizing a hash table, this
- * is completely recoverable simply by not carrying out the resize. The
- * hash table will continue to function normally.  So a malloc failure
- * during a hash table resize is a benign fault.
- */
-
-#include "sqlInt.h"
-
-/*
- * Global variables.
- */
-typedef struct BenignMallocHooks BenignMallocHooks;
-static SQL_WSD struct BenignMallocHooks {
-	void (*xBenignBegin) (void);
-	void (*xBenignEnd) (void);
-} sqlHooks = {
-0, 0};
-
-/* The "wsdHooks" macro will resolve to the appropriate BenignMallocHooks
- * structure.  If writable static data is unsupported on the target,
- * we have to locate the state vector at run-time.  In the more common
- * case where writable static data is supported, wsdHooks can refer directly
- * to the "sqlHooks" state vector declared above.
- */
-#define wsdHooksInit
-#define wsdHooks sqlHooks
-
-/*
- * This (sqlEndBenignMalloc()) is called by sql code to indicate that
- * subsequent malloc failures are benign. A call to sqlEndBenignMalloc()
- * indicates that subsequent malloc failures are non-benign.
- */
-void
-sqlBeginBenignMalloc(void)
-{
-	wsdHooksInit;
-	if (wsdHooks.xBenignBegin) {
-		wsdHooks.xBenignBegin();
-	}
-}
-
-void
-sqlEndBenignMalloc(void)
-{
-	wsdHooksInit;
-	if (wsdHooks.xBenignEnd) {
-		wsdHooks.xBenignEnd();
-	}
-}
-
diff --git a/src/box/sql/hash.c b/src/box/sql/hash.c
index 5bc8109dc..36f965b81 100644
--- a/src/box/sql/hash.c
+++ b/src/box/sql/hash.c
@@ -149,18 +149,7 @@ rehash(Hash * pH, unsigned int new_size)
 	if (new_size == pH->htsize)
 		return 0;
 #endif
-
-	/* The inability to allocates space for a larger hash table is
-	 * a performance hit but it is not a fatal error.  So mark the
-	 * allocation as a benign. Use sqlMalloc()/memset(0) instead of
-	 * sqlMallocZero() to make the allocation, as sqlMallocZero()
-	 * only zeroes the requested number of bytes whereas this module will
-	 * use the actual amount of space allocated for the hash table (which
-	 * may be larger than the requested amount).
-	 */
-	sqlBeginBenignMalloc();
 	new_ht = (struct _ht *)sqlMalloc(new_size * sizeof(struct _ht));
-	sqlEndBenignMalloc();
 
 	if (new_ht == 0)
 		return 0;
diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index f19b7d027..d92709b8e 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -368,17 +368,6 @@ sqlDbStrNDup(sql * db, const char *z, u64 n)
 	return zNew;
 }
 
-/*
- * Call this routine to record the fact that an OOM (out-of-memory) error
- * has happened.  This routine will set db->mallocFailed.
- */
-void
-sqlOomFault(sql * db)
-{
-	if (db->mallocFailed == 0 && db->bBenignMalloc == 0)
-		db->mallocFailed = 1;
-}
-
 /*
  * This routine reactivates the memory allocator and clears the
  * db->mallocFailed flag as necessary.
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 2e7bf3363..e4c584333 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -1107,7 +1107,6 @@ struct sql {
 	u16 dbOptFlags;		/* Flags to enable/disable optimizations */
 	u8 enc;			/* Text encoding */
 	u8 mallocFailed;	/* True if we have seen a malloc failure */
-	u8 bBenignMalloc;	/* Do not require OOMs if true */
 	u8 dfltLockMode;	/* Default locking-mode for attached dbs */
 	u8 mTrace;		/* zero or more sql_TRACE flags */
 	u32 magic;		/* Magic number for detect library misuse */
@@ -4290,7 +4289,14 @@ int sqlCreateFunc(sql *, const char *, enum field_type,
 		      void (*)(sql_context *, int, sql_value **),
 		      void (*)(sql_context *),
 		      FuncDestructor * pDestructor);
-void sqlOomFault(sql *);
+
+/** Set OOM error flag. */
+static inline void
+sqlOomFault(struct sql *db)
+{
+	db->mallocFailed = 1;
+}
+
 void sqlOomClear(sql *);
 int sqlApiExit(sql * db, int);
 
@@ -4472,13 +4478,6 @@ fk_constraint_emit_actions(struct Parse *parser, struct space *space, int reg_ol
 bool
 fk_constraint_is_required(struct space *space, const int *changes);
 
-/*
- * The interface to the code in fault.c used for identifying "benign"
- * malloc failures.
- */
-void sqlBeginBenignMalloc(void);
-void sqlEndBenignMalloc(void);
-
 /*
  * Allowed return values from sqlFindInIndex()
  */
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 579b2006c..c8887f9b7 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -747,7 +747,6 @@ int sqlVdbeExec(Vdbe *p)
 	assert(p->explain==0);
 	p->pResultSet = 0;
 #ifdef SQL_DEBUG
-	sqlBeginBenignMalloc();
 	if (p->pc == 0 &&
 	    (p->sql_flags & (SQL_VdbeListing|SQL_VdbeEQP|SQL_VdbeTrace)) != 0) {
 		int i;
@@ -771,7 +770,6 @@ int sqlVdbeExec(Vdbe *p)
 		if ((p->sql_flags & SQL_VdbeTrace) != 0)
 			printf("VDBE Trace:\n");
 	}
-	sqlEndBenignMalloc();
 #endif
 	for(pOp=&aOp[p->pc]; 1; pOp++) {
 		/* Errors are detected by individual opcodes, with an immediate

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 18/28] sql: remove SQL_CONSTRAINT errcode
  2019-06-18 20:40       ` Vladislav Shpilevoy
@ 2019-06-19  8:02         ` Mergen Imeev
  0 siblings, 0 replies; 56+ messages in thread
From: Mergen Imeev @ 2019-06-19  8:02 UTC (permalink / raw)
  To: Vladislav Shpilevoy; +Cc: tarantool-patches

Thank you for review! My answer, diff and new patch below.

On Tue, Jun 18, 2019 at 10:40:04PM +0200, Vladislav Shpilevoy wrote:
> Hi! Thanks for the patch!
> 
> On 15/06/2019 12:00, Mergen Imeev wrote:
> > On Fri, Jun 14, 2019 at 12:24:55AM +0200, Vladislav Shpilevoy wrote:
> >> Thanks for the patch!
> >>
> >> I've found 'sql_CONSTRAINT_UNIQUE' in sql-tap/unique.test.lua
> 
> It is still here. Please, fix.
> 
Sorry, missed this. Fixed.

Diff:

diff --git a/test/sql-tap/unique.test.lua b/test/sql-tap/unique.test.lua
index 358a06f..9818f90 100755
--- a/test/sql-tap/unique.test.lua
+++ b/test/sql-tap/unique.test.lua
@@ -1,6 +1,6 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
-test:plan(32)
+test:plan(35)
 
 --!./tcltestrunner.lua
 -- 2001 September 27
@@ -20,12 +20,7 @@ test:plan(32)
 -- $Id: unique.test,v 1.9 2009/05/02 15:46:47 drh Exp $
 -- ["set","testdir",[["file","dirname",["argv0"]]]]
 -- ["source",[["testdir"],"\/tester.tcl"]]
--- MUST_WORK_TEST
-if (0 > 0)
- then
-    -- Try to create a table with two primary keys.
-    -- (This is allowed in sql even that it is not valid SQL)
-end
+
 test:do_catchsql_test(
     "unique-1.1",
     [[
@@ -213,20 +208,16 @@ test:do_catchsql_test(
         -- </unique-2.7>
     })
 
--- MUST_WORK_TEST i2 is checking not only "a" column #2495
-if 0 > 0 then
 test:do_catchsql_test(
     "unique-2.8",
     [[
-        select a from t2;
-        --CREATE UNIQUE INDEX i2 ON t2(a);
+        CREATE UNIQUE INDEX i2 ON t2(a);
     ]], {
         -- <unique-2.8>
-        1, "UNIQUE constraint failed: t2.a"
+        1, "Duplicate key exists in unique index 'I2' in space 'T2'"
         -- </unique-2.8>
     })
 
--- verify_ex_errcode unique-2.8b sql_CONSTRAINT_UNIQUE
 test:do_catchsql_test(
     "unique-2.9",
     [[
@@ -236,7 +227,6 @@ test:do_catchsql_test(
         0
         -- </unique-2.9>
     })
-end
 
 --integrity_check unique-2.10
 -- Test the UNIQUE keyword as used on two or more fields.
@@ -391,18 +381,15 @@ test:do_catchsql_test(
         -- </unique-4.9>
     })
 
--- MUST_WORK_TEST i4c is checking not only "b" column #2495
-if 0 > 0 then
 test:do_catchsql_test(
     "unique-4.10",
     [[
         CREATE UNIQUE INDEX i4c ON t4(b)
     ]], {
         -- <unique-4.10>
-        1, "UNIQUE constraint failed: t4.b"
+        1, "Duplicate key exists in unique index 'I4C' in space 'T4'"
         -- </unique-4.10>
     })
-end
 
 --integrity_check unique-4.99
 -- Test the error message generation logic.  In particular, make sure we
diff --git a/test/sql-tap/index4.test.lua b/test/sql-tap/index4.test.lua
index d8c6bab..37c0569 100755
--- a/test/sql-tap/index4.test.lua
+++ b/test/sql-tap/index4.test.lua
@@ -1,6 +1,6 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
-test:plan(6)
+test:plan(7)
 
 --!./tcltestrunner.lua
 -- 2011 July 9
@@ -150,20 +150,15 @@ test:do_execsql_test(
         COMMIT;
     ]])
 
--- MUST_WORK_TEST possible reason of failing #2495
-if (0 > 0)
- then
-    test:do_catchsql_test(
-        2.2,
-        [[
-            CREATE UNIQUE INDEX i3 ON t2(x);
-        ]], {
-            -- <2.2>
-            1, "UNIQUE constraint failed: t2.x"
-            -- </2.2>
-        })
-
-end
+test:do_catchsql_test(
+    2.2,
+    [[
+        CREATE UNIQUE INDEX i3 ON t2(x);
+    ]], {
+        -- <2.2>
+        1, "Duplicate key exists in unique index 'I3' in space 'T2'"
+        -- </2.2>
+    })
 
 
 test:finish_test()


New patch:

From 8394c34eab7f945ce3d18bb80027a2f5c195328f Mon Sep 17 00:00:00 2001
Date: Wed, 22 May 2019 17:42:11 +0300
Subject: [PATCH] sql: remove SQL_CONSTRAINT errcode

Removing this error code is part of getting rid of the SQL error
system.

diff --git a/src/box/sql/fk_constraint.c b/src/box/sql/fk_constraint.c
index 08e7f62..6cb41f8 100644
--- a/src/box/sql/fk_constraint.c
+++ b/src/box/sql/fk_constraint.c
@@ -44,7 +44,7 @@
  *
  * Foreign keys in sql come in two flavours: deferred and immediate.
  * If an immediate foreign key constraint is violated,
- * SQL_CONSTRAINT_FOREIGNKEY is returned and the current
+ * -1 is returned and the current
  * statement transaction rolled back. If a
  * deferred foreign key constraint is violated, no action is taken
  * immediately. However if the application attempts to commit the
@@ -110,7 +110,7 @@
  * is that the counter used is stored as part of each individual statement
  * object (struct Vdbe). If, after the statement has run, its immediate
  * constraint counter is greater than zero,
- * it returns SQL_CONSTRAINT_FOREIGNKEY
+ * it returns -1.
  * and the statement transaction is rolled back. An exception is an INSERT
  * statement that inserts a single row only (no triggers). In this case,
  * instead of using a counter, an exception is thrown immediately if the
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 4af65b0..f9f19bf 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -332,7 +332,6 @@ enum sql_ret_code {
 	/** Some kind of disk I/O error occurred. */
 	SQL_IOERR,
 	/** Abort due to constraint violation. */
-	SQL_CONSTRAINT,
 	SQL_TARANTOOL_ERROR,
 	/** sql_step() has another row ready. */
 	SQL_ROW,
@@ -554,9 +553,6 @@ sql_exec(sql *,	/* An open database */
 #define SQL_IOERR_CLOSE             (SQL_IOERR | (16<<8))
 #define SQL_IOERR_DELETE_NOENT      (SQL_IOERR | (23<<8))
 #define SQL_IOERR_GETTEMPPATH       (SQL_IOERR | (25<<8))
-#define SQL_CONSTRAINT_FOREIGNKEY   (SQL_CONSTRAINT | (3<<8))
-#define SQL_CONSTRAINT_NOTNULL      (SQL_CONSTRAINT | (5<<8))
-#define SQL_CONSTRAINT_TRIGGER      (SQL_CONSTRAINT | (7<<8))
 
 /**
  * Subtype of a main type. Allows to do some subtype specific
@@ -3520,17 +3516,16 @@ sql_generate_index_key(struct Parse *parse, struct index *index, int cursor,
  * ----------  ----------  --------------------------------------
  *    any       ROLLBACK   The current transaction is rolled
  *                         back and VDBE stops immediately
- *                         with return code of sql_CONSTRAINT.
+ *                         with an error.
  *
  *    any        ABORT     Back out changes from the current
  *                         command only (do not do a complete
  *                         rollback) then cause VDBE to return
- *                         immediately with sql_CONSTRAINT.
+ *                         immediately with an error.
  *
- *    any        FAIL      VDBE returns immediately with a
- *                         return code of sql_CONSTRAINT. The
- *                         transaction is not rolled back and any
- *                         changes to prior rows are retained.
+ *    any        FAIL      VDBE returns immediately with an error.
+ *                         The transaction is not rolled back and
+ *                         any changes to prior rows are retained.
  *
  *    any       IGNORE     The attempt in insert or update the
  *                         current row is skipped, without
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 918e73c..878724b 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -1065,7 +1065,6 @@ case OP_Halt: {
 	}
 	rc = sqlVdbeHalt(p);
 	assert(rc == 0 || rc == SQL_ERROR);
-	assert(rc == 0 || (p->rc & 0xff) == SQL_CONSTRAINT);
 	rc = p->rc ? SQL_TARANTOOL_ERROR : SQL_DONE;
 	goto vdbe_return;
 }
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 2a9e39b..53e9463 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -2013,8 +2013,7 @@ sqlVdbeCloseStatement(Vdbe * p, int eOp)
  * violations, return SQL_ERROR. Otherwise, 0.
  *
  * If there are outstanding FK violations and this function returns
- * SQL_ERROR, set the result of the VM to SQL_CONSTRAINT_FOREIGNKEY
- * and write an error message to it. Then return SQL_ERROR.
+ * SQL_TARANTOOL_ERROR and set an error.
  */
 int
 sqlVdbeCheckFk(Vdbe * p, int deferred)
@@ -2177,7 +2176,6 @@ sqlVdbeHalt(Vdbe * p)
 						closeCursorsAndFree(p);
 						return SQL_ERROR;
 					}
-					rc = SQL_CONSTRAINT_FOREIGNKEY;
 				} else {
 					/* The auto-commit flag is true, the vdbe program was successful
 					 * or hit an 'OR FAIL' constraint and there are no deferred foreign
@@ -2220,17 +2218,15 @@ sqlVdbeHalt(Vdbe * p)
 		/* If eStatementOp is non-zero, then a statement transaction needs to
 		 * be committed or rolled back. Call sqlVdbeCloseStatement() to
 		 * do so. If this operation returns an error, and the current statement
-		 * error code is 0 or SQL_CONSTRAINT, then promote the
+		 * error code is 0 or -1, then promote the
 		 * current statement error code.
 		 */
 		if (eStatementOp) {
 			rc = sqlVdbeCloseStatement(p, eStatementOp);
 			if (rc) {
 				box_txn_rollback();
-				if (p->rc == 0
-				    || (p->rc & 0xff) == SQL_CONSTRAINT) {
+				if (p->rc == 0)
 					p->rc = rc;
-				}
 				closeCursorsAndFree(p);
 				sqlRollbackAll(p);
 				sqlCloseSavepoints(p);
diff --git a/test/sql-tap/index4.test.lua b/test/sql-tap/index4.test.lua
index d8c6bab..37c0569 100755
--- a/test/sql-tap/index4.test.lua
+++ b/test/sql-tap/index4.test.lua
@@ -1,6 +1,6 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
-test:plan(6)
+test:plan(7)
 
 --!./tcltestrunner.lua
 -- 2011 July 9
@@ -150,20 +150,15 @@ test:do_execsql_test(
         COMMIT;
     ]])
 
--- MUST_WORK_TEST possible reason of failing #2495
-if (0 > 0)
- then
-    test:do_catchsql_test(
-        2.2,
-        [[
-            CREATE UNIQUE INDEX i3 ON t2(x);
-        ]], {
-            -- <2.2>
-            1, "UNIQUE constraint failed: t2.x"
-            -- </2.2>
-        })
-
-end
+test:do_catchsql_test(
+    2.2,
+    [[
+        CREATE UNIQUE INDEX i3 ON t2(x);
+    ]], {
+        -- <2.2>
+        1, "Duplicate key exists in unique index 'I3' in space 'T2'"
+        -- </2.2>
+    })
 
 
 test:finish_test()
diff --git a/test/sql-tap/trigger1.test.lua b/test/sql-tap/trigger1.test.lua
index 38d7c55..bc02d62 100755
--- a/test/sql-tap/trigger1.test.lua
+++ b/test/sql-tap/trigger1.test.lua
@@ -511,7 +511,7 @@ test:do_catchsql_test(
         -- </trigger1-6.3>
     })
 
--- verify_ex_errcode trigger1-6.3b sql_CONSTRAINT_TRIGGER
+-- Verify the previous test has not deleted anything.
 test:do_execsql_test(
     "trigger1-6.4",
     [[
diff --git a/test/sql-tap/unique.test.lua b/test/sql-tap/unique.test.lua
index fbd73a6..9818f90 100755
--- a/test/sql-tap/unique.test.lua
+++ b/test/sql-tap/unique.test.lua
@@ -1,6 +1,6 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
-test:plan(32)
+test:plan(35)
 
 --!./tcltestrunner.lua
 -- 2001 September 27
@@ -20,12 +20,7 @@ test:plan(32)
 -- $Id: unique.test,v 1.9 2009/05/02 15:46:47 drh Exp $
 -- ["set","testdir",[["file","dirname",["argv0"]]]]
 -- ["source",[["testdir"],"\/tester.tcl"]]
--- MUST_WORK_TEST
-if (0 > 0)
- then
-    -- Try to create a table with two primary keys.
-    -- (This is allowed in sql even that it is not valid SQL)
-end
+
 test:do_catchsql_test(
     "unique-1.1",
     [[
@@ -74,7 +69,7 @@ test:do_catchsql_test(
         -- </unique-1.3>
     })
 
--- verify_ex_errcode unique-1.3b sql_CONSTRAINT_PRIMARYKEY
+-- Verify the previous test has not inserted anything.
 test:do_execsql_test(
     "unique-1.4",
     [[
@@ -95,7 +90,7 @@ test:do_catchsql_test(
         -- </unique-1.5>
     })
 
--- verify_ex_errcode unique-1.5b sql_CONSTRAINT_UNIQUE
+-- Verify the previous test has not inserted anything.
 test:do_execsql_test(
     "unique-1.6",
     [[
@@ -171,7 +166,7 @@ test:do_catchsql_test(
         -- </unique-2.3>
     })
 
--- verify_ex_errcode unique-2.3b sql_CONSTRAINT_UNIQUE
+-- Verify the previous test has not inserted anything.
 test:do_catchsql_test(
     "unique-2.4",
     [[
@@ -213,20 +208,16 @@ test:do_catchsql_test(
         -- </unique-2.7>
     })
 
--- MUST_WORK_TEST i2 is checking not only "a" column #2495
-if 0 > 0 then
 test:do_catchsql_test(
     "unique-2.8",
     [[
-        select a from t2;
-        --CREATE UNIQUE INDEX i2 ON t2(a);
+        CREATE UNIQUE INDEX i2 ON t2(a);
     ]], {
         -- <unique-2.8>
-        1, "UNIQUE constraint failed: t2.a"
+        1, "Duplicate key exists in unique index 'I2' in space 'T2'"
         -- </unique-2.8>
     })
 
--- verify_ex_errcode unique-2.8b sql_CONSTRAINT_UNIQUE
 test:do_catchsql_test(
     "unique-2.9",
     [[
@@ -236,7 +227,6 @@ test:do_catchsql_test(
         0
         -- </unique-2.9>
     })
-end
 
 --integrity_check unique-2.10
 -- Test the UNIQUE keyword as used on two or more fields.
@@ -291,7 +281,6 @@ test:do_catchsql_test(
         -- </unique-3.4>
     })
 
--- verify_ex_errcode unique-3.4b sql_CONSTRAINT_UNIQUE
 --integrity_check unique-3.5
 -- Make sure NULLs are distinct as far as the UNIQUE tests are
 -- concerned.
@@ -392,20 +381,16 @@ test:do_catchsql_test(
         -- </unique-4.9>
     })
 
--- MUST_WORK_TEST i4c is checking not only "b" column #2495
-if 0 > 0 then
 test:do_catchsql_test(
     "unique-4.10",
     [[
         CREATE UNIQUE INDEX i4c ON t4(b)
     ]], {
         -- <unique-4.10>
-        1, "UNIQUE constraint failed: t4.b"
+        1, "Duplicate key exists in unique index 'I4C' in space 'T4'"
         -- </unique-4.10>
     })
-end
 
--- verify_ex_errcode unique-4.10b sql_CONSTRAINT_UNIQUE
 --integrity_check unique-4.99
 -- Test the error message generation logic.  In particular, make sure we
 -- do not overflow the static buffer used to generate the error message.
@@ -448,7 +433,4 @@ test:do_catchsql_test(
         -- </unique-5.2>
     })
 
--- verify_ex_errcode unique-5.2b sql_CONSTRAINT_UNIQUE
-
-
 test:finish_test()

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 26/28] sql: cleanup of legacy memory management system
  2019-06-18 20:40       ` Vladislav Shpilevoy
@ 2019-06-19  8:04         ` Mergen Imeev
  0 siblings, 0 replies; 56+ messages in thread
From: Mergen Imeev @ 2019-06-19  8:04 UTC (permalink / raw)
  To: Vladislav Shpilevoy; +Cc: tarantool-patches

On Tue, Jun 18, 2019 at 10:40:09PM +0200, Vladislav Shpilevoy wrote:
> Thanks for the squash. I've found one another part of
> SQL memory subsystem that can be removed. Please, consider
> my review fixes here and on the branch in a separate commit.
> 
Thank you! I squashed this commit.

New patch:

From 20be4d79979c0869ceaab4c465f31b00ff1fa025 Mon Sep 17 00:00:00 2001
From: Nikita Pettik <korablev@tarantool.org>
Date: Sat, 25 May 2019 18:50:33 +0300
Subject: [PATCH] sql: cleanup of legacy memory management system

Follow-up for #4074

diff --git a/src/box/sql/CMakeLists.txt b/src/box/sql/CMakeLists.txt
index 7059b57..1f2a664 100644
--- a/src/box/sql/CMakeLists.txt
+++ b/src/box/sql/CMakeLists.txt
@@ -31,7 +31,6 @@ add_library(sql STATIC
     date.c
     delete.c
     expr.c
-    fault.c
     fk_constraint.c
     func.c
     global.c
@@ -49,7 +48,6 @@ add_library(sql STATIC
     random.c
     resolve.c
     select.c
-    status.c
     tokenize.c
     treeview.c
     trigger.c
diff --git a/src/box/sql/date.c b/src/box/sql/date.c
index 5cb7c85..2e2a71a 100644
--- a/src/box/sql/date.c
+++ b/src/box/sql/date.c
@@ -536,9 +536,6 @@ clearYMD_HMS_TZ(DateTime * p)
  * is available.  This routine returns 0 on success and
  * non-zero on any kind of error.
  *
- * If the sqlGlobalConfig.bLocaltimeFault variable is true then this
- * routine will always fail.
- *
  * EVIDENCE-OF: R-62172-00036 In this implementation, the standard C
  * library function localtime_r() is used to assist in the calculation of
  * local time.
@@ -550,18 +547,10 @@ osLocaltime(time_t * t, struct tm *pTm)
 #if !HAVE_LOCALTIME_R && !HAVE_LOCALTIME_S
 	struct tm *pX;
 	pX = localtime(t);
-
-	if (sqlGlobalConfig.bLocaltimeFault)
-		pX = 0;
-
 	if (pX)
 		*pTm = *pX;
 	rc = pX == 0;
 #else
-
-	if (sqlGlobalConfig.bLocaltimeFault)
-		return 1;
-
 #if HAVE_LOCALTIME_R
 	rc = localtime_r(t, pTm) == 0;
 #else
diff --git a/src/box/sql/fault.c b/src/box/sql/fault.c
deleted file mode 100644
index 62e9924..0000000
--- a/src/box/sql/fault.c
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright 2010-2017, Tarantool AUTHORS, please see AUTHORS file.
- *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * 1. Redistributions of source code must retain the above
- *    copyright notice, this list of conditions and the
- *    following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above
- *    copyright notice, this list of conditions and the following
- *    disclaimer in the documentation and/or other materials
- *    provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- *
- * This file contains code to support the concept of "benign"
- * malloc failures (when the xMalloc() or xRealloc() method of the
- * sql_mem_methods structure fails to allocate a block of memory
- * and returns 0).
- *
- * Most malloc failures are non-benign. After they occur, sql
- * abandons the current operation and returns an error
- * to the user. However, sometimes a fault is not necessarily
- * fatal. For example, if a malloc fails while resizing a hash table, this
- * is completely recoverable simply by not carrying out the resize. The
- * hash table will continue to function normally.  So a malloc failure
- * during a hash table resize is a benign fault.
- */
-
-#include "sqlInt.h"
-
-/*
- * Global variables.
- */
-typedef struct BenignMallocHooks BenignMallocHooks;
-static SQL_WSD struct BenignMallocHooks {
-	void (*xBenignBegin) (void);
-	void (*xBenignEnd) (void);
-} sqlHooks = {
-0, 0};
-
-/* The "wsdHooks" macro will resolve to the appropriate BenignMallocHooks
- * structure.  If writable static data is unsupported on the target,
- * we have to locate the state vector at run-time.  In the more common
- * case where writable static data is supported, wsdHooks can refer directly
- * to the "sqlHooks" state vector declared above.
- */
-#define wsdHooksInit
-#define wsdHooks sqlHooks
-
-/*
- * Register hooks to call when sqlBeginBenignMalloc() and
- * sqlEndBenignMalloc() are called, respectively.
- */
-void
-sqlBenignMallocHooks(void (*xBenignBegin) (void), void (*xBenignEnd) (void)
-    )
-{
-	wsdHooksInit;
-	wsdHooks.xBenignBegin = xBenignBegin;
-	wsdHooks.xBenignEnd = xBenignEnd;
-}
-
-/*
- * This (sqlEndBenignMalloc()) is called by sql code to indicate that
- * subsequent malloc failures are benign. A call to sqlEndBenignMalloc()
- * indicates that subsequent malloc failures are non-benign.
- */
-void
-sqlBeginBenignMalloc(void)
-{
-	wsdHooksInit;
-	if (wsdHooks.xBenignBegin) {
-		wsdHooks.xBenignBegin();
-	}
-}
-
-void
-sqlEndBenignMalloc(void)
-{
-	wsdHooksInit;
-	if (wsdHooks.xBenignEnd) {
-		wsdHooks.xBenignEnd();
-	}
-}
-
diff --git a/src/box/sql/global.c b/src/box/sql/global.c
index 2d937d7..6cadef8 100644
--- a/src/box/sql/global.c
+++ b/src/box/sql/global.c
@@ -137,29 +137,6 @@ const unsigned char sqlCtypeMap[256] = {
 	0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40	/* f8..ff    ........ */
 };
 
-/* EVIDENCE-OF: R-02982-34736 In order to maintain full backwards
- * compatibility for legacy applications, the URI filename capability is
- * disabled by default.
- *
- * EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled
- * using the SQL_USE_URI=1 or SQL_USE_URI=0 compile-time options.
- *
- * EVIDENCE-OF: R-43642-56306 By default, URI handling is globally
- * disabled. The default value may be changed by compiling with the
- * SQL_USE_URI symbol defined.
- */
-#ifndef SQL_USE_URI
-#define  SQL_USE_URI 0
-#endif
-
-/* EVIDENCE-OF: R-38720-18127 The default setting is determined by the
- * SQL_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if
- * that compile-time option is omitted.
- */
-#ifndef SQL_ALLOW_COVERING_INDEX_SCAN
-#define SQL_ALLOW_COVERING_INDEX_SCAN 1
-#endif
-
 /* The minimum PMA size is set to this value multiplied by the database
  * page size in bytes.
  */
@@ -172,35 +149,16 @@ const unsigned char sqlCtypeMap[256] = {
  * the sql library.
  */
 SQL_WSD struct sqlConfig sqlConfig = {
-	SQL_DEFAULT_MEMSTATUS,	/* bMemstat */
-	SQL_USE_URI,		/* bOpenUri */
-	SQL_ALLOW_COVERING_INDEX_SCAN,	/* bUseCis */
-	0x7ffffffe,		/* mxStrlen */
-	0,			/* neverCorrupt */
-	0,			/* nStmtSpill */
-	(void *)0,		/* pHeap */
-	0,			/* nHeap */
-	0, 0,			/* mnHeap, mxHeap */
 	SQL_DEFAULT_MMAP_SIZE,	/* szMmap */
 	SQL_MAX_MMAP_SIZE,	/* mxMmap */
-	(void *)0,		/* pScratch */
-	0,			/* szScratch */
-	0,			/* nScratch */
-	(void *)0,		/* pPage */
-	0,			/* szPage */
-	SQL_DEFAULT_PCACHE_INITSZ,	/* nPage */
-	0,			/* mxParserStack */
-	0,			/* sharedCacheEnabled */
 	SQL_SORTER_PMASZ,	/* szPma */
 	/* All the rest should always be initialized to zero */
 	0,			/* isInit */
 	0,			/* inProgress */
-	0,			/* isMallocInit */
 #ifdef SQL_VDBE_COVERAGE
 	0,			/* xVdbeBranch */
 	0,			/* pVbeBranchArg */
 #endif
-	0,			/* bLocaltimeFault */
 	0x7ffffffe		/* iOnceResetThreshold */
 };
 
diff --git a/src/box/sql/hash.c b/src/box/sql/hash.c
index 5bc8109..36f965b 100644
--- a/src/box/sql/hash.c
+++ b/src/box/sql/hash.c
@@ -149,18 +149,7 @@ rehash(Hash * pH, unsigned int new_size)
 	if (new_size == pH->htsize)
 		return 0;
 #endif
-
-	/* The inability to allocates space for a larger hash table is
-	 * a performance hit but it is not a fatal error.  So mark the
-	 * allocation as a benign. Use sqlMalloc()/memset(0) instead of
-	 * sqlMallocZero() to make the allocation, as sqlMallocZero()
-	 * only zeroes the requested number of bytes whereas this module will
-	 * use the actual amount of space allocated for the hash table (which
-	 * may be larger than the requested amount).
-	 */
-	sqlBeginBenignMalloc();
 	new_ht = (struct _ht *)sqlMalloc(new_size * sizeof(struct _ht));
-	sqlEndBenignMalloc();
 
 	if (new_ht == 0)
 		return 0;
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index d2688e7..59c8315 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -105,11 +105,6 @@ sql_initialize(void)
 	if (sqlGlobalConfig.isInit)
 		return 0;
 
-	if (!sqlGlobalConfig.isMallocInit)
-		sqlMallocInit();
-	if (rc == 0)
-		sqlGlobalConfig.isMallocInit = 1;
-
 	/* If rc is not 0 at this point, then the malloc
 	 * subsystem could not be initialized.
 	 */
diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index 62184f4..d92709b 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -62,23 +62,6 @@ sql_sized_malloc(int nByte)
 }
 
 /*
- * Like free() but works for allocations obtained from sql_sized_malloc()
- * or sql_sized_realloc().
- *
- * For this low-level routine, we already know that pPrior!=0 since
- * cases where pPrior==0 will have been intecepted and dealt with
- * by higher-level routines.
- */
-static void
-sql_sized_free(void *pPrior)
-{
-	sql_int64 *p = (sql_int64 *) pPrior;
-	assert(pPrior != 0);
-	p--;
-	free(p);
-}
-
-/*
  * Report the allocated size of a prior return from sql_sized_malloc()
  * or sql_sized_realloc().
  */
@@ -121,145 +104,6 @@ sql_sized_realloc(void *pPrior, int nByte)
 }
 
 /*
- * Attempt to release up to n bytes of non-essential memory currently
- * held by sql. An example of non-essential memory is memory used to
- * cache database pages that are not currently in use.
- */
-int
-sql_release_memory(int n)
-{
-	/* IMPLEMENTATION-OF: R-34391-24921 The sql_release_memory() routine
-	 * is a no-op returning zero if sql is not compiled with
-	 * SQL_ENABLE_MEMORY_MANAGEMENT.
-	 */
-	UNUSED_PARAMETER(n);
-	return 0;
-}
-
-/*
- * An instance of the following object records the location of
- * each unused scratch buffer.
- */
-typedef struct ScratchFreeslot {
-	struct ScratchFreeslot *pNext;	/* Next unused scratch buffer */
-} ScratchFreeslot;
-
-/*
- * State information local to the memory allocation subsystem.
- */
-static SQL_WSD struct Mem0Global {
-	sql_int64 alarmThreshold;	/* The soft heap limit */
-
-	/*
-	 * Pointers to the end of sqlGlobalConfig.pScratch memory
-	 * (so that a range test can be used to determine if an allocation
-	 * being freed came from pScratch) and a pointer to the list of
-	 * unused scratch allocations.
-	 */
-	void *pScratchEnd;
-	ScratchFreeslot *pScratchFree;
-	u32 nScratchFree;
-
-	/*
-	 * True if heap is nearly "full" where "full" is defined by the
-	 * sql_soft_heap_limit() setting.
-	 */
-	int nearlyFull;
-} mem0 = {
-0, 0, 0, 0, 0};
-
-#define mem0 GLOBAL(struct Mem0Global, mem0)
-
-/*
- * Initialize the memory allocation subsystem.
- */
-void
-sqlMallocInit(void)
-{
-	memset(&mem0, 0, sizeof(mem0));
-	if (sqlGlobalConfig.pScratch && sqlGlobalConfig.szScratch >= 100
-	    && sqlGlobalConfig.nScratch > 0) {
-		int i, n, sz;
-		ScratchFreeslot *pSlot;
-		sz = ROUNDDOWN8(sqlGlobalConfig.szScratch);
-		sqlGlobalConfig.szScratch = sz;
-		pSlot = (ScratchFreeslot *) sqlGlobalConfig.pScratch;
-		n = sqlGlobalConfig.nScratch;
-		mem0.pScratchFree = pSlot;
-		mem0.nScratchFree = n;
-		for (i = 0; i < n - 1; i++) {
-			pSlot->pNext = (ScratchFreeslot *) (sz + (char *)pSlot);
-			pSlot = pSlot->pNext;
-		}
-		pSlot->pNext = 0;
-		mem0.pScratchEnd = (void *)&pSlot[1];
-	} else {
-		mem0.pScratchEnd = 0;
-		sqlGlobalConfig.pScratch = 0;
-		sqlGlobalConfig.szScratch = 0;
-		sqlGlobalConfig.nScratch = 0;
-	}
-	if (sqlGlobalConfig.pPage == 0 || sqlGlobalConfig.szPage < 512
-	    || sqlGlobalConfig.nPage <= 0) {
-		sqlGlobalConfig.pPage = 0;
-		sqlGlobalConfig.szPage = 0;
-	}
-}
-
-/*
- * Return true if the heap is currently under memory pressure - in other
- * words if the amount of heap used is close to the limit set by
- * sql_soft_heap_limit().
- */
-int
-sqlHeapNearlyFull(void)
-{
-	return mem0.nearlyFull;
-}
-
-/*
- * Trigger the alarm
- */
-static void
-sqlMallocAlarm(int nByte)
-{
-	if (mem0.alarmThreshold <= 0)
-		return;
-	sql_release_memory(nByte);
-}
-
-/*
- * Do a memory allocation with statistics and alarms.  Assume the
- * lock is already held.
- */
-static int
-mallocWithAlarm(int n, void **pp)
-{
-	int nFull;
-	void *p;
-	nFull = ROUND8(n);
-	sqlStatusHighwater(SQL_STATUS_MALLOC_SIZE, n);
-	if (mem0.alarmThreshold > 0) {
-		sql_int64 nUsed =
-		    sqlStatusValue(SQL_STATUS_MEMORY_USED);
-		if (nUsed >= mem0.alarmThreshold - nFull) {
-			mem0.nearlyFull = 1;
-			sqlMallocAlarm(nFull);
-		} else {
-			mem0.nearlyFull = 0;
-		}
-	}
-	p = sql_sized_malloc(nFull);
-	if (p) {
-		nFull = sqlMallocSize(p);
-		sqlStatusUp(SQL_STATUS_MEMORY_USED, nFull);
-		sqlStatusUp(SQL_STATUS_MALLOC_COUNT, 1);
-	}
-	*pp = p;
-	return nFull;
-}
-
-/*
  * Allocate memory.  This routine is like sql_malloc() except that it
  * assumes the memory subsystem has already been initialized.
  */
@@ -275,8 +119,6 @@ sqlMalloc(u64 n)
 		 * this amount.  The only way to reach the limit is with sql_malloc()
 		 */
 		p = 0;
-	} else if (sqlGlobalConfig.bMemstat) {
-		mallocWithAlarm((int)n, &p);
 	} else {
 		p = sql_sized_malloc((int)n);
 	}
@@ -311,37 +153,17 @@ sqlMallocSize(void *p)
 	return sql_sized_sizeof(p);
 }
 
-sql_uint64
-sql_msize(void *p)
-{
-	return p ? sql_sized_sizeof(p) : 0;
-}
-
 /*
  * Free memory previously obtained from sqlMalloc().
  */
 void
 sql_free(void *p)
 {
-	if (p == 0)
-		return;		/* IMP: R-49053-54554 */
-	if (sqlGlobalConfig.bMemstat) {
-		sqlStatusDown(SQL_STATUS_MEMORY_USED,
-				  sqlMallocSize(p));
-		sqlStatusDown(SQL_STATUS_MALLOC_COUNT, 1);
-		sql_sized_free(p);
-	} else
-		sql_sized_free(p);
-}
-
-/*
- * Add the size of memory allocation "p" to the count in
- * *db->pnBytesFreed.
- */
-static SQL_NOINLINE void
-measureAllocationSize(sql * db, void *p)
-{
-	*db->pnBytesFreed += sqlMallocSize(p);
+	if (p == NULL)
+		return;
+	sql_int64 *raw_p = (sql_int64 *) p;
+	raw_p--;
+	free(raw_p);
 }
 
 /*
@@ -351,14 +173,7 @@ measureAllocationSize(sql * db, void *p)
 void
 sqlDbFree(sql * db, void *p)
 {
-	if (p == 0)
-		return;
-	if (db) {
-		if (db->pnBytesFreed) {
-			measureAllocationSize(db, p);
-			return;
-		}
-	}
+	(void) db;
 	sql_free(p);
 }
 
@@ -368,7 +183,7 @@ sqlDbFree(sql * db, void *p)
 void *
 sqlRealloc(void *pOld, u64 nBytes)
 {
-	int nOld, nNew, nDiff;
+	int nOld, nNew;
 	void *pNew;
 	if (pOld == 0) {
 		return sqlMalloc(nBytes);	/* IMP: R-04300-56712 */
@@ -383,36 +198,14 @@ sqlRealloc(void *pOld, u64 nBytes)
 	}
 	nOld = sqlMallocSize(pOld);
 	nNew = ROUND8((int)nBytes);
-	if (nOld == nNew) {
+	if (nOld == nNew)
 		pNew = pOld;
-	} else if (sqlGlobalConfig.bMemstat) {
-		sqlStatusHighwater(SQL_STATUS_MALLOC_SIZE, (int)nBytes);
-		nDiff = nNew - nOld;
-		if (nDiff > 0
-		    && sqlStatusValue(SQL_STATUS_MEMORY_USED) >=
-		    mem0.alarmThreshold - nDiff) {
-			sqlMallocAlarm(nDiff);
-		}
+	else
 		pNew = sql_sized_realloc(pOld, nNew);
-		if (pNew == 0 && mem0.alarmThreshold > 0) {
-			sqlMallocAlarm((int)nBytes);
-			pNew = sql_sized_realloc(pOld, nNew);
-		}
-		if (pNew) {
-			nNew = sqlMallocSize(pNew);
-			sqlStatusUp(SQL_STATUS_MEMORY_USED, nNew - nOld);
-		}
-	} else {
-		pNew = sql_sized_realloc(pOld, nNew);
-	}
 	assert(EIGHT_BYTE_ALIGNMENT(pNew));	/* IMP: R-11148-40995 */
 	return pNew;
 }
 
-/*
- * The public interface to sqlRealloc.  Make sure that the memory
- * subsystem is initialized prior to invoking sqlRealloc.
- */
 void *
 sql_realloc64(void *pOld, sql_uint64 n)
 {
@@ -481,7 +274,7 @@ sqlDbMallocRaw(sql * db, u64 n)
 void *
 sqlDbMallocRawNN(sql * db, u64 n)
 {
-	assert(db != NULL && db->pnBytesFreed == NULL);
+	assert(db != NULL);
 	if (db->mallocFailed)
 		return NULL;
 	void *p = sqlMalloc(n);
@@ -576,17 +369,6 @@ sqlDbStrNDup(sql * db, const char *z, u64 n)
 }
 
 /*
- * Call this routine to record the fact that an OOM (out-of-memory) error
- * has happened.  This routine will set db->mallocFailed.
- */
-void
-sqlOomFault(sql * db)
-{
-	if (db->mallocFailed == 0 && db->bBenignMalloc == 0)
-		db->mallocFailed = 1;
-}
-
-/*
  * This routine reactivates the memory allocator and clears the
  * db->mallocFailed flag as necessary.
  *
@@ -601,16 +383,6 @@ sqlOomClear(sql * db)
 }
 
 /*
- * Take actions at the end of an API call to indicate an OOM error
- */
-static SQL_NOINLINE int
-apiOomError(sql * db)
-{
-	sqlOomClear(db);
-	return -1;
-}
-
-/*
  * This function must be called before exiting any API function (i.e.
  * returning control to the user) that has called sql_malloc or
  * sql_realloc.
@@ -623,7 +395,8 @@ sqlApiExit(sql * db, int rc)
 {
 	assert(db != 0);
 	if (db->mallocFailed) {
-		return apiOomError(db);
+		sqlOomClear(db);
+		return -1;
 	}
 	return rc;
 }
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 434a5bd..e4c5843 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -168,15 +168,6 @@
 #define SQL_NOINLINE
 #endif
 
-/*
- * EVIDENCE-OF: R-25715-37072 Memory allocation statistics are enabled by
- * default unless sql is compiled with sql_DEFAULT_MEMSTATUS=0 in
- * which case memory allocation statistics are disabled by default.
- */
-#if !defined(SQL_DEFAULT_MEMSTATUS)
-#define SQL_DEFAULT_MEMSTATUS 1
-#endif
-
 #if defined(SQL_SYSTEM_MALLOC) \
   + defined(SQL_ZERO_MALLOC) > 1
 #error "Two or more of the following compile-time configuration options\
@@ -578,13 +569,6 @@ sql_initialize(void);
 
 #define SQL_DETERMINISTIC    0x800
 
-#define SQL_STATUS_MEMORY_USED          0
-#define SQL_STATUS_MALLOC_SIZE          5
-#define SQL_STATUS_PARSER_STACK         6
-#define SQL_STATUS_PAGECACHE_SIZE       7
-#define SQL_STATUS_SCRATCH_SIZE         8
-#define SQL_STATUS_MALLOC_COUNT         9
-
 int
 sql_create_function_v2(sql * db,
 			   const char *zFunctionName,
@@ -782,16 +766,6 @@ sql_bind_parameter_lindex(sql_stmt * pStmt, const char *zName,
 #endif
 
 /*
- * The default initial allocation for the pagecache when using separate
- * pagecaches for each database connection.  A positive number is the
- * number of pages.  A negative number N translations means that a buffer
- * of -1024*N bytes is allocated and used for as many pages as it will hold.
- */
-#ifndef SQL_DEFAULT_PCACHE_INITSZ
-#define SQL_DEFAULT_PCACHE_INITSZ 100
-#endif
-
-/*
  * GCC does not define the offsetof() macro so we'll have to do it
  * ourselves.
  */
@@ -1133,7 +1107,6 @@ struct sql {
 	u16 dbOptFlags;		/* Flags to enable/disable optimizations */
 	u8 enc;			/* Text encoding */
 	u8 mallocFailed;	/* True if we have seen a malloc failure */
-	u8 bBenignMalloc;	/* Do not require OOMs if true */
 	u8 dfltLockMode;	/* Default locking-mode for attached dbs */
 	u8 mTrace;		/* zero or more sql_TRACE flags */
 	u32 magic;		/* Magic number for detect library misuse */
@@ -1162,7 +1135,6 @@ struct sql {
 	void (*xUpdateCallback) (void *, int, const char *, const char *,
 				 sql_int64);
 	Hash aFunc;		/* Hash table of connection functions */
-	int *pnBytesFreed;	/* If not NULL, increment this in DbFree() */
 };
 
 /*
@@ -1223,11 +1195,7 @@ struct sql {
  * than being distinct from one another.
  */
 #define SQL_MAGIC_OPEN     0xa029a697	/* Database is open */
-#define SQL_MAGIC_CLOSED   0x9f3c2d33	/* Database is closed */
-#define SQL_MAGIC_SICK     0x4b771290	/* Error and awaiting close */
 #define SQL_MAGIC_BUSY     0xf03b7906	/* Database currently in use */
-#define SQL_MAGIC_ERROR    0xb5357930	/* An sql_MISUSE error occurred */
-#define SQL_MAGIC_ZOMBIE   0x64cffc7f	/* Close with last statement close */
 
 /**
  * SQL type definition. Now it is an alias to type, but in
@@ -2563,32 +2531,14 @@ struct StrAccum {
  * This structure also contains some state information.
  */
 struct sqlConfig {
-	int bMemstat;		/* True to enable memory status */
-	int bOpenUri;		/* True to interpret filenames as URIs */
-	int bUseCis;		/* Use covering indices for full-scans */
-	int mxStrlen;		/* Maximum string length */
-	int neverCorrupt;	/* Database is always well-formed */
-	int nStmtSpill;		/* Stmt-journal spill-to-disk threshold */
-	void *pHeap;		/* Heap storage space */
-	int nHeap;		/* Size of pHeap[] */
-	int mnReq, mxReq;	/* Min and max heap requests sizes */
 	sql_int64 szMmap;	/* mmap() space per open file */
 	sql_int64 mxMmap;	/* Maximum value for szMmap */
-	void *pScratch;		/* Scratch memory */
-	int szScratch;		/* Size of each scratch buffer */
-	int nScratch;		/* Number of scratch buffers */
-	void *pPage;		/* Page cache memory */
-	int szPage;		/* Size of each page in pPage[] */
-	int nPage;		/* Number of pages in pPage[] */
-	int mxParserStack;	/* maximum depth of the parser stack */
-	int sharedCacheEnabled;	/* true if shared-cache mode enabled */
 	u32 szPma;		/* Maximum Sorter PMA size */
 	/* The above might be initialized to non-zero.  The following need to always
 	 * initially be zero, however.
 	 */
 	int isInit;		/* True after initialization has finished */
 	int inProgress;		/* True while initialization in progress */
-	int isMallocInit;	/* True after malloc is initialized */
 #ifdef SQL_VDBE_COVERAGE
 	/* The following callback (if not NULL) is invoked on every VDBE branch
 	 * operation.  Set the callback using sql_TESTCTRL_VDBE_COVERAGE.
@@ -2596,7 +2546,6 @@ struct sqlConfig {
 	void (*xVdbeBranch) (void *, int iSrcLine, u8 eThis, u8 eMx);	/* Callback */
 	void *pVdbeBranchArg;	/* 1st argument */
 #endif
-	int bLocaltimeFault;	/* True to fail localtime() calls */
 	int iOnceResetThreshold;	/* When to reset OP_Once counters */
 };
 
@@ -2685,7 +2634,6 @@ int sqlStrICmp(const char *, const char *);
 unsigned sqlStrlen30(const char *);
 #define sqlStrNICmp sql_strnicmp
 
-void sqlMallocInit(void);
 void *sqlMalloc(u64);
 void *sqlMallocZero(u64);
 void *sqlDbMallocZero(sql *, u64);
@@ -2698,8 +2646,6 @@ void *sqlDbReallocOrFree(sql *, void *, u64);
 void *sqlDbRealloc(sql *, void *, u64);
 void sqlDbFree(sql *, void *);
 int sqlMallocSize(void *);
-void sqlBenignMallocHooks(void (*)(void), void (*)(void));
-int sqlHeapNearlyFull(void);
 
 /*
  * On systems with ample stack space and that support alloca(), make
@@ -2719,11 +2665,6 @@ int sqlHeapNearlyFull(void);
 #define sqlStackFree(D,P)       sqlDbFree(D,P)
 #endif
 
-sql_int64 sqlStatusValue(int);
-void sqlStatusUp(int, int);
-void sqlStatusDown(int, int);
-void sqlStatusHighwater(int, int);
-
 int sqlIsNaN(double);
 
 /*
@@ -4348,7 +4289,14 @@ int sqlCreateFunc(sql *, const char *, enum field_type,
 		      void (*)(sql_context *, int, sql_value **),
 		      void (*)(sql_context *),
 		      FuncDestructor * pDestructor);
-void sqlOomFault(sql *);
+
+/** Set OOM error flag. */
+static inline void
+sqlOomFault(struct sql *db)
+{
+	db->mallocFailed = 1;
+}
+
 void sqlOomClear(sql *);
 int sqlApiExit(sql * db, int);
 
@@ -4531,13 +4479,6 @@ bool
 fk_constraint_is_required(struct space *space, const int *changes);
 
 /*
- * The interface to the code in fault.c used for identifying "benign"
- * malloc failures.
- */
-void sqlBeginBenignMalloc(void);
-void sqlEndBenignMalloc(void);
-
-/*
  * Allowed return values from sqlFindInIndex()
  */
 #define IN_INDEX_EPH          2	/* Search an ephemeral b-tree */
diff --git a/src/box/sql/status.c b/src/box/sql/status.c
deleted file mode 100644
index 515274a..0000000
--- a/src/box/sql/status.c
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright 2010-2017, Tarantool AUTHORS, please see AUTHORS file.
- *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * 1. Redistributions of source code must retain the above
- *    copyright notice, this list of conditions and the
- *    following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above
- *    copyright notice, this list of conditions and the following
- *    disclaimer in the documentation and/or other materials
- *    provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- *
- * This module implements the sql_status() interface and related
- * functionality.
- */
-#include "sqlInt.h"
-#include "vdbeInt.h"
-/*
- * Variables in which to record status information.
- */
-#if SQL_PTRSIZE>4
-typedef sql_int64 sqlStatValueType;
-#else
-typedef u32 sqlStatValueType;
-#endif
-typedef struct sqlStatType sqlStatType;
-static SQL_WSD struct sqlStatType {
-	sqlStatValueType nowValue[10];	/* Current value */
-	sqlStatValueType mxValue[10];	/* Maximum value */
-} sqlStat = { {
-0,}, {
-0,}};
-
-
-/* The "wsdStat" macro will resolve to the status information
- * state vector. In the common case where writable static data is
- * supported, wsdStat can refer directly  to the "sqlStat" state
- * vector declared above.
- */
-#define wsdStatInit
-#define wsdStat sqlStat
-
-/*
- * Return the current value of a status parameter.
- */
-sql_int64
-sqlStatusValue(int op)
-{
-	wsdStatInit;
-	assert(op >= 0 && op < ArraySize(wsdStat.nowValue));
-
-	return wsdStat.nowValue[op];
-}
-
-/*
- * Add N to the value of a status record.
- *
- * The StatusUp() routine can accept positive or negative values for N.
- * The value of N is added to the current status value and the high-water
- * mark is adjusted if necessary.
- *
- * The StatusDown() routine lowers the current value by N.  The highwater
- * mark is unchanged.  N must be non-negative for StatusDown().
- */
-void
-sqlStatusUp(int op, int N)
-{
-	wsdStatInit;
-	assert(op >= 0 && op < ArraySize(wsdStat.nowValue));
-
-	wsdStat.nowValue[op] += N;
-	if (wsdStat.nowValue[op] > wsdStat.mxValue[op]) {
-		wsdStat.mxValue[op] = wsdStat.nowValue[op];
-	}
-}
-
-void
-sqlStatusDown(int op, int N)
-{
-	wsdStatInit;
-	assert(N >= 0);
-
-	assert(op >= 0 && op < ArraySize(wsdStat.nowValue));
-	wsdStat.nowValue[op] -= N;
-}
-
-/*
- * Adjust the highwater mark if necessary.
- */
-void
-sqlStatusHighwater(int op, int X)
-{
-	sqlStatValueType newValue;
-	wsdStatInit;
-	assert(X >= 0);
-	newValue = (sqlStatValueType) X;
-	assert(op >= 0 && op < ArraySize(wsdStat.nowValue));
-
-	assert(op == SQL_STATUS_MALLOC_SIZE
-	       || op == SQL_STATUS_PAGECACHE_SIZE
-	       || op == SQL_STATUS_SCRATCH_SIZE
-	       || op == SQL_STATUS_PARSER_STACK);
-	if (newValue > wsdStat.mxValue[op]) {
-		wsdStat.mxValue[op] = newValue;
-	}
-}
diff --git a/src/box/sql/tokenize.c b/src/box/sql/tokenize.c
index ea364de..9fa069d 100644
--- a/src/box/sql/tokenize.c
+++ b/src/box/sql/tokenize.c
@@ -430,7 +430,7 @@ sql_token(const char *z, int *type, bool *is_reserved)
 static void
 parser_space_delete(struct sql *db, struct space *space)
 {
-	if (space == NULL || db == NULL || db->pnBytesFreed == 0)
+	if (space == NULL || db == NULL)
 		return;
 	assert(space->def->opts.is_ephemeral);
 	for (uint32_t i = 0; i < space->index_count; ++i)
@@ -514,11 +514,6 @@ sqlRunParser(Parse * pParse, const char *zSql)
 		}
 	}
 	pParse->zTail = &zSql[i];
-#ifdef YYTRACKMAXSTACKDEPTH
-	sqlStatusHighwater(SQL_STATUS_PARSER_STACK,
-			       sqlParserStackPeak(pEngine)
-	    );
-#endif				/* YYDEBUG */
 	sqlParserFree(pEngine, sql_free);
 	if (db->mallocFailed)
 		pParse->is_aborted = true;
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 8d512d3..c8887f9 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -226,10 +226,6 @@ allocateCursor(
 	 *     different sized allocations. Memory cells provide growable
 	 *     allocations.
 	 *
-	 *   * When using ENABLE_MEMORY_MANAGEMENT, memory cell buffers can
-	 *     be freed lazily via the sql_release_memory() API. This
-	 *     minimizes the number of malloc calls made by the system.
-	 *
 	 * The memory cell for cursor 0 is aMem[0]. The rest are allocated from
 	 * the top of the register space.  Cursor 1 is at Mem[p->nMem-1].
 	 * Cursor 2 is at Mem[p->nMem-2]. And so forth.
@@ -751,7 +747,6 @@ int sqlVdbeExec(Vdbe *p)
 	assert(p->explain==0);
 	p->pResultSet = 0;
 #ifdef SQL_DEBUG
-	sqlBeginBenignMalloc();
 	if (p->pc == 0 &&
 	    (p->sql_flags & (SQL_VdbeListing|SQL_VdbeEQP|SQL_VdbeTrace)) != 0) {
 		int i;
@@ -775,7 +770,6 @@ int sqlVdbeExec(Vdbe *p)
 		if ((p->sql_flags & SQL_VdbeTrace) != 0)
 			printf("VDBE Trace:\n");
 	}
-	sqlEndBenignMalloc();
 #endif
 	for(pOp=&aOp[p->pc]; 1; pOp++) {
 		/* Errors are detected by individual opcodes, with an immediate
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index bc5a14a..364f7ed 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -664,17 +664,6 @@ freeEphemeralFunction(sql * db, FuncDef * pDef)
 
 static void vdbeFreeOpArray(sql *, Op *, int);
 
-/*
- * Delete a P4 value if necessary.
- */
-static SQL_NOINLINE void
-freeP4Mem(sql * db, Mem * p)
-{
-	if (p->szMalloc)
-		sqlDbFree(db, p->zMalloc);
-	sqlDbFree(db, p);
-}
-
 static SQL_NOINLINE void
 freeP4FuncCtx(sql * db, sql_context * p)
 {
@@ -705,14 +694,9 @@ freeP4(sql * db, int p4type, void *p4)
 			freeEphemeralFunction(db, (FuncDef *) p4);
 			break;
 		}
-	case P4_MEM:{
-			if (db->pnBytesFreed == 0) {
-				sqlValueFree((sql_value *) p4);
-			} else {
-				freeP4Mem(db, (Mem *) p4);
-			}
-			break;
-		}
+	case P4_MEM:
+		sqlValueFree((sql_value *) p4);
+		break;
 	}
 }
 
@@ -1305,13 +1289,6 @@ releaseMemArray(Mem * p, int N)
 	if (p && N) {
 		Mem *pEnd = &p[N];
 		sql *db = p->db;
-		if (db->pnBytesFreed) {
-			do {
-				if (p->szMalloc)
-					sqlDbFree(db, p->zMalloc);
-			} while ((++p) < pEnd);
-			return;
-		}
 		do {
 			assert((&p[1]) == pEnd || p[0].db == p[1].db);
 			assert(sqlVdbeCheckMemInvariants(p));
diff --git a/src/box/sql/vdbesort.c b/src/box/sql/vdbesort.c
index 5873fab..7091a99 100644
--- a/src/box/sql/vdbesort.c
+++ b/src/box/sql/vdbesort.c
@@ -819,43 +819,32 @@ sqlVdbeSorterInit(sql * db,	/* Database connection (for malloc()) */
 
 	pSorter = (VdbeSorter *) sqlDbMallocZero(db, sizeof(VdbeSorter));
 	pCsr->uc.pSorter = pSorter;
-	if (pSorter == 0) {
+	if (pSorter == 0)
+		return -1;
+
+	pSorter->key_def = pCsr->key_def;
+	pSorter->pgsz = pgsz = 1024;
+	pSorter->db = db;
+	pSorter->aTask.pSorter = pSorter;
+
+	/* Cache size in bytes */
+	i64 mxCache;
+	u32 szPma = sqlGlobalConfig.szPma;
+	pSorter->mnPmaSize = szPma * pgsz;
+
+	mxCache = SQL_DEFAULT_CACHE_SIZE;
+	mxCache = mxCache * -1024;
+	mxCache = MIN(mxCache, SQL_MAX_PMASZ);
+	pSorter->mxPmaSize = MAX(pSorter->mnPmaSize, (int)mxCache);
+	assert(pSorter->iMemory == 0);
+	pSorter->nMemory = pgsz;
+	pSorter->list.aMemory = (u8 *) sqlMalloc(pgsz);
+	if (!pSorter->list.aMemory)
 		rc = -1;
-	} else {
-		pSorter->key_def = pCsr->key_def;
-		pSorter->pgsz = pgsz = 1024;
-		pSorter->db = db;
-		pSorter->aTask.pSorter = pSorter;
-
-		i64 mxCache;	/* Cache size in bytes */
-		u32 szPma = sqlGlobalConfig.szPma;
-		pSorter->mnPmaSize = szPma * pgsz;
-
-		mxCache = SQL_DEFAULT_CACHE_SIZE;
-		mxCache = mxCache * -1024;
-		mxCache = MIN(mxCache, SQL_MAX_PMASZ);
-		pSorter->mxPmaSize =
-		    MAX(pSorter->mnPmaSize, (int)mxCache);
-
-		/* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
-		 * scratch memory using SQL_CONFIG_SCRATCH, sql avoids unnecessary
-		 * large heap allocations.
-		 */
-		if (sqlGlobalConfig.pScratch == 0) {
-			assert(pSorter->iMemory == 0);
-			pSorter->nMemory = pgsz;
-			pSorter->list.aMemory =
-			    (u8 *) sqlMalloc(pgsz);
-			if (!pSorter->list.aMemory)
-				rc = -1;
-		}
 
-		if (pCsr->key_def->part_count < 13
-		    && (pCsr->key_def->parts[0].coll == NULL)) {
-			pSorter->typeMask =
-			    SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT;
-		}
-	}
+	if (pCsr->key_def->part_count < 13 &&
+	    pCsr->key_def->parts[0].coll == NULL)
+		pSorter->typeMask = SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT;
 
 	return rc;
 }
@@ -1486,9 +1475,6 @@ sqlVdbeSorterWrite(const VdbeCursor * pCsr,	/* Sorter cursor */
 	 *
 	 *   * The total memory allocated for the in-memory list is greater
 	 *     than (page-size * cache-size), or
-	 *
-	 *   * The total memory allocated for the in-memory list is greater
-	 *     than (page-size * 10) and sqlHeapNearlyFull() returns true.
 	 */
 	nReq = pVal->n + sizeof(SorterRecord);
 	nPMA = pVal->n + sqlVarintLen(pVal->n);
@@ -1497,10 +1483,7 @@ sqlVdbeSorterWrite(const VdbeCursor * pCsr,	/* Sorter cursor */
 			bFlush = pSorter->iMemory
 			    && (pSorter->iMemory + nReq) > pSorter->mxPmaSize;
 		} else {
-			bFlush = ((pSorter->list.szPMA > pSorter->mxPmaSize)
-				  || (pSorter->list.szPMA > pSorter->mnPmaSize
-				      && sqlHeapNearlyFull())
-			    );
+			bFlush = ((pSorter->list.szPMA > pSorter->mxPmaSize));
 		}
 		if (bFlush) {
 			rc = vdbeSorterFlushPMA(pSorter);

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 00/28] sql: Remove SQL error system
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (29 preceding siblings ...)
  2019-06-13 22:24 ` Vladislav Shpilevoy
@ 2019-06-19 19:11 ` Vladislav Shpilevoy
  2019-06-20 16:08 ` Kirill Yukhin
  31 siblings, 0 replies; 56+ messages in thread
From: Vladislav Shpilevoy @ 2019-06-19 19:11 UTC (permalink / raw)
  To: Kirill Yukhin; +Cc: imeevma, tarantool-patches

LGTM.

On 10/06/2019 15:56, imeevma@tarantool.org wrote:
> This patch-set removes unused and unnecessary code of SQL error
> system.
> 
> Mergen Imeev (26):
>   sql: remove field zErrMsg from struct Vdbe
>   sql: remove field pErr from struct sql
>   sql: remove field errCode from struct sql
>   sql: remove sqlError() and remove sqlErrorWithMsg()
>   sql: remove unused functions of SQL error system
>   sql: disable lookaside system
>   sql: remove SQL_OK error/status code
>   sql: remove SQL_PERM, SQL_WARNING, SQL_ABORT errcodes
>   sql: remove SQL_CANTOPEN errcode
>   sql: remove SQL_NOTFOUND error/status code
>   sql: remove SQL_LOCKED errcode
>   sql: remove SQL_FULL errcode
>   sql: remove SQL_MISUSE errcode
>   sql: remove SQL_RANGE errcode
>   sql: remove SQL_SCHEMA errcode
>   sql: remove SQL_TOOBIG errcode
>   sql: remove SQL_BUSY errcode
>   sql: remove SQL_CONSTRAINT errcode
>   sql: remove SQL_ERROR errcode
>   sql: remove SQL_NOMEM errcode
>   sql: remove SQL_IOERR errcode
>   sql: remove SQL_TARANTOOL_ERROR errcode
>   sql: remove field errMask from struct sql
>   sql: replace rc by is_aborted in struct VDBE
>   sql: remove sql_log()
>   sql: remove function sqlApiExit()
> 
> Nikita Pettik (2):
>   sql: cleanup of legacy memory management system
>   sql: make function return void instead of int
> 
>  src/box/bind.c                |  37 +---
>  src/box/ck_constraint.c       |   4 +-
>  src/box/execute.c             |   6 +-
>  src/box/lua/lua_sql.c         |   2 +-
>  src/box/sql.c                 | 104 ++++------
>  src/box/sql/analyze.c         |   2 +-
>  src/box/sql/build.c           |   6 +-
>  src/box/sql/cursor.c          |   4 +-
>  src/box/sql/date.c            |  14 +-
>  src/box/sql/expr.c            |   7 +-
>  src/box/sql/fault.c           |   4 +-
>  src/box/sql/fk_constraint.c   |   8 +-
>  src/box/sql/func.c            |  16 +-
>  src/box/sql/global.c          |   3 -
>  src/box/sql/insert.c          |   9 +-
>  src/box/sql/legacy.c          |  21 +-
>  src/box/sql/main.c            | 266 ++++---------------------
>  src/box/sql/malloc.c          | 445 +-----------------------------------------
>  src/box/sql/os.c              |  14 +-
>  src/box/sql/os_unix.c         | 281 ++++++++------------------
>  src/box/sql/prepare.c         |  73 ++-----
>  src/box/sql/printf.c          |  36 +---
>  src/box/sql/resolve.c         |   3 +-
>  src/box/sql/select.c          |  61 +++---
>  src/box/sql/sqlInt.h          | 173 +---------------
>  src/box/sql/status.c          | 182 -----------------
>  src/box/sql/tarantoolInt.h    |  11 +-
>  src/box/sql/tokenize.c        |   5 -
>  src/box/sql/trigger.c         |   2 +-
>  src/box/sql/util.c            | 162 ---------------
>  src/box/sql/vdbe.c            | 111 ++++-------
>  src/box/sql/vdbeInt.h         |  13 +-
>  src/box/sql/vdbeapi.c         | 357 +++++++++------------------------
>  src/box/sql/vdbeaux.c         | 217 ++++++--------------
>  src/box/sql/vdbemem.c         | 120 ++++++------
>  src/box/sql/vdbesort.c        | 274 ++++++++++++--------------
>  src/box/sql/where.c           | 108 +++++-----
>  src/box/sql/whereexpr.c       |   3 +-
>  test/sql/bind.result          |   8 +
>  test/sql/bind.test.lua        |   3 +
>  test/sql/func-recreate.result |   3 +-
>  41 files changed, 726 insertions(+), 2452 deletions(-)
> 

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [tarantool-patches] Re: [PATCH v1 00/28] sql: Remove SQL error system
  2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
                   ` (30 preceding siblings ...)
  2019-06-19 19:11 ` Vladislav Shpilevoy
@ 2019-06-20 16:08 ` Kirill Yukhin
  31 siblings, 0 replies; 56+ messages in thread
From: Kirill Yukhin @ 2019-06-20 16:08 UTC (permalink / raw)
  To: tarantool-patches; +Cc: v.shpilevoy

Hello,

On 10 Jun 16:56, imeevma@tarantool.org wrote:
> This patch-set removes unused and unnecessary code of SQL error
> system.
> 
> Mergen Imeev (26):
>   sql: remove field zErrMsg from struct Vdbe
>   sql: remove field pErr from struct sql
>   sql: remove field errCode from struct sql
>   sql: remove sqlError() and remove sqlErrorWithMsg()
>   sql: remove unused functions of SQL error system
>   sql: disable lookaside system
>   sql: remove SQL_OK error/status code
>   sql: remove SQL_PERM, SQL_WARNING, SQL_ABORT errcodes
>   sql: remove SQL_CANTOPEN errcode
>   sql: remove SQL_NOTFOUND error/status code
>   sql: remove SQL_LOCKED errcode
>   sql: remove SQL_FULL errcode
>   sql: remove SQL_MISUSE errcode
>   sql: remove SQL_RANGE errcode
>   sql: remove SQL_SCHEMA errcode
>   sql: remove SQL_TOOBIG errcode
>   sql: remove SQL_BUSY errcode
>   sql: remove SQL_CONSTRAINT errcode
>   sql: remove SQL_ERROR errcode
>   sql: remove SQL_NOMEM errcode
>   sql: remove SQL_IOERR errcode
>   sql: remove SQL_TARANTOOL_ERROR errcode
>   sql: remove field errMask from struct sql
>   sql: replace rc by is_aborted in struct VDBE
>   sql: remove sql_log()
>   sql: remove function sqlApiExit()
> 
> Nikita Pettik (2):
>   sql: cleanup of legacy memory management system
>   sql: make function return void instead of int

I've checked your patchset into master.

--
Regards, Kirill Yukhin

^ permalink raw reply	[flat|nested] 56+ messages in thread

end of thread, other threads:[~2019-06-20 16:08 UTC | newest]

Thread overview: 56+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-10 13:56 [tarantool-patches] [PATCH v1 00/28] sql: Remove SQL error system imeevma
2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 01/28] sql: remove field zErrMsg from struct Vdbe imeevma
2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 02/28] sql: remove field pErr from struct sql imeevma
2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 03/28] sql: remove field errCode " imeevma
2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 04/28] sql: remove sqlError() and remove sqlErrorWithMsg() imeevma
2019-06-13 22:25   ` [tarantool-patches] " Vladislav Shpilevoy
2019-06-15  9:45     ` Mergen Imeev
2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 05/28] sql: remove unused functions of SQL error system imeevma
2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 06/28] sql: disable lookaside system imeevma
2019-06-13 22:25   ` [tarantool-patches] " Vladislav Shpilevoy
2019-06-15  9:47     ` Mergen Imeev
2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 07/28] sql: remove SQL_OK error/status code imeevma
2019-06-13 22:24   ` [tarantool-patches] " Vladislav Shpilevoy
2019-06-15  9:52     ` Mergen Imeev
2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 08/28] sql: remove SQL_PERM, SQL_WARNING, SQL_ABORT errcodes imeevma
2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 09/28] sql: remove SQL_CANTOPEN errcode imeevma
2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 10/28] sql: remove SQL_NOTFOUND error/status code imeevma
2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 11/28] sql: remove SQL_LOCKED errcode imeevma
2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 12/28] sql: remove SQL_FULL errcode imeevma
2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 13/28] sql: remove SQL_MISUSE errcode imeevma
2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 14/28] sql: remove SQL_RANGE errcode imeevma
2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 15/28] sql: remove SQL_SCHEMA errcode imeevma
2019-06-13 22:24   ` [tarantool-patches] " Vladislav Shpilevoy
2019-06-15  9:55     ` Mergen Imeev
2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 16/28] sql: remove SQL_TOOBIG errcode imeevma
2019-06-13 22:24   ` [tarantool-patches] " Vladislav Shpilevoy
2019-06-15  9:57     ` Mergen Imeev
2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 17/28] sql: remove SQL_BUSY errcode imeevma
2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 18/28] sql: remove SQL_CONSTRAINT errcode imeevma
2019-06-13 22:24   ` [tarantool-patches] " Vladislav Shpilevoy
2019-06-15 10:00     ` Mergen Imeev
2019-06-18 20:40       ` Vladislav Shpilevoy
2019-06-19  8:02         ` Mergen Imeev
2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 19/28] sql: remove SQL_ERROR errcode imeevma
2019-06-10 13:56 ` [tarantool-patches] [PATCH v1 20/28] sql: remove SQL_NOMEM errcode imeevma
2019-06-13 22:24   ` [tarantool-patches] " Vladislav Shpilevoy
2019-06-15 10:01     ` Mergen Imeev
2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 21/28] sql: remove SQL_IOERR errcode imeevma
2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 22/28] sql: remove SQL_TARANTOOL_ERROR errcode imeevma
2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 23/28] sql: remove field errMask from struct sql imeevma
2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 24/28] sql: replace rc by is_aborted in struct VDBE imeevma
2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 25/28] sql: remove sql_log() imeevma
2019-06-13 22:24   ` [tarantool-patches] " Vladislav Shpilevoy
2019-06-15 10:02     ` Mergen Imeev
2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 26/28] sql: cleanup of legacy memory management system imeevma
2019-06-13 22:24   ` [tarantool-patches] " Vladislav Shpilevoy
2019-06-15 10:04     ` Mergen Imeev
2019-06-18 20:40       ` Vladislav Shpilevoy
2019-06-19  8:04         ` Mergen Imeev
2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 27/28] sql: make function return void instead of int imeevma
2019-06-10 13:57 ` [tarantool-patches] [PATCH v1 28/28] sql: remove function sqlApiExit() imeevma
2019-06-11 10:00 ` [tarantool-patches] Re: [PATCH v1 00/28] sql: Remove SQL error system Imeev Mergen
2019-06-13 22:24 ` Vladislav Shpilevoy
2019-06-15 10:08   ` Mergen Imeev
2019-06-19 19:11 ` Vladislav Shpilevoy
2019-06-20 16:08 ` Kirill Yukhin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox