Index: ext/session/session2.test ================================================================== --- ext/session/session2.test +++ ext/session/session2.test @@ -112,25 +112,46 @@ CREATE TABLE t3(a, b, c, PRIMARY KEY(a, b)); } foreach {tn sql} { 1 { INSERT INTO t1 VALUES(1, 2) } + 2 { INSERT INTO t2 VALUES(1, NULL); INSERT INTO t2 VALUES(2, NULL); INSERT INTO t2 VALUES(3, NULL); DELETE FROM t2 WHERE a = 2; 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: ext/session/sqlite3session.c ================================================================== --- ext/session/sqlite3session.c +++ ext/session/sqlite3session.c @@ -263,33 +263,35 @@ *pnWrite += nByte; 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; inBucket. */ -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; inCol; i++){ if( pTab->abPK[i] ){ int rc; @@ -333,19 +335,25 @@ *piHash = (h % pTab->nChange); 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; inCol; i++){ int eType = *a++; int isPK = pTab->abPK[i];