/ Check-in [65e02368]
Login

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

Overview
Comment:Add further tests for sqlite3rbu_bp_progress(). Fix a problem in handling WITHOUT ROWID tables in the same.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | rbu-percent-progress
Files: files | file ages | folders
SHA1: 65e02368e2b6cec349ea71af5a456d6783b0d15e
User & Date: dan 2016-03-18 20:12:28
Context
2016-03-19
15:34
Merge latest trunk changes, including fixes to test script rbudiff.test, into this branch. check-in: 734fc68f user: dan tags: rbu-percent-progress
2016-03-18
20:12
Add further tests for sqlite3rbu_bp_progress(). Fix a problem in handling WITHOUT ROWID tables in the same. check-in: 65e02368 user: dan tags: rbu-percent-progress
18:56
Change the name of the new API on this branch to "sqlite3_bp_progress". Add tests and documentation for the same. check-in: 1a1b69e8 user: dan tags: rbu-percent-progress
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/rbu/rbuprogress.test.

    66     66   proc do_sp_test {tn bReopen target rbu reslist} {
    67     67     uplevel [list do_test $tn [subst -nocommands {
    68     68       if {$bReopen==0} { sqlite3rbu rbu $target $rbu }
    69     69       set res [list]
    70     70       while 1 {
    71     71         if {$bReopen} { sqlite3rbu rbu $target $rbu }
    72     72         set rc [rbu step]
    73         -      if {[set rc] != "SQLITE_OK"} { error "error 1" }
           73  +      if {[set rc] != "SQLITE_OK"} { rbu close ; error "error 1" }
    74     74         lappend res [lindex [rbu bp_progress] 0]
    75     75         if {[lindex [set res] end]==10000} break
    76     76         if {$bReopen} { rbu close }
    77     77       }
    78     78       if {[set res] != [list $reslist]} {
           79  +      rbu close
    79     80         error "1. reslist incorrect (expect=$reslist got=[set res])"
    80     81       }
    81     82   
    82     83       # One step to clean up the temporary tables used to update the only
    83     84       # target table in the rbu database. And one more to move the *-oal 
    84     85       # file to *-wal. After each of these steps, the progress remains
    85     86       # at "10000 0".
    86     87       #
    87     88       if {[lindex [list $reslist] 0]!=-1} {
    88     89         rbu step
    89     90         set res [rbu bp_progress]
    90     91         if {[set res] != [list 10000 0]} {
           92  +        rbu close
    91     93           error "2. reslist incorrect (expect=10000 0 got=[set res])"
    92     94         }
    93     95       }
    94     96   
    95     97       rbu step
    96     98       set res [rbu bp_progress]
    97     99       if {[set res] != [list 10000 0]} {
          100  +      rbu close
    98    101         error "3. reslist incorrect (expect=10000 0 got=[set res])"
    99    102       }
   100    103   
   101    104       # Do the checkpoint.
   102    105       while {[rbu step]=="SQLITE_OK"} { 
   103    106         foreach {a b} [rbu bp_progress] {}
   104    107         if {[set a]!=10000 || [set b]<=0 || [set b]>10000} {
          108  +        rbu close
   105    109           error "4. reslist incorrect (expect=10000 1..10000 got=[set a] [set b])"
   106    110         }
   107    111       }
   108    112   
   109    113       set res [rbu bp_progress]
   110    114       if {[set res] != [list 10000 10000]} {
          115  +      rbu close
   111    116         error "5. reslist is incorrect (expect=10000 10000 got=[set res])"
   112    117       }
   113    118   
   114    119       rbu close
   115    120     }] {SQLITE_DONE}]
   116    121   }
   117    122   
   118    123   foreach {bReopen} { 0 1 } {
   119         -
   120    124     reset_db
   121    125     do_test 2.$bReopen.1.0 {
   122    126       execsql {
   123    127         CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
   124    128       }
   125    129       create_db_file rbu.db {
   126    130         CREATE TABLE data_t1(a, b, c, rbu_control);
................................................................................
   283    287         INSERT INTO rbu_count VALUES('data_t3', 1);
   284    288         INSERT INTO rbu_count VALUES('data_t4', 1);
   285    289       }
   286    290     } {}
   287    291     do_phase2_test 3.$bReopen.1.1 $bReopen test.db rbu.db 5
   288    292   }
   289    293   
          294  +
          295  +foreach {bReopen} { 0 1 } {
          296  +  foreach {tn tbl} {
          297  +    ipk { CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c) }
          298  +    wr  { CREATE TABLE t1(a INT PRIMARY KEY, b, c) WITHOUT ROWID }
          299  +    pk  { CREATE TABLE t1(a INT PRIMARY KEY, b, c) }
          300  +  } {
          301  +
          302  +    foreach {tn2 rbusql r1 r3} {
          303  +      1 {
          304  +        CREATE TABLE data0_t1(a, b, c, rbu_control);
          305  +        INSERT INTO data0_t1 VALUES(15, 15, 15, 0);
          306  +        INSERT INTO data0_t1 VALUES(20, 20, 20, 0);
          307  +        CREATE TABLE rbu_count(tbl, cnt);
          308  +        INSERT INTO rbu_count VALUES('data0_t1', 2); 
          309  +      } 
          310  +      {2500 5000 7500 10000}
          311  +      {1666 3333 5000 6666 8333 10000}
          312  +
          313  +      2 {
          314  +        CREATE TABLE data0_t1(a, b, c, rbu_control);
          315  +        INSERT INTO data0_t1 VALUES(10, 10, 10, 2);
          316  +        CREATE TABLE rbu_count(tbl, cnt);
          317  +        INSERT INTO rbu_count VALUES('data0_t1', 1); 
          318  +      } 
          319  +      {3333 6666 10000}
          320  +      {2000 4000 6000 8000 10000}
          321  +
          322  +      3 {
          323  +        CREATE TABLE data0_t1(a, b, c, rbu_control);
          324  +        INSERT INTO data0_t1 VALUES(7, 7, 7, 2);
          325  +        INSERT INTO data0_t1 VALUES(10, 10, 10, 2);
          326  +        CREATE TABLE rbu_count(tbl, cnt);
          327  +        INSERT INTO rbu_count VALUES('data0_t1', 2); 
          328  +      } 
          329  +      {2500 4000 6000 8000 10000}
          330  +      {1666 2500 3750 5000 6250 7500 8750 10000}
          331  +
          332  +    } {
          333  +
          334  +      reset_db ; execsql $tbl
          335  +      do_test 4.$tn.$bReopen.$tn2.0 {
          336  +        execsql {
          337  +          CREATE INDEX t1c ON t1(c);
          338  +          INSERT INTO t1 VALUES(1, 1, 1);
          339  +          INSERT INTO t1 VALUES(5, 5, 5);
          340  +          INSERT INTO t1 VALUES(10, 10, 10);
          341  +        }
          342  +        create_db_file rbu.db $rbusql
          343  +      } {}
          344  +
          345  +      set R(ipk) $r1
          346  +      set R(wr) $r1
          347  +      set R(pk) $r3
          348  +      do_sp_test 4.$tn.$bReopen.$tn2.1 $bReopen test.db rbu.db $R($tn)
          349  +    }
          350  +  }
          351  +}
          352  +
          353  +foreach {bReopen} { 0 1 } {
          354  +  foreach {tn tbl} {
          355  +    nopk { 
          356  +      CREATE TABLE t1(a, b, c);
          357  +      CREATE INDEX t1c ON t1(c);
          358  +    }
          359  +    vtab { 
          360  +      CREATE VIRTUAL TABLE t1 USING fts5(a, b, c);
          361  +    }
          362  +  } {
          363  +
          364  +    foreach {tn2 rbusql r1 r2} {
          365  +      1 {
          366  +        CREATE TABLE data0_t1(a, b, c, rbu_rowid, rbu_control);
          367  +        INSERT INTO data0_t1 VALUES(15, 15, 15, 4, 0);
          368  +        INSERT INTO data0_t1 VALUES(20, 20, 20, 5, 0);
          369  +        CREATE TABLE rbu_count(tbl, cnt);
          370  +        INSERT INTO rbu_count VALUES('data0_t1', 2); 
          371  +      } 
          372  +      {2500 5000 7500 10000}
          373  +      {5000 10000}
          374  +
          375  +      2 {
          376  +        CREATE TABLE data0_t1(rbu_rowid, a, b, c, rbu_control);
          377  +        INSERT INTO data0_t1 VALUES(0, 7, 7, 7, 2);
          378  +        INSERT INTO data0_t1 VALUES(2, 10, 10, 10, 2);
          379  +        CREATE TABLE rbu_count(tbl, cnt);
          380  +        INSERT INTO rbu_count VALUES('data0_t1', 2); 
          381  +      } 
          382  +      {2500 4000 6000 8000 10000}
          383  +      {5000 10000}
          384  +    } {
          385  +
          386  +      reset_db ; execsql $tbl
          387  +      do_test 5.$tn.$bReopen.$tn2.0 {
          388  +        execsql {
          389  +          INSERT INTO t1 VALUES(1, 1, 1);
          390  +          INSERT INTO t1 VALUES(5, 5, 5);
          391  +          INSERT INTO t1 VALUES(10, 10, 10);
          392  +        }
          393  +        create_db_file rbu.db $rbusql
          394  +      } {}
          395  +
          396  +      set R(nopk) $r1
          397  +      set R(vtab) $r2
          398  +      do_sp_test 5.$tn.$bReopen.$tn2.1 $bReopen test.db rbu.db $R($tn)
          399  +    }
          400  +  }
          401  +}
          402  +
   290    403   
   291    404   finish_test
   292    405   

Changes to ext/rbu/sqlite3rbu.c.

  1197   1197         int iCid = sqlite3_column_int(pXInfo, 1);
  1198   1198         if( iCid>=0 ) pIter->abIndexed[iCid] = 1;
  1199   1199       }
  1200   1200       rbuFinalize(p, pXInfo);
  1201   1201       bIndex = 1;
  1202   1202       pIter->nIndex++;
  1203   1203     }
         1204  +
         1205  +  if( pIter->eType==RBU_PK_WITHOUT_ROWID ){
         1206  +    /* "PRAGMA index_list" includes the main PK b-tree */
         1207  +    pIter->nIndex--;
         1208  +  }
  1204   1209   
  1205   1210     rbuFinalize(p, pList);
  1206   1211     if( bIndex==0 ) pIter->abIndexed = 0;
  1207   1212   }
  1208   1213   
  1209   1214   
  1210   1215   /*
................................................................................
  1309   1314           iOrder++;
  1310   1315         }
  1311   1316       }
  1312   1317   
  1313   1318       rbuFinalize(p, pStmt);
  1314   1319       rbuObjIterCacheIndexedCols(p, pIter);
  1315   1320       assert( pIter->eType!=RBU_PK_VTAB || pIter->abIndexed==0 );
         1321  +    assert( pIter->eType!=RBU_PK_VTAB || pIter->nIndex==0 );
  1316   1322     }
  1317   1323   
  1318   1324     return p->rc;
  1319   1325   }
  1320   1326   
  1321   1327   /*
  1322   1328   ** This function constructs and returns a pointer to a nul-terminated 
................................................................................
  3118   3124     sqlite3_stmt *pStmt = 0;
  3119   3125     char *zErrmsg = 0;
  3120   3126     int rc;
  3121   3127   
  3122   3128     assert( nVal==1 );
  3123   3129     
  3124   3130     rc = prepareFreeAndCollectError(p->dbMain, &pStmt, &zErrmsg, 
  3125         -      sqlite3_mprintf("PRAGMA index_list = %Q", sqlite3_value_text(apVal[0]))
         3131  +      sqlite3_mprintf("SELECT count(*) FROM sqlite_master "
         3132  +        "WHERE type='index' AND tbl_name = %Q", sqlite3_value_text(apVal[0]))
  3126   3133     );
  3127   3134     if( rc!=SQLITE_OK ){
  3128   3135       sqlite3_result_error(pCtx, zErrmsg, -1);
  3129   3136     }else{
  3130   3137       int nIndex = 0;
  3131         -    while( SQLITE_ROW==sqlite3_step(pStmt) ){
  3132         -      nIndex++;
         3138  +    if( SQLITE_ROW==sqlite3_step(pStmt) ){
         3139  +      nIndex = sqlite3_column_int(pStmt, 0);
  3133   3140       }
  3134   3141       rc = sqlite3_finalize(pStmt);
  3135   3142       if( rc==SQLITE_OK ){
  3136   3143         sqlite3_result_int(pCtx, nIndex);
  3137   3144       }else{
  3138   3145         sqlite3_result_error(pCtx, sqlite3_errmsg(p->dbMain), -1);
  3139   3146       }