From: drh Date: Wed, 5 Dec 2018 17:48:57 +0000 (+0000) Subject: Simplifications to the sqlite3_normalized_sql() implementation. X-Git-Tag: version-3.27.0~330 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=19efd0db4133f2d0f9985856ae9b4b5572abf733;p=thirdparty%2Fsqlite.git Simplifications to the sqlite3_normalized_sql() implementation. FossilOrigin-Name: 94ea6379178e3ff6a0d1d5819ca4ac558bdadb1ca8a3637c797079db7dc0cd61 --- diff --git a/manifest b/manifest index fabc9f14b7..06972a00ce 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\sthat\sALTER\sTABLE\smodifies\stable\sand\scolumn\snames\sembedded\sin\sWITH\nclauses\sthat\sare\spart\sof\sviews\sand\striggers. -D 2018-12-05T13:49:04.148 +C Simplifications\sto\sthe\ssqlite3_normalized_sql()\simplementation. +D 2018-12-05T17:48:57.422 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 68d0ba0f0b533d5bc84c78c13a6ce84ee81183a67014caa47a969e67f028fa1c @@ -452,7 +452,7 @@ F src/btree.c ba7c7eef4461790f37c309936bfc5d0d6ba9b194b02d3c8ff1fd53b420ea6d3b F src/btree.h febb2e817be499570b7a2e32a9bbb4b607a9234f6b84bb9ae84916d4806e96f2 F src/btreeInt.h 620ab4c7235f43572cf3ac2ac8723cbdf68073be4d29da24897c7b77dda5fd96 F src/build.c fce47a9789704e65c63299b01be8153745faee7919f5137d3f29b7c3c0b549bd -F src/callback.c 789bd33d188146f66c0dd8306472a72d1c05f71924b24a91caf6bd45cf9aba73 +F src/callback.c 25dda5e1c2334a367b94a64077b1d06b2553369f616261ca6783c48bcb6bda73 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 109e58d00f62e8e71ee1eb5944ac18b90171c928ab2e082e058056e1137cc20b F src/date.c ebe1dc7c8a347117bb02570f1a931c62dd78f4a2b1b516f4837d45b7d6426957 @@ -464,8 +464,8 @@ F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 972a4ba14296bef2303a0abbad1e3d82bc3c61f9e6ce4e8e9528bdee68748812 F src/func.c 7c288b4ce309b5a8b8473514b88e1f8e69a80134509a8c0db8e39c858e367e7f F src/global.c 8291eee0782b83124de14ec0389ec9fd6ae1873358a6b0d9469fe17a46ad803b -F src/hash.c 6d2f67276469384fb8784fb8e962deeaae6832955626468325d705a01b999594 -F src/hash.h eebf2250e56b5d5353b873406557e373d2888cf51f111e28917666456d479e85 +F src/hash.c a12580e143f10301ed5166ea4964ae2853d3905a511d4e0c44497245c7ce1f7a +F src/hash.h ab34c5c54a9e9de2e790b24349ba5aab3dbb4fd4 F src/hwtime.h 747c1bbe9df21a92e9c50f3bbec1de841dc5e5da F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/insert.c f12f27eb606d601825be9a229a7390a8d64d40226697883f96de8e088d620055 @@ -502,7 +502,7 @@ F src/pcache.h 4f87acd914cef5016fae3030343540d75f5b85a1877eed1a2a19b9f284248586 F src/pcache1.c ad0ffc5b35b0280d045ac569d34d4b842e3e6a4a118f6396b320987a0957afcc F src/pragma.c 4e056f042683b99c4ea0db395f68d051b1a95833ab40951c40d3ef7e1fee1354 F src/pragma.h fdd03d78a7497f74a3f652909f945328480089189526841ae829ce7313d98d13 -F src/prepare.c 277c8af17124bd4f67ae6e1a8e795a91f12bf7ce3a4b344c7eac46d360250c20 +F src/prepare.c f77ebf812f46a174e805d939cec0017771904e79049d04edf66dbbb3ec25ad3e F src/printf.c 0f1177cf1dd4d7827bf64d840768514ec76409abecaca9e8b577dbd065150381 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c 976e7879286a1eecdc71ceff64f6d1b3f58c8f8096537ba668b3dc0887f410c1 @@ -512,7 +512,7 @@ F src/shell.c.in 1f0819e69fb1ebd2eb44695530dc43936608bf9b752981a0ffd4e2e4a9e3883 F src/sqlite.h.in cce9feede1c1c03923c091b4bbbd081dd77aaf92024cc2cdbf65f712c2f668c3 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 960f1b86c3610fa23cb6a267572a97dcf286e77aa0dd3b9b23292ffaa1ea8683 -F src/sqliteInt.h 128f2ef4cd6037300cb5510dd3c882417b225d6f4ed6210bddfd920104c7341f +F src/sqliteInt.h e96520f27310016d0dabb496e13346244bbea83a6adc3134810e026f1d4a02b6 F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b F src/status.c 46e7aec11f79dad50965a5ca5fa9de009f7d6bde08be2156f1538a0a296d4d0e F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 @@ -1782,7 +1782,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7da617e97eb905cb009c47403786682b911e32a630f266e1c53ea72836fc88b5 -R 5be4b63edcb6a436be7d6ac2ccab0473 -U dan -Z 758395cc3e6658700c83b35c2e31d2cc +P f44bc7a8b3fac82aa5598e9bdaf65ea4dd3c331cf90c1d5ba26ff1698e92c230 +R 14f7302635d9f1332de56d5fb4d8f1a4 +U drh +Z b51bb6387d49f37b8a1232489a1c6ba3 diff --git a/manifest.uuid b/manifest.uuid index 7bb95e4443..6334ab25e4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f44bc7a8b3fac82aa5598e9bdaf65ea4dd3c331cf90c1d5ba26ff1698e92c230 \ No newline at end of file +94ea6379178e3ff6a0d1d5819ca4ac558bdadb1ca8a3637c797079db7dc0cd61 \ No newline at end of file diff --git a/src/callback.c b/src/callback.c index faf6d520c4..ad53bd4d3c 100644 --- a/src/callback.c +++ b/src/callback.c @@ -283,7 +283,7 @@ static int matchQuality( ** Search a FuncDefHash for a function with the given name. Return ** a pointer to the matching FuncDef if found, or 0 if there is no match. */ -static FuncDef *functionSearch( +FuncDef *sqlite3FunctionSearch( int h, /* Hash of the name */ const char *zFunc /* Name of function */ ){ @@ -295,21 +295,6 @@ static FuncDef *functionSearch( } return 0; } -#ifdef SQLITE_ENABLE_NORMALIZE -FuncDef *sqlite3FunctionSearchN( - int h, /* Hash of the name */ - const char *zFunc, /* Name of function */ - int nFunc /* Length of the name */ -){ - FuncDef *p; - for(p=sqlite3BuiltinFunctions.a[h]; p; p=p->u.pHash){ - if( sqlite3StrNICmp(p->zName, zFunc, nFunc)==0 ){ - return p; - } - } - return 0; -} -#endif /* SQLITE_ENABLE_NORMALIZE */ /* ** Insert a new FuncDef into a FuncDefHash hash table. @@ -325,7 +310,7 @@ void sqlite3InsertBuiltinFuncs( int nName = sqlite3Strlen30(zName); int h = SQLITE_FUNC_HASH(zName[0], nName); assert( zName[0]>='a' && zName[0]<='z' ); - pOther = functionSearch(h, zName); + pOther = sqlite3FunctionSearch(h, zName); if( pOther ){ assert( pOther!=&aDef[i] && pOther->pNext!=&aDef[i] ); aDef[i].pNext = pOther->pNext; @@ -403,7 +388,7 @@ FuncDef *sqlite3FindFunction( if( !createFlag && (pBest==0 || (db->mDbFlags & DBFLAG_PreferBuiltin)!=0) ){ bestScore = 0; h = SQLITE_FUNC_HASH(sqlite3UpperToLower[(u8)zName[0]], nName); - p = functionSearch(h, zName); + p = sqlite3FunctionSearch(h, zName); while( p ){ int score = matchQuality(p, nArg, enc); if( score>bestScore ){ diff --git a/src/hash.c b/src/hash.c index e725f2aa5e..79bb85ac01 100644 --- a/src/hash.c +++ b/src/hash.c @@ -64,20 +64,6 @@ static unsigned int strHash(const char *z){ } return h; } -#ifdef SQLITE_ENABLE_NORMALIZE -static unsigned int strHashN(const char *z, int n){ - unsigned int h = 0; - int i; - for(i=0; iht ){ /*OPTIMIZATION-IF-TRUE*/ - struct _ht *pEntry; - h = strHashN(pKey, nKey) % pH->htsize; - pEntry = &pH->ht[h]; - elem = pEntry->chain; - count = pEntry->count; - }else{ - h = 0; - elem = pH->first; - count = pH->count; - } - if( pHash ) *pHash = h; - while( count-- ){ - assert( elem!=0 ); - if( sqlite3StrNICmp(elem->pKey,pKey,nKey)==0 ){ - return elem; - } - elem = elem->next; - } - return &nullElement; -} -#endif /* SQLITE_ENABLE_NORMALIZE */ /* Remove a single entry from the hash table given a pointer to that ** element and a hash on the element's key. @@ -267,14 +219,6 @@ void *sqlite3HashFind(const Hash *pH, const char *pKey){ assert( pKey!=0 ); return findElementWithHash(pH, pKey, 0)->data; } -#ifdef SQLITE_ENABLE_NORMALIZE -void *sqlite3HashFindN(const Hash *pH, const char *pKey, int nKey){ - assert( pH!=0 ); - assert( pKey!=0 ); - assert( nKey>=0 ); - return findElementWithHashN(pH, pKey, nKey, 0)->data; -} -#endif /* SQLITE_ENABLE_NORMALIZE */ /* Insert an element into the hash table pH. The key is pKey ** and the data is "data". diff --git a/src/hash.h b/src/hash.h index cf773663b7..90540eda50 100644 --- a/src/hash.h +++ b/src/hash.h @@ -68,9 +68,6 @@ struct HashElem { void sqlite3HashInit(Hash*); void *sqlite3HashInsert(Hash*, const char *pKey, void *pData); void *sqlite3HashFind(const Hash*, const char *pKey); -#ifdef SQLITE_ENABLE_NORMALIZE -void *sqlite3HashFindN(const Hash *pH, const char *pKey, int nKey); -#endif void sqlite3HashClear(Hash*); /* diff --git a/src/prepare.c b/src/prepare.c index 86afac5350..7ac96a68f6 100644 --- a/src/prepare.c +++ b/src/prepare.c @@ -728,27 +728,41 @@ static int shouldTreatAsIdentifier( Hash *pHash; /* Hash table of tables for current database. */ HashElem *e; /* Hash element for hash table iteration. */ Table *pTab; /* Database table for columns being checked. */ + char *zId; /* Zero terminated name of the identifier */ + char zSpace[50]; /* Static space for the zero-terminated name */ - if( sqlite3IsRowidN(zToken, nToken) ){ - return 1; + if( nToken0 ){ int hash = SQLITE_FUNC_HASH(sqlite3UpperToLower[(u8)zToken[0]], nToken); - if( sqlite3FunctionSearchN(hash, zToken, nToken) ) return 1; + if( sqlite3FunctionSearch(hash, zId) ){ + bFound = 1; + goto done; + } } assert( db!=0 ); sqlite3_mutex_enter(db->mutex); sqlite3BtreeEnterAll(db); for(i=0; inDb; i++){ pHash = &db->aFunc; - if( sqlite3HashFindN(pHash, zToken, nToken) ){ + if( sqlite3HashFind(pHash, zId) ){ bFound = 1; break; } pSchema = db->aDb[i].pSchema; if( pSchema==0 ) continue; pHash = &pSchema->tblHash; - if( sqlite3HashFindN(pHash, zToken, nToken) ){ + if( sqlite3HashFind(pHash, zId) ){ bFound = 1; break; } @@ -770,7 +784,7 @@ static int shouldTreatAsIdentifier( goto done; } } - if( pHash && sqlite3HashFindN(pHash, zToken, nToken) ){ + if( pHash && sqlite3HashFind(pHash, zId) ){ bFound = 1; goto done; } @@ -779,6 +793,7 @@ static int shouldTreatAsIdentifier( done: sqlite3BtreeLeaveAll(db); sqlite3_mutex_leave(db->mutex); + if( zId!=zSpace ) sqlite3DbFree(db, zId); return bFound; } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index fc52fecfe2..9373accf8d 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -4056,9 +4056,7 @@ ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int); SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int); IdList *sqlite3IdListDup(sqlite3*,IdList*); Select *sqlite3SelectDup(sqlite3*,Select*,int); -#ifdef SQLITE_ENABLE_NORMALIZE -FuncDef *sqlite3FunctionSearchN(int,const char*,int); -#endif +FuncDef *sqlite3FunctionSearch(int,const char*); void sqlite3InsertBuiltinFuncs(FuncDef*,int); FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,u8,u8); void sqlite3RegisterBuiltinFunctions(void);