PlanNode rewrittenSource = planRewriter.rewrite(node.getSource(), Long.MAX_VALUE);
if (limit != Long.MAX_VALUE) {
return new TopNNode(node.getId(), rewrittenSource, limit, node.getOrderBy(), node.getOrderings(), false);
}
else if (rewrittenSource != node.getSource()) {
return new SortNode(node.getId(), rewrittenSource, node.getOrderBy(), node.getOrderings());
}
return node;
}