use of org.voltdb.types.SortDirectionType in project voltdb by VoltDB.
the class IndexScanPlanNode method isOutputOrdered.
@Override
public boolean isOutputOrdered(List<AbstractExpression> sortExpressions, List<SortDirectionType> sortDirections) {
assert (sortExpressions.size() == sortDirections.size());
// The output is unordered if there is an inline hash aggregate
AbstractPlanNode agg = AggregatePlanNode.getInlineAggregationNode(this);
if (agg != null && agg.getPlanNodeType() == PlanNodeType.HASHAGGREGATE) {
return false;
}
// Verify that all sortDirections match
for (SortDirectionType sortDirection : sortDirections) {
if (sortDirection != getSortDirection()) {
return false;
}
}
// Verify that all sort expressions are covered by the consecutive index expressions
// starting from the first one
List<AbstractExpression> indexedExprs = new ArrayList<>();
List<ColumnRef> indexedColRefs = new ArrayList<>();
boolean columnIndex = CatalogUtil.getCatalogIndexExpressions(getCatalogIndex(), getTableScan(), indexedExprs, indexedColRefs);
int indexExprCount = (columnIndex) ? indexedColRefs.size() : indexedExprs.size();
if (indexExprCount < sortExpressions.size()) {
// Not enough index expressions to cover all of the sort expressions
return false;
}
if (columnIndex) {
for (int idxToCover = 0; idxToCover < sortExpressions.size(); ++idxToCover) {
AbstractExpression sortExpression = sortExpressions.get(idxToCover);
if (!isSortExpressionCovered(sortExpression, indexedColRefs, idxToCover, getTableScan())) {
return false;
}
}
} else {
for (int idxToCover = 0; idxToCover < sortExpressions.size(); ++idxToCover) {
AbstractExpression sortExpression = sortExpressions.get(idxToCover);
if (!isSortExpressionCovered(sortExpression, indexedExprs, idxToCover)) {
return false;
}
}
}
return true;
}
Aggregations