} else {
limitRows = Math.min(l, limitRows);
}
}
int columnCount = expressions.size();
LocalResult result = new LocalResult(session, expressionArray, visibleColumnCount);
if (!sortUsingIndex || distinct) {
result.setSortOrder(sort);
}
if (distinct && !isDistinctQuery) {
result.setDistinct();
}
topTableFilter.startQuery(session);
topTableFilter.reset();
boolean exclusive = isForUpdate && !isForUpdateMvcc;
topTableFilter.lock(session, exclusive, exclusive);
if (isForUpdateMvcc) {
if (isGroupQuery) {
throw DbException.getUnsupportedException("FOR UPDATE && GROUP");
} else if (distinct) {
throw DbException.getUnsupportedException("FOR UPDATE && DISTINCT");
} else if (isQuickAggregateQuery) {
throw DbException.getUnsupportedException("FOR UPDATE && AGGREGATE");
} else if (topTableFilter.getJoin() != null) {
throw DbException.getUnsupportedException("FOR UPDATE && JOIN");
} else if (topTableFilter.getJoin() != null) {
throw DbException.getUnsupportedException("FOR UPDATE && JOIN");
}
}
if (isQuickAggregateQuery) {
queryQuick(columnCount, result);
} else if (isGroupQuery) {
if (isGroupSortedQuery) {
queryGroupSorted(columnCount, result);
} else {
queryGroup(columnCount, result);
}
} else if (isDistinctQuery) {
queryDistinct(result, limitRows);
} else {
queryFlat(columnCount, result, limitRows);
}
if (offsetExpr != null) {
result.setOffset(offsetExpr.getValue(session).getInt());
}
if (limitRows != 0) {
result.setLimit(limitRows);
}
result.done();
return result;
}