[Tarantool-patches] [PATCH v2 4/4] sql: introduce mem_cmp_msgpack()

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Sun Jul 11 18:05:38 MSK 2021


Thanks for the patch!

See 4 comments below.

On 10.07.2021 16:33, Mergen Imeev via Tarantool-patches wrote:
> This patch introduces the mem_cmp_scalar() function that compares MEM

1. scalar -> msgpack.

> diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
> index 576596c9f..471b69a18 100644
> --- a/src/box/sql/mem.c
> +++ b/src/box/sql/mem.c
> @@ -2073,35 +2073,72 @@ mem_cmp_scalar(const struct Mem *a, const struct Mem *b, int *result,

<...>

> -
> -/*
> - * The input pBlob is guaranteed to be a Blob that is not marked
> - * with MEM_Zero.  Return true if it could be a zero-blob.
> - */
> -static int
> -isAllZero(const char *z, int n)
> +int
> +mem_cmp_msgpack(const struct Mem *a, const char *b, int *result,
> +		const struct coll *coll)

2. Maybe better make the function return 'b' after decoding via
making it an out parameter. So as the caller could save mp_next()
call.

>  {
> -	int i;
> -	for (i = 0; i < n; i++) {
> -		if (z[i])
> -			return 0;
> +	struct Mem mem;
> +	switch (mp_typeof(*b)) {
> +	case MP_NIL:
> +		mem.type = MEM_TYPE_NULL;
> +		break;
> +	case MP_BOOL:
> +		mem.type = MEM_TYPE_BOOL;
> +		mem.u.b = mp_decode_bool(&b);
> +		break;
> +	case MP_UINT:
> +		mem.type = MEM_TYPE_UINT;
> +		mem.u.u = mp_decode_uint(&b);
> +		break;
> +	case MP_INT:
> +		mem.type = MEM_TYPE_INT;
> +		mem.u.i = mp_decode_int(&b);
> +		break;
> +	case MP_FLOAT:
> +		mem.type = MEM_TYPE_DOUBLE;
> +		mem.u.r = mp_decode_float(&b);
> +		break;
> +	case MP_DOUBLE:
> +		mem.type = MEM_TYPE_DOUBLE;
> +		mem.u.r = mp_decode_double(&b);
> +		break;
> +	case MP_STR:
> +		mem.type = MEM_TYPE_STR;
> +		mem.n = mp_decode_strl(&b);
> +		mem.z = (char *)b;
> +		mem.flags = MEM_Ephem;
> +		break;
> +	case MP_BIN:
> +		mem.type = MEM_TYPE_BIN;
> +		mem.n = mp_decode_binl(&b);
> +		mem.z = (char *)b;

3. Shouldn't this also have MEM_Ephem?

> +		break;
> +	case MP_ARRAY:
> +	case MP_MAP:
> +		*result = -1;
> +		return 0;
> +	case MP_EXT: {
> +		int8_t type;
> +		const char *buf = b;
> +		uint32_t len = mp_decode_extl(&b, &type);
> +		if (type == MP_UUID) {
> +			assert(len == UUID_LEN);
> +			mem.type = MEM_TYPE_UUID;
> +			b = buf;

4. You can decode &buf below without changing b.

> +			if (mp_decode_uuid(&b, &mem.u.uuid) == NULL)
> +				return -1;
> +			break;
> +		}
> +		b += len;
> +		mem.type = MEM_TYPE_BIN;
> +		mem.z = (char *)buf;
> +		mem.n = b - buf;
> +		break;
>  	}
> -	return 1;
> +	default:
> +		unreachable();
> +	}
> +	return mem_cmp_scalar(a, &mem, result, coll);
>  }


More information about the Tarantool-patches mailing list