ct_retain.slt 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. mode cockroach
  10. # Retention Window
  11. statement ok
  12. CREATE TABLE append_only (val STRING, ts_col TIMESTAMPTZ)
  13. statement ok
  14. CREATE CONTINUAL TASK retain
  15. FROM RETAIN append_only
  16. WHILE (ts_col + INTERVAL '2s' > mz_now())
  17. # The 1m row will never be inserted in the first place because the INSERT in the
  18. # de-sugared version filters by the retain expr.
  19. statement ok
  20. INSERT INTO append_only VALUES ('1s', now() - INTERVAL '1s'), ('1m', now() - INTERVAL '1m')
  21. query T
  22. SELECT val FROM retain
  23. ----
  24. 1s
  25. # Sleep so that the 1s row has aged out.
  26. statement ok
  27. SELECT mz_unsafe.mz_sleep(2)
  28. # SUBTLE: CTs (currently) only write at times in the input, not at every time.
  29. # This means the aged out data will not be deleted until the next INSERT.
  30. # Further, that insert has to actually insert data, so we can't use 1m again.
  31. #
  32. # It is currently an open question whether this is the right semantics. There
  33. # are some tradeoffs the other way too.
  34. query T
  35. SELECT val FROM retain
  36. ----
  37. 1s
  38. statement ok
  39. INSERT INTO append_only VALUES ('0s', now())
  40. query T
  41. SELECT val FROM retain
  42. ----
  43. 0s