updates.slt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. # This test may seem simple, but it is surprisingly good at verifying that
  10. # logical timestamp handling for internal inputs is sane.
  11. statement ok
  12. CREATE TABLE t (a INT)
  13. statement ok
  14. INSERT INTO t VALUES (1)
  15. query I rowsort
  16. SELECT a FROM t
  17. ----
  18. 1
  19. statement ok
  20. INSERT INTO t VALUES (2)
  21. query I rowsort
  22. SELECT a FROM t
  23. ----
  24. 1
  25. 2
  26. statement ok
  27. CREATE TABLE t2 (a INT)
  28. statement ok
  29. INSERT INTO t2 VALUES (1), (3)
  30. query I
  31. SELECT a FROM t NATURAL JOIN t2
  32. ----
  33. 1
  34. statement ok
  35. INSERT INTO t VALUES (3)
  36. query I rowsort
  37. SELECT a FROM t NATURAL JOIN t2
  38. ----
  39. 1
  40. 3
  41. # Test that updates work in Serializable mode
  42. statement ok
  43. CREATE TABLE t1( x INTEGER)
  44. statement ok
  45. SET transaction_isolation=serializable
  46. statement ok
  47. INSERT INTO t1 VALUES(1)
  48. statement ok
  49. CREATE INDEX t1i1 ON t1(x)
  50. statement ok
  51. UPDATE t1 SET x=1
  52. statement ok
  53. UPDATE t1 SET x=2
  54. statement ok
  55. UPDATE t1 SET x=3
  56. statement ok
  57. UPDATE t1 SET x=4
  58. statement ok
  59. SET transaction_isolation='strict serializable'
  60. query I
  61. SELECT * FROM t1
  62. ----
  63. 4
  64. # Test that updates work in Strong Session Serializable mode
  65. simple conn=mz_system,user=mz_system
  66. ALTER SYSTEM SET enable_session_timelines = true;
  67. ----
  68. COMPLETE 0
  69. statement ok
  70. SET transaction_isolation='strong session serializable'
  71. statement ok
  72. UPDATE t1 SET x=1
  73. statement ok
  74. UPDATE t1 SET x=2
  75. statement ok
  76. UPDATE t1 SET x=3
  77. statement ok
  78. UPDATE t1 SET x=4
  79. statement ok
  80. SET transaction_isolation='strict serializable'
  81. query I
  82. SELECT * FROM t1
  83. ----
  84. 4
  85. # Test UPDATE AS
  86. statement ok
  87. UPDATE t1 AS m SET x = 5 WHERE m.x < 10
  88. query I
  89. SELECT * FROM t1
  90. ----
  91. 5
  92. statement ok
  93. UPDATE t1 AS m SET x = 6 WHERE x < 10
  94. query I
  95. SELECT * FROM t1
  96. ----
  97. 6
  98. statement error db error: ERROR: column "t1\.x" does not exist
  99. UPDATE t1 AS m SET x = 5 WHERE t1.x < 10
  100. # Regression for database-issues#7334
  101. simple
  102. BEGIN;
  103. SELECT 1;
  104. INSERT INTO t VALUES (1) RETURNING 0;
  105. COMMIT;
  106. ----
  107. db error: ERROR: INSERT INTO t VALUES (1) RETURNING 0 cannot be run inside a transaction block
  108. # Regression for non-constant VALUES
  109. # VALUES cannot contain a query that references a table.
  110. simple
  111. ROLLBACK;
  112. BEGIN;
  113. INSERT INTO t1 VALUES((SELECT x FROM t1 LIMIT 1));
  114. COMMIT;
  115. ----
  116. db error: ERROR: INSERT INTO t1 VALUES ((SELECT x FROM t1 LIMIT 1)) cannot be run inside a transaction block
  117. # VALUES can contain a subselect with no table references.
  118. simple
  119. ROLLBACK;
  120. BEGIN;
  121. INSERT INTO t1 VALUES((SELECT 1));
  122. COMMIT;
  123. ----
  124. COMPLETE 0
  125. COMPLETE 0
  126. COMPLETE 1
  127. COMPLETE 0
  128. # Make sure we can't trick the constant checker with things like an ORDER BY.
  129. simple
  130. BEGIN;
  131. INSERT INTO t1 VALUES((SELECT 1 ORDER BY (SELECT x FROM t1 LIMIT 1)));
  132. COMMIT;
  133. ----
  134. db error: ERROR: INSERT INTO t1 VALUES ((SELECT 1 ORDER BY (SELECT x FROM t1 LIMIT 1))) cannot be run inside a transaction block
  135. statement ok
  136. ROLLBACK
  137. # Need to disable the result stash, so that we actually exceed max result size
  138. simple conn=mz_system,user=mz_system
  139. ALTER SYSTEM SET enable_compute_peek_response_stash = false
  140. ----
  141. COMPLETE 0
  142. # Verify that max_query_result_size doesn't affect read part of RTW queries.
  143. # See database-issues#8099
  144. statement ok
  145. SET max_query_result_size = '8B';
  146. query error db error: ERROR: result exceeds max size of 8 B
  147. SELECT generate_series(1, 1000000)
  148. statement ok
  149. CREATE TABLE t_big (a int);
  150. # Slow in coverage
  151. statement ok
  152. SET statement_timeout = '120s'
  153. statement ok
  154. INSERT INTO t_big SELECT generate_series(1, 1000000)
  155. statement ok
  156. INSERT INTO t SELECT * FROM t_big
  157. # But the internal var does limit.
  158. simple conn=mz_system,user=mz_system
  159. ALTER SYSTEM SET max_result_size = '1MB'
  160. ----
  161. COMPLETE 0
  162. statement error db error: ERROR: result exceeds max size of 1048.6 KB
  163. INSERT INTO t SELECT * FROM t_big
  164. simple conn=mz_system,user=mz_system
  165. ALTER SYSTEM RESET enable_compute_peek_response_stash
  166. ----
  167. COMPLETE 0
  168. # Test unmat fns in the SET clause.
  169. statement ok
  170. CREATE TABLE dt (t TIMESTAMP)
  171. statement count 1
  172. INSERT INTO dt VALUES (now())
  173. statement count 1
  174. UPDATE dt SET t = now()
  175. statement error db error: ERROR: calls to mz_now in write statements are not supported
  176. UPDATE dt SET t = mz_now()