]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Use a hash table to improve the preformance of column name uniqueness checking.
authordrh <drh@noemail.net>
Sat, 14 Nov 2015 20:52:43 +0000 (20:52 +0000)
committerdrh <drh@noemail.net>
Sat, 14 Nov 2015 20:52:43 +0000 (20:52 +0000)
FossilOrigin-Name: 5b08f29f458c600401860c7d70d8174cf61e69f8

manifest
manifest.uuid
src/select.c

index abc88a688687ce44116eae68ec80a290db71ee3f..201d4ffc8cf9436f45ac7533bc2275307373a782 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Use\srandomness\sto\sprevent\sshowness\sin\sthe\sgenerated-column-name\suniqueness\nchecking.
-D 2015-11-14T16:47:23.463
+C Use\sa\shash\stable\sto\simprove\sthe\spreformance\sof\scolumn\sname\suniqueness\schecking.
+D 2015-11-14T20:52:43.849
 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc e928e68168df69b353300ac87c10105206653a03
@@ -339,7 +339,7 @@ F src/printf.c 0c4bcdd1c2e2521024f0a69cb5eb334f86b3652a
 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696
 F src/resolve.c 1954a0f01bf65d78d7d559aea3d5c67f33376d91
 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e
-F src/select.c 7ef4a946893f171920843d4d8c30c2544a060fbe
+F src/select.c d5878c33d9bb66c82b2b7773731bf290248763bb
 F src/shell.c acefb4593a9bf0338a757c968f1f1bb05690d830
 F src/sqlite.h.in fa62718f73553f06b2f2e362fd09ccb4e1cbb626
 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad
@@ -1403,7 +1403,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P dfd6d9f4fbe902086f9158dfa5f37e781765a683
-R f75d239f0c3cc028f9c3bdc5405581af
+P 6266712968a2cdcd6f5a3007d60c2cf1b3faf912
+R 7d9535e63307ca117e4aa92e0ee4dc2c
 U drh
-Z df73d438cc87e48519d39f020060cfa5
+Z d8b237007fcc1a03b5ce77808531ddb1
index ea0fe67b119c47217cd48ca7ad1cbfeb9b03a1fa..8463d0d8ec86063ea7fde02b9a4ca9fe6df711b0 100644 (file)
@@ -1 +1 @@
-6266712968a2cdcd6f5a3007d60c2cf1b3faf912
\ No newline at end of file
+5b08f29f458c600401860c7d70d8174cf61e69f8
\ No newline at end of file
index afebf87ba4a3815b32b9f382725944a959ee9e4c..802e75eeca0b623ec47a7ea1143d17a713adaadc 100644 (file)
@@ -1602,7 +1602,9 @@ int sqlite3ColumnsFromExprList(
   Expr *p;                    /* Expression for a single result column */
   char *zName;                /* Column name */
   int nName;                  /* Size of name in zName[] */
+  Hash ht;                    /* Hash table of column names */
 
+  sqlite3HashInit(&ht);
   if( pEList ){
     nCol = pEList->nExpr;
     aCol = sqlite3DbMallocZero(db, sizeof(aCol[0])*nCol);
@@ -1614,7 +1616,7 @@ int sqlite3ColumnsFromExprList(
   *pnCol = nCol;
   *paCol = aCol;
 
-  for(i=0, pCol=aCol; i<nCol; i++, pCol++){
+  for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){
     /* Get an appropriate name for the column
     */
     p = sqlite3ExprSkipCollate(pEList->a[i].pExpr);
@@ -1643,32 +1645,28 @@ int sqlite3ColumnsFromExprList(
         zName = sqlite3MPrintf(db, "%s", pEList->a[i].zSpan);
       }
     }
-    if( db->mallocFailed ){
-      sqlite3DbFree(db, zName);
-      break;
-    }
 
     /* Make sure the column name is unique.  If the name is not unique,
     ** append an integer to the name so that it becomes unique.
     */
-    nName = sqlite3Strlen30(zName);
-    for(j=cnt=0; j<i; j++){
-      if( sqlite3StrICmp(aCol[j].zName, zName)==0 ){
-        char *zNewName;
-        int k;
-        for(k=nName-1; k>1 && sqlite3Isdigit(zName[k]); k--){}
-        if( k>=0 && zName[k]==':' ) nName = k;
-        zName[nName] = 0;
-        zNewName = sqlite3MPrintf(db, "%s:%u", zName, ++cnt);
-        sqlite3DbFree(db, zName);
-        zName = zNewName;
-        j = -1;
-        if( zName==0 ) break;
-        if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt);
-      }
+    cnt = 0;
+    while( zName && sqlite3HashFind(&ht, zName)!=0 ){
+      char *zNewName;
+      nName = sqlite3Strlen30(zName);
+      for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){}
+      if( zName[j]==':' ) nName = j;
+      zName[nName] = 0;
+      zNewName = sqlite3MPrintf(db, "%s:%u", zName, ++cnt);
+      sqlite3DbFree(db, zName);
+      zName = zNewName;
+      if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt);
     }
     pCol->zName = zName;
+    if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){
+      db->mallocFailed = 1;
+    }
   }
+  sqlite3HashClear(&ht);
   if( db->mallocFailed ){
     for(j=0; j<i; j++){
       sqlite3DbFree(db, aCol[j].zName);