transactions-multi-conn.td 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. $ set-sql-timeout duration=1s
  10. #
  11. # Test that transactions work properly
  12. #
  13. > CREATE SECRET mysqlpass AS '${arg.mysql-root-password}'
  14. > CREATE CONNECTION mysql_conn TO MYSQL (
  15. HOST mysql,
  16. USER root,
  17. PASSWORD SECRET mysqlpass
  18. )
  19. $ mysql-connect name=mysql1 url=mysql://root@mysql password=${arg.mysql-root-password}
  20. $ mysql-connect name=mysql2 url=mysql://root@mysql password=${arg.mysql-root-password}
  21. $ mysql-connect name=mysql3 url=mysql://root@mysql password=${arg.mysql-root-password}
  22. $ mysql-execute name=mysql1
  23. DROP DATABASE IF EXISTS public;
  24. CREATE DATABASE public;
  25. USE public;
  26. CREATE TABLE t1 (a INT);
  27. CREATE TABLE t2 (a INT);
  28. CREATE TABLE t3 (a INT);
  29. > CREATE SOURCE mz_source
  30. FROM MYSQL CONNECTION mysql_conn
  31. FOR ALL TABLES;
  32. > SELECT count(*) FROM t1;
  33. 0
  34. > SELECT count(*) FROM t2;
  35. 0
  36. > SELECT count(*) FROM t3;
  37. 0
  38. $ mysql-execute name=mysql1
  39. SET AUTOCOMMIT = FALSE;
  40. $ mysql-execute name=mysql2
  41. SET AUTOCOMMIT = FALSE;
  42. USE public;
  43. $ mysql-execute name=mysql3
  44. SET AUTOCOMMIT = FALSE;
  45. USE public;
  46. $ mysql-execute name=mysql1
  47. INSERT INTO t1 VALUES (1000);
  48. INSERT INTO t2 VALUES (1000);
  49. INSERT INTO t3 VALUES (1000);
  50. $ mysql-execute name=mysql2
  51. INSERT INTO t1 VALUES (2000);
  52. INSERT INTO t2 VALUES (2000);
  53. INSERT INTO t3 VALUES (2000);
  54. $ mysql-execute name=mysql3
  55. INSERT INTO t1 VALUES (3000);
  56. INSERT INTO t2 VALUES (3000);
  57. INSERT INTO t3 VALUES (3000);
  58. $ mysql-execute name=mysql1
  59. COMMIT;
  60. $ mysql-execute name=mysql3
  61. COMMIT;
  62. > SELECT * FROM t1;
  63. 1000
  64. 3000
  65. > SELECT * FROM t2;
  66. 1000
  67. 3000
  68. > SELECT * FROM t3;
  69. 1000
  70. 3000
  71. $ mysql-execute name=mysql2
  72. COMMIT;
  73. > SELECT * FROM t1;
  74. 1000
  75. 2000
  76. 3000
  77. # delete and insert statements cannot be done in multiple transactions on the same table even with fine-grained where condition
  78. $ mysql-execute name=mysql1
  79. INSERT INTO t1 VALUES (1001);
  80. INSERT INTO t2 VALUES (1001);
  81. INSERT INTO t3 VALUES (1001);
  82. $ mysql-execute name=mysql2
  83. INSERT INTO t1 VALUES (2001);
  84. INSERT INTO t2 VALUES (2001);
  85. INSERT INTO t3 VALUES (2001);
  86. $ mysql-execute name=mysql3
  87. INSERT INTO t1 VALUES (3001);
  88. INSERT INTO t2 VALUES (3001);
  89. INSERT INTO t3 VALUES (3001);
  90. $ mysql-execute name=mysql1
  91. COMMIT;
  92. $ mysql-execute name=mysql3
  93. COMMIT;
  94. > SELECT * FROM t1;
  95. 1000
  96. 1001
  97. 2000
  98. 3000
  99. 3001
  100. > SELECT * FROM t2;
  101. 1000
  102. 1001
  103. 2000
  104. 3000
  105. 3001
  106. > SELECT * FROM t3;
  107. 1000
  108. 1001
  109. 2000
  110. 3000
  111. 3001
  112. $ mysql-execute name=mysql2
  113. COMMIT;
  114. INSERT INTO t1 VALUES (2002);
  115. $ mysql-execute name=mysql1
  116. INSERT INTO t1 VALUES (1002);
  117. DELETE FROM t2 WHERE a = 2000;
  118. $ mysql-execute name=mysql2
  119. DELETE FROM t3 WHERE a = 2000;
  120. $ mysql-execute name=mysql1
  121. COMMIT;
  122. > SELECT * FROM t1;
  123. 1000
  124. 1001
  125. 1002
  126. 2000
  127. 2001
  128. 3000
  129. 3001
  130. > SELECT * FROM t2;
  131. 1000
  132. 1001
  133. 2001
  134. 3000
  135. 3001
  136. > SELECT * FROM t3;
  137. 1000
  138. 1001
  139. 2000
  140. 2001
  141. 3000
  142. 3001
  143. $ mysql-execute name=mysql2
  144. COMMIT;
  145. > SELECT * FROM t1;
  146. 1000
  147. 1001
  148. 1002
  149. 2000
  150. 2001
  151. 2002
  152. 3000
  153. 3001
  154. > SELECT * FROM t2;
  155. 1000
  156. 1001
  157. 2001
  158. 3000
  159. 3001
  160. > SELECT * FROM t3;
  161. 1000
  162. 1001
  163. 2001
  164. 3000
  165. 3001