Tarantool development patches archive
 help / color / mirror / Atom feed
From: "n.pettik" <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Nikita Tatunov <n.tatunov@tarantool.org>,
	Alexander Turenko <alexander.turenko@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH 2/2] sql: remove GLOB from Tarantool
Date: Wed, 14 Nov 2018 17:16:52 +0300	[thread overview]
Message-ID: <086379A5-15D0-4D16-951E-5F5DBE852068@tarantool.org> (raw)
In-Reply-To: <20181113192305.v3uxbrp6ebqrb4gs@tkn_work_nb>



> On 13 Nov 2018, at 22:23, Alexander Turenko <alexander.turenko@tarantool.org> wrote:
> 
> Hi!
> 
> I gave some minor comments and I think I cannot add any value anymore.
> Nikita N., can you look into this patch?

>    Part of #3589
>    Part of #3572
>    Needed for #3251
>    Needed for #3334

Why this patch is ’needed for’ but comes after
these issues are closed by previous patch?

Also I don’t like the fact that your patch not only removes
GLOB function, but also changes some user-visible interface.
It still would be OK if you wrote about it in commit message
or in doc request. For instance, as I understand from code,
percent symbol (‘%’) now works as star (‘*’) did before.

Personally I don’t like many code style fixes because
they obfuscate patch and make it complicate to review.
What is more, they don’t deal with all problems: they
partially fix comments but don’t fix naming. It looks awful.
But since it is done and two reviewers already gave their
OK I guess it would be irrational to start from scratch.

Finally, to be honest I didn’t review ALL changed tests.
I looked through and they seem to be OK.

I’ve pushed also several non-functional fixes -
see branch np/gh-3251-where-like-hangs.

Let's assume this as formal LGTM.

diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index f0baf3db0..c3d3ccfb2 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -1674,12 +1674,6 @@ setLikeOptFlag(sqlite3 * db, const char *zName, u8 flagVal)
 
 /**
  * Register the built-in LIKE function.
- *
- * @param db database structure.
- * @param is_case_sensitive whether like should be case sensitive
- *                         or not.
- *
- * @retval none.
  */
 void
 sqlite3RegisterLikeFunctions(sqlite3 *db, int is_case_insensitive)
@@ -1699,30 +1693,18 @@ sqlite3RegisterLikeFunctions(sqlite3 *db, int is_case_insensitive)
                       SQLITE_FUNC_CASE) : SQLITE_FUNC_LIKE);
 }
 
-/**
- * Check if the function implements LIKE-style comparison & if it
- * is appropriate to apply a LIKE query optimization.
- *
- * @param db database structure.
- * @param pExpr pointer to a function-implementing expression.
- * @param is_like_ci true if LIKE is case insensitive.
- *
- * @retval 0 if it's appropriate to apply optimization.
- *         1 if it's not.
- */
 int
-sql_is_like_func(sqlite3 *db, Expr *pExpr, int *is_like_ci)
+sql_is_like_func(struct sqlite3 *db, struct Expr *expr, bool *is_like_ci)
 {
-       FuncDef *pDef;
-       if (pExpr->op != TK_FUNCTION || !pExpr->x.pList ||
-           pExpr->x.pList->nExpr != 2)
+       if (expr->op != TK_FUNCTION || !expr->x.pList ||
+           expr->x.pList->nExpr != 2)
                return 0;
-       assert(!ExprHasProperty(pExpr, EP_xIsSelect));
-       pDef = sqlite3FindFunction(db, pExpr->u.zToken, 2, 0);
-       if (NEVER(pDef == 0) || (pDef->funcFlags & SQLITE_FUNC_LIKE) == 0) {
+       assert(!ExprHasProperty(expr, EP_xIsSelect));
+       struct FuncDef *func = sqlite3FindFunction(db, expr->u.zToken, 2, 0);
+       assert(func != NULL);
+       if ((func->funcFlags & SQLITE_FUNC_LIKE) == 0)
                return 0;
-       }
-       *is_like_ci = (pDef->funcFlags & SQLITE_FUNC_CASE) == 0;
+       *is_like_ci = (func->funcFlags & SQLITE_FUNC_CASE) == 0;
        return 1;
 }
 
diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h
index 07e83e444..af124b731 100644
--- a/src/box/sql/sqliteInt.h
+++ b/src/box/sql/sqliteInt.h
@@ -4552,7 +4552,20 @@ struct key_def *
 sql_key_info_to_key_def(struct sql_key_info *key_info);
 
 void sqlite3RegisterLikeFunctions(sqlite3 *, int);
-int sql_is_like_func(sqlite3 *, Expr *, int *);
+
+/**
+ * Check if the function implements LIKE-style comparison & if it
+ * is appropriate to apply a LIKE query optimization.
+ *
+ * @param db database structure.
+ * @param pExpr pointer to a function-implementing expression.
+ * @param[out] is_like_ci true if LIKE is case insensitive.
+ *
+ * @retval 1 if LIKE optimization can be used, 0 otherwise.
+ */
+int
+sql_is_like_func(struct sqlite3 *db, struct Expr *expr, bool *is_like_ci);
+
 int sqlite3CreateFunc(sqlite3 *, const char *, enum affinity_type,
                      int, int, void *,
                      void (*)(sqlite3_context *, int, sqlite3_value **),
diff --git a/src/box/sql/whereexpr.c b/src/box/sql/whereexpr.c
index 5f6344405..5d6b04418 100644
--- a/src/box/sql/whereexpr.c
+++ b/src/box/sql/whereexpr.c
@@ -232,21 +232,17 @@ operatorMask(int op)
  * @param pParse      Parsing and code generating context.
  * @param pExpr       Test this expression.
  * @param ppPrefix    Pointer to TK_STRING expression with
- *                   pattern prefix.
+ *                    pattern prefix.
  * @param pisComplete True if the only wildcard is '%' in the
- *                   last character.
+ *                    last character.
  * @param pnoCase     True if case insensitive.
  *
  * @retval True if the given expr is a LIKE operator & is
- *        optimizable using inequality constraints.
- *        False if not.
+ *         optimizable using inequality constraints.
  */
 static int
-is_like(Parse *pParse,
-       Expr *pExpr,
-       Expr **ppPrefix,
-       int *pisComplete,
-       int *pnoCase)
+like_optimization_is_valid(Parse *pParse, Expr *pExpr, Expr **ppPrefix,
+                          int *pisComplete, int *pnoCase)
 {
        /* String on RHS of LIKE operator. */
        const char *z = 0;
@@ -1158,17 +1154,16 @@ exprAnalyze(SrcList * pSrc,     /* the FROM clause */
         * is made all lowercase so that the bounds also work
         * when comparing BLOBs.
         */
-       if (pWC->op == TK_AND
-           && is_like(pParse, pExpr, &pStr1, &isComplete, &noCase)) {
-               /* LHS of LIKE operator */
+       if (pWC->op == TK_AND &&
+           like_optimization_is_valid(pParse, pExpr, &pStr1,
+                                      &isComplete, &noCase)) {
                Expr *pLeft;
-               /* Copy of pStr1 - RHS of LIKE operator */
+               /* Copy of pStr1 - RHS of LIKE operator. */
                Expr *pStr2;
                Expr *pNewExpr1;
                Expr *pNewExpr2;
                int idxNew1;
                int idxNew2;
-               /* Name of collating sequence */
                const char *zCollSeqName;
                const u16 wtFlags = TERM_LIKEOPT | TERM_VIRTUAL | TERM_DYNAMIC;
 
@@ -1179,7 +1174,7 @@ exprAnalyze(SrcList * pSrc,       /* the FROM clause */
                 * Convert the lower bound to upper-case and the
                 * upper bound to lower-case (upper-case is less
                 * than lower-case in ASCII) so that the range
-                * constraints also work for BLOBs
+                * constraints also work for BLOBs.
                 */
                if (noCase && !pParse->db->mallocFailed) {
                        int i;
diff --git a/test/sql-tap/e_expr.test.lua b/test/sql-tap/e_expr.test.lua
index f49810999..db44999a6 100755
--- a/test/sql-tap/e_expr.test.lua
+++ b/test/sql-tap/e_expr.test.lua
@@ -1264,7 +1264,6 @@ test:do_execsql_test(
 test:execsql [[
     CREATE TABLE tblname(cname INT PRIMARY KEY);
 ]]
-
 local function glob(args)
     return 1
 end

  reply	other threads:[~2018-11-14 14:16 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-16 17:00 [tarantool-patches] [PATCH v2 0/2] sql: pattern comparison fixes & GLOB removal N.Tatunov
2018-08-16 17:00 ` [tarantool-patches] [PATCH 1/2] sql: LIKE & GLOB pattern comparison issue N.Tatunov
2018-08-17  9:23   ` [tarantool-patches] " Alex Khatskevich
2018-08-17 11:17     ` Alexander Turenko
2018-08-17 11:42       ` Alex Khatskevich
2018-09-09 13:33         ` Nikita Tatunov
2018-09-10 22:20           ` Alex Khatskevich
2018-09-11  6:06             ` Nikita Tatunov
2018-09-11 10:06               ` Alex Khatskevich
2018-09-11 13:31                 ` Nikita Tatunov
2018-10-18 18:02                   ` Nikita Tatunov
2018-10-21  3:51                     ` Alexander Turenko
2018-10-26 15:19                       ` Nikita Tatunov
2018-10-29 13:01                         ` Alexander Turenko
2018-10-31  5:25                           ` Nikita Tatunov
2018-11-01 10:30                             ` Alexander Turenko
2018-11-14 14:16                               ` n.pettik
2018-11-14 17:06                                 ` Alexander Turenko
2018-08-16 17:00 ` [tarantool-patches] [PATCH 2/2] sql: remove GLOB from Tarantool N.Tatunov
2018-08-17  8:25   ` [tarantool-patches] " Alex Khatskevich
2018-08-17  8:49     ` n.pettik
2018-08-17  9:01       ` Alex Khatskevich
2018-08-17  9:20         ` n.pettik
2018-08-17  9:28           ` Alex Khatskevich
     [not found]     ` <04D02794-07A5-4146-9144-84EE720C8656@corp.mail.ru>
2018-08-17  8:53       ` Alex Khatskevich
2018-08-17 11:26     ` Alexander Turenko
2018-08-17 11:34       ` Alexander Turenko
2018-08-17 13:46     ` Nikita Tatunov
2018-09-09 14:57     ` Nikita Tatunov
2018-09-10 22:06       ` Alex Khatskevich
2018-09-11  7:38         ` Nikita Tatunov
2018-09-11 10:11           ` Alexander Turenko
2018-09-11 10:22             ` Alex Khatskevich
2018-09-11 12:03           ` Alex Khatskevich
2018-10-18 20:28             ` Nikita Tatunov
2018-10-21  3:48               ` Alexander Turenko
2018-10-26 15:21                 ` Nikita Tatunov
2018-10-29 12:15                   ` Alexander Turenko
2018-11-08 15:09                     ` Nikita Tatunov
2018-11-09 12:18                       ` Alexander Turenko
2018-11-10  3:38                         ` Nikita Tatunov
2018-11-13 19:23                           ` Alexander Turenko
2018-11-14 14:16                             ` n.pettik [this message]
2018-11-14 17:41                               ` Alexander Turenko
2018-11-14 21:48                                 ` n.pettik
2018-11-15  4:57 ` [tarantool-patches] Re: [PATCH v2 0/2] sql: pattern comparison fixes & GLOB removal 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=086379A5-15D0-4D16-951E-5F5DBE852068@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=alexander.turenko@tarantool.org \
    --cc=n.tatunov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH 2/2] sql: remove GLOB from Tarantool' \
    /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