The LIKE optimization does the right thing when collating sequences are
present. LIKE expressions where the left-hand side has COLLATE NOCASE
are optimized in the default case. (CVS 2637)
FossilOrigin-Name: ef84ff795c85e9d28f1cac84ff42d8d4ef84cfc4
diff --git a/src/where.c b/src/where.c
index 4e355e8..3e59338 100644
--- a/src/where.c
+++ b/src/where.c
@@ -16,7 +16,7 @@
** so is applicable. Because this module is responsible for selecting
** indices, you might also think of this module as the "query optimizer".
**
-** $Id: where.c,v 1.165 2005/08/24 03:52:19 drh Exp $
+** $Id: where.c,v 1.166 2005/08/28 17:00:25 drh Exp $
*/
#include "sqliteInt.h"
@@ -479,8 +479,11 @@
Expr *pRight, *pLeft;
ExprList *pList;
int c, cnt;
+ int noCase;
char wc[3];
- if( !sqlite3IsLikeFunction(db, pExpr, wc) ){
+ CollSeq *pColl;
+
+ if( !sqlite3IsLikeFunction(db, pExpr, &noCase, wc) ){
return 0;
}
pList = pExpr->pList;
@@ -492,6 +495,14 @@
if( pLeft->op!=TK_COLUMN ){
return 0;
}
+ pColl = pLeft->pColl;
+ if( pColl==0 ){
+ pColl = db->pDfltColl;
+ }
+ if( (pColl->type!=SQLITE_COLL_BINARY || noCase) &&
+ (pColl->type!=SQLITE_COLL_NOCASE || !noCase) ){
+ return 0;
+ }
sqlite3DequoteExpr(pRight);
z = pRight->token.z;
for(cnt=0; (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2]; cnt++){}