[tarantool-patches] Re: [PATCH v1 26/28] sql: cleanup of legacy memory management system

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Fri Jun 14 01:24:45 MSK 2019


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




More information about the Tarantool-patches mailing list