apache / apache/datafusion

Onyl recompute schema in `TypeCoercion` when necessary

Open
#10,365 0 comments 0 reactions 1 assignee Claimed by @alamb View on GitHub
enhancement
Dominant language
Rust
Stars
9.3k
Forks
2.4k
Avg merge
3d 7h
Merged PRs (30d)
344

Description

### Is your feature request related to a problem or challenge?

Part of https://github.com/apache/datafusion/issues/10210 we are trying to make the optimizer faster by making the different optimizer passes faster.

https://github.com/apache/datafusion/pull/10356 avoids a bunch of copies in the TypeCoercion pass

@peter-toth pointed out https://github.com/apache/datafusion/pull/10356/files#r1588892502 that this pass still does more work than necessary as it still always recomputes the schema, even when it didn't make any changes

The root cause for this is that the expression rewrite that happens via `TypeCoercionRewriter` doesn't return `Transformed` and thus we must conservatively assume that the schema needs to be recomputed

### Describe the solution you'd like

1. Change `TypeCoercionRewriter` to return Transformed somehow
2. Only call `LogicalPlan::recompute_schema` when the expression is actually transformed

### Describe alternatives you've considered

_No response_

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.