table-persistence-before-interleaved.td 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #
  10. # Tests with interleaved transactions - the INSERTs made by both transactions
  11. # must be present in full post-restart regardless of the order of execution.
  12. #
  13. # Mz currently does not support other DML statements in a transactional context.
  14. #
  15. # Second transaction completes before first
  16. > CREATE TABLE second_completes_first (f1 INTEGER);
  17. $ postgres-connect name=conn1 url=postgres://materialize:materialize@${testdrive.materialize-sql-addr}
  18. $ postgres-connect name=conn2 url=postgres://materialize:materialize@${testdrive.materialize-sql-addr}
  19. $ postgres-execute connection=conn1
  20. BEGIN;
  21. INSERT INTO second_completes_first VALUES (1);
  22. INSERT INTO second_completes_first VALUES (2);
  23. INSERT INTO second_completes_first VALUES (3);
  24. $ postgres-execute connection=conn2
  25. BEGIN;
  26. INSERT INTO second_completes_first VALUES (4);
  27. INSERT INTO second_completes_first VALUES (5);
  28. INSERT INTO second_completes_first VALUES (6);
  29. COMMIT;
  30. $ postgres-execute connection=conn1
  31. INSERT INTO second_completes_first VALUES (7);
  32. INSERT INTO second_completes_first VALUES (8);
  33. INSERT INTO second_completes_first VALUES (9);
  34. INSERT INTO second_completes_first VALUES (10)
  35. COMMIT;
  36. # Second transaction completes after first
  37. > CREATE TABLE second_completes_last (f1 INTEGER);
  38. $ postgres-execute connection=conn1
  39. BEGIN;
  40. INSERT INTO second_completes_last VALUES (1);
  41. INSERT INTO second_completes_last VALUES (2);
  42. INSERT INTO second_completes_last VALUES (3);
  43. $ postgres-execute connection=conn2
  44. INSERT INTO second_completes_last VALUES (4);
  45. INSERT INTO second_completes_last VALUES (5);
  46. INSERT INTO second_completes_last VALUES (6);
  47. $ postgres-execute connection=conn1
  48. INSERT INTO second_completes_last VALUES (7);
  49. INSERT INTO second_completes_last VALUES (8);
  50. INSERT INTO second_completes_last VALUES (9);
  51. COMMIT;
  52. $ postgres-execute connection=conn2
  53. INSERT INTO second_completes_last VALUES (10);
  54. COMMIT;
  55. # Both transaction operate on the same values
  56. > CREATE TABLE same_values (f1 INTEGER);
  57. $ postgres-execute connection=conn1
  58. BEGIN;
  59. INSERT INTO same_values VALUES (1);
  60. $ postgres-execute connection=conn2
  61. BEGIN;
  62. INSERT INTO same_values VALUES (5);
  63. $ postgres-execute connection=conn1
  64. INSERT INTO same_values VALUES (2);
  65. $ postgres-execute connection=conn2
  66. INSERT INTO same_values VALUES (4);
  67. $ postgres-execute connection=conn1
  68. INSERT INTO same_values VALUES (3);
  69. $ postgres-execute connection=conn2
  70. INSERT INTO same_values VALUES (3);
  71. $ postgres-execute connection=conn1
  72. INSERT INTO same_values VALUES (4);
  73. $ postgres-execute connection=conn2
  74. INSERT INTO same_values VALUES (2);
  75. $ postgres-execute connection=conn1
  76. INSERT INTO same_values VALUES (5);
  77. COMMIT;
  78. $ postgres-execute connection=conn2
  79. INSERT INTO same_values VALUES (1);
  80. COMMIT;