You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Exponential planning time when window function is partitioned by multiple columns #17401
changed the title [-]Long planning time when window function is partitioned by multiple columns[/-][+]Exponential planning time when window function is partitioned by multiple columns[/+]on Sep 4, 2025
Improve Planning Time #13015 -- but that one does not involve aggregate functions. It indicates EquivalenceProperties as the culprit and my naive analysis also points at that class.
( cd datafusion-cli && cargo run --bin datafusion-cli -- --command "WITH source AS ( SELECT 1 AS n, '' AS a1, '' AS a2, '' AS a3, '' AS a4, '' AS a5, '' AS a6, '' AS a7, '' AS a8, '' AS a9, '' AS a10, '' AS a11, '' AS a12)SELECT sum(n) OVER (PARTITION BY a1, a2, a3, a4, a5, a6, a7, a8, a9 )FROM source;"; )
it resulted in
ea0686b8ce4b45cb61ba7fecac563cfa17f13595 is the first bad commit
commit ea0686b8ce4b45cb61ba7fecac563cfa17f13595 (HEAD)
Date: Wed Feb 26 17:35:37 2025 +0300
Window Functions Order Conservation -- Follow-up On Set Monotonicity (#14813)
for each of N input expressions, sort_options_resolving_constant returns pair of values (N pairs)
then multi_cartesian_product calculates cartesian product of these pairs, 2^N combinations
Perhaps we can find a way of detecting redundancy of the order propagation over window ops (or just a simple rule) and skip those high complexity calculations
Activity
[-]Long planning time when window function is partitioned by multiple columns[/-][+]Exponential planning time when window function is partitioned by multiple columns[/+]findepi commentedon Sep 4, 2025
Related issues
EquivalencePropertiesas the culprit and my naive analysis also points at that class.UNIONandORDER BYqueries #13748 -- because that one is also about exponential planning time, however talks about UNION and ORDER BY, here we have only a window functionfindepi commentedon Sep 4, 2025
I run
git bisect, inspecting timing of the queryit resulted in
cc @berkaysynnada @ozankabak @Omega359 @alamb
findepi commentedon Sep 4, 2025
Some code pieces with seemingly exponential complexity
datafusion/datafusion/physical-plan/src/windows/mod.rs
Lines 375 to 376 in a5c242c
sort_options_resolving_constantreturns pair of values (N pairs)then
multi_cartesian_productcalculates cartesian product of these pairs, 2^N combinationsdatafusion/datafusion/physical-plan/src/windows/mod.rs
Lines 469 to 470 in a5c242c
However, every usage of
multi_cartesian_productlooks suspicious.For example, this one looks also dangerous, just not related to window functions
datafusion/datafusion/expr-common/src/signature.rs
Line 551 in 9e062df
berkaysynnada commentedon Sep 6, 2025
Perhaps we can find a way of detecting redundancy of the order propagation over window ops (or just a simple rule) and skip those high complexity calculations
findepi commentedon Sep 9, 2025
@berkaysynnada has an idea how to replace the exponential algorithm with a linear one: #14813 (comment)
🚀