-
Notifications
You must be signed in to change notification settings - Fork 465
/
Copy pathct_retain.slt
53 lines (43 loc) · 1.42 KB
/
ct_retain.slt
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
# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.
mode cockroach
# Retention Window
statement ok
CREATE TABLE append_only (val STRING, ts_col TIMESTAMPTZ)
statement ok
CREATE CONTINUAL TASK retain
FROM RETAIN append_only
WHILE (ts_col + INTERVAL '2s' > mz_now())
# The 1m row will never be inserted in the first place because the INSERT in the
# de-sugared version filters by the retain expr.
statement ok
INSERT INTO append_only VALUES ('1s', now() - INTERVAL '1s'), ('1m', now() - INTERVAL '1m')
query T
SELECT val FROM retain
----
1s
# Sleep so that the 1s row has aged out.
statement ok
SELECT mz_unsafe.mz_sleep(2)
# SUBTLE: CTs (currently) only write at times in the input, not at every time.
# This means the aged out data will not be deleted until the next INSERT.
# Further, that insert has to actually insert data, so we can't use 1m again.
#
# It is currently an open question whether this is the right semantics. There
# are some tradeoffs the other way too.
query T
SELECT val FROM retain
----
1s
statement ok
INSERT INTO append_only VALUES ('0s', now())
query T
SELECT val FROM retain
----
0s