import { omitFanout } from "./planner-node.js";
class PlannerFanOut {
  kind = "fan-out";
  #type;
  #outputs = [];
  #input;
  constructor(input) {
    this.#type = "FO";
    this.#input = input;
  }
  get type() {
    return this.#type;
  }
  addOutput(node) {
    this.#outputs.push(node);
  }
  get outputs() {
    return this.#outputs;
  }
  closestJoinOrSource() {
    return this.#input.closestJoinOrSource();
  }
  propagateConstraints(branchPattern, constraint, from, planDebugger) {
    planDebugger?.log({
      type: "node-constraint",
      nodeType: "fan-out",
      node: "FO",
      branchPattern,
      constraint,
      from: from?.kind ?? "unknown"
    });
    this.#input.propagateConstraints(
      branchPattern,
      constraint,
      this,
      planDebugger
    );
  }
  estimateCost(downstreamChildSelectivity, branchPattern, planDebugger) {
    const ret = this.#input.estimateCost(
      downstreamChildSelectivity,
      branchPattern,
      planDebugger
    );
    if (planDebugger) {
      planDebugger.log({
        type: "node-cost",
        nodeType: "fan-out",
        node: "FO",
        branchPattern,
        downstreamChildSelectivity,
        costEstimate: omitFanout(ret)
      });
    }
    return ret;
  }
  convertToUFO() {
    this.#type = "UFO";
  }
  reset() {
    this.#type = "FO";
  }
  /**
   * Propagate unlimiting when a parent join is flipped.
   * Fan-out propagates to its input.
   */
  propagateUnlimitFromFlippedJoin() {
    if ("propagateUnlimitFromFlippedJoin" in this.#input && typeof this.#input.propagateUnlimitFromFlippedJoin === "function") {
      this.#input.propagateUnlimitFromFlippedJoin();
    }
  }
}
export {
  PlannerFanOut
};
//# sourceMappingURL=planner-fan-out.js.map
