like.slt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. # We have some tests also in cockroach/like.slt, but those go through const folding. The below tests avoid const folding.
  11. # Run all tests on a multi-process cluster, because there were some serialization issues in the past that happened
  12. # only on multi-process clusters.
  13. statement ok
  14. CREATE CLUSTER multiprocess REPLICAS (a (SIZE '2-2'));
  15. statement ok
  16. SET cluster = 'multiprocess';
  17. statement ok
  18. CREATE TABLE t(s string, like_pat string, regex_pat string);
  19. statement ok
  20. INSERT INTO t VALUES ('abc', 'a%', 'a.*'), ('ABC', 'a%', 'a.*'), ('ccc', 'a%', 'a.*');
  21. query T multiline
  22. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR
  23. SELECT s FROM t WHERE s LIKE 'a%';
  24. ----
  25. Explained Query:
  26. Project (#0{s})
  27. Filter like["a%"](#0{s})
  28. ReadStorage materialize.public.t
  29. Source materialize.public.t
  30. filter=(like["a%"](#0{s}))
  31. Target cluster: multiprocess
  32. EOF
  33. query T
  34. SELECT s FROM t WHERE s LIKE 'a%';
  35. ----
  36. abc
  37. query T multiline
  38. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR
  39. SELECT s FROM t WHERE s ILIKE 'a%';
  40. ----
  41. Explained Query:
  42. Project (#0{s})
  43. Filter ilike["a%"](#0{s})
  44. ReadStorage materialize.public.t
  45. Source materialize.public.t
  46. filter=(ilike["a%"](#0{s}))
  47. Target cluster: multiprocess
  48. EOF
  49. query T
  50. SELECT s FROM t WHERE s ILIKE 'a%';
  51. ----
  52. ABC
  53. abc
  54. query T multiline
  55. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR
  56. SELECT s FROM t WHERE s NOT ILIKE 'a%';
  57. ----
  58. Explained Query:
  59. Project (#0{s})
  60. Filter NOT(ilike["a%"](#0{s}))
  61. ReadStorage materialize.public.t
  62. Source materialize.public.t
  63. filter=(NOT(ilike["a%"](#0{s})))
  64. Target cluster: multiprocess
  65. EOF
  66. query T
  67. SELECT s FROM t WHERE s NOT ILIKE 'a%';
  68. ----
  69. ccc
  70. query T multiline
  71. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR
  72. SELECT s FROM t WHERE NOT (s ILIKE 'a%');
  73. ----
  74. Explained Query:
  75. Project (#0{s})
  76. Filter NOT(ilike["a%"](#0{s}))
  77. ReadStorage materialize.public.t
  78. Source materialize.public.t
  79. filter=(NOT(ilike["a%"](#0{s})))
  80. Target cluster: multiprocess
  81. EOF
  82. # Binary versions (MirScalarExpr::reduce changes them into unary when the pattern is a constant, which we prevent here.)
  83. query T multiline
  84. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR
  85. SELECT s FROM t WHERE s LIKE like_pat;
  86. ----
  87. Explained Query:
  88. Project (#0{s})
  89. Filter (#0{s} like #1{like_pat})
  90. ReadStorage materialize.public.t
  91. Source materialize.public.t
  92. filter=((#0{s} like #1{like_pat}))
  93. Target cluster: multiprocess
  94. EOF
  95. query T
  96. SELECT s FROM t WHERE s LIKE like_pat;
  97. ----
  98. abc
  99. query T multiline
  100. EXPLAIN OPTIMIZED PLAN WITH (humanized expressions) AS VERBOSE TEXT FOR
  101. SELECT s FROM t WHERE s ILIKE like_pat;
  102. ----
  103. Explained Query:
  104. Project (#0{s})
  105. Filter (#0{s} ilike #1{like_pat})
  106. ReadStorage materialize.public.t
  107. Source materialize.public.t
  108. filter=((#0{s} ilike #1{like_pat}))
  109. Target cluster: multiprocess
  110. EOF
  111. query T
  112. SELECT s FROM t WHERE s ILIKE like_pat;
  113. ----
  114. ABC
  115. abc
  116. # Regression test for https://github.com/MaterializeInc/database-issues/issues/7790
  117. statement ok
  118. CREATE TABLE t2 (text_val TEXT);
  119. statement ok
  120. INSERT INTO t2 VALUES ('abc');
  121. statement ok
  122. CREATE CLUSTER test SIZE '2-1';
  123. statement ok
  124. SET cluster = test;
  125. query B
  126. SELECT text_val NOT ILIKE '%A%' FROM t2;
  127. ----
  128. false
  129. query B
  130. SELECT text_val NOT ILIKE '%A%' FROM t2;
  131. ----
  132. false
  133. query B
  134. SELECT text_val NOT ILIKE '%A%' FROM t2;
  135. ----
  136. false
  137. query B
  138. SELECT text_val NOT ILIKE '%A%' FROM t2;
  139. ----
  140. false
  141. query B
  142. SELECT text_val NOT ILIKE '%A%' FROM t2;
  143. ----
  144. false
  145. query B
  146. SELECT text_val NOT ILIKE '%A%' FROM t2;
  147. ----
  148. false
  149. query B
  150. SELECT text_val NOT ILIKE '%A%' FROM t2;
  151. ----
  152. false
  153. # Test that % matches \n
  154. query B
  155. SELECT E'test line 1\ntest line 2' LIKE '%1%2%';
  156. ----
  157. true
  158. statement ok
  159. INSERT INTO t2 VALUES ('test line 1\ntest line 2');
  160. query B
  161. SELECT text_val LIKE '%1%2%' FROM t2;
  162. ----
  163. false
  164. true
  165. statement ok
  166. DROP CLUSTER multiprocess;