]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix a problem with resizing a hash table in sqlite3session.c.
authordan <dan@noemail.net>
Sat, 19 Mar 2011 16:26:11 +0000 (16:26 +0000)
committerdan <dan@noemail.net>
Sat, 19 Mar 2011 16:26:11 +0000 (16:26 +0000)
FossilOrigin-Name: 6e5907e14d3316d56313243c4f8ce8f14d0858fc

ext/session/session2.test
ext/session/sqlite3session.c
manifest
manifest.uuid

index 21a457fde919737af2b1350d31c7aa524a2a522e..ee5cbd2daf077bf1610ce2237c5c3db21af4eb44 100644 (file)
@@ -114,6 +114,7 @@ do_common_sql {
 
 foreach {tn sql} {
   1 { INSERT INTO t1 VALUES(1, 2) } 
+
   2 {
     INSERT INTO t2 VALUES(1, NULL);
     INSERT INTO t2 VALUES(2, NULL);
@@ -122,13 +123,33 @@ foreach {tn sql} {
     INSERT INTO t2 VALUES(4, NULL);
     UPDATE t2 SET b=0 WHERE b=1;
   } 
+
   3 { INSERT INTO t3 SELECT *, NULL FROM t2 }
+
   4 {
     INSERT INTO t3 SELECT a||a, b||b, NULL FROM t3;
     DELETE FROM t3 WHERE rowid%2;
   }
+
   5 { UPDATE t3 SET c = a||b }
+
   6 { UPDATE t1 SET a = 32 }
+
+  7 { 
+    INSERT INTO t1 SELECT randomblob(32), randomblob(32) FROM t1; --    2
+    INSERT INTO t1 SELECT randomblob(32), randomblob(32) FROM t1; --    4
+    INSERT INTO t1 SELECT randomblob(32), randomblob(32) FROM t1; --    8
+    INSERT INTO t1 SELECT randomblob(32), randomblob(32) FROM t1; --   16
+    INSERT INTO t1 SELECT randomblob(32), randomblob(32) FROM t1; --   32
+    INSERT INTO t1 SELECT randomblob(32), randomblob(32) FROM t1; --   64
+    INSERT INTO t1 SELECT randomblob(32), randomblob(32) FROM t1; --  128
+    INSERT INTO t1 SELECT randomblob(32), randomblob(32) FROM t1; --  256
+    INSERT INTO t1 SELECT randomblob(32), randomblob(32) FROM t1; --  512
+    INSERT INTO t1 SELECT randomblob(32), randomblob(32) FROM t1; -- 1024
+    INSERT INTO t1 SELECT randomblob(32), randomblob(32) FROM t1; -- 2048
+    DELETE FROM t1 WHERE (rowid%3)==0;
+  }
+
 } {
   do_then_apply_sql $sql
   do_test $tn { compare_db db db2 } {}
index 411e0823773af5074386fb31479820f5c72f8eff..a76d2d29f33ff9368451301f8b596319f5aa70a2 100644 (file)
@@ -265,29 +265,31 @@ static int sessionSerializeValue(
   return SQLITE_OK;
 }
 
-#define HASH_APPEND(hash, add) ((hash) << 3) ^ (hash) ^ (int)(add)
-static int sessionHashAppendI64(int h, i64 i){
+#define HASH_APPEND(hash, add) ((hash) << 3) ^ (hash) ^ (unsigned int)(add)
+static unsigned int sessionHashAppendI64(unsigned int h, i64 i){
   h = HASH_APPEND(h, i & 0xFFFFFFFF);
   return HASH_APPEND(h, (i>>32)&0xFFFFFFFF);
 }
-static int sessionHashAppendBlob(int h, int n, const u8 *z){
+static unsigned int sessionHashAppendBlob(unsigned int h, int n, const u8 *z){
   int i;
   for(i=0; i<n; i++) h = HASH_APPEND(h, z[i]);
   return h;
 }
 
 /*
-** This function calculates a hash based on the primary key values of
-** the old.* or new.* row currently available.
+** This function may only be called from within a pre-update callback.
+** It calculates a hash based on the primary key values of the old.* or 
+** new.* row currently available. The value returned is guaranteed to
+** be less than pTab->nBucket.
 */
-static int sessionPreupdateHash(
+static unsigned int sessionPreupdateHash(
   sqlite3 *db,                    /* Database handle */
   SessionTable *pTab,             /* Session table handle */
   int bNew,                       /* True to hash the new.* PK */
   int *piHash                     /* OUT: Hash value */
 ){
-  int h = 0;
-  int i;
+  unsigned int h = 0;             /* Hash value to return */
+  int i;                          /* Used to iterate through columns */
 
   assert( pTab->nCol==sqlite3_preupdate_count(db) );
   for(i=0; i<pTab->nCol; i++){
@@ -335,15 +337,21 @@ static int sessionPreupdateHash(
   return SQLITE_OK;
 }
 
-static int sessionChangeHash(
-  sqlite3 *db,
-  SessionTable *pTab,
-  SessionChange *pChange,
-  int nBucket
+/*
+** Based on the primary key values stored in change pChange, calculate a
+** hash key, assuming the has table has nBucket buckets. The hash keys
+** calculated by this function are compatible with those calculated by
+** sessionPreupdateHash().
+*/
+static unsigned int sessionChangeHash(
+  sqlite3 *db,                    /* Database handle */
+  SessionTable *pTab,             /* Table handle */
+  SessionChange *pChange,         /* Change handle */
+  int nBucket                     /* Assume this many buckets in hash table */
 ){
-  int h = 0;
-  int i;
-  u8 *a = pChange->aRecord;
+  unsigned int h = 0;             /* Value to return */
+  int i;                          /* Used to iterate through columns */
+  u8 *a = pChange->aRecord;       /* Used to iterate through change record */
 
   for(i=0; i<pTab->nCol; i++){
     int eType = *a++;
index 15369f40cddf1de325c96a55e3c998646acd8fdc..3aa28c08c62e44f7057678c6bc7b5ba654617750 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\ssome\sbugs\sin\ssqlite3changeset_apply().
-D 2011-03-19T15:37:02
+C Fix\sa\sproblem\swith\sresizing\sa\shash\stable\sin\ssqlite3session.c.
+D 2011-03-19T16:26:12
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 27701a1653595a1f2187dc61c8117e00a6c1d50f
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -99,8 +99,8 @@ F ext/rtree/rtree_util.tcl 06aab2ed5b826545bf215fff90ecb9255a8647ea
 F ext/rtree/sqlite3rtree.h 1af0899c63a688e272d69d8e746f24e76f10a3f0
 F ext/rtree/tkt3363.test 142ab96eded44a3615ec79fba98c7bde7d0f96de
 F ext/rtree/viewrtree.tcl eea6224b3553599ae665b239bd827e182b466024
-F ext/session/session2.test 72f5926805b46a9a5f240db856dab0e5f59fc693
-F ext/session/sqlite3session.c 6518a335592f4b118d9e6b9ed9dcbe27b0ebcda7
+F ext/session/session2.test 61c7ee56d158ab614b058b860508c85db2985810
+F ext/session/sqlite3session.c 55ec4205c7a12e417c38743d81e229a31a0f7e25
 F ext/session/sqlite3session.h 9551c002efd5fde07c52994c6b592308e0df2d6a
 F ext/session/test_session.c 2559ef68e421c7fb83e2c19ef08a17343b70d535
 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
@@ -921,7 +921,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 24d4d5dd007197a141555bcca6f2ac9ab47cde80
-R 985767b788ac43658b5fdac318a5d51e
+P 7250318dda542c5bbf28852c1f1d0f3c52ae8f96
+R fb3197b98aa7c2cdada7337c44e7d717
 U dan
-Z e6cf037758a8ddd02cc6b33f9980e9f6
+Z 1901f146e1ed8385b77ee721ba556bd6
index 75eb322606517293eed55208a49ae22e42ac583f..cb8c1bd8bec45015fc77a3e138fbdd88ae635bc0 100644 (file)
@@ -1 +1 @@
-7250318dda542c5bbf28852c1f1d0f3c52ae8f96
\ No newline at end of file
+6e5907e14d3316d56313243c4f8ce8f14d0858fc
\ No newline at end of file