1 | #include "catch.hpp" |
2 | #include "duckdb/common/file_system.hpp" |
3 | #include "test_helpers.hpp" |
4 | #include "duckdb/main/appender.hpp" |
5 | |
6 | using namespace duckdb; |
7 | using namespace std; |
8 | |
9 | TEST_CASE("Test scanning of persisted storage" , "[storage]" ) { |
10 | auto config = GetTestConfig(); |
11 | unique_ptr<QueryResult> result; |
12 | auto storage_database = TestCreatePath("storage_test" ); |
13 | |
14 | // make sure the database does not exist |
15 | DeleteDatabase(storage_database); |
16 | { |
17 | // create a database and insert values |
18 | DuckDB db(storage_database, config.get()); |
19 | Connection con(db); |
20 | REQUIRE_NO_FAIL(con.Query("CREATE TABLE test (a INTEGER);" )); |
21 | REQUIRE_NO_FAIL(con.Query("INSERT INTO test VALUES (11), (12), (13), (14), (15), (NULL)" )); |
22 | } |
23 | // perform read-only scans a few times |
24 | for (idx_t i = 0; i < 2; i++) { |
25 | DuckDB db(storage_database, config.get()); |
26 | Connection con(db); |
27 | result = con.Query("SELECT * FROM test ORDER BY a" ); |
28 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), 11, 12, 13, 14, 15})); |
29 | result = con.Query("SELECT * FROM test ORDER BY a" ); |
30 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), 11, 12, 13, 14, 15})); |
31 | } |
32 | // now perform a deletion |
33 | { |
34 | DuckDB db(storage_database, config.get()); |
35 | Connection con(db); |
36 | result = con.Query("SELECT * FROM test ORDER BY a" ); |
37 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), 11, 12, 13, 14, 15})); |
38 | result = con.Query("SELECT * FROM test ORDER BY a" ); |
39 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), 11, 12, 13, 14, 15})); |
40 | |
41 | REQUIRE_NO_FAIL(con.Query("DELETE FROM test WHERE a=12;" )); |
42 | |
43 | result = con.Query("SELECT * FROM test ORDER BY a" ); |
44 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), 11, 13, 14, 15})); |
45 | } |
46 | // reload and perform another deletion |
47 | { |
48 | DuckDB db(storage_database, config.get()); |
49 | Connection con(db); |
50 | result = con.Query("SELECT * FROM test ORDER BY a" ); |
51 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), 11, 13, 14, 15})); |
52 | |
53 | REQUIRE_NO_FAIL(con.Query("DELETE FROM test WHERE a=13;" )); |
54 | |
55 | result = con.Query("SELECT * FROM test ORDER BY a" ); |
56 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), 11, 14, 15})); |
57 | } |
58 | // reload and read again |
59 | { |
60 | DuckDB db(storage_database, config.get()); |
61 | Connection con(db); |
62 | result = con.Query("SELECT * FROM test ORDER BY a" ); |
63 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), 11, 14, 15})); |
64 | result = con.Query("SELECT * FROM test ORDER BY a" ); |
65 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), 11, 14, 15})); |
66 | } |
67 | DeleteDatabase(storage_database); |
68 | } |
69 | |