File: optimistic_write_drop_column.test_slow

package info (click to toggle)
duckdb 1.5.1-3
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 299,196 kB
  • sloc: cpp: 865,414; ansic: 57,292; python: 18,871; sql: 12,663; lisp: 11,751; yacc: 7,412; lex: 1,682; sh: 747; makefile: 564
file content (115 lines) | stat: -rw-r--r-- 2,304 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# name: test/sql/storage/optimistic_write/optimistic_write_drop_column.test_slow
# description: Test optimistic write with drop column in transaction-local storage
# group: [optimistic_write]

load __TEST_DIR__/optimistic_write_drop.db

statement ok
CREATE TABLE test (a INTEGER, b INTEGER, c INTEGER);

statement ok
BEGIN TRANSACTION

statement ok
INSERT INTO test SELECT i, i + 1, i + 2 FROM range(1000000) tbl(i)

statement ok
ALTER TABLE test DROP COLUMN c

statement ok
COMMIT

query II
SELECT SUM(a), SUM(b) FROM test
----
499999500000	500000500000

restart

query II
SELECT SUM(a), SUM(b) FROM test
----
499999500000	500000500000

statement ok
BEGIN TRANSACTION

statement ok
INSERT INTO test SELECT i, i FROM range(1000000) t(i)

statement ok
ALTER TABLE test DROP COLUMN b

statement ok
ROLLBACK

query II
SELECT SUM(a), SUM(b) FROM test
----
499999500000	500000500000

# Ensure that we reclaim space correctly.

require skip_reload

statement ok
CHECKPOINT

# For smaller block sizes (16KB) the total blocks alternate between a few values in the loop.
# Therefore, we compare to a range of total block counts.
statement ok
CREATE TABLE total_blocks_tbl AS SELECT total_blocks FROM pragma_database_size();

loop i 0 10

statement ok
DROP TABLE test

statement ok
CREATE TABLE test (a INTEGER, b INTEGER, c INTEGER);

statement ok
BEGIN TRANSACTION

statement ok
INSERT INTO test SELECT i, i + 1, i + 2 FROM range(1000000) tbl(i)

statement ok
ALTER TABLE test DROP COLUMN c

statement ok
COMMIT

query II
SELECT SUM(a), SUM(b) FROM test
----
499999500000	500000500000

statement ok
CHECKPOINT

# Ensure that the total blocks don't exceed the total blocks after the first iteration
# by more than 1.5.

query I
SELECT CASE WHEN ${i} = 0 THEN NULL
	WHEN current.total_blocks <= total_blocks_tbl.total_blocks * 1.5 THEN NULL
	ELSE {'current': current.total_blocks, 'total': total_blocks_tbl.total_blocks} END
FROM pragma_database_size() AS current, total_blocks_tbl;
----
NULL

# Adjust total_blocks_tbl once to the count after the first iteration.

statement ok
UPDATE total_blocks_tbl SET total_blocks = (
	SELECT CASE WHEN ${i} = 0 THEN (SELECT current.total_blocks FROM pragma_database_size() AS current)
		ELSE (total_blocks) END);

statement ok
CHECKPOINT;

statement ok
CHECKPOINT;

endloop