cockroachdb / cockroachdb/cockroach
opt: null_ordered_last with DISTINCT unexpectedly errors
Open
C-bug
O-support
P-3
T-sql-queries
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
Setting `null_order_last=true` can cause queries with `DISTINCT` expressions to incorrectly error. See the reproduction below:
```sql
CREATE TABLE t (
k INT PRIMARY KEY,
i INT
);
SELECT DISTINCT i FROM t ORDER BY i;
-- i
-- -----
-- (0 rows)
SET null_ordered_last = true;
SELECT DISTINCT i FROM t ORDER BY i;
-- ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
-- SQLSTATE: 42P10
```
This bug has been present since v22.1.0 when `null_ordered_last` was introduced.
Jira issue: CRDB-57535
Contributor guide
Assessment
This issue has not been assessed yet.