Skip to content

Commit

Permalink
adapter: define OptimizePeek
Browse files Browse the repository at this point in the history
Define an `OptimizePeek` struct which implements an end-to-end
optimizer for `Peek` plans statements using the `Optimize` API.
  • Loading branch information
aalexandrov committed Nov 7, 2023
1 parent be37cc8 commit e47e0af
Show file tree
Hide file tree
Showing 4 changed files with 452 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/adapter/src/coord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,8 @@ impl Coordinator {
);

// MIR ⇒ MIR optimization (global)
let index_plan = optimize::Index::new(entry.name(), &idx.on, &idx.keys);
let index_plan =
optimize::index::Index::new(entry.name(), &idx.on, &idx.keys);
let global_mir_plan = optimizer.optimize(index_plan)?;
// Timestamp selection
let as_of = self.bootstrap_index_as_of(
Expand Down
4 changes: 2 additions & 2 deletions src/adapter/src/coord/sequencer/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ impl Coordinator {
);

// MIR ⇒ MIR optimization (global)
let index_plan = optimize::Index::new(&name, &on, &keys);
let index_plan = optimize::index::Index::new(&name, &on, &keys);
let global_mir_plan = optimizer.optimize(index_plan)?;
// Timestamp selection
let since = self.least_valid_read(&global_mir_plan.id_bundle());
Expand Down Expand Up @@ -3705,7 +3705,7 @@ impl Coordinator {

let (df_desc, df_meta, used_indexes) = catch_unwind(broken, "optimize", || {
// MIR ⇒ MIR optimization (global)
let index_plan = optimize::Index::new(&name, &index.on, &index.keys);
let index_plan = optimize::index::Index::new(&name, &index.on, &index.keys);
let global_mir_plan = optimizer.optimize(index_plan)?;

// Collect the list of indexes used by the dataflow at this point
Expand Down
25 changes: 14 additions & 11 deletions src/adapter/src/optimize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@
//! For details, see the `20230714_optimizer_interface.md` design doc in this
//! repository.

mod index;
mod materialized_view;
mod subscribe;
mod view;
pub mod index;
pub mod materialized_view;
pub mod peek;
pub mod subscribe;
pub mod view;

// Re-export optimzier structs
pub use index::{Index, OptimizeIndex};
pub use index::OptimizeIndex;
pub use materialized_view::OptimizeMaterializedView;
pub use peek::OptimizePeek;
pub use subscribe::OptimizeSubscribe;
pub use view::OptimizeView;

Expand Down Expand Up @@ -90,11 +92,11 @@ use crate::AdapterError;
/// The `'s: 'ctx` bound in the `optimize` method call ensures that an optimizer
/// instance can run an optimization stage that produces a `Self::To` with
/// `&'ctx` references.
pub trait Optimize<From>: Send + Sync
pub trait Optimize<From>: Send
where
From: Send + Sync,
From: Send,
{
type To: Send + Sync;
type To: Send;

/// Execute the optimization stage, transforming the input plan of type
/// `From` to an output plan of type `To`.
Expand All @@ -112,7 +114,7 @@ where
}

// Feature flags for the optimizer.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct OptimizerConfig {
/// The mode in which the optimizer runs.
pub mode: OptimizeMode,
Expand All @@ -126,13 +128,14 @@ pub struct OptimizerConfig {
/// The collection of type information happens in MIR ⇒ LIR lowering.
pub enable_specialized_arrangements: bool,
/// An exclusive upper bound on the number of results we may return from a
/// Persist fast-path peek.
/// Persist fast-path peek. Required by the `create_fast_path_plan` call in
/// [`OptimizePeek`].
pub persist_fast_path_limit: usize,
/// Enable outer join lowering implemented in #22343.
pub enable_new_outer_join_lowering: bool,
}

#[derive(Clone, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum OptimizeMode {
/// A mode where the optimized statement is executed.
Execute,
Expand Down
Loading

0 comments on commit e47e0af

Please sign in to comment.