prestodb / presto

The official home of the Presto distributed SQL query engine for big data
http://prestodb.io
Apache License 2.0
15.75k stars 5.29k forks source link

preSorting for Prestissimo Window node #23125

Open aditi-pandit opened 3 days ago

aditi-pandit commented 3 days ago

Presto Java has property preSortedPrefix set by the optimizer to indicate which group of partition + sort keys are already presorted in the window input. This can be used to optimize the sorting in Prestissimo Window operator.

Velox window operator already has an inputsSorted_ field that uses a WindowBuild which skips sorting as an optimization when the preSortedPrefix is the full set of partition by + order by fields. This can be easily used as a first optimization.

Subsequent optimizations to use presortedKeys (which are a subset of the partition keys + order by keys) as an optimization in the global sort in SortWindowBuild can be done as well.

@amitkdutta