From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 018C76EC55; Tue, 13 Jul 2021 00:09:06 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 018C76EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1626124146; bh=+rmAdHlNGt3L4yPtHAt1avYEpN6JifbdURHOEMrlEcA=; h=To:Cc:References:Date:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=a2Y9UsoQRd1nmjroYAholed9TySg002h34Pf69bkYHxIQIlrjjqMlwFhf7nkXFDJf E1al/1StZJa7A7+KtbhFo520js9DvJtoRmZRcq0dchnxxhZ4NLRhAxyxEcOItdjHUS hDLP8mxOckJto85NOvT+kD7M3CwRD+rQZVaCZ44Y= Received: from smtpng2.i.mail.ru (smtpng2.i.mail.ru [94.100.179.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id D793F6EC55 for ; Tue, 13 Jul 2021 00:09:03 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D793F6EC55 Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1m33Al-0002Kw-4l; Tue, 13 Jul 2021 00:09:03 +0300 To: Mergen Imeev Cc: tarantool-patches@dev.tarantool.org References: <28d370911c40124da91441be2f25cad49e4973b4.1625926838.git.imeevma@gmail.com> <20c6c37d-6364-8fdb-0aa5-c7c82407b143@tarantool.org> <20210711175916.GB99369@tarantool.org> Message-ID: <913595cc-0d71-1a69-7997-ca4a136f97a1@tarantool.org> Date: Mon, 12 Jul 2021 23:09:02 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210711175916.GB99369@tarantool.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD97BB0EF39AD2B33D598226807B8A1E9DC331E3F9997896515182A05F53808504011680031745863FE2D8E7CC927B762F42947A6E0BCC2B889DD60F18365569971 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE70D278D70F8433719EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006379FED03E15F715FAA8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D89C0A9BC980807D898E26E37C5E598EB4117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8B2EE5AD8F952D28FBA471835C12D1D977C4224003CC8364762BB6847A3DEAEFB0F43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7C468D16C903838CAB43847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: 0D63561A33F958A5BD8DDC04CF02B276168E38BCFD7A11FB182634D1EAED498DD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA759DD14948C6BCD3BA410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D345C110A855FC09999D7470B8F7881EA0425087C846206CA34B97FD0E22861400DC8DA86192471513D1D7E09C32AA3244C7B2C61BB280DB013BB942117BA179001250262A5EE9971B0729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojAZDAgpmGsvbnM69qyqCVog== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D4C8CE512183EAC9A9203B6E40BE45AFC3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v2 4/4] sql: introduce mem_cmp_msgpack() X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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.)