timedomain.slt 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. mode cockroach
  10. # This is to make the id in the EXPLAIN SHOW VIEWS test stable.
  11. reset-server
  12. statement ok
  13. CREATE TABLE t (i INT);
  14. # Transactions that don't start with sources or mz_now can later include sources.
  15. simple
  16. BEGIN;
  17. SELECT row(1, 2);
  18. SELECT 1 FROM mz_types LIMIT 1;
  19. SELECT 3 FROM pg_type LIMIT 1; -- mz_catalog and pg_catalog should be treated as the same schema
  20. ----
  21. COMPLETE 0
  22. (1,2)
  23. COMPLETE 1
  24. 1
  25. COMPLETE 1
  26. 3
  27. COMPLETE 1
  28. # But we can only change timedomains once.
  29. query error Transactions can only reference objects in the same timedomain.
  30. SELECT * FROM t
  31. # Referring to the timestamp prevents including sources later.
  32. simple
  33. ROLLBACK;
  34. BEGIN;
  35. SELECT mz_now() LIMIT 0;
  36. ----
  37. COMPLETE 0
  38. COMPLETE 0
  39. COMPLETE 0
  40. query error Transactions can only reference objects in the same timedomain.
  41. SELECT 1 FROM mz_types LIMIT 1
  42. simple
  43. ROLLBACK;
  44. BEGIN;
  45. SELECT 1 FROM mz_types LIMIT 1;
  46. -- Use a timestamp-independent statement here, which should not allow
  47. -- the timedomain to change because the transaction's previous statement
  48. -- established a timedomain.
  49. SELECT 2;
  50. ----
  51. COMPLETE 0
  52. COMPLETE 0
  53. 1
  54. COMPLETE 1
  55. 2
  56. COMPLETE 1
  57. query error db error: ERROR: querying the following items "materialize\.public\.t" is not allowed from the "mz_catalog_server" cluster
  58. SELECT * FROM t;
  59. statement ok
  60. ROLLBACK
  61. # Test that user table and mz_catalog system tables cannot be mixed in a transaction because they
  62. # belong to different timedomains.
  63. statement ok
  64. BEGIN;
  65. query I rowsort
  66. SELECT * FROM t
  67. ----
  68. # This may stop failing in the future if a view in pg_catalog starts to depend on this. In that case
  69. # just change this query to select from an object that isn't referenced from pg_catalog.
  70. query error Transactions can only reference objects in the same timedomain.
  71. SELECT * FROM mz_internal.mz_show_default_privileges
  72. statement ok
  73. ROLLBACK
  74. # Test that timeline dependent queries can be included in transaction.
  75. statement ok
  76. BEGIN
  77. query I rowsort
  78. SELECT * FROM t
  79. ----
  80. query I rowsort
  81. SELECT mz_now() LIMIT 0
  82. ----
  83. statement ok
  84. COMMIT
  85. # Test that timeline independent queries can be included at the end transaction.
  86. statement ok
  87. BEGIN
  88. query I rowsort
  89. SELECT 1 FROM pg_attribute LIMIT 1
  90. ----
  91. 1
  92. query I rowsort
  93. SELECT 1 FROM pg_catalog.pg_am LIMIT 1
  94. ----
  95. statement ok
  96. COMMIT
  97. # Test that timeline independent queries can be included at the start transaction.
  98. statement ok
  99. BEGIN
  100. query I rowsort
  101. SELECT 1 FROM pg_catalog.pg_am LIMIT 1
  102. ----
  103. query I rowsort
  104. SELECT 1 FROM pg_attribute LIMIT 1
  105. ----
  106. 1
  107. statement ok
  108. COMMIT
  109. statement ok
  110. CREATE VIEW v AS SELECT 1
  111. statement ok
  112. BEGIN
  113. query I rowsort
  114. SELECT 1 FROM v LIMIT 1
  115. ----
  116. 1
  117. query I rowsort
  118. SELECT 1 FROM t LIMIT 1
  119. ----
  120. statement ok
  121. COMMIT
  122. statement ok
  123. BEGIN
  124. query I rowsort
  125. SELECT 1
  126. ----
  127. 1
  128. query I rowsort
  129. SELECT 1 FROM pg_attribute LIMIT 1
  130. ----
  131. 1
  132. statement ok
  133. COMMIT
  134. # Verify that system tables are always included in read txns, even if not
  135. # mentioned in the first query.
  136. simple
  137. BEGIN;
  138. SELECT * FROM t;
  139. SELECT n.nspname = ANY(current_schemas(true)), n.nspname, t.typname FROM pg_catalog.pg_type t JOIN pg_catalog.pg_namespace n ON t.typnamespace = n.oid WHERE t.oid = 2249;
  140. COMMIT;
  141. ----
  142. COMPLETE 0
  143. COMPLETE 0
  144. t,pg_catalog,record
  145. COMPLETE 1
  146. COMPLETE 0
  147. simple
  148. BEGIN;
  149. SELECT row(1, 2);
  150. SELECT n.nspname = ANY(current_schemas(true)), n.nspname, t.typname FROM pg_catalog.pg_type t JOIN pg_catalog.pg_namespace n ON t.typnamespace = n.oid WHERE t.oid = 2249;
  151. COMMIT;
  152. ----
  153. COMPLETE 0
  154. (1,2)
  155. COMPLETE 1
  156. t,pg_catalog,record
  157. COMPLETE 1
  158. COMPLETE 0
  159. # Test that queries aren't auto-routed to mz_catalog_server mid-transaction.
  160. statement ok
  161. BEGIN
  162. query I
  163. SELECT * FROM t
  164. ----
  165. query T multiline
  166. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR SHOW VIEWS
  167. ----
  168. Explained Query:
  169. With
  170. cte l0 =
  171. Project (#0{id}..=#2{name}, #4{comment})
  172. Join on=(#0{id} = #3{id}) type=differential
  173. ArrangeBy keys=[[#0{id}]]
  174. Project (#0{id}, #2{schema_id}, #3{name})
  175. ReadStorage mz_catalog.mz_views
  176. ArrangeBy keys=[[#0{id}]]
  177. Project (#0{id}, #3{comment})
  178. Filter (#2{object_sub_id}) IS NULL AND (#1{object_type} = "view")
  179. ReadStorage mz_internal.mz_comments
  180. cte l1 =
  181. Project (#0{id}, #3{name})
  182. Filter (#2{schema_id} = "u3")
  183. ReadStorage mz_catalog.mz_views
  184. Return
  185. Project (#0{name}, #2)
  186. Map (coalesce(#1{comment}, ""))
  187. Union
  188. Map (null)
  189. Union
  190. Negate
  191. Project (#1{name})
  192. Join on=(#0{id} = #2{id}) type=differential
  193. ArrangeBy keys=[[#0{id}]]
  194. Get l1
  195. ArrangeBy keys=[[#0{id}]]
  196. Distinct project=[#0{id}]
  197. Project (#0{id})
  198. Get l0
  199. Project (#1{name})
  200. Get l1
  201. Project (#2{name}, #3{comment})
  202. Filter (#1{schema_id} = "u3")
  203. Get l0
  204. Source mz_catalog.mz_views
  205. Source mz_internal.mz_comments
  206. filter=((#1{object_type} = "view") AND (#2{object_sub_id}) IS NULL)
  207. Target cluster: quickstart
  208. EOF
  209. statement ok
  210. COMMIT