You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2020/10/20 11:12:11 UTC
[GitHub] [incubator-doris] ccoffline opened a new issue #4772: [Bug] UNION ALL query return wrong empty set
ccoffline opened a new issue #4772:
URL: https://github.com/apache/incubator-doris/issues/4772
**Describe the bug**
```sql
-- 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.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] ccoffline commented on issue #4772: [Bug] UNION ALL query return wrong empty set
Posted by GitBox <gi...@apache.org>.
ccoffline commented on issue #4772:
URL: https://github.com/apache/incubator-doris/issues/4772#issuecomment-716422477
This bug was caused by #4206's fix #4235, `scanNodes.clear()` here remove all previous `scanNodes` if the last statement's condition is false.
https://github.com/apache/incubator-doris/blob/a61eea3b2e76d741c98b9faed8cec51c1d469f94/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java#L284-L290
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] ccoffline edited a comment on issue #4772: [Bug] UNION ALL query return wrong empty set
Posted by GitBox <gi...@apache.org>.
ccoffline edited a comment on issue #4772:
URL: https://github.com/apache/incubator-doris/issues/4772#issuecomment-716422477
This bug is caused by #4206's fix #4235, `scanNodes.clear()` here remove all previous `scanNodes` if the last statement is considered to return an empty set.
https://github.com/apache/incubator-doris/blob/a61eea3b2e76d741c98b9faed8cec51c1d469f94/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java#L284-L290
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] ccoffline removed a comment on issue #4772: [Bug] UNION ALL query return wrong empty set
Posted by GitBox <gi...@apache.org>.
ccoffline removed a comment on issue #4772:
URL: https://github.com/apache/incubator-doris/issues/4772#issuecomment-714904742
This is most likely because Doris treats UNION clause conditions as conditions for the entire previous query.
Test result on `MySQL 5.7` shows that these two queries return the same result.
I haven't found any description of union queries like this in the SQL standard, but I think Doris should keep the same actions as `MySQL`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] kangkaisen edited a comment on issue #4772: [Bug] UNION ALL query return wrong empty set
Posted by GitBox <gi...@apache.org>.
kangkaisen edited a comment on issue #4772:
URL: https://github.com/apache/incubator-doris/issues/4772#issuecomment-716987878
@ccoffline Sorry. you could add this method to `PlanNode`:
```
protected List<TupleId> getAllScanTupleIds() {
List<TupleId> tupleIds = Lists.newArrayList();
List<ScanNode> scanNodes = Lists.newArrayList();
collectAll(Predicates.instanceOf(ScanNode.class), scanNodes);
for(ScanNode node: scanNodes) {
tupleIds.addAll(node.getTupleIds());
}
return tupleIds;
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] kangkaisen commented on issue #4772: [Bug] UNION ALL query return wrong empty set
Posted by GitBox <gi...@apache.org>.
kangkaisen commented on issue #4772:
URL: https://github.com/apache/incubator-doris/issues/4772#issuecomment-716494100
I forget to submit a PR to the Github master branch.
You could change the code to, and submit a PR.
```
if (analyzer.hasEmptyResultSet()) {
List<TupleId> scanTupleIds = root.getAllScanTupleIds();
PlanNode node = createEmptyNode(stmt, analyzer);
// Ensure result exprs will be substituted by right outputSmap
node.setOutputSmap(root.outputSmap);
// Must and could only remove the scanNode that the tuple id is same with EmptyNode,
// otherwise we will get NPE in Coordinator::computeScanRangeAssignment
scanNodes.removeIf(scanNode -> scanTupleIds.contains(scanNode.getTupleIds().get(0)));
// Currently, getMaterializedTupleIds for AnalyticEvalNode is wrong,
// So we explicitly add AnalyticEvalNode tuple ids to EmptySetNode
if (root instanceof AnalyticEvalNode) {
node.getTupleIds().addAll(root.tupleIds);
}
return node;
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] kangkaisen commented on issue #4772: [Bug] UNION ALL query return wrong empty set
Posted by GitBox <gi...@apache.org>.
kangkaisen commented on issue #4772:
URL: https://github.com/apache/incubator-doris/issues/4772#issuecomment-716987878
@ccoffline Sorry. you could add this method to `PlanNode`:
```
protected List<TupleId> getAllScanTupleIds() {
List<TupleId> tupleIds = Lists.newArrayList();
List<OlapScanNode> scanNodes = Lists.newArrayList();
collectAll(Predicates.instanceOf(OlapScanNode.class), scanNodes);
for(OlapScanNode node: scanNodes) {
tupleIds.addAll(node.getTupleIds());
}
return tupleIds;
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] ccoffline closed issue #4772: [Bug] UNION ALL query return wrong empty set
Posted by GitBox <gi...@apache.org>.
ccoffline closed issue #4772:
URL: https://github.com/apache/incubator-doris/issues/4772
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] ccoffline commented on issue #4772: [Bug] UNION ALL query return wrong empty set
Posted by GitBox <gi...@apache.org>.
ccoffline commented on issue #4772:
URL: https://github.com/apache/incubator-doris/issues/4772#issuecomment-716976794
> I forget to submit a PR to the Github master branch.
> You could change the code to, and submit a PR.
>
> ```
> if (analyzer.hasEmptyResultSet()) {
> List<TupleId> scanTupleIds = root.getAllScanTupleIds();
> PlanNode node = createEmptyNode(stmt, analyzer);
> // Ensure result exprs will be substituted by right outputSmap
> node.setOutputSmap(root.outputSmap);
>
> // Must and could only remove the scanNode that the tuple id is same with EmptyNode,
> // otherwise we will get NPE in Coordinator::computeScanRangeAssignment
> scanNodes.removeIf(scanNode -> scanTupleIds.contains(scanNode.getTupleIds().get(0)));
> // Currently, getMaterializedTupleIds for AnalyticEvalNode is wrong,
> // So we explicitly add AnalyticEvalNode tuple ids to EmptySetNode
> if (root instanceof AnalyticEvalNode) {
> node.getTupleIds().addAll(root.tupleIds);
> }
> return node;
> }
> ```
I can't find method `getAllScanTupleIds` in `PlanNode root`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] ccoffline edited a comment on issue #4772: [Bug] UNION ALL query return wrong empty set
Posted by GitBox <gi...@apache.org>.
ccoffline edited a comment on issue #4772:
URL: https://github.com/apache/incubator-doris/issues/4772#issuecomment-716422477
This bug is caused by #4206's fix #4235, `scanNodes.clear()` here remove all previous `scanNodes` if the last statement's condition is false.
https://github.com/apache/incubator-doris/blob/a61eea3b2e76d741c98b9faed8cec51c1d469f94/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java#L284-L290
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org
[GitHub] [incubator-doris] ccoffline commented on issue #4772: [Bug] UNION ALL query return wrong empty set
Posted by GitBox <gi...@apache.org>.
ccoffline commented on issue #4772:
URL: https://github.com/apache/incubator-doris/issues/4772#issuecomment-714904742
This is most likely because Doris treats UNION clause conditions as conditions for the entire previous query.
Test result on `MySQL 5.7` shows that these two queries return the same result.
I haven't found any description of union queries like this in the SQL standard, but I think Doris should keep the same actions as `MySQL`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org