Search in sources :

Example 6 with SortDirectionType

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;
}
Also used : AbstractExpression(org.voltdb.expressions.AbstractExpression) ArrayList(java.util.ArrayList) SortDirectionType(org.voltdb.types.SortDirectionType) ColumnRef(org.voltdb.catalog.ColumnRef)

Aggregations

AbstractExpression (org.voltdb.expressions.AbstractExpression)6 SortDirectionType (org.voltdb.types.SortDirectionType)6 ArrayList (java.util.ArrayList)3 AbstractPlanNode (org.voltdb.plannodes.AbstractPlanNode)3 Constraint (org.voltdb.catalog.Constraint)2 TupleValueExpression (org.voltdb.expressions.TupleValueExpression)2 WindowFunctionExpression (org.voltdb.expressions.WindowFunctionExpression)2 OrderByPlanNode (org.voltdb.plannodes.OrderByPlanNode)2 SeqScanPlanNode (org.voltdb.plannodes.SeqScanPlanNode)2 WindowFunctionPlanNode (org.voltdb.plannodes.WindowFunctionPlanNode)2 VoltXMLElement (org.hsqldb_voltpatches.VoltXMLElement)1 JSONException (org.json_voltpatches.JSONException)1 ColumnRef (org.voltdb.catalog.ColumnRef)1 Index (org.voltdb.catalog.Index)1 ComparisonExpression (org.voltdb.expressions.ComparisonExpression)1 StmtTableScan (org.voltdb.planner.parseinfo.StmtTableScan)1 AbstractScanPlanNode (org.voltdb.plannodes.AbstractScanPlanNode)1 AggregatePlanNode (org.voltdb.plannodes.AggregatePlanNode)1 IndexScanPlanNode (org.voltdb.plannodes.IndexScanPlanNode)1 IndexUseForOrderBy (org.voltdb.plannodes.IndexUseForOrderBy)1