truncate.slt 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. # Copyright 2015 - 2019 The Cockroach Authors. All rights reserved.
  2. # Copyright Materialize, Inc. and contributors. All rights reserved.
  3. #
  4. # Use of this software is governed by the Business Source License
  5. # included in the LICENSE file at the root of this repository.
  6. #
  7. # As of the Change Date specified in that file, in accordance with
  8. # the Business Source License, use of this software will be governed
  9. # by the Apache License, Version 2.0.
  10. #
  11. # This file is derived from the logic test suite in CockroachDB. The
  12. # original file was retrieved on June 10, 2019 from:
  13. #
  14. # https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/truncate
  15. #
  16. # The original source code is subject to the terms of the Apache
  17. # 2.0 license, a copy of which can be found in the LICENSE file at the
  18. # root of this repository.
  19. # not supported yet
  20. halt
  21. mode cockroach
  22. statement ok
  23. CREATE TABLE kv (
  24. k INT PRIMARY KEY,
  25. v INT
  26. )
  27. statement ok
  28. INSERT INTO kv VALUES (1, 2), (3, 4), (5, 6), (7, 8)
  29. query II rowsort
  30. SELECT * FROM kv
  31. ----
  32. 1 2
  33. 3 4
  34. 5 6
  35. 7 8
  36. statement ok
  37. CREATE VIEW kview AS SELECT k,v FROM kv
  38. query II rowsort
  39. SELECT * FROM kview
  40. ----
  41. 1 2
  42. 3 4
  43. 5 6
  44. 7 8
  45. statement error "kview" is not a table
  46. TRUNCATE TABLE kview
  47. query II rowsort
  48. SELECT * FROM kview
  49. ----
  50. 1 2
  51. 3 4
  52. 5 6
  53. 7 8
  54. statement ok
  55. TRUNCATE TABLE kv
  56. query II
  57. SELECT * FROM kv
  58. ----
  59. query II
  60. SELECT * FROM kview
  61. ----
  62. query TT
  63. SELECT status, running_status FROM [SHOW JOBS] WHERE job_type = 'SCHEMA CHANGE'
  64. ----
  65. running waiting for GC TTL
  66. # Ensure that TRUNCATE works with a self referential FK.
  67. statement ok
  68. CREATE TABLE selfref (
  69. y INT PRIMARY KEY,
  70. Z INT REFERENCES selfref (y)
  71. )
  72. statement ok
  73. TRUNCATE table selfref
  74. statement ok
  75. INSERT INTO selfref VALUES (1, NULL);
  76. statement ok
  77. DROP TABLE selfref
  78. subtest truncate_interleave
  79. statement ok
  80. CREATE TABLE a (a INT PRIMARY KEY)
  81. statement ok
  82. CREATE TABLE b (a INT, b INT, PRIMARY KEY (a, b), UNIQUE INDEX(b)) INTERLEAVE IN PARENT a(a)
  83. statement error "a" is interleaved by table "b"
  84. TRUNCATE a
  85. statement ok
  86. TRUNCATE a CASCADE
  87. statement ok
  88. TRUNCATE b
  89. statement ok
  90. TRUNCATE b CASCADE
  91. statement ok
  92. CREATE TABLE c (c INT PRIMARY KEY, d INT REFERENCES b(b))
  93. statement error "b" is referenced by foreign key from table "c"
  94. TRUNCATE a, b
  95. statement ok
  96. INSERT INTO b VALUES(1, 2)
  97. statement ok
  98. INSERT INTO c VALUES(1, 2)
  99. statement ok
  100. TRUNCATE a CASCADE
  101. query II
  102. SELECT * FROM c
  103. ----
  104. statement ok
  105. CREATE TABLE d (c INT PRIMARY KEY) INTERLEAVE IN PARENT c(c);
  106. statement ok
  107. TRUNCATE a, b, c, d
  108. statement error "c" is interleaved by table "d"
  109. TRUNCATE a, b, c
  110. statement error "c" is interleaved by table "d"
  111. TRUNCATE a, b, c
  112. statement ok
  113. INSERT INTO b VALUES(1, 2)
  114. statement ok
  115. INSERT INTO c VALUES(1, 2)
  116. statement ok
  117. INSERT INTO d VALUES (1)
  118. statement ok
  119. TRUNCATE a CASCADE
  120. query I
  121. SELECT * FROM d
  122. ----
  123. subtest truncate_29010
  124. statement ok
  125. CREATE SEQUENCE foo;
  126. statement ok
  127. CREATE TABLE bar (
  128. id INT NOT NULL DEFAULT nextval('foo':::STRING),
  129. description STRING NULL,
  130. CONSTRAINT "primary" PRIMARY KEY (id ASC),
  131. FAMILY "primary" (id, description)
  132. );
  133. statement ok
  134. TRUNCATE bar
  135. statement ok
  136. DROP TABLE bar;
  137. subtest truncate_30547
  138. statement ok
  139. CREATE TABLE tt AS SELECT 'foo'
  140. query TTT
  141. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR TRUNCATE TABLE tt
  142. ----
  143. truncate · ·
  144. # Verify that EXPLAIN did not cause the truncate to be performed.
  145. query T
  146. SELECT * FROM tt
  147. ----
  148. foo