From: Mergen Imeev via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: Timur Safin <tsafin@tarantool.org> Cc: tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH v2 4/4] sql: introduce mem_cmp_msgpack() Date: Mon, 19 Jul 2021 13:07:13 +0300 [thread overview] Message-ID: <28dd1848-e29d-c416-1f38-9ff8da2d3fd2@tarantool.org> (raw) In-Reply-To: <189d01d77c7e$bbab2cc0$33018640$@tarantool.org> 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@tarantool.org <imeevma@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 >
next prev parent reply other threads:[~2021-07-19 10:07 UTC|newest] Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-07-16 8:57 [Tarantool-patches] [PATCH v2 0/4] Follow ups for uuid introduction Mergen Imeev via Tarantool-patches 2021-07-16 8:57 ` [Tarantool-patches] [PATCH v2 1/4] sql: introduce uuid to quote() Mergen Imeev via Tarantool-patches 2021-07-19 9:16 ` Timur Safin via Tarantool-patches 2021-07-16 8:57 ` [Tarantool-patches] [PATCH v2 2/4] sql: allow to bind uuid values Mergen Imeev via Tarantool-patches 2021-07-19 9:16 ` Timur Safin via Tarantool-patches 2021-07-16 8:57 ` [Tarantool-patches] [PATCH v2 3/4] sql: introduce mem_cmp_scalar() Mergen Imeev via Tarantool-patches 2021-07-19 9:17 ` Timur Safin via Tarantool-patches 2021-07-16 8:57 ` [Tarantool-patches] [PATCH v2 4/4] sql: introduce mem_cmp_msgpack() Mergen Imeev via Tarantool-patches 2021-07-19 9:16 ` Timur Safin via Tarantool-patches 2021-07-19 10:07 ` Mergen Imeev via Tarantool-patches [this message] -- strict thread matches above, loose matches on Subject: below -- 2021-07-10 14:33 [Tarantool-patches] [PATCH v2 0/4] Follow ups for uuid introduction Mergen Imeev via Tarantool-patches 2021-07-10 14:33 ` [Tarantool-patches] [PATCH v2 4/4] sql: introduce mem_cmp_msgpack() Mergen Imeev via Tarantool-patches 2021-07-11 15:05 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-11 17:59 ` Mergen Imeev via Tarantool-patches 2021-07-12 21:09 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-13 8:10 ` Mergen Imeev via Tarantool-patches 2021-07-13 20:39 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-14 6:51 ` Mergen Imeev via Tarantool-patches 2021-07-14 21:53 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-15 6:58 ` 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=28dd1848-e29d-c416-1f38-9ff8da2d3fd2@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=imeevma@tarantool.org \ --cc=tsafin@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v2 4/4] sql: introduce mem_cmp_msgpack()' \ /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