/ Check-in [8c44b02f14]
Login

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

Overview
Comment:Fix a problem with RBU function sqlite3rbu_bp_progress() when used during an RBU vacuum.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 8c44b02f1479cec61554800702a3c1d806e4ee64b41ba2af17320f62794a02fe
User & Date: dan 2019-08-13 15:11:25
Context
2019-08-13
17:27
Update some corruption test cases to take [724f4df9c] into account. check-in: 927cd7b4c5 user: dan tags: trunk
15:22
Merge latest trunk changes with this branch. check-in: 5b4689d89c user: dan tags: reuse-schema
15:11
Fix a problem with RBU function sqlite3rbu_bp_progress() when used during an RBU vacuum. check-in: 8c44b02f14 user: dan tags: trunk
2019-08-12
18:26
Make sure the btree cursor overflow cache is cleared when overwriting a cell in sqlite3BtreeInsert(). Ticket [3cf9bb227e9a5d32] check-in: 7dae7b969e user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/rbu/rbuprogress.test.

   409    409   
   410    410         set R(nopk) $r1
   411    411         set R(vtab) $r2
   412    412         do_sp_test 5.$tn.$bReopen.$tn2.1 $bReopen test.db rbu.db $R($tn)
   413    413       }
   414    414     }
   415    415   }
          416  +
          417  +#-------------------------------------------------------------------------
          418  +# Test that sqlite3_bp_progress() works with an RBU vacuum if there
          419  +# is an rbu_count table in the db being vacuumed.
          420  +#
          421  +reset_db
          422  +do_execsql_test 6.0 {
          423  +  CREATE TABLE t1(a, b, c);
          424  +  CREATE INDEX i1 ON t1(a);
          425  +  CREATE INDEX i2 ON t1(b);
          426  +  WITH s(i) AS (
          427  +    SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100
          428  +  )
          429  +  INSERT INTO t1 SELECT i, i, i FROM s;
          430  +  CREATE TABLE rbu_count(tbl TEXT PRIMARY KEY, cnt INTEGER) WITHOUT ROWID;
          431  +  INSERT INTO rbu_count VALUES('t1', (SELECT count(*) FROM t1));
          432  +  INSERT INTO rbu_count VALUES('rbu_count', 2);
          433  +}
          434  +
          435  +forcedelete state.db
          436  +do_test 6.1 {
          437  +  set maxA 0
          438  +  set maxB 0
          439  +  sqlite3rbu_vacuum rbu test.db state.db
          440  +  while {[rbu step]=="SQLITE_OK"} {
          441  +    foreach {a b} [rbu bp_progress] {
          442  +      if {$a > $maxA} { set maxA $a }
          443  +      if {$b > $maxB} { set maxB $b }
          444  +    }
          445  +  }
          446  +  list [rbu close] $maxA $maxB
          447  +} {SQLITE_DONE 10000 10000}
   416    448   
   417    449   
   418    450   finish_test

Changes to ext/rbu/sqlite3rbu.c.

   940    940     sqlite3rbu *p = sqlite3_user_data(pCtx);
   941    941     const char *zIn;
   942    942     assert( argc==1 || argc==2 );
   943    943   
   944    944     zIn = (const char*)sqlite3_value_text(argv[0]);
   945    945     if( zIn ){
   946    946       if( rbuIsVacuum(p) ){
   947         -      assert( argc==2 );
   948         -      if( 0==sqlite3_value_int(argv[1]) ){
          947  +      assert( argc==2 || argc==1 );
          948  +      if( argc==1 || 0==sqlite3_value_int(argv[1]) ){
   949    949           sqlite3_result_text(pCtx, zIn, -1, SQLITE_STATIC);
   950    950         }
   951    951       }else{
   952    952         if( strlen(zIn)>4 && memcmp("data", zIn, 4)==0 ){
   953    953           int i;
   954    954           for(i=4; zIn[i]>='0' && zIn[i]<='9'; i++);
   955    955           if( zIn[i]=='_' && zIn[i+1] ){
................................................................................
  3856   3856     int nVal,
  3857   3857     sqlite3_value **apVal
  3858   3858   ){
  3859   3859     sqlite3rbu *p = (sqlite3rbu*)sqlite3_user_data(pCtx);
  3860   3860     sqlite3_stmt *pStmt = 0;
  3861   3861     char *zErrmsg = 0;
  3862   3862     int rc;
         3863  +  sqlite3 *db = (rbuIsVacuum(p) ? p->dbRbu : p->dbMain);
  3863   3864   
  3864   3865     assert( nVal==1 );
  3865   3866     
  3866         -  rc = prepareFreeAndCollectError(p->dbMain, &pStmt, &zErrmsg, 
         3867  +  rc = prepareFreeAndCollectError(db, &pStmt, &zErrmsg, 
  3867   3868         sqlite3_mprintf("SELECT count(*) FROM sqlite_master "
  3868   3869           "WHERE type='index' AND tbl_name = %Q", sqlite3_value_text(apVal[0]))
  3869   3870     );
  3870   3871     if( rc!=SQLITE_OK ){
  3871   3872       sqlite3_result_error(pCtx, zErrmsg, -1);
  3872   3873     }else{
  3873   3874       int nIndex = 0;
................................................................................
  3874   3875       if( SQLITE_ROW==sqlite3_step(pStmt) ){
  3875   3876         nIndex = sqlite3_column_int(pStmt, 0);
  3876   3877       }
  3877   3878       rc = sqlite3_finalize(pStmt);
  3878   3879       if( rc==SQLITE_OK ){
  3879   3880         sqlite3_result_int(pCtx, nIndex);
  3880   3881       }else{
  3881         -      sqlite3_result_error(pCtx, sqlite3_errmsg(p->dbMain), -1);
         3882  +      sqlite3_result_error(pCtx, sqlite3_errmsg(db), -1);
  3882   3883       }
  3883   3884     }
  3884   3885   
  3885   3886     sqlite3_free(zErrmsg);
  3886   3887   }
  3887   3888   
  3888   3889   /*