SQLite

Check-in [3fae483fae]
Login

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

Overview
Comment:Fix an issue that was causing the new database image to be assembled entirely in heap memory when VACUUMing a database, even if it should use a temp file. This could cause SQLITE_NOMEM errors when vacuuming very large databases on 32-bit systems.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | branch-3.15
Files: files | file ages | folders
SHA1: 3fae483faea3370785ac44ac65dbd03c21b9f6f2
User & Date: drh 2016-11-03 18:36:26.648
Context
2016-11-03
18:38
Escape non-ASCII character from an ICU extension comment. (check-in: ee16fedd20 user: drh tags: branch-3.15)
18:36
Fix an issue that was causing the new database image to be assembled entirely in heap memory when VACUUMing a database, even if it should use a temp file. This could cause SQLITE_NOMEM errors when vacuuming very large databases on 32-bit systems. (check-in: 3fae483fae user: drh tags: branch-3.15)
18:35
Make sure left-join markings are transferred to the virtual scalar subexpressions when decomposing a vector comparison in the ON clause of a LEFT JOIN. Fix for ticket [fef4bb4bd9185ec8f]. (check-in: aba1e22bba user: drh tags: branch-3.15)
2016-11-02
14:50
Fix an issue that was causing the new database image to be assembled entirely in heap memory when VACUUMing a database, even if it should use a temp file. This could cause SQLITE_NOMEM errors when vacuuming very large databases on 32-bit systems. (check-in: 3028845329 user: dan tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/vacuum.c.
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
    sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
    if( nKey ) db->nextPagesize = 0;
  }
#endif

  sqlite3BtreeSetCacheSize(pTemp, db->aDb[iDb].pSchema->cache_size);
  sqlite3BtreeSetSpillSize(pTemp, sqlite3BtreeSetSpillSize(pMain,0));
  sqlite3BtreeSetPagerFlags(pTemp, PAGER_SYNCHRONOUS_OFF);

  /* Begin a transaction and take an exclusive lock on the main database
  ** file. This is done before the sqlite3BtreeGetPageSize(pMain) call below,
  ** to ensure that we do not try to change the page-size on a WAL database.
  */
  rc = execSql(db, pzErrMsg, "BEGIN");
  if( rc!=SQLITE_OK ) goto end_of_vacuum;







|







187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
    sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
    if( nKey ) db->nextPagesize = 0;
  }
#endif

  sqlite3BtreeSetCacheSize(pTemp, db->aDb[iDb].pSchema->cache_size);
  sqlite3BtreeSetSpillSize(pTemp, sqlite3BtreeSetSpillSize(pMain,0));
  sqlite3BtreeSetPagerFlags(pTemp, PAGER_SYNCHRONOUS_OFF|PAGER_CACHESPILL);

  /* Begin a transaction and take an exclusive lock on the main database
  ** file. This is done before the sqlite3BtreeGetPageSize(pMain) call below,
  ** to ensure that we do not try to change the page-size on a WAL database.
  */
  rc = execSql(db, pzErrMsg, "BEGIN");
  if( rc!=SQLITE_OK ) goto end_of_vacuum;
Changes to test/vacuum5.test.
10
11
12
13
14
15
16

17
18
19
20
21
22
23
#***********************************************************************
# 
# This file implements a test for VACUUM on attached databases.
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl


# If the VACUUM statement is disabled in the current build, skip all
# the tests in this file.
#
ifcapable !vacuum {
  finish_test
  return







>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#***********************************************************************
# 
# This file implements a test for VACUUM on attached databases.
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix vacuum5

# If the VACUUM statement is disabled in the current build, skip all
# the tests in this file.
#
ifcapable !vacuum {
  finish_test
  return
106
107
108
109
110
111
112
113





































114
do_execsql_test vacuum5-1.4.2 {
  PRAGMA temp.page_count;
} $sizeTemp

do_catchsql_test vacuum5-2.0 {
  VACUUM olaf;
} {1 {unknown database olaf}}






































finish_test








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
do_execsql_test vacuum5-1.4.2 {
  PRAGMA temp.page_count;
} $sizeTemp

do_catchsql_test vacuum5-2.0 {
  VACUUM olaf;
} {1 {unknown database olaf}}

#-------------------------------------------------------------------------
# Test that a temp file is opened as part of VACUUM.
#
if {$::TEMP_STORE<3} {
  db close
  testvfs tvfs 
  tvfs filter xOpen
  tvfs script open_cb
  forcedelete test.db

  set ::openfiles [list]
  proc open_cb {method args} {
    lappend ::openfiles [file tail [lindex $args 0]]
  }
  sqlite3 db test.db -vfs tvfs

  do_execsql_test 3.0 {
    PRAGMA page_size = 1024;
    PRAGMA cache_size = 50;
    CREATE TABLE t1(i INTEGER PRIMARY KEY, j UNIQUE);
    WITH s(i) AS (
      VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<1000
    )
    INSERT INTO t1 SELECT NULL, randomblob(100) FROM s;
  }

  do_execsql_test 3.1 { VACUUM }

  db close
  tvfs delete
  do_test 3.2 {
    set ::openfiles
  } {test.db test.db-journal test.db-journal {} test.db-journal}
} 



finish_test