aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2010-05-19 19:26:05 +0000
committerdrh <drh@noemail.net>2010-05-19 19:26:05 +0000
commit9ff27ecdb2de9f010c4ba4bce262a0ea1c96ecdb (patch)
tree74ecb7012a13b09c887830b0cbb95fd1db5b0257 /src
parent4c1cb6ab052377aed62d04eba6da4ac7ee2d3468 (diff)
downloadsqlite-9ff27ecdb2de9f010c4ba4bce262a0ea1c96ecdb.tar.gz
sqlite-9ff27ecdb2de9f010c4ba4bce262a0ea1c96ecdb.zip
Add the SQLITE_FCNTL_SIZE_HINT operator to sqlite3_file_control() and use it
to give the VFS hints about the ultimate size of a database file when the file is growing. FossilOrigin-Name: 2b7e3b4a30d6a7c4a8a4b8e7dd2ed728b565c96d
Diffstat (limited to 'src')
-rw-r--r--src/os_unix.c6
-rw-r--r--src/pager.c8
-rw-r--r--src/sqlite.h.in8
3 files changed, 22 insertions, 0 deletions
diff --git a/src/os_unix.c b/src/os_unix.c
index 928ee6355..ecdd261d2 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -3045,6 +3045,12 @@ static int unixFileControl(sqlite3_file *id, int op, void *pArg){
*(int*)pArg = ((unixFile*)id)->lastErrno;
return SQLITE_OK;
}
+ case SQLITE_FCNTL_SIZE_HINT: {
+ sqlite3_int64 szFile = *(sqlite3_int64*)pArg;
+ unixFile *pFile = (unixFile*)id;
+ ftruncate(pFile->h, szFile);
+ return SQLITE_OK;
+ }
#ifndef NDEBUG
/* The pager calls this method to signal that it has done
** a rollback and that the database is therefore unchanged and
diff --git a/src/pager.c b/src/pager.c
index 42403c997..43ac8eb32 100644
--- a/src/pager.c
+++ b/src/pager.c
@@ -3332,6 +3332,14 @@ static int pager_write_pagelist(PgHdr *pList){
rc = pagerOpentemp(pPager, pPager->fd, pPager->vfsFlags);
}
+ /* Before the first write, give the VFS a hint of what the final
+ ** file size will be.
+ */
+ if( pPager->dbSize > (pPager->dbOrigSize+1) && isOpen(pPager->fd) ){
+ sqlite3_int64 szFile = pPager->pageSize * (sqlite3_int64)pPager->dbSize;
+ sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SIZE_HINT, &szFile);
+ }
+
while( rc==SQLITE_OK && pList ){
Pgno pgno = pList->pgno;
diff --git a/src/sqlite.h.in b/src/sqlite.h.in
index 8676aeaa7..4c149a684 100644
--- a/src/sqlite.h.in
+++ b/src/sqlite.h.in
@@ -678,11 +678,19 @@ struct sqlite3_io_methods {
** into an integer that the pArg argument points to. This capability
** is used during testing and only needs to be supported when SQLITE_TEST
** is defined.
+**
+** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
+** layer a hint of how large the database file will grow to be during the
+** current transaction. This hint is not guaranteed to be accurate but it
+** is often close. The underlying VFS might choose to preallocate database
+** file space based on this hint in order to help writes to the database
+** file run faster.
*/
#define SQLITE_FCNTL_LOCKSTATE 1
#define SQLITE_GET_LOCKPROXYFILE 2
#define SQLITE_SET_LOCKPROXYFILE 3
#define SQLITE_LAST_ERRNO 4
+#define SQLITE_FCNTL_SIZE_HINT 5
/*
** CAPI3REF: Mutex Handle