Skip to content

UNION ALL doesn't work correctly in combination with LIMIT #2904

@puzpuzpuz

Description

@puzpuzpuz

Describe the bug

See the below reproducer.

To reproduce

create table x as (
  select x,
         rnd_symbol(4, 10, 10, 0) sym,
         cast(172800000000 as timestamp) ts
  from long_sequence(100)
) timestamp(ts) partition by day;

select *
from (
  (select sym, max(x) from x order by sym limit 0,2)
  union all
  (select sym, max(x) from x order by sym limit 2,4)
);

The above select returns the following record set:

"sym","max"
"FHUDMNJRJP",97
"KFXSBQIYCH",96
"RCMGUPZLXU",100
"KFXSBQIYCH",96

Notice duplicated KFXSBQIYCH records. The bug is that this record is returned only by the first sub-query.

Expected Behavior

No response

Environment

- **QuestDB version**: latest `master`
- **OS**:
- **Browser**:

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIncorrect or unexpected behaviorSQLIssues or changes relating to SQL execution

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions