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
QueryNodewith differentoperatorNameorargs - Remove a node - return
sourcedirectly, skipping this node - Collapse two nodes into one - use
sourceas the new node'ssource(fusing the current node with its already-transformed predecessor)
Example
// 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
| Parameter | Type |
|---|---|
node | IQueryNode |
Returns
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
transformNode()
protectedtransformNode(node,source):IQueryNode
Defined in: src/queryplan/QueryPlanTransformer.ts:62
Transforms a single node. Override to intercept specific operators.
Parameters
| Parameter | Type | Description |
|---|---|---|
node | IQueryNode | The original node (unmodified). |
source | Nullable<IQueryNode> | The transformed predecessor, or null for source nodes. |
Returns
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.