/ Check-in [44a015b3]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Auto-vacuum bug: Don't set meta(3) to a pointer-map page number when deleting a table. (CVS 2066)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 44a015b3a3bbecc4ec1e02bb371d3274e2b6edf3
User & Date: danielk1977 2004-11-05 12:58:25
Context
2004-11-05
15:45
Make auto-vacuum a run-time option (default determined by SQLITE_DEFAULT_AUTOVACUUM macro). (CVS 2067) check-in: b9d5f007 user: danielk1977 tags: trunk
12:58
Auto-vacuum bug: Don't set meta(3) to a pointer-map page number when deleting a table. (CVS 2066) check-in: 44a015b3 user: danielk1977 tags: trunk
12:27
Fix allocation of tables in an auto-vacuum database when the required root-page is on the free-list. (CVS 2065) check-in: 4e243337 user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

     5      5   ** a legal notice, here is a blessing:
     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12         -** $Id: btree.c,v 1.208 2004/11/05 12:27:02 danielk1977 Exp $
           12  +** $Id: btree.c,v 1.209 2004/11/05 12:58:25 danielk1977 Exp $
    13     13   **
    14     14   ** This file implements a external (disk-based) database using BTrees.
    15     15   ** For a detailed discussion of BTrees, refer to
    16     16   **
    17     17   **     Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
    18     18   **     "Sorting And Searching", pages 473-480. Addison-Wesley
    19     19   **     Publishing Company, Reading, Massachusetts.
................................................................................
  4578   4578           releasePage(pMove);
  4579   4579           if( rc!=SQLITE_OK ){
  4580   4580             return rc;
  4581   4581           }
  4582   4582           *piMoved = maxRootPgno;
  4583   4583         }
  4584   4584   
  4585         -      rc = sqlite3BtreeUpdateMeta(pBt, 4, maxRootPgno-1);
         4585  +      maxRootPgno--;
         4586  +      if( maxRootPgno==PTRMAP_PAGENO(pBt->pageSize, maxRootPgno) ){
         4587  +        maxRootPgno--;
         4588  +      }
         4589  +      rc = sqlite3BtreeUpdateMeta(pBt, 4, maxRootPgno);
  4586   4590       }else{
  4587   4591         rc = freePage(pPage);
  4588   4592         releasePage(pPage);
  4589   4593       }
  4590   4594   #endif
  4591   4595     }else{
  4592   4596       /* If sqlite3BtreeDropTable was called on page 1. */

Changes to test/autovacuum.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is testing the SELECT statement.
    13     13   #
    14         -# $Id: autovacuum.test,v 1.7 2004/11/05 12:27:03 danielk1977 Exp $
           14  +# $Id: autovacuum.test,v 1.8 2004/11/05 12:58:26 danielk1977 Exp $
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   
    19     19   # Return a string $len characters long. The returned string is $char repeated
    20     20   # over and over. For example, [make_str abc 8] returns "abcabcab".
    21     21   proc make_str {char len} {
................................................................................
   244    244     file_pages
   245    245   } {15}
   246    246   do_test autovacuum-2.4.3 {
   247    247     execsql {
   248    248       SELECT rootpage FROM sqlite_master ORDER by rootpage
   249    249     }
   250    250   } {3 4 5 6 7 8 9 10}
          251  +
          252  +# Right now there are 5 free pages in the database. Consume and then free
          253  +# a 520 pages. Then create 520 tables. This ensures that at least some of the
          254  +# desired root-pages reside on the second free-list trunk page, and that the
          255  +# trunk itself is required at some point.
          256  +do_test autovacuum-2.4.4 {
          257  +  execsql "
          258  +    INSERT INTO av3 VALUES ('[make_str abcde [expr 1020*520 + 500]]');
          259  +    DELETE FROM av3;
          260  +  "
          261  +} {}
          262  +set root_page_list [list]
          263  +for {set i 3} {$i<=532} {incr i} {
          264  +  # 207 and 412 are pointer-map pages.
          265  +  if { $i!=207 && $i!=412 } {
          266  +    lappend root_page_list $i
          267  +  }
          268  +}
          269  +do_test autovacuum-2.4.5 {
          270  +  for {set i 11} {$i<=530} {incr i} {
          271  +    execsql "CREATE TABLE av$i (x)"
          272  +  }
          273  +  execsql {
          274  +    SELECT rootpage FROM sqlite_master ORDER by rootpage
          275  +  }
          276  +} $root_page_list
          277  +
          278  +# Just for fun, delete all those tables and see if the database is 1 page.
          279  +do_test autovacuum-2.4.6 {
          280  +  execsql COMMIT;
          281  +  file_pages
          282  +} 561
          283  +integrity_check autovacuum-2.4.6
          284  +do_test autovacuum-2.4.7 {
          285  +  execsql BEGIN
          286  +  for {set i 3} {$i<=530} {incr i} {
          287  +    execsql "DROP TABLE av$i"
          288  +  }
          289  +  execsql COMMIT
          290  +  file_pages
          291  +} 1
   251    292   
   252    293   finish_test
   253    294