sql: ILIKE 'k' does not match the Kelvin sign (U+212A) with vectorize off but matches it with vectorize on
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Go
- Stelle
- 32.6k
- Fork
- 4.2k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di cockroachdb/cockroach
-
C-bug O-community X-blathers-untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
cockroachdb/cockroach#176245 · 1 commento ·
-
sql: pg_database.dattablespace is 0 but pg_tablespace.oid is 1663, so they no longer joinForse già presa @1AbdullahButt l’ha presa 14 giorni fa. ApertaC-bug O-community X-blathers-triaged X-move-internal
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
cockroachdb/cockroach#176228 · 1 commento ·
-
PG compat: overflow in integer power calculation triggers incompatible SQLSTATEForse di nuovo libera @darshpatel1052 l’ha presa 18 giorni fa e non c’è nessuna pull request aperta. ApertaC-bug O-community X-blathers-untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
cockroachdb/cockroach#176223 · 2 commenti ·
-
util/log: bufferedSinkCloser.Close leaks a goroutine after timeoutForse già presa @dajiaohuang l’ha presa 14 giorni fa. ApertaC-bug O-community X-blathers-untriaged
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 84/100
cockroachdb/cockroach#176210 · 1 commento ·
-
C-bug O-community T-sql-queries X-blathers-triaged X-move-internal
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
cockroachdb/cockroach#176150 · 1 commento ·
Tutte le issue di cockroachdb/cockroach
Issue simili
-
☢️ Bug v3
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
area/import-export area/projects concern/ux
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
go-vikunja/vikunja#4455 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
Dependabot PRs no longer merge automaticallyForse già presa @dwisiswant0 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
projectdiscovery/urlfinder#160 ·
I maintainer di solito rispondono entro 1 giorno
-
database
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
chnm/legal-modernism#450 ·
I maintainer di solito rispondono entro 1 giorno
-
tech-debt
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno