Skip to content

[Bug] UNION ALL query return wrong empty set #4772

@ccoffline

Description

@ccoffline

Describe the bug

-- create table
DROP TABLE IF EXISTS `test_t`;
CREATE TABLE `test_t` (
  `name` VARCHAR(1000) NULL COMMENT "string"
) ENGINE=OLAP
DUPLICATE KEY(`name`)
DISTRIBUTED BY HASH(`name`) BUCKETS 5
PROPERTIES (
"replication_num" = "1",
"in_memory" = "false",
"storage_format" = "DEFAULT"
);

-- insert data
INSERT INTO test_t (`name`)
VALUES ('aaaaa'), ('ccccc')
;

-- returns wrong empty set
SELECT `t1`.`name`
FROM (
   SELECT `name`
   FROM `test_t`
GROUP BY `name`
   ) `t1`
UNION ALL
SELECT `t2`.`name`
FROM (
   SELECT `name`,
      -1 as `bool`
   FROM `test_t`
GROUP BY `name`
   ) `t2`
WHERE `t2`.`bool` = 1
;

-- returns correct result ‘aaaaa’ and ‘ccccc’
SELECT `t2`.`name`
FROM (
   SELECT `name`,
      -1 as `bool`
   FROM `test_t`
GROUP BY `name`
   ) `t2`
WHERE `t2`.`bool` = 1
UNION ALL
SELECT `t1`.`name`
FROM (
   SELECT `name`
   FROM `test_t`
GROUP BY `name`
   ) `t1`
;

Additional context
Fixing, may need some help QAQ.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions