Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org, korablev@tarantool.org
Cc: kostja@tarantool.org, Kirill Shcherbatov <kshcherbatov@tarantool.org>
Subject: [tarantool-patches] [PATCH v2 04/12] sql: rework LIKE case-insensitive mode
Date: Wed, 10 Jul 2019 14:01:03 +0300	[thread overview]
Message-ID: <b49a80a94725f639665fea567e87080debdaeb9f.1562756438.git.kshcherbatov@tarantool.org> (raw)
In-Reply-To: <cover.1562756438.git.kshcherbatov@tarantool.org>

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 <unicode/ustring.h>
 #include <unicode/ucasemap.h>
 #include <unicode/ucnv.h>
@@ -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 <BOOLEAN> 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

  parent reply	other threads:[~2019-07-10 11:01 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-10 11:00 [tarantool-patches] [PATCH v2 00/12] sql: uniform SQL and Lua functions subsystem Kirill Shcherbatov
2019-07-10 11:00 ` [tarantool-patches] [PATCH v2 01/12] sql: get rid of SOUNDEX, MATCH Kirill Shcherbatov
2019-07-10 18:45   ` [tarantool-patches] " Konstantin Osipov
2019-07-12  8:44   ` Kirill Yukhin
2019-07-10 11:00 ` [tarantool-patches] [PATCH v2 10/12] sql: refactor builtins signatures with port Kirill Shcherbatov
2019-07-10 18:47   ` [tarantool-patches] " Konstantin Osipov
2019-07-11  7:33     ` Kirill Shcherbatov
2019-07-10 11:00 ` [tarantool-patches] [PATCH v2 11/12] box: use own vtab per each function object Kirill Shcherbatov
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 12/12] sql: use schema's func hash instead of FuncDef hash Kirill Shcherbatov
2019-07-10 20:22   ` [tarantool-patches] " Konstantin Osipov
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 02/12] sql: get rid of LIKELY, UNLIKELY and LIKEHOOD Kirill Shcherbatov
2019-07-10 19:02   ` [tarantool-patches] " Konstantin Osipov
2019-07-11  7:38     ` Kirill Shcherbatov
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 03/12] sql: put analyze helpers to FuncDef cache Kirill Shcherbatov
2019-07-10 19:04   ` [tarantool-patches] " Konstantin Osipov
2019-07-12  8:47   ` Kirill Yukhin
2019-07-10 11:01 ` Kirill Shcherbatov [this message]
2019-07-10 19:09   ` [tarantool-patches] Re: [PATCH v2 04/12] sql: rework LIKE case-insensitive mode Konstantin Osipov
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 05/12] sql: replace bool is_derived_coll marker with flag Kirill Shcherbatov
2019-07-10 19:10   ` [tarantool-patches] " Konstantin Osipov
2019-07-12  8:48   ` Kirill Yukhin
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 06/12] sql: remove SQL_PreferBuiltin flag Kirill Shcherbatov
2019-07-10 19:11   ` [tarantool-patches] " Konstantin Osipov
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 07/12] sql: move LIKE UConverter object to collation library Kirill Shcherbatov
2019-07-12  8:49   ` [tarantool-patches] " Kirill Yukhin
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 08/12] sql: rfc for SQL and Lua functions Kirill Shcherbatov
2019-07-10 19:17   ` [tarantool-patches] " Konstantin Osipov
2019-07-10 19:18     ` Konstantin Osipov
2019-07-11  7:40       ` Kirill Shcherbatov
2019-07-11 13:59   ` Kirill Yukhin
2019-07-10 11:01 ` [tarantool-patches] [PATCH v2 09/12] box: introduce Lua persistent functions Kirill Shcherbatov
2019-07-10 19:26   ` [tarantool-patches] " Konstantin Osipov
2019-07-12 21:49   ` Konstantin Osipov
2019-07-13 13:55     ` Kirill Yukhin
2019-07-13 14:17       ` Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b49a80a94725f639665fea567e87080debdaeb9f.1562756438.git.kshcherbatov@tarantool.org \
    --to=kshcherbatov@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH v2 04/12] sql: rework LIKE case-insensitive mode' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox