From ae82558bd03677c6e06fd9af76ff6fec6373307d Mon Sep 17 00:00:00 2001 From: danielk1977 Date: Tue, 23 Nov 2004 09:06:55 +0000 Subject: [PATCH] Fix a bug involving balance_shallow() and the sqlite_master table. (CVS 2143) FossilOrigin-Name: 557be3ff5b1c46a3f3836ea3a9d9dede5dc46998 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/btree.c | 5 ++++- src/pager.c | 9 ++++++++- test/table.test | 22 +++++++++++++++++++++- 5 files changed, 43 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 2586360507..3df48f90bc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C More\swork\son\sthe\simplementation\sof\scursors,\sbut\sthey\sare\sstill\snot\nfunctioning.\s(CVS\s2142) -D 2004-11-23T01:47:30 +C Fix\sa\sbug\sinvolving\sbalance_shallow()\sand\sthe\ssqlite_master\stable.\s(CVS\s2143) +D 2004-11-23T09:06:56 F Makefile.in 8291610f5839939a5fbff4dbbf85adb0fe1ac37f F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457 F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1 @@ -29,7 +29,7 @@ F sqlite3.def dbaeb20c153e1d366e8f421b55a573f5dfc00863 F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a F src/attach.c e49d09dad9f5f9fb10b4b0c1be5a70ae4c45e689 F src/auth.c 3b81f2a42f48a62c2c9c9b0eda31a157c681edea -F src/btree.c 05fe410ebbcbac72b66bc3aeeadf7e5588b0699e +F src/btree.c fa113d624d38bcb36700a0244b47f39d57d34efb F src/btree.h 861e40b759a195ba63819740e484390012cf81ab F src/build.c b62389de594d0b413068d6e067794249a1f1d209 F src/cursor.c f883813759742068890b1f699335872bfa8fdf41 @@ -53,7 +53,7 @@ F src/os_unix.c 5824b22ba41fe9d514ef9169aac1b5fde73af229 F src/os_unix.h f3097815e041e82e24d92505e1ff61ba24172d13 F src/os_win.c 9482dfc92f289b68205bb2c9315757c7e3946bfb F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b -F src/pager.c ee88fcecb081e3635c281bc09d604e934429e2f5 +F src/pager.c 2907f0b0c9b6efc99076d5a112cadb3f9153025e F src/pager.h 9eba8c53dd91eae7f3f90743b2ee242da02a9862 F src/parse.y ceba179b9703657180963568f54b0e75f33e36e1 F src/pragma.c d6406e12c9eac353b3a026b50d41e4fd561afcc2 @@ -177,7 +177,7 @@ F test/select6.test c00d300d90f0ae3fa4e4f4336c71b2345bfa819c F test/select7.test b952604c22a5644a065e9e99dc904b5a65565f07 F test/sort.test 87882e6c72a75d45e98a1c802c1ded0eac557d85 F test/subselect.test ff3850d0aab1443dafa4ecbdab1d01e58e7b366d -F test/table.test 87a6219c784722249a2f604b6495ce171ca2588a +F test/table.test 9e0d406073cb5752e25cee36a48a1c349f634b66 F test/tableapi.test b21ab097e87a5484bb61029e69e1a4e5c5e65ede F test/tclsqlite.test 5e262df81a638a058536fb6d6666f316843ac7b2 F test/temptable.test 63a16e3ad19adf073cfbcdf7624c92ac5236522c @@ -261,7 +261,7 @@ F www/tclsqlite.tcl 560ecd6a916b320e59f2917317398f3d59b7cc25 F www/vdbe.tcl 095f106d93875c94b47367384ebc870517431618 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0 F www/whentouse.tcl fdacb0ba2d39831e8a6240d05a490026ad4c4e4c -P fc8c1393c86017a816beb52725b68af3b973f979 -R 98af4fe305ebafc3241be9d01cb582a6 -U drh -Z 5a67f7855a17ccbeb24c26f03275c455 +P 8b61d1ae1ca469b80f2b344d550c3b363448b193 +R 3b5021df085c0b0cbca8f147556371d1 +U danielk1977 +Z bf1645a7f2a7f97f2983b5f556ee8c1a diff --git a/manifest.uuid b/manifest.uuid index a7b2ef862e..deae89baed 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8b61d1ae1ca469b80f2b344d550c3b363448b193 \ No newline at end of file +557be3ff5b1c46a3f3836ea3a9d9dede5dc46998 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 8e88f21286..44f6768c1a 100644 --- a/src/btree.c +++ b/src/btree.c @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.224 2004/11/22 19:07:10 drh Exp $ +** $Id: btree.c,v 1.225 2004/11/23 09:06:56 danielk1977 Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** For a detailed discussion of BTrees, refer to @@ -4076,6 +4076,9 @@ static int balance_shallower(MemPage *pPage){ szCell[i] = cellSizePtr(pChild, apCell[i]); } assemblePage(pPage, pChild->nCell, apCell, szCell); + /* Copy the right-pointer of the child to the parent. */ + put4byte(&pPage->aData[pPage->hdrOffset+8], + get4byte(&pChild->aData[pChild->hdrOffset+8])); freePage(pChild); TRACE(("BALANCE: child %d transfer to page 1\n", pChild->pgno)); }else{ diff --git a/src/pager.c b/src/pager.c index f92a661dd9..ec1529928b 100644 --- a/src/pager.c +++ b/src/pager.c @@ -18,7 +18,7 @@ ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.177 2004/11/10 15:27:38 danielk1977 Exp $ +** @(#) $Id: pager.c,v 1.178 2004/11/23 09:06:56 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -3315,6 +3315,7 @@ int sqlite3pager_movepage(Pager *pPager, void *pData, Pgno pgno){ needSyncPgno = pPg->pgno; assert( pPg->inJournal ); assert( pPg->dirty ); + assert( pPager->needSync ); } /* Unlink pPg from it's hash-chain */ @@ -3334,6 +3335,7 @@ int sqlite3pager_movepage(Pager *pPager, void *pData, Pgno pgno){ assert( pPgOld->inJournal ); pPg->inJournal = 1; pPg->needSync = 1; + assert( pPager->needSync ); } } @@ -3357,11 +3359,16 @@ int sqlite3pager_movepage(Pager *pPager, void *pData, Pgno pgno){ ** Currently, no such page exists in the page-cache and the ** Pager.aInJournal bit has been set. This needs to be remedied by loading ** the page into the pager-cache and setting the PgHdr.needSync flag. + ** + ** The sqlite3pager_get() call may cause the journal to sync. So make + ** sure the Pager.needSync flag is set too. */ int rc; void *pNeedSync; + assert( pPager->needSync ); rc = sqlite3pager_get(pPager, needSyncPgno, &pNeedSync); if( rc!=SQLITE_OK ) return rc; + pPager->needSync = 1; DATA_TO_PGHDR(pNeedSync)->needSync = 1; DATA_TO_PGHDR(pNeedSync)->inJournal = 1; DATA_TO_PGHDR(pNeedSync)->dirty = 1; diff --git a/test/table.test b/test/table.test index 9069a5f343..7024e2bc63 100644 --- a/test/table.test +++ b/test/table.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this file is testing the CREATE TABLE statement. # -# $Id: table.test,v 1.33 2004/11/10 11:55:15 danielk1977 Exp $ +# $Id: table.test,v 1.34 2004/11/23 09:06:56 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -627,5 +627,25 @@ do_test table-14.4 { set result [list $rc $msg] } {1 {database table is locked}} +# Create and drop 2000 tables. This is to check that the balance_shallow() +# routine works correctly on the sqlite_master table. At one point it +# contained a bug that would prevent the right-child pointer of the +# child page from being copied to the root page. +# +do_test table-15.1 { + execsql {BEGIN} + for {set i 0} {$i<2000} {incr i} { + execsql "CREATE TABLE tbl$i (a, b, c)" + } + execsql {COMMIT} +} {} +do_test table-15.2 { + execsql {BEGIN} + for {set i 0} {$i<2000} {incr i} { + execsql "DROP TABLE tbl$i" + } + execsql {COMMIT} +} {} + finish_test