From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 53ECB1FAA9 for ; Wed, 10 Jul 2019 07:01:15 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Gtvyn8MAjznN for ; Wed, 10 Jul 2019 07:01:15 -0400 (EDT) Received: from smtp60.i.mail.ru (smtp60.i.mail.ru [217.69.128.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id E8CA2248D5 for ; Wed, 10 Jul 2019 07:01:14 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v2 04/12] sql: rework LIKE case-insensitive mode Date: Wed, 10 Jul 2019 14:01:03 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org, korablev@tarantool.org Cc: kostja@tarantool.org, Kirill Shcherbatov The case_sensitive_like pragma used to process a strange way: on each call a new instance of function having appropriate properties was created. Reworked legacy code with user session object to define this property there. The new approach allows to rework sql builtins machinery with further patches. Needed for #4113, #2200, #2233 --- src/box/sql/func.c | 41 +++++------------------------------------ src/box/sql/pragma.c | 8 -------- src/box/sql/sqlInt.h | 3 --- 3 files changed, 5 insertions(+), 47 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 580571709..ae75a1c3c 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -39,6 +39,7 @@ #include "version.h" #include "coll/coll.h" #include "tarantoolInt.h" +#include "box/session.h" #include #include #include @@ -885,7 +886,8 @@ likeFunc(sql_context *context, int argc, sql_value **argv) u32 escape = SQL_END_OF_STRING; int nPat; sql *db = sql_context_db_handle(context); - int is_like_ci = SQL_PTR_TO_INT(sql_user_data(context)); + bool is_like_ci = + (current_session()->sql_flags & LIKE_CASE_SENS_FLAG) == 0; int rhs_type = sql_value_type(argv[0]); int lhs_type = sql_value_type(argv[1]); @@ -1704,40 +1706,6 @@ groupConcatFinalize(sql_context * context) } } -/* - * Set the LIKEOPT flag on the 2-argument function with the given name. - */ -static void -setLikeOptFlag(sql * db, const char *zName, u8 flagVal) -{ - FuncDef *pDef; - pDef = sqlFindFunction(db, zName, 2, 0); - if (ALWAYS(pDef)) { - pDef->funcFlags |= flagVal; - } -} - -/** - * Register the built-in LIKE function. - */ -void -sqlRegisterLikeFunctions(sql *db, int is_case_insensitive) -{ - /* - * FIXME: after introducing type LIKE must - * return that type: TRUE if the string matches the - * supplied pattern and FALSE otherwise. - */ - int *is_like_ci = SQL_INT_TO_PTR(is_case_insensitive); - sqlCreateFunc(db, "LIKE", FIELD_TYPE_BOOLEAN, 2, 0, - is_like_ci, likeFunc, 0, 0, 0); - sqlCreateFunc(db, "LIKE", FIELD_TYPE_BOOLEAN, 3, 0, - is_like_ci, likeFunc, 0, 0, 0); - setLikeOptFlag(db, "LIKE", - !(is_case_insensitive) ? (SQL_FUNC_LIKE | - SQL_FUNC_CASE) : SQL_FUNC_LIKE); -} - int sql_is_like_func(struct sql *db, struct Expr *expr, int *is_like_ci) { @@ -1749,7 +1717,8 @@ sql_is_like_func(struct sql *db, struct Expr *expr, int *is_like_ci) assert(func != NULL); if ((func->funcFlags & SQL_FUNC_LIKE) == 0) return 0; - *is_like_ci = (func->funcFlags & SQL_FUNC_CASE) == 0; + *is_like_ci = + (current_session()->sql_flags & LIKE_CASE_SENS_FLAG) == 0; return 1; } diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c index 53524b617..1fd74c0a3 100644 --- a/src/box/sql/pragma.c +++ b/src/box/sql/pragma.c @@ -484,17 +484,9 @@ sqlPragma(Parse * pParse, Token * pId, /* First part of [schema.]id field */ sqlParserTrace(0, 0); } #endif - /* - * Reinstall the LIKE and functions. The - * variant of LIKE * used will be case - * sensitive or not depending on the RHS. - */ - if (mask == LIKE_CASE_SENS_FLAG) - sqlRegisterLikeFunctions(db, !is_pragma_set); } break; } - case PragTyp_TABLE_INFO: sql_pragma_table_info(pParse, zRight); break; diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index 9f439fb07..7bcbb4eb1 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -1271,7 +1271,6 @@ struct FuncDestructor { * SQL_FUNC_CONSTANT == sql_DETERMINISTIC from the API */ #define SQL_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */ -#define SQL_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */ #define SQL_FUNC_EPHEM 0x0010 /* Ephemeral. Delete with VDBE */ #define SQL_FUNC_NEEDCOLL 0x0020 /* sqlGetFuncCollSeq() might be called. * The flag is set when the collation @@ -4262,8 +4261,6 @@ sql_key_info_unref(struct sql_key_info *key_info); struct key_def * sql_key_info_to_key_def(struct sql_key_info *key_info); -void sqlRegisterLikeFunctions(sql *, int); - /** * Check if the function implements LIKE-style comparison & if it * is appropriate to apply a LIKE query optimization. -- 2.21.0