From: danielk1977 Date: Sun, 6 Jun 2004 12:41:49 +0000 (+0000) Subject: Performance improvements for LIKE. It is still too slow though. (CVS 1535) X-Git-Tag: version-3.6.10~4540 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ad7dd42558fe65d4e30e9a9066d413b56d03f1fe;p=thirdparty%2Fsqlite.git Performance improvements for LIKE. It is still too slow though. (CVS 1535) FossilOrigin-Name: 30b81507fc404355751705c6f9856c178249eff1 --- diff --git a/manifest b/manifest index d81ead2f6c..b45e3a6b69 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhance\suser\sfunction\sAPI\sto\ssupport\sassociation\sof\smeta-data\swith\sconstant\narguments\sand\sthe\sspecification\sof\stext\sencoding\spreference.\sThe\sLIKE\noperator\stakes\sadvantage\sof\sboth.\s(CVS\s1534) -D 2004-06-06T09:44:04 +C Performance\simprovements\sfor\sLIKE.\sIt\sis\sstill\stoo\sslow\sthough.\s(CVS\s1535) +D 2004-06-06T12:41:50 F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -31,8 +31,8 @@ F src/build.c e12e602f06e37a0fbcb49af17cba68ad85e101b6 F src/date.c 8e6fa3173386fb29fdef012ee08a853c1e9908b2 F src/delete.c b30f08250c9ed53a25a13c7c04599c1e8753992d F src/encode.c a876af473d1d636faa3dca51c7571f2e007eea37 -F src/expr.c f05a5594679fe5297d41578d2e0ffff827772906 -F src/func.c e873366ba5ad97926336fd05c3af22ca54ad3e74 +F src/expr.c 2b18dd4ed178e39989f22d75bf0e68ba6ed3923c +F src/func.c 730741443e8de788de370e2b0d641df69d174697 F src/hash.c 440c2f8cb373ee1b4e13a0988489c7cd95d55b6f F src/hash.h 762d95f1e567664d1eafc1687de755626be962fb F src/insert.c 4268d9e3959cc845ea243fb4ec7507269404dad9 @@ -67,8 +67,8 @@ F src/test5.c 44178ce85c3afd2004ab4eeb5cfd7487116ce366 F src/tokenize.c 183c5d7da11affab5d70d903d33409c8c0ce6c5b F src/trigger.c 04b2c310d0d056b213609cab6df5fff03d5eaf88 F src/update.c 259f06e7b22c684b2d3dda54a18185892d6e9573 -F src/utf.c 0e83deb064da62c202c1765e6194e938ca16d20f -F src/util.c 026035fcb4d34cce0b541c4b8b0b058d93cb1da6 +F src/utf.c c2c8e445bfea724f3502609d6389fe66651f02ab +F src/util.c 8b3680271111bcdf5b395916b08b9a6684e0e73d F src/vacuum.c b921eb778842592e1fb48a9d4cef7e861103878f F src/vdbe.c 392c6b02c525ea12dff403ba4ceb42b0afcb42f5 F src/vdbe.h 46f74444a213129bc4b5ce40124dd8ed613b0cde @@ -215,7 +215,7 @@ F www/support.tcl 1801397edd271cc39a2aadd54e701184b5181248 F www/tclsqlite.tcl 19191cf2a1010eaeff74c51d83fd5f5a4d899075 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4 -P 9e6cd9ec75f726ef85e60f593aaa895791315071 -R f098c036151f30238f65c2c50a0dd90e +P 92337d8f79b9754cd61c73e7db2e792a1f482f50 +R fd9052eaad985197e4f082c9d9a0d480 U danielk1977 -Z 5b48605b31bccaed46d70ecdd5c38ae2 +Z a1980072adc559c578b2d7aa47186c8d diff --git a/manifest.uuid b/manifest.uuid index 5ebff6bb9d..1a189a258b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -92337d8f79b9754cd61c73e7db2e792a1f482f50 \ No newline at end of file +30b81507fc404355751705c6f9856c178249eff1 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index dd2a8cef34..36b421f53c 100644 --- a/src/expr.c +++ b/src/expr.c @@ -12,7 +12,7 @@ ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** -** $Id: expr.c,v 1.135 2004/06/06 09:44:04 danielk1977 Exp $ +** $Id: expr.c,v 1.136 2004/06/06 12:41:50 danielk1977 Exp $ */ #include "sqliteInt.h" #include @@ -1752,6 +1752,7 @@ FuncDef *sqlite3FindFunction( pBest->nArg = nArg; pBest->pNext = pFirst; pBest->zName = (char*)&pBest[1]; + pBest->iPrefEnc = eTextRep; memcpy(pBest->zName, zName, nName); pBest->zName[nName] = 0; sqlite3HashInsert(&db->aFunc, pBest->zName, nName, (void*)pBest); diff --git a/src/func.c b/src/func.c index e6cd5d0f70..bf4d6d4ae8 100644 --- a/src/func.c +++ b/src/func.c @@ -16,7 +16,7 @@ ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: func.c,v 1.63 2004/06/06 09:44:04 danielk1977 Exp $ +** $Id: func.c,v 1.64 2004/06/06 12:41:50 danielk1977 Exp $ */ #include #include @@ -418,7 +418,11 @@ LikePattern *compileLike(sqlite3_value *pPattern, u8 enc){ if( pc_state<0 ){ aState[n].failstate = -1; }else if( pc_state==n ){ - aState[n].failstate = pc_state; + if( c ){ + aState[n].failstate = pc_state; + }else{ + aState[n].failstate = -2; + } }else{ int k = pLike->aState[n-1].failstate; while( k>pc_state && aState[k+1].val!=-1 && aState[k+1].val!=c ){ @@ -461,13 +465,13 @@ static void likeFunc( int argc, sqlite3_value **argv ){ - int s; - int c; - int nc; + register int c; u8 enc; int offset = 0; const unsigned char *zString; LikePattern *pLike = sqlite3_get_auxdata(context, 0); + struct LikeState *aState; + register struct LikeState *pState; /* If either argument is NULL, the result is NULL */ if( sqlite3_value_type(argv[1])==SQLITE_NULL || @@ -479,6 +483,7 @@ static void likeFunc( if( sqlite3_user_data(context) ){ enc = TEXT_Utf16; zString = (const unsigned char *)sqlite3_value_text16(argv[1]); + assert(0); }else{ enc = TEXT_Utf8; zString = sqlite3_value_text(argv[1]); @@ -493,33 +498,39 @@ static void likeFunc( } sqlite3_set_auxdata(context, 0, pLike, deleteLike); } + aState = pLike->aState; + pState = aState; - s = 0; - nc = 1; do { - int val = pLike->aState[s].val; - if( nc ) c = sqlite3ReadUniChar(zString, &offset, &enc, 1); + if( enc==TEXT_Utf8 ){ + c = zString[offset++]; + if( c&0x80 ){ + offset--; + c = sqlite3ReadUniChar(zString, &offset, &enc, 1); + } + }else{ + c = sqlite3ReadUniChar(zString, &offset, &enc, 1); + } + +skip_read: #if defined(TRACE_LIKE) && !defined(NDEBUG) printf("State=%d:(%d, %d) Input=%d\n", - s, pLike->aState[s].val, - pLike->aState[s].failstate, c); + (aState - pState), pState->val, pState->failstate, c); #endif - if( val==-1 || val==c ){ - s++; - nc = 1; + if( pState->val==-1 || pState->val==c ){ + pState++; }else{ - if( pLike->aState[s].failstate==s ){ - nc = 1; - }else{ - nc = 0; - s = pLike->aState[s].failstate; + struct LikeState *pFailState = &aState[pState->failstate]; + if( pState!=pFailState ){ + pState = pFailState; + if( c && pState>=aState ) goto skip_read; } } - }while( c && s>=0 ); + }while( c && pState>=aState ); - if( s==pLike->nState ){ + if( (pState-aState)==pLike->nState || (pState-aState)<-1 ){ sqlite3_result_int(context, 1); }else{ sqlite3_result_int(context, 0); @@ -916,8 +927,8 @@ void sqlite3RegisterBuiltinFunctions(sqlite *db){ case 1: pArg = db; break; case 2: pArg = (void *)(-1); break; } - sqlite3_create_function(db, aFuncs[i].zName, aFuncs[i].nArg, 0, 0, - pArg, aFuncs[i].xFunc, 0, 0); + sqlite3_create_function(db, aFuncs[i].zName, aFuncs[i].nArg, + aFuncs[i].eTextRep, 0, pArg, aFuncs[i].xFunc, 0, 0); } for(i=0; i @@ -917,7 +917,7 @@ int sqlite3SortCompare(const char *a, const char *b){ ** UCS character. This only works right if z points to a well-formed ** UTF-8 string. */ -static int sqlite3ReadUtf8(const unsigned char *z){ +int sqlite3ReadUtf8(const unsigned char *z){ int c; static const int initVal[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,