[Tarantool-patches] [PATCH v1 7/7] sql: remove unused MEM cast functions

Mergen Imeev imeevma at tarantool.org
Fri Aug 6 02:45:08 MSK 2021


Thank you for the review! My answers and new patch below. Also, patch become a
lot less since I decided to not remove "precise" cast functions and
mem_cast_implicit().

On Thu, Aug 05, 2021 at 12:27:41AM +0200, Vladislav Shpilevoy wrote:
> Thanks for the patch!
> 
> > diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
> > index 4a1fdb637..fc06e502e 100644
> > --- a/src/box/sql/vdbeaux.c
> > +++ b/src/box/sql/vdbeaux.c
> > @@ -2323,17 +2323,15 @@ sqlVdbeDb(Vdbe * v)
> >   * The returned value must be freed by the caller using sqlValueFree().
> >   */
> >  sql_value *
> > -sqlVdbeGetBoundValue(Vdbe * v, int iVar, u8 aff)
> > +sqlVdbeGetBoundValue(Vdbe * v, int iVar)
> 
> 1. No need for a whitespace after *.
> 
Fixed.

> >  {
> >  	assert(iVar > 0);
> >  	if (v) {
> >  		Mem *pMem = &v->aVar[iVar - 1];
> >  		if (!mem_is_null(pMem)) {
> >  			sql_value *pRet = sqlValueNew(v->db);
> > -			if (pRet) {
> > +			if (pRet)
> 
> 2. != NULL.
Fixed.

New patch:


commit a399bca95e72aea615600e3e8c6a15a8c11f2987
Author: Mergen Imeev <imeevma at gmail.com>
Date:   Tue Jul 27 23:37:06 2021 +0300

    sql: remove unused MEM cast functions
    
    This patch removes functions that become unused due to changes of
    implicit and explicit cast rules.
    
    Part of #4470

diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
index e654cac41..d1ef92a86 100644
--- a/src/box/sql/mem.c
+++ b/src/box/sql/mem.c
@@ -1293,88 +1293,6 @@ mem_cast_implicit(struct Mem *mem, enum field_type type)
 	return -1;
 }
 
-int
-mem_cast_implicit_old(struct Mem *mem, enum field_type type)
-{
-	if (mem->type == MEM_TYPE_NULL)
-		return 0;
-	switch (type) {
-	case FIELD_TYPE_UNSIGNED:
-		if (mem->type == MEM_TYPE_UINT)
-			return 0;
-		if (mem->type == MEM_TYPE_DOUBLE)
-			return double_to_uint_precise(mem);
-		if (mem->type == MEM_TYPE_STR)
-			return str_to_uint(mem);
-		return -1;
-	case FIELD_TYPE_STRING:
-		if ((mem->type & (MEM_TYPE_STR | MEM_TYPE_BIN)) != 0)
-			return 0;
-		if ((mem->type & (MEM_TYPE_INT | MEM_TYPE_UINT)) != 0)
-			return int_to_str0(mem);
-		if (mem->type == MEM_TYPE_DOUBLE)
-			return double_to_str0(mem);
-		if (mem->type == MEM_TYPE_UUID)
-			return uuid_to_str0(mem);
-		return -1;
-	case FIELD_TYPE_DOUBLE:
-		if (mem->type == MEM_TYPE_DOUBLE)
-			return 0;
-		if ((mem->type & (MEM_TYPE_INT | MEM_TYPE_UINT)) != 0)
-			return int_to_double(mem);
-		if (mem->type == MEM_TYPE_STR)
-			return bin_to_str(mem);
-		return -1;
-	case FIELD_TYPE_INTEGER:
-		if ((mem->type & (MEM_TYPE_INT | MEM_TYPE_UINT)) != 0)
-			return 0;
-		if (mem->type == MEM_TYPE_STR)
-			return str_to_int(mem);
-		if (mem->type == MEM_TYPE_DOUBLE)
-			return double_to_int_precise(mem);
-		return -1;
-	case FIELD_TYPE_BOOLEAN:
-		if (mem->type == MEM_TYPE_BOOL)
-			return 0;
-		return -1;
-	case FIELD_TYPE_VARBINARY:
-		if (mem->type == MEM_TYPE_BIN)
-			return 0;
-		if (mem->type == MEM_TYPE_UUID)
-			return uuid_to_bin(mem);
-		return -1;
-	case FIELD_TYPE_NUMBER:
-		if (mem_is_num(mem))
-			return 0;
-		if (mem->type == MEM_TYPE_STR)
-			return mem_to_number(mem);
-		return -1;
-	case FIELD_TYPE_MAP:
-		if (mem->type == MEM_TYPE_MAP)
-			return 0;
-		return -1;
-	case FIELD_TYPE_ARRAY:
-		if (mem->type == MEM_TYPE_ARRAY)
-			return 0;
-		return -1;
-	case FIELD_TYPE_SCALAR:
-		if ((mem->type & (MEM_TYPE_MAP | MEM_TYPE_ARRAY)) != 0)
-			return -1;
-		return 0;
-	case FIELD_TYPE_UUID:
-		if (mem->type == MEM_TYPE_UUID)
-			return 0;
-		if (mem->type == MEM_TYPE_STR)
-			return str_to_uuid(mem);
-		if (mem->type == MEM_TYPE_BIN)
-			return bin_to_uuid(mem);
-		return -1;
-	default:
-		break;
-	}
-	return -1;
-}
-
 int
 mem_cast_implicit_number(struct Mem *mem, enum field_type type)
 {
diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h
index 4f61cbab0..9681fc736 100644
--- a/src/box/sql/mem.h
+++ b/src/box/sql/mem.h
@@ -740,12 +740,6 @@ mem_cast_explicit(struct Mem *mem, enum field_type type);
 int
 mem_cast_implicit(struct Mem *mem, enum field_type type);
 
-/**
- * Convert the given MEM to given type according to legacy implicit cast rules.
- */
-int
-mem_cast_implicit_old(struct Mem *mem, enum field_type type);
-
 /**
  * Cast MEM with numeric value to given numeric type. Doesn't fail. The return
  * value is < 0 if the original value is less than the result, > 0 if the
diff --git a/src/box/sql/vdbe.h b/src/box/sql/vdbe.h
index 118f1cd83..be112c72d 100644
--- a/src/box/sql/vdbe.h
+++ b/src/box/sql/vdbe.h
@@ -266,7 +266,7 @@ sql *sqlVdbeDb(Vdbe *);
 void sqlVdbeSetSql(Vdbe *, const char *z, int n);
 void sqlVdbeSwap(Vdbe *, Vdbe *);
 VdbeOp *sqlVdbeTakeOpArray(Vdbe *, int *, int *);
-sql_value *sqlVdbeGetBoundValue(Vdbe *, int, u8);
+sql_value *sqlVdbeGetBoundValue(Vdbe *, int);
 char *sqlVdbeExpandSql(Vdbe *, const char *);
 
 /**
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 4a1fdb637..61be7b489 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -2323,17 +2323,15 @@ sqlVdbeDb(Vdbe * v)
  * The returned value must be freed by the caller using sqlValueFree().
  */
 sql_value *
-sqlVdbeGetBoundValue(Vdbe * v, int iVar, u8 aff)
+sqlVdbeGetBoundValue(struct Vdbe *v, int iVar)
 {
 	assert(iVar > 0);
 	if (v) {
 		Mem *pMem = &v->aVar[iVar - 1];
 		if (!mem_is_null(pMem)) {
 			sql_value *pRet = sqlValueNew(v->db);
-			if (pRet) {
+			if (pRet != NULL)
 				mem_copy(pRet, pMem);
-				mem_cast_implicit_old(pRet, aff);
-			}
 			return pRet;
 		}
 	}
diff --git a/src/box/sql/whereexpr.c b/src/box/sql/whereexpr.c
index fe7329ea8..6849f13ec 100644
--- a/src/box/sql/whereexpr.c
+++ b/src/box/sql/whereexpr.c
@@ -309,9 +309,7 @@ like_optimization_is_valid(Parse *pParse, Expr *pExpr, Expr **ppPrefix,
 	if (op == TK_VARIABLE) {
 		Vdbe *pReprepare = pParse->pReprepare;
 		int iCol = pRight->iColumn;
-		pVal =
-		    sqlVdbeGetBoundValue(pReprepare, iCol,
-					     FIELD_TYPE_SCALAR);
+		pVal = sqlVdbeGetBoundValue(pReprepare, iCol);
 		if (pVal != NULL && mem_is_str(pVal)) {
 			if (mem_as_str0(pVal) == NULL)
 				return -1;


More information about the Tarantool-patches mailing list