[
https://issues.apache.org/jira/browse/PHOENIX-2989?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15328025#comment-15328025
]
James Taylor commented on PHOENIX-2989:
---------------------------------------
Patch looks good. Here's a good test you can add to WhereOptimizerTest:
{code}
@Test
public void testNoAggregatorForOrderBy() throws SQLException {
Connection conn = DriverManager.getConnection(getUrl(),
PropertiesUtil.deepCopy(TEST_PROPERTIES));
conn.createStatement().execute("create table test (pk1 integer not
null, pk2 integer not null, constraint pk primary key (pk1,pk2))");
StatementContext context = compileStatement("select count(distinct pk1)
from test order by count(distinct pk2)");
assertEquals(1,
context.getAggregationManager().getAggregators().getAggregatorCount());
}
{code}
> Allow DistinctPrefixFilter optimization when HAVING clause only reference
> COUNT(DISTINCT)
> -----------------------------------------------------------------------------------------
>
> Key: PHOENIX-2989
> URL: https://issues.apache.org/jira/browse/PHOENIX-2989
> Project: Phoenix
> Issue Type: Sub-task
> Reporter: James Taylor
> Fix For: 4.8.0
>
> Attachments: 2989-orderby-v2.txt, 2989-orderby.txt
>
>
> The DistinctPrefixFilter optimization can still be used if a HAVING clause
> only references COUNT(DISTINCT) expressions. One way to detect this is to
> collect a Set<ParseNode> using a visitor for the SELECT and HAVING which only
> collects COUNT(DISTINCT) expressions. This set will then be used as the GROUP
> BY nodes if there's no existing GROUP BY.
> The check for whether or not to add the filter can then change to something
> like this:
> {code}
> if (... &&
> ( context.getAggregationManager().isEmpty() ||
> ( plan.getGroupBy().isUngroupedAggregate() &&
> plan.getGroupBy().getKeyExpressions().size() ==
> context.getAggregationManager().getAggregators().getAggregatorCount()
> ) ) )
> {code}
> That way, it'll only add the filter if all expressions pulled in as a GROUP
> BY expression (only the count distinct ones) account for all of the
> aggregators.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)