From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Mergen Imeev <imeevma@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v2 4/4] sql: introduce mem_cmp_msgpack()
Date: Mon, 12 Jul 2021 23:09:02 +0200 [thread overview]
Message-ID: <913595cc-0d71-1a69-7997-ca4a136f97a1@tarantool.org> (raw)
In-Reply-To: <20210711175916.GB99369@tarantool.org>
Thanks for the fixes!
See 2 comments below.
> diff --git a/src/box/sql.c b/src/box/sql.c
> index 790ca7f70..a5afcfabb 100644
> --- a/src/box/sql.c
> +++ b/src/box/sql.c
> @@ -765,10 +765,12 @@ 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;
> + mem_cmp_msgpack(mem, &p, &rc, coll);
1. The same as in the previous patch - you either need to fill
rc out parameter even in case of a fail, or check result of
mem_cmp_msgpack() to keep the results stable. Not depending on
the stack's garbage content.
The same in the other places where it is called.
> 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 da27cd191..4062ff4b3 100644
> --- a/src/box/sql/mem.c
> +++ b/src/box/sql/mem.c
> @@ -2077,35 +2077,78 @@ mem_cmp_scalar(const struct Mem *a, const struct Mem *b, int *result,
<...>
> + case MP_EXT: {
> + int8_t type;
> + const char *buf = *b;
> + uint32_t len = mp_decode_extl(&buf, &type);
> + if (type == MP_UUID) {
> + assert(len == UUID_LEN);
> + mem.type = MEM_TYPE_UUID;
> + if (mp_decode_uuid(b, &mem.u.uuid) == NULL)
> + return -1;
> + break;
> + }
> + len += buf - *b;
> + mem.type = MEM_TYPE_BIN;
> + mem.z = (char *)*b;
> + mem.n = len;
> + mem.flags = MEM_Ephem;
> + *b += len;
> + break;
2. I just remembered now, that we have uuid_unpack(). It is better
to use when you already decoded the EXT header. Consider this:
====================
@@ -2129,20 +2129,18 @@ mem_cmp_msgpack(const struct Mem *a, const char **b, int *result,
case MP_EXT: {
int8_t type;
const char *buf = *b;
- uint32_t len = mp_decode_extl(&buf, &type);
+ uint32_t len = mp_decode_extl(b, &type);
if (type == MP_UUID) {
- assert(len == UUID_LEN);
- mem.type = MEM_TYPE_UUID;
- if (mp_decode_uuid(b, &mem.u.uuid) == NULL)
+ if (uuid_unpack(&b, len, &mem.u.uuid) == NULL)
return -1;
+ mem.type = MEM_TYPE_UUID;
break;
}
- len += buf - *b;
mem.type = MEM_TYPE_BIN;
- mem.z = (char *)*b;
- mem.n = len;
+ mem.z = (char *)buf;
+ mem.n = b - buf + len;
mem.flags = MEM_Ephem;
- *b += len;
+ b += len;
break;
}
default:
====================
(I didn't test though.)
next prev parent reply other threads:[~2021-07-12 21:09 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
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 1/4] sql: introduce uuid to quote() Mergen Imeev via Tarantool-patches
2021-07-10 14:33 ` [Tarantool-patches] [PATCH v2 2/4] sql: allow to bind uuid values Mergen Imeev via Tarantool-patches
2021-07-10 14:33 ` [Tarantool-patches] [PATCH v2 3/4] sql: introduce mem_cmp_scalar() Mergen Imeev via Tarantool-patches
2021-07-11 15:03 ` Vladislav Shpilevoy via Tarantool-patches
2021-07-11 17:51 ` Mergen Imeev via Tarantool-patches
2021-07-12 21:06 ` Vladislav Shpilevoy via Tarantool-patches
2021-07-13 8:04 ` 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 [this message]
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
2021-07-15 20:44 ` [Tarantool-patches] [PATCH v2 0/4] Follow ups for uuid introduction Vladislav Shpilevoy via Tarantool-patches
2021-07-16 8:57 Mergen Imeev 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
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=913595cc-0d71-1a69-7997-ca4a136f97a1@tarantool.org \
--to=tarantool-patches@dev.tarantool.org \
--cc=imeevma@tarantool.org \
--cc=v.shpilevoy@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