/ Check-in [226a9056]
Login

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

Overview
Comment:All the page_size pragma to change the page size on a new :memory: database, but not a vacuumed :memory: database. Ticket #3335 (CVS 5617)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 226a9056783247679fcf442e10807a1f2707f463
User & Date: drh 2008-08-26 21:07:27
Context
2008-08-26
21:33
In the TCL interface, disable the authorizer when during a BEGIN, COMMIT, or ROLLBACK associated with the transaction method. Ticket #3336. (CVS 5618) check-in: 7e1032ab user: drh tags: trunk
21:07
All the page_size pragma to change the page size on a new :memory: database, but not a vacuumed :memory: database. Ticket #3335 (CVS 5617) check-in: 226a9056 user: drh tags: trunk
19:08
Disable some very expensive asserts in pcache.c that are too slow for all.test. (CVS 5616) check-in: 555dad90 user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pager.c.

    14     14   ** The pager is used to access a database disk file.  It implements
    15     15   ** atomic commit and rollback through the use of a journal file that
    16     16   ** is separate from the database file.  The pager also implements file
    17     17   ** locking to prevent two processes from writing the same database
    18     18   ** file simultaneously, or one process from reading the database while
    19     19   ** another is writing.
    20     20   **
    21         -** @(#) $Id: pager.c,v 1.480 2008/08/26 18:05:48 danielk1977 Exp $
           21  +** @(#) $Id: pager.c,v 1.481 2008/08/26 21:07:27 drh Exp $
    22     22   */
    23     23   #ifndef SQLITE_OMIT_DISKIO
    24     24   #include "sqliteInt.h"
    25     25   
    26     26   /*
    27     27   ** Macros for troubleshooting.  Normally turned off
    28     28   */
................................................................................
  1941   1941   ** value before returning.
  1942   1942   */
  1943   1943   int sqlite3PagerSetPagesize(Pager *pPager, u16 *pPageSize){
  1944   1944     int rc = SQLITE_OK;
  1945   1945     u16 pageSize = *pPageSize;
  1946   1946     assert( pageSize==0 || (pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE) );
  1947   1947     if( pageSize && pageSize!=pPager->pageSize 
  1948         -   && !pPager->memDb && sqlite3PcacheRefCount(pPager->pPCache)==0 
         1948  +   && (pPager->memDb==0 || pPager->dbSize==0)
         1949  +   && sqlite3PcacheRefCount(pPager->pPCache)==0 
  1949   1950     ){
  1950   1951       char *pNew = (char *)sqlite3PageMalloc(pageSize);
  1951   1952       if( !pNew ){
  1952   1953         rc = SQLITE_NOMEM;
  1953   1954       }else{
  1954   1955         pager_reset(pPager);
  1955   1956         pPager->pageSize = pageSize;
  1956         -      setSectorSize(pPager);
         1957  +      if( !pPager->memDb ) setSectorSize(pPager);
  1957   1958         sqlite3PageFree(pPager->pTmpSpace);
  1958   1959         pPager->pTmpSpace = pNew;
  1959   1960         sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
  1960   1961       }
  1961   1962     }
  1962   1963     *pPageSize = pPager->pageSize;
  1963   1964     return rc;
................................................................................
  3568   3569   }
  3569   3570   
  3570   3571   /*
  3571   3572   ** Sync the pager file to disk.
  3572   3573   */
  3573   3574   int sqlite3PagerSync(Pager *pPager){
  3574   3575     int rc;
  3575         -  rc = sqlite3OsSync(pPager->fd, pPager->sync_flags);
         3576  +  if( MEMDB ){
         3577  +    rc = SQLITE_OK;
         3578  +  }else{
         3579  +    rc = sqlite3OsSync(pPager->fd, pPager->sync_flags);
         3580  +  }
  3576   3581     return rc;
  3577   3582   }
  3578   3583   
  3579   3584   /*
  3580   3585   ** Sync the database file for the pager pPager. zMaster points to the name
  3581   3586   ** of a master journal file that should be written into the individual
  3582   3587   ** journal file. zMaster may be NULL, which is interpreted as no master

Changes to src/vacuum.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used to implement the VACUUM command.
    13     13   **
    14     14   ** Most of the code in this file may be omitted by defining the
    15     15   ** SQLITE_OMIT_VACUUM macro.
    16     16   **
    17         -** $Id: vacuum.c,v 1.82 2008/08/23 16:17:56 danielk1977 Exp $
           17  +** $Id: vacuum.c,v 1.83 2008/08/26 21:07:27 drh Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include "vdbeInt.h"
    21     21   
    22     22   #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
    23     23   /*
    24     24   ** Execute zSql on database db. Return an error code.
................................................................................
    77     77   
    78     78   /*
    79     79   ** This routine implements the OP_Vacuum opcode of the VDBE.
    80     80   */
    81     81   int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
    82     82     int rc = SQLITE_OK;     /* Return code from service routines */
    83     83     Btree *pMain;           /* The database being vacuumed */
           84  +  Pager *pMainPager;      /* Pager for database being vacuumed */
    84     85     Btree *pTemp;           /* The temporary database we vacuum into */
    85     86     char *zSql = 0;         /* SQL statements */
    86     87     int saved_flags;        /* Saved value of the db->flags */
    87     88     int saved_nChange;      /* Saved value of db->nChange */
    88     89     int saved_nTotalChange; /* Saved value of db->nTotalChange */
    89     90     Db *pDb = 0;            /* Database to detach at end of vacuum */
           91  +  int isMemDb;            /* True is vacuuming a :memory: database */
    90     92     int nRes;
    91     93   
    92     94     /* Save the current value of the write-schema flag before setting it. */
    93     95     saved_flags = db->flags;
    94     96     saved_nChange = db->nChange;
    95     97     saved_nTotalChange = db->nTotalChange;
    96     98     db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks;
................................................................................
    97     99   
    98    100     if( !db->autoCommit ){
    99    101       sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
   100    102       rc = SQLITE_ERROR;
   101    103       goto end_of_vacuum;
   102    104     }
   103    105     pMain = db->aDb[0].pBt;
          106  +  pMainPager = sqlite3BtreePager(pMain);
          107  +  isMemDb = sqlite3PagerFile(pMainPager)->pMethods==0;
   104    108   
   105    109     /* Attach the temporary database as 'vacuum_db'. The synchronous pragma
   106    110     ** can be set to 'off' for this file, as it is not recovered if a crash
   107    111     ** occurs anyway. The integrity of the database is maintained by a
   108    112     ** (possibly synchronous) transaction opened on the main database before
   109    113     ** sqlite3BtreeCopyFile() is called.
   110    114     **
................................................................................
   133    137       char *zKey;
   134    138       sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
   135    139       if( nKey ) db->nextPagesize = 0;
   136    140     }
   137    141   #endif
   138    142   
   139    143     if( sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain), nRes)
   140         -   || sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes)
          144  +   || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes))
   141    145      || db->mallocFailed 
   142    146     ){
   143    147       rc = SQLITE_NOMEM;
   144    148       goto end_of_vacuum;
   145    149     }
   146    150     rc = execSql(db, "PRAGMA vacuum_db.synchronous=OFF");
   147    151     if( rc!=SQLITE_OK ){

Changes to test/pagesize.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.
    12     12   # This file implements tests for the page_size PRAGMA.
    13     13   #
    14         -# $Id: pagesize.test,v 1.12 2007/04/06 21:42:22 drh Exp $
           14  +# $Id: pagesize.test,v 1.13 2008/08/26 21:07:27 drh Exp $
    15     15   
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # This test script depends entirely on "PRAGMA page_size". So if this
    21     21   # pragma is not available, omit the whole file.
................................................................................
    75     75       }
    76     76     } 8192
    77     77   }  
    78     78   foreach PGSZ {512 2048 4096 8192} {
    79     79     if {[info exists SQLITE_MAX_PAGE_SIZE]
    80     80              && $SQLITE_MAX_PAGE_SIZE<$PGSZ} continue
    81     81     ifcapable memorydb {
    82         -    do_test pagesize-2.$PGSZ.0 {
           82  +    do_test pagesize-2.$PGSZ.0.1 {
    83     83         db close
    84     84         sqlite3 db :memory:
    85     85         execsql "PRAGMA page_size=$PGSZ;"
    86     86         execsql {PRAGMA page_size}
    87         -    } 1024
           87  +    } $PGSZ
           88  +    do_test pagesize-2.$PGSZ.0.2 {
           89  +      execsql {CREATE TABLE t1(x UNIQUE, y UNIQUE, z UNIQUE)}
           90  +      execsql {PRAGMA page_size}
           91  +    } $PGSZ
           92  +    do_test pagesize-2.$PGSZ.0.3 {
           93  +      execsql {
           94  +        INSERT INTO t1 VALUES(1,2,3);
           95  +        INSERT INTO t1 VALUES(2,3,4);
           96  +        SELECT * FROM t1;
           97  +      }
           98  +    } {1 2 3 2 3 4}
    88     99     }
    89    100     do_test pagesize-2.$PGSZ.1 {
    90    101       db close
    91    102       file delete -force test.db
    92    103       sqlite3 db test.db
    93    104       execsql "PRAGMA page_size=$PGSZ"
    94    105       execsql {

Changes to test/vacuum3.test.

     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 changing the database page size using a 
    13     13   # VACUUM statement.
    14     14   #
    15         -# $Id: vacuum3.test,v 1.8 2008/08/23 16:17:56 danielk1977 Exp $
           15  +# $Id: vacuum3.test,v 1.9 2008/08/26 21:07:27 drh Exp $
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # If the VACUUM statement is disabled in the current build, skip all
    21     21   # the tests in this file.
    22     22   #
................................................................................
   231    231     execsql {
   232    232       PRAGMA page_size=1024;
   233    233       VACUUM;
   234    234     }
   235    235     execsql { SELECT * FROM abc } db2
   236    236   } {1 2 3 4 5 6}
   237    237   
          238  +# Unable to change the page-size of an in-memory using vacuum.
   238    239   db2 close
          240  +sqlite3 db2 :memory:
          241  +do_test vacuum3-5.1 {
          242  +  db2 eval {
          243  +    CREATE TABLE t1(x);
          244  +    INSERT INTO t1 VALUES(1234);
          245  +    PRAGMA page_size=4096;
          246  +    VACUUM;
          247  +    SELECT * FROM t1;
          248  +  }
          249  +} {1234}
          250  +do_test vacuum3-5.2 {
          251  +  db2 eval {
          252  +    PRAGMA page_size
          253  +  }
          254  +} {1024}
   239    255   
   240    256   set create_database_sql {
   241    257     BEGIN; 
   242    258     CREATE TABLE t1(a, b, c); 
   243    259     INSERT INTO t1 VALUES(1, randstr(50,50), randstr(50,50)); 
   244    260     INSERT INTO t1 SELECT a+2, b||'-'||rowid, c||'-'||rowid FROM t1; 
   245    261     INSERT INTO t1 SELECT a+4, b||'-'||rowid, c||'-'||rowid FROM t1;