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 69E286EC55; Mon, 19 Jul 2021 12:16:23 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 69E286EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1626686183; bh=QsZYZabxHqmLKySAKIt8R6eY2E7Pdz7Tg1nL0IgurmE=; h=To:Cc:References:In-Reply-To:Date:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=pvEFqPvHn0jGVC8R/FfKis239QxDyvqhohfKJ8bq781pkFnK4T81g+g8+QInkMESa 6XBx593sY4FWIfjvAgwauxZSILtcFUiDh/82JK6oEOCG+ah8O+NoUdz1UBcXE55AJC kCLoNcC/6l57a+FjEKzk8iytJvHlJOVLqlsxwr8M= Received: from smtp57.i.mail.ru (smtp57.i.mail.ru [217.69.128.37]) (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 0E55E6EC55 for ; Mon, 19 Jul 2021 12:16:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 0E55E6EC55 Received: by smtp57.i.mail.ru with esmtpa (envelope-from ) id 1m5PNt-0004xD-CS; Mon, 19 Jul 2021 12:16:21 +0300 To: Cc: References: In-Reply-To: Date: Mon, 19 Jul 2021 12:16:17 +0300 Message-ID: <189d01d77c7e$bbab2cc0$33018640$@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQD0dPzMRKuVIAksNaGzWjRUzQP0JQInmycerP7K6IA= Content-Language: ru X-4EC0790: 10 X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD941C43E597735A9C3FDAB68B812060C77E621B90589399EB5182A05F5380850403CE455DF59DBB9D577B7C8ED33671FF4251498620D5445946BDC78EE3C30DE40 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE795530B80AF2ADB7BEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063748789019239639CB8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D85294D03B7D1CF4A23F78F0E6168BEDEC117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC8C7ADC89C2F0B2A5A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18BDFBBEFFF4125B51D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EEC65AC60A1F0286FE07FB45A5F6E725C8D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE30A6B3CD6EB70C81876E601842F6C81A1F004C906525384307823802FF610243DF43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7CD0F529D6CE73765543847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: 0D63561A33F958A567CC6DF99749A7668AA20F22E710DDC61A4AF05A3F92F669D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7501A9DF589746230F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3480665FBD8F49180C3E49149150FEE89A9B409FE66DCF1DEED5FC4D6AE42F604D4B5F1973726D8A081D7E09C32AA3244C3547EBBB0F35161E1928D996B14ECC64FE8DA44ABE2443F7729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj+8+KVR9NZrHM1wx71rxlUg== X-Mailru-Sender: 9B1A9A1451179B430DCE2B318EA4156206CCD3D6FB4AE3DA7F9289FAD0BEA98F68BDFECA33165F425C2808D6142752370A8ED71B308007E3DC85537438B7E1A423D748DE48713E689437F6177E88F7363CDA0F3B3F5B9367 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: Timur Safin via Tarantool-patches Reply-To: Timur Safin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" LGTM, but with 1 question... : From: imeevma@tarantool.org : Subject: [PATCH v2 4/4] sql: introduce mem_cmp_msgpack() :=20 : 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. :=20 : 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(-) :=20 : 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 =3D fieldno + 1; : - rc =3D sqlVdbeCompareMsgpack(&p, unpacked, i); : + struct key_part *part =3D &unpacked->key_def->parts[i]; : + struct Mem *mem =3D unpacked->aMem + i; : + struct coll *coll =3D part->coll; : + if (mem_cmp_msgpack(mem, &p, &rc, coll) !=3D 0) : + rc =3D 0; : if (rc !=3D 0) { : - if (unpacked->key_def->parts[i].sort_order !=3D : - SORT_ORDER_ASC) : + if (part->sort_order =3D=3D SORT_ORDER_ASC) : rc =3D -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; : } :=20 : -/* : - * 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 =3D (*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 =3D 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 =3D MEM_TYPE_NULL; : + mp_decode_nil(b); : + break; : + case MP_BOOL: : + mem.type =3D MEM_TYPE_BOOL; : + mem.u.b =3D mp_decode_bool(b); : + break; : + case MP_UINT: : + mem.type =3D MEM_TYPE_UINT; : + mem.u.u =3D mp_decode_uint(b); : + break; : + case MP_INT: : + mem.type =3D MEM_TYPE_INT; : + mem.u.i =3D mp_decode_int(b); : + break; : + case MP_FLOAT: : + mem.type =3D MEM_TYPE_DOUBLE; : + mem.u.r =3D mp_decode_float(b); : + break; : + case MP_DOUBLE: : + mem.type =3D MEM_TYPE_DOUBLE; : + mem.u.r =3D mp_decode_double(b); : + break; : + case MP_STR: : + mem.type =3D MEM_TYPE_STR; : + mem.n =3D mp_decode_strl(b); : + mem.z =3D (char *)*b; : + *b +=3D mem.n; : + mem.flags =3D MEM_Ephem; : + break; : + case MP_BIN: : + mem.type =3D MEM_TYPE_BIN; : + mem.n =3D mp_decode_binl(b); : + mem.z =3D (char *)*b; : + *b +=3D mem.n; : + mem.flags =3D MEM_Ephem; : + break; : + case MP_ARRAY: : + case MP_MAP: : + mp_next(b); : + *result =3D -1; : + return 0; : + case MP_EXT: { : + int8_t type; : + const char *buf =3D *b; : + uint32_t len =3D mp_decode_extl(b, &type); Decimals are coming here? Yes? : + if (type =3D=3D MP_UUID) { : + assert(len =3D=3D UUID_LEN); : + mem.type =3D MEM_TYPE_UUID; : + if (uuid_unpack(b, len, &mem.u.uuid) =3D=3D NULL) : + return -1; : + break; : + } : + *b +=3D len; : + mem.type =3D MEM_TYPE_BIN; : + mem.z =3D (char *)buf; : + mem.n =3D *b - buf; : + mem.flags =3D MEM_Ephem; : + break; : } : - return 1; : + default: : + unreachable(); : + } : + return mem_cmp_scalar(a, &mem, result, coll); : } :=20 : char * Regards, Timur