replan_catalog_items.slt 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. statement ok
  11. CREATE TABLE t1 (
  12. x int,
  13. y int
  14. );
  15. statement ok
  16. CREATE TABLE t2 (
  17. y int,
  18. z int
  19. );
  20. statement ok
  21. CREATE VIEW v AS SELECT x, sum(z) FROM t1 JOIN t2 USING(y) GROUP BY x
  22. statement ok
  23. CREATE MATERIALIZED VIEW mv AS SELECT x, sum(z) FROM t1 JOIN t2 USING(y) GROUP BY x
  24. statement ok
  25. CREATE INDEX ON t1(y);
  26. # EXPLAIN and EXPLAIN REPLAN should coincide.
  27. query T multiline
  28. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR
  29. MATERIALIZED VIEW mv;
  30. ----
  31. materialize.public.mv:
  32. Reduce group_by=[#0{x}] aggregates=[sum(#1{z})]
  33. Project (#0{x}, #3{z})
  34. Join on=(#1{y} = #2{y}) type=differential
  35. ArrangeBy keys=[[#1{y}]]
  36. Filter (#1{y}) IS NOT NULL
  37. ReadStorage materialize.public.t1
  38. ArrangeBy keys=[[#0{y}]]
  39. Filter (#0{y}) IS NOT NULL
  40. ReadStorage materialize.public.t2
  41. Source materialize.public.t1
  42. filter=((#1{y}) IS NOT NULL)
  43. Source materialize.public.t2
  44. filter=((#0{y}) IS NOT NULL)
  45. Target cluster: quickstart
  46. EOF
  47. # EXPLAIN and EXPLAIN REPLAN should coincide.
  48. query T multiline
  49. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR
  50. REPLAN MATERIALIZED VIEW mv;
  51. ----
  52. materialize.public.mv:
  53. Reduce group_by=[#0{x}] aggregates=[sum(#1{z})]
  54. Project (#0{x}, #3{z})
  55. Join on=(#1{y} = #2{y}) type=differential
  56. ArrangeBy keys=[[#1{y}]]
  57. Filter (#1{y}) IS NOT NULL
  58. ReadStorage materialize.public.t1
  59. ArrangeBy keys=[[#0{y}]]
  60. Filter (#0{y}) IS NOT NULL
  61. ReadStorage materialize.public.t2
  62. Source materialize.public.t1
  63. filter=((#1{y}) IS NOT NULL)
  64. Source materialize.public.t2
  65. filter=((#0{y}) IS NOT NULL)
  66. Target cluster: quickstart
  67. EOF
  68. # EXPLAIN CREATE should differ from the above two.
  69. query T multiline
  70. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR
  71. CREATE MATERIALIZED VIEW mv AS SELECT x, sum(z) FROM t1 JOIN t2 USING(y) GROUP BY x;
  72. ----
  73. materialize.public.mv:
  74. Reduce group_by=[#0{x}] aggregates=[sum(#1{z})]
  75. Project (#0{x}, #3{z})
  76. Join on=(#1{y} = #2{y}) type=differential
  77. ArrangeBy keys=[[#1{y}]]
  78. ReadIndex on=t1 t1_y_idx=[differential join]
  79. ArrangeBy keys=[[#0{y}]]
  80. Filter (#0{y}) IS NOT NULL
  81. ReadStorage materialize.public.t2
  82. Source materialize.public.t2
  83. filter=((#0{y}) IS NOT NULL)
  84. Used Indexes:
  85. - materialize.public.t1_y_idx (differential join)
  86. Target cluster: quickstart
  87. EOF
  88. statement ok
  89. CREATE INDEX v_idx ON v(x);
  90. # EXPLAIN and EXPLAIN REPLAN should coincide.
  91. query T multiline
  92. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR
  93. INDEX v_idx;
  94. ----
  95. materialize.public.v_idx:
  96. ArrangeBy keys=[[#0{x}]]
  97. ReadGlobalFromSameDataflow materialize.public.v
  98. materialize.public.v:
  99. Reduce group_by=[#0{x}] aggregates=[sum(#1{z})]
  100. Project (#0{x}, #3{z})
  101. Join on=(#1{y} = #2{y}) type=differential
  102. ArrangeBy keys=[[#1{y}]]
  103. ReadIndex on=t1 t1_y_idx=[differential join]
  104. ArrangeBy keys=[[#0{y}]]
  105. Filter (#0{y}) IS NOT NULL
  106. ReadStorage materialize.public.t2
  107. Source materialize.public.t2
  108. filter=((#0{y}) IS NOT NULL)
  109. Used Indexes:
  110. - materialize.public.t1_y_idx (differential join)
  111. Target cluster: quickstart
  112. EOF
  113. # EXPLAIN and EXPLAIN REPLAN should coincide.
  114. query T multiline
  115. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR
  116. REPLAN INDEX v_idx;
  117. ----
  118. materialize.public.v_idx:
  119. ArrangeBy keys=[[#0{x}]]
  120. ReadGlobalFromSameDataflow materialize.public.v
  121. materialize.public.v:
  122. Reduce group_by=[#0{x}] aggregates=[sum(#1{z})]
  123. Project (#0{x}, #3{z})
  124. Join on=(#1{y} = #2{y}) type=differential
  125. ArrangeBy keys=[[#1{y}]]
  126. ReadIndex on=t1 t1_y_idx=[differential join]
  127. ArrangeBy keys=[[#0{y}]]
  128. Filter (#0{y}) IS NOT NULL
  129. ReadStorage materialize.public.t2
  130. Source materialize.public.t2
  131. filter=((#0{y}) IS NOT NULL)
  132. Used Indexes:
  133. - materialize.public.t1_y_idx (differential join)
  134. Target cluster: quickstart
  135. EOF
  136. # EXPLAIN CREATE should differ from the above two.
  137. query T multiline
  138. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR
  139. CREATE INDEX ON v(x);
  140. ----
  141. materialize.public.v_x_idx:
  142. ArrangeBy keys=[[#0{x}]]
  143. ReadIndex on=v v_idx=[plan root (no new arrangement)]
  144. Used Indexes:
  145. - materialize.public.v_idx (plan root (no new arrangement), index export)
  146. Target cluster: quickstart
  147. Notices:
  148. - Notice: Index materialize.public.v_x_idx is identical to materialize.public.v_idx, which is also defined on v(x).
  149. Hint: Please drop all indexes except the first index created on v(x) and recreate all dependent objects.
  150. EOF