risingwave_frontend/optimizer/rule/
mod.rsuse std::convert::Infallible;
use std::ops::FromResidual;
use thiserror_ext::AsReport;
use super::PlanRef;
use crate::error::RwError;
pub enum ApplyResult<T = PlanRef> {
Ok(T),
NotApplicable,
Err(RwError),
}
impl ApplyResult {
pub fn unwrap(self) -> PlanRef {
match self {
ApplyResult::Ok(plan) => plan,
ApplyResult::NotApplicable => panic!("unwrap ApplyResult::NotApplicable"),
ApplyResult::Err(e) => panic!("unwrap ApplyResult::Err, error: {:?}", e.as_report()),
}
}
}
impl<T> FromResidual<Option<Infallible>> for ApplyResult<T> {
fn from_residual(residual: Option<Infallible>) -> Self {
match residual {
Some(i) => match i {},
None => Self::NotApplicable,
}
}
}
impl<T, E> FromResidual<Result<Infallible, E>> for ApplyResult<T>
where
E: Into<RwError>,
{
fn from_residual(residual: Result<Infallible, E>) -> Self {
match residual {
Ok(i) => match i {},
Err(e) => Self::Err(e.into()),
}
}
}
trait InfallibleRule: Send + Sync + Description {
fn apply(&self, plan: PlanRef) -> Option<PlanRef>;
}
use InfallibleRule as Rule;
pub trait FallibleRule: Send + Sync + Description {
fn apply(&self, plan: PlanRef) -> ApplyResult;
}
impl<T> FallibleRule for T
where
T: InfallibleRule,
{
fn apply(&self, plan: PlanRef) -> ApplyResult {
match InfallibleRule::apply(self, plan) {
Some(plan) => ApplyResult::Ok(plan),
None => ApplyResult::NotApplicable,
}
}
}
pub trait Description {
fn description(&self) -> &str;
}
pub(super) type BoxedRule = Box<dyn FallibleRule>;
mod logical_filter_expression_simplify_rule;
pub use logical_filter_expression_simplify_rule::*;
mod over_window_merge_rule;
pub use over_window_merge_rule::*;
mod project_join_merge_rule;
pub use project_join_merge_rule::*;
mod project_eliminate_rule;
pub use project_eliminate_rule::*;
mod project_merge_rule;
pub use project_merge_rule::*;
mod pull_up_correlated_predicate_rule;
pub use pull_up_correlated_predicate_rule::*;
mod index_delta_join_rule;
pub use index_delta_join_rule::*;
mod left_deep_tree_join_ordering_rule;
pub use left_deep_tree_join_ordering_rule::*;
mod apply_agg_transpose_rule;
pub use apply_agg_transpose_rule::*;
mod apply_filter_transpose_rule;
pub use apply_filter_transpose_rule::*;
mod apply_project_transpose_rule;
pub use apply_project_transpose_rule::*;
mod apply_eliminate_rule;
pub use apply_eliminate_rule::*;
mod translate_apply_rule;
pub use translate_apply_rule::*;
mod merge_multijoin_rule;
pub use merge_multijoin_rule::*;
mod max_one_row_eliminate_rule;
pub use max_one_row_eliminate_rule::*;
mod apply_join_transpose_rule;
pub use apply_join_transpose_rule::*;
mod apply_to_join_rule;
pub use apply_to_join_rule::*;
mod distinct_agg_rule;
pub use distinct_agg_rule::*;
mod index_selection_rule;
pub use index_selection_rule::*;
mod push_calculation_of_join_rule;
pub use push_calculation_of_join_rule::*;
mod join_commute_rule;
mod over_window_to_agg_and_join_rule;
pub use over_window_to_agg_and_join_rule::*;
mod over_window_split_rule;
pub use over_window_split_rule::*;
mod over_window_to_topn_rule;
pub use join_commute_rule::*;
pub use over_window_to_topn_rule::*;
mod union_to_distinct_rule;
pub use union_to_distinct_rule::*;
mod agg_project_merge_rule;
pub use agg_project_merge_rule::*;
mod union_merge_rule;
pub use union_merge_rule::*;
mod dag_to_tree_rule;
pub use dag_to_tree_rule::*;
mod apply_share_eliminate_rule;
pub use apply_share_eliminate_rule::*;
mod top_n_on_index_rule;
pub use top_n_on_index_rule::*;
mod stream;
pub use stream::bushy_tree_join_ordering_rule::*;
pub use stream::filter_with_now_to_join_rule::*;
pub use stream::generate_series_with_now_rule::*;
pub use stream::split_now_and_rule::*;
pub use stream::split_now_or_rule::*;
pub use stream::stream_project_merge_rule::*;
mod trivial_project_to_values_rule;
pub use trivial_project_to_values_rule::*;
mod union_input_values_merge_rule;
pub use union_input_values_merge_rule::*;
mod rewrite_like_expr_rule;
pub use rewrite_like_expr_rule::*;
mod min_max_on_index_rule;
pub use min_max_on_index_rule::*;
mod always_false_filter_rule;
pub use always_false_filter_rule::*;
mod join_project_transpose_rule;
pub use join_project_transpose_rule::*;
mod limit_push_down_rule;
pub use limit_push_down_rule::*;
mod pull_up_hop_rule;
pub use pull_up_hop_rule::*;
mod apply_offset_rewriter;
use apply_offset_rewriter::ApplyOffsetRewriter;
mod intersect_to_semi_join_rule;
pub use intersect_to_semi_join_rule::*;
mod except_to_anti_join_rule;
pub use except_to_anti_join_rule::*;
mod intersect_merge_rule;
pub use intersect_merge_rule::*;
mod except_merge_rule;
pub use except_merge_rule::*;
mod apply_union_transpose_rule;
pub use apply_union_transpose_rule::*;
mod apply_dedup_transpose_rule;
pub use apply_dedup_transpose_rule::*;
mod project_join_separate_rule;
pub use project_join_separate_rule::*;
mod grouping_sets_to_expand_rule;
pub use grouping_sets_to_expand_rule::*;
mod apply_project_set_transpose_rule;
pub use apply_project_set_transpose_rule::*;
mod cross_join_eliminate_rule;
pub use cross_join_eliminate_rule::*;
mod table_function_to_project_set_rule;
pub use table_function_to_project_set_rule::*;
mod apply_topn_transpose_rule;
pub use apply_topn_transpose_rule::*;
mod apply_limit_transpose_rule;
pub use apply_limit_transpose_rule::*;
mod batch;
pub use batch::batch_project_merge_rule::*;
mod common_sub_expr_extract_rule;
pub use common_sub_expr_extract_rule::*;
mod apply_over_window_transpose_rule;
pub use apply_over_window_transpose_rule::*;
mod apply_expand_transpose_rule;
pub use apply_expand_transpose_rule::*;
mod expand_to_project_rule;
pub use expand_to_project_rule::*;
mod agg_group_by_simplify_rule;
pub use agg_group_by_simplify_rule::*;
mod apply_hop_window_transpose_rule;
pub use apply_hop_window_transpose_rule::*;
mod agg_call_merge_rule;
pub use agg_call_merge_rule::*;
mod pull_up_correlated_predicate_agg_rule;
mod source_to_iceberg_scan_rule;
mod source_to_kafka_scan_rule;
mod table_function_to_file_scan_rule;
mod table_function_to_mysql_query_rule;
mod table_function_to_postgres_query_rule;
mod values_extract_project_rule;
pub use batch::batch_iceberg_predicate_pushdown::*;
pub use batch::batch_push_limit_to_scan_rule::*;
pub use pull_up_correlated_predicate_agg_rule::*;
pub use source_to_iceberg_scan_rule::*;
pub use source_to_kafka_scan_rule::*;
pub use table_function_to_file_scan_rule::*;
pub use table_function_to_mysql_query_rule::*;
pub use table_function_to_postgres_query_rule::*;
pub use values_extract_project_rule::*;
#[macro_export]
macro_rules! for_all_rules {
($macro:ident) => {
$macro! {
{ ApplyAggTransposeRule }
, { ApplyFilterTransposeRule }
, { ApplyProjectTransposeRule }
, { ApplyProjectSetTransposeRule }
, { ApplyEliminateRule }
, { ApplyJoinTransposeRule }
, { ApplyShareEliminateRule }
, { ApplyToJoinRule }
, { MaxOneRowEliminateRule }
, { DistinctAggRule }
, { IndexDeltaJoinRule }
, { MergeMultiJoinRule }
, { ProjectEliminateRule }
, { ProjectJoinMergeRule }
, { ProjectMergeRule }
, { PullUpCorrelatedPredicateRule }
, { LeftDeepTreeJoinOrderingRule }
, { TranslateApplyRule }
, { PushCalculationOfJoinRule }
, { IndexSelectionRule }
, { OverWindowToTopNRule }
, { OverWindowToAggAndJoinRule }
, { OverWindowSplitRule }
, { OverWindowMergeRule }
, { JoinCommuteRule }
, { UnionToDistinctRule }
, { AggProjectMergeRule }
, { UnionMergeRule }
, { DagToTreeRule }
, { SplitNowAndRule }
, { SplitNowOrRule }
, { FilterWithNowToJoinRule }
, { GenerateSeriesWithNowRule }
, { TopNOnIndexRule }
, { TrivialProjectToValuesRule }
, { UnionInputValuesMergeRule }
, { RewriteLikeExprRule }
, { MinMaxOnIndexRule }
, { AlwaysFalseFilterRule }
, { BushyTreeJoinOrderingRule }
, { StreamProjectMergeRule }
, { LogicalFilterExpressionSimplifyRule }
, { JoinProjectTransposeRule }
, { LimitPushDownRule }
, { PullUpHopRule }
, { IntersectToSemiJoinRule }
, { ExceptToAntiJoinRule }
, { IntersectMergeRule }
, { ExceptMergeRule }
, { ApplyUnionTransposeRule }
, { ApplyDedupTransposeRule }
, { ProjectJoinSeparateRule }
, { GroupingSetsToExpandRule }
, { CrossJoinEliminateRule }
, { ApplyTopNTransposeRule }
, { TableFunctionToProjectSetRule }
, { TableFunctionToFileScanRule }
, { TableFunctionToPostgresQueryRule }
, { TableFunctionToMySqlQueryRule }
, { ApplyLimitTransposeRule }
, { CommonSubExprExtractRule }
, { BatchProjectMergeRule }
, { ApplyOverWindowTransposeRule }
, { ApplyExpandTransposeRule }
, { ExpandToProjectRule }
, { AggGroupBySimplifyRule }
, { ApplyHopWindowTransposeRule }
, { AggCallMergeRule }
, { ValuesExtractProjectRule }
, { BatchPushLimitToScanRule }
, { BatchIcebergPredicatePushDownRule }
, { PullUpCorrelatedPredicateAggRule }
, { SourceToKafkaScanRule }
, { SourceToIcebergScanRule }
}
};
}
macro_rules! impl_description {
($( { $name:ident }),*) => {
paste::paste!{
$(impl Description for [<$name>] {
fn description(&self) -> &str {
stringify!([<$name>])
}
})*
}
}
}
for_all_rules! {impl_description}