Skip to content

Avoid sorts for descending ORDER BY on lookup join index columns #88319

@msirek

Description

@msirek

Is your feature request related to a problem? Please describe.
#84689 improves the number of cases a sort is avoided for lookup join queries with ORDER BY on the lookup index columns, but does not handle descending index columns

Example:

CREATE TABLE xyz (x INT, y INT, z INT, PRIMARY KEY(x, y, z));
CREATE TABLE uvw (u INT, v INT, w INT, PRIMARY KEY(u, v, w));

The following avoids a sort:

SELECT * FROM xyz INNER LOOKUP JOIN uvw ON x = u AND y = v ORDER BY x, y, z, u, v, w;

But if the PK of table uvw is (u, v, w DESC) and we have ORDER BY x, y, z, u, v, w DESC; This should avoid a sort.
A reverse scan is not required so I believe lookup join should be able to support it.

Describe alternatives you've considered
None

Jira issue: CRDB-19769

Metadata

Metadata

Assignees

Labels

C-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)O-qaT-sql-queriesSQL Queries Team

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions