TCQ Window Semantics

By Fred Reiss

Syntax

After each stream in a query there may appear a window clause in the form:
[ RANGE BY '<time>' SLIDE BY '<time>' START AT '<time>' ]
Together, these three parameters specify a sliding, hopping, or jumping time window over the stream.
The START AT parameter is optional; if you don't specify a START AT value, the first window will start at the end of the last second before the query was submitted.
Inside the query, a special aggregate, wtime(*), allows you to retrieve the rightmost endpoint of the current time window.

Semantics

Our current aggregate window semantics are as follows:

Implementation

Currently, sliding windows for aggregates are implemented by the Fjord Aggregate operator, located in src/backend/executor/nodeFAgg.c. This operator maintains a buffer of "live" join tuples and reevaluates the aggregation tree every time a window slides. Documentation for the algorithm and data structures the operator uses can be found at the top of nodeFAgg.c.
An interesting aspect of the implementation is the computation of "birth" and "death" times (the times when tuples become "live" and "dead," respectively) for join tuples. We compute the birth and death times as follows:
  1. For each base tuple in the join tuple, do the following:
    1. Compute the first and last time windows that the tuple appears in (also check to see whether the tuple appears in no windows at all)
    1. The birth time of the base tuple is at the end of the first window containing the tuple
    2. The death time of the base tuple is at the end of the window immediately after the last window that contains the tuple
  2. The birth time of the join tuple is the maximum of the birth times of its base tuples
  3. The death time of the join tuple is the minimum of those of the base tuples.

Windows and Shared Aggregates

Known Issues

The current implementation of sliding windows has several known issues: