cockroachdb / cockroachdb/cockroach

sql: null_ordered_last does not produce correct results with tuples

Offen
#93,558 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
A-sql-pgcompat C-bug docs-done docs-known-limitation T-sql-queries
Vorherrschende Sprache
Go
Sterne
32.5k
Forks
4.1k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

**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

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.