You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: cascade.rs
    path of file: ./repos/databend/src/query/sql/src/planner/optimizer/cascades
    
    the code of the file until where you have to start completion: // Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::sync::Arc;

use databend_common_catalog::table_context::TableContext;
use databend_common_exception::ErrorCode;
use databend_common_exception::Result;
use log::debug;

use super::explore_rules::get_explore_rule_set;
use crate::optimizer::cascades::scheduler::Scheduler;
use crate::optimiz
    
    pub fn optimize(&mut self, s_expr: SExpr) -> Result<SExpr> {
        self.init(s_expr)?;

        debug!("Init memo:\n{}", display_memo(&self.memo)?);

        let root_index = self
            .memo
            .root()
            .ok_or_else(|| ErrorCode::Internal("Root group cannot be None after initialization"))?
            .group_index;

        let root_required_prop = if self.enforce_distribution {
            RequiredProperty {
                distribution: Distribution::Serial,
            }
        } else {
            Default::default()
        };

        let root_task = OptimizeGroupTask::new(
            self.ctx.clone(),
            None,
            root_index,
            root_required_prop.clone(),
        );

        let task_limit = if self.ctx.get_settings().get_enable_cbo()? {
            DEFAULT_TASK_LIMIT
        } else {
            0
        };

        let mut scheduler = Scheduler::new().with_task_limit(task_limit);
        scheduler.add_task(Task::OptimizeGroup(root_task));
        scheduler.run(self)?;

        debug!("Memo:\n{}", display_memo(&self.memo)?);

        self.find_best_plan(root_index, &root_required_prop)
    }