diff --git a/src/lib.rs b/src/lib.rs index 2ccb398..8b26d85 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,3 +43,18 @@ pub mod materialized; /// An implementation of Query Rewriting, an optimization that rewrites queries to make use of materialized views. pub mod rewrite; + +/// Configuration options for materialized view related features. +#[derive(Debug, Clone)] +pub struct MaterializedConfig { + /// Whether or not query rewriting should exploit this materialized view. + pub use_in_query_rewrite: bool, +} + +impl Default for MaterializedConfig { + fn default() -> Self { + Self { + use_in_query_rewrite: true, + } + } +} diff --git a/src/materialized.rs b/src/materialized.rs index 4a0a7ac..e089591 100644 --- a/src/materialized.rs +++ b/src/materialized.rs @@ -44,6 +44,8 @@ use datafusion::{ use datafusion_expr::LogicalPlan; use itertools::Itertools; +use crate::MaterializedConfig; + /// The identifier of the column that [`RowMetadataSource`](row_metadata::RowMetadataSource) implementations should store row metadata in. pub const META_COLUMN: &str = "__meta"; @@ -102,6 +104,12 @@ pub fn cast_to_listing_table(table: &dyn TableProvider) -> Option<&dyn ListingTa pub trait Materialized: ListingTableLike { /// The query that defines this materialized view. fn query(&self) -> LogicalPlan; + + /// Configuration to control materialized view related features. + /// By default, returns the default value for [`MaterializedConfig`] + fn config(&self) -> MaterializedConfig { + MaterializedConfig::default() + } } /// Register a [`Materialized`] implementation in this registry. diff --git a/src/rewrite/exploitation.rs b/src/rewrite/exploitation.rs index 69c485b..b6fb761 100644 --- a/src/rewrite/exploitation.rs +++ b/src/rewrite/exploitation.rs @@ -60,6 +60,10 @@ impl ViewMatcher { continue; }; + if !mv.config().use_in_query_rewrite { + continue; + } + // Analyze the plan to normalize things such as wildcard expressions let analyzed_plan = session_state.analyzer().execute_and_check( mv.query(),