Skip to content

Sorting is lost when wrap a query with an additional selection #14368

@askalt

Description

@askalt

Describe the bug

DataFusion CLI v44.0.0
> create table pairs(x int, y int) as values (2, 2), (1, 1), (3, 3);
0 row(s) fetched. 
Elapsed 0.025 seconds.

> with subquery as (select * from pairs order by x)
  select * from subquery;
+---+---+
| x | y |
+---+---+
| 2 | 2 |
| 1 | 1 |
| 3 | 3 |
+---+---+

> explain select * from (select * from pairs order by x);
+---------------+-----------------------------------------------+
| plan_type     | plan                                          |
+---------------+-----------------------------------------------+
| logical_plan  | TableScan: pairs projection=[x, y]            |
| physical_plan | MemoryExec: partitions=1, partition_sizes=[1] |
|               |                                               |
+---------------+-----------------------------------------------+
2 row(s) fetched. 
Elapsed 0.008 seconds.

x is not ordered and the logical plan does not contain sort.

To Reproduce

Steps are described above.

Expected behavior

Ordered key is ordered in the output, a logical plan tells about it.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions