sql: ILIKE 'k' does not match the Kelvin sign (U+212A) with vectorize off but matches it with vectorize on
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 48/100
Research direction
Start by reading optimizedLikeFunc in pkg/sql/sem/eval/match.go and the related issue #176146, which reports a similar Unicode case-folding mismatch. Compare the row-by-row fast paths described here with the regular expression path and the vectorized operator selection in pkg/sql/colexec/colexeccmp/like_ops.go. Reproduce with the provided SQL for ILIKE 'k' under both vectorization settings; done when the row-by-row result agrees with the vectorized and regexp results for the reported patterns.
Written by the indexing model from the issue text.
Description
Describe the problem
For a string value that is the Kelvin sign (U+212A), s ILIKE 'k' returns no row in the row-by-row engine and returns the row in the vectorized engine. Other short patterns that take the same path in the row-by-row engine behave the same way, for example ILIKE 'k_' and NOT ILIKE E'%\\k'. The row-by-row engine is also inconsistent with itself: for patterns that it matches with a regular expression, such as '%k%a%', it does match the Kelvin sign. ILIKE is a case-insensitive match, and the same input and the same kind of pattern should not give a different result depending on which matching path the pattern happens to take. The Kelvin sign should match k, as it does in the vectorized engine and in the row-by-row engine's own regular expression path.
To Reproduce
Deployment: a single-node CockroachDB cluster started with cockroach start-single-node --insecure (tested: v26.2.7, 1 node, default settings except sql.stats.automatic_collection.enabled = false). Run the script in an empty database. The script runs the query twice in one session: first with vectorize = off (row-by-row engine), then with vectorize = on (vectorized engine).
The inserted value is the Kelvin sign U+212A, not the ASCII letter K.
SET TIME ZONE 'UTC';
CREATE TABLE t (s STRING);
INSERT INTO t VALUES ('K');
-- row-by-row engine
SET vectorize = off;
EXPLAIN (VERBOSE) SELECT s FROM t WHERE s ILIKE 'k';
SELECT s FROM t WHERE s ILIKE 'k';
-- vectorized engine
SET vectorize = on;
EXPLAIN (VERBOSE) SELECT s FROM t WHERE s ILIKE 'k';
SELECT s FROM t WHERE s ILIKE 'k';
Expected behavior
The row is returned. The CockroachDB v26.2 documentation (String pattern matching, scalar-expressions) says: "ILIKE causes the match to be tested case-insensitively". The PostgreSQL 18.6 manual says: "The key word ILIKE can be used instead of LIKE to make the match case-insensitive according to the active locale". Neither document says how Unicode characters such as the Kelvin sign are folded, so the expectation rests on consistency: the row-by-row engine's regular expression path and the vectorized engine both match the Kelvin sign against k, and the result should not depend on the matching path. PostgreSQL 18.6 also returns the row for this query.
PostgreSQL 18.6 (Debian 18.6-1.pgdg12+2):
SELECT s FROM t WHERE s ILIKE 'k';
psql:<stdin>:5: ERROR: 42P01: relation "t" does not exist
LINE 1: SELECT s FROM t WHERE s ILIKE 'k';
^
LOCATION: parserOpenTable, parse_relation.c:1498
Additional data / screenshots
With vectorize = off the query returns no rows. With vectorize = on it returns one row, s = U+212A (the Kelvin sign).
-- row-by-row engine
EXPLAIN (VERBOSE) SELECT s FROM t WHERE s ILIKE 'k';
info
--------------------------------------------------
distribution: local
vectorized: false
• filter
│ columns: (s)
│ estimated row count: 330 (missing stats)
│ filter: s ILIKE 'k'
│
└── • scan
columns: (s)
estimated row count: 1,000 (missing stats)
table: t@t_pkey
spans: FULL SCAN
(13 rows)
SELECT s FROM t WHERE s ILIKE 'k';
s
---
(0 rows)
-- vectorized engine
EXPLAIN (VERBOSE) SELECT s FROM t WHERE s ILIKE 'k';
info
--------------------------------------------------
distribution: local
vectorized: true
• filter
│ columns: (s)
│ estimated row count: 330 (missing stats)
│ filter: s ILIKE 'k'
│
└── • scan
columns: (s)
estimated row count: 1,000 (missing stats)
table: t@t_pkey
spans: FULL SCAN
(13 rows)
SELECT s FROM t WHERE s ILIKE 'k';
s
---
K
(1 row)
Environment:
- CockroachDB version:
CockroachDB CCL v26.2.7-dev-8652ac22d9f90501e48ae4f24efd7faab33cf7c5 (x86_64-pc-linux-gnu, built 2026/10/23 21:35:41, go1.25.13)
- Server OS: Linux 6.8.0-138-generic x86_64, AMD EPYC 7J13 64-Core Processor
- Client app:
psql
Additional context
In the row-by-row engine, optimizedLikeFunc returns a fast-path closure for a single-byte pattern without wildcards. For ILIKE the closure upper-cases both the input and the pattern with strings.ToUpper and compares them byte by byte. The upper case of U+212A is U+212A itself, which differs from K, so the comparison fails. The same ToUpper comparison is used in the other fast-path branches of the function (around lines 325, 345, 366 and 403). When no fast path applies, matchLike uses the regular expression from anchorPattern (^(?si:%s)$), which folds case by Unicode simple folding, and there the Kelvin sign is equivalent to K and k. In the vectorized engine, GetLikeOperatorType does not select a byte operator for a pattern of length 1 (it requires len(pattern) > 1), so the pattern falls through to LikeRegexp and uses the same kind of (?i) regular expression. The row-by-row fast path is therefore the odd one out.
The related issue already reports this disagreement for the pattern 'ı_' (a pattern ending in _): it points at the strings.ToUpper(s) == strings.ToUpper(pattern) comparison in optimizedLikeFunc and the (?i) regular expression in the vectorized engine. It does not mention the single-byte pattern without wildcards (ILIKE 'k') or the escaped suffix pattern (NOT ILIKE E'%\\k'), which are the remaining shapes this issue covers.
- CockroachDB: pkg/sql/sem/eval/match.go#L291 —
optimizedLikeFunc - CockroachDB: pkg/sql/colexec/colexeccmp/like_ops.go#L101 —
GetLikeOperatorType
Related: https://github.com/cockroachdb/cockroach/issues/176146
Found with AI assistance.
Jira issue: CRDB-70786
- Dominant language
- Go
- Stars
- 32.6k
- Forks
- 4.2k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cockroachdb/cockroach
-
C-bug O-community X-blathers-untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
cockroachdb/cockroach#176245 · 1 comment ·
-
sql: pg_database.dattablespace is 0 but pg_tablespace.oid is 1663, so they no longer joinPossibly taken @1AbdullahButt claimed this 14 days ago. OpenC-bug O-community X-blathers-triaged X-move-internal
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
cockroachdb/cockroach#176228 · 1 comment ·
-
PG compat: overflow in integer power calculation triggers incompatible SQLSTATEMay be free again @darshpatel1052 claimed this 18 days ago, and no pull request is open. OpenC-bug O-community X-blathers-untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
cockroachdb/cockroach#176223 · 2 comments ·
-
util/log: bufferedSinkCloser.Close leaks a goroutine after timeoutPossibly taken @dajiaohuang claimed this 14 days ago. OpenC-bug O-community X-blathers-untriaged
Difficulty 1/5 Under an hour Newbie friendliness 84/100
cockroachdb/cockroach#176210 · 1 comment ·
-
C-bug O-community T-sql-queries X-blathers-triaged X-move-internal
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
cockroachdb/cockroach#176150 · 1 comment ·
All issues in cockroachdb/cockroach
Similar issues
-
area/import-export area/projects concern/ux
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
go-vikunja/vikunja#4455 · 1 comment ·
Maintainers usually reply within 2 days
-
Dependabot PRs no longer merge automaticallyPossibly taken @dwisiswant0 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
projectdiscovery/urlfinder#160 ·
Maintainers usually reply within 1 day
-
database
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
chnm/legal-modernism#450 ·
Maintainers usually reply within 1 day
-
tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
bug ready-for-triage ready-to-code
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
RedHatInsights/insights-ingress-go#946 · 4 comments ·
Maintainers usually reply within 1 day