Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/prolly_mutate.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,13 +663,11 @@ static int tryInsertOrReplaceSingleNoRechunk(ProllyMutator *pMut){
const u8 *pOldVal;
int nOldVal;
ProllyNodeBuilder b;
int sameSize;
int i;

prollyNodeValue(pLeaf, idx, &pOldVal, &nOldVal);
if( nOldVal!=pEdit->nVal ){
prollyCursorClose(&cur);
return SQLITE_NOTFOUND;
}
sameSize = (nOldVal==pEdit->nVal);

prollyNodeBuilderInit(&b, 0, pMut->flags);
for(i=0; i<(int)pLeaf->nItems; i++){
Expand All @@ -685,7 +683,13 @@ static int tryInsertOrReplaceSingleNoRechunk(ProllyMutator *pMut){
return rc;
}
}
rc = writeBuilderNode(pMut->pStore, &b, &childHash);
if( sameSize ){
rc = writeBuilderNode(pMut->pStore, &b, &childHash);
}else{
rc = finishAndWriteBuilderNode(pMut->pStore, &b,
!cursorLeafIsRightmost(&cur),
&childHash);
}
prollyNodeBuilderFree(&b);
if( rc!=SQLITE_OK ){
prollyCursorClose(&cur);
Expand Down
29 changes: 29 additions & 0 deletions test/invariant_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,35 @@ static void test_single_row_mutation_fast_path(void){
check("single_mutation_integrity",
strcmp(queryScalarText(db, "PRAGMA integrity_check"), "ok")==0);

execSql(db, "CREATE TABLE tblob(id BLOB PRIMARY KEY, val TEXT, pad TEXT)");
execSql(db, "BEGIN");
for( i=1; i<=5000; i++ ){
char sql[256];
snprintf(sql, sizeof(sql),
"INSERT INTO tblob VALUES(x'%032x', 'row_%d', 'pad')", i, i);
execSql(db, sql);
}
execSql(db, "COMMIT");

execSql(db,
"UPDATE tblob SET val='short' WHERE id=x'000000000000000000000000000009c4'");
execSql(db,
"UPDATE tblob SET val='this replacement is intentionally longer' "
"WHERE id=x'00000000000000000000000000000d05'");

check("single_mutation_blob_count",
queryScalarInt(db, "SELECT count(*) FROM tblob")==5000);
check("single_mutation_blob_short",
strcmp(queryScalarText(db,
"SELECT val FROM tblob WHERE id=x'000000000000000000000000000009c4'"),
"short")==0);
check("single_mutation_blob_long",
strcmp(queryScalarText(db,
"SELECT val FROM tblob WHERE id=x'00000000000000000000000000000d05'"),
"this replacement is intentionally longer")==0);
check("single_mutation_blob_integrity",
strcmp(queryScalarText(db, "PRAGMA integrity_check"), "ok")==0);

sqlite3_close(db);
removeDb(dbpath);
}
Expand Down
Loading