xref: /sqlite-3.40.0/test/vacuummem.test (revision cf2ad7ae)
189441bf1Sdan# 2005 February 15
289441bf1Sdan#
389441bf1Sdan# The author disclaims copyright to this source code.  In place of
489441bf1Sdan# a legal notice, here is a blessing:
589441bf1Sdan#
689441bf1Sdan#    May you do good and not evil.
789441bf1Sdan#    May you find forgiveness for yourself and forgive others.
889441bf1Sdan#    May you share freely, never taking more than you give.
989441bf1Sdan#
1089441bf1Sdan#***********************************************************************
1189441bf1Sdan# This file implements regression tests for SQLite library.  The
1289441bf1Sdan# focus of this file is testing that the VACUUM statement correctly
1389441bf1Sdan# frees any memory used for a temporary cache.
1489441bf1Sdan#
15*cf2ad7aeSdan# TESTRUNNER: slow
1689441bf1Sdan
1789441bf1Sdanset testdir [file dirname $argv0]
1889441bf1Sdansource $testdir/tester.tcl
1989441bf1Sdanset testprefix vacuummem
2089441bf1Sdan
2149dcd79eSdrhif {[permutation]=="memsubsys1"} {
2249dcd79eSdrh  finish_test
2349dcd79eSdrh  return
2449dcd79eSdrh}
2549dcd79eSdrh
2630f8c236Sdan# If ENABLE_MEMORY_MANAGEMENT is defined, when VACUUM is run the temp db
2730f8c236Sdan# is able to borrow space from the main db (and it does, because the
2830f8c236Sdan# temp db is configure with a very small cache). When the VACUUM is
2930f8c236Sdan# finished and the temp db closed, all the page-cache memory currently
3030f8c236Sdan# assigned to the temp db is freed. If ENABLE_MEMORY_MANAGEMENT is defined
3130f8c236Sdan# this causes the total memory usage to drop much more than expected,
3230f8c236Sdan# causing tests in this file to fail.
3330f8c236Sdan#
3430f8c236Sdanifcapable memorymanage {
3530f8c236Sdan  finish_test
3630f8c236Sdan  return
3730f8c236Sdan}
3830f8c236Sdan
3949dcd79eSdrh
4089441bf1Sdanproc memory_used {} {
4189441bf1Sdan  set stat [sqlite3_status SQLITE_STATUS_MEMORY_USED 1]
4289441bf1Sdan  lindex $stat 1
4389441bf1Sdan}
4489441bf1Sdan
4589441bf1Sdando_execsql_test 1.0 {
4689441bf1Sdan  PRAGMA cache_size = -2000;
4789441bf1Sdan  CREATE TABLE t1(a, b, c);
4889441bf1Sdan
4989441bf1Sdan  WITH r(i) AS (
5089441bf1Sdan    SELECT 1 UNION ALL SELECT i+1 FROM r WHERE i<100000
5189441bf1Sdan  )
5289441bf1Sdan  INSERT INTO t1 SELECT randomblob(100),randomblob(100),randomblob(100) FROM r;
5389441bf1Sdan
5489441bf1Sdan  CREATE INDEX t1a ON t1(a);
5589441bf1Sdan  CREATE INDEX t1b ON t1(b);
5689441bf1Sdan  CREATE INDEX t1c ON t1(c);
5789441bf1Sdan}
5826fe413bSdrhset ans "#/[memory_used]/"
5989441bf1Sdan
6026fe413bSdrhdo_test 1.1 { memory_used } $ans
6189441bf1Sdan
6289441bf1Sdando_execsql_test 1.2 VACUUM
6389441bf1Sdan
6426fe413bSdrhdo_test 1.3 { memory_used } $ans
6589441bf1Sdan
6689441bf1Sdando_execsql_test 1.4 {
6789441bf1Sdan  SELECT count(*) FROM t1 WHERE +a IS NOT NULL
6889441bf1Sdan} {100000}
6989441bf1Sdan
7026fe413bSdrhdo_test 1.5 { memory_used } $ans
7189441bf1Sdan
7289441bf1Sdan
7389441bf1Sdan
7489441bf1Sdanfinish_test
75