diff options
author | drh <drh@noemail.net> | 2005-08-14 01:20:37 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2005-08-14 01:20:37 +0000 |
commit | 55ef4d9758ed27c332f07ca56fc9ba61cadfe2e7 (patch) | |
tree | 8f59d79014cb49e92d37a1ebe548537b6bdbadf1 /src/where.c | |
parent | 3d94662a062a5da6340568b5ad656c3057f053c5 (diff) | |
download | sqlite-55ef4d9758ed27c332f07ca56fc9ba61cadfe2e7.tar.gz sqlite-55ef4d9758ed27c332f07ca56fc9ba61cadfe2e7.zip |
The case_sensitive_like pragma added.
Test cases added for the LIKE optimization. (CVS 2592)
FossilOrigin-Name: 72ee21c05e618b6f46f5460f8c85779c72fe32d7
Diffstat (limited to 'src/where.c')
-rw-r--r-- | src/where.c | 41 |
1 files changed, 11 insertions, 30 deletions
diff --git a/src/where.c b/src/where.c index c34062621..e98363d14 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.161 2005/08/13 16:13:05 drh Exp $ +** $Id: where.c,v 1.162 2005/08/14 01:20:39 drh Exp $ */ #include "sqliteInt.h" @@ -467,54 +467,35 @@ static void exprAnalyzeAll( ** literal that does not begin with a wildcard. */ static int isLikeOrGlob( + sqlite3 *db, /* The database */ Expr *pExpr, /* Test this expression */ int *pnPattern, /* Number of non-wildcard prefix characters */ int *pisComplete /* True if the only wildcard is % in the last character */ ){ const char *z; Expr *pRight, *pLeft; + ExprList *pList; int c, cnt; - char wc1, wc2, wc3; - if( pExpr->op!=TK_FUNCTION ){ + char wc[3]; + if( !sqlite3IsLikeFunction(db, pExpr, wc) ){ return 0; } - if( pExpr->pList->nExpr!=2 ){ - return 0; - } - if( pExpr->token.n!=4 ){ - return 0; - } - z = pExpr->token.z; - if( sqlite3StrNICmp(z, "glob", 4)==0 ){ - wc1 = '*'; - wc2 = '?'; - wc3 = '['; - } -#ifdef SQLITE_CASE_SENSITIVE_LIKE - else if( sqlite3StrNICmp(z, "like", 4)==0 ){ - wc1 = '%'; - wc2 = '_'; - wc3 = '_'; - } -#endif - else{ - return 0; - } - pRight = pExpr->pList->a[0].pExpr; + pList = pExpr->pList; + pRight = pList->a[0].pExpr; if( pRight->op!=TK_STRING ){ return 0; } - pLeft = pExpr->pList->a[1].pExpr; + pLeft = pList->a[1].pExpr; if( pLeft->op!=TK_COLUMN ){ return 0; } sqlite3DequoteExpr(pRight); z = pRight->token.z; - for(cnt=0; (c=z[cnt])!=0 && c!=wc1 && c!=wc2 && c!=wc3; cnt++){} + for(cnt=0; (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2]; cnt++){} if( cnt==0 || 255==(u8)z[cnt] ){ return 0; } - *pisComplete = z[cnt]==wc1 && z[cnt+1]==0; + *pisComplete = z[cnt]==wc[0] && z[cnt+1]==0; *pnPattern = cnt; return 1; } @@ -671,7 +652,7 @@ or_not_possible: /* Add constraints to reduce the search space on a LIKE or GLOB ** operator. */ - if( isLikeOrGlob(pExpr, &nPattern, &isComplete) ){ + if( isLikeOrGlob(pTerm->pWC->pParse->db, pExpr, &nPattern, &isComplete) ){ Expr *pLeft, *pRight; Expr *pStr1, *pStr2; Expr *pNewExpr1, *pNewExpr2; |