You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (Jira)" <ji...@apache.org> on 2022/04/13 21:24:00 UTC
[jira] [Comment Edited] (CALCITE-1583) Wrong results for query with correlated subqueries with aggregate subquery expression
[ https://issues.apache.org/jira/browse/CALCITE-1583?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17521958#comment-17521958 ]
Julian Hyde edited comment on CALCITE-1583 at 4/13/22 9:23 PM:
---------------------------------------------------------------
[~nobigo], Yes, go ahead. Assign it to yourself. Feel free to use my work, if it helps.
For the query given in the description,
{code}
select * from depts where exists (select sum(empno) from emps where depts.deptno = emps.deptno and 1=2)
{code}
I suspect that {{RelMdMinRowCount}} for the subquery will return 1 or more, and therefore the 'exists (subquery)' can safely be converted to 'true'. That optimization might already be present.
was (Author: julianhyde):
[~nobigo], Yes, go ahead. Feel free to use my work, if it helps.
For the query given in the description,
{code}
select * from depts where exists (select sum(empno) from emps where depts.deptno = emps.deptno and 1=2)
{code}
I suspect that {{RelMdMinRowCount}} for the subquery will return 1 or more, and therefore the 'exists (subquery)' can safely be converted to 'true'. That optimization might already be present.
> Wrong results for query with correlated subqueries with aggregate subquery expression
> -------------------------------------------------------------------------------------
>
> Key: CALCITE-1583
> URL: https://issues.apache.org/jira/browse/CALCITE-1583
> Project: Calcite
> Issue Type: Bug
> Reporter: Vineet Garg
> Priority: Major
> Labels: sub-query
>
> Following query produces wrong result:
> {code} select * from depts where exists (select sum(empno) from emps where depts.deptno = emps.deptno and 1=2) {code}
> Expected Result:
> {noformat}
> deptno | name
> --------+-----------
> 10 | Sales
> 20 | Marketing
> 30 | Accounts
> (3 rows)
> {noformat}
> Actual results
> {noformat} zero rows {noformat}
> Calcite rewrites such queries into JOIN which ignores the fact that aggregate functions such as {{sum}} always produce one row, effectively making {{EXISTS}} predicate always true.
> Same is the case with {{Scalar}} and {{IN}} sub-queries.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)