ColinLeeo commented on code in PR #18869: URL: https://github.com/apache/iotdb/pull/18869#discussion_r4313071079
########## iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/SharedExchangeMemoryEligibility.java: ########## @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iotdb.db.queryengine.plan.planner; + +import org.apache.iotdb.commons.queryengine.plan.planner.plan.node.PlanNode; +import org.apache.iotdb.commons.queryengine.plan.relational.planner.node.CollectNode; +import org.apache.iotdb.commons.queryengine.plan.relational.planner.node.TopKNode; +import org.apache.iotdb.commons.queryengine.plan.relational.planner.node.UnionNode; +import org.apache.iotdb.db.queryengine.plan.relational.planner.node.ExchangeNode; + +import java.util.ArrayDeque; +import java.util.Deque; +import java.util.List; + +/** Select shared budgets only for FIs whose fan-in can consume any ready input. */ +final class SharedExchangeMemoryEligibility { + private SharedExchangeMemoryEligibility() {} + + static boolean isEligible(PlanNode root) { + boolean hasCollect = false; + Deque<PlanNode> nodes = new ArrayDeque<>(); + nodes.push(root); + while (!nodes.isEmpty()) { + PlanNode node = nodes.pop(); + if (node instanceof ExchangeNode) { + // An upstream plan, if still attached, belongs to a different FI. + continue; + } + // TopK's input ordering assumptions remain unchanged, including its single-child form. + if (node instanceof TopKNode) { + return false; + } Review Comment: Thanks for the review. - TopK: It remains excluded from ready-first consumption in this PR. We believe it has potential for a similar optimization, but that should be explored separately. - COPY TO: The same target device can appear in multiple children. Even when children are consumed sequentially, their time ranges may overlap or be consumed in the wrong order, producing non-increasing timestamps for that device. Therefore, COPY TO could already fail before this change; sequential Collect was never a general ordering guarantee. By design, users should specify an appropriate ORDER BY in the source query when needed to satisfy the writer’s ordering requirement. Explicit ordering must continue to be preserved. - FILL / diff(): These operations depend on the input sequence, but without defined input ordering, the previous Collect sequence is not guaranteed. Different values alone therefore do not establish a correctness violation. FILL_GROUP and explicit input ordering remain enforced by the planner. For these reasons, I don’t think we need additional ready-first restrictions for COPY TO, FILL, or diff() in this PR. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
