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 8FE0F6ECE3; Mon, 1 Nov 2021 13:53:54 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8FE0F6ECE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1635764034; bh=hiDqGpc+erpDtYDWi9bEVTyTotxKMDeokS+/rLY7obo=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=xFDWYW6VDqiJtEZ0VolrKf39Lb7UySTYh4pnj5/WKBjwVYSC7zNYBdZkzyVUHNeoL Qm8ciyFTobCP9x7+utBmqGC021ibzHBjj8Fisrrklcg02h7VA59yFyC6oR9taZPMck 2HXD/lm0/AXGOHARRF59F2IsdPDNTQC+nEfJgC6U= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (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 00DD46ECE3 for ; Mon, 1 Nov 2021 13:53:52 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 00DD46ECE3 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mhUwq-0004Fo-9f; Mon, 01 Nov 2021 13:53:52 +0300 Date: Mon, 1 Nov 2021 13:53:51 +0300 To: Vladislav Shpilevoy , tarantool-patches@dev.tarantool.org Message-ID: <20211101105351.GA228918@tarantool.org> References: <873f9256f524e841ae7489ca21933ce16a9a34e0.1633105483.git.imeevma@gmail.com> <762d321c-004d-4ef9-7d8c-1314c19fc673@tarantool.org> <20211020171938.GG203963@tarantool.org> <20211101104851.GF227579@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20211101104851.GF227579@tarantool.org> X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD98893113B6235BE9154FDE3298F0A37FC272DDC0DDA52D3DE182A05F538085040748D19943AB3C27A07FB2B9A5BDA028A02C29CFEF0A7F8891137FBF6EE95E400 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE712EB008F780777E9EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006379108F895B68B2FFD8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8DDF4DF4FC2C71D222913FC861D6E6CF5117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B66F6A3E018CF4DC80089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A59AAF40B2033493D2415BC6D13EC45064E7E2A095615EA1FDD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA752DA3D96DA0CEF5C48E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34951738D4D62E58A4498E193B6EC9B516B098BD26F3C81718647342279AB8FD9D3AFBB3C1F83DE3471D7E09C32AA3244C98C5C778CCB8A0320485ABE462293CB51DD47778AE04E04D729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojsm8N/O5xSHSXP9SBEJ5RIA== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D046FD926E3D34070B5DA6C423C2285B383D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v1 8/8] sql: refactor LIKE() function 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: Mergen Imeev via Tarantool-patches Reply-To: Mergen Imeev Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" I am sorry, I uncluded wrong diff and patch. Diff and patch below. On Mon, Nov 01, 2021 at 01:48:51PM +0300, Mergen Imeev via Tarantool-patches wrote: > Thank you for the review! I replaced ucnv_getNextUChar() by U8_NEXT(). Diff and > new patch below. > > On Wed, Oct 20, 2021 at 08:19:38PM +0300, Mergen Imeev via Tarantool-patches wrote: > > Diff: diff --git a/src/box/sql/func.c b/src/box/sql/func.c index b055c7515..868d51145 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -1301,11 +1301,11 @@ likeFunc(sql_context *context, int argc, struct Mem *argv) * single UTF-8 character. Otherwise, return an * error. */ - UErrorCode err = U_ZERO_ERROR; - const char *pos = argv[2].z; - const char *end = argv[2].z + argv[2].n; - escape = ucnv_getNextUChar(icu_utf8_conv, &pos, end, &err); - if (pos != end || err != U_ZERO_ERROR) { + const char *str = argv[2].z; + int pos = 0; + int end = argv[2].n; + U8_NEXT((uint8_t *)str, pos, end, escape); + if (pos != end || end == 0) { diag_set(ClientError, ER_SQL_EXECUTE, "ESCAPE "\ "expression must be a single character"); context->is_aborted = true; Patch: commit 43d41680d9198a098f866ba7669739221952f446 Author: Mergen Imeev Date: Mon Sep 27 19:29:28 2021 +0300 sql: refactor LIKE() function Part of #4145 diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 7e71a757b..868d51145 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -1271,63 +1271,46 @@ likeFunc(sql_context *context, int argc, struct Mem *argv) { u32 escape = SQL_END_OF_STRING; int nPat; - if (argc != 2 && argc != 3) { - diag_set(ClientError, ER_FUNC_WRONG_ARG_COUNT, - "LIKE", "2 or 3", argc); - context->is_aborted = true; - return; - } - sql *db = sql_context_db_handle(context); - int rhs_type = sql_value_type(&argv[0]); - int lhs_type = sql_value_type(&argv[1]); - - if (lhs_type != MP_STR || rhs_type != MP_STR) { - if (lhs_type == MP_NIL || rhs_type == MP_NIL) - return; - const char *str = rhs_type != MP_STR ? - mem_str(&argv[0]) : mem_str(&argv[1]); - diag_set(ClientError, ER_INCONSISTENT_TYPES, "string", str); - context->is_aborted = true; + assert(argc == 2 || argc == 3); + if (mem_is_any_null(&argv[0], &argv[1])) return; - } - const char *zB = mem_as_str0(&argv[0]); - const char *zA = mem_as_str0(&argv[1]); - const char *zB_end = zB + mem_len_unsafe(&argv[0]); - const char *zA_end = zA + mem_len_unsafe(&argv[1]); + assert(mem_is_str(&argv[0]) && mem_is_str(&argv[1])); + const char *zB = argv[0].z; + const char *zA = argv[1].z; + const char *zB_end = zB + argv[0].n; + const char *zA_end = zA + argv[1].n; /* * Limit the length of the LIKE pattern to avoid problems * of deep recursion and N*N behavior in * sql_utf8_pattern_compare(). */ - nPat = mem_len_unsafe(&argv[0]); - testcase(nPat == db->aLimit[SQL_LIMIT_LIKE_PATTERN_LENGTH]); - testcase(nPat == db->aLimit[SQL_LIMIT_LIKE_PATTERN_LENGTH] + 1); - if (nPat > db->aLimit[SQL_LIMIT_LIKE_PATTERN_LENGTH]) { + nPat = argv[0].n; + if (nPat > sql_get()->aLimit[SQL_LIMIT_LIKE_PATTERN_LENGTH]) { diag_set(ClientError, ER_SQL_EXECUTE, "LIKE pattern is too "\ "complex"); context->is_aborted = true; return; } - /* Encoding did not change */ - assert(zB == mem_as_str0(&argv[0])); if (argc == 3) { + if (mem_is_null(&argv[2])) + return; /* * The escape character string must consist of a * single UTF-8 character. Otherwise, return an * error. */ - const unsigned char *zEsc = mem_as_ustr(&argv[2]); - if (zEsc == 0) - return; - if (sql_utf8_char_count(zEsc, mem_len_unsafe(&argv[2])) != 1) { + const char *str = argv[2].z; + int pos = 0; + int end = argv[2].n; + U8_NEXT((uint8_t *)str, pos, end, escape); + if (pos != end || end == 0) { diag_set(ClientError, ER_SQL_EXECUTE, "ESCAPE "\ "expression must be a single character"); context->is_aborted = true; return; } - escape = sqlUtf8Read(&zEsc); } if (!zA || !zB) return; @@ -1342,7 +1325,7 @@ likeFunc(sql_context *context, int argc, struct Mem *argv) context->is_aborted = true; return; } - sql_result_bool(context, res == MATCH); + mem_set_bool(context->pOut, res == MATCH); } /**