Skip to content

tyneq


tyneq / QueryPlanTransformer

Class: QueryPlanTransformer

Defined in: src/queryplan/QueryPlanTransformer.ts:36

Base class for immutable query plan rewriting.

Remarks

Recursively rebuilds the node chain, calling QueryPlanTransformer.transformNode once per node. The default implementation is an identity transform - every node is reconstructed with the same data, producing a structurally equivalent copy.

Subclasses override transformNode to intercept specific operators. Three rewrite patterns are possible:

  • Rewrite a node - return a new QueryNode with different operatorName or args
  • Remove a node - return source directly, skipping this node
  • Collapse two nodes into one - use source as the new node's source (fusing the current node with its already-transformed predecessor)

Example

ts
// Rename all 'where' nodes to 'filter' in the plan view
class RenameWhere extends QueryPlanTransformer {
    protected override transformNode(node: QueryPlanNode, source: QueryPlanNode | null): QueryPlanNode {
        if (node.operatorName === "where") {
            return new QueryNode("filter", node.args, source, node.category);
        }
        return super.transformNode(node, source);
    }
}

Extended by

Implements

Constructors

Constructor

new QueryPlanTransformer(): QueryPlanTransformer

Returns

QueryPlanTransformer

Methods

visit()

visit(node): IQueryNode

Defined in: src/queryplan/QueryPlanTransformer.ts:46

Transforms the full chain rooted at node and returns the new root node.

Parameters

ParameterType
nodeIQueryNode

Returns

IQueryNode

Remarks

Processes source-first (bottom-up): the source chain is fully transformed before transformNode is called for the current node. This means source passed to transformNode is always already the transformed predecessor.

Implementation of

QueryPlanVisitor.visit


transformNode()

protected transformNode(node, source): IQueryNode

Defined in: src/queryplan/QueryPlanTransformer.ts:62

Transforms a single node. Override to intercept specific operators.

Parameters

ParameterTypeDescription
nodeIQueryNodeThe original node (unmodified).
sourceNullable<IQueryNode>The transformed predecessor, or null for source nodes.

Returns

IQueryNode

Remarks

The default implementation reconstructs the node with identical data (identity transform). source is the already-transformed predecessor - use it as the source of any returned node to preserve chain continuity.