Skip to content

Commit 6d6e573

Browse files
authored
fix: transient should ignore retention period settings and table options (#18295)
1 parent 9c2271e commit 6d6e573

File tree

2 files changed

+115
-13
lines changed

2 files changed

+115
-13
lines changed

src/query/storages/fuse/src/fuse_table.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,15 +491,18 @@ impl FuseTable {
491491
/// 1. Number of snapshots to keep (from table option or setting)
492492
/// 2. Time-based retention period (if snapshot count is not specified)
493493
pub fn get_data_retention_policy(&self, ctx: &dyn TableContext) -> Result<RetentionPolicy> {
494-
let policy =
494+
let policy = if self.is_transient() {
495+
RetentionPolicy::ByNumOfSnapshotsToKeep(1)
496+
} else {
495497
// Try to get number of snapshots to keep
496498
if let Some(num_snapshots) = self.try_get_policy_by_num_snapshots_to_keep(ctx)? {
497499
RetentionPolicy::ByNumOfSnapshotsToKeep(num_snapshots as usize)
498500
} else {
499501
// Fall back to time-based retention policy
500502
let duration = self.get_data_retention_period(ctx)?;
501503
RetentionPolicy::ByTimePeriod(duration)
502-
};
504+
}
505+
};
503506

504507
Ok(policy)
505508
}
Lines changed: 110 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,140 @@
11
statement ok
2-
DROP DATABASE IF EXISTS db1
2+
create or replace database ee_vacuum_03_0018;
33

44
statement ok
5-
CREATE DATABASE db1
5+
use ee_vacuum_03_0018;
66

77
statement ok
8-
USE db1
8+
CREATE OR REPLACE TRANSIENT TABLE test_tbl(a int);
9+
10+
####################################################################################
11+
# transient tables should ignore the data_retention_num_snapshots_to_keep settings #
12+
####################################################################################
13+
14+
statement ok
15+
set data_retention_num_snapshots_to_keep = 20;
16+
17+
statement ok
18+
INSERT INTO test_tbl VALUES(1)
19+
20+
statement ok
21+
INSERT INTO test_tbl VALUES(2)
22+
23+
statement ok
24+
INSERT INTO test_tbl VALUES(3)
25+
26+
query I
27+
select * from test_tbl order by a
28+
----
29+
1
30+
2
31+
3
32+
33+
query B
34+
select count(*)=1 from fuse_snapshot('ee_vacuum_03_0018', 'test_tbl')
35+
----
36+
1
37+
38+
###############################################################################
39+
# test data_retention_time_in_days setting does not affect transient tables #
40+
###############################################################################
41+
42+
# reset data_retention_num_snapshots_to_keep to default value
43+
statement ok
44+
unset data_retention_num_snapshots_to_keep
45+
46+
statement ok
47+
CREATE OR REPLACE TRANSIENT TABLE test_tbl(a int);
48+
49+
# transient tables should ignore the data_retention_time_in_days settings
50+
statement ok
51+
set data_retention_time_in_days = 20;
52+
53+
statement ok
54+
INSERT INTO test_tbl VALUES(1)
55+
56+
statement ok
57+
INSERT INTO test_tbl VALUES(2)
58+
59+
statement ok
60+
INSERT INTO test_tbl VALUES(3)
61+
62+
query I
63+
select * from test_tbl order by a
64+
----
65+
1
66+
2
67+
3
68+
69+
query B
70+
select count(*)=1 from fuse_snapshot('ee_vacuum_03_0018', 'test_tbl')
71+
----
72+
1
73+
74+
######################################################################################
75+
# test table option data_retention_period_in_hours does not affect transient tables #
76+
######################################################################################
77+
78+
# reset data_retention_time_in_days to default value
79+
statement ok
80+
unset data_retention_time_in_days;
81+
82+
# transient tables should ignore the data_retention_period_in_hours table option
83+
statement ok
84+
CREATE OR REPLACE TRANSIENT TABLE test_tbl(a int) data_retention_period_in_hours = 1;
985

1086
statement ok
11-
CREATE TRANSIENT TABLE IF NOT EXISTS t09_0016(a int)
87+
unset data_retention_num_snapshots_to_keep;
1288

1389
statement ok
14-
INSERT INTO t09_0016 VALUES(1)
90+
INSERT INTO test_tbl VALUES(1)
1591

1692
statement ok
17-
INSERT INTO t09_0016 VALUES(2)
93+
INSERT INTO test_tbl VALUES(2)
1894

1995
statement ok
20-
INSERT INTO t09_0016 VALUES(3)
96+
INSERT INTO test_tbl VALUES(3)
2197

2298
query I
23-
select * from t09_0016 order by a
99+
select * from test_tbl order by a
24100
----
25101
1
26102
2
27103
3
28104

29105
query B
30-
select count(*)=1 from fuse_snapshot('db1', 't09_0016')
106+
select count(*)=1 from fuse_snapshot('ee_vacuum_03_0018', 'test_tbl')
31107
----
32108
1
33109

110+
######################################################################################
111+
# test table option data_retention_num_snapshots_to_keep does not affect transient tables #
112+
######################################################################################
34113

114+
# transient tables should ignore the data_retention_num_snapshots_to_keep table option
115+
statement ok
116+
CREATE OR REPLACE TRANSIENT TABLE test_tbl(a int) data_retention_num_snapshots_to_keep = 100;
117+
118+
statement ok
119+
INSERT INTO test_tbl VALUES(1)
35120

36121
statement ok
37-
DROP TABLE t09_0016
122+
INSERT INTO test_tbl VALUES(2)
38123

39124
statement ok
40-
DROP DATABASE db1
125+
INSERT INTO test_tbl VALUES(3)
126+
127+
query I
128+
select * from test_tbl order by a
129+
----
130+
1
131+
2
132+
3
133+
134+
query B
135+
select count(*)=1 from fuse_snapshot('ee_vacuum_03_0018', 'test_tbl')
136+
----
137+
1
138+
139+
41140

0 commit comments

Comments
 (0)