index_already_exists.slt 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. simple conn=mz_system,user=mz_system
  10. ALTER SYSTEM SET unsafe_enable_table_keys TO true
  11. ----
  12. COMPLETE 0
  13. simple conn=mz_system,user=mz_system
  14. ALTER SYSTEM SET enable_mz_notices TO true
  15. ----
  16. COMPLETE 0
  17. # Disable rbac checks in order to select from mz_notices.
  18. simple conn=mz_system,user=mz_system
  19. ALTER SYSTEM SET enable_rbac_checks TO false
  20. ----
  21. COMPLETE 0
  22. statement ok
  23. CREATE SCHEMA notices;
  24. statement ok
  25. SET SCHEMA = notices;
  26. statement ok
  27. CREATE TABLE t (
  28. a int,
  29. b int
  30. );
  31. # Create an index on t(a + 7).
  32. statement ok
  33. CREATE INDEX t_idx1 ON t(a + 7);
  34. # EXPLAIN CREATE INDEX for an identical index that emits the optimizer notice.
  35. query T multiline
  36. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR CREATE INDEX t_idx2 ON t(a + 7);
  37. ----
  38. materialize.notices.t_idx2:
  39. ArrangeBy keys=[[(#0{a} + 7)]]
  40. ReadIndex on=t t_idx1=[plan root (no new arrangement)]
  41. Used Indexes:
  42. - materialize.notices.t_idx1 (plan root (no new arrangement), index export)
  43. Target cluster: quickstart
  44. Notices:
  45. - Notice: Index materialize.notices.t_idx2 is identical to materialize.notices.t_idx1, which is also defined on t((a + 7)).
  46. Hint: Please drop all indexes except the first index created on t((a + 7)) and recreate all dependent objects.
  47. EOF
  48. # CREATE INDEX for an identical index that emits the optimizer notice.
  49. statement ok
  50. CREATE INDEX t_idx2 ON t(a + 7);
  51. # Verify that the notice is shown in EXPLAIN.
  52. query T multiline
  53. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR INDEX t_idx2;
  54. ----
  55. materialize.notices.t_idx2:
  56. ArrangeBy keys=[[(#0{a} + 7)]]
  57. ReadIndex on=t t_idx1=[plan root (no new arrangement)]
  58. Used Indexes:
  59. - materialize.notices.t_idx1 (plan root (no new arrangement), index export)
  60. Target cluster: quickstart
  61. Notices:
  62. - Notice: Index materialize.notices.t_idx2 is identical to materialize.notices.t_idx1, which is also defined on t((a + 7)).
  63. Hint: Please drop all indexes except the first index created on t((a + 7)) and recreate all dependent objects.
  64. EOF
  65. # Verify that the same notice can be found in the catalog.
  66. query TTTTTTTT
  67. SELECT
  68. n.notice_type, n.message, n.redacted_message, n.hint, n.redacted_hint, n.action, n.redacted_action, n.action_type
  69. FROM
  70. mz_internal.mz_notices n JOIN
  71. mz_catalog.mz_indexes idx ON(n.object_id = idx.id)
  72. WHERE
  73. idx.name LIKE 't_idx%'
  74. ----
  75. An identical index already exists
  76. Index materialize.notices.t_idx2 is identical to materialize.notices.t_idx1, which is also defined on t((a + 7)).
  77. Index materialize.notices.t_idx2 is identical to materialize.notices.t_idx1, which is also defined on t((a + █)).
  78. Please drop all indexes except the first index created on t((a + 7)) and recreate all dependent objects.
  79. Please drop all indexes except the first index created on t((a + █)) and recreate all dependent objects.
  80. NULL
  81. NULL
  82. NULL
  83. # Drop the catalog item associated with the notice.
  84. statement ok
  85. DROP INDEX t_idx2;
  86. # Verify that the notice is no longer in the catalog.
  87. query TTTTTTTT
  88. SELECT
  89. n.notice_type, n.message, n.redacted_message, n.hint, n.redacted_hint, n.action, n.redacted_action, n.action_type
  90. FROM
  91. mz_internal.mz_notices n JOIN
  92. mz_catalog.mz_indexes idx ON(n.object_id = idx.id)
  93. ----
  94. # CREATE INDEX for an identical index that emits the optimizer notice.
  95. statement ok
  96. CREATE INDEX t_idx3 ON t(a + 7);
  97. # Verify that the notice is shown in EXPLAIN.
  98. query T multiline
  99. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR INDEX t_idx3;
  100. ----
  101. materialize.notices.t_idx3:
  102. ArrangeBy keys=[[(#0{a} + 7)]]
  103. ReadIndex on=t t_idx1=[plan root (no new arrangement)]
  104. Used Indexes:
  105. - materialize.notices.t_idx1 (plan root (no new arrangement), index export)
  106. Target cluster: quickstart
  107. Notices:
  108. - Notice: Index materialize.notices.t_idx3 is identical to materialize.notices.t_idx1, which is also defined on t((a + 7)).
  109. Hint: Please drop all indexes except the first index created on t((a + 7)) and recreate all dependent objects.
  110. EOF
  111. # Verify that the same notice can be found in the catalog.
  112. query TTTTTTTT
  113. SELECT
  114. n.notice_type, n.message, n.redacted_message, n.hint, n.redacted_hint, n.action, n.redacted_action, n.action_type
  115. FROM
  116. mz_internal.mz_notices n JOIN
  117. mz_catalog.mz_indexes idx ON(n.object_id = idx.id)
  118. WHERE
  119. idx.name = 't_idx3'
  120. ----
  121. An identical index already exists
  122. Index materialize.notices.t_idx3 is identical to materialize.notices.t_idx1, which is also defined on t((a + 7)).
  123. Index materialize.notices.t_idx3 is identical to materialize.notices.t_idx1, which is also defined on t((a + █)).
  124. Please drop all indexes except the first index created on t((a + 7)) and recreate all dependent objects.
  125. Please drop all indexes except the first index created on t((a + █)) and recreate all dependent objects.
  126. NULL
  127. NULL
  128. NULL
  129. # Drop the catalog item associated with the notice.
  130. statement ok
  131. DROP INDEX t_idx1;
  132. # Verify that the notice is no longer shown in EXPLAIN.
  133. query T multiline
  134. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR INDEX t_idx3;
  135. ----
  136. materialize.notices.t_idx3:
  137. ArrangeBy keys=[[(#0{a} + 7)]]
  138. ReadIndex on=t [DELETED INDEX]=[plan root (no new arrangement)]
  139. Used Indexes:
  140. - [DELETED INDEX] (plan root (no new arrangement), index export)
  141. Target cluster: quickstart
  142. EOF
  143. # Verify that the notice is no longer in the catalog.
  144. query TTTTTTTT
  145. SELECT
  146. n.notice_type, n.message, n.redacted_message, n.hint, n.redacted_hint, n.action, n.redacted_action, n.action_type
  147. FROM
  148. mz_internal.mz_notices n JOIN
  149. mz_catalog.mz_indexes idx ON(n.object_id = idx.id)
  150. WHERE
  151. idx.name = 't_idx3'
  152. ----
  153. # This further tests `drop_plans_and_metainfos`
  154. statement ok
  155. DROP SCHEMA notices CASCADE;