Get rid of the hash table used to track IN operators in the

sqlite3_normalized_sql() implementation.  Use simple integer variables
instead.

FossilOrigin-Name: 272dc74fd0304d6a28aaa8798d13e2f950c1a24d92d17519e3c32aef86714586
This commit is contained in:
drh 2018-12-05 23:56:02 +00:00
parent 253a6af532
commit 7b278f0c3d
3 changed files with 17 additions and 25 deletions

View File

@ -1,5 +1,5 @@
C The\ssqlite3_normalized_sql()\sinterface\sshould\snot\sbe\stransforming\squoted\nidentifier\snames\sinto\swildcards.\s\sFix\sthis,\sand\sat\sthe\ssame\stime\ssimplify\nthe\scode\ssubstantially.
D 2018-12-05T23:45:46.950
C Get\srid\sof\sthe\shash\stable\sused\sto\strack\sIN\soperators\sin\sthe\nsqlite3_normalized_sql()\simplementation.\s\sUse\ssimple\sinteger\svariables\ninstead.
D 2018-12-05T23:56:02.639
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F Makefile.in 68d0ba0f0b533d5bc84c78c13a6ce84ee81183a67014caa47a969e67f028fa1c
@ -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 90099721296d9646addc5dda092464da21546e7410406818dde1600467b120c4
F src/prepare.c 66b5f9791a3ef57131cbba58c33104ebea814a70a5cfcafabf5aed5a3e3858fe
F src/printf.c 0f1177cf1dd4d7827bf64d840768514ec76409abecaca9e8b577dbd065150381
F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
F src/resolve.c 976e7879286a1eecdc71ceff64f6d1b3f58c8f8096537ba668b3dc0887f410c1
@ -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 f69624373e33c4d370a9264a317ffdb0adbce967a950f243de2b41161a8c7ded
R f3aa45194b952de0676e91bd1b04c704
P e8540377ec66fa5f9ae3c93bedb5c094057698199c37fc211f7ea95429e815e4
R d3461cbb797157ae329a2dd1a53cba4d
U drh
Z 5f1f0ed88784c364d2e88ebae6a00a1f
Z ad7226daa41778e03500de0c126598a5

View File

@ -1 +1 @@
e8540377ec66fa5f9ae3c93bedb5c094057698199c37fc211f7ea95429e815e4
272dc74fd0304d6a28aaa8798d13e2f950c1a24d92d17519e3c32aef86714586

View File

@ -793,7 +793,8 @@ char *sqlite3Normalize(
int prevTokenType = 0; /* Type of the previous token, except spaces */
int n; /* Size of the next token */
int nParen = 0; /* Nesting level of parenthesis */
Hash inHash; /* Table of parenthesis levels to output index. */
int iStartIN = 0; /* Start of RHS of IN operator in z[] */
int nParenAtIN = 0; /* Value of nParent at start of RHS of IN operator */
db = sqlite3VdbeDb(pVdbe);
assert( db!=0 );
@ -801,7 +802,6 @@ char *sqlite3Normalize(
nZ = estimateNormalizedSize(zSql, nSql);
z = sqlite3DbMallocRawNN(db, nZ);
if( z==0 ) goto normalizeError;
sqlite3HashInit(&inHash);
for(i=j=0; i<nSql && zSql[i]; i+=n){
int flags = 0;
if( tokenType!=TK_SPACE ) prevTokenType = tokenType;
@ -826,21 +826,18 @@ char *sqlite3Normalize(
if( tokenType==TK_LP ){
nParen++;
if( prevTokenType==TK_IN ){
assert( nParen<nSql );
sqlite3HashInsert(&inHash, zSql+nParen, SQLITE_INT_TO_PTR(j));
iStartIN = j;
nParenAtIN = nParen;
}
}else{
int jj;
assert( nParen<nSql );
jj = SQLITE_PTR_TO_INT(sqlite3HashFind(&inHash, zSql+nParen));
if( jj>0 ){
sqlite3HashInsert(&inHash, zSql+nParen, 0);
assert( jj+6<nZ );
memcpy(z+jj+1, "?,?,?", 5);
j = jj+6;
if( iStartIN>0 && nParen==nParenAtIN ){
assert( iStartIN+6<nZ );
memcpy(z+iStartIN+1, "?,?,?", 5);
j = iStartIN+6;
assert( nZ-1-j>=0 );
assert( nZ-1-j<nZ );
memset(z+j, 0, nZ-1-j);
iStartIN = 0;
}
nParen--;
}
@ -886,10 +883,7 @@ char *sqlite3Normalize(
}
if( tokenType==TK_ID ){
int i2 = i, n2 = n;
if( nParen>0 ){
assert( nParen<nSql );
sqlite3HashInsert(&inHash, zSql+nParen, 0);
}
if( nParen==nParenAtIN ) iStartIN = 0;
if( flags&SQLITE_TOKEN_QUOTED ){ i2++; n2-=2; }
}
copyNormalizedToken(zSql, i, n, flags, z, &j);
@ -902,12 +896,10 @@ char *sqlite3Normalize(
if( j>0 && z[j-1]!=';' ){ z[j++] = ';'; }
z[j] = 0;
assert( j<nZ && "two" );
sqlite3HashClear(&inHash);
return z;
normalizeError:
sqlite3DbFree(db, z);
sqlite3HashClear(&inHash);
return 0;
}
#endif /* SQLITE_ENABLE_NORMALIZE */