Skip to main content

Module window_topn

Module window_topn 

Source
Expand description

WindowTopN optimizer rule for per-partition top-K window queries.

Detects queries of the form:

SELECT * FROM (
    SELECT *, ROW_NUMBER() OVER (PARTITION BY pk ORDER BY val) as rn
    FROM t
) WHERE rn <= K;

And replaces the FilterExec โ†’ BoundedWindowAggExec โ†’ SortExec pipeline with BoundedWindowAggExec โ†’ PartitionedTopKExec(fetch=K), removing both the FilterExec and SortExec.

See PartitionedTopKExec for details on the replacement operator.

Structsยง

WindowTopN
Physical optimizer rule that converts per-partition ROW_NUMBER top-K queries into a more efficient plan using PartitionedTopKExec.