collatedstring_index1.slt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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/collatedstring_index1
  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. ##
  23. # Test a primary key with a collated string in first position (can get a key range).
  24. #
  25. # Danish collation chart: http://www.unicode.org/cldr/charts/30/collation/da.html
  26. statement ok
  27. CREATE TABLE t (
  28. a STRING COLLATE da,
  29. b INT,
  30. c BOOL,
  31. PRIMARY KEY (a, b)
  32. )
  33. statement ok
  34. INSERT INTO t VALUES
  35. ('A' COLLATE da, 1, TRUE),
  36. ('A' COLLATE da, 2, NULL),
  37. ('a' COLLATE da, 2, FALSE),
  38. ('a' COLLATE da, 3, TRUE),
  39. ('B' COLLATE da, 3, NULL),
  40. ('b' COLLATE da, 4, FALSE),
  41. ('ü' COLLATE da, 6, TRUE),
  42. ('ü' COLLATE da, 5, NULL),
  43. ('x' COLLATE da, 5, FALSE)
  44. query TI
  45. SELECT a, b FROM t ORDER BY a, b
  46. ----
  47. a 2
  48. a 3
  49. A 1
  50. A 2
  51. b 4
  52. B 3
  53. x 5
  54. ü 5
  55. ü 6
  56. query IT
  57. SELECT b, a FROM t ORDER BY b, a
  58. ----
  59. 1 A
  60. 2 a
  61. 2 A
  62. 3 a
  63. 3 B
  64. 4 b
  65. 5 x
  66. 5 ü
  67. 6 ü
  68. query I
  69. SELECT COUNT (a) FROM t WHERE a = ('a' COLLATE da)
  70. ----
  71. 2
  72. query I
  73. SELECT COUNT (a) FROM t WHERE a = ('y' COLLATE da)
  74. ----
  75. 0
  76. query I
  77. SELECT COUNT (a) FROM t WHERE a > ('a' COLLATE da) AND a < ('c' COLLATE da)
  78. ----
  79. 4
  80. # Create an index and try again.
  81. statement ok
  82. CREATE INDEX ON t (b, a) STORING (c)
  83. query TI
  84. SELECT a, b FROM t ORDER BY a, b
  85. ----
  86. a 2
  87. a 3
  88. A 1
  89. A 2
  90. b 4
  91. B 3
  92. x 5
  93. ü 5
  94. ü 6
  95. query IT
  96. SELECT b, a FROM t ORDER BY b, a
  97. ----
  98. 1 A
  99. 2 a
  100. 2 A
  101. 3 a
  102. 3 B
  103. 4 b
  104. 5 x
  105. 5 ü
  106. 6 ü
  107. query I
  108. SELECT COUNT (a) FROM t WHERE a = ('a' COLLATE da)
  109. ----
  110. 2
  111. query I
  112. SELECT COUNT (a) FROM t WHERE a = ('y' COLLATE da)
  113. ----
  114. 0
  115. query I
  116. SELECT COUNT (a) FROM t WHERE a > ('a' COLLATE da) AND a < ('c' COLLATE da)
  117. ----
  118. 4
  119. # Update and try again.
  120. statement ok
  121. UPDATE t SET a = (a :: STRING || a :: STRING) COLLATE da
  122. query TI
  123. SELECT a, b FROM t ORDER BY a, b
  124. ----
  125. bb 4
  126. BB 3
  127. xx 5
  128. üü 5
  129. üü 6
  130. aa 2
  131. aa 3
  132. AA 1
  133. AA 2
  134. query IT
  135. SELECT b, a FROM t ORDER BY b, a
  136. ----
  137. 1 AA
  138. 2 aa
  139. 2 AA
  140. 3 BB
  141. 3 aa
  142. 4 bb
  143. 5 xx
  144. 5 üü
  145. 6 üü
  146. # Delete and try again
  147. statement ok
  148. DELETE FROM t WHERE a > ('a' COLLATE da) AND a < ('c' COLLATE da)
  149. query TI
  150. SELECT a, b FROM t ORDER BY a, b
  151. ----
  152. xx 5
  153. üü 5
  154. üü 6
  155. aa 2
  156. aa 3
  157. AA 1
  158. AA 2
  159. query IT
  160. SELECT b, a FROM t ORDER BY b, a
  161. ----
  162. 1 AA
  163. 2 aa
  164. 2 AA
  165. 3 aa
  166. 5 xx
  167. 5 üü
  168. 6 üü