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 0E26A6EC55; Mon, 19 Jul 2021 12:17:54 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 0E26A6EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1626686274; bh=sNwOTlQ0zKXytVkpidPEKLulFUYwyzKsQQDjw0zL1zE=; 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=ukotvTLHOUrhP46qsrQrjwWy6wjk/yrEZ8GqtFBJcKsNfyTPcCI4qAsiDdd4N6VpW NHiSwpCB0eF1GU4m0QAlM1oENWyrcsCHzVdS3faPZuR37bYoYjDXisZKGTejhGoe8t tlWYOVT5WEVnUpUXyHHQO/+q2Juz/yVwSoU5t984= Received: from smtp16.mail.ru (smtp16.mail.ru [94.100.176.153]) (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 AF6886EC55 for ; Mon, 19 Jul 2021 12:17:05 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org AF6886EC55 Received: by smtp16.mail.ru with esmtpa (envelope-from ) id 1m5POb-0004B9-01; Mon, 19 Jul 2021 12:17:05 +0300 To: Cc: References: In-Reply-To: Date: Mon, 19 Jul 2021 12:17:01 +0300 Message-ID: <18a301d77c7e$d5a9af70$80fd0e50$@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: AQD0dPzMRKuVIAksNaGzWjRUzQP0JQHh+zEvrQD0sFA= Content-Language: ru X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD941C43E597735A9C30A5AB0699C09BB51962E4FF0DD431C8A182A05F53808504079E748BBBAD25BB6EAF7B2E25A88E7BF910B6D7770FEA4C60091E70028273235 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7548C33FFD72831AFEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006379428F6EA0D091379EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BBCA57AF85F7723F281AEE72EC76050456EFE013B0B2D106FCC7F00164DA146DAFE8445B8C89999728AA50765F7900637F3E38EE449E3E2AE389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8744B801E316CB65FF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947CAC824117EA78743876E601842F6C81A12EF20D2F80756B5F7E9C4E3C761E06A776E601842F6C81A127C277FBC8AE2E8BC25E96735524CBED3AA81AA40904B5D9DBF02ECDB25306B2201CA6A4E26CD07C3BBE47FD9DD3FB595F5C1EE8F4F765FC72CEEB2601E22B093A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E735BA6625F88748EAEFC4224003CC83647689D4C264860C145E X-C1DE0DAB: 0D63561A33F958A59E185F84F81A974F841C3683DC4B1C33EB2A2D4DB84665F7D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7501A9DF589746230F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34D7D5115130EFC8246150E6E8554BBE5259B1B2437C2F61325BB07E6B0E5F34635CE178384686FDAA1D7E09C32AA3244CB58473B4C975F4437DFA2E7A83E2A74C33C9DC155518937F729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj+8+KVR9NZrHdMVkjWgoQPQ== X-Mailru-Sender: 9B1A9A1451179B430DCE2B318EA415620A2AB7B6557A3412CFC4F405438CEAB0342CD0BA774DB6A95C2808D6142752370A8ED71B308007E3DC85537438B7E1A423D748DE48713E689437F6177E88F7363CDA0F3B3F5B9367 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v2 3/4] sql: introduce mem_cmp_scalar() 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, yup, it's much simpler now! : From: imeevma@tarantool.org : Subject: [PATCH v2 3/4] sql: introduce mem_cmp_scalar() :=20 : This patch introduces the mem_cmp_scalar() function that compares two : MEMs using SCALAR rules. MEMs must be scalars. Prior to this patch, = there : was a : function that used SCALAR rules to compare two MEMs, but its design = became : overly complex as new types appeared. :=20 : Part of #6164 : @@ -2030,6 +2068,36 @@ mem_cmp_uuid(const struct Mem *a, const struct = Mem : *b, int *result) : return 0; : } :=20 : +int : +mem_cmp_scalar(const struct Mem *a, const struct Mem *b, int *result, : + const struct coll *coll) : +{ : + enum mem_class class_a =3D mem_type_class(a->type); : + enum mem_class class_b =3D mem_type_class(b->type); : + if (class_a !=3D class_b) { : + *result =3D class_a - class_b; : + return 0; : + } : + switch (class_a) { : + case MEM_CLASS_NULL: : + *result =3D 0; : + return 0; : + case MEM_CLASS_BOOL: : + return mem_cmp_bool(a, b, result); : + case MEM_CLASS_NUMBER: : + return mem_cmp_num(a, b, result); : + case MEM_CLASS_STR: : + return mem_cmp_str(a, b, result, coll); : + case MEM_CLASS_BIN: : + return mem_cmp_bin(a, b, result); : + case MEM_CLASS_UUID: : + return mem_cmp_uuid(a, b, result); : + default: : + unreachable(); : + } : + return 0; : +} : + : /* : * Both *pMem1 and *pMem2 contain string values. Compare the two = values : * using the collation sequence pColl. As usual, return a negative , = zero : @@ -2463,82 +2531,6 @@ sqlVdbeMemTooBig(Mem * p) : return 0; : } :=20 : -/* : - * Compare the values contained by the two memory cells, returning : - * negative, zero or positive if pMem1 is less than, equal to, or = greater : - * than pMem2. Sorting order is NULL's first, followed by numbers = (integers : - * and reals) sorted numerically, followed by text ordered by the = collating : - * sequence pColl and finally blob's ordered by memcmp(). : - * : - * Two NULL values are considered equal by this function. : - */ : -int : -sqlMemCompare(const Mem * pMem1, const Mem * pMem2, const struct coll = * : pColl) : -{ : - int res; : - : - enum mem_type type1 =3D pMem1->type; : - enum mem_type type2 =3D pMem2->type; : - : - /* If one value is NULL, it is less than the other. If both values : - * are NULL, return 0. : - */ : - if (((type1 | type2) & MEM_TYPE_NULL) !=3D 0) : - return (int)(type2 =3D=3D MEM_TYPE_NULL) - : - (int)(type1 =3D=3D MEM_TYPE_NULL); : - : - if (((type1 | type2) & MEM_TYPE_BOOL) !=3D 0) { : - if ((type1 & type2 & MEM_TYPE_BOOL) !=3D 0) { : - if (pMem1->u.b =3D=3D pMem2->u.b) : - return 0; : - if (pMem1->u.b) : - return 1; : - return -1; : - } : - if (type2 =3D=3D MEM_TYPE_BOOL) : - return +1; : - return -1; : - } : - : - if (((type1 | type2) & MEM_TYPE_UUID) !=3D 0) { : - if (mem_cmp_uuid(pMem1, pMem2, &res) =3D=3D 0) : - return res; : - if (type1 !=3D MEM_TYPE_UUID) : - return +1; : - return -1; : - } : - : - /* At least one of the two values is a number : - */ : - if (((type1 | type2) & : - (MEM_TYPE_INT | MEM_TYPE_UINT | MEM_TYPE_DOUBLE)) !=3D 0) { : - if (!mem_is_num(pMem1)) : - return +1; : - if (!mem_is_num(pMem2)) : - return -1; : - mem_cmp_num(pMem1, pMem2, &res); : - return res; : - } : - : - /* If one value is a string and the other is a blob, the string is : less. : - * If both are strings, compare using the collating functions. : - */ : - if (((type1 | type2) & MEM_TYPE_STR) !=3D 0) { : - if (type1 !=3D MEM_TYPE_STR) { : - return 1; : - } : - if (type2 !=3D MEM_TYPE_STR) { : - return -1; : - } : - mem_cmp_str(pMem1, pMem2, &res, pColl); : - return res; : - } : - : - /* Both values must be blobs. Compare using memcmp(). */ : - mem_cmp_bin(pMem1, pMem2, &res); : - return res; : -} : - : int : sql_vdbemem_finalize(struct Mem *mem, struct func *func) : {