[Tarantool-patches] [PATCH v3 5/8] sql: remove mem_apply_type() from OP_MustBeInt

Nikita Pettik korablev at tarantool.org
Mon Jun 29 16:29:57 MSK 2020


On 25 Jun 18:17, imeevma at tarantool.org wrote:
> diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
> index 276956170..a609fa985 100644
> --- a/src/box/sql/vdbe.c
> +++ b/src/box/sql/vdbe.c
> @@ -2122,17 +2122,13 @@ case OP_AddImm: {            /* in1 */
>   */
>  case OP_MustBeInt: {            /* jump, in1 */
>  	pIn1 = &aMem[pOp->p1];
> -	if ((pIn1->flags & (MEM_Int | MEM_UInt)) == 0) {
> -		mem_apply_type(pIn1, FIELD_TYPE_INTEGER);
> -		if ((pIn1->flags & (MEM_Int | MEM_UInt)) == 0) {
> -			if (pOp->p2==0) {
> -				diag_set(ClientError, ER_SQL_TYPE_MISMATCH,
> -					 sql_value_to_diag_str(pIn1), "integer");
> -				goto abort_due_to_error;
> -			} else {
> -				goto jump_to_p2;
> -			}
> -		}
> +	if ((pIn1->flags & (MEM_Int | MEM_UInt)) == 0 &&
> +	    mem_convert_to_integer(pIn1, true) != 0) {

Please split this conditions into two branches. Like this:

diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 2bc8c9817..da76d7321 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -2122,13 +2122,14 @@ case OP_AddImm: {            /* in1 */
  */
 case OP_MustBeInt: {            /* jump, in1 */
        pIn1 = &aMem[pOp->p1];
-       if ((pIn1->flags & (MEM_Int | MEM_UInt)) == 0 &&
-           mem_convert_to_integer(pIn1, true) != 0) {
-               if (pOp->p2 != 0)
-                       goto jump_to_p2;
-               diag_set(ClientError, ER_SQL_TYPE_MISMATCH,
-                        sql_value_to_diag_str(pIn1), "integer");
-               goto abort_due_to_error;
+       if ((pIn1->flags & (MEM_Int | MEM_UInt)) == 0) {
+               if (mem_convert_to_integer(pIn1, true) != 0) {
+                       if (pOp->p2 != 0)
+                               goto jump_to_p2;
+                       diag_set(ClientError, ER_SQL_TYPE_MISMATCH,
+                                sql_value_to_diag_str(pIn1), "integer");
+                       goto abort_due_to_error;
+               }
        }
        break;

It ehcnances code readability. Or even integrate this check into
mem_covert_to_ingeger().

The rest is OK (hope you carefully verified changed tests, since
I've only briefly looked through).



More information about the Tarantool-patches mailing list