enable_eager_delta_joins.slt 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. # Test the ability to catch plan changes using the `enable eager delta joins`
  10. # config flag in EXPLAIN. This test can be deleted when the feature flag is
  11. # removed.
  12. mode cockroach
  13. simple conn=mz_system,user=mz_system
  14. ALTER SYSTEM SET enable_eager_delta_joins TO false;
  15. ----
  16. COMPLETE 0
  17. statement ok
  18. CREATE TABLE t1 (
  19. x int,
  20. y int
  21. );
  22. statement ok
  23. CREATE TABLE t2 (
  24. x int,
  25. y int
  26. );
  27. statement ok
  28. CREATE TABLE t3 (
  29. x int,
  30. y int
  31. );
  32. # Test materialized views
  33. # -----------------------
  34. # A query that will produce different plans depending on the value of the
  35. # `enable eager delta joins` feature flag.
  36. statement ok
  37. CREATE MATERIALIZED VIEW mv AS
  38. SELECT
  39. t1.y as c1,
  40. t2.y as c2,
  41. t3.y as c3
  42. FROM
  43. t1, t2, t3
  44. where
  45. t1.x = t2.x AND
  46. t2.y = t3.y;
  47. # EXPLAIN and EXPLAIN REPLAN should coincide.
  48. query T multiline
  49. EXPLAIN OPTIMIZED PLAN WITH(join implementations, humanized expressions) AS VERBOSE TEXT FOR
  50. MATERIALIZED VIEW mv;
  51. ----
  52. materialize.public.mv:
  53. Project (#1{y}, #3{y}, #3{y})
  54. Join on=(#0{x} = #2{x} AND #3{y} = #4{y}) type=differential
  55. implementation
  56. %0:t1[#0{x}]K » %1:t2[#0{x}]K » %2:t3[#0{y}]K
  57. ArrangeBy keys=[[#0{x}]]
  58. Filter (#0{x}) IS NOT NULL
  59. ReadStorage materialize.public.t1
  60. ArrangeBy keys=[[#0{x}]]
  61. Filter (#0{x}) IS NOT NULL AND (#1{y}) IS NOT NULL
  62. ReadStorage materialize.public.t2
  63. ArrangeBy keys=[[#0{y}]]
  64. Project (#1{y})
  65. Filter (#1{y}) IS NOT NULL
  66. ReadStorage materialize.public.t3
  67. Source materialize.public.t1
  68. filter=((#0{x}) IS NOT NULL)
  69. Source materialize.public.t2
  70. filter=((#0{x}) IS NOT NULL AND (#1{y}) IS NOT NULL)
  71. Source materialize.public.t3
  72. filter=((#1{y}) IS NOT NULL)
  73. Target cluster: quickstart
  74. EOF
  75. # EXPLAIN and EXPLAIN REPLAN should coincide.
  76. query T multiline
  77. EXPLAIN OPTIMIZED PLAN WITH(join implementations, humanized expressions) AS VERBOSE TEXT FOR
  78. REPLAN MATERIALIZED VIEW mv;
  79. ----
  80. materialize.public.mv:
  81. Project (#1{y}, #3{y}, #3{y})
  82. Join on=(#0{x} = #2{x} AND #3{y} = #4{y}) type=differential
  83. implementation
  84. %0:t1[#0{x}]K » %1:t2[#0{x}]K » %2:t3[#0{y}]K
  85. ArrangeBy keys=[[#0{x}]]
  86. Filter (#0{x}) IS NOT NULL
  87. ReadStorage materialize.public.t1
  88. ArrangeBy keys=[[#0{x}]]
  89. Filter (#0{x}) IS NOT NULL AND (#1{y}) IS NOT NULL
  90. ReadStorage materialize.public.t2
  91. ArrangeBy keys=[[#0{y}]]
  92. Project (#1{y})
  93. Filter (#1{y}) IS NOT NULL
  94. ReadStorage materialize.public.t3
  95. Source materialize.public.t1
  96. filter=((#0{x}) IS NOT NULL)
  97. Source materialize.public.t2
  98. filter=((#0{x}) IS NOT NULL AND (#1{y}) IS NOT NULL)
  99. Source materialize.public.t3
  100. filter=((#1{y}) IS NOT NULL)
  101. Target cluster: quickstart
  102. EOF
  103. # EXPLAIN REPLAN WITH(enable eager delta joins) should differ.
  104. query T multiline
  105. EXPLAIN OPTIMIZED PLAN WITH(join implementations, enable eager delta joins, humanized expressions) AS VERBOSE TEXT FOR
  106. REPLAN MATERIALIZED VIEW mv;
  107. ----
  108. materialize.public.mv:
  109. Project (#1{y}, #3{y}, #3{y})
  110. Join on=(#0{x} = #2{x} AND #3{y} = #4{y}) type=delta
  111. implementation
  112. %0:t1 » %1:t2[#0{x}]K » %2:t3[#0{y}]K
  113. %1:t2 » %0:t1[#0{x}]K » %2:t3[#0{y}]K
  114. %2:t3 » %1:t2[#1{y}]K » %0:t1[#0{x}]K
  115. ArrangeBy keys=[[#0{x}]]
  116. Filter (#0{x}) IS NOT NULL
  117. ReadStorage materialize.public.t1
  118. ArrangeBy keys=[[#0{x}], [#1{y}]]
  119. Filter (#0{x}) IS NOT NULL AND (#1{y}) IS NOT NULL
  120. ReadStorage materialize.public.t2
  121. ArrangeBy keys=[[#0{y}]]
  122. Project (#1{y})
  123. Filter (#1{y}) IS NOT NULL
  124. ReadStorage materialize.public.t3
  125. Source materialize.public.t1
  126. filter=((#0{x}) IS NOT NULL)
  127. Source materialize.public.t2
  128. filter=((#0{x}) IS NOT NULL AND (#1{y}) IS NOT NULL)
  129. Source materialize.public.t3
  130. filter=((#1{y}) IS NOT NULL)
  131. Target cluster: quickstart
  132. EOF
  133. # Test indexed views
  134. # ------------------
  135. # Same as above, but as an indexed view.
  136. statement ok
  137. CREATE VIEW v AS
  138. SELECT
  139. t1.y as c1,
  140. t2.y as c2,
  141. t3.y as c3
  142. FROM
  143. t1, t2, t3
  144. where
  145. t1.x = t2.x AND
  146. t2.y = t3.y;
  147. statement ok
  148. CREATE INDEX v_idx ON v(c1);
  149. # EXPLAIN and EXPLAIN REPLAN should coincide.
  150. query T multiline
  151. EXPLAIN OPTIMIZED PLAN WITH(join implementations, humanized expressions) AS VERBOSE TEXT FOR
  152. INDEX v_idx;
  153. ----
  154. materialize.public.v_idx:
  155. ArrangeBy keys=[[#0{c1}]]
  156. ReadGlobalFromSameDataflow materialize.public.v
  157. materialize.public.v:
  158. Project (#1{y}, #3{y}, #3{y})
  159. Join on=(#0{x} = #2{x} AND #3{y} = #4{y}) type=differential
  160. implementation
  161. %0:t1[#0{x}]K » %1:t2[#0{x}]K » %2:t3[#0{y}]K
  162. ArrangeBy keys=[[#0{x}]]
  163. Filter (#0{x}) IS NOT NULL
  164. ReadStorage materialize.public.t1
  165. ArrangeBy keys=[[#0{x}]]
  166. Filter (#0{x}) IS NOT NULL AND (#1{y}) IS NOT NULL
  167. ReadStorage materialize.public.t2
  168. ArrangeBy keys=[[#0{y}]]
  169. Project (#1{y})
  170. Filter (#1{y}) IS NOT NULL
  171. ReadStorage materialize.public.t3
  172. Source materialize.public.t1
  173. filter=((#0{x}) IS NOT NULL)
  174. Source materialize.public.t2
  175. filter=((#0{x}) IS NOT NULL AND (#1{y}) IS NOT NULL)
  176. Source materialize.public.t3
  177. filter=((#1{y}) IS NOT NULL)
  178. Target cluster: quickstart
  179. EOF
  180. # EXPLAIN and EXPLAIN REPLAN should coincide.
  181. query T multiline
  182. EXPLAIN OPTIMIZED PLAN WITH(join implementations, humanized expressions) AS VERBOSE TEXT FOR
  183. REPLAN INDEX v_idx;
  184. ----
  185. materialize.public.v_idx:
  186. ArrangeBy keys=[[#0{c1}]]
  187. ReadGlobalFromSameDataflow materialize.public.v
  188. materialize.public.v:
  189. Project (#1{y}, #3{y}, #3{y})
  190. Join on=(#0{x} = #2{x} AND #3{y} = #4{y}) type=differential
  191. implementation
  192. %0:t1[#0{x}]K » %1:t2[#0{x}]K » %2:t3[#0{y}]K
  193. ArrangeBy keys=[[#0{x}]]
  194. Filter (#0{x}) IS NOT NULL
  195. ReadStorage materialize.public.t1
  196. ArrangeBy keys=[[#0{x}]]
  197. Filter (#0{x}) IS NOT NULL AND (#1{y}) IS NOT NULL
  198. ReadStorage materialize.public.t2
  199. ArrangeBy keys=[[#0{y}]]
  200. Project (#1{y})
  201. Filter (#1{y}) IS NOT NULL
  202. ReadStorage materialize.public.t3
  203. Source materialize.public.t1
  204. filter=((#0{x}) IS NOT NULL)
  205. Source materialize.public.t2
  206. filter=((#0{x}) IS NOT NULL AND (#1{y}) IS NOT NULL)
  207. Source materialize.public.t3
  208. filter=((#1{y}) IS NOT NULL)
  209. Target cluster: quickstart
  210. EOF
  211. # EXPLAIN REPLAN WITH(enable eager delta joins) should differ.
  212. query T multiline
  213. EXPLAIN OPTIMIZED PLAN WITH(join implementations, enable eager delta joins, humanized expressions) AS VERBOSE TEXT FOR
  214. REPLAN INDEX v_idx;
  215. ----
  216. materialize.public.v_idx:
  217. ArrangeBy keys=[[#0{c1}]]
  218. ReadGlobalFromSameDataflow materialize.public.v
  219. materialize.public.v:
  220. Project (#1{y}, #3{y}, #3{y})
  221. Join on=(#0{x} = #2{x} AND #3{y} = #4{y}) type=delta
  222. implementation
  223. %0:t1 » %1:t2[#0{x}]K » %2:t3[#0{y}]K
  224. %1:t2 » %0:t1[#0{x}]K » %2:t3[#0{y}]K
  225. %2:t3 » %1:t2[#1{y}]K » %0:t1[#0{x}]K
  226. ArrangeBy keys=[[#0{x}]]
  227. Filter (#0{x}) IS NOT NULL
  228. ReadStorage materialize.public.t1
  229. ArrangeBy keys=[[#0{x}], [#1{y}]]
  230. Filter (#0{x}) IS NOT NULL AND (#1{y}) IS NOT NULL
  231. ReadStorage materialize.public.t2
  232. ArrangeBy keys=[[#0{y}]]
  233. Project (#1{y})
  234. Filter (#1{y}) IS NOT NULL
  235. ReadStorage materialize.public.t3
  236. Source materialize.public.t1
  237. filter=((#0{x}) IS NOT NULL)
  238. Source materialize.public.t2
  239. filter=((#0{x}) IS NOT NULL AND (#1{y}) IS NOT NULL)
  240. Source materialize.public.t3
  241. filter=((#1{y}) IS NOT NULL)
  242. Target cluster: quickstart
  243. EOF