verify-rtr.td 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. $ postgres-execute connection=postgres://mz_system:materialize@${testdrive.materialize-internal-sql-addr}
  10. ALTER SYSTEM SET allow_real_time_recency = true
  11. > SET TRANSACTION_ISOLATION = 'STRICT SERIALIZABLE';
  12. > SET REAL_TIME_RECENCY TO TRUE
  13. $ postgres-execute connection=postgres://postgres:postgres@postgres
  14. INSERT INTO table_a SELECT 1,2 FROM generate_series(1, 100);
  15. INSERT INTO table_b SELECT 1,2 FROM generate_series(1, 100);
  16. INSERT INTO table_a SELECT 1,2 FROM generate_series(1, 101);
  17. INSERT INTO table_b SELECT 1,2 FROM generate_series(1, 102);
  18. # This is a RTR query, so the first result should be correct
  19. $ set-max-tries max-tries=1
  20. > SELECT sum(count)
  21. FROM (
  22. SELECT count(*) FROM table_a
  23. UNION ALL SELECT count(*) FROM table_b
  24. UNION ALL SELECT count(*) FROM t
  25. );
  26. 604
  27. # Do it again
  28. $ postgres-execute connection=postgres://postgres:postgres@postgres
  29. INSERT INTO table_a SELECT 1,2 FROM generate_series(1, 101);
  30. INSERT INTO table_b SELECT 1,2 FROM generate_series(1, 102);
  31. > SELECT sum(count)
  32. FROM (
  33. SELECT count(*) FROM table_a
  34. UNION ALL SELECT count(*) FROM table_b
  35. UNION ALL SELECT count(*) FROM t
  36. );
  37. 807
  38. # Demo materialized views built on sources obey RTR.
  39. > SET REAL_TIME_RECENCY TO FALSE
  40. $ postgres-execute connection=postgres://postgres:postgres@postgres
  41. INSERT INTO table_a SELECT 1,2 FROM generate_series(1, 100);
  42. INSERT INTO table_b SELECT 1,2 FROM generate_series(1, 100);
  43. > SELECT sum < 1007 FROM sum;
  44. true
  45. > SET REAL_TIME_RECENCY TO TRUE
  46. > SELECT sum FROM sum;
  47. 1007
  48. # Do it again
  49. $ postgres-execute connection=postgres://postgres:postgres@postgres
  50. INSERT INTO table_a SELECT 1,2 FROM generate_series(1, 100);
  51. INSERT INTO table_b SELECT 1,2 FROM generate_series(1, 100);
  52. > SELECT sum FROM sum;
  53. 1207