2007-06-24 12:00:42 +04:00
|
|
|
# 2002 March 6
|
|
|
|
#
|
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
|
|
|
#
|
|
|
|
# May you do good and not evil.
|
|
|
|
# May you find forgiveness for yourself and forgive others.
|
|
|
|
# May you share freely, never taking more than you give.
|
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
# This file implements regression tests for SQLite library.
|
|
|
|
#
|
|
|
|
# This file implements tests for the PRAGMA command.
|
|
|
|
#
|
2007-10-09 12:29:32 +04:00
|
|
|
# $Id: pragma2.test,v 1.4 2007/10/09 08:29:33 danielk1977 Exp $
|
2007-06-24 12:00:42 +04:00
|
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
|
|
|
|
|
|
|
# Test organization:
|
|
|
|
#
|
|
|
|
# pragma2-1.*: Test freelist_count pragma on the main database.
|
|
|
|
# pragma2-2.*: Test freelist_count pragma on an attached database.
|
|
|
|
# pragma2-3.*: Test trying to write to the freelist_count is a no-op.
|
2013-08-17 04:25:07 +04:00
|
|
|
# pragma2-4.*: Tests for PRAGMA cache_spill
|
2007-06-24 12:00:42 +04:00
|
|
|
#
|
|
|
|
|
2007-09-12 21:01:45 +04:00
|
|
|
ifcapable !pragma||!schema_pragmas {
|
2007-06-24 12:00:42 +04:00
|
|
|
finish_test
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-07-24 22:56:44 +03:00
|
|
|
test_set_config_pagecache 0 0
|
|
|
|
|
2007-06-24 12:00:42 +04:00
|
|
|
# Delete the preexisting database to avoid the special setup
|
|
|
|
# that the "all.test" script does.
|
|
|
|
#
|
|
|
|
db close
|
2011-08-02 04:57:34 +04:00
|
|
|
delete_file test.db test.db-journal
|
|
|
|
delete_file test3.db test3.db-journal
|
2007-06-24 12:00:42 +04:00
|
|
|
sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
|
2007-06-27 14:20:00 +04:00
|
|
|
db eval {PRAGMA auto_vacuum=0}
|
2007-06-24 12:00:42 +04:00
|
|
|
|
2015-02-27 23:28:08 +03:00
|
|
|
|
2015-09-11 23:54:44 +03:00
|
|
|
# EVIDENCE-OF: R-11211-21323 PRAGMA schema.freelist_count; Return the
|
2015-02-27 23:28:08 +03:00
|
|
|
# number of unused pages in the database file.
|
|
|
|
#
|
2007-06-24 12:00:42 +04:00
|
|
|
do_test pragma2-1.1 {
|
|
|
|
execsql {
|
|
|
|
PRAGMA freelist_count;
|
|
|
|
}
|
|
|
|
} {0}
|
|
|
|
do_test pragma2-1.2 {
|
|
|
|
execsql {
|
|
|
|
CREATE TABLE abc(a, b, c);
|
|
|
|
PRAGMA freelist_count;
|
|
|
|
}
|
|
|
|
} {0}
|
|
|
|
do_test pragma2-1.3 {
|
|
|
|
execsql {
|
|
|
|
DROP TABLE abc;
|
|
|
|
PRAGMA freelist_count;
|
|
|
|
}
|
|
|
|
} {1}
|
|
|
|
do_test pragma2-1.4 {
|
|
|
|
execsql {
|
|
|
|
PRAGMA main.freelist_count;
|
|
|
|
}
|
|
|
|
} {1}
|
|
|
|
|
2011-08-02 04:57:34 +04:00
|
|
|
forcedelete test2.db
|
|
|
|
forcedelete test2.db-journal
|
2007-06-24 12:00:42 +04:00
|
|
|
|
2007-10-09 12:29:32 +04:00
|
|
|
ifcapable attach {
|
|
|
|
do_test pragma2-2.1 {
|
|
|
|
execsql {
|
|
|
|
ATTACH 'test2.db' AS aux;
|
|
|
|
PRAGMA aux.auto_vacuum=OFF;
|
|
|
|
PRAGMA aux.freelist_count;
|
|
|
|
}
|
|
|
|
} {0}
|
|
|
|
do_test pragma2-2.2 {
|
|
|
|
execsql {
|
|
|
|
CREATE TABLE aux.abc(a, b, c);
|
|
|
|
PRAGMA aux.freelist_count;
|
|
|
|
}
|
|
|
|
} {0}
|
|
|
|
do_test pragma2-2.3 {
|
|
|
|
set ::val [string repeat 0123456789 1000]
|
|
|
|
execsql {
|
|
|
|
INSERT INTO aux.abc VALUES(1, 2, $::val);
|
|
|
|
PRAGMA aux.freelist_count;
|
|
|
|
}
|
|
|
|
} {0}
|
|
|
|
do_test pragma2-2.4 {
|
|
|
|
expr {[file size test2.db] / 1024}
|
|
|
|
} {11}
|
|
|
|
do_test pragma2-2.5 {
|
|
|
|
execsql {
|
|
|
|
DELETE FROM aux.abc;
|
|
|
|
PRAGMA aux.freelist_count;
|
|
|
|
}
|
|
|
|
} {9}
|
|
|
|
|
|
|
|
do_test pragma2-3.1 {
|
|
|
|
execsql {
|
|
|
|
PRAGMA aux.freelist_count;
|
|
|
|
PRAGMA main.freelist_count;
|
|
|
|
PRAGMA freelist_count;
|
|
|
|
}
|
|
|
|
} {9 1 1}
|
|
|
|
do_test pragma2-3.2 {
|
|
|
|
execsql {
|
|
|
|
PRAGMA freelist_count = 500;
|
|
|
|
PRAGMA freelist_count;
|
|
|
|
}
|
|
|
|
} {1 1}
|
|
|
|
do_test pragma2-3.3 {
|
|
|
|
execsql {
|
|
|
|
PRAGMA aux.freelist_count = 500;
|
|
|
|
PRAGMA aux.freelist_count;
|
|
|
|
}
|
|
|
|
} {9 9}
|
|
|
|
}
|
2007-06-24 12:00:42 +04:00
|
|
|
|
2013-08-17 04:25:07 +04:00
|
|
|
# Default setting of PRAGMA cache_spill is always ON
|
|
|
|
#
|
2015-12-04 01:33:55 +03:00
|
|
|
# EVIDENCE-OF: R-63549-59887 PRAGMA cache_spill; PRAGMA
|
|
|
|
# cache_spill=boolean; PRAGMA schema.cache_spill=N;
|
2013-10-12 00:14:37 +04:00
|
|
|
#
|
|
|
|
# EVIDENCE-OF: R-23955-02765 Cache_spill is enabled by default
|
|
|
|
#
|
2013-08-17 04:25:07 +04:00
|
|
|
db close
|
|
|
|
delete_file test.db test.db-journal
|
2013-08-17 19:42:29 +04:00
|
|
|
delete_file test2.db test2.db-journal
|
2013-08-17 04:25:07 +04:00
|
|
|
sqlite3 db test.db
|
|
|
|
do_execsql_test pragma2-4.1 {
|
2015-11-13 00:42:40 +03:00
|
|
|
PRAGMA main.cache_size=2000;
|
|
|
|
PRAGMA temp.cache_size=2000;
|
2013-08-17 04:25:07 +04:00
|
|
|
PRAGMA cache_spill;
|
|
|
|
PRAGMA main.cache_spill;
|
|
|
|
PRAGMA temp.cache_spill;
|
2015-11-12 17:57:19 +03:00
|
|
|
} {2000 2000 2000}
|
2013-08-17 04:25:07 +04:00
|
|
|
do_execsql_test pragma2-4.2 {
|
|
|
|
PRAGMA cache_spill=OFF;
|
|
|
|
PRAGMA cache_spill;
|
|
|
|
PRAGMA main.cache_spill;
|
|
|
|
PRAGMA temp.cache_spill;
|
|
|
|
} {0 0 0}
|
|
|
|
do_execsql_test pragma2-4.3 {
|
|
|
|
PRAGMA page_size=1024;
|
|
|
|
PRAGMA cache_size=50;
|
|
|
|
BEGIN;
|
|
|
|
CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, d);
|
|
|
|
INSERT INTO t1 VALUES(1, randomblob(400), 1, randomblob(400));
|
|
|
|
INSERT INTO t1 SELECT a+1, randomblob(400), a+1, randomblob(400) FROM t1;
|
|
|
|
INSERT INTO t1 SELECT a+2, randomblob(400), a+2, randomblob(400) FROM t1;
|
|
|
|
INSERT INTO t1 SELECT a+4, randomblob(400), a+4, randomblob(400) FROM t1;
|
|
|
|
INSERT INTO t1 SELECT a+8, randomblob(400), a+8, randomblob(400) FROM t1;
|
|
|
|
INSERT INTO t1 SELECT a+16, randomblob(400), a+16, randomblob(400) FROM t1;
|
|
|
|
INSERT INTO t1 SELECT a+32, randomblob(400), a+32, randomblob(400) FROM t1;
|
|
|
|
INSERT INTO t1 SELECT a+64, randomblob(400), a+64, randomblob(400) FROM t1;
|
|
|
|
COMMIT;
|
2013-08-17 19:42:29 +04:00
|
|
|
ATTACH 'test2.db' AS aux1;
|
|
|
|
CREATE TABLE aux1.t2(a INTEGER PRIMARY KEY, b, c, d);
|
|
|
|
INSERT INTO t2 SELECT * FROM t1;
|
|
|
|
DETACH aux1;
|
2013-08-17 04:25:07 +04:00
|
|
|
PRAGMA cache_spill=ON;
|
|
|
|
} {}
|
2013-08-19 22:37:18 +04:00
|
|
|
sqlite3_release_memory
|
2013-10-12 00:14:37 +04:00
|
|
|
#
|
|
|
|
# EVIDENCE-OF: R-07634-40532 The cache_spill pragma enables or disables
|
|
|
|
# the ability of the pager to spill dirty cache pages to the database
|
|
|
|
# file in the middle of a transaction.
|
|
|
|
#
|
2013-08-17 04:25:07 +04:00
|
|
|
do_test pragma2-4.4 {
|
|
|
|
db eval {
|
|
|
|
BEGIN;
|
|
|
|
UPDATE t1 SET c=c+1;
|
|
|
|
PRAGMA lock_status;
|
|
|
|
}
|
|
|
|
} {main exclusive temp unknown} ;# EXCLUSIVE lock due to cache spill
|
2015-11-12 17:57:19 +03:00
|
|
|
do_test pragma2-4.5.1 {
|
2013-08-17 04:25:07 +04:00
|
|
|
db eval {
|
2015-11-12 17:57:19 +03:00
|
|
|
ROLLBACK;
|
2013-08-17 04:25:07 +04:00
|
|
|
PRAGMA cache_spill=OFF;
|
2015-11-12 17:57:19 +03:00
|
|
|
PRAGMA Cache_Spill;
|
2013-08-17 04:25:07 +04:00
|
|
|
BEGIN;
|
2015-11-12 17:57:19 +03:00
|
|
|
UPDATE t1 SET c=c+1;
|
|
|
|
PRAGMA lock_status;
|
|
|
|
}
|
|
|
|
} {0 main reserved temp unknown} ;# No cache spill, so no exclusive lock
|
2015-12-04 01:33:55 +03:00
|
|
|
|
|
|
|
|
|
|
|
# EVIDENCE-OF: R-34657-61226 The "PRAGMA cache_spill=N" form of this
|
|
|
|
# pragma sets a minimum cache size threshold required for spilling to
|
|
|
|
# occur.
|
2015-11-12 17:57:19 +03:00
|
|
|
do_test pragma2-4.5.2 {
|
|
|
|
db eval {
|
|
|
|
ROLLBACK;
|
|
|
|
PRAGMA cache_spill=100000;
|
|
|
|
PRAGMA cache_spill;
|
|
|
|
BEGIN;
|
|
|
|
UPDATE t1 SET c=c+1;
|
|
|
|
PRAGMA lock_status;
|
|
|
|
}
|
2015-11-12 18:47:48 +03:00
|
|
|
} {100000 main reserved temp unknown} ;# Big spill threshold -> no excl lock
|
2015-11-13 15:32:01 +03:00
|
|
|
ifcapable !memorymanage {
|
|
|
|
do_test pragma2-4.5.3 {
|
|
|
|
db eval {
|
|
|
|
ROLLBACK;
|
|
|
|
PRAGMA cache_spill=25;
|
|
|
|
PRAGMA main.cache_spill;
|
|
|
|
BEGIN;
|
|
|
|
UPDATE t1 SET c=c+1;
|
|
|
|
PRAGMA lock_status;
|
|
|
|
}
|
|
|
|
} {50 main exclusive temp unknown} ;# Small cache spill -> exclusive lock
|
|
|
|
do_test pragma2-4.5.4 {
|
|
|
|
db eval {
|
|
|
|
ROLLBACK;
|
|
|
|
PRAGMA cache_spill(-25);
|
|
|
|
PRAGMA main.cache_spill;
|
|
|
|
BEGIN;
|
|
|
|
UPDATE t1 SET c=c+1;
|
|
|
|
PRAGMA lock_status;
|
|
|
|
}
|
|
|
|
} {50 main exclusive temp unknown} ;# Small cache spill -> exclusive lock
|
|
|
|
}
|
2015-11-12 17:57:19 +03:00
|
|
|
|
2013-08-17 04:25:07 +04:00
|
|
|
|
2013-08-17 19:42:29 +04:00
|
|
|
# Verify that newly attached databases inherit the cache_spill=OFF
|
|
|
|
# setting.
|
|
|
|
#
|
|
|
|
do_execsql_test pragma2-4.6 {
|
2015-11-12 17:57:19 +03:00
|
|
|
ROLLBACK;
|
|
|
|
PRAGMA cache_spill=OFF;
|
2013-08-17 19:42:29 +04:00
|
|
|
ATTACH 'test2.db' AS aux1;
|
|
|
|
PRAGMA aux1.cache_size=50;
|
|
|
|
BEGIN;
|
|
|
|
UPDATE t2 SET c=c+1;
|
|
|
|
PRAGMA lock_status;
|
|
|
|
} {main unlocked temp unknown aux1 reserved}
|
|
|
|
do_execsql_test pragma2-4.7 {
|
|
|
|
COMMIT;
|
2013-08-19 22:37:18 +04:00
|
|
|
}
|
|
|
|
sqlite3_release_memory
|
|
|
|
do_execsql_test pragma2-4.8 {
|
2013-08-17 19:42:29 +04:00
|
|
|
PRAGMA cache_spill=ON; -- Applies to all databases
|
|
|
|
BEGIN;
|
|
|
|
UPDATE t2 SET c=c-1;
|
|
|
|
PRAGMA lock_status;
|
|
|
|
} {main unlocked temp unknown aux1 exclusive}
|
2015-11-12 18:47:48 +03:00
|
|
|
db close
|
|
|
|
forcedelete test.db
|
|
|
|
sqlite3 db test.db
|
|
|
|
|
|
|
|
do_execsql_test pragma2-5.1 {
|
|
|
|
PRAGMA page_size=16384;
|
|
|
|
CREATE TABLE t1(x);
|
|
|
|
PRAGMA cache_size=2;
|
|
|
|
PRAGMA cache_spill=YES;
|
|
|
|
PRAGMA cache_spill;
|
|
|
|
} {2}
|
|
|
|
do_execsql_test pragma2-5.2 {
|
|
|
|
PRAGMA cache_spill=NO;
|
|
|
|
PRAGMA cache_spill;
|
|
|
|
} {0}
|
|
|
|
do_execsql_test pragma2-5.3 {
|
|
|
|
PRAGMA cache_spill(-51);
|
|
|
|
PRAGMA cache_spill;
|
|
|
|
} {3}
|
2013-08-17 19:42:29 +04:00
|
|
|
|
2015-07-24 22:56:44 +03:00
|
|
|
test_restore_config_pagecache
|
2007-06-24 12:00:42 +04:00
|
|
|
finish_test
|