should be it

This commit is contained in:
2025-10-24 19:21:19 -05:00
parent a4b23fc57c
commit f09560c7b1
14047 changed files with 3161551 additions and 1 deletions

View File

@@ -0,0 +1,13 @@
# name: test/sql/storage/wal/test_wal_bc.test
# description: Test WAL backwards compatibility
# group: [wal]
# The database is written with a vector size of 2048.
require vector_size 2048
load data/storage/wal_test_092.db readonly
query II
SELECT COUNT(*), SUM(i) FROM integers
----
1000 499500

View File

@@ -0,0 +1,44 @@
# name: test/sql/storage/wal/wal_blob_storage.test
# description: Test BLOB with persistent storage with WAL
# group: [wal]
# load the DB from disk
load __TEST_DIR__/blob_storage_test.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# create a table with hugeints
statement ok
CREATE TABLE blobs (b BLOB);
statement ok
INSERT INTO blobs VALUES('a'), ('\xAA'), ('\xAA\xFF\xAA'), (''), (NULL), ('\x55\xAA\xFF\x55\xAA\xFF\x55\xAA\xFF\x01'), ('\x55\xAA\xFF\x55\xAA\xFF\x55\xAA\xFF\x01')
# reload the database from disk a few times, and check that the data is still there
loop i 0 2
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
query I
SELECT * FROM blobs
----
a
\xAA
\xAA\xFF\xAA
(empty)
NULL
U\xAA\xFFU\xAA\xFFU\xAA\xFF\x01
U\xAA\xFFU\xAA\xFFU\xAA\xFF\x01
endloop

View File

@@ -0,0 +1,45 @@
# name: test/sql/storage/wal/wal_check_constraint.test
# description: Test serialization of CHECK constraint
# group: [wal]
# load the DB from disk
load __TEST_DIR__/check_storage_test.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# create a table with a check constraint
statement ok
CREATE TABLE test(a INTEGER CHECK (a<10), b INTEGER CHECK(CASE WHEN b < 10 THEN a < b ELSE a + b < 100 END));
# reload the database
restart
# matching tuple
statement ok
INSERT INTO test VALUES (3, 7);
# check constraint on a violated (a < 10)
statement error
INSERT INTO test VALUES (12, 13);
----
<REGEX>:.*Constraint Error.*CHECK constraint failed on table.*
# check constraint on b violated (b < 10) => (a < b)
statement error
INSERT INTO test VALUES (5, 3);
----
<REGEX>:.*Constraint Error.*CHECK constraint failed on table.*
# check constraint on b not violated !(b < 10) => (a + b < 100)
statement ok
INSERT INTO test VALUES (9, 90);
# check constraint on b violated !(b < 10) => (a + b < 100)
statement error
INSERT INTO test VALUES (9, 99);
----
<REGEX>:.*Constraint Error.*CHECK constraint failed on table.*

View File

@@ -0,0 +1,227 @@
# name: test/sql/storage/wal/wal_create_index.test
# description: Test serialization of index to WAL
# group: [wal]
load __TEST_DIR__/test_wal_create_index.db
statement ok
PRAGMA disable_checkpoint_on_shutdown;
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement ok
CREATE TABLE integers(i INTEGER, j INTEGER);
statement ok
INSERT INTO integers VALUES (1, 1), (2, 2), (3, 3);
# Test single indexed column.
statement ok
CREATE UNIQUE INDEX i_index ON integers(i);
query II
EXPLAIN ANALYZE SELECT i, j FROM integers WHERE i = 1;
----
analyzed_plan <REGEX>:.*Type: Index Scan.*
query II
SELECT i, j FROM integers WHERE i = 1;
----
1 1
statement error
INSERT INTO integers VALUES (1, 1);
----
<REGEX>:Constraint Error.*violates unique constraint.*
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown;
statement ok
PRAGMA wal_autocheckpoint='1TB';
query II
EXPLAIN ANALYZE SELECT i, j FROM integers WHERE i = 1;
----
analyzed_plan <REGEX>:.*Type: Index Scan.*
query II
SELECT i, j FROM integers WHERE i = 1;
----
1 1
statement error
INSERT INTO integers VALUES (1, 1);
----
<REGEX>:Constraint Error.*violates unique constraint.*
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown;
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement ok
DROP INDEX i_index;
statement ok
INSERT INTO integers VALUES (1, 1);
statement ok
DROP TABLE integers;
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown;
statement ok
PRAGMA wal_autocheckpoint='1TB';
# Test a multi-column index expression.
statement ok
CREATE TABLE integers(i INTEGER, j INTEGER);
statement ok
INSERT INTO integers VALUES (1, 1), (2, 2), (3, 3);
statement ok
CREATE UNIQUE INDEX i_index ON integers USING art((i + j));
query II
SELECT i, j FROM integers WHERE i + j = 2;
----
1 1
statement error
INSERT INTO integers VALUES (1, 1);
----
<REGEX>:Constraint Error.*violates unique constraint.*
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown;
statement ok
PRAGMA wal_autocheckpoint='1TB';
query II
SELECT i, j FROM integers WHERE i + j = 2;
----
1 1
statement error
INSERT INTO integers VALUES (1, 1);
----
<REGEX>:Constraint Error.*violates unique constraint.*
statement ok
DROP INDEX i_index;
statement ok
INSERT INTO integers VALUES (1, 1);
statement ok
DROP TABLE integers;
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown;
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement ok
CREATE TABLE integers(i INTEGER, j INTEGER);
statement ok
INSERT INTO integers VALUES (1, 1), (2, 2), (3, 3);
# Change the column order in the multi-column index expression.
statement ok
CREATE UNIQUE INDEX i_index ON integers USING art((j + i));
query II
SELECT i, j FROM integers WHERE j + i = 2;
----
1 1
statement error
INSERT INTO integers VALUES (1, 1);
----
<REGEX>:Constraint Error.*violates unique constraint.*
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown;
statement ok
PRAGMA wal_autocheckpoint='1TB';
query II
SELECT i, j FROM integers WHERE j + i = 2;
----
1 1
statement error
INSERT INTO integers VALUES (1, 1);
----
<REGEX>:Constraint Error.*violates unique constraint.*
statement ok
DROP INDEX i_index;
statement ok
INSERT INTO integers VALUES (1, 1);
statement ok
DROP TABLE integers;
restart
# Test compound keys.
statement ok
PRAGMA disable_checkpoint_on_shutdown;
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement ok
CREATE TABLE integers(i INTEGER, j INTEGER);
statement ok
INSERT INTO integers VALUES (1, 1), (2, 2), (3, 3);
statement ok
CREATE UNIQUE INDEX i_index ON integers USING art((j + i), j, i);
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown;
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement error
INSERT INTO integers VALUES (1, 1);
----
<REGEX>:Constraint Error.*violates unique constraint.*
statement ok
DROP INDEX i_index;
statement ok
INSERT INTO integers VALUES (1, 1);

View File

@@ -0,0 +1,107 @@
# name: test/sql/storage/wal/wal_create_insert_drop.test
# description: Test serialization of CHECK constraint
# group: [wal]
# load the DB from disk
load __TEST_DIR__/wal_create_insert_drop.db
statement ok
PRAGMA disable_checkpoint_on_shutdown;
statement ok
SET checkpoint_threshold='999999GB';
statement ok
begin
statement ok
create table bla as select 42;
statement ok
drop table bla;
statement ok
create table bla as select 84;
statement ok
commit;
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown;
statement ok
SET checkpoint_threshold='999999GB';
query I
SELECT * FROM bla
----
84
statement ok
drop table bla
statement ok
begin
statement ok
create table bla as select 42;
statement ok
drop table bla;
statement ok
commit;
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown;
statement ok
SET checkpoint_threshold='999999GB';
statement ok
begin
statement ok
create table bla as select 84;
statement ok
alter table bla rename to bla2
statement ok
commit
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown;
statement ok
SET checkpoint_threshold='999999GB';
query I
from bla2
----
84
statement ok
begin
statement ok
create or replace table bla as select 84;
statement ok
create or replace table bla as select 42;
statement ok
commit
restart
query I
from bla
----
42

View File

@@ -0,0 +1,61 @@
# name: test/sql/storage/wal/wal_drop_table.test
# description: Test serialization of NOT NULL constraint
# group: [wal]
# load the DB from disk
load __TEST_DIR__/test_drop_table.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# create a schema and table and insert values
statement ok
CREATE SCHEMA test;
statement ok
CREATE TABLE test.test (a INTEGER, b INTEGER);
statement ok
INSERT INTO test.test VALUES (11, 22), (13, 22);
# drop the schema/table
statement ok
DROP TABLE test.test
statement ok
DROP SCHEMA test
# now create then again
statement ok
CREATE SCHEMA test;
statement ok
CREATE TABLE test.test (a INTEGER, b INTEGER);
statement ok
INSERT INTO test.test VALUES (11, 22), (13, 22);
# restart the database
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
# after reload the table and schema are there: we can drop them again
statement ok
DROP TABLE test.test
statement ok
DROP SCHEMA test
restart
# after another reload they are still gone: create them again
statement ok
CREATE SCHEMA test;
statement ok
CREATE TABLE test.test (a INTEGER, b INTEGER);

View File

@@ -0,0 +1,31 @@
# name: test/sql/storage/wal/wal_empty_table.test
# description: Test empty table with WAL
# group: [wal]
# load the DB from disk
load __TEST_DIR__/test_empty_table.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement ok
CREATE TABLE test (a INTEGER, b VARCHAR)
query I
SELECT COUNT(*) FROM test
----
0
# verify that the table is still there after restart
restart
query I
SELECT COUNT(*) FROM test
----
0

View File

@@ -0,0 +1,46 @@
# name: test/sql/storage/wal/wal_hugeint_storage.test
# description: Test HUGEINT with persistent storage with WAL
# group: [wal]
# load the DB from disk
load __TEST_DIR__/hugeint_storage_test.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# create a table with hugeints
statement ok
CREATE TABLE hugeints (h HUGEINT);
statement ok
INSERT INTO hugeints VALUES (1043178439874412422424), (42), (NULL), (47289478944894789472897441242);
# reload the database from disk a few times, and check that the data is still there
loop i 0 2
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
query I
SELECT * FROM hugeints
----
1043178439874412422424
42
NULL
47289478944894789472897441242
query I
SELECT * FROM hugeints WHERE h = 42
----
42
query I
SELECT h FROM hugeints WHERE h < 10 ORDER BY 1;
----
endloop

View File

@@ -0,0 +1,51 @@
# name: test/sql/storage/wal/wal_interval_storage.test
# description: Test INTERVAL with persistent storage with WAL
# group: [wal]
# load the DB from disk
load __TEST_DIR__/interval_storage_test.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# create a table with hugeints
statement ok
CREATE TABLE interval (t INTERVAL);
statement ok
INSERT INTO interval VALUES (INTERVAL '1' DAY), (NULL), (INTERVAL '3 months 2 days 5 seconds')
# reload the database from disk a few times, and check that the data is still there
loop i 0 2
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
query I
SELECT * FROM interval
----
1 day
NULL
3 months 2 days 00:00:05
query I
SELECT t FROM interval WHERE t = INTERVAL '1' DAY;
----
1 day
query I
SELECT t FROM interval WHERE t >= INTERVAL '1' DAY ORDER BY 1;
----
1 day
3 months 2 days 00:00:05
query I
SELECT t FROM interval WHERE t > INTERVAL '10' YEAR ORDER BY 1;
----
endloop

View File

@@ -0,0 +1,36 @@
# name: test/sql/storage/wal/wal_lazy_creation.test
# description: Verify the WAL is lazily created when attaching.
# group: [wal]
# If we enable alternative verification, then we disable checkpointing on shutdown.
# Thus, we'll keep the WAL alive when detaching the database.
require no_alternative_verify
require skip_reload
statement ok
ATTACH '__TEST_DIR__/attach_no_wal.db';
statement ok
CREATE TABLE attach_no_wal.integers(i INTEGER);
statement ok
INSERT INTO attach_no_wal.integers FROM range(10000);
statement ok
DETACH attach_no_wal;
statement ok
ATTACH '__TEST_DIR__/attach_no_wal.db';
# Verify that we don't have a WAL after attaching.
query I
SELECT COUNT(*) FROM glob('__TEST_DIR__/attach_no_wal.db.wal');
----
0
# Verify that we checkpointed the WAL.
query I
SELECT COUNT(*) FROM attach_no_wal.integers;
----
10000

View File

@@ -0,0 +1,124 @@
# name: test/sql/storage/wal/wal_list_storage.test
# description: Test lists with persistent storage
# group: [wal]
load __TEST_DIR__/list_storage_test.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement ok
CREATE TABLE a(b INTEGER[]);
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
query I
SELECT * FROM a
----
statement ok
INSERT INTO a VALUES ([1, 2]), (NULL), ([3, 4, 5, 6]), ([NULL, 7]);
query I
SELECT * FROM a
----
[1, 2]
NULL
[3, 4, 5, 6]
[NULL, 7]
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
query I
SELECT * FROM a
----
[1, 2]
NULL
[3, 4, 5, 6]
[NULL, 7]
# nested lists
statement ok
CREATE TABLE b(b INTEGER[][]);
statement ok
INSERT INTO b VALUES ([[1, 2], [3, 4]]), (NULL), ([NULL, [7, 8, NULL], [2, 3]]), ([[NULL, 6], NULL, [1, 2, NULL]]);
query I
SELECT * FROM b
----
[[1, 2], [3, 4]]
NULL
[NULL, [7, 8, NULL], [2, 3]]
[[NULL, 6], NULL, [1, 2, NULL]]
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
query I
SELECT * FROM b
----
[[1, 2], [3, 4]]
NULL
[NULL, [7, 8, NULL], [2, 3]]
[[NULL, 6], NULL, [1, 2, NULL]]
statement ok
CREATE TABLE c(b VARCHAR[]);
statement ok
INSERT INTO c VALUES (['hello', 'world']), (NULL), (['fejwfoaejwfoijwafew', 'b', 'c']), ([NULL, 'XXXXXXXXXXXXXXXXXXXXXXXX']);
query I
SELECT * FROM c
----
[hello, world]
NULL
[fejwfoaejwfoijwafew, b, c]
[NULL, XXXXXXXXXXXXXXXXXXXXXXXX]
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
query I
SELECT * FROM c
----
[hello, world]
NULL
[fejwfoaejwfoijwafew, b, c]
[NULL, XXXXXXXXXXXXXXXXXXXXXXXX]
restart
query I
SELECT * FROM c
----
[hello, world]
NULL
[fejwfoaejwfoijwafew, b, c]
[NULL, XXXXXXXXXXXXXXXXXXXXXXXX]

View File

@@ -0,0 +1,54 @@
# name: test/sql/storage/wal/wal_map_storage.test
# description: Test maps with persistent storage and WAL
# group: [wal]
# load the DB from disk
load __TEST_DIR__/map_storage_test.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement ok
CREATE TABLE a(b MAP(INTEGER,INTEGER));
statement ok
INSERT INTO a VALUES (MAP([1], [2])), (MAP([1, 2, 3], [4, 5, 6]));
query I
SELECT * FROM a;
----
{1=2}
{1=4, 2=5, 3=6}
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
query I
SELECT * FROM a;
----
{1=2}
{1=4, 2=5, 3=6}
restart
query I
SELECT * FROM a;
----
{1=2}
{1=4, 2=5, 3=6}
restart
query I
SELECT * FROM a;
----
{1=2}
{1=4, 2=5, 3=6}

View File

@@ -0,0 +1,112 @@
# name: test/sql/storage/wal/wal_prepared_storage.test
# description: PREPARE and WAL
# group: [wal]
require skip_reload
# load the DB from disk
load __TEST_DIR__/prepared_storage.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# insert values in a database using prepared statements
statement ok
CREATE TABLE t (a INTEGER)
statement ok
PREPARE p1 AS INSERT INTO t VALUES ($1)
statement ok
EXECUTE p1(42)
statement ok
EXECUTE p1(43)
statement ok
DEALLOCATE p1
query I
SELECT a FROM t
----
42
43
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
# now restart and verify that the data is still there
query I
SELECT a FROM t
----
42
43
# unhelpfully use the same statement name again, it should be available, but do nothing with it
statement ok
PREPARE p1 AS DELETE FROM t WHERE a=$1
restart
# do the same with delete
statement ok
PREPARE p1 AS DELETE FROM t WHERE a=$1
statement ok
EXECUTE p1(43)
query I
SELECT a FROM t
----
42
# restart again
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
# data is still gone
query I
SELECT a FROM t
----
42
# now with update
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
query I
SELECT a FROM t
----
42
statement ok
PREPARE p1 AS UPDATE t SET a = $1
statement ok
EXECUTE p1(43)
query I
SELECT a FROM t
----
43
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
query I
SELECT a FROM t
----
43

View File

@@ -0,0 +1,36 @@
# name: test/sql/storage/wal/wal_promote_version.test
# description: WAL promote version
# group: [wal]
statement ok
PRAGMA disable_checkpoint_on_shutdown;
statement ok
SET checkpoint_threshold='1TB'
statement ok
ATTACH '__TEST_DIR__/wal_promote.db';
statement ok
CREATE TABLE wal_promote.T AS (FROM range(10));
statement ok
DETACH wal_promote;
statement ok
ATTACH '__TEST_DIR__/wal_promote.db' (STORAGE_VERSION 'latest');
statement ok
INSERT INTO wal_promote.T VALUES (42);
statement ok
DETACH wal_promote;
statement ok
ATTACH '__TEST_DIR__/wal_promote.db' (STORAGE_VERSION 'latest');
statement ok
INSERT INTO wal_promote.T VALUES (42);
statement ok
DETACH wal_promote;

View File

@@ -0,0 +1,39 @@
# name: test/sql/storage/wal/wal_sequence_uncommitted_transaction.test
# description: Use sequences with uncommited transaction
# group: [wal]
load __TEST_DIR__/store_sequences.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement ok
CREATE SEQUENCE seq
# start a transaction in con2
statement ok con2
BEGIN transaction
# select the nextval
query I con2
SELECT nextval('seq')
----
1
# query the sequence in con as well
query I
SELECT nextval('seq')
----
2
# restart the database
restart
# the sequence is now at position 3
query I
SELECT nextval('seq')
----
3

View File

@@ -0,0 +1,152 @@
# name: test/sql/storage/wal/wal_storage_types.test
# description: Test storage of columns with various types
# group: [wal]
require skip_reload
# load the DB from disk
load __TEST_DIR__/storage_types.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
foreach type <integral>
statement ok
CREATE TABLE a_${type} AS SELECT range::${type} i FROM range(100)
query IIII
SELECT MIN(i), MAX(i), COUNT(*), COUNT(i) FROM a_${type}
----
0 99 100 100
query IIII
SELECT MIN(i), MAX(i), COUNT(*), COUNT(i) FROM a_${type} WHERE i=1
----
1 1 1 1
endloop
# interval
statement ok
CREATE TABLE a_interval AS SELECT interval (range) year i FROM range(1,1001)
query IIII
SELECT MIN(i), MAX(i), COUNT(*), COUNT(i) FROM a_interval
----
1 year 1000 years 1000 1000
query IIII
SELECT MIN(i), MAX(i), COUNT(*), COUNT(i) FROM a_interval WHERE i=interval 1 year
----
1 year 1 year 1 1
# bool
statement ok
CREATE TABLE a_bool AS SELECT range%2=0 i FROM range(1000)
query IIII
SELECT MIN(i), MAX(i), COUNT(*), COUNT(i) FROM a_bool
----
false true 1000 1000
query IIII
SELECT MIN(i), MAX(i), COUNT(*), COUNT(i) FROM a_bool WHERE not i
----
false false 500 500
# enum
statement ok
CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
statement ok
CREATE TABLE person (
name text,
current_mood mood
);
statement ok
INSERT INTO person VALUES ('Moe', 'happy');
query TT
select * from person
----
Moe happy
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# restart and check all types again
foreach type <integral>
query IIII
SELECT MIN(i), MAX(i), COUNT(*), COUNT(i) FROM a_${type}
----
0 99 100 100
query IIII
SELECT MIN(i), MAX(i), COUNT(*), COUNT(i) FROM a_${type} WHERE i=1
----
1 1 1 1
endloop
query IIII
SELECT MIN(i), MAX(i), COUNT(*), COUNT(i) FROM a_interval
----
1 year 1000 years 1000 1000
query IIII
SELECT MIN(i), MAX(i), COUNT(*), COUNT(i) FROM a_interval WHERE i=interval 1 year
----
1 year 1 year 1 1
query IIII
SELECT MIN(i), MAX(i), COUNT(*), COUNT(i) FROM a_bool
----
false true 1000 1000
query IIII
SELECT MIN(i), MAX(i), COUNT(*), COUNT(i) FROM a_bool WHERE not i
----
false false 500 500
query TT
select * from person
----
Moe happy
statement ok
begin transaction
statement ok
drop table person;
statement ok
drop TYPE mood;
statement ok
commit
restart
statement error
CREATE TABLE aliens (
name text,
current_mood mood
);
----
<REGEX>:.*Catalog Error.*does not exist.*

View File

@@ -0,0 +1,54 @@
# name: test/sql/storage/wal/wal_store_add_column.test
# description: Test storage of alter table add column
# group: [wal]
require skip_reload
load __TEST_DIR__/test_store_add_column.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# create a table and add a column to it
statement ok
CREATE TABLE test (a INTEGER, b INTEGER);
statement ok
INSERT INTO test VALUES (11, 22), (13, 22), (12, 21)
statement ok
ALTER TABLE test ADD COLUMN k INTEGER DEFAULT 2
query I
SELECT k FROM test ORDER BY k
----
2
2
2
restart
# reload and verify the column is still there
query I
SELECT k FROM test ORDER BY k
----
2
2
2
# verify the default is still correct
statement ok
INSERT INTO test(a, b) VALUES (1, 1)
query I
SELECT k FROM test ORDER BY k
----
2
2
2
2

View File

@@ -0,0 +1,46 @@
# name: test/sql/storage/wal/wal_store_add_column_persistent.test
# description: Add column to persistent table
# group: [wal]
load __TEST_DIR__/test_store_add_column_persistent.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# first create a persistent table and insert data
statement ok
CREATE TABLE test (a INTEGER, b INTEGER);
statement ok
INSERT INTO test VALUES (11, 22), (13, 22), (12, 21)
# now reload
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
# add the column
statement ok
ALTER TABLE test ADD COLUMN k INTEGER DEFAULT 2
query I
SELECT k FROM test ORDER BY k
----
2
2
2
# reload again
restart
# the column is still there
query I
SELECT k FROM test ORDER BY k
----
2
2
2

View File

@@ -0,0 +1,113 @@
# name: test/sql/storage/wal/wal_store_alter_type.test
# description: Remove column from persistent table
# group: [wal]
require skip_reload
load __TEST_DIR__/test_store_alter_type.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# create a table and add a column to it
statement ok
CREATE TABLE test (a INTEGER, b INTEGER);
statement ok
INSERT INTO test VALUES (11, 22), (13, 22), (12, 21)
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement ok
ALTER TABLE test ALTER b TYPE VARCHAR
query IT
SELECT * FROM test ORDER BY 1
----
11 22
12 21
13 22
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
query IT
SELECT * FROM test ORDER BY 1
----
11 22
12 21
13 22
statement ok
INSERT INTO test VALUES (10, 'hello')
query IT
SELECT * FROM test ORDER BY 1
----
10 hello
11 22
12 21
13 22
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
query IT
SELECT * FROM test ORDER BY 1
----
10 hello
11 22
12 21
13 22
statement ok
DELETE FROM test WHERE b='hello'
restart
query IT
SELECT * FROM test ORDER BY 1
----
11 22
12 21
13 22
statement ok
INSERT INTO test VALUES (10, 'hello')
query IT
SELECT * FROM test ORDER BY 1
----
10 hello
11 22
12 21
13 22
restart
query IT
SELECT * FROM test ORDER BY 1
----
10 hello
11 22
12 21
13 22

View File

@@ -0,0 +1,54 @@
# name: test/sql/storage/wal/wal_store_alter_type_crash.test
# description: Remove column from persistent table
# group: [wal]
load __TEST_DIR__/test_store_alter_type.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# create a table and add a column to it
statement ok
CREATE TABLE test (a INTEGER, b INTEGER);
statement ok
INSERT INTO test VALUES (11, 22), (13, 22), (12, 21)
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
ALTER TABLE test ALTER b TYPE VARCHAR
query IT
SELECT * FROM test ORDER BY 1
----
11 22
12 21
13 22
statement ok
INSERT INTO test VALUES (10, 'hello')
query IT
SELECT * FROM test ORDER BY 1
----
10 hello
11 22
12 21
13 22
restart
query IT
SELECT * FROM test ORDER BY 1
----
10 hello
11 22
12 21
13 22

View File

@@ -0,0 +1,76 @@
# name: test/sql/storage/wal/wal_store_default_sequence.test
# description: Test storage of default values with sequences
# group: [wal]
require skip_reload
load __TEST_DIR__/test_store_defaults.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# create a table with a reference to a sequence as default value
statement ok
CREATE SEQUENCE seq;
# use the sequence so that currval can return a value
query I
SELECT nextval('seq')
----
1
statement ok
CREATE TABLE test (a INTEGER DEFAULT nextval('seq'), b INTEGER, c INTEGER DEFAULT currval('seq'));
statement ok
INSERT INTO test (b) VALUES (11)
# restart the database
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
query III
SELECT * FROM test ORDER BY b
----
2 11 2
# verify that the sequence was used during the append
statement ok
INSERT INTO test (b) VALUES (12);
statement ok
INSERT INTO test (b) VALUES (13);
query III
SELECT * FROM test ORDER BY b
----
2 11 2
3 12 3
4 13 4
# restart and insert one more time
restart
statement ok
INSERT INTO test (b) VALUES (14)
statement ok
INSERT INTO test (b) VALUES (15)
query III
SELECT * FROM test ORDER BY b
----
2 11 2
3 12 3
4 13 4
5 14 5
6 15 6

View File

@@ -0,0 +1,71 @@
# name: test/sql/storage/wal/wal_store_defaults.test
# description: Test storage of default values
# group: [wal]
require skip_reload
# load the DB from disk
load __TEST_DIR__/test_store_defaults.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# create a table with a default value
statement ok
CREATE TABLE test (a INTEGER DEFAULT 1, b INTEGER);
statement ok
INSERT INTO test (b) VALUES (11)
query II
SELECT * FROM test ORDER BY b
----
1 11
# reload the database
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# verify that the table contains the correct contents
query II
SELECT * FROM test ORDER BY b
----
1 11
# append more entries
statement ok
INSERT INTO test (b) VALUES (12), (13)
# check that the default value was used in the INSERT
query II
SELECT * FROM test ORDER BY b
----
1 11
1 12
1 13
# reload and append one more time
restart
# append more entries
statement ok
INSERT INTO test (b) VALUES (14), (15)
# check that the default value was used in the INSERT
query II
SELECT * FROM test ORDER BY b
----
1 11
1 12
1 13
1 14
1 15

View File

@@ -0,0 +1,88 @@
# name: test/sql/storage/wal/wal_store_deletes.test
# description: Test deletes with storage with WAL
# group: [wal]
require skip_reload
# load the DB from disk
load __TEST_DIR__/test_store_deletes.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement ok
BEGIN TRANSACTION;
statement ok
CREATE TABLE test (a INTEGER, b INTEGER);
statement ok
INSERT INTO test VALUES (11, 22), (12, 21), (13, 22), (12, 21)
statement ok
DELETE FROM test WHERE a=12
query II
SELECT a, b FROM test ORDER BY a
----
11 22
13 22
statement ok
COMMIT
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
query II
SELECT a, b FROM test ORDER BY a
----
11 22
13 22
statement ok
DELETE FROM test WHERE a=11
query II
SELECT a, b FROM test ORDER BY a
----
13 22
statement ok
INSERT INTO test VALUES (11, 24), (12, 25)
query II
SELECT a, b FROM test ORDER BY a
----
11 24
12 25
13 22
statement ok
DELETE FROM test WHERE a=12
query II
SELECT a, b FROM test ORDER BY a
----
11 24
13 22
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
query II
SELECT a, b FROM test ORDER BY a
----
11 24
13 22

View File

@@ -0,0 +1,43 @@
# name: test/sql/storage/wal/wal_store_integers.test
# description: Test simple storage with WAL
# group: [wal]
# load the DB from disk
load __TEST_DIR__/test_store_integers.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# create a database and insert values
statement ok
CREATE TABLE test (a INTEGER, b INTEGER);
statement ok
INSERT INTO test VALUES (11, 22), (13, 22), (12, 21), (NULL, NULL)
statement ok
CREATE TABLE test2 (a INTEGER);
statement ok
INSERT INTO test2 VALUES (13), (12), (11)
# verify that the tables are still there after a restart
restart
query II
SELECT * FROM test ORDER BY a
----
11 22
12 21
13 22
NULL NULL
query I
SELECT * FROM test2 ORDER BY a
----
11
12
13

View File

@@ -0,0 +1,119 @@
# name: test/sql/storage/wal/wal_store_mixed_updates_big.test
# description: Test updates mix with a big table
# group: [wal]
require skip_reload
# load the DB from disk
load __TEST_DIR__/test_store_updates.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement ok
CREATE TABLE test AS SELECT -i a, -i b FROM range(100000) tbl(i)
statement ok
INSERT INTO test SELECT i+1 a, i+1 b FROM range(1000) tbl(i)
query IIIIIII
SELECT COUNT(*), SUM(a), SUM(b), MIN(a), MAX(a), MIN(b), MAX(b) FROM test WHERE a>0
----
1000 500500 500500 1 1000 1 1000
query I
SELECT COUNT(*) FROM test WHERE a>0
----
1000
query I
SELECT COUNT(*) FROM test WHERE a>0 AND a<>b
----
0
query I
SELECT SUM(CASE WHEN b IS NULL THEN 1 ELSE 0 END) FROM test WHERE a>0 AND a%2=0
----
0
query I
UPDATE test SET b=b+1 WHERE a>0 AND a%2=0
----
500
query II nosort select_after_update
SELECT * FROM test WHERE a>0 ORDER BY 1,2
----
query I
SELECT COUNT(*) FROM test WHERE a>0
----
1000
query I
SELECT COUNT(*) FROM test WHERE a>0 AND a<>b
----
500
query II nosort select_after_update
SELECT * FROM test WHERE a>0 ORDER BY 1,2
----
query IIIIIII
SELECT COUNT(*), SUM(a), SUM(b), MIN(a), MAX(a), MIN(b), MAX(b) FROM test WHERE a>0
----
1000 500500 501000 1 1000 1 1001
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
query I
SELECT COUNT(*) FROM test WHERE a>0 AND a%2=0
----
500
query I
SELECT COUNT(*) FROM test WHERE a IS NULL OR b IS NULL
----
0
query I
SELECT COUNT(*) FROM test WHERE a>0 AND a<>b
----
500
query II nosort select_after_update
SELECT * FROM test WHERE a>0 ORDER BY 1,2
----
query IIIIIII
SELECT COUNT(*), SUM(a), SUM(b), MIN(a), MAX(a), MIN(b), MAX(b) FROM test WHERE a>0
----
1000 500500 501000 1 1000 1 1001
query I
UPDATE test SET b=NULL WHERE a>0 AND a%2=1
----
500
query IIIIIII
SELECT COUNT(*), SUM(a), SUM(b), MIN(a), MAX(a), MIN(b), MAX(b) FROM test WHERE a>0
----
1000 500500 251000 1 1000 3 1001
restart
query IIIIIII
SELECT COUNT(*), SUM(a), SUM(b), MIN(a), MAX(a), MIN(b), MAX(b) FROM test WHERE a>0
----
1000 500500 251000 1 1000 3 1001

View File

@@ -0,0 +1,98 @@
# name: test/sql/storage/wal/wal_store_mixed_updates_big_null.test
# description: Test updates mix with a big table and NULL values
# group: [wal]
require skip_reload
# load the DB from disk
load __TEST_DIR__/test_store_updates.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement ok
CREATE TABLE test AS SELECT -i a, -i b FROM range(100000) tbl(i)
statement ok
INSERT INTO test SELECT i+1 a, i+1 b FROM range(1000) tbl(i)
query IIIIIII
SELECT COUNT(*), SUM(a), SUM(b), MIN(a), MAX(a), MIN(b), MAX(b) FROM test WHERE a>0
----
1000 500500 500500 1 1000 1 1000
query I
SELECT COUNT(*) FROM test WHERE a>0
----
1000
query I
SELECT COUNT(*) FROM test WHERE a>0 AND a<>b
----
0
query I
UPDATE test SET b=NULL WHERE a>0 AND a%2=0
----
500
query II nosort select_after_update
SELECT * FROM test WHERE a>0 ORDER BY 1,2
----
query I
SELECT COUNT(*) FROM test WHERE a>0
----
1000
query I
SELECT COUNT(*) FROM test WHERE a>0 AND b IS NULL
----
500
query II nosort select_after_update
SELECT * FROM test WHERE a>0 ORDER BY 1,2
----
query IIIIIIII
SELECT COUNT(*), SUM(a), SUM(b), MIN(a), MAX(a), MIN(b), MAX(b), COUNT(b) FROM test WHERE a>0
----
1000 500500 250000 1 1000 1 999 500
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
query I
SELECT COUNT(*) FROM test WHERE a>0 AND a%2=0
----
500
query I
SELECT COUNT(*) FROM test WHERE a IS NULL OR b IS NULL
----
500
query II nosort select_after_update
SELECT * FROM test WHERE a>0 ORDER BY 1,2
----
query IIIIIIII
SELECT COUNT(*), SUM(a), SUM(b), MIN(a), MAX(a), MIN(b), MAX(b), COUNT(b) FROM test WHERE a>0
----
1000 500500 250000 1 1000 1 999 500
restart
query IIIIIIII
SELECT COUNT(*), SUM(a), SUM(b), MIN(a), MAX(a), MIN(b), MAX(b), COUNT(b) FROM test WHERE a>0
----
1000 500500 250000 1 1000 1 999 500

View File

@@ -0,0 +1,41 @@
# name: test/sql/storage/wal/wal_store_nulls_strings.test
# description: Test storing NULLs and strings with WAL
# group: [wal]
# load the DB from disk
load __TEST_DIR__/test_store_null_string.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# create a database and insert values
statement ok
CREATE TABLE test (a INTEGER, b STRING);
statement ok
INSERT INTO test VALUES (NULL, 'hello'), (13, 'abcdefgh'), (12, NULL)
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
query II
SELECT a, b FROM test ORDER BY a
----
12 NULL
13 abcdefgh
NULL hello
statement error
CREATE TABLE test (a INTEGER, b STRING);
----
statement ok
CREATE TABLE IF NOT EXISTS test (a INTEGER, b STRING);

View File

@@ -0,0 +1,45 @@
# name: test/sql/storage/wal/wal_store_remove_column.test
# description: Remove column from persistent table
# group: [wal]
load __TEST_DIR__/test_store_add_column.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# create a table and add a column to it
statement ok
CREATE TABLE test (a INTEGER, b INTEGER);
statement ok
INSERT INTO test VALUES (11, 22), (13, 22), (12, 21)
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement ok
ALTER TABLE test DROP COLUMN b
query I
SELECT * FROM test ORDER BY 1
----
11
12
13
restart
query I
SELECT * FROM test ORDER BY 1
----
11
12
13

View File

@@ -0,0 +1,92 @@
# name: test/sql/storage/wal/wal_store_rename_column.test
# description: Test storage of alter table rename column
# group: [wal]
# load the DB from disk
load __TEST_DIR__/test_rename_column.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement ok
CREATE TABLE test (a INTEGER, b INTEGER);
statement ok
INSERT INTO test VALUES (11, 22), (13, 22), (12, 21)
# rename the column and rollback the transaction
statement ok
BEGIN TRANSACTION
query I
SELECT a FROM test ORDER BY a
----
11
12
13
statement ok
ALTER TABLE test RENAME COLUMN a TO k
query I
SELECT k FROM test ORDER BY k
----
11
12
13
statement ok
ROLLBACK
# reload
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement ok
BEGIN TRANSACTION
# verify that the column is not renamed
query I
SELECT a FROM test ORDER BY a
----
11
12
13
# now repeat the process but this time commit
statement ok
ALTER TABLE test RENAME COLUMN a TO k
query I
SELECT k FROM test ORDER BY k
----
11
12
13
statement ok
COMMIT
# reload the database
restart
# verify that the column is still renamed
query I
SELECT k FROM test ORDER BY k
----
11
12
13
statement error
SELECT a FROM test
----
<REGEX>:.*Binder Error.*not found in FROM clause.*

View File

@@ -0,0 +1,80 @@
# name: test/sql/storage/wal/wal_store_rename_table.test
# description: Test storage of alter table rename table
# group: [wal]
# load the DB from disk
load __TEST_DIR__/test_rename_table.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement ok
CREATE TABLE test (a INTEGER, b INTEGER);
statement ok
INSERT INTO test VALUES (11, 22), (13, 22), (12, 21)
statement ok
BEGIN TRANSACTION
query I
SELECT a FROM test ORDER BY a
----
11
12
13
statement ok
ALTER TABLE test RENAME TO new_name
query I
SELECT a FROM new_name ORDER BY 1
----
11
12
13
statement ok
ROLLBACK
# restart the database
restart
statement ok
BEGIN TRANSACTION
# verify that the table is still there in the original form
query I
SELECT a FROM test ORDER BY a
----
11
12
13
# now repeat the process, but this time commit
statement ok
ALTER TABLE test RENAME TO new_name
query I
SELECT a FROM new_name ORDER BY 1
----
11
12
13
statement ok
COMMIT
restart
# after a restart, the renamed table is still here
query I
SELECT a FROM new_name ORDER BY 1
----
11
12
13

View File

@@ -0,0 +1,88 @@
# name: test/sql/storage/wal/wal_store_rename_view.test
# description: Test storage of alter view
# group: [wal]
# load the DB from disk
load __TEST_DIR__/test_rename_view.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement ok
CREATE TABLE test (a INTEGER, b INTEGER);
statement ok
INSERT INTO test VALUES (11, 22), (13, 22), (12, 21)
statement ok
CREATE VIEW vtest AS SELECT * FROM test
statement ok
BEGIN TRANSACTION
query I
SELECT a FROM vtest ORDER BY a
----
11
12
13
statement ok
ALTER VIEW vtest RENAME TO new_name
query I
SELECT a FROM new_name ORDER BY 1
----
11
12
13
statement ok
ROLLBACK
# restart the database
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement ok
BEGIN TRANSACTION
# verify that the table is still there in the original form
query I
SELECT a FROM vtest ORDER BY a
----
11
12
13
# now repeat the process, but this time commit
statement ok
ALTER VIEW vtest RENAME TO new_name
query I
SELECT a FROM new_name ORDER BY 1
----
11
12
13
statement ok
COMMIT
restart
# after a restart, the renamed table is still here
query I
SELECT a FROM new_name ORDER BY 1
----
11
12
13

View File

@@ -0,0 +1,86 @@
# name: test/sql/storage/wal/wal_store_sequences.test
# description: Use sequences over different runs
# group: [wal]
load __TEST_DIR__/store_sequences.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# standard sequence
statement ok
CREATE SEQUENCE seq
# more complex sequence
statement ok
CREATE SEQUENCE seq_cycle INCREMENT 1 MAXVALUE 3 START 2 CYCLE;
query I
SELECT nextval('seq')
----
1
query I
SELECT nextval('seq_cycle')
----
2
statement ok
CREATE SEQUENCE seq2
statement ok
DROP SEQUENCE seq2
# restart and check that sequence still works
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
query I
SELECT nextval('seq')
----
2
query I
SELECT nextval('seq_cycle')
----
3
statement error
SELECT nextval('seq2')
----
# again
restart
query II
SELECT nextval('seq'), nextval('seq')
----
3 4
query I
SELECT nextval('seq_cycle')
----
1
# drop sequence
statement ok
DROP SEQUENCE seq;
restart
# verify that sequence is gone
statement error
SELECT nextval('seq')
----
# other sequence is still there
statement ok
SELECT nextval('seq_cycle')

View File

@@ -0,0 +1,96 @@
# name: test/sql/storage/wal/wal_store_temporary.test
# description: Temporary tables are not written to disk
# group: [wal]
require skip_reload
# load the DB from disk
load __TEST_DIR__/test_store_temporary.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# create a temporary table and do some ops on there
statement ok
CREATE TABLE persistent (i INTEGER)
statement ok
CREATE TEMPORARY TABLE temp.a (i INTEGER)
# insert values, delete them, etc
statement ok
INSERT INTO a VALUES (42)
statement ok
DELETE FROM a
statement ok
DELETE FROM temp.a
# check schema
statement error
DELETE FROM asdf.a
----
# temporary sequences
statement ok
CREATE TEMPORARY SEQUENCE seq
statement ok
CREATE TEMPORARY SEQUENCE seq2
statement ok
DROP SEQUENCE seq2
# temporary views
statement ok
CREATE TEMPORARY VIEW v1 AS SELECT 42
statement ok
CREATE TEMPORARY VIEW v2 AS SELECT 42
statement ok
DROP VIEW v2
statement ok
INSERT INTO temp.a VALUES (43)
statement ok
UPDATE temp.a SET i = 44
statement ok
UPDATE a SET i = 45
# alter table on a temporary structure
statement ok
ALTER TABLE a RENAME COLUMN i TO k
statement ok
SELECT * FROM persistent
statement ok
SELECT * FROM a
# now restart
restart
# persistent table is still there
statement ok
SELECT * FROM persistent
# temporary table is gone
statement error
SELECT * FROM a
----
statement ok
CREATE TEMPORARY TABLE a (i INTEGER)
statement ok
CREATE TEMPORARY SEQUENCE seq
statement ok
CREATE TEMPORARY VIEW v1 AS SELECT 42

View File

@@ -0,0 +1,73 @@
# name: test/sql/storage/wal/wal_store_updates_big.test
# description: Test updates with storage and null values on a big table
# group: [wal]
require skip_reload
# load the DB from disk
load __TEST_DIR__/test_store_updates.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement ok
CREATE TABLE test AS SELECT -i a, -i b FROM range(100000) tbl(i)
statement ok
INSERT INTO test VALUES (11, 22), (NULL, 22), (12, 21)
query I
UPDATE test SET b=b+1 WHERE a=11
----
1
query II
SELECT a, b FROM test WHERE a>0 OR a IS NULL ORDER BY a
----
11 23
12 21
NULL 22
query I
UPDATE test SET b=b+1 WHERE a=11
----
1
query II
SELECT a, b FROM test WHERE a>0 OR a IS NULL ORDER BY a
----
11 24
12 21
NULL 22
statement ok
UPDATE test SET b=NULL WHERE a=11
query II
SELECT a, b FROM test WHERE a>0 OR a IS NULL ORDER BY a
----
11 NULL
12 21
NULL 22
restart
query II
SELECT a, b FROM test WHERE a>0 OR a IS NULL ORDER BY a
----
11 NULL
12 21
NULL 22
restart
query II
SELECT a, b FROM test WHERE a>0 OR a IS NULL ORDER BY a
----
11 NULL
12 21
NULL 22

View File

@@ -0,0 +1,72 @@
# name: test/sql/storage/wal/wal_store_updates_big_varchar.test
# description: Test updates with storage and null values
# group: [wal]
require skip_reload
# load the DB from disk
load __TEST_DIR__/test_store_updates.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement ok
CREATE TABLE test AS SELECT (-i)::VARCHAR a, (-i)::VARCHAR b FROM range(100000) tbl(i)
statement ok
INSERT INTO test VALUES ('11', '22'), (NULL, '22'), ('12', '21')
query I
UPDATE test SET b=(b::INT+1)::VARCHAR WHERE a='11'
----
1
query II
SELECT a, b FROM test WHERE a::INTEGER>0 OR a IS NULL ORDER BY a
----
11 23
12 21
NULL 22
query I
UPDATE test SET b=(b::INT+1)::VARCHAR WHERE a='11'
----
1
query II
SELECT a, b FROM test WHERE a::INTEGER>0 OR a IS NULL ORDER BY a
----
11 24
12 21
NULL 22
statement ok
UPDATE test SET b=NULL WHERE a='11'
query II
SELECT a, b FROM test WHERE a::INTEGER>0 OR a IS NULL ORDER BY a
----
11 NULL
12 21
NULL 22
restart
query II
SELECT a, b FROM test WHERE a::INTEGER>0 OR a IS NULL ORDER BY a
----
11 NULL
12 21
NULL 22
restart
query II
SELECT a, b FROM test WHERE a::INTEGER>0 OR a IS NULL ORDER BY a
----
11 NULL
12 21
NULL 22

View File

@@ -0,0 +1,67 @@
# name: test/sql/storage/wal/wal_test_null_updates.test
# description: Test updates with storage and null values
# group: [wal]
statement ok
SET default_null_order='nulls_first';
require skip_reload
# load the DB from disk
load __TEST_DIR__/test_store_updates.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement ok
CREATE TABLE test (a INTEGER, b INTEGER);
statement ok
INSERT INTO test VALUES (11, 22), (NULL, 22), (12, 21)
query I
UPDATE test SET b=b+1 WHERE a=11
----
1
query II
SELECT a, b FROM test ORDER BY a
----
11 23
12 21
NULL 22
query I
UPDATE test SET b=b+1 WHERE a=11
----
1
query II
SELECT a, b FROM test ORDER BY a
----
11 24
12 21
NULL 22
statement ok
UPDATE test SET b=NULL WHERE a=11
query II
SELECT a, b FROM test ORDER BY a
----
11 NULL
12 21
NULL 22
restart
query II
SELECT a, b FROM test ORDER BY a
----
11 NULL
12 21
NULL 22

View File

@@ -0,0 +1,72 @@
# name: test/sql/storage/wal/wal_test_string_null_updates.test
# description: Test updates with storage and null values
# group: [wal]
require skip_reload
# load the DB from disk
load __TEST_DIR__/test_store_updates.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement ok
CREATE TABLE test (a VARCHAR, b VARCHAR);
statement ok
INSERT INTO test VALUES ('11', '22'), (NULL, '22'), ('12', '21')
query I
UPDATE test SET b=(b::INT+1)::VARCHAR WHERE a='11'
----
1
query II
SELECT a, b FROM test ORDER BY a
----
11 23
12 21
NULL 22
query I
UPDATE test SET b=(b::INT+1)::VARCHAR WHERE a='11'
----
1
query II
SELECT a, b FROM test ORDER BY a
----
11 24
12 21
NULL 22
statement ok
UPDATE test SET b=NULL WHERE a='11'
query II
SELECT a, b FROM test ORDER BY a
----
11 NULL
12 21
NULL 22
restart
query II
SELECT a, b FROM test ORDER BY a
----
11 NULL
12 21
NULL 22
restart
query II
SELECT a, b FROM test ORDER BY a
----
11 NULL
12 21
NULL 22

View File

@@ -0,0 +1,53 @@
# name: test/sql/storage/wal/wal_test_updates.test
# description: Test updates with storage with WAL
# group: [wal]
# load the DB from disk
load __TEST_DIR__/test_store_updates.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
statement ok
CREATE TABLE test (a INTEGER, b INTEGER);
statement ok
INSERT INTO test VALUES (11, 22), (13, 22), (12, 21)
statement ok
UPDATE test SET b=b+1 WHERE a=11
query II
SELECT a, b FROM test ORDER BY a
----
11 23
12 21
13 22
statement ok
UPDATE test SET b=b+1 WHERE a=11
query II
SELECT a, b FROM test ORDER BY a
----
11 24
12 21
13 22
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
query II
SELECT a, b FROM test ORDER BY a
----
11 24
12 21
13 22

View File

@@ -0,0 +1,51 @@
# name: test/sql/storage/wal/wal_timestamp_storage.test
# description: Test storage for timestamp type with WAL
# group: [wal]
# load the DB from disk
load __TEST_DIR__/timestamp_storage_test.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# create a table with hugeints
statement ok
CREATE TABLE timestamp (t TIMESTAMP)
statement ok
INSERT INTO timestamp VALUES ('2008-01-01 00:00:01'), (NULL), ('2007-01-01 00:00:01'), ('2008-02-01 00:00:01'), ('2008-01-02 00:00:01'), ('2008-01-01 10:00:00'), ('2008-01-01 00:10:00'), ('2008-01-01 00:00:10')
# reload the database from disk a few times
loop i 0 2
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
query I
SELECT * FROM timestamp ORDER BY t
----
2007-01-01 00:00:01
2008-01-01 00:00:01
2008-01-01 00:00:10
2008-01-01 00:10:00
2008-01-01 10:00:00
2008-01-02 00:00:01
2008-02-01 00:00:01
NULL
query I
SELECT * FROM timestamp WHERE t=TIMESTAMP '2007-01-01 00:00:01' ORDER BY t
----
2007-01-01 00:00:01
query I
SELECT * FROM timestamp WHERE t=TIMESTAMP '2000-01-01 00:00:01' ORDER BY t
----
endloop

View File

@@ -0,0 +1,46 @@
# name: test/sql/storage/wal/wal_uhugeint_storage.test
# description: Test UHUGEINT with persistent storage with WAL
# group: [wal]
# load the DB from disk
load __TEST_DIR__/uhugeint_storage_test.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# create a table with uhugeints
statement ok
CREATE TABLE uhugeints (h UHUGEINT);
statement ok
INSERT INTO uhugeints VALUES (1043178439874412422424), (42), (NULL), (47289478944894789472897441242);
# reload the database from disk a few times, and check that the data is still there
loop i 0 2
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
query I
SELECT * FROM uhugeints
----
1043178439874412422424
42
NULL
47289478944894789472897441242
query I
SELECT * FROM uhugeints WHERE h = 42
----
42
query I
SELECT h FROM uhugeints WHERE h < 10 ORDER BY 1;
----
endloop

View File

@@ -0,0 +1,48 @@
# name: test/sql/storage/wal/wal_unaligned_row_groups.test_slow
# description: Test loading of unaligned row groups
# group: [wal]
# load the DB from disk
load __TEST_DIR__/unaligned_row_groups.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# create a table with a check constraint
statement ok
CREATE TABLE test(a VARCHAR);
loop i 0 2
statement ok
INSERT INTO test SELECT concat('helloworldxxx', i) from range(150000) tbl(i);
statement ok
INSERT INTO test SELECT concat('helloworldxxx', i) from range(16534) tbl(i);
statement ok
INSERT INTO test SELECT concat('helloworldxxx', i) from range(999) tbl(i);
statement ok
INSERT INTO test SELECT concat('helloworldxxx', i) from range(31) tbl(i);
statement ok
INSERT INTO test SELECT concat('helloworldxxx', i) from range(34569) tbl(i);
endloop
query IIII
SELECT MIN(a), MAX(a), COUNT(*), AVG(REPLACE(a, 'helloworldxxx', '')::INT) FROM test
----
helloworldxxx0 helloworldxxx99999 404266 59290.629798202174
# reload the database
restart
query IIII
SELECT MIN(a), MAX(a), COUNT(*), AVG(REPLACE(a, 'helloworldxxx', '')::INT) FROM test
----
helloworldxxx0 helloworldxxx99999 404266 59290.629798202174

View File

@@ -0,0 +1,52 @@
# name: test/sql/storage/wal/wal_uuid_storage.test
# description: Test UUID with persistent storage with WAL
# group: [wal]
# load the DB from disk
load __TEST_DIR__/uuid_storage_test.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# create a table with uuid
statement ok
CREATE TABLE uuids (u uuid);
statement ok
INSERT INTO uuids VALUES ('A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11'), (NULL), ('47183823-2574-4bfd-b411-99ed177d3e43'), ('{10203040506070800102030405060708}');
# reload the database from disk a few times, and check that the data is still there
loop i 0 2
restart
query I
SELECT * FROM uuids
----
a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11
NULL
47183823-2574-4bfd-b411-99ed177d3e43
10203040-5060-7080-0102-030405060708
# can query by the upper case
query I
SELECT * FROM uuids WHERE u = 'A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11'
----
a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11
# can also query by the standard format
query I
SELECT * FROM uuids WHERE u = 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'
----
a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11
query I
SELECT u FROM uuids WHERE u > '10203040-5060-7080-0102-030405060708' ORDER BY 1;
----
47183823-2574-4bfd-b411-99ed177d3e43
a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11
endloop

View File

@@ -0,0 +1,77 @@
# name: test/sql/storage/wal/wal_view_explicit_aliases.test
# description: Test views with explicit column aliases
# group: [wal]
require skip_reload
# load the DB from disk
load __TEST_DIR__/view_explicit_aliases_storage.db
statement ok
set enable_view_dependencies=true
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# create a database and insert the table/view
statement ok
CREATE SCHEMA test;
statement ok
CREATE TABLE test.t (a INTEGER, b INTEGER);
# the view has aliases (b, c)
statement ok
CREATE VIEW test.v (b,c) AS SELECT * FROM test.t;
# check the view info
query II nosort view_info
PRAGMA table_info('test.v')
----
statement ok
SELECT * FROM test.v
statement ok
DROP TABLE test.t CASCADE;
loop i 0 2
# now reload
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
# can check info, but not query the view
statement error
PRAGMA table_info('test.v')
----
Catalog Error: Table with name v does not exist!
statement error
SELECT * FROM test.v
----
statement ok
CREATE TABLE test.t (a INTEGER, b INTEGER);
statement ok
SELECT * FROM test.t
# we need to recreate the view to query 'v' after recreating the table
statement error
SELECT b,c FROM test.v
----
statement ok
CREATE VIEW test.v (b,c) AS SELECT * FROM test.t;
statement ok
DROP TABLE test.t CASCADE;
endloop

View File

@@ -0,0 +1,74 @@
# name: test/sql/storage/wal/wal_view_explicit_aliases_no_view_dependencies.test
# description: Test views with explicit column aliases
# group: [wal]
require skip_reload
# load the DB from disk
load __TEST_DIR__/view_explicit_aliases_storage.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# create a database and insert the table/view
statement ok
CREATE SCHEMA test;
statement ok
CREATE TABLE test.t (a INTEGER, b INTEGER);
# the view has aliases (b, c)
statement ok
CREATE VIEW test.v (b,c) AS SELECT * FROM test.t;
# check the view info
query II nosort view_info
PRAGMA table_info('test.v')
----
statement ok
SELECT * FROM test.v
statement ok
DROP TABLE test.t
# we can still query this after the table is gone
query II nosort view_info
PRAGMA table_info('test.v')
----
loop i 0 2
# now reload
restart
statement ok
PRAGMA disable_checkpoint_on_shutdown
# can check info, but not query the view
query II nosort view_info
PRAGMA table_info('test.v')
----
statement error
SELECT * FROM test.v
----
# we can query again after recreating the table
statement ok
CREATE TABLE test.t (a INTEGER, b INTEGER);
statement ok
SELECT * FROM test.t
statement ok
SELECT b,c FROM test.v
statement ok
DROP TABLE test.t
endloop

View File

@@ -0,0 +1,105 @@
# name: test/sql/storage/wal/wal_view_storage.test
# description: Create and drop a view over different runs
# group: [wal]
require skip_reload
# load the DB from disk
load __TEST_DIR__/view_storage.db
statement ok
set enable_view_dependencies=true
statement ok
PRAGMA disable_checkpoint_on_shutdown
# Make sure the WAL doesn't get flushed by a checkpoint
statement ok
PRAGMA wal_autocheckpoint='1TB';
# Create a schema containing a table and a view
statement ok
CREATE SCHEMA test;
CREATE TABLE test.t (a INTEGER, b INTEGER);
CREATE VIEW test.v AS SELECT * FROM test.t;
# read the info from the view
query IIIIII
PRAGMA table_info('test.v')
----
0 a INTEGER 0 NULL 0
1 b INTEGER 0 NULL 0
# Try to drop the table
statement error
drop table test.t;
----
view "v" depends on table "t".
# Now with CASCADE
statement ok
drop table test.t cascade;
statement error
PRAGMA table_info('test.v')
----
Catalog Error: Table with name v does not exist!
statement ok
CREATE VIEW test.v2 AS SELECT 42
statement ok
DROP VIEW test.v2
loop i 0 2
# restart the system, causing the database to restore from the WAL
restart
# the view no longer exists
statement error
PRAGMA table_info('test.v')
----
Catalog Error: Table with name v does not exist!
statement error
SELECT * FROM test.v
----
# after recreating the table, we can query the view again
statement ok
CREATE TABLE test.t (a INTEGER, b INTEGER);
statement ok
SELECT * FROM test.t
# We created the table, but the view still doesn't exist
statement error
SELECT * FROM test.v
----
Catalog Error: Table with name v does not exist!
statement ok
CREATE VIEW test.v AS SELECT * FROM test.t;
query IIIIII
PRAGMA table_info('test.v')
----
0 a INTEGER 0 NULL 0
1 b INTEGER 0 NULL 0
# Try to drop the table
statement error
drop table test.t;
----
view "v" depends on table "t".
# Now with CASCADE
statement ok
drop table test.t cascade;
statement error
SELECT * FROM test.v2
----
endloop

View File

@@ -0,0 +1,97 @@
# name: test/sql/storage/wal/wal_view_storage_no_view_dependencies.test
# description: Create and drop a view over different runs
# group: [wal]
require skip_reload
# load the DB from disk
load __TEST_DIR__/view_storage.db
statement ok
PRAGMA disable_checkpoint_on_shutdown
statement ok
PRAGMA wal_autocheckpoint='1TB';
# create a schema and view
statement ok
CREATE SCHEMA test;
statement ok
CREATE TABLE test.t (a INTEGER, b INTEGER);
statement ok
CREATE VIEW test.v AS SELECT * FROM test.t;
# read the info from the view
query IIIIII
PRAGMA table_info('test.v')
----
0 a INTEGER 0 NULL 0
1 b INTEGER 0 NULL 0
# drop the table the view is based on
statement ok
DROP TABLE test.t
# we can still query the types and column names
query IIIIII
PRAGMA table_info('test.v')
----
0 a INTEGER 0 NULL 0
1 b INTEGER 0 NULL 0
# but querying the view fails
statement error
SELECT * FROM test.v
----
statement ok
CREATE VIEW test.v2 AS SELECT 42
statement ok
DROP VIEW test.v2
loop i 0 2
# restart the system
restart
# the view still exists, but the table does not
# we can check the types, but not query it
query IIIIII
PRAGMA table_info('test.v')
----
0 a INTEGER 0 NULL 0
1 b INTEGER 0 NULL 0
statement error
SELECT * FROM test.v
----
# after recreating the table, we can query the view again
statement ok
CREATE TABLE test.t (a INTEGER, b INTEGER);
statement ok
SELECT * FROM test.t
statement ok
SELECT * FROM test.v
query IIIIII
PRAGMA table_info('test.v')
----
0 a INTEGER 0 NULL 0
1 b INTEGER 0 NULL 0
# drop the table again
statement ok
DROP TABLE test.t
statement error
SELECT * FROM test.v2
----
endloop