cockroachdb / cockroachdb/cockroach

sql: null_ordered_last does not produce correct results with tuples

Aperta
#93,558 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
A-sql-pgcompat C-bug docs-done docs-known-limitation T-sql-queries
Lingua principale
Go
Stelle
32.5k
Fork
4.1k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

**Describe the problem**

By default, CockroachDB orders NULLs before all other values. For compatibility with Postgres, we added a session setting, `null_ordered_last`, which changes the default to order NULLs after all other values. This works in most cases, thanks to some transformations we make in the optimizer to add extra ordering columns. However, it is broken when the ordering column is a tuple.

**To Reproduce**

On `./cockroach demo`, on master (23.1 alpha), run the following:
```
SET null_ordered_last = true;

WITH t (x, y) AS (
VALUES
((1, 1), 1),
((NULL::RECORD), 2),
((1, NULL::INT), 3),
((NULL::INT, NULL::INT), 4)
)
SELECT *
FROM t
ORDER BY x;
```
The result on CockorachDB:
```
x | y
--------+----
(1,) | 3
(1,1) | 1
NULL | 2
(,) | 4
```
The result on Postgres:
```
x | y
-------+---
(1,1) | 1
(1,) | 3
(,) | 4
| 2
```

**Expected behavior**
The CockroachDB output should match Postgres when `null_ordered_last` is true.

**Environment:**
- CockroachDB version: v23.1.0-alpha....dirty
- Server OS: macOS Monterey
- Client app: cockroach demo

Jira issue: CRDB-22400

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.