From: Mergen Imeev via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH v1 7/7] sql: remove unused MEM cast functions Date: Wed, 28 Jul 2021 23:51:20 +0300 [thread overview] Message-ID: <551fd439d751a10c19877016805811e826d28825.1627504973.git.imeevma@gmail.com> (raw) In-Reply-To: <cover.1627504972.git.imeevma@gmail.com> This patch removes functions that become unused due to changes of implicit and explicit cast rules. Part of #4470 --- src/box/sql/func.c | 2 +- src/box/sql/mem.c | 222 ---------------------------------------- src/box/sql/mem.h | 19 ---- src/box/sql/vdbe.h | 2 +- src/box/sql/vdbeaux.c | 6 +- src/box/sql/whereexpr.c | 4 +- 6 files changed, 5 insertions(+), 250 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 9a96e96ff..7dd3a4897 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -58,7 +58,7 @@ static const void * mem_as_bin(struct Mem *mem) { const char *s; - if (mem_cast_implicit(mem, FIELD_TYPE_VARBINARY) != 0 && + if (mem_cast_explicit(mem, FIELD_TYPE_VARBINARY) != 0 && mem_to_str(mem) != 0) return NULL; if (mem_get_bin(mem, &s) != 0) diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c index 98b367054..d965d327b 100644 --- a/src/box/sql/mem.c +++ b/src/box/sql/mem.c @@ -820,58 +820,6 @@ double_to_int(struct Mem *mem) return -1; } -static inline int -double_to_int_precise(struct Mem *mem) -{ - assert(mem->type == MEM_TYPE_DOUBLE); - double d = mem->u.r; - if (d < 0 && d >= (double)INT64_MIN && (double)(int64_t)d == d) { - mem->u.i = (int64_t)d; - mem->type = MEM_TYPE_INT; - assert(mem->flags == 0); - mem->field_type = FIELD_TYPE_INTEGER; - return 0; - } - if (d >= 0 && d < (double)UINT64_MAX && (double)(uint64_t)d == d) { - mem->u.u = (uint64_t)d; - mem->type = MEM_TYPE_UINT; - assert(mem->flags == 0); - mem->field_type = FIELD_TYPE_UNSIGNED; - return 0; - } - return -1; -} - -static inline int -double_to_uint(struct Mem *mem) -{ - assert(mem->type == MEM_TYPE_DOUBLE); - double d = mem->u.r; - if (d >= 0 && d < (double)UINT64_MAX) { - mem->u.u = (uint64_t)d; - mem->type = MEM_TYPE_UINT; - assert(mem->flags == 0); - mem->field_type = FIELD_TYPE_UNSIGNED; - return 0; - } - return -1; -} - -static inline int -double_to_uint_precise(struct Mem *mem) -{ - assert(mem->type == MEM_TYPE_DOUBLE); - double d = mem->u.r; - if (d >= 0 && d < (double)UINT64_MAX && (double)(uint64_t)d == d) { - mem->u.u = (uint64_t)d; - mem->type = MEM_TYPE_UINT; - assert(mem->flags == 0); - mem->field_type = FIELD_TYPE_UNSIGNED; - return 0; - } - return -1; -} - static inline int double_to_str0(struct Mem *mem) { @@ -1025,19 +973,6 @@ mem_to_int(struct Mem *mem) return -1; } -int -mem_to_int_precise(struct Mem *mem) -{ - assert(mem->type < MEM_TYPE_INVALID); - 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; -} - int mem_to_double(struct Mem *mem) { @@ -1183,163 +1118,6 @@ mem_cast_explicit(struct Mem *mem, enum field_type type) return -1; } -int -mem_cast_implicit(struct Mem *mem, enum field_type type) -{ - if (mem->type == MEM_TYPE_NULL) { - mem->field_type = type; - 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(mem); - return -1; - case FIELD_TYPE_STRING: - if (mem->type == MEM_TYPE_STR) - return 0; - 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); - return -1; - case FIELD_TYPE_INTEGER: - if ((mem->type & (MEM_TYPE_INT | MEM_TYPE_UINT)) != 0) - return 0; - if (mem->type == MEM_TYPE_DOUBLE) - return double_to_int(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 | MEM_TYPE_MAP | - MEM_TYPE_ARRAY)) != 0) - 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; - 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; - case FIELD_TYPE_ANY: - return 0; - default: - break; - } - 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 5d1d7592e..de0558150 100644 --- a/src/box/sql/mem.h +++ b/src/box/sql/mem.h @@ -692,15 +692,6 @@ mem_cmp(const struct Mem *a, const struct Mem *b, int *result, int mem_to_int(struct Mem *mem); -/** - * Convert the given MEM to INTEGER. This function and the function above define - * the rules that are used to convert values of all other types to INTEGER. In - * this function, the conversion from double to integer is only possible if it - * is lossless. - */ -int -mem_to_int_precise(struct Mem *mem); - /** * Convert the given MEM to DOUBLE. This function defines the rules that are * used to convert values of all other types to DOUBLE. @@ -736,16 +727,6 @@ mem_to_str0(struct Mem *mem); int mem_cast_explicit(struct Mem *mem, enum field_type type); -/** Convert the given MEM to given type according to implicit cast rules. */ -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); - /** * Convert the given MEM that contains numeric value to given numeric type * according to implicit cast rules. This function cannot fail. Returns: 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..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) { 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) 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; -- 2.25.1
next prev parent reply other threads:[~2021-07-28 20:54 UTC|newest] Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-07-28 20:51 [Tarantool-patches] [PATCH v1 0/7] Rework implicit cast Mergen Imeev via Tarantool-patches 2021-07-28 20:51 ` [Tarantool-patches] [PATCH v1 1/7] sql: rework implicit cast fo assignment Mergen Imeev via Tarantool-patches 2021-07-30 21:55 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-04 22:21 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-05 23:27 ` Mergen Imeev via Tarantool-patches 2021-08-06 0:13 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-28 20:51 ` [Tarantool-patches] [PATCH v1 2/7] sql: remove implicit cast from comparison opcodes Mergen Imeev via Tarantool-patches 2021-08-04 22:24 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-05 23:33 ` Mergen Imeev via Tarantool-patches 2021-08-06 0:13 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-28 20:51 ` [Tarantool-patches] [PATCH v1 3/7] sql: rework OP_Seek* opcodes Mergen Imeev via Tarantool-patches 2021-08-04 22:25 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-05 23:40 ` Mergen Imeev via Tarantool-patches 2021-07-28 20:51 ` [Tarantool-patches] [PATCH v1 4/7] sql: remove unnecessary calls of OP_ApplyType Mergen Imeev via Tarantool-patches 2021-08-04 22:26 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-05 23:41 ` Mergen Imeev via Tarantool-patches 2021-07-28 20:51 ` [Tarantool-patches] [PATCH v1 5/7] sql: remove implicit cast from OP_MakeRecord Mergen Imeev via Tarantool-patches 2021-08-04 22:27 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-05 23:43 ` Mergen Imeev via Tarantool-patches 2021-08-06 0:13 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-28 20:51 ` [Tarantool-patches] [PATCH v1 6/7] sql: remove implicit cast from OP_MustBeInt Mergen Imeev via Tarantool-patches 2021-08-05 23:47 ` Mergen Imeev via Tarantool-patches 2021-07-28 20:51 ` Mergen Imeev via Tarantool-patches [this message] 2021-08-04 22:27 ` [Tarantool-patches] [PATCH v1 7/7] sql: remove unused MEM cast functions Vladislav Shpilevoy via Tarantool-patches 2021-08-05 23:45 ` Mergen Imeev via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=551fd439d751a10c19877016805811e826d28825.1627504973.git.imeevma@gmail.com \ --to=tarantool-patches@dev.tarantool.org \ --cc=imeevma@tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v1 7/7] sql: remove unused MEM cast functions' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox