[Tarantool-patches] [PATCH v5 07/52] sql: remove unused MEM-related functions

imeevma at tarantool.org imeevma at tarantool.org
Fri Apr 9 19:59:49 MSK 2021


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

On 30.03.2021 01:58, Vladislav Shpilevoy wrote:
> Thanks for the patch!
>
> On 23.03.2021 10:35, Mergen Imeev via Tarantool-patches wrote:
>> This patch removes remove unused MEM-related functions.
>
> You can simply omit commit message when it is the same as the
> title.
Fixed, removed the commit message.


New patch:

commit a3cd1dea89dae108586c1cf3cd0a3cbc9badfbc4
Author: Mergen Imeev <imeevma at gmail.com>
Date:   Tue Mar 2 10:58:15 2021 +0300

    sql: remove unused MEM-related functions
    
    Part of #5818

diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index c1a42fc2f..dd8163f5e 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -474,10 +474,6 @@ sql_column_text(sql_stmt *,
 enum mp_type
 sql_column_type(sql_stmt *stmt, int field_no);
 
-sql_value *
-sql_column_value(sql_stmt *,
-        int iCol);
-
 /*
  * Terminate the current execution of an SQL statement and reset
  * it back to its starting state so that it can be reused.
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 775bce96f..a4a8c45f2 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -181,14 +181,6 @@ vdbeTakeBranch(int iSrcLine, u8 I, u8 M)
 }
 #endif
 
-/*
- * Convert the given register into a string if it isn't one
- * already. Return non-zero if a malloc() fails.
- */
-#define Stringify(P)           \
- if(((P)->flags&(MEM_Str|MEM_Blob))==0 && sqlVdbeMemStringify(P)) \
- { goto no_mem; }
-
 /*
  * An ephemeral string value (signified by the MEM_Ephem flag) contains
  * a pointer to a dynamically allocated string where some other entity
diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h
index b2d4f27c1..541b93d30 100644
--- a/src/box/sql/vdbeInt.h
+++ b/src/box/sql/vdbeInt.h
@@ -333,8 +333,6 @@ int sqlVdbeList(Vdbe *);
 
 int sqlVdbeHalt(Vdbe *);
 
-int sqlVdbeMemFromBtree(BtCursor *, u32, u32, Mem *);
-
 /**
  * In terms of VDBE memory cell type, _BIN, _ARRAY and _MAP
  * messagepacks are stored as binary string (i.e. featuring
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 24fa99f17..671338361 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -101,63 +101,12 @@ sql_stmt_reset(sql_stmt *pStmt)
  return rc;
 }
 
-/*
- * Set all the parameters in the compiled SQL statement to NULL.
- */
-int
-sql_clear_bindings(sql_stmt * pStmt)
-{
- int i;
- int rc = 0;
- Vdbe *p = (Vdbe *) pStmt;
- for (i = 0; i < p->nVar; i++) {
-   sqlVdbeMemRelease(&p->aVar[i]);
-   p->aVar[i].flags = MEM_Null;
- }
- return rc;
-}
-
 bool
 sql_metadata_is_full()
 {
  return current_session()->sql_flags & SQL_FullMetadata;
 }
 
-/* Make a copy of an sql_value object
- */
-sql_value *
-sql_value_dup(const sql_value * pOrig)
-{
- sql_value *pNew;
- if (pOrig == 0)
-   return 0;
- pNew = sql_malloc(sizeof(*pNew));
- if (pNew == 0)
-   return 0;
- memset(pNew, 0, sizeof(*pNew));
- memcpy(pNew, pOrig, MEMCELLSIZE);
- pNew->flags &= ~MEM_Dyn;
- pNew->db = 0;
- if (pNew->flags & (MEM_Str | MEM_Blob)) {
-   pNew->flags &= ~(MEM_Static | MEM_Dyn);
-   pNew->flags |= MEM_Ephem;
-   if (sqlVdbeMemMakeWriteable(pNew) != 0) {
-     sqlValueFree(pNew);
-     pNew = 0;
-   }
- }
- return pNew;
-}
-
-/* Destroy an sql_value object previously obtained from
- * sql_value_dup().
- */
-void
-sql_value_free(sql_value * pOld)
-{
- sqlValueFree(pOld);
-}
-
 /**************************** sql_result_  ******************************
  * The following routines are used by user-defined functions to specify
  * the function result.
@@ -566,17 +515,6 @@ sql_column_text(sql_stmt * pStmt, int i)
  return sql_value_text(columnMem(pStmt, i));
 }
 
-sql_value *
-sql_column_value(sql_stmt * pStmt, int i)
-{
- Mem *pOut = columnMem(pStmt, i);
- if (pOut->flags & MEM_Static) {
-   pOut->flags &= ~MEM_Static;
-   pOut->flags |= MEM_Ephem;
- }
- return (sql_value *) pOut;
-}
-
 enum mp_type
 sql_column_type(sql_stmt * pStmt, int i)
 {
diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
index 092350caa..d977cbac8 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -67,71 +67,6 @@ sqlVdbeMemAboutToChange(Vdbe * pVdbe, Mem * pMem)
  pMem->pScopyFrom = 0;
 }
 #endif       /* SQL_DEBUG */
-/*
- * Move data out of a btree key or data field and into a Mem structure.
- * The data is payload from the entry that pCur is currently pointing
- * to.  offset and amt determine what portion of the data or key to retrieve.
- * The result is written into the pMem element.
- *
- * The pMem object must have been initialized.  This routine will use
- * pMem->zMalloc to hold the content from the btree, if possible.  New
- * pMem->zMalloc space will be allocated if necessary.  The calling routine
- * is responsible for making sure that the pMem object is eventually
- * destroyed.
- *
- * If this routine fails for any reason (malloc returns NULL or unable
- * to read from the disk) then the pMem is left in an inconsistent state.
- */
-static SQL_NOINLINE int
-vdbeMemFromBtreeResize(BtCursor * pCur,  /* Cursor pointing at record to retrieve. */
-          u32 offset,  /* Offset from the start of data to return bytes from. */
-          u32 amt, /* Number of bytes to return. */
-          Mem * pMem /* OUT: Return data in this Mem structure. */
-    )
-{
- int rc;
- pMem->flags = MEM_Null;
- 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;
-}
-
-int
-sqlVdbeMemFromBtree(BtCursor * pCur, /* Cursor pointing at record to retrieve. */
-     u32 offset, /* Offset from the start of data to return bytes from. */
-     u32 amt,  /* Number of bytes to return. */
-     Mem * pMem  /* OUT: Return data in this Mem structure. */
-    )
-{
- char *zData;    /* Data from the btree layer */
- u32 available = 0;  /* Number of bytes available on the local btree page */
- int rc = 0; /* Return code */
-
- assert(sqlCursorIsValid(pCur));
- assert(!VdbeMemDynamic(pMem));
- assert(pCur->curFlags & BTCF_TaCursor ||
-        pCur->curFlags & BTCF_TEphemCursor);
-
-
- zData = (char *)tarantoolsqlPayloadFetch(pCur, &available);
- assert(zData != 0);
-
- if (offset + amt <= available) {
-   pMem->z = &zData[offset];
-   pMem->flags = MEM_Blob | MEM_Ephem;
-   pMem->n = (int)amt;
- } else {
-   rc = vdbeMemFromBtreeResize(pCur, offset, amt, pMem);
- }
-
- return rc;
-}
-
 /*
  * Context object passed by sqlStat4ProbeSetValue() through to
  * valueNew(). See comments above valueNew() for details.


More information about the Tarantool-patches mailing list