import { QueryAST } from '@dxos/echo-protocol'; import { QueryPlan } from './plan.ts'; export type QueryPlannerOptions = { defaultTextSearchKind: QueryPlan.TextSearchKind; /** * When true, downgrade index-backed selectors to WildcardSelector + FilterStep. * Use when executing against an in-memory working set without SQL index access. * TextSelector and TimestampSelector remain as-is so the caller can detect them and bail. */ noIndexes?: boolean; }; /** * Constructs an optimized query plan. */ export declare class QueryPlanner { private readonly _options; constructor(options?: Partial); /** The uncompiled steps. Pure, so the SQL compiler recurses through it for `in-query` subqueries. */ createPlan(query: QueryAST.Query): QueryPlan.Plan; private _validateChangesFilters; private _routeChanges; /** * Marks the select of a plan that only counts objects by index fields as {@link QueryPlan.SelectStep.bare}, * so the executor groups index rows instead of loading documents. Eligible shape: a space-scoped * wildcard, type or timestamp select, then deleted handling, a plain typename re-check and natural * ordering in any order, ending in an aggregate of `count`, `type` and `timestamp` only. */ private _optimizeBareAggregate; private _generate; private _generateOptionsClause; private _generateFromClause; private _generateSelectClause; private _generateSelectionFromFilter; private _generateDeletedHandlingSteps; private _generateUnionClause; private _generateSetDifferenceClause; private _generateReferenceTraversalClause; private _generateIncomingReferencesClause; private _generateRelationTraversalClause; private _generateRelationClause; private _generateFilterClause; private _generateHierarchyTraversalClause; private _validateQueryScoped; /** * `aggregate` must be the outermost data clause: only `from()`/`options()` and the group-level * pagination clauses `limit()`/`skip()` may wrap it. At most one `aggregate` may appear anywhere * in the tree — including inside a `.from(subquery)` source, which the planner flattens (so an * aggregated subquery would otherwise produce an unsupported double-`aggregate`). The DSL's types * can't enforce this (`Query` still exposes `orderBy`/`select`/etc.), so * it's validated here at plan time. * * `limit`/`skip` above an `aggregate` page over whole groups (see the group-aware `LimitStep`/ * `SkipStep` execution); a `limit`/`skip` below it windows the flat object stream before aggregating. */ private _validateAggregatePlacement; /** * Removes filter steps that have no predicates. */ private _optimizeEmptyFilters; /** * Removes union steps that have only one child. */ private _optimizeSoloUnions; private _generateOrderClause; private _generateLimitClause; private _generateSkipClause; private _generateAggregateClause; private _ensureOrderStep; /** * Propagates limits from LimitStep to SelectStep and OrderStep when possible. * Limits can only be propagated if there are no unions or traversals between the LimitStep and SelectStep/OrderStep. */ private _optimizeLimits; } export declare const queryContainsChanges: (query: QueryAST.Query) => boolean; /** * Returns true if the filter is a subquery-membership predicate (`Filter.in(query.project(...))`, * AST type `in-query`) or composes one via `and` / `or` / `not` / a nested `object` prop. Unlike * `child-of`, which is only ever a root filter, `in-query` is always nested inside an `object` * filter's `props` — the residual FilterStep produced by `_generateSelectionFromFilter`'s `object` * case (above) is always `type: 'object'`, so this must recurse into `props` to find it. * * Exported (unlike the sibling `_filterContains*` helpers) so `query-executor.ts`'s `extractScopes` * can reuse it — a bare `filter.type === 'in-query'` check there would miss the common case. */ export declare const filterContainsInQuery: (filter: QueryAST.Filter) => boolean; //# sourceMappingURL=query-planner.d.ts.map