Skip to content

Commit 3cfaa82

Browse files
author
Alexander Alexandrov
authored
Merge pull request #24155 from frankmcsherry/equivalence_propagation
Equivalence propagation
2 parents 2ef3deb + 151c0cd commit 3cfaa82

File tree

24 files changed

+1116
-101
lines changed

24 files changed

+1116
-101
lines changed

misc/python/materialize/mzcompose/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"enable_comment": "true",
6666
"enable_disk_cluster_replicas": "true",
6767
"enable_eager_delta_joins": "true",
68+
"enable_equivalence_propagation": "true",
6869
"enable_expressions_in_limit_syntax": "true",
6970
"enable_logical_compaction_window": "true",
7071
"enable_multi_worker_storage_persist_sink": "true",

src/adapter/src/optimize/mod.rs

+13-20
Original file line numberDiff line numberDiff line change
@@ -155,35 +155,28 @@ where
155155
///
156156
/// To add a new feature flag, do the following steps:
157157
///
158-
/// 1. To make the flag available to all stages in our [`Optimize`] pipelines:
159-
/// 1. Add the flag as an [`OptimizerConfig`] field.
160-
///
161-
/// 2. To allow engineers to set a system-wide override for this feature flag:
162-
/// 1. Add the flag to the `feature_flags!(...)` macro call.
163-
/// 2. Extend the `From<&SystemVars>` implementation for [`OptimizerConfig`].
158+
/// 1. To make the flag available to all stages in our [`Optimize`] pipelines
159+
/// and allow engineers to set a system-wide override:
160+
/// 1. Add the flag to the `optimizer_feature_flags!(...)` macro call.
161+
/// 2. Add the flag to the `feature_flags!(...)` macro call and extend the
162+
/// `From<&SystemVars>` implementation for [`OptimizerFeatures`].
164163
///
165-
/// 3. To enable `EXPLAIN ... WITH(...)` overrides which will allow engineers to
164+
/// 2. To enable `EXPLAIN ... WITH(...)` overrides which will allow engineers to
166165
/// inspect plan differences before deploying the optimizer changes:
167-
/// 1. Add the flag as a [`mz_repr::explain::ExplainConfig`] field.
168-
/// 2. Add the flag to the `ExplainPlanOptionName` definition.
169-
/// 3. Add the flag to the `generate_extracted_config!(ExplainPlanOption,
166+
/// 1. Add the flag to the `ExplainPlanOptionName` definition.
167+
/// 2. Add the flag to the `generate_extracted_config!(ExplainPlanOption,
170168
/// ...)` macro call.
171-
/// 4. Extend the `TryFrom<ExplainPlanOptionExtracted>` implementation for
169+
/// 3. Extend the `TryFrom<ExplainPlanOptionExtracted>` implementation for
172170
/// [`mz_repr::explain::ExplainConfig`].
173-
/// 5. Extend the `OverrideFrom<ExplainContext>` implementation for
174-
/// [`OptimizerConfig`].
175171
///
176-
/// 4. To enable `CLUSTER ... FEATURES(...)` overrides which will allow
172+
/// 3. To enable `CLUSTER ... FEATURES(...)` overrides which will allow
177173
/// engineers to experiment with runtime differences before deploying the
178174
/// optimizer changes:
179-
/// 1. Add the flag to the `optimizer_feature_flags!(...)` macro call.
180-
/// 2. Add the flag to the `ClusterFeatureName` definition.
181-
/// 3. Add the flag to the `generate_extracted_config!(ClusterFeature, ...)`
175+
/// 1. Add the flag to the `ClusterFeatureName` definition.
176+
/// 2. Add the flag to the `generate_extracted_config!(ClusterFeature, ...)`
182177
/// macro call.
183-
/// 4. Extend the `let optimizer_feature_overrides = ...` call in
178+
/// 3. Extend the `let optimizer_feature_overrides = ...` call in
184179
/// `plan_create_cluster`.
185-
/// 4. Extend the `OverrideFrom<OptimizerFeatureOverrides>` implementation
186-
/// for [`OptimizerConfig`].
187180
#[derive(Clone, Debug)]
188181
pub struct OptimizerConfig {
189182
/// The mode in which the optimizer runs.

src/repr/src/optimize.rs

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ optimizer_feature_flags!({
9797
enable_consolidate_after_union_negate: bool,
9898
// Bound from `SystemVars::enable_eager_delta_joins`.
9999
enable_eager_delta_joins: bool,
100+
// Enable the `EquivalencePropagation` transform in the optimizer.
101+
enable_equivalence_propagation: bool,
100102
// Bound from `SystemVars::enable_new_outer_join_lowering`.
101103
enable_new_outer_join_lowering: bool,
102104
// Bound from `SystemVars::enable_reduce_mfp_fusion`.

src/sql-lexer/src/keywords.txt

+2
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ End
138138
Endpoint
139139
Enforced
140140
Envelope
141+
Equivalence
141142
Error
142143
Escape
143144
Every
@@ -310,6 +311,7 @@ Primary
310311
Privatelink
311312
Privileges
312313
Progress
314+
Propagation
313315
Protobuf
314316
Protocol
315317
Publication

src/sql-parser/src/ast/defs/statement.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1732,6 +1732,7 @@ pub enum ClusterFeatureName {
17321732
ReoptimizeImportedViews,
17331733
EnableNewOuterJoinLowering,
17341734
EnableEagerDeltaJoins,
1735+
EnableEquivalencePropagation,
17351736
}
17361737

17371738
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
@@ -3093,6 +3094,7 @@ pub enum ExplainPlanOptionName {
30933094
ReoptimizeImportedViews,
30943095
EnableNewOuterJoinLowering,
30953096
EnableEagerDeltaJoins,
3097+
EnableEquivalencePropagation,
30963098
}
30973099

30983100
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]

src/sql/src/plan/statement/ddl.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -3336,7 +3336,8 @@ generate_extracted_config!(
33363336
ClusterFeature,
33373337
(ReoptimizeImportedViews, Option<bool>, Default(None)),
33383338
(EnableEagerDeltaJoins, Option<bool>, Default(None)),
3339-
(EnableNewOuterJoinLowering, Option<bool>, Default(None))
3339+
(EnableNewOuterJoinLowering, Option<bool>, Default(None)),
3340+
(EnableEquivalencePropagation, Option<bool>, Default(None))
33403341
);
33413342

33423343
pub fn plan_create_cluster(
@@ -3413,12 +3414,14 @@ pub fn plan_create_cluster(
34133414
reoptimize_imported_views,
34143415
enable_eager_delta_joins,
34153416
enable_new_outer_join_lowering,
3417+
enable_equivalence_propagation,
34163418
seen: _,
34173419
} = ClusterFeatureExtracted::try_from(features)?;
34183420
let optimizer_feature_overrides = OptimizerFeatureOverrides {
34193421
reoptimize_imported_views,
34203422
enable_eager_delta_joins,
34213423
enable_new_outer_join_lowering,
3424+
enable_equivalence_propagation,
34223425
..Default::default()
34233426
};
34243427

src/sql/src/plan/statement/dml.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ generate_extracted_config!(
353353
(Types, bool, Default(false)),
354354
(ReoptimizeImportedViews, Option<bool>, Default(None)),
355355
(EnableNewOuterJoinLowering, Option<bool>, Default(None)),
356-
(EnableEagerDeltaJoins, Option<bool>, Default(None))
356+
(EnableEagerDeltaJoins, Option<bool>, Default(None)),
357+
(EnableEquivalencePropagation, Option<bool>, Default(None))
357358
);
358359

359360
impl TryFrom<ExplainPlanOptionExtracted> for ExplainConfig {
@@ -395,6 +396,7 @@ impl TryFrom<ExplainPlanOptionExtracted> for ExplainConfig {
395396
types: v.types,
396397
features: OptimizerFeatureOverrides {
397398
enable_eager_delta_joins: v.enable_eager_delta_joins,
399+
enable_equivalence_propagation: v.enable_equivalence_propagation,
398400
enable_new_outer_join_lowering: v.enable_new_outer_join_lowering,
399401
reoptimize_imported_views: v.reoptimize_imported_views,
400402
..Default::default()

src/sql/src/session/vars/definitions.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2105,13 +2105,21 @@ feature_flags!(
21052105
internal: true,
21062106
enable_for_item_parsing: false,
21072107
},
2108+
{
2109+
name: enable_equivalence_propagation,
2110+
desc: "Enable the EquivalencePropagation transform in the optimizer",
2111+
default: true, // TODO(aalexandrov): revert this to false
2112+
internal: true,
2113+
enable_for_item_parsing: false,
2114+
},
21082115
);
21092116

21102117
impl From<&super::SystemVars> for OptimizerFeatures {
21112118
fn from(vars: &super::SystemVars) -> Self {
21122119
Self {
21132120
enable_consolidate_after_union_negate: vars.enable_consolidate_after_union_negate(),
21142121
enable_eager_delta_joins: vars.enable_eager_delta_joins(),
2122+
enable_equivalence_propagation: vars.enable_equivalence_propagation(),
21152123
enable_new_outer_join_lowering: vars.enable_new_outer_join_lowering(),
21162124
enable_reduce_mfp_fusion: vars.enable_reduce_mfp_fusion(),
21172125
persist_fast_path_limit: vars.persist_fast_path_limit(),

src/transform/src/analysis.rs

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
//! Traits and types for reusable expression analysis
1111
12+
pub mod equivalences;
13+
1214
use mz_expr::MirRelationExpr;
1315

1416
pub use common::{Derived, DerivedBuilder, DerivedView};
@@ -121,6 +123,7 @@ pub mod common {
121123
///
122124
/// This is best thought of as a node in a tree rather
123125
#[allow(missing_debug_implementations)]
126+
#[derive(Copy, Clone)]
124127
pub struct DerivedView<'a> {
125128
derived: &'a Derived,
126129
lower: usize,

0 commit comments

Comments
 (0)