Skip to content
Merged
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
36 changes: 28 additions & 8 deletions src/adapter/src/coord/catalog_serving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use mz_repr::namespaces::is_system_schema;
use mz_sql::catalog::SessionCatalog;
use mz_sql::plan::{
ExplainPlanPlan, ExplainTimestampPlan, Explainee, ExplaineeStatement, Plan, SubscribeFrom,
SubscribePlan,
};
use smallvec::SmallVec;

Expand All @@ -41,6 +42,16 @@ pub fn auto_run_on_catalog_server<'a, 's, 'p>(
session: &'s Session,
plan: &'p Plan,
) -> TargetCluster {
let inspect_subscribe = |plan: &SubscribePlan| {
(
plan.from.depends_on(),
match &plan.from {
SubscribeFrom::Id(_) => false,
SubscribeFrom::Query { expr, desc: _ } => expr.could_run_expensive_function(),
},
)
};

let (depends_on, could_run_expensive_function) = match plan {
Plan::Select(plan) => (
plan.source.depends_on(),
Expand All @@ -50,20 +61,18 @@ pub fn auto_run_on_catalog_server<'a, 's, 'p>(
plan.select_plan.source.depends_on(),
plan.select_plan.source.could_run_expensive_function(),
),
Plan::Subscribe(plan) => (
plan.from.depends_on(),
match &plan.from {
SubscribeFrom::Id(_) => false,
SubscribeFrom::Query { expr, desc: _ } => expr.could_run_expensive_function(),
},
),
Plan::Subscribe(plan) => inspect_subscribe(plan),
Plan::ExplainPlan(ExplainPlanPlan {
explainee: Explainee::Statement(ExplaineeStatement::Select { plan, .. }),
..
}) => (
plan.source.depends_on(),
plan.source.could_run_expensive_function(),
),
Plan::ExplainPlan(ExplainPlanPlan {
explainee: Explainee::Statement(ExplaineeStatement::Subscribe { plan, .. }),
..
}) => inspect_subscribe(plan),
Plan::ExplainTimestamp(ExplainTimestampPlan { raw_plan, .. }) => (
raw_plan.depends_on(),
raw_plan.could_run_expensive_function(),
Expand Down Expand Up @@ -103,7 +112,18 @@ pub fn auto_run_on_catalog_server<'a, 's, 'p>(
| Plan::AbortTransaction(_)
| Plan::CopyFrom(_)
| Plan::CopyTo(_)
| Plan::ExplainPlan(_)
| Plan::ExplainPlan(ExplainPlanPlan {
explainee:
Explainee::Statement(
// Explicitly list all enum variants, to avoid bugs when somebody
// adds a new variant (e.g., for `Plan::Execute`).
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This change is not changing functionality; it just does what the comment says.)

ExplaineeStatement::CreateView { .. }
| ExplaineeStatement::CreateMaterializedView { .. }
| ExplaineeStatement::CreateIndex { .. },
),
..
})
| Plan::ExplainPlan(ExplainPlanPlan { explainee: _, .. })
| Plan::ExplainPushdown(_)
| Plan::ExplainSinkSchema(_)
| Plan::Insert(_)
Expand Down
12 changes: 12 additions & 0 deletions test/sqllogictest/auto_route_expensive.slt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ Target cluster: mz_catalog_server

EOF

query T multiline
EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
SUBSCRIBE (SELECT 1)
----
Explained Query:
Constant
- (1)

Target cluster: mz_catalog_server

EOF

query T multiline
EXPLAIN OPTIMIZED PLAN WITH(humanized expressions) AS VERBOSE TEXT FOR
SELECT 1 / 1
Expand Down
Loading