select_index_flags.slt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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/select_index_flags
  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 abcd (
  24. a INT PRIMARY KEY,
  25. b INT,
  26. c INT,
  27. d INT,
  28. INDEX b (b),
  29. INDEX cd (c,d),
  30. UNIQUE INDEX bcd (b,c,d)
  31. )
  32. statement ok
  33. INSERT INTO abcd VALUES (10, 11, 12, 13), (20, 21, 22, 23), (30, 31, 32, 33), (40, 41, 42, 43)
  34. # No hint
  35. query IIII rowsort
  36. SELECT * FROM abcd WHERE a >= 20 AND a <= 30
  37. ----
  38. 20 21 22 23
  39. 30 31 32 33
  40. # Force primary
  41. query IIII rowsort
  42. SELECT * FROM abcd@primary WHERE a >= 20 AND a <= 30
  43. ----
  44. 20 21 22 23
  45. 30 31 32 33
  46. # Force primary, reverse scan.
  47. query IIII rowsort
  48. SELECT * FROM abcd@{FORCE_INDEX=primary,DESC} WHERE a >= 20 AND a <= 30
  49. ----
  50. 20 21 22 23
  51. 30 31 32 33
  52. # Force index b
  53. query IIII rowsort
  54. SELECT * FROM abcd@b WHERE a >= 20 AND a <= 30
  55. ----
  56. 20 21 22 23
  57. 30 31 32 33
  58. # Force index b, reverse scan.
  59. query IIII rowsort
  60. SELECT * FROM abcd@{FORCE_INDEX=b,DESC} WHERE a >= 20 AND a <= 30
  61. ----
  62. 20 21 22 23
  63. 30 31 32 33
  64. # Force index cd
  65. query IIII rowsort
  66. SELECT * FROM abcd@cd WHERE a >= 20 AND a <= 30
  67. ----
  68. 20 21 22 23
  69. 30 31 32 33
  70. # Force index bcd
  71. query IIII rowsort
  72. SELECT * FROM abcd@bcd WHERE a >= 20 AND a <= 30
  73. ----
  74. 20 21 22 23
  75. 30 31 32 33
  76. # Force index b (covering)
  77. query I rowsort
  78. SELECT b FROM abcd@b WHERE a >= 20 AND a <= 30
  79. ----
  80. 21
  81. 31
  82. # Force index b (non-covering due to WHERE clause)
  83. query I rowsort
  84. SELECT b FROM abcd@b WHERE c >= 20 AND c <= 30
  85. ----
  86. 21
  87. # No hint, should be using index cd
  88. query II rowsort
  89. SELECT c, d FROM abcd WHERE c >= 20 AND c < 40
  90. ----
  91. 22 23
  92. 32 33
  93. # Force primary index
  94. query II rowsort
  95. SELECT c, d FROM abcd@primary WHERE c >= 20 AND c < 40
  96. ----
  97. 22 23
  98. 32 33
  99. # Force index b
  100. query II rowsort
  101. SELECT c, d FROM abcd@b WHERE c >= 20 AND c < 40
  102. ----
  103. 22 23
  104. 32 33
  105. query error index \"badidx\" not found
  106. SELECT * FROM abcd@badidx
  107. query error index \"badidx\" not found
  108. SELECT * FROM abcd@{FORCE_INDEX=badidx}