Skip to content

Commit 914a391

Browse files
committed
docs: state that wrapper rules must forward skip_if_unchanged
The optimizer consults the rule it holds, so a rule that runs other rules inside its own optimize() decides for all of them. A wrapper leaving this at the default silently opts its inner rules out of the skip, which is the same trap apache#25316 describes for schema_check(). Say so where an implementor reads it, with the all() form, since a wrapper is skippable only if every rule it would have run is.
1 parent 6b1731c commit 914a391

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

‎datafusion/session/src/physical_optimizer.rs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ pub trait PhysicalOptimizerRule: Debug + std::any::Any {
9797
/// counters, randomness — since the same input would no longer imply the
9898
/// same output. Debug builds verify the claim: when a skip would fire,
9999
/// the rule is run anyway and the result is asserted to be unchanged.
100+
///
101+
/// The optimizer reads this from the rule it holds, so a rule that runs
102+
/// *other* rules inside its own [`optimize`] must forward their answer —
103+
/// in practice `all()` over the rules it wraps, since the wrapper is only
104+
/// skippable if every rule it would have run is. A wrapper that leaves
105+
/// this at the default silently opts its inner rules out:
106+
///
107+
/// ```text
108+
/// fn skip_if_unchanged(&self) -> bool {
109+
/// self.wrapped.iter().all(|rule| rule.skip_if_unchanged())
110+
/// }
111+
/// ```
112+
///
113+
/// [`optimize`]: PhysicalOptimizerRule::optimize
100114
fn skip_if_unchanged(&self) -> bool {
101115
false
102116
}

0 commit comments

Comments
 (0)