sql: casting FLOAT in [32767, 32767.5) to INT2 fails with "integer out of range" only in the vectorized engine
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
Research direction
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.
Written by the indexing model from the issue text.
Description
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:263floatToIntchecksv >= float(MaxInt16)/v <= float(MinInt16)before rounding, so 32767.0 itself is rejected. - Row engine:
sem/eval/cast.go:216checks the INT8 range, rounds withRoundToEven, and then checks the width inAdjustValueToType. - Related but different: #115131 (the row engine returns 32767 for
'32767.6'::float8::int2instead of an error).
Environment:
- CockroachDB v26.2.7 (official Docker image), Linux
Found with AI assistance.
Jira issue: CRDB-70075
- 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