Commit 215ebb8
authored
Fix union equivalence schema rewrite with stale constants (#23375)
## Which issue does this PR close?
- Closes #23374.
## Rationale for this change
`UnionExec::try_new` can panic while computing equivalence properties if
stale constant metadata is carried across a projection and then
rewritten to the union output schema.
In the observed shape, a filter such as `ticker = 'ESU6'` can leave a
uniform string constant in equivalence properties. After a parent
projection drops `ticker`, union property schema rewriting can see the
remaining column slot as a timestamp column and attempt to cast `'ESU6'`
to `Timestamp`, which fails during planning.
Equivalence constants are optimizer metadata, so an unrepresentable
constant after schema rewrite should be discarded rather than failing
query planning.
## What changes are included in this PR?
- Drops a uniform constant during
`EquivalenceProperties::with_new_schema` if its value cannot be cast to
the rewritten expression type.
- Removes trivial equivalence classes after dropping such constants.
- Propagates `UnionExec::compute_properties` errors from
`UnionExec::try_new` instead of unwrapping.
- Adds a regression test for union equivalence schema rewrite with an
unrepresentable stale constant value.
## Are these changes tested?
Yes:
## Are there any user-facing changes?
No API change. This prevents a planner panic for affected `UNION ALL` +
filter + projection query shapes.1 parent b790763 commit 215ebb8
3 files changed
Lines changed: 44 additions & 5 deletions
Lines changed: 12 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1314 | 1314 | | |
1315 | 1315 | | |
1316 | 1316 | | |
1317 | | - | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
1318 | 1329 | | |
1319 | 1330 | | |
1320 | 1331 | | |
| |||
Lines changed: 31 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
311 | 311 | | |
312 | 312 | | |
313 | 313 | | |
314 | | - | |
| 314 | + | |
315 | 315 | | |
316 | 316 | | |
317 | 317 | | |
| |||
899 | 899 | | |
900 | 900 | | |
901 | 901 | | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
902 | 932 | | |
903 | 933 | | |
904 | 934 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
134 | | - | |
135 | | - | |
| 133 | + | |
136 | 134 | | |
137 | 135 | | |
138 | 136 | | |
| |||
0 commit comments