Skip to content

Alias, Order by and Distributed tables does not work properly together #86227

@crakjie

Description

@crakjie

Describe what's wrong

Order by used on a distributed table with an alias seems to shuffle the columns.

Does it reproduce on the most recent release?

Yes - v25.7.2

How to reproduce

Table setup

CREATE TABLE shard_Test ON CLUSTER `{cluster}`
(
    `a` String,
    `b` Float64,
    `c` Float64,
    `d` Float64,
    `e` Float64 ALIAS b + c,
    `f` Float64 ALIAS c + d
)
ENGINE = MergeTree
ORDER BY a;

CREATE TABLE Test ON CLUSTER `{cluster}`
(
    `a` String,
    `b` Float64,
    `c` Float64,
    `d` Float64,
    `e` Float64 ALIAS b + c,
    `f` Float64 ALIAS c + d
)
ENGINE =  Distributed('{cluster}', 'default', 'shard_Test', rand());


INSERT INTO Test VALUES('a', 1,2,3);

Simple query

SELECT
    e,
    f
FROM Test

   ┌─e─┬─f─┐
1. │ 35 │
   └───┴───┘

Query with order by

SELECT
    e,
    f
FROM Test
ORDER BY a ASC


   ┌─e─┬─f─┐
1. │ 53 │
   └───┴───┘

Expected behavior

Both queries should return the sames results

Additional context

probably linked to #85895

Metadata

Metadata

Labels

analyzerIssues and pull-requests related to new analyzerbugConfirmed user-visible misbehaviour in official release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions