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
Optimize redundant calls to UDFs producing StructArray #23655
Is your feature request related to a problem or challenge?
Since UDF can only return a single column as output, returning a StructArray is desired in many cases. However, accessing fields of the returned struct results in redundant calls to the UDF.
SELECT
example_struct(c)['a'],
example_struct(c)['b']
FROM (SELECT unnest(range(1,100)) as c)
Datafusion produces the following projection step for the query, resulting in calling the UDF with the same column twice.
ProjectionExec: expr=[get_field(example_struct(c@0), a) as example_struct(c)[a], get_field(example_struct(c@0), b) as example_struct(c)[b]]
Note that calling the UDF in a CTE or view does not change the execution plan.
Activity
tohuya6 commentedon Jul 17, 2026
take
fix(optimizer): evaluate struct-returning UDFs once across repeated f…
fix: evaluate struct-returning UDFs once across repeated field accesses
fix: evaluate struct-returning UDFs once across repeated field accesses
fix(optimizer): count bare references when guarding KeepInPlace merges
fix: evaluate struct-returning UDFs once across repeated field access…
test: cover merge_would_duplicate_kept_expr site counting
test: close five mutation-testing gaps in leaf expression pushdown gu…
test: cover a struct-returning function evaluated one time in `cse.slt`
fix: evaluate struct-returning UDFs once across repeated field access…
test: close five mutation-testing gaps in leaf expression pushdown gu…