use super::{Arc, BindingMap, BindingNameSet, CteRowsMap, CteScope, ProductionControl, SQLError};
impl<S: Clone> CteScope<S> {
pub fn copy_with_control(&self, control: &ProductionControl<'_>) -> Result<Self, SQLError> {
let mut output = self.copy_context_with_control(control)?;
output.rows = self.rows.copy_with_control(control)?;
output.deferred_ctes = self
.deferred_ctes
.copy_with_control(control, |plan| Ok(plan.clone()))?;
output.definition_scopes = self
.definition_scopes
.copy_with_control(control, |definition| Ok(Arc::clone(definition)))?;
output.folded_ctes = self.folded_ctes.copy_with_control(control)?;
output.non_returning_ctes = self.non_returning_ctes.copy_with_control(control)?;
output.visible_cte_names = self.visible_cte_names.copy_with_control(control)?;
output.recursive_control_widths = self
.recursive_control_widths
.copy_with_control(control, |width| Ok(*width))?;
Ok(output)
}
pub(in crate::query::scope) fn copy_context_with_control(
&self,
control: &ProductionControl<'_>,
) -> Result<Self, SQLError> {
control.check()?;
Ok(Self {
producers: self.producers.clone(),
rows: CteRowsMap::new(),
deferred_ctes: BindingMap::new(),
definition_scopes: BindingMap::new(),
folded_ctes: BindingNameSet::new(),
non_returning_ctes: BindingNameSet::new(),
scalar_subqueries: self.scalar_subqueries.clone(),
source_outer_rewrites: self.source_outer_rewrites.clone(),
lock_identities: self.lock_identities,
row_lock: self.row_lock.clone(),
visible_cte_names: BindingNameSet::new(),
recursive_control_widths: BindingMap::new(),
scalar_subquery_arena: self.scalar_subquery_arena,
read_command_overlay: self.read_command_overlay,
stream_command_progress: self.stream_command_progress,
scan_backwards: self.scan_backwards,
next_scalar_subquery_arena: Arc::clone(&self.next_scalar_subquery_arena),
scalar_subquery_cache: Arc::clone(&self.scalar_subquery_cache),
catalog: self.catalog.clone(),
catalog_revision: self.catalog_revision,
catalog_resolution: self.catalog_resolution.clone(),
privilege_subject: self.privilege_subject.clone(),
command_cte_snapshot: self.command_cte_snapshot.clone(),
statement_commands: self.statement_commands.clone(),
})
}
}