sql: ILIKE 'k' does not match the Kelvin sign (U+212A) with vectorize off but matches it with vectorize on

Open
#176,191 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go, sql
Domain
backend, databases

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

C-bug O-community T-sql-queries X-blathers-triaged X-move-internal

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.

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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cockroachdb/cockroach

All issues in cockroachdb/cockroach

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.