peek_persist.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. from materialize.checks.actions import Testdrive
  10. from materialize.checks.checks import Check
  11. class PeekPersist(Check):
  12. """Make sure old data can still be read by the PeekPersist LIMIT optimization"""
  13. def initialize(self) -> Testdrive:
  14. return Testdrive(
  15. """
  16. > CREATE TABLE peek_persist (f1 INTEGER);
  17. > INSERT INTO peek_persist VALUES (1), (2), (3), (NULL);
  18. """
  19. )
  20. def manipulate(self) -> list[Testdrive]:
  21. return [
  22. Testdrive(s)
  23. for s in [
  24. """
  25. > INSERT INTO peek_persist VALUES (NULL), (1), (2), (3);
  26. > UPDATE peek_persist SET f1 = f1 + 1;
  27. """,
  28. """
  29. > INSERT INTO peek_persist VALUES (3), (NULL), (1), (2);
  30. > DELETE FROM peek_persist WHERE f1 = 4;
  31. """,
  32. ]
  33. ]
  34. def validate(self) -> Testdrive:
  35. return Testdrive(
  36. """
  37. > SELECT * FROM peek_persist LIMIT 100
  38. <null>
  39. <null>
  40. <null>
  41. 1
  42. 2
  43. 2
  44. 2
  45. 3
  46. 3
  47. 3
  48. # TODO(bkirwi): revisit this when persist peeks have stabilized
  49. # ? EXPLAIN OPTIMIZED PLAN AS VERBOSE TEXT FOR SELECT * FROM peek_persist LIMIT 100
  50. # Explained Query (fast path):
  51. # Finish limit=100 output=[#0]
  52. # PeekPersist materialize.public.peek_persist
  53. """
  54. )