]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix a problem in the new b-tree balancer that was causing corruption of
authordrh <drh@noemail.net>
Thu, 27 Nov 2014 03:46:04 +0000 (03:46 +0000)
committerdrh <drh@noemail.net>
Thu, 27 Nov 2014 03:46:04 +0000 (03:46 +0000)
the fragmentation count.

FossilOrigin-Name: f242394e079dd185aad90f2aee902a5edf27e150

manifest
manifest.uuid
src/btree.c
test/btree01.test [new file with mode: 0644]

index 61c47f746e7e391e3bc875464e14a8f864082bee..21c1471b6b0942c6fa6a0288c57e1909a0fed1bb 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\san\sinteger\soverflow\sbug\sin\svdbesort.c.
-D 2014-11-25T18:59:55.761
+C Fix\sa\sproblem\sin\sthe\snew\sb-tree\sbalancer\sthat\swas\scausing\scorruption\sof\nthe\sfragmentation\scount.
+D 2014-11-27T03:46:04.203
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in a226317fdf3f4c895fb3cfedc355b4d0868ce1fb
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -173,7 +173,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240
 F src/backup.c 7ddee9c7d505e07e959a575b18498f17c71e53ea
 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb
 F src/btmutex.c 49ca66250c7dfa844a4d4cb8272b87420d27d3a5
-F src/btree.c 4db5e06ca2d1a5437be7075251fa702c76179b0e
+F src/btree.c c82a514c0622e47141cca05617f5fa17ecbc909f
 F src/btree.h e31a3a3ebdedb1caf9bda3ad5dbab3db9b780f6e
 F src/btreeInt.h 3363e18fd76f69a27a870b25221b2345b3fd4d21
 F src/build.c 67bb05b1077e0cdaccb2e36bfcbe7a5df9ed31e8
@@ -379,6 +379,7 @@ F test/boundary3.tcl 23361e108a125dca9c4080c2feb884fe54d69243
 F test/boundary3.test 56ef82096b4329aca2be74fa1e2b0f762ea0eb45
 F test/boundary4.tcl 0bb4b1a94f4fc5ae59b79b9a2b7a140c405e2983
 F test/boundary4.test 89e02fa66397b8a325d5eb102b5806f961f8ec4b
+F test/btree01.test 717fcf43f66da534671bef795c993e2f9b3b2e3e
 F test/btreefault.test c2bcb542685eea44621275cfedbd8a13f65201e3
 F test/busy.test 76b4887f8b9160ba903c1ac22e8ff406ad6ae2f0
 F test/cache.test 13bc046b26210471ca6f2889aceb1ea52dc717de
@@ -1222,7 +1223,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 1e1221fc4823a6bb6fc5d2408732e27aca585de9
-R d9420ee27960cebcc5a5d23852d1a5da
-U dan
-Z 0b92bbab30b87a9f1cf79fdddb96f8d5
+P 623827192532f08b68bc0eb9ed1449e173361f0c
+R 93dc522ced281537ee4ee3dde5b73f25
+U drh
+Z 0ffb28de24b6b45b6e628c5a31b22be7
index 03036e1affffa79ef5b79cedfee167368946bab0..a6fb19304dea7a12d5f8a9834b96667ab4cf40b2 100644 (file)
@@ -1 +1 @@
-623827192532f08b68bc0eb9ed1449e173361f0c
\ No newline at end of file
+f242394e079dd185aad90f2aee902a5edf27e150
\ No newline at end of file
index 5ae5986cfa3544a9102a1b0e68c38d5479ab1102..49ac6208a9314174a24bcb431c764d3a9db512b7 100644 (file)
@@ -6257,6 +6257,14 @@ static int pageFreeArray(
 }
 
 /*
+** apCell[] and szCell[] contains pointers to and sizes of all cells in the
+** pages being balanced.  The current page, pPg, has pPg->nCell cells starting
+** with apCell[iOld].  After balancing, this page should hold nNew cells
+** starting at apCell[iNew].
+**
+** This routine makes the necessary adjustments to pPg so that it contains
+** the correct cells after being balanced.
+**
 ** The pPg->nFree field is invalid when this function returns. It is the
 ** responsibility of the caller to set it correctly.
 */
@@ -6297,12 +6305,13 @@ static void editPage(
     );
   }
 
-  pData = &aData[get2byte(&aData[hdr+5])];
+  pData = &aData[get2byteNotZero(&aData[hdr+5])];
   if( pData<pBegin ) goto editpage_fail;
 
   /* Add cells to the start of the page */
   if( iNew<iOld ){
-    int nAdd = iOld-iNew;
+    int nAdd = MIN(nNew,iOld-iNew);
+    assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB );
     pCellptr = pPg->aCellIdx;
     memmove(&pCellptr[nAdd*2], pCellptr, nCell*2);
     if( pageInsertArray(
diff --git a/test/btree01.test b/test/btree01.test
new file mode 100644 (file)
index 0000000..09358ff
--- /dev/null
@@ -0,0 +1,34 @@
+# 2014-11-27
+#
+# The author disclaims copyright to this source code.  In place of
+# a legal notice, here is a blessing:
+#
+#    May you do good and not evil.
+#    May you find forgiveness for yourself and forgive others.
+#    May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+# This file contains test cases for b-tree logic.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix btree01
+
+# The refactoring on the b-tree balance() routine in check-in
+# http://www.sqlite.org/src/info/face33bea1ba3a (2014-10-27)
+# caused the integrity_check on the following SQL to fail.
+#
+do_execsql_test btree01-1.1 {
+  PRAGMA page_size=65536;
+  CREATE TABLE t1(a INTEGER PRIMARY KEY, b BLOB);
+  WITH RECURSIVE
+     c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30)
+  INSERT INTO t1(a,b) SELECT i, zeroblob(6500) FROM c;
+  UPDATE t1 SET b=zeroblob(3000);
+  UPDATE t1 SET b=zeroblob(64000) WHERE a=2;
+  PRAGMA integrity_check;
+} {ok}
+
+finish_test