Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH 0/3] Make LIKE accept only arguments of type TEXT
@ 2019-03-09 16:59 Nikita Pettik
  2019-03-09 17:00 ` [tarantool-patches] [PATCH 1/3] sql: remove SQL_LIKE_DOESNT_MATCH_BLOBS Nikita Pettik
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Nikita Pettik @ 2019-03-09 16:59 UTC (permalink / raw)
  To: tarantool-patches; +Cc: v.shpilevoy, Nikita Pettik

First two patches simply remove unnecessary macro and code connected
with it. Third one - disallows arguments of LIKE be of different
from text-like types.

Branch: https://github.com/tarantool/tarantool/tree/np/gh-3954-disallow-blob-in-like
Issue: https://github.com/tarantool/tarantool/issues/3954

Nikita Pettik (3):
  sql: remove SQL_LIKE_DOESNT_MATCH_BLOBS
  sql: remove sql_like_count global counter
  sql: make LIKE accept only TEXT arguments

 src/box/sql/func.c            | 34 +++++++++-----------
 src/box/sql/sqlInt.h          |  2 --
 src/box/sql/vdbe.c            | 14 +--------
 src/box/sql/vdbeInt.h         |  6 ++++
 src/box/sql/where.c           |  8 -----
 src/box/sql/whereInt.h        |  4 ---
 src/box/sql/wherecode.c       | 73 -------------------------------------------
 test/sql-tap/tkt1537.test.lua |  4 +--
 test/sql/types.result         | 45 ++++++++++++++++++++++++++
 test/sql/types.test.lua       | 15 +++++++++
 10 files changed, 84 insertions(+), 121 deletions(-)

-- 
2.15.1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [tarantool-patches] [PATCH 1/3] sql: remove SQL_LIKE_DOESNT_MATCH_BLOBS
  2019-03-09 16:59 [tarantool-patches] [PATCH 0/3] Make LIKE accept only arguments of type TEXT Nikita Pettik
@ 2019-03-09 17:00 ` Nikita Pettik
  2019-03-11  8:07   ` [tarantool-patches] " Konstantin Osipov
  2019-03-09 17:00 ` [tarantool-patches] [PATCH 2/3] sql: remove sql_like_count global counter Nikita Pettik
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Nikita Pettik @ 2019-03-09 17:00 UTC (permalink / raw)
  To: tarantool-patches; +Cc: v.shpilevoy, Nikita Pettik

We are going to always throw an error if value of BLOB type gets to LIKE
arguments, so code under is macro is not needed anymore.

Part of #3954
---
 src/box/sql/func.c      |  2 --
 src/box/sql/sqlInt.h    |  2 --
 src/box/sql/vdbe.c      |  8 ------
 src/box/sql/where.c     |  8 ------
 src/box/sql/whereInt.h  |  4 ---
 src/box/sql/wherecode.c | 73 -------------------------------------------------
 6 files changed, 97 deletions(-)

diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 2de6ef5ce..a0df830f6 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -826,7 +826,6 @@ likeFunc(sql_context *context, int argc, sql_value **argv)
 	sql *db = sql_context_db_handle(context);
 	int is_like_ci = SQL_PTR_TO_INT(sql_user_data(context));
 
-#ifdef SQL_LIKE_DOESNT_MATCH_BLOBS
 	if (sql_value_type(argv[0]) == SQL_BLOB
 	    || sql_value_type(argv[1]) == SQL_BLOB) {
 #ifdef SQL_TEST
@@ -835,7 +834,6 @@ likeFunc(sql_context *context, int argc, sql_value **argv)
 		sql_result_int(context, 0);
 		return;
 	}
-#endif
 	const char *zB = (const char *) sql_value_text(argv[0]);
 	const char *zA = (const char *) sql_value_text(argv[1]);
 	const char *zB_end = zB + sql_value_bytes(argv[0]);
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 1d8fae5b0..c1974d181 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -291,8 +291,6 @@ void sqlCoverage(int);
  */
 #define IS_BIG_INT(X)  (((X)&~(i64)0xffffffff)!=0)
 
-#define SQL_LIKE_DOESNT_MATCH_BLOBS
-
 #include "hash.h"
 #include "parse.h"
 #include <stdio.h>
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index c1da9a4aa..d66fdd1f3 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -1201,14 +1201,6 @@ case OP_String: {          /* out2 */
 	pOut->z = pOp->p4.z;
 	pOut->n = pOp->p1;
 	UPDATE_MAX_BLOBSIZE(pOut);
-#ifndef SQL_LIKE_DOESNT_MATCH_BLOBS
-	if (pOp->p3>0) {
-		assert(pOp->p3<=(p->nMem+1 - p->nCursor));
-		pIn3 = &aMem[pOp->p3];
-		assert(pIn3->flags & MEM_Int);
-		if (pIn3->u.i==pOp->p5) pOut->flags = MEM_Blob|MEM_Static|MEM_Term;
-	}
-#endif
 	break;
 }
 
diff --git a/src/box/sql/where.c b/src/box/sql/where.c
index 5a3c9be1a..b46b7c315 100644
--- a/src/box/sql/where.c
+++ b/src/box/sql/where.c
@@ -4778,14 +4778,6 @@ sqlWhereEnd(WhereInfo * pWInfo)
 			sqlVdbeJumpHere(v, pLevel->addrSkip);
 			sqlVdbeJumpHere(v, pLevel->addrSkip - 2);
 		}
-#ifndef SQL_LIKE_DOESNT_MATCH_BLOBS
-		if (pLevel->addrLikeRep) {
-			sqlVdbeAddOp2(v, OP_DecrJumpZero,
-					  (int)(pLevel->iLikeRepCntr >> 1),
-					  pLevel->addrLikeRep);
-			VdbeCoverage(v);
-		}
-#endif
 		if (pLevel->iLeftJoin) {
 			int ws = pLoop->wsFlags;
 			addr =
diff --git a/src/box/sql/whereInt.h b/src/box/sql/whereInt.h
index 1f4b22abb..47430aef1 100644
--- a/src/box/sql/whereInt.h
+++ b/src/box/sql/whereInt.h
@@ -86,10 +86,6 @@ struct WhereLevel {
 	int addrCont;		/* Jump here to continue with the next loop cycle */
 	int addrFirst;		/* First instruction of interior of the loop */
 	int addrBody;		/* Beginning of the body of this loop */
-#ifndef SQL_LIKE_DOESNT_MATCH_BLOBS
-	u32 iLikeRepCntr;	/* LIKE range processing counter register (times 2) */
-	int addrLikeRep;	/* LIKE range processing address */
-#endif
 	u8 iFrom;		/* Which entry in the FROM clause */
 	u8 op, p3, p5;		/* Opcode, P3 & P5 of the opcode that ends the loop */
 	int p1, p2;		/* Operands of the opcode used to ends the loop */
diff --git a/src/box/sql/wherecode.c b/src/box/sql/wherecode.c
index 018fd8a28..f7b604f6a 100644
--- a/src/box/sql/wherecode.c
+++ b/src/box/sql/wherecode.c
@@ -785,44 +785,6 @@ codeAllEqualityTerms(Parse * pParse,	/* Parsing context */
 	return regBase;
 }
 
-#ifndef SQL_LIKE_DOESNT_MATCH_BLOBS
-/*
- * If the most recently coded instruction is a constant range constraint
- * (a string literal) that originated from the LIKE optimization, then
- * set P3 and P5 on the OP_String opcode so that the string will be cast
- * to a BLOB at appropriate times.
- *
- * The LIKE optimization trys to evaluate "x LIKE 'abc%'" as a range
- * expression: "x>='ABC' AND x<'abd'".  But this requires that the range
- * scan loop run twice, once for strings and a second time for BLOBs.
- * The OP_String opcodes on the second pass convert the upper and lower
- * bound string constants to blobs.  This routine makes the necessary changes
- * to the OP_String opcodes for that to happen.
- *
- * Except, of course, if SQL_LIKE_DOESNT_MATCH_BLOBS is defined, then
- * only the one pass through the string space is required, so this routine
- * becomes a no-op.
- */
-static void
-whereLikeOptimizationStringFixup(Vdbe * v,		/* prepared statement under construction */
-				 WhereLevel * pLevel,	/* The loop that contains the LIKE operator */
-				 WhereTerm * pTerm)	/* The upper or lower bound just coded */
-{
-	if (pTerm->wtFlags & TERM_LIKEOPT) {
-		VdbeOp *pOp;
-		assert(pLevel->iLikeRepCntr > 0);
-		pOp = sqlVdbeGetOp(v, -1);
-		assert(pOp != 0);
-		assert(pOp->opcode == OP_String8
-		       || pTerm->pWC->pWInfo->pParse->db->mallocFailed);
-		pOp->p3 = (int)(pLevel->iLikeRepCntr >> 1);	/* Register holding counter */
-		pOp->p5 = (u8) (pLevel->iLikeRepCntr & 1);	/* ASC or DESC */
-	}
-}
-#else
-#define whereLikeOptimizationStringFixup(A,B,C)
-#endif
-
 /*
  * If the expression passed as the second argument is a vector, generate
  * code to write the first nReg elements of the vector into an array
@@ -1056,29 +1018,6 @@ sqlWhereCodeOneLoopStart(WhereInfo * pWInfo,	/* Complete information about the W
 		if (pLoop->wsFlags & WHERE_TOP_LIMIT) {
 			pRangeEnd = pLoop->aLTerm[j++];
 			nExtraReg = MAX(nExtraReg, pLoop->nTop);
-#ifndef SQL_LIKE_DOESNT_MATCH_BLOBS
-			if ((pRangeEnd->wtFlags & TERM_LIKEOPT) != 0) {
-				assert(pRangeStart != 0);	/* LIKE opt constraints */
-				assert(pRangeStart->wtFlags & TERM_LIKEOPT);	/* occur in pairs */
-				pLevel->iLikeRepCntr = (u32)++ pParse->nMem;
-				sqlVdbeAddOp2(v, OP_Integer, 1,
-						  (int)pLevel->iLikeRepCntr);
-				VdbeComment((v, "LIKE loop counter"));
-				pLevel->addrLikeRep = sqlVdbeCurrentAddr(v);
-				/* iLikeRepCntr actually stores 2x the counter register number.  The
-				 * bottom bit indicates whether the search order is ASC or DESC.
-				 */
-				testcase(bRev);
-				testcase(pIdx->aSortOrder[nEq] ==
-					 SORT_ORDER_DESC);
-				assert((bRev & ~1) == 0);
-				struct key_def *def = idx_def->key_def;
-				pLevel->iLikeRepCntr <<= 1;
-				pLevel->iLikeRepCntr |=
-					bRev ^ (def->parts[nEq].sort_order ==
-						SORT_ORDER_DESC);
-			}
-#endif
 			if (pRangeStart == 0) {
 				j = idx_def->key_def->parts[nEq].fieldno;
 				if (is_format_set &&
@@ -1133,8 +1072,6 @@ sqlWhereCodeOneLoopStart(WhereInfo * pWInfo,	/* Complete information about the W
 			Expr *pRight = pRangeStart->pExpr->pRight;
 			codeExprOrVector(pParse, pRight, regBase + nEq, nBtm);
 
-			whereLikeOptimizationStringFixup(v, pLevel,
-							 pRangeStart);
 			if ((pRangeStart->wtFlags & TERM_VNULL) == 0
 			    && sqlExprCanBeNull(pRight)) {
 				sqlVdbeAddOp2(v, OP_IsNull, regBase + nEq,
@@ -1232,7 +1169,6 @@ sqlWhereCodeOneLoopStart(WhereInfo * pWInfo,	/* Complete information about the W
 			Expr *pRight = pRangeEnd->pExpr->pRight;
 			sqlExprCacheRemove(pParse, regBase + nEq, 1);
 			codeExprOrVector(pParse, pRight, regBase + nEq, nTop);
-			whereLikeOptimizationStringFixup(v, pLevel, pRangeEnd);
 			if ((pRangeEnd->wtFlags & TERM_VNULL) == 0
 			    && sqlExprCanBeNull(pRight)) {
 				sqlVdbeAddOp2(v, OP_IsNull, regBase + nEq,
@@ -1672,16 +1608,7 @@ sqlWhereCodeOneLoopStart(WhereInfo * pWInfo,	/* Complete information about the W
 			 * for strings.  So do not skip the call to the function on the pass
 			 * that compares BLOBs.
 			 */
-#ifdef SQL_LIKE_DOESNT_MATCH_BLOBS
 			continue;
-#else
-			u32 x = pLevel->iLikeRepCntr;
-			assert(x > 0);
-			skipLikeAddr =
-			    sqlVdbeAddOp1(v, (x & 1) ? OP_IfNot : OP_If,
-					      (int)(x >> 1));
-			VdbeCoverage(v);
-#endif
 		}
 		sqlExprIfFalse(pParse, pE, addrCont, SQL_JUMPIFNULL);
 		if (skipLikeAddr)
-- 
2.15.1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [tarantool-patches] [PATCH 2/3] sql: remove sql_like_count global counter
  2019-03-09 16:59 [tarantool-patches] [PATCH 0/3] Make LIKE accept only arguments of type TEXT Nikita Pettik
  2019-03-09 17:00 ` [tarantool-patches] [PATCH 1/3] sql: remove SQL_LIKE_DOESNT_MATCH_BLOBS Nikita Pettik
@ 2019-03-09 17:00 ` Nikita Pettik
  2019-03-09 17:00 ` [tarantool-patches] [PATCH 3/3] sql: make LIKE accept only TEXT arguments Nikita Pettik
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Nikita Pettik @ 2019-03-09 17:00 UTC (permalink / raw)
  To: tarantool-patches; +Cc: v.shpilevoy, Nikita Pettik

We don't rely on this debug facility anymore, so let's remove it.
---
 src/box/sql/func.c | 14 --------------
 1 file changed, 14 deletions(-)

diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index a0df830f6..0c07f7e3c 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -800,14 +800,6 @@ sql_strlike_ci(const char *zPattern, const char *zStr, unsigned int esc)
 		                        zStr + strlen(zStr), 1, esc);
 }
 
-/**
- * Count the number of times that the LIKE operator gets called.
- * This is used for testing only.
- */
-#ifdef SQL_TEST
-int sql_like_count = 0;
-#endif
-
 /**
  * Implementation of the like() SQL function. This function
  * implements the built-in LIKE operator. The first argument to
@@ -828,9 +820,6 @@ likeFunc(sql_context *context, int argc, sql_value **argv)
 
 	if (sql_value_type(argv[0]) == SQL_BLOB
 	    || sql_value_type(argv[1]) == SQL_BLOB) {
-#ifdef SQL_TEST
-		sql_like_count++;
-#endif
 		sql_result_int(context, 0);
 		return;
 	}
@@ -874,9 +863,6 @@ likeFunc(sql_context *context, int argc, sql_value **argv)
 	}
 	if (!zA || !zB)
 		return;
-#ifdef SQL_TEST
-	sql_like_count++;
-#endif
 	int res;
 	res = sql_utf8_pattern_compare(zB, zA, zB_end, zA_end,
 				       is_like_ci, escape);
-- 
2.15.1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [tarantool-patches] [PATCH 3/3] sql: make LIKE accept only TEXT arguments
  2019-03-09 16:59 [tarantool-patches] [PATCH 0/3] Make LIKE accept only arguments of type TEXT Nikita Pettik
  2019-03-09 17:00 ` [tarantool-patches] [PATCH 1/3] sql: remove SQL_LIKE_DOESNT_MATCH_BLOBS Nikita Pettik
  2019-03-09 17:00 ` [tarantool-patches] [PATCH 2/3] sql: remove sql_like_count global counter Nikita Pettik
@ 2019-03-09 17:00 ` Nikita Pettik
  2019-03-15 14:41 ` [tarantool-patches] Re: [PATCH 0/3] Make LIKE accept only arguments of type TEXT Vladislav Shpilevoy
  2019-03-15 14:49 ` Kirill Yukhin
  4 siblings, 0 replies; 8+ messages in thread
From: Nikita Pettik @ 2019-03-09 17:00 UTC (permalink / raw)
  To: tarantool-patches; +Cc: v.shpilevoy, Nikita Pettik

According to ANSI[1] specification, LIKE arguments must be of
string-like type (VARCHAR, CHAR, TEXT etc). If one of arguments is NULL,
then the result of LIKE function is NULL as well. This patch makes LIKE
follow these rules.

ANSI 2013 Part 2: Foundation; Chapter 8.5 <like predicate>

Closes #3954
---
 src/box/sql/func.c            | 18 ++++++++++++++---
 src/box/sql/vdbe.c            |  6 +-----
 src/box/sql/vdbeInt.h         |  6 ++++++
 test/sql-tap/tkt1537.test.lua |  4 ++--
 test/sql/types.result         | 45 +++++++++++++++++++++++++++++++++++++++++++
 test/sql/types.test.lua       | 15 +++++++++++++++
 6 files changed, 84 insertions(+), 10 deletions(-)

diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 0c07f7e3c..855177dff 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -809,6 +809,9 @@ sql_strlike_ci(const char *zPattern, const char *zStr, unsigned int esc)
  *       A LIKE B
  *
  * are implemented as like(B,A).
+ *
+ * Both arguments (A and B) must be of type TEXT. If one arguments
+ * is NULL then result is NULL as well.
  */
 static void
 likeFunc(sql_context *context, int argc, sql_value **argv)
@@ -817,10 +820,19 @@ likeFunc(sql_context *context, int argc, sql_value **argv)
 	int nPat;
 	sql *db = sql_context_db_handle(context);
 	int is_like_ci = SQL_PTR_TO_INT(sql_user_data(context));
+	int rhs_type = sql_value_type(argv[0]);
+	int lhs_type = sql_value_type(argv[1]);
 
-	if (sql_value_type(argv[0]) == SQL_BLOB
-	    || sql_value_type(argv[1]) == SQL_BLOB) {
-		sql_result_int(context, 0);
+	if (lhs_type != SQL_TEXT || rhs_type != SQL_TEXT) {
+		if (lhs_type == SQL_NULL || rhs_type == SQL_NULL)
+			return;
+		char *inconsistent_type = rhs_type != SQL_TEXT ?
+					  mem_type_to_str(argv[0]) :
+					  mem_type_to_str(argv[1]);
+		diag_set(ClientError, ER_INCONSISTENT_TYPES, "TEXT",
+			 inconsistent_type);
+		context->fErrorOrAux = 1;
+		context->isError = SQL_TARANTOOL_ERROR;
 		return;
 	}
 	const char *zB = (const char *) sql_value_text(argv[0]);
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index d66fdd1f3..ed7bf8870 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -617,11 +617,7 @@ vdbe_add_new_autoinc_id(struct Vdbe *vdbe, int64_t id)
 	return 0;
 }
 
-/**
- * Simple type to str convertor. It is used to simplify
- * error reporting.
- */
-static char *
+char *
 mem_type_to_str(const struct Mem *p)
 {
 	assert(p != NULL);
diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h
index 61b7d58b2..c84f22caf 100644
--- a/src/box/sql/vdbeInt.h
+++ b/src/box/sql/vdbeInt.h
@@ -262,6 +262,12 @@ enum {
 	MEM_PURE_TYPE_MASK = 0x1f
 };
 
+/**
+ * Simple type to str convertor. It is used to simplify
+ * error reporting.
+ */
+char *
+mem_type_to_str(const struct Mem *p);
 
 /* Return TRUE if Mem X contains dynamically allocated content - anything
  * that needs to be deallocated to avoid a leak.
diff --git a/test/sql-tap/tkt1537.test.lua b/test/sql-tap/tkt1537.test.lua
index 29f2bff7e..a5a45601c 100755
--- a/test/sql-tap/tkt1537.test.lua
+++ b/test/sql-tap/tkt1537.test.lua
@@ -185,7 +185,7 @@ test:do_execsql_test(
 test:do_execsql_test(
     "tkt1537-3.1",
     [[
-        SELECT * FROM t1 LEFT JOIN t2 ON b LIKE 'abc%' WHERE t1.id=1;
+        SELECT * FROM t1 LEFT JOIN t2 ON printf('%d', b) LIKE 'abc%' WHERE t1.id=1;
     ]], {
         -- <tkt1537-3.1>
         1, "", "", "", ""
@@ -195,7 +195,7 @@ test:do_execsql_test(
 test:do_execsql_test(
     "tkt1537-3.2",
     [[
-        SELECT * FROM t2 LEFT JOIN t1 ON a1 LIKE 'abc%' WHERE t2.id=3;
+        SELECT * FROM t2 LEFT JOIN t1 ON printf('%d', a1) LIKE 'abc%' WHERE t2.id=3;
     ]], {
         -- <tkt1537-3.2>
         3, 1, "", "", ""
diff --git a/test/sql/types.result b/test/sql/types.result
index 11b045c05..4cee1b30d 100644
--- a/test/sql/types.result
+++ b/test/sql/types.result
@@ -169,3 +169,48 @@ box.sql.execute("VALUES (TYPEOF(randomblob(5) || zeroblob(5)));")
 ---
 - - ['blob']
 ...
+-- gh-3954: LIKE accepts only arguments of type TEXT and NULLs.
+--
+box.sql.execute("CREATE TABLE t1 (s SCALAR PRIMARY KEY);")
+---
+...
+box.sql.execute("INSERT INTO t1 VALUES (randomblob(5));")
+---
+...
+box.sql.execute("SELECT * FROM t1 WHERE s LIKE 'blob';")
+---
+- error: 'Inconsistent types: expected TEXT got BLOB'
+...
+box.sql.execute("SELECT * FROM t1 WHERE 'blob' LIKE s;")
+---
+- error: 'Inconsistent types: expected TEXT got BLOB'
+...
+box.sql.execute("SELECT * FROM t1 WHERE 'blob' LIKE x'0000';")
+---
+- error: 'Inconsistent types: expected TEXT got BLOB'
+...
+box.sql.execute("SELECT s LIKE NULL FROM t1;")
+---
+- - [null]
+...
+box.sql.execute("DELETE FROM t1;")
+---
+...
+box.sql.execute("INSERT INTO t1 VALUES (1);")
+---
+...
+box.sql.execute("SELECT * FROM t1 WHERE s LIKE 'int';")
+---
+- error: 'Inconsistent types: expected TEXT got INTEGER'
+...
+box.sql.execute("SELECT * FROM t1 WHERE 'int' LIKE 4;")
+---
+- error: 'Inconsistent types: expected TEXT got INTEGER'
+...
+box.sql.execute("SELECT NULL LIKE s FROM t1;")
+---
+- - [null]
+...
+box.space.T1:drop()
+---
+...
diff --git a/test/sql/types.test.lua b/test/sql/types.test.lua
index 799e9aed3..bb8bf7db7 100644
--- a/test/sql/types.test.lua
+++ b/test/sql/types.test.lua
@@ -55,3 +55,18 @@ box.sql.execute("SELECT randomblob(5) || 'x';")
 -- Result of BLOBs concatenation must be BLOB.
 --
 box.sql.execute("VALUES (TYPEOF(randomblob(5) || zeroblob(5)));")
+
+-- gh-3954: LIKE accepts only arguments of type TEXT and NULLs.
+--
+box.sql.execute("CREATE TABLE t1 (s SCALAR PRIMARY KEY);")
+box.sql.execute("INSERT INTO t1 VALUES (randomblob(5));")
+box.sql.execute("SELECT * FROM t1 WHERE s LIKE 'blob';")
+box.sql.execute("SELECT * FROM t1 WHERE 'blob' LIKE s;")
+box.sql.execute("SELECT * FROM t1 WHERE 'blob' LIKE x'0000';")
+box.sql.execute("SELECT s LIKE NULL FROM t1;")
+box.sql.execute("DELETE FROM t1;")
+box.sql.execute("INSERT INTO t1 VALUES (1);")
+box.sql.execute("SELECT * FROM t1 WHERE s LIKE 'int';")
+box.sql.execute("SELECT * FROM t1 WHERE 'int' LIKE 4;")
+box.sql.execute("SELECT NULL LIKE s FROM t1;")
+box.space.T1:drop()
-- 
2.15.1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [tarantool-patches] Re: [PATCH 1/3] sql: remove SQL_LIKE_DOESNT_MATCH_BLOBS
  2019-03-09 17:00 ` [tarantool-patches] [PATCH 1/3] sql: remove SQL_LIKE_DOESNT_MATCH_BLOBS Nikita Pettik
@ 2019-03-11  8:07   ` Konstantin Osipov
  2019-03-11 12:12     ` n.pettik
  0 siblings, 1 reply; 8+ messages in thread
From: Konstantin Osipov @ 2019-03-11  8:07 UTC (permalink / raw)
  To: tarantool-patches; +Cc: v.shpilevoy, Nikita Pettik

* Nikita Pettik <korablev@tarantool.org> [19/03/09 22:50]:
> We are going to always throw an error if value of BLOB type gets to LIKE
> arguments, so code under is macro is not needed anymore.

What's the decision about LIKE for MP_STR + collaction binary or
no collation at all? Shouldn't we need this code as an optimized
implementation of LIKE for binary?


-- 
Konstantin Osipov, Moscow, Russia, +7 903 626 22 32
http://tarantool.io - www.twitter.com/kostja_osipov

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [tarantool-patches] Re: [PATCH 1/3] sql: remove SQL_LIKE_DOESNT_MATCH_BLOBS
  2019-03-11  8:07   ` [tarantool-patches] " Konstantin Osipov
@ 2019-03-11 12:12     ` n.pettik
  0 siblings, 0 replies; 8+ messages in thread
From: n.pettik @ 2019-03-11 12:12 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Konstantin Osipov, Vladislav Shpilevoy



> On 11 Mar 2019, at 11:07, Konstantin Osipov <kostja.osipov@gmail.com> wrote:
> 
> * Nikita Pettik <korablev@tarantool.org> [19/03/09 22:50]:
>> We are going to always throw an error if value of BLOB type gets to LIKE
>> arguments, so code under is macro is not needed anymore.
> 
> What's the decision about LIKE for MP_STR + collaction binary or
> no collation at all? Shouldn't we need this code as an optimized
> implementation of LIKE for binary?

Firstly, this optimisation has been turned off for quite a while.
I’m not sure that it can be enabled without significant patching.
Secondly, MP_STR + binary (or none) collation is still stored as
a string (MEM_Str in terms of VDBE), meanwhile deleted code
was operating on real blob values (MEM_Blob):

‘''

- * The LIKE optimization trys to evaluate "x LIKE 'abc%'" as a range
- * expression: "x>='ABC' AND x<'abd'".  But this requires that the range
- * scan loop run twice, once for strings and a second time for BLOBs.
- * The OP_String opcodes on the second pass convert the upper and lower
- * bound string constants to blobs.  This routine makes the necessary changes
- * to the OP_String opcodes for that to happen.

‘’'

Note that now LIKE doesn’t use implicitly set collation:

tarantool> create table t1(id int primary key, a text collate "binary")
---
...

tarantool> insert into t1 values (1, 'ABC')
---
...

tarantool> select * from t1 where a like 'abc'
---
- - [1, 'ABC']
…

It is going to be fixed in https://github.com/tarantool/tarantool/issues/3589

> 
> -- 
> Konstantin Osipov, Moscow, Russia, +7 903 626 22 32
> http://tarantool.io - www.twitter.com/kostja_osipov

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [tarantool-patches] Re: [PATCH 0/3] Make LIKE accept only arguments of type TEXT
  2019-03-09 16:59 [tarantool-patches] [PATCH 0/3] Make LIKE accept only arguments of type TEXT Nikita Pettik
                   ` (2 preceding siblings ...)
  2019-03-09 17:00 ` [tarantool-patches] [PATCH 3/3] sql: make LIKE accept only TEXT arguments Nikita Pettik
@ 2019-03-15 14:41 ` Vladislav Shpilevoy
  2019-03-15 14:49 ` Kirill Yukhin
  4 siblings, 0 replies; 8+ messages in thread
From: Vladislav Shpilevoy @ 2019-03-15 14:41 UTC (permalink / raw)
  To: tarantool-patches, Nikita Pettik, Kirill Yukhin

LGTM.

On 09/03/2019 19:59, Nikita Pettik wrote:
> First two patches simply remove unnecessary macro and code connected
> with it. Third one - disallows arguments of LIKE be of different
> from text-like types.
> 
> Branch: https://github.com/tarantool/tarantool/tree/np/gh-3954-disallow-blob-in-like
> Issue: https://github.com/tarantool/tarantool/issues/3954
> 
> Nikita Pettik (3):
>    sql: remove SQL_LIKE_DOESNT_MATCH_BLOBS
>    sql: remove sql_like_count global counter
>    sql: make LIKE accept only TEXT arguments
> 
>   src/box/sql/func.c            | 34 +++++++++-----------
>   src/box/sql/sqlInt.h          |  2 --
>   src/box/sql/vdbe.c            | 14 +--------
>   src/box/sql/vdbeInt.h         |  6 ++++
>   src/box/sql/where.c           |  8 -----
>   src/box/sql/whereInt.h        |  4 ---
>   src/box/sql/wherecode.c       | 73 -------------------------------------------
>   test/sql-tap/tkt1537.test.lua |  4 +--
>   test/sql/types.result         | 45 ++++++++++++++++++++++++++
>   test/sql/types.test.lua       | 15 +++++++++
>   10 files changed, 84 insertions(+), 121 deletions(-)
> 
> -- 
> 2.15.1
> 
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [tarantool-patches] Re: [PATCH 0/3] Make LIKE accept only arguments of type TEXT
  2019-03-09 16:59 [tarantool-patches] [PATCH 0/3] Make LIKE accept only arguments of type TEXT Nikita Pettik
                   ` (3 preceding siblings ...)
  2019-03-15 14:41 ` [tarantool-patches] Re: [PATCH 0/3] Make LIKE accept only arguments of type TEXT Vladislav Shpilevoy
@ 2019-03-15 14:49 ` Kirill Yukhin
  4 siblings, 0 replies; 8+ messages in thread
From: Kirill Yukhin @ 2019-03-15 14:49 UTC (permalink / raw)
  To: tarantool-patches; +Cc: v.shpilevoy, Nikita Pettik

Hello,

On 09 Mar 19:59, Nikita Pettik wrote:
> First two patches simply remove unnecessary macro and code connected
> with it. Third one - disallows arguments of LIKE be of different
> from text-like types.
> 
> Branch: https://github.com/tarantool/tarantool/tree/np/gh-3954-disallow-blob-in-like
> Issue: https://github.com/tarantool/tarantool/issues/3954

I've checked the patchset into 2.1 branch.

--
Regards, Kirill Yukhin

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-03-15 14:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-09 16:59 [tarantool-patches] [PATCH 0/3] Make LIKE accept only arguments of type TEXT Nikita Pettik
2019-03-09 17:00 ` [tarantool-patches] [PATCH 1/3] sql: remove SQL_LIKE_DOESNT_MATCH_BLOBS Nikita Pettik
2019-03-11  8:07   ` [tarantool-patches] " Konstantin Osipov
2019-03-11 12:12     ` n.pettik
2019-03-09 17:00 ` [tarantool-patches] [PATCH 2/3] sql: remove sql_like_count global counter Nikita Pettik
2019-03-09 17:00 ` [tarantool-patches] [PATCH 3/3] sql: make LIKE accept only TEXT arguments Nikita Pettik
2019-03-15 14:41 ` [tarantool-patches] Re: [PATCH 0/3] Make LIKE accept only arguments of type TEXT Vladislav Shpilevoy
2019-03-15 14:49 ` Kirill Yukhin

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