Skip to content

Commit bacc017

Browse files
committed
Fix SingleTimeMonotonic to take into account FlatMap's TableFunc's preserves_monotonicity
1 parent 779f893 commit bacc017

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/compute-types/src/plan/interpret/physically_monotonic.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,10 @@ impl Interpreter for SingleTimeMonotonic<'_> {
139139
_input_key: &Option<Vec<MirScalarExpr>>,
140140
input: Self::Domain,
141141
_exprs: &Vec<MirScalarExpr>,
142-
_func: &TableFunc,
142+
func: &TableFunc,
143143
_mfp: &MapFilterProject,
144144
) -> Self::Domain {
145-
// In a single-time context, we just propagate the monotonicity
146-
// status of the input
147-
input
145+
PhysicallyMonotonic(input.0 && func.preserves_monotonicity())
148146
}
149147

150148
fn join(

test/sqllogictest/transform/relax_must_consolidate.slt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,8 +1217,12 @@ COMPLETE 0
12171217
statement ok
12181218
CREATE SOURCE mono_src FROM WEBHOOK BODY FORMAT TEXT;
12191219

1220-
# Regression test for https://github.com/MaterializeInc/database-issues/issues/11310
1220+
# Regression test for https://github.com/MaterializeInc/database-issues/issues/11310, i.e., that we set the
1221+
# `must_consolidate` flag when `repeat_row` is involved.
12211222
# Relies on RelaxMustConsolidate's SingleTimeMonotonic correctly handling FlatMap's TableFunc being !preserves_monotonicity.
1223+
# Note that the plans are still somewhat wrong, in that monotonic operators won't produce correct results when presented
1224+
# with negative accumulations even with the `must_consolidate` flag set. However, the expectation is that they'll have
1225+
# an easier time detecting negative accumulations and cleanly erroring out when the `must_consolidate` flag is set.
12221226
query T multiline
12231227
EXPLAIN PHYSICAL PLAN AS VERBOSE TEXT FOR
12241228
SELECT MAX(body) FROM mono_src, repeat_row(length(body));
@@ -1229,6 +1233,7 @@ Explained Query:
12291233
Reduce::Hierarchical
12301234
aggr_funcs=[max]
12311235
monotonic
1236+
must_consolidate
12321237
key_plan
12331238
project=()
12341239
val_plan=id

0 commit comments

Comments
 (0)