[
https://issues.apache.org/jira/browse/PHOENIX-1560?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14279397#comment-14279397
]
James Taylor commented on PHOENIX-1560:
---------------------------------------
I think the fix for PHOENIX-1589 would be pretty straightforward. The easiest
way would be to have QueryCompiler.compileSingleFlatQuery() check right before
creating the plan whether or not the GROUP BY expressions are equal to the
table PK columns. Not sure how this would interop with join code path, though.
{code}
QueryPlan plan = innerPlan;
if (plan == null) {
boolean optimizeOutGroupBy = optimizeOutGroupBy(tableRef, groupBy);
ParallelIteratorFactory parallelIteratorFactory = asSubquery ? null
: this.parallelIteratorFactory;
plan = !optimizeOutGroupBy && (select.isAggregate() ||
select.isDistinct()) ?
new AggregatePlan(context, select, tableRef, projector,
limit, orderBy, parallelIteratorFactory, groupBy, having)
: new ScanPlan(context, select, tableRef, projector, limit,
orderBy, parallelIteratorFactory, allowPageFilter);
}
private static boolean optimizeOutGroupBy(TableRef tableRef, GroupBy
groupBy) {
List<PColumn> pkColumns = tableRef.getTable().getPKColumns();
List<Expression> groupByExpressions = groupBy.getExpressions();
if (groupByExpressions.size() != pkColumns.size()) {
return false;
}
for (int i = 0; i < pkColumns.size(); i++) {
PColumn column = pkColumns.get(i);
ColumnRef columnRef = new ColumnRef(tableRef, column.getPosition());
ColumnExpression colExpr = columnRef.newColumnExpression();
if (!colExpr.equals(groupByExpressions.get(i)) {
return false;
}
}
return true;
}
{code}
> Join between global index and data table if INDEX hint used
> -----------------------------------------------------------
>
> Key: PHOENIX-1560
> URL: https://issues.apache.org/jira/browse/PHOENIX-1560
> Project: Phoenix
> Issue Type: Bug
> Reporter: James Taylor
> Assignee: Maryann Xue
> Attachments: 1560.patch, 1560.v2.patch
>
>
> We already have an INDEX hint, and we already have a mechanism to collect
> referenced columns in the data table that are not in the index table (used
> only for local indexes currently). Instead of not using the global index when
> a referenced data column is not found in the index, we should rewrite the
> query to join back to the data table when the INDEX hint is present. This is
> always possible, as we always have the data PK columns in the index table,
> and our join optimization would kick in as well.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)