transactions.pt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. # Test implicit and explicit transaction semantics in ways that
  2. # MZ differs from PG.
  3. # See pgtest/transactions.pt for more details
  4. send
  5. Query {"query": "DROP TABLE IF EXISTS t"}
  6. ----
  7. until ignore=NoticeResponse
  8. ReadyForQuery
  9. ----
  10. CommandComplete {"tag":"DROP TABLE"}
  11. ReadyForQuery {"status":"I"}
  12. # Verify implicit transactions are properly upgraded
  13. send
  14. Query {"query": "CREATE TABLE t (a INT)"}
  15. Parse {"query": "INSERT INTO t VALUES (1)"}
  16. Bind
  17. Execute
  18. Sync
  19. ----
  20. until err_field_typs=M ignore=RowDescription
  21. ReadyForQuery
  22. ReadyForQuery
  23. ----
  24. CommandComplete {"tag":"CREATE TABLE"}
  25. ReadyForQuery {"status":"I"}
  26. ParseComplete
  27. BindComplete
  28. CommandComplete {"tag":"INSERT 0 1"}
  29. ReadyForQuery {"status":"I"}
  30. # PG permits commits writes that are part of read-only txns, but
  31. # we do not if the read involves a timestamp
  32. send
  33. Query {"query": "INSERT INTO t VALUES (2); BEGIN READ ONLY; SELECT * FROM t;"}
  34. Query {"query": "COMMIT"}
  35. ----
  36. until err_field_typs=M ignore=RowDescription
  37. ReadyForQuery
  38. ReadyForQuery
  39. ----
  40. CommandComplete {"tag":"INSERT 0 1"}
  41. CommandComplete {"tag":"BEGIN"}
  42. ErrorResponse {"fields":[{"typ":"M","value":"transaction in write-only mode"}]}
  43. ReadyForQuery {"status":"E"}
  44. CommandComplete {"tag":"ROLLBACK"}
  45. ReadyForQuery {"status":"I"}
  46. # Unlike PostgreSQL, we do not upgrade implicit transactions in the
  47. # extended protocol
  48. send
  49. Parse {"query": "INSERT INTO t VALUES (2)"}
  50. Bind
  51. Execute
  52. Parse {"query": "BEGIN"}
  53. Bind
  54. Execute
  55. Parse {"query": "COMMIT"}
  56. Bind
  57. Execute
  58. Sync
  59. Parse {"query": "SELECT a FROM t"}
  60. Bind
  61. Execute
  62. Sync
  63. ----
  64. until err_field_typs=M ignore=RowDescription
  65. ReadyForQuery
  66. ReadyForQuery
  67. ----
  68. ParseComplete
  69. BindComplete
  70. CommandComplete {"tag":"INSERT 0 1"}
  71. ParseComplete
  72. BindComplete
  73. CommandComplete {"tag":"BEGIN"}
  74. ParseComplete
  75. BindComplete
  76. CommandComplete {"tag":"COMMIT"}
  77. ReadyForQuery {"status":"I"}
  78. ParseComplete
  79. BindComplete
  80. DataRow {"fields":["1"]}
  81. DataRow {"fields":["2"]}
  82. CommandComplete {"tag":"SELECT 2"}
  83. ReadyForQuery {"status":"I"}
  84. send
  85. Parse {"query": "INSERT INTO t VALUES (3)"}
  86. Bind
  87. Execute
  88. Parse {"query": "BEGIN"}
  89. Bind
  90. Execute
  91. Parse {"query": "SELECT 0/0"}
  92. Bind
  93. Execute
  94. Sync
  95. Parse {"query": "COMMIT"}
  96. Bind
  97. Execute
  98. Sync
  99. Parse {"query": "SELECT a FROM t"}
  100. Bind
  101. Execute
  102. Sync
  103. ----
  104. until err_field_typs=M ignore=RowDescription
  105. ReadyForQuery
  106. ReadyForQuery
  107. ReadyForQuery
  108. ----
  109. ParseComplete
  110. BindComplete
  111. CommandComplete {"tag":"INSERT 0 1"}
  112. ParseComplete
  113. BindComplete
  114. CommandComplete {"tag":"BEGIN"}
  115. ParseComplete
  116. BindComplete
  117. ErrorResponse {"fields":[{"typ":"M","value":"division by zero"}]}
  118. ReadyForQuery {"status":"E"}
  119. ParseComplete
  120. BindComplete
  121. CommandComplete {"tag":"ROLLBACK"}
  122. ReadyForQuery {"status":"I"}
  123. ParseComplete
  124. BindComplete
  125. DataRow {"fields":["1"]}
  126. DataRow {"fields":["2"]}
  127. DataRow {"fields":["3"]}
  128. CommandComplete {"tag":"SELECT 3"}
  129. ReadyForQuery {"status":"I"}
  130. # Verify eager committing in implicit transactions for the extended protocol.
  131. # In Materialize we eagerly commit all statements in an implicit transaction
  132. # for the extended protocol. This differs from PostgreSQL, which only eagerly
  133. # commits certain statements.
  134. send
  135. Parse {"query": "INSERT INTO t VALUES (4)"}
  136. Bind
  137. Execute
  138. Parse {"query": "SELECT 1/(SELECT 0)"}
  139. Bind
  140. Execute
  141. Sync
  142. Query {"query": "SELECT * FROM t"}
  143. ----
  144. until
  145. ReadyForQuery
  146. ReadyForQuery
  147. ----
  148. ParseComplete
  149. BindComplete
  150. CommandComplete {"tag":"INSERT 0 1"}
  151. ParseComplete
  152. BindComplete
  153. ErrorResponse {"fields":[{"typ":"S","value":"ERROR"},{"typ":"C","value":"XX000"},{"typ":"M","value":"division by zero"}]}
  154. ReadyForQuery {"status":"I"}
  155. RowDescription {"fields":[{"name":"a"}]}
  156. DataRow {"fields":["1"]}
  157. DataRow {"fields":["2"]}
  158. DataRow {"fields":["3"]}
  159. DataRow {"fields":["4"]}
  160. CommandComplete {"tag":"SELECT 4"}
  161. ReadyForQuery {"status":"I"}
  162. # Verify that we don't eagerly commit in implicit transactions for the simple
  163. # protocol.
  164. send
  165. Query {"query": "INSERT INTO t VALUES (5); SELECT 1/(SELECT 0)"}
  166. Query {"query": "SELECT * FROM t"}
  167. ----
  168. until
  169. ReadyForQuery
  170. ReadyForQuery
  171. ----
  172. CommandComplete {"tag":"INSERT 0 1"}
  173. RowDescription {"fields":[{"name":"?column?"}]}
  174. ErrorResponse {"fields":[{"typ":"S","value":"ERROR"},{"typ":"C","value":"XX000"},{"typ":"M","value":"division by zero"}]}
  175. ReadyForQuery {"status":"I"}
  176. RowDescription {"fields":[{"name":"a"}]}
  177. DataRow {"fields":["1"]}
  178. DataRow {"fields":["2"]}
  179. DataRow {"fields":["3"]}
  180. DataRow {"fields":["4"]}
  181. CommandComplete {"tag":"SELECT 4"}
  182. ReadyForQuery {"status":"I"}