pub fn plan(
    pcx: Option<&PlanContext>,
    catalog: &dyn SessionCatalog,
    stmt: Statement<Raw>,
    params: &Params,
) -> Result<Plan, anyhow::Error> {
    let param_types = params
        .types
        .iter()
        .enumerate()
        .map(|(i, ty)| (i + 1, ty.clone()))
        .collect();

    let scx = &StatementContext {
        pcx,
        catalog,
        param_types: RefCell::new(param_types),
    };

    match stmt {
        // DDL statements.
        Statement::CreateDatabase(stmt) => ddl::plan_create_database(scx, stmt),
        Statement::CreateSchema(stmt) => ddl::plan_create_schema(scx, stmt),
        Statement::CreateTable(stmt) => ddl::plan_create_table(scx, stmt),
        Statement::CreateSource(stmt) => ddl::plan_create_source(scx, stmt),
        Statement::CreateView(stmt) => ddl::plan_create_view(scx, stmt, params),
        Statement::CreateViews(stmt) => ddl::plan_create_views(scx, stmt),
        Statement::CreateSink(stmt) => ddl::plan_create_sink(scx, stmt),
        Statement::CreateIndex(stmt) => ddl::plan_create_index(scx, stmt),
        Statement::CreateType(stmt) => ddl::plan_create_type(scx, stmt),
        Statement::CreateRole(stmt) => ddl::plan_create_role(scx, stmt),
        Statement::DropDatabase(stmt) => ddl::plan_drop_database(scx, stmt),
        Statement::DropObjects(stmt) => ddl::plan_drop_objects(scx, stmt),
        Statement::AlterIndex(stmt) => ddl::plan_alter_index_options(scx, stmt),
        Statement::AlterObjectRename(stmt) => ddl::plan_alter_object_rename(scx, stmt),

        // DML statements.
        Statement::Insert(stmt) => dml::plan_insert(scx, stmt, params),
        Statement::Update(stmt) => dml::plan_update(scx, stmt, params),
        Statement::Delete(stmt) => dml::plan_delete(scx, stmt, params),
        Statement::Select(stmt) => dml::plan_select(scx, stmt, params, None),
        Statement::Explain(stmt) => dml::plan_explain(scx, stmt, params),
        Statement::Tail(stmt) => dml::plan_tail(scx, stmt, None),
        Statement::Copy(stmt) => dml::plan_copy(scx, stmt),

        // `SHOW` statements.
        Statement::ShowColumns(stmt) => show::show_columns(scx, stmt)?.plan(),
        Statement::ShowCreateTable(stmt) => show::plan_show_create_table(scx, stmt),
        Statement::ShowCreateSource(stmt) => show::plan_show_create_source(scx, stmt),
        Statement::ShowCreateView(stmt) => show::plan_show_create_view(scx, stmt),
        Statement::ShowCreateSink(stmt) => show::plan_show_create_sink(scx, stmt),
        Statement::ShowCreateIndex(stmt) => show::plan_show_create_index(scx, stmt),
        Statement::ShowDatabases(stmt) => show::show_databases(scx, stmt)?.plan(),
        Statement::ShowObjects(stmt) => show::show_objects(scx, stmt)?.plan(),
        Statement::ShowIndexes(stmt) => show::show_indexes(scx, stmt)?.plan(),

        // SCL statements.
        Statement::SetVariable(stmt) => scl::plan_set_variable(scx, stmt),
        Statement::ShowVariable(stmt) => scl::plan_show_variable(scx, stmt),
        Statement::Discard(stmt) => scl::plan_discard(scx, stmt),
        Statement::Declare(stmt) => scl::plan_declare(scx, stmt),
        Statement::Fetch(stmt) => scl::plan_fetch(scx, stmt),
        Statement::Close(stmt) => scl::plan_close(scx, stmt),
        Statement::Prepare(stmt) => scl::plan_prepare(scx, stmt),
        Statement::Execute(stmt) => scl::plan_execute(scx, stmt),
        Statement::Deallocate(stmt) => scl::plan_deallocate(scx, stmt),

        // TCL statements.
        Statement::StartTransaction(stmt) => tcl::plan_start_transaction(scx, stmt),
        Statement::SetTransaction(stmt) => tcl::plan_set_transaction(scx, stmt),
        Statement::Rollback(stmt) => tcl::plan_rollback(scx, stmt),
        Statement::Commit(stmt) => tcl::plan_commit(scx, stmt),
    }
}
/// Produces a [`Plan`] from the purified statement `stmt`.
///
/// Planning is a pure, synchronous function and so requires that the provided
/// `stmt` does does not depend on any external state. To purify a statement,
/// use [`crate::pure::purify`].
///
/// The returned plan is tied to the state of the provided catalog. If the state
/// of the catalog changes after planning, the validity of the plan is not
/// guaranteed.
Produces a [`Plan`] from the purified statement `stmt`.
Planning is a pure, synchronous function and so requires that the provided
`stmt` does does not depend on any external state. To purify a statement,
use [`crate::pure::purify`].

The returned plan is tied to the state of the provided catalog. If the state
of the catalog changes after planning, the validity of the plan is not
guaranteed.
Produces a [ ` Plan ` ] from the purified statement ` stmt ` . Planning is a pure synchronous function and so requires that the provided ` stmt ` does does not depend on any external state . To purify a statement use [ ` crate :: pure :: purify ` ] . The returned plan is tied to the state of the provided catalog . If the state of the catalog changes after planning the validity of the plan is not guaranteed .
pub fn plan(
    pcx: Option<&PlanContext>,
    catalog: &dyn SessionCatalog,
    stmt: Statement<Raw>,
    params: &Params,
) -> Result<Plan, anyhow::Error> {
    let param_types = params
        .types
        .iter()
        .enumerate()
        .map(|(i, ty)| (i + 1, ty.clone()))
        .collect();
    let scx = &StatementContext {
        pcx,
        catalog,
        param_types: RefCell::new(param_types),
    };
    match stmt {
        // DDL statements.
        Statement::CreateDatabase(stmt) => ddl::plan_create_database(scx, stmt),
        Statement::CreateSchema(stmt) => ddl::plan_create_schema(scx, stmt),
        Statement::CreateTable(stmt) => ddl::plan_create_table(scx, stmt),
        Statement::CreateSource(stmt) => ddl::plan_create_source(scx, stmt),
        Statement::CreateView(stmt) => ddl::plan_create_view(scx, stmt, params),
        Statement::CreateViews(stmt) => ddl::plan_create_views(scx, stmt),
        Statement::CreateSink(stmt) => ddl::plan_create_sink(scx, stmt),
        Statement::CreateIndex(stmt) => ddl::plan_create_index(scx, stmt),
        Statement::CreateType(stmt) => ddl::plan_create_type(scx, stmt),
        Statement::CreateRole(stmt) => ddl::plan_create_role(scx, stmt),
        Statement::DropDatabase(stmt) => ddl::plan_drop_database(scx, stmt),
        Statement::DropObjects(stmt) => ddl::plan_drop_objects(scx, stmt),
        Statement::AlterIndex(stmt) => ddl::plan_alter_index_options(scx, stmt),
        Statement::AlterObjectRename(stmt) => ddl::plan_alter_object_rename(scx, stmt),
        // DML statements.
        Statement::Insert(stmt) => dml::plan_insert(scx, stmt, params),
        Statement::Update(stmt) => dml::plan_update(scx, stmt, params),
        Statement::Delete(stmt) => dml::plan_delete(scx, stmt, params),
        Statement::Select(stmt) => dml::plan_select(scx, stmt, params, None),
        Statement::Explain(stmt) => dml::plan_explain(scx, stmt, params),
        Statement::Tail(stmt) => dml::plan_tail(scx, stmt, None),
        Statement::Copy(stmt) => dml::plan_copy(scx, stmt),
        // `SHOW` statements.
        Statement::ShowColumns(stmt) => show::show_columns(scx, stmt)?.plan(),
        Statement::ShowCreateTable(stmt) => show::plan_show_create_table(scx, stmt),
        Statement::ShowCreateSource(stmt) => show::plan_show_create_source(scx, stmt),
        Statement::ShowCreateView(stmt) => show::plan_show_create_view(scx, stmt),
        Statement::ShowCreateSink(stmt) => show::plan_show_create_sink(scx, stmt),
        Statement::ShowCreateIndex(stmt) => show::plan_show_create_index(scx, stmt),
        Statement::ShowDatabases(stmt) => show::show_databases(scx, stmt)?.plan(),
        Statement::ShowObjects(stmt) => show::show_objects(scx, stmt)?.plan(),
        Statement::ShowIndexes(stmt) => show::show_indexes(scx, stmt)?.plan(),
        // SCL statements.
        Statement::SetVariable(stmt) => scl::plan_set_variable(scx, stmt),
        Statement::ShowVariable(stmt) => scl::plan_show_variable(scx, stmt),
        Statement::Discard(stmt) => scl::plan_discard(scx, stmt),
        Statement::Declare(stmt) => scl::plan_declare(scx, stmt),
        Statement::Fetch(stmt) => scl::plan_fetch(scx, stmt),
        Statement::Close(stmt) => scl::plan_close(scx, stmt),
        Statement::Prepare(stmt) => scl::plan_prepare(scx, stmt),
        Statement::Execute(stmt) => scl::plan_execute(scx, stmt),
        Statement::Deallocate(stmt) => scl::plan_deallocate(scx, stmt),
        // TCL statements.
        Statement::StartTransaction(stmt) => tcl::plan_start_transaction(scx, stmt),
        Statement::SetTransaction(stmt) => tcl::plan_set_transaction(scx, stmt),
        Statement::Rollback(stmt) => tcl::plan_rollback(scx, stmt),
        Statement::Commit(stmt) => tcl::plan_commit(scx, stmt),
    }
}
pub fn plan ( pcx : Option < & PlanContext > , catalog : & dyn SessionCatalog , stmt : Statement < Raw > , params : & Params , ) -> Result < Plan , anyhow :: Error > { let param_types = params . types . iter ( ) . enumerate ( ) . map ( | ( i , ty ) | ( i + 1 , ty . clone ( ) ) ) . collect ( ) ; let scx = & StatementContext { pcx , catalog , param_types : RefCell :: new ( param_types ) , } ; match stmt { // DDL statements. Statement :: CreateDatabase ( stmt ) => ddl :: plan_create_database ( scx , stmt ) , Statement :: CreateSchema ( stmt ) => ddl :: plan_create_schema ( scx , stmt ) , Statement :: CreateTable ( stmt ) => ddl :: plan_create_table ( scx , stmt ) , Statement :: CreateSource ( stmt ) => ddl :: plan_create_source ( scx , stmt ) , Statement :: CreateView ( stmt ) => ddl :: plan_create_view ( scx , stmt , params ) , Statement :: CreateViews ( stmt ) => ddl :: plan_create_views ( scx , stmt ) , Statement :: CreateSink ( stmt ) => ddl :: plan_create_sink ( scx , stmt ) , Statement :: CreateIndex ( stmt ) => ddl :: plan_create_index ( scx , stmt ) , Statement :: CreateType ( stmt ) => ddl :: plan_create_type ( scx , stmt ) , Statement :: CreateRole ( stmt ) => ddl :: plan_create_role ( scx , stmt ) , Statement :: DropDatabase ( stmt ) => ddl :: plan_drop_database ( scx , stmt ) , Statement :: DropObjects ( stmt ) => ddl :: plan_drop_objects ( scx , stmt ) , Statement :: AlterIndex ( stmt ) => ddl :: plan_alter_index_options ( scx , stmt ) , Statement :: AlterObjectRename ( stmt ) => ddl :: plan_alter_object_rename ( scx , stmt ) , // DML statements. Statement :: Insert ( stmt ) => dml :: plan_insert ( scx , stmt , params ) , Statement :: Update ( stmt ) => dml :: plan_update ( scx , stmt , params ) , Statement :: Delete ( stmt ) => dml :: plan_delete ( scx , stmt , params ) , Statement :: Select ( stmt ) => dml :: plan_select ( scx , stmt , params , None ) , Statement :: Explain ( stmt ) => dml :: plan_explain ( scx , stmt , params ) , Statement :: Tail ( stmt ) => dml :: plan_tail ( scx , stmt , None ) , Statement :: Copy ( stmt ) => dml :: plan_copy ( scx , stmt ) , // `SHOW` statements. Statement :: ShowColumns ( stmt ) => show :: show_columns ( scx , stmt ) ? . plan ( ) , Statement :: ShowCreateTable ( stmt ) => show :: plan_show_create_table ( scx , stmt ) , Statement :: ShowCreateSource ( stmt ) => show :: plan_show_create_source ( scx , stmt ) , Statement :: ShowCreateView ( stmt ) => show :: plan_show_create_view ( scx , stmt ) , Statement :: ShowCreateSink ( stmt ) => show :: plan_show_create_sink ( scx , stmt ) , Statement :: ShowCreateIndex ( stmt ) => show :: plan_show_create_index ( scx , stmt ) , Statement :: ShowDatabases ( stmt ) => show :: show_databases ( scx , stmt ) ? . plan ( ) , Statement :: ShowObjects ( stmt ) => show :: show_objects ( scx , stmt ) ? . plan ( ) , Statement :: ShowIndexes ( stmt ) => show :: show_indexes ( scx , stmt ) ? . plan ( ) , // SCL statements. Statement :: SetVariable ( stmt ) => scl :: plan_set_variable ( scx , stmt ) , Statement :: ShowVariable ( stmt ) => scl :: plan_show_variable ( scx , stmt ) , Statement :: Discard ( stmt ) => scl :: plan_discard ( scx , stmt ) , Statement :: Declare ( stmt ) => scl :: plan_declare ( scx , stmt ) , Statement :: Fetch ( stmt ) => scl :: plan_fetch ( scx , stmt ) , Statement :: Close ( stmt ) => scl :: plan_close ( scx , stmt ) , Statement :: Prepare ( stmt ) => scl :: plan_prepare ( scx , stmt ) , Statement :: Execute ( stmt ) => scl :: plan_execute ( scx , stmt ) , Statement :: Deallocate ( stmt ) => scl :: plan_deallocate ( scx , stmt ) , // TCL statements. Statement :: StartTransaction ( stmt ) => tcl :: plan_start_transaction ( scx , stmt ) , Statement :: SetTransaction ( stmt ) => tcl :: plan_set_transaction ( scx , stmt ) , Statement :: Rollback ( stmt ) => tcl :: plan_rollback ( scx , stmt ) , Statement :: Commit ( stmt ) => tcl :: plan_commit ( scx , stmt ) , } }
Produces a [`Plan`] from the purified statement `stmt`.
Produces a [ ` Plan ` ] from the purified statement ` stmt ` .
pcx
Option<&PlanContext>
catalog
&dyn SessionCatalog
stmt
Statement<Raw>
params
&Params
pcx
Option<&PlanContext>
catalog
&dyn SessionCatalog
stmt
Statement<Raw>
params
&Params