galaxytemple commented on PR #27646:
URL: https://github.com/apache/datafusion/pull/27646#issuecomment-7091420312
Thanks for the review @jayzhan211! I applied the
EquivalenceProperties::normalize_mapping change and the regression test.
I also checked where else volatile expressions could enter equivalence
properties and found the following SQL cases, so I added guards in
EquivalenceGroup::add_equal_conditions and EquivalenceGroup::add_constant as
well.
- EquivalenceGroup::add_equal_conditions
1) Two filter predicates comparing against the same volatile expression
```sql
EXPLAIN SELECT a, b FROM (
SELECT a, b FROM volatile_eq_t WHERE a = floor(random() * 3) AND b =
floor(random() * 3)
UNION ALL
SELECT a, b FROM volatile_eq_t WHERE a = floor(random() * 3) AND b =
floor(random() * 3)
) ORDER BY a, b;
```
2) Projecting the same volatile expression above the filter projected
```sql
EXPLAIN SELECT a, r FROM (
SELECT a, floor(random() * 3) AS r FROM volatile_eq_t WHERE a =
floor(random() * 3)
UNION ALL
SELECT a, floor(random() * 3) AS r FROM volatile_eq_t WHERE a =
floor(random() * 3)
) ORDER BY a, r;
```
- EquivalenceGroup::add_constant
(datafusion/physical-expr/src/equivalence/class.rs)
Filtering `floor(random() * 3) = 1` registered `floor(random() * 3)` as a
constant
```sql
EXPLAIN SELECT a FROM (
SELECT a FROM volatile_eq_t WHERE floor(random() * 3) = 1
) ORDER BY floor(random() * 3);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]