1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Improvements to the way that truncation is implemented in sqlite_dbpage().

FossilOrigin-Name: ac4bb2e4ecf0bdb0d8ac12b1ccb42d51af02f519a038cfc79faab5c216971056
This commit is contained in:
drh
2025-01-02 15:03:13 +00:00
parent e0b6ee5185
commit a683b055fb
5 changed files with 152 additions and 20 deletions

View File

@ -317,6 +317,24 @@ static int dbpageRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){
return SQLITE_OK;
}
/*
** Open write transactions. Since we do not know in advance which database
** files will be written by the sqlite_dbpage virtual table, start a write
** transaction on them all.
**
** Return SQLITE_OK if successful, or an SQLite error code otherwise.
*/
static int dbpageBeginTrans(DbpageTable *pTab){
sqlite3 *db = pTab->db;
int rc = SQLITE_OK;
int i;
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
Btree *pBt = db->aDb[i].pBt;
if( pBt ) rc = sqlite3BtreeBeginTrans(pBt, 1, 0);
}
return rc;
}
static int dbpageUpdate(
sqlite3_vtab *pVtab,
int argc,
@ -384,6 +402,12 @@ static int dbpageUpdate(
goto update_fail;
}
}
if( dbpageBeginTrans(pTab)!=SQLITE_OK ){
zErr = "failed to open transaction";
goto update_fail;
}
pPager = sqlite3BtreePager(pBt);
rc = sqlite3PagerGet(pPager, pgno, (DbPage**)&pDbPage, 0);
if( rc==SQLITE_OK ){
@ -405,18 +429,8 @@ update_fail:
return SQLITE_ERROR;
}
/* Since we do not know in advance which database files will be
** written by the sqlite_dbpage virtual table, start a write transaction
** on them all.
*/
static int dbpageBegin(sqlite3_vtab *pVtab){
DbpageTable *pTab = (DbpageTable *)pVtab;
sqlite3 *db = pTab->db;
int i;
for(i=0; i<db->nDb; i++){
Btree *pBt = db->aDb[i].pBt;
if( pBt ) (void)sqlite3BtreeBeginTrans(pBt, 1, 0);
}
pTab->pgnoTrunc = 0;
return SQLITE_OK;
}
@ -474,7 +488,7 @@ int sqlite3DbpageRegister(sqlite3 *db){
0, /* xRename */
0, /* xSavepoint */
0, /* xRelease */
dbpageRollbackTo, /* xRollbackTo */
0/*dbpageRollbackTo*/, /* xRollbackTo */
0, /* xShadowName */
0 /* xIntegrity */
};