/ Check-in [1d75a41b]
Login

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

Overview
Comment:Update RBU to avoid repreparing a statement immediately after it is prepared.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 1d75a41bb2f7fcd32f9f08768517b814e452e456
User & Date: dan 2015-08-08 15:13:08
Context
2015-08-08
23:30
Fix compiler warnings and remove unreachable code. check-in: fd5608fb user: drh tags: trunk
22:47
Fix compiler warnings and remove unreachable code. check-in: be190fe7 user: drh tags: warnings
15:13
Update RBU to avoid repreparing a statement immediately after it is prepared. check-in: 1d75a41b user: dan tags: trunk
2015-08-07
20:57
Enhance the query planner so that it is able to use partial indexes that use AND-connected terms in the WHERE clause. check-in: 06576590 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Added ext/rbu/rbuB.test.

            1  +# 2014 August 30
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +#
           12  +#
           13  +
           14  +source [file join [file dirname [info script]] rbu_common.tcl]
           15  +set ::testprefix rbuB
           16  +
           17  +db close
           18  +sqlite3_shutdown
           19  +test_sqlite3_log xLog
           20  +reset_db
           21  +
           22  +proc xLog {args} { }
           23  +
           24  +set db_sql {
           25  +  CREATE TABLE t1(a PRIMARY KEY, b, c);
           26  +}
           27  +set rbu_sql {
           28  +  CREATE TABLE data_t1(a, b, c, rbu_control);
           29  +  INSERT INTO data_t1 VALUES(1, 2, 3, 0);
           30  +  INSERT INTO data_t1 VALUES(4, 5, 6, 0);
           31  +  INSERT INTO data_t1 VALUES(7, 8, 9, 0);
           32  +}
           33  +
           34  +do_test 1.1 {
           35  +  forcedelete rbu.db
           36  +  sqlite3 rbu rbu.db
           37  +  rbu eval $rbu_sql
           38  +  rbu close
           39  +
           40  +  db eval $db_sql
           41  +} {}
           42  +
           43  +set ::errlog [list]
           44  +proc xLog {err msg} { lappend ::errlog $err }
           45  +do_test 1.2 {
           46  +  run_rbu test.db rbu.db
           47  +} {SQLITE_DONE}
           48  +
           49  +do_test 1.3 {
           50  +  set ::errlog
           51  +} {SQLITE_NOTICE_RECOVER_WAL SQLITE_INTERNAL}
           52  +
           53  +do_execsql_test 1.4 {
           54  +  SELECT * FROM t1
           55  +} {1 2 3 4 5 6 7 8 9}
           56  +
           57  +db close
           58  +sqlite3_shutdown
           59  +test_sqlite3_log 
           60  +sqlite3_initialize
           61  +finish_test
           62  +

Added ext/rbu/rbu_common.tcl.

            1  +# 2015 Aug 8
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +#
           12  +
           13  +if {![info exists testdir]} {
           14  +  set testdir [file join [file dirname [info script]] .. .. test]
           15  +}
           16  +source $testdir/tester.tcl
           17  +
           18  +# Run the RBU in file $rbu on target database $target until completion.
           19  +#
           20  +proc run_rbu {target rbu} {
           21  +  sqlite3rbu rbu $target $rbu
           22  +  while 1 {
           23  +    set rc [rbu step]
           24  +    if {$rc!="SQLITE_OK"} break
           25  +  }
           26  +  rbu close
           27  +}
           28  +
           29  +proc step_rbu {target rbu} {
           30  +  while 1 {
           31  +    sqlite3rbu rbu $target $rbu
           32  +    set rc [rbu step]
           33  +    rbu close
           34  +    if {$rc != "SQLITE_OK"} break
           35  +  }
           36  +  set rc
           37  +}
           38  +

Changes to ext/rbu/sqlite3rbu.c.

  1935   1935         char *zWhere = rbuObjIterGetWhere(p, pIter);
  1936   1936         char *zOldlist = rbuObjIterGetOldlist(p, pIter, "old");
  1937   1937         char *zNewlist = rbuObjIterGetOldlist(p, pIter, "new");
  1938   1938   
  1939   1939         zCollist = rbuObjIterGetCollist(p, pIter);
  1940   1940         pIter->nCol = pIter->nTblCol;
  1941   1941   
  1942         -      /* Create the SELECT statement to read keys from data_xxx */
  1943         -      if( p->rc==SQLITE_OK ){
  1944         -        p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz,
  1945         -            sqlite3_mprintf(
  1946         -              "SELECT %s, rbu_control%s FROM '%q'%s", 
  1947         -              zCollist, (bRbuRowid ? ", rbu_rowid" : ""), 
  1948         -              pIter->zDataTbl, zLimit
  1949         -            )
  1950         -        );
  1951         -      }
  1952         -
  1953   1942         /* Create the imposter table or tables (if required). */
  1954   1943         rbuCreateImposterTable(p, pIter);
  1955   1944         rbuCreateImposterTable2(p, pIter);
  1956   1945         zWrite = (pIter->eType==RBU_PK_VTAB ? "" : "rbu_imp_");
  1957   1946   
  1958   1947         /* Create the INSERT statement to write to the target PK b-tree */
  1959   1948         if( p->rc==SQLITE_OK ){
................................................................................
  2017   2006                 "END;",
  2018   2007                 zWrite, zTbl, zNewlist
  2019   2008             );
  2020   2009           }
  2021   2010   
  2022   2011           rbuObjIterPrepareTmpInsert(p, pIter, zCollist, zRbuRowid);
  2023   2012         }
         2013  +
         2014  +      /* Create the SELECT statement to read keys from data_xxx */
         2015  +      if( p->rc==SQLITE_OK ){
         2016  +        p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz,
         2017  +            sqlite3_mprintf(
         2018  +              "SELECT %s, rbu_control%s FROM '%q'%s", 
         2019  +              zCollist, (bRbuRowid ? ", rbu_rowid" : ""), 
         2020  +              pIter->zDataTbl, zLimit
         2021  +            )
         2022  +        );
         2023  +      }
  2024   2024   
  2025   2025         sqlite3_free(zWhere);
  2026   2026         sqlite3_free(zOldlist);
  2027   2027         sqlite3_free(zNewlist);
  2028   2028         sqlite3_free(zBindings);
  2029   2029       }
  2030   2030       sqlite3_free(zCollist);