cockroachdb / cockroachdb/cockroach
Inconsistent results for the least function
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
**Describe the problem**
Run the following statements, which are expected to return -1347373370.
**To Reproduce**
```sql
CREATE TABLE t1 (c1 INT2, c2 INT4);
INSERT INTO t1 VALUES (-9551, -1347373370);
SELECT (least(c1, (least(0, c2)))) FROM t1; -- actual: {-18746}, expected: {-1347373370}
```
**Expected behavior**
Return -1347373370.
**Actual behavior**
It seems that a truncated value -18746 is returned because the first parameter of least func is c1 with type of INT2.
However, -1347373370 cannot be directly converted into INT2. Thus, the truncated value is confusing.
**Environment:**
- CockroachDB version [CCL v26.1.0-alpha.1-dev]
- Server OS: [Linux]
- Client app [psql]
Jira issue: CRDB-57712
Contributor guide
Research direction
Start by reproducing the CREATE TABLE, INSERT, and nested least() query from the issue in CockroachDB, then trace how least() resolves argument types and converts values. Done means the query returns -1347373370 without truncation, with regression coverage for the INT2 and INT4 combination.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100