[
https://issues.apache.org/jira/browse/CALCITE-4182?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Wang Yanlin updated CALCITE-4182:
---------------------------------
Description:
MV recognition fails when query has constant filter for group by list in mv,
but has no group by itself.
{noformat}
@Test void testConstantFilterInAgg() {
final String mv = ""
+ "select \"name\", count(distinct \"deptno\") as cnt\n"
+ "from \"emps\" group by \"name\"";
final String query = ""
+ "select count(distinct \"deptno\") as cnt\n"
+ "from \"emps\" where \"name\" = 'hello'";
sql(mv, query).ok();
}
{noformat}
This case fails, however we can see that, we can rewrite the query with mv like
this, suppose *mv* is the name of the table.
{noformat}
select cnt from mv where name = 'hello';
{noformat}
However, this query has the same semantics with the query in the case, using
this query for mv recognition, the case will success
{noformat}
final String query = ""
+ "select cnt from(\n"
+ " select \"name\", count(distinct \"deptno\") as cnt "
+ " from \"emps\" group by \"name\") t\n"
+ "where \"name\" = 'hello'";
{noformat}
But we cannot force users to only write their queries in this way, so maybe we
need a rule to expand aggregate group by list with constant filter condition.
was:
Mv re
{noformat}
@Test void testConstantFilterInAgg() {
final String mv = ""
+ "select \"name\", count(distinct \"deptno\") as cnt\n"
+ "from \"emps\" group by \"name\"";
final String query = ""
+ "select count(distinct \"deptno\") as cnt\n"
+ "from \"emps\" where \"name\" = 'hello'";
sql(mv, query).ok();
}
{noformat}
> MV recognition fails when query has constant filter for group by list in mv,
> but without group by
> -------------------------------------------------------------------------------------------------
>
> Key: CALCITE-4182
> URL: https://issues.apache.org/jira/browse/CALCITE-4182
> Project: Calcite
> Issue Type: Bug
> Reporter: Wang Yanlin
> Priority: Major
>
> MV recognition fails when query has constant filter for group by list in mv,
> but has no group by itself.
>
> {noformat}
> @Test void testConstantFilterInAgg() {
> final String mv = ""
> + "select \"name\", count(distinct \"deptno\") as cnt\n"
> + "from \"emps\" group by \"name\"";
> final String query = ""
> + "select count(distinct \"deptno\") as cnt\n"
> + "from \"emps\" where \"name\" = 'hello'";
> sql(mv, query).ok();
> }
> {noformat}
> This case fails, however we can see that, we can rewrite the query with mv
> like this, suppose *mv* is the name of the table.
> {noformat}
> select cnt from mv where name = 'hello';
> {noformat}
> However, this query has the same semantics with the query in the case, using
> this query for mv recognition, the case will success
> {noformat}
> final String query = ""
> + "select cnt from(\n"
> + " select \"name\", count(distinct \"deptno\") as cnt "
> + " from \"emps\" group by \"name\") t\n"
> + "where \"name\" = 'hello'";
> {noformat}
> But we cannot force users to only write their queries in this way, so maybe
> we need a rule to expand aggregate group by list with constant filter
> condition.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)