Skip to content

Commit 4071577

Browse files
authored
Expose a get_mv_candidates_for_table API for ViewMatcher (#112)
* Expose a get_mv_candidates_for_table API for ViewMatcher * refine comments
1 parent 547aa4d commit 4071577

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/rewrite/exploitation.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,43 @@ impl ViewMatcher {
119119
pub fn mv_plans(&self) -> &HashMap<TableReference, (Arc<dyn TableProvider>, SpjNormalForm)> {
120120
&self.mv_plans
121121
}
122+
123+
/// Returns materialized views that potentially reference the given table.
124+
///
125+
/// This is a preliminary filter - it only checks if the MV references the table
126+
/// but does NOT guarantee that the MV can actually be used to rewrite queries
127+
/// involving that table.
128+
///
129+
/// # Arguments
130+
///
131+
/// * `table_reference` - The table reference to find candidates for
132+
///
133+
/// # Returns
134+
///
135+
/// A vector of tuples containing:
136+
/// - The materialized view's table reference
137+
/// - The materialized view's table provider
138+
/// - The materialized view's SPJ normal form
139+
pub fn get_potential_mv_candidates_for_table(
140+
&self,
141+
table_reference: &TableReference,
142+
) -> Vec<(TableReference, Arc<dyn TableProvider>, &SpjNormalForm)> {
143+
self.mv_plans
144+
.iter()
145+
.filter_map(|(mv_table_ref, (mv_provider, mv_normal_form))| {
146+
// Check if this MV references the target table
147+
if mv_normal_form.referenced_tables().contains(table_reference) {
148+
Some((
149+
mv_table_ref.clone(),
150+
Arc::clone(mv_provider),
151+
mv_normal_form,
152+
))
153+
} else {
154+
None
155+
}
156+
})
157+
.collect()
158+
}
122159
}
123160

124161
impl OptimizerRule for ViewMatcher {

0 commit comments

Comments
 (0)