Skip to content

Add OptimizationBegan query lifecycle event #32508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/adapter/src/coord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ pub struct PeekStageFinish {
plan_insights_optimizer_trace: Option<OptimizerTrace>,
insights_ctx: Option<Box<PlanInsightsContext>>,
global_lir_plan: optimize::peek::GlobalLirPlan,
optimization_began_at: EpochMillis,
optimization_finished_at: EpochMillis,
}

Expand All @@ -548,6 +549,7 @@ pub struct PeekStageCopyTo {
validity: PlanValidity,
optimizer: optimize::copy_to::Optimizer,
global_lir_plan: optimize::copy_to::GlobalLirPlan,
optimization_began_at: EpochMillis,
optimization_finished_at: EpochMillis,
source_ids: BTreeSet<GlobalId>,
}
Expand Down
16 changes: 16 additions & 0 deletions src/adapter/src/coord/sequencer/inner/peek.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ impl Coordinator {
}
};

let optimization_began_at = now();
let pipeline_result = pipeline();
let optimization_finished_at = now();

Expand Down Expand Up @@ -649,6 +650,7 @@ impl Coordinator {
finishing: optimizer.finishing().clone(),
plan_insights_optimizer_trace: Some(optimizer_trace),
global_lir_plan,
optimization_began_at,
optimization_finished_at,
insights_ctx,
})
Expand All @@ -665,6 +667,7 @@ impl Coordinator {
finishing: optimizer.finishing().clone(),
plan_insights_optimizer_trace: None,
global_lir_plan,
optimization_began_at,
optimization_finished_at,
insights_ctx,
}),
Expand Down Expand Up @@ -695,6 +698,7 @@ impl Coordinator {
validity,
optimizer,
global_lir_plan,
optimization_began_at,
optimization_finished_at,
source_ids,
})
Expand Down Expand Up @@ -819,11 +823,17 @@ impl Coordinator {
finishing,
plan_insights_optimizer_trace,
global_lir_plan,
optimization_began_at,
optimization_finished_at,
insights_ctx,
}: PeekStageFinish,
) -> Result<StageResult<Box<PeekStage>>, AdapterError> {
if let Some(id) = ctx.extra.contents() {
self.record_statement_lifecycle_event(
&id,
&StatementLifecycleEvent::OptimizationBegan,
optimization_began_at,
);
self.record_statement_lifecycle_event(
&id,
&StatementLifecycleEvent::OptimizationFinished,
Expand Down Expand Up @@ -997,11 +1007,17 @@ impl Coordinator {
validity: _,
optimizer,
global_lir_plan,
optimization_began_at,
optimization_finished_at,
source_ids,
}: PeekStageCopyTo,
) -> Result<StageResult<Box<PeekStage>>, AdapterError> {
if let Some(id) = ctx.extra.contents() {
self.record_statement_lifecycle_event(
&id,
&StatementLifecycleEvent::OptimizationBegan,
optimization_began_at,
);
self.record_statement_lifecycle_event(
&id,
&StatementLifecycleEvent::OptimizationFinished,
Expand Down
2 changes: 2 additions & 0 deletions src/adapter/src/statement_logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::{AdapterError, ExecuteResponse};
#[derive(Clone, Debug)]
pub enum StatementLifecycleEvent {
ExecutionBegan,
OptimizationBegan,
OptimizationFinished,
StorageDependenciesFinished,
ComputeDependenciesFinished,
Expand All @@ -30,6 +31,7 @@ impl StatementLifecycleEvent {
pub fn as_str(&self) -> &str {
match self {
Self::ExecutionBegan => "execution-began",
Self::OptimizationBegan => "optimization-began",
Self::OptimizationFinished => "optimization-finished",
Self::StorageDependenciesFinished => "storage-dependencies-finished",
Self::ComputeDependenciesFinished => "compute-dependencies-finished",
Expand Down
9 changes: 9 additions & 0 deletions test/cluster/statement-logging/statement-logging.td
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ COMMIT execution-finished
"EXECUTE p('hello world')" compute-dependencies-finished
"EXECUTE p('hello world')" execution-began
"EXECUTE p('hello world')" execution-finished
"EXECUTE p('hello world')" optimization-began
"EXECUTE p('hello world')" optimization-finished
"EXECUTE p('hello world')" storage-dependencies-finished
"FETCH c" compute-dependencies-finished
Expand All @@ -177,6 +178,7 @@ COMMIT execution-finished
"FETCH c" execution-finished
"FETCH c" execution-finished
"FETCH c" execution-finished
"FETCH c" optimization-began
"FETCH c" optimization-finished
"FETCH c" storage-dependencies-finished
"INSERT INTO t VALUES (1)" execution-began
Expand All @@ -186,21 +188,25 @@ COMMIT execution-finished
"SELECT 'beginning real test!'" compute-dependencies-finished
"SELECT 'beginning real test!'" execution-began
"SELECT 'beginning real test!'" execution-finished
"SELECT 'beginning real test!'" optimization-began
"SELECT 'beginning real test!'" optimization-finished
"SELECT 'beginning real test!'" storage-dependencies-finished
"SELECT 'serializable'" compute-dependencies-finished
"SELECT 'serializable'" execution-began
"SELECT 'serializable'" execution-finished
"SELECT 'serializable'" optimization-began
"SELECT 'serializable'" optimization-finished
"SELECT 'serializable'" storage-dependencies-finished
"SELECT * FROM t" compute-dependencies-finished
"SELECT * FROM t" execution-began
"SELECT * FROM t" execution-finished
"SELECT * FROM t" optimization-began
"SELECT * FROM t" optimization-finished
"SELECT * FROM t" storage-dependencies-finished
"SELECT count(*) > 0 FROM mz_internal.mz_cluster_replica_metrics" compute-dependencies-finished
"SELECT count(*) > 0 FROM mz_internal.mz_cluster_replica_metrics" execution-began
"SELECT count(*) > 0 FROM mz_internal.mz_cluster_replica_metrics" execution-finished
"SELECT count(*) > 0 FROM mz_internal.mz_cluster_replica_metrics" optimization-began
"SELECT count(*) > 0 FROM mz_internal.mz_cluster_replica_metrics" optimization-finished
"SELECT count(*) > 0 FROM mz_internal.mz_cluster_replica_metrics" storage-dependencies-finished
"SELECT count(*) FROM t" compute-dependencies-finished
Expand All @@ -209,13 +215,16 @@ COMMIT execution-finished
"SELECT count(*) FROM t" execution-began
"SELECT count(*) FROM t" execution-finished
"SELECT count(*) FROM t" execution-finished
"SELECT count(*) FROM t" optimization-began
"SELECT count(*) FROM t" optimization-began
"SELECT count(*) FROM t" optimization-finished
"SELECT count(*) FROM t" optimization-finished
"SELECT count(*) FROM t" storage-dependencies-finished
"SELECT count(*) FROM t" storage-dependencies-finished
"SELECT f/0 FROM t" compute-dependencies-finished
"SELECT f/0 FROM t" execution-began
"SELECT f/0 FROM t" execution-finished
"SELECT f/0 FROM t" optimization-began
"SELECT f/0 FROM t" optimization-finished
"SELECT f/0 FROM t" storage-dependencies-finished
"SET cluster TO c" execution-began
Expand Down