A window over a whole partition is a join with its grouping #
A window whose frame is the whole partition asks of each row exactly what a grouping asks of its group. It should therefore be expressible without a window at all: join every row with the group row of its own partition, and keep the group's aggregate column.
That is what this module proves, over plain relations and over annotated
ones. The plain statement is a rearrangement. The annotated statement is
not: the join carries the group's existence factor δ(⊕ U) into the row's
annotation, which the window never produces, and the two agree only because
the group of a row contains that row – so the factor reads
α ⊗ δ(α ⊕ β'), which is α by δ-absorption. A frame that excluded the
current row would have no such identity, and no such rewriting.
The join picks one group per row #
Joining on a key picks out one entry per row. A table with distinct keys, joined with a relation on the key, gives each row exactly the entry of its own key – so the join has as many rows as the relation, one per row.
Dependency graph
The window written as a join #
The composite is the one of the semantics: join the query with its own grouping on the partition key, keep the original columns and the group's aggregate column.
The kind vector of a query joined with its grouping: the query's own columns, then the group key, then the aggregate token.
Equations
- AggQueryIn.winJoinKinds n m = Fin.append (ColKind.allReg n) (ColKind.gammaKinds m 1)
Instances For
Dependency graph
The position of an original column in the join.
Equations
- AggQueryIn.winLeftPos m k = Fin.castAdd (m + 1) k
Instances For
Dependency graph
The position of a group-key column in the join.
Equations
- AggQueryIn.winKeyPos n j = Fin.natAdd n (Fin.castAdd 1 j)
Instances For
Dependency graph
The position of the aggregate column in the join.
Equations
- AggQueryIn.winAggPos n m = Fin.natAdd n (Fin.natAdd m 0)
Instances For
Dependency graph
Dependency graph
Dependency graph
Dependency graph
The projection keeping the original columns and the aggregate.
Equations
- AggQueryIn.winProj n m = Fin.snoc (fun (k : Fin n) => ProjColIn.term (TermGIn.index (AggQueryIn.winLeftPos m k) ⋯)) (ProjColIn.token (AggQueryIn.winAggPos n m) ⋯)
Instances For
Dependency graph
Dependency graph
A window over a whole partition, written without a window: join the query with its grouping on the partition key, and keep the group's aggregate column.
Equations
- One or more equations did not get rendered due to their size.