From: drh Date: Thu, 16 Apr 2015 21:57:37 +0000 (+0000) Subject: Use a heap rather than a bitmap for cell coverage and overlap testing on X-Git-Tag: version-3.8.10~104 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a33b68364b173b49652ddc884b05ea67313090b9;p=thirdparty%2Fsqlite.git Use a heap rather than a bitmap for cell coverage and overlap testing on btree pages in PRAGMA integrity_check. FossilOrigin-Name: e94b2ef2242d716379a35dba3d2df1ac512c8d30 --- a33b68364b173b49652ddc884b05ea67313090b9 diff --cc manifest index 4eae8fd3c1,b0560fd036..7fd7cbd6c6 --- a/manifest +++ b/manifest @@@ -1,5 -1,5 +1,5 @@@ - C Fix\sa\scouple\sof\sunreachable\sbranches. - D 2015-04-16T20:27:09.079 -C Use\sa\sheap\sinstead\sof\sa\sbitmap\sfor\scell\soverlap\sand\scoverage\stesting\sof\nbtree\spages\sin\sPRAGMA\sintegrity_check. -D 2015-04-16T11:56:03.678 ++C Use\sa\sheap\srather\sthan\sa\sbitmap\sfor\scell\scoverage\sand\soverlap\stesting\son\nbtree\spages\sin\sPRAGMA\sintegrity_check. ++D 2015-04-16T21:57:37.861 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f78b1ab81b64e7c57a75d170832443e66c0880a F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@@ -173,7 -173,7 +173,7 @@@ F src/auth.c b56c78ebe40a2110fd361379f7 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 - F src/btree.c c6e32d84442f79d5b96965265d65b3baa231dffc -F src/btree.c c0e7a97c1125b7b0791ced5fc7ab82adb1b47861 ++F src/btree.c 127aceb71ba93f59bc9c6ba810e992a04299e98a F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 973a22a6fd61350b454ad614832b1f0a5e25a1e4 F src/build.c 01b969b20a44a3d9620e597d9af8242348123540 @@@ -1250,7 -1250,10 +1250,8 @@@ F tool/vdbe_profile.tcl 67746953071a9f8 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f - P 55d10baf0bffdb1a34bf5627ed8f25e4a4efd942 - R 114fb2d7e0df7ea2622d3974dda61e5a -P d3c00d61581c8ba6dce5618391432d3af8d324d4 -R 47f1d98f50d53f3c70bce340530e7599 -T *branch * integrity-check-heap -T *sym-integrity-check-heap * -T -sym-trunk * ++P 8f391dffcfe068d48f854784648610d8a86f6bc8 5619c959bf7babb19fd8ba8b228be7f090fe0ce3 ++R 72a6fa603587f85ee318933146285087 ++T +closed 5619c959bf7babb19fd8ba8b228be7f090fe0ce3 U drh - Z 08da3cff84a49c68f76471919d394d1c -Z 60d66e717d835dfb89af877c15f0d57c ++Z e48be2bfe822e32604f22d78d2be1c02 diff --cc manifest.uuid index 8ae628632f,025d2170ab..9dea5b13da --- a/manifest.uuid +++ b/manifest.uuid @@@ -1,1 -1,1 +1,1 @@@ - 8f391dffcfe068d48f854784648610d8a86f6bc8 -5619c959bf7babb19fd8ba8b228be7f090fe0ce3 ++e94b2ef2242d716379a35dba3d2df1ac512c8d30 diff --cc src/btree.c index 51fca4b4be,1383193982..c23cdb947a --- a/src/btree.c +++ b/src/btree.c @@@ -8528,6 -8528,57 +8528,57 @@@ static void checkList } #endif /* SQLITE_OMIT_INTEGRITY_CHECK */ + /* + ** An implementation of a min-heap. + ** + ** aHeap[0] is the number of elements on the heap. aHeap[1] is the -** root element. For element aHeap[N] the daughter nodes are aHeap[N*2] ++** root element. The daughter nodes of aHeap[N] are aHeap[N*2] + ** and aHeap[N*2+1]. + ** + ** The heap property is this: Every node is less than or equal to both + ** of its daughter nodes. A consequence of the heap property is that the + ** root node aHeap[1] is always the minimum value current in the heap. + ** + ** The btreeHeapInsert() routine inserts an unsigned 32-bit number onto + ** the heap, preserving the heap property. The btreeHeapPull() routine + ** removes the root element from the heap (the minimum value in the heap) + ** and then move other nodes around as necessary to preserve the heap + ** property. + ** + ** This heap is used for cell overlap and coverage testing. Each u32 + ** entry represents the span of a cell or freeblock on a btree page. + ** The upper 16 bits are the index of the first byte of a range and the + ** lower 16 bits are the index of the last byte of that range. + */ + static void btreeHeapInsert(u32 *aHeap, u32 x){ + u32 j, i = ++aHeap[0]; + aHeap[i] = x; - while( i>1 && aHeap[j=i/2]>aHeap[i] ){ ++ while( (j = i/2)>0 && aHeap[j]>aHeap[i] ){ + x = aHeap[j]; + aHeap[j] = aHeap[i]; + aHeap[i] = x; + i = j; + } + } + static int btreeHeapPull(u32 *aHeap, u32 *pOut){ + u32 j, i, x; + if( (x = aHeap[0])==0 ) return 0; + *pOut = aHeap[1]; + aHeap[1] = aHeap[x]; + aHeap[x] = 0xffffffff; + aHeap[0]--; + i = 1; + while( (j = i*2)<=aHeap[0] ){ + if( aHeap[j]>aHeap[j+1] ) j++; + if( aHeap[i]zPfx; @@@ -8772,7 -8829,7 +8829,7 @@@ ** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the ** number of fragmented free bytes within the cell content area. */ -- if( cnt!=data[hdr+7] ){ ++ if( heap[0]==0 && cnt!=data[hdr+7] ){ checkAppendMsg(pCheck, "Fragmentation of %d bytes reported as %d on page %d", cnt, data[hdr+7], iPage);