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 EDCB770296; Thu, 11 Nov 2021 13:49:32 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EDCB770296 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1636627773; bh=1xD1qMf4d6pTUHIsFdk21Qhgd3exYzgwtdYQ8uRuy0o=; h=To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=CObBM5HpWMm5zs1+pOOfDbww762Fcq1ysFUDv+OZ5BhSbX66ud/99AVQudH2sldAn 1+dHL+zIhv/KtPgMigGxr+r7S9Xroa6Afk5PHHhYHpIhwn+LYNJvwxWaC4kndRGYF9 5qahlQZEd5T6R9AZl1eg4EXM5+m23VlJ3VtpaF1c= 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 7D6136CE3F for ; Thu, 11 Nov 2021 13:45:42 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7D6136CE3F Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1ml7aP-000361-As; Thu, 11 Nov 2021 13:45:41 +0300 To: kyukhin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Thu, 11 Nov 2021 13:45:41 +0300 Message-Id: <92870d2b9586e42cce84bf0a5dfef9154e5edd59.1636627366.git.imeevma@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9731B3922EC0639794B1FA730FFF2612B18842EFC24E0D5F400894C459B0CD1B94D05FC9138202DC693E4D85300C988E3BD7B9CED87D255676BC431959DD8AF3A X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE712EB008F780777E9EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637CAA352D56883AEE98638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D894FD0A7A74283B13BE898B67C8B1D8BB117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B62CFFCC7B69C47339089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C7E9FEBB9C11794A119FBCA061049347E0E1D77531BD8935A9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFCDE59DDCCE53AF2B699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34D7D5115130EFC8248200FD28F9AE4BD4F19A09D99A87E0BDC85558756380F3BD6E49098B2C83B8D11D7E09C32AA3244C216E7D155C7AF8F45565539D0EC53483B018FE5BB746DCD1729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj4t8MBgWr8bL1jGiaCvT8rg== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DC1E9F5066E80F708CA8677CCA681316383D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [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: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Part of #4145 --- src/box/sql/func.c | 51 ++++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 34 deletions(-) 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); } /** -- 2.25.1