IF Commons GitHub

aide/plan/mod

Planning (commons lang-sql 0010-aide FR-006, FR-007): a query over one table as a plan of scan, filter, sort, project and limit, written as text by explain, and split, which divides a plan between a backend that can do some of it and the process that does the rest, so that the residual run on what the backend gives is what the whole plan gives.

Spec: 0010-aide FR-006, FR-007

Source: commons/lang-sql/src/aide/plan/mod.ts

4 of 8 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

Plantypeno test imports it
type Plan = | { readonly kind: "scan"; readonly table: string; readonly alias: string; /** the backend has done the wo… (592 characters)
type Plan =
  | { readonly kind: "scan"; readonly table: string; readonly alias: string; /** the backend has done the work of the plan below it */ readonly pushed: boolean }
  | { readonly kind: "filter"; readonly input: Plan; readonly predicate: Expr }
  | { readonly kind: "sort"; readonly input: Plan; readonly order: readonly OrderItem[] }
  | { readonly kind: "project"; readonly input: Plan; readonly items: readonly SelectItem[]; readonly distinct: boolean }
  | { readonly kind: "limit"; readonly input: Plan; readonly limit: number | undefined; readonly offset: number | undefined };

A logical plan of a query over one table.

PlanErrorinterfaceno test imports it
interface PlanError

A construct the planner does not plan.

MemberTypeWhat it is
startnumber
endnumber
messagestring
planfunction
function plan(select: Select, bound: Bound): Result<Plan, readonly PlanError[]>

The plan of a query over one table; an error value for a construct it does not plan.

Imported by 8 tests of the run (8 passed, 0 failed): the library's results

explainfunction
function explain(p: Plan): string

A plan as text, one operator on a line, the input of an operator below it and indented.

Imported by 8 tests of the run (8 passed, 0 failed): the library's results

Capabilitiesinterface
interface Capabilities

What a backend can do.

MemberTypeWhat it is
canEval(expr: Expr) => booleanWhether the backend evaluates this expression exactly as SQL does.
sortbooleanWhether it orders by expressions it can evaluate.
limitbooleanWhether it limits the rows it gives.

Imported by 8 tests of the run (8 passed, 0 failed): the library's results

Pushedinterfaceno test imports it
interface Pushed

What goes to the backend.

MemberTypeWhat it is
tablestring
aliasstring
predicateExpr | undefined
sortreadonly OrderItem[] | undefined
limit{ readonly limit: number | undefined; readonly offset: number | undefined; } | undefined
Splitinterfaceno test imports it
interface Split

A plan divided between a backend and the process.

MemberTypeWhat it is
pushedPushed
residualPlanWhat the process runs on the rows of the pushed part.
splitfunction
function split(p: Plan, caps: Capabilities): Split

Divides a plan: each conjunct the backend can evaluate is pushed, the sort where the backend can, the limit where nothing stands between.

Imported by 8 tests of the run (8 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.