Skip to content

Commit 1ffaad5

Browse files
authored
exclude some materialized views from query rewriting (#57)
* exclude some materialized views from query rewriting * newline at EOF * fmt
1 parent 54d810c commit 1ffaad5

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,18 @@ pub mod materialized;
4343

4444
/// An implementation of Query Rewriting, an optimization that rewrites queries to make use of materialized views.
4545
pub mod rewrite;
46+
47+
/// Configuration options for materialized view related features.
48+
#[derive(Debug, Clone)]
49+
pub struct MaterializedConfig {
50+
/// Whether or not query rewriting should exploit this materialized view.
51+
pub use_in_query_rewrite: bool,
52+
}
53+
54+
impl Default for MaterializedConfig {
55+
fn default() -> Self {
56+
Self {
57+
use_in_query_rewrite: true,
58+
}
59+
}
60+
}

src/materialized.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ use datafusion::{
4444
use datafusion_expr::LogicalPlan;
4545
use itertools::Itertools;
4646

47+
use crate::MaterializedConfig;
48+
4749
/// The identifier of the column that [`RowMetadataSource`](row_metadata::RowMetadataSource) implementations should store row metadata in.
4850
pub const META_COLUMN: &str = "__meta";
4951

@@ -102,6 +104,12 @@ pub fn cast_to_listing_table(table: &dyn TableProvider) -> Option<&dyn ListingTa
102104
pub trait Materialized: ListingTableLike {
103105
/// The query that defines this materialized view.
104106
fn query(&self) -> LogicalPlan;
107+
108+
/// Configuration to control materialized view related features.
109+
/// By default, returns the default value for [`MaterializedConfig`]
110+
fn config(&self) -> MaterializedConfig {
111+
MaterializedConfig::default()
112+
}
105113
}
106114

107115
/// Register a [`Materialized`] implementation in this registry.

src/rewrite/exploitation.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ impl ViewMatcher {
6060
continue;
6161
};
6262

63+
if !mv.config().use_in_query_rewrite {
64+
continue;
65+
}
66+
6367
// Analyze the plan to normalize things such as wildcard expressions
6468
let analyzed_plan = session_state.analyzer().execute_and_check(
6569
mv.query(),

0 commit comments

Comments
 (0)