[tarantool-patches] Re: [PATCH v1 06/28] sql: disable lookaside system

Mergen Imeev imeevma at tarantool.org
Sat Jun 15 12:47:11 MSK 2019


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()
-





More information about the Tarantool-patches mailing list