Tarantool development patches archive
 help / color / mirror / Atom feed
From: Nikita Pettik <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: v.shpilevoy@tarantool.org, Nikita Pettik <korablev@tarantool.org>
Subject: [tarantool-patches] [PATCH 1/3] sql: remove SQL_LIKE_DOESNT_MATCH_BLOBS
Date: Sat,  9 Mar 2019 20:00:00 +0300	[thread overview]
Message-ID: <819cad361d29e627f17cf38c6ca6ffd0e10d3e2b.1552149462.git.korablev@tarantool.org> (raw)
In-Reply-To: <cover.1552149462.git.korablev@tarantool.org>
In-Reply-To: <cover.1552149462.git.korablev@tarantool.org>

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

  reply	other threads:[~2019-03-09 17:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2019-03-11  8:07   ` [tarantool-patches] Re: [PATCH 1/3] sql: remove SQL_LIKE_DOESNT_MATCH_BLOBS 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

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=819cad361d29e627f17cf38c6ca6ffd0e10d3e2b.1552149462.git.korablev@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH 1/3] sql: remove SQL_LIKE_DOESNT_MATCH_BLOBS' \
    /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