You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

246 lines
6.9 KiB

  1. #
  2. # Test A Outline:
  3. # ===============
  4. #
  5. # This test tests the scenario for MW-369 where a new child table
  6. # row referring to parent table row is inserted concurrently from
  7. # another node while the transaction which tries to delete a
  8. # referred row from the parent table is committing.
  9. #
  10. # The p table will originally have rows (1, 0), (2, 0).
  11. # The c table will be empty.
  12. #
  13. # A new row (1, 1) pointing to parent row (1, 0) is inserted from
  14. # connection node_2, the transaction which tries to remove the
  15. # parent row (1, 0) is run from connection node_1.
  16. #
  17. # Expected outcome:
  18. # ================
  19. #
  20. # The transaction on node_1 will fail. The parent table will contain
  21. # rows (1, 0), (2, 0) and the child table will contain row (1, 1).
  22. #
  23. --source include/galera_cluster.inc
  24. --source include/have_innodb.inc
  25. --source include/have_debug_sync.inc
  26. --source suite/galera/include/galera_have_debug_sync.inc
  27. CREATE TABLE p (f1 INTEGER PRIMARY KEY, f2 INTEGER) ENGINE=INNODB;
  28. CREATE TABLE c (f1 INTEGER PRIMARY KEY, p_id INTEGER,
  29. CONSTRAINT fk_1 FOREIGN KEY (p_id) REFERENCES p (f1)) ;
  30. INSERT INTO p VALUES (1, 0);
  31. INSERT INTO p VALUES (2, 0);
  32. --let $mw_369_parent_query = DELETE FROM p WHERE f1 = 1
  33. --let $mw_369_child_query = INSERT INTO c VALUES (1, 1)
  34. #
  35. # we must open connection node_1a here, MW-369.inc will use it later
  36. #
  37. --connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1
  38. --source MW-369.inc
  39. # Commit fails
  40. --connection node_1
  41. --error ER_LOCK_DEADLOCK
  42. --reap
  43. --connection node_2
  44. SELECT * FROM p;
  45. SELECT * FROM c;
  46. DROP TABLE c;
  47. DROP TABLE p;
  48. #
  49. # Test B Outline:
  50. # ===============
  51. #
  52. # This test tests the scenario for MW-369 where a existing
  53. # child table row is updated concurrently from another node
  54. # with a transaction which updates the parent table.
  55. #
  56. # The p table will originally have rows (1, 0), (2, 0).
  57. # The c table will originally have rows (1, 1, 0) which points
  58. # to parent table row (1, 0).
  59. #
  60. # Expected outcome:
  61. # ================
  62. #
  63. # Both updates should succeed since they are done to separate tables and
  64. # rows. The parent table will contain rows (1, 1), (2, 0). The child
  65. # table will contain row (1, 1, 1).
  66. #
  67. --connection node_1
  68. CREATE TABLE p (f1 INTEGER PRIMARY KEY, f2 INTEGER) ENGINE=INNODB;
  69. CREATE TABLE c (f1 INTEGER PRIMARY KEY, p_id INTEGER,
  70. f2 INTEGER,
  71. CONSTRAINT fk_1 FOREIGN KEY (p_id) REFERENCES p (f1)) ;
  72. INSERT INTO p VALUES (1, 0);
  73. INSERT INTO p VALUES (2, 0);
  74. INSERT INTO c VALUES (1, 1, 0);
  75. --let mw_369_parent_query = UPDATE p SET f2 = 1 WHERE f1 = 1
  76. --let $mw_369_child_query = UPDATE c SET f2 = 1 WHERE f1 = 1
  77. --source MW-369.inc
  78. # Commit succeeds
  79. --connection node_1
  80. --reap
  81. --connection node_2
  82. SELECT * FROM p;
  83. SELECT * FROM c;
  84. DROP TABLE c;
  85. DROP TABLE p;
  86. #
  87. # Test C Outline:
  88. # ===============
  89. #
  90. # This test tests the scenario for MW-369 where a child table row is
  91. # deleted concurrently from the other node while a transaction updates
  92. # the parent table referred by the child table row.
  93. #
  94. # The p table will originally have rows (1, 0), (2, 0)
  95. # The c table will originally have row (1, 1) which points to parent
  96. # table row (1, 0).
  97. #
  98. # A row (1, 1) pointing to parent row (1, 0) is deleted from
  99. # connection node_2, the transaction which tries to update the
  100. # parent row (1, 0) is run from connection node_1.
  101. #
  102. # Expected Outcome:
  103. # ================
  104. # Both operations on node_1 and node_2 should succeed without conflicts.
  105. # The parent table should contain values (1, 1), (2, 0) and the child
  106. # table should be empty.
  107. --connection node_1
  108. CREATE TABLE p (f1 INTEGER PRIMARY KEY, f2 INTEGER) ENGINE=INNODB;
  109. CREATE TABLE c (f1 INTEGER PRIMARY KEY, p_id INTEGER,
  110. CONSTRAINT fk_1 FOREIGN KEY (p_id) REFERENCES p (f1)) ;
  111. INSERT INTO p VALUES (1, 0);
  112. INSERT INTO p VALUES (2, 0);
  113. INSERT INTO c VALUES (1, 1);
  114. --let $mw_369_parent_query = UPDATE p SET f2 = 1 WHERE f1 = 1
  115. --let $mw_369_child_query = DELETE FROM c WHERE f1 = 1
  116. --source MW-369.inc
  117. # Commit succeeds
  118. --connection node_1
  119. --reap
  120. --connection node_2
  121. SELECT * FROM p;
  122. SELECT * FROM c;
  123. DROP TABLE c;
  124. DROP TABLE p;
  125. #
  126. # Test D Outline:
  127. # ===============
  128. #
  129. # This test is similar to test A, where parent row is deleted while a child row
  130. # is inserted simultaneously on node 2. However, in this test case the FK
  131. # constraint's target column is a unique key, and parent row is not delete,
  132. # but this key value is changed so that insert on node 2 will cause FK
  133. # violation
  134. #
  135. # The p table will originally have rows (1, 0)
  136. # The c table will originally be empty
  137. #
  138. # in node_1, parent row is updated to value (1,1)
  139. # A row (1, 0) pointing to the old version of parent row (1, 0) is inserted
  140. # in connection node_2
  141. #
  142. # Expected Outcome:
  143. # ================
  144. # This is a true conflict and one transaciton must abort. In this case it is node_1
  145. # transaction, which was scheduled later.
  146. # Parent table should have row (1,0)
  147. # child table should have row (1,0)
  148. #
  149. CREATE TABLE p (f1 INTEGER PRIMARY KEY, f2 INTEGER UNIQUE KEY) ENGINE=INNODB;
  150. CREATE TABLE c (f1 INTEGER PRIMARY KEY, p_id INTEGER,
  151. CONSTRAINT fk_1 FOREIGN KEY (p_id) REFERENCES p (f2)) ;
  152. INSERT INTO p VALUES (1, 0);
  153. --let $mw_369_parent_query = UPDATE p SET f2 = 1 WHERE f1 = 1
  154. --let $mw_369_child_query = INSERT INTO c VALUES (1, 0);
  155. --source MW-369.inc
  156. # Commit fails
  157. --connection node_1
  158. --error ER_LOCK_DEADLOCK
  159. --reap
  160. --connection node_2
  161. SELECT * FROM p;
  162. SELECT * FROM c;
  163. DROP TABLE c;
  164. DROP TABLE p;
  165. #
  166. # Test E Outline:
  167. # ===============
  168. #
  169. # This test is similar to test B, where parent row is deleted while a child row
  170. # is updated simultaneously on node 2. However, in this test case the FK
  171. # constraint has ON DELETE CASCADE option, and the delete on parent row will
  172. # cascade a delete on child row as well. This will cause true conflict with
  173. # connection node_2, which tries to update unrelated column on child table.
  174. #
  175. # The p table will originally have rows (1, 0), (2,0)
  176. # The c table will originally have row (1,1,0)
  177. #
  178. # in node_1, parent row (1,0) is deleted and cascaded delete will happen on
  179. # child table row (1,1,0).
  180. # in connection node_2 child table row is update to value (1,1,1)
  181. #
  182. # Expected Outcome:
  183. # ================
  184. # This is a true conflict and one transaciton must abort. In this case it is node_1
  185. # transaction, which was scheduled later.
  186. # Parent table should have rows (1,0), (2,0)
  187. # child table should have row (1,1,1)
  188. #
  189. CREATE TABLE p (f1 INTEGER PRIMARY KEY, f2 INTEGER) ENGINE=INNODB;
  190. CREATE TABLE c (f1 INTEGER PRIMARY KEY, p_id INTEGER, f2 INTEGER,
  191. CONSTRAINT fk_1 FOREIGN KEY (p_id) REFERENCES p (f1)
  192. ON DELETE CASCADE) ;
  193. INSERT INTO p VALUES (1, 0);
  194. INSERT INTO p VALUES (2, 0);
  195. INSERT INTO c VALUES (1, 1, 0);
  196. --let $mw_369_parent_query = DELETE FROM p WHERE f1 = 1
  197. --let $mw_369_child_query = UPDATE c SET f2 = 1 WHERE f1 = 1
  198. --source MW-369.inc
  199. # Commit fails
  200. --connection node_1
  201. --error ER_LOCK_DEADLOCK
  202. --reap
  203. --connection node_2
  204. SELECT * FROM p;
  205. SELECT * FROM c;
  206. DROP TABLE c;
  207. DROP TABLE p;