AbstractScanPlanNode scan_node = CollectionUtil.first(PlanNodeUtil.getPlanNodes(root, AbstractScanPlanNode.class));
assert (scan_node != null) : "Unexpected PlanTree:\n" + PlanNodeUtil.debug(root);
SendPlanNode send_node = (SendPlanNode) scan_node.getParent(0);
assert (send_node != null);
send_node.addIntermediary(limit_node);
if (orderby_node != null) {
limit_node.addIntermediary(orderby_node);
// Need to make sure that the LIMIT has the proper output columns
limit_node.setOutputColumns(orderby_node.getOutputColumnGUIDs());
state.markDirty(orderby_node);