[Tarantool-patches] [PATCH v2 4/4] sql: introduce mem_cmp_msgpack()
Mergen Imeev
imeevma at tarantool.org
Mon Jul 19 13:07:13 MSK 2021
Hi! Thank you for the review. My answer below.
On 19.07.2021 12:16, Timur Safin wrote:
> LGTM, but with 1 question...
>
> : From: imeevma at tarantool.org <imeevma at tarantool.org>
> : Subject: [PATCH v2 4/4] sql: introduce mem_cmp_msgpack()
> :
> : This patch introduces the mem_cmp_msgpack() function that compares MEM
> : and packed to msgpack value using SCALAR rules. MEM and packed value
> : must be scalars. Prior to this patch, there was a function that used
> : SCALAR rules to compare MEM and packed value, but its design became
> : overly complex as new types appeared.
> :
> : Closes #6164
> : ---
> : src/box/sql.c | 9 +-
> : src/box/sql/mem.c | 289 +++++-------------
> : src/box/sql/mem.h | 24 +-
> : test/sql-tap/gh-6164-uuid-follow-ups.test.lua | 14 +-
> : 4 files changed, 107 insertions(+), 229 deletions(-)
> :
> : diff --git a/src/box/sql.c b/src/box/sql.c
> : index 790ca7f70..7471c3832 100644
> : --- a/src/box/sql.c
> : +++ b/src/box/sql.c
> : @@ -765,10 +765,13 @@ tarantoolsqlIdxKeyCompare(struct BtCursor *cursor,
> : }
> : }
> : next_fieldno = fieldno + 1;
> : - rc = sqlVdbeCompareMsgpack(&p, unpacked, i);
> : + struct key_part *part = &unpacked->key_def->parts[i];
> : + struct Mem *mem = unpacked->aMem + i;
> : + struct coll *coll = part->coll;
> : + if (mem_cmp_msgpack(mem, &p, &rc, coll) != 0)
> : + rc = 0;
> : if (rc != 0) {
> : - if (unpacked->key_def->parts[i].sort_order !=
> : - SORT_ORDER_ASC)
> : + if (part->sort_order == SORT_ORDER_ASC)
> : rc = -rc;
> : goto out;
> : }
> : diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
> : index a8cde6769..fa80f6d5a 100644
> : --- a/src/box/sql/mem.c
> : +++ b/src/box/sql/mem.c
> : @@ -2098,35 +2098,77 @@ mem_cmp_scalar(const struct Mem *a, const struct Mem
> : *b, int *result,
> : return 0;
> : }
> :
> : -/*
> : - * Both *pMem1 and *pMem2 contain string values. Compare the two values
> : - * using the collation sequence pColl. As usual, return a negative , zero
> : - * or positive value if *pMem1 is less than, equal to or greater than
> : - * *pMem2, respectively. Similar in spirit to "rc = (*pMem1) - (*pMem2);".
> : - *
> : - * Strungs assume to be UTF-8 encoded
> : - */
> : -static int
> : -vdbeCompareMemString(const Mem * pMem1, const Mem * pMem2,
> : - const struct coll * pColl)
> : -{
> : - return pColl->cmp(pMem1->z, (size_t)pMem1->n,
> : - pMem2->z, (size_t)pMem2->n, pColl);
> : -}
> : -
> : -/*
> : - * 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 i;
> : - for (i = 0; i < n; i++) {
> : - if (z[i])
> : - return 0;
> : +int
> : +mem_cmp_msgpack(const struct Mem *a, const char **b, int *result,
> : + const struct coll *coll)
> : +{
> : + struct Mem mem;
> : + switch (mp_typeof(**b)) {
> : + case MP_NIL:
> : + mem.type = MEM_TYPE_NULL;
> : + mp_decode_nil(b);
> : + 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;
> : + *b += mem.n;
> : + mem.flags = MEM_Ephem;
> : + break;
> : + case MP_BIN:
> : + mem.type = MEM_TYPE_BIN;
> : + mem.n = mp_decode_binl(b);
> : + mem.z = (char *)*b;
> : + *b += mem.n;
> : + mem.flags = MEM_Ephem;
> : + break;
> : + case MP_ARRAY:
> : + case MP_MAP:
> : + mp_next(b);
> : + *result = -1;
> : + return 0;
> : + case MP_EXT: {
> : + int8_t type;
> : + const char *buf = *b;
> : + uint32_t len = mp_decode_extl(b, &type);
>
> Decimals are coming here? Yes?
Yes. If you want I can give you branch where DECIMAL is partially done.
> : + if (type == MP_UUID) {
> : + assert(len == UUID_LEN);
> : + mem.type = MEM_TYPE_UUID;
> : + if (uuid_unpack(b, len, &mem.u.uuid) == NULL)
> : + return -1;
> : + break;
> : + }
> : + *b += len;
> : + mem.type = MEM_TYPE_BIN;
> : + mem.z = (char *)buf;
> : + mem.n = *b - buf;
> : + mem.flags = MEM_Ephem;
> : + break;
> : }
> : - return 1;
> : + default:
> : + unreachable();
> : + }
> : + return mem_cmp_scalar(a, &mem, result, coll);
> : }
> :
> : char *
>
> Regards,
> Timur
>
More information about the Tarantool-patches
mailing list