sql: casting FLOAT in [32767, 32767.5) to INT2 fails with "integer out of range" only in the vectorized engine

Aperta
#176,149 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go, sql
Ambito
databases

Direzione di ricerca

Start with floatToInt in pkg/sql/colexec/execgen/cmd/execgen/cast_gen_util.go and compare it with pkg/sql/sem/eval/cast.go. Run the supplied SET vectorize queries around the INT2 and INT4 bounds, then exercise the vectorized cast implementation identified by EXPLAIN (VEC). Done means rounded values that fit the target integer width succeed consistently in both engines, with coverage for the positive and negative boundary cases.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Describe the problem

With vectorize=on, casting a FLOAT in [32767, 32767.5) or (-32768.5, -32768] to INT2 fails with integer out of range, although the rounded value is in range. With vectorize=off the cast returns 32767 / -32768. INT4 behaves the same way near its bounds.

To Reproduce

Single node, cockroach start-single-node --insecure:

CREATE TABLE t (f FLOAT8);
INSERT INTO t VALUES (32767.0), (32767.4), (-32768.4), (2147483647.2);

SET vectorize = off;
SELECT f, f::INT2 FROM t WHERE f < 40000;   -- 32767, 32767, -32768
SELECT f, f::INT4 FROM t WHERE f > 40000;   -- 2147483647
SET vectorize = on;
SELECT f, f::INT2 FROM t WHERE f < 40000;   -- ERROR: integer out of range (22003)
SELECT f, f::INT4 FROM t WHERE f > 40000;   -- ERROR: integer out of range (22003)

EXPLAIN (VEC) shows colexecbase.castFloatInt2Op.

Expected behavior

32767 / -32768 / 2147483647 in both engines (PostgreSQL also returns 32767 for 32767.4::float8::int2).

Additional context

  • Vectorized: execgen/cast_gen_util.go:263 floatToInt checks v >= float(MaxInt16) / v <= float(MinInt16) before rounding, so 32767.0 itself is rejected.
  • Row engine: sem/eval/cast.go:216 checks the INT8 range, rounds with RoundToEven, and then checks the width in AdjustValueToType.
  • Related but different: #115131 (the row engine returns 32767 for '32767.6'::float8::int2 instead of an error).

Environment:

  • CockroachDB v26.2.7 (official Docker image), Linux

Found with AI assistance.

Jira issue: CRDB-70075

Lingua principale
Go
Stelle
32.6k
Fork
4.2k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di cockroachdb/cockroach

Tutte le issue di cockroachdb/cockroach

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.