@@ -63,7 +63,7 @@ class InnerDatabaseFile : public SQLiteVFS::File {
6363
6464 std::unique_ptr<SQLite::Database> outer_db_;
6565 std::string inner_db_pages_table_;
66- bool read_only_;
66+ bool read_only_, web_ ;
6767
6868 std::string btree_interior_index_;
6969
@@ -194,10 +194,12 @@ class InnerDatabaseFile : public SQLiteVFS::File {
194194 FetchJob (InnerDatabaseFile &that)
195195 : cursor(*(that.outer_db_), "SELECT pageno, data, meta1, meta2 FROM " +
196196 that.inner_db_pages_table_ +
197- " WHERE pageno >= ? ORDER BY pageno"),
197+ " NOT INDEXED WHERE pageno >= ? ORDER BY pageno"),
198198 page_size(that.page_size_) {
199199 PutState (State::NEW);
200- if (!that.btree_interior_index_ .empty ()) {
200+ // prepare to read from btree interior index in web mode only. it can be
201+ // counterproductive locally due to its big index keys => low fan-out
202+ if (that.web_ && !that.btree_interior_index_ .empty ()) {
201203 btree_interior_cursor.reset (new SQLite::Statement (
202204 *(that.outer_db_ ), " SELECT pageno, data, meta1, meta2 FROM " +
203205 that.inner_db_pages_table_ + " INDEXED BY " +
@@ -248,6 +250,7 @@ class InnerDatabaseFile : public SQLiteVFS::File {
248250#ifndef NDEBUG
249251 non_sequential++;
250252#endif
253+
251254 // first try the covering index of interior btree pages
252255 if (btree_interior_cursor &&
253256 (btree_interior_cursor->reset (), btree_interior_cursor->bind (1 , pageno),
@@ -259,6 +262,7 @@ class InnerDatabaseFile : public SQLiteVFS::File {
259262 } else {
260263 // otherwise seek the main cursor
261264 ResetCursor ();
265+
262266 cursor.bind (1 , pageno);
263267 }
264268 } else {
@@ -1071,6 +1075,7 @@ class InnerDatabaseFile : public SQLiteVFS::File {
10711075 bool noprefetch, bool web)
10721076 : outer_db_(std::move(outer_db)),
10731077 inner_db_pages_table_ (inner_db_tablename_prefix + " pages" ), read_only_(read_only),
1078+ web_(web),
10741079 // MAX(pageno) instead of COUNT(pageno) because the latter would trigger table scan
10751080 select_page_count_(*outer_db_,
10761081 " SELECT IFNULL(MAX(pageno), 0) FROM " + inner_db_pages_table_),
@@ -1149,7 +1154,7 @@ class VFS : public SQLiteVFS::Wrapper {
11491154 for (const auto &p : ddl) {
11501155 SQLite::Statement (db, p.first + inner_db_tablename_prefix_ + p.second ).executeStep ();
11511156 }
1152- if (!sqlite3_uri_boolean (zName, " no_btree_interior_index " , 0 )) {
1157+ if (!sqlite3_uri_boolean (zName, " web_nodbi " , 0 )) {
11531158 // covering index of interior btree pages
11541159 SQLite::Statement (db, " CREATE INDEX " + inner_db_tablename_prefix_ +
11551160 " pages_btree_interior ON " + inner_db_tablename_prefix_ +
0 commit comments