{"record":{"id":"1c76cb0f5697376d","repo":"databendlabs/databend","slug":"input-plan-must-be-query-but-it-s-1c76cb","errorCode":null,"errorMessage":"Input plan must be Query, but it's {}","messagePattern":"Input plan must be Query, but it's (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/query/service/src/interpreters/interpreter_set.rs","lineNumber":196,"sourceCode":"\n    fn is_ddl(&self) -> bool {\n        false\n    }\n\n    #[async_backtrace::framed]\n    async fn execute2(&self) -> Result<PipelineBuildResult> {\n        let scalars = match &self.set.values {\n            SetScalarsOrQuery::VarValue(scalars) => scalars.clone(),\n            SetScalarsOrQuery::Query(query) => {\n                let (s_expr, metadata, bind_context, formatted_ast) = match query.as_ref() {\n                    Plan::Query {\n                        s_expr,\n                        metadata,\n                        bind_context,\n                        formatted_ast,\n                        ..\n                    } => (s_expr, metadata, bind_context, formatted_ast),\n                    v => unreachable!(\"Input plan must be Query, but it's {}\", v),\n                };\n\n                let select_interpreter = SelectInterpreter::try_create(\n                    self.ctx.clone(),\n                    *(bind_context.clone()),\n                    *s_expr.clone(),\n                    metadata.clone(),\n                    formatted_ast.clone(),\n                    false,\n                )?;\n\n                let stream = select_interpreter\n                    .execute_with_hooks(self.ctx.clone(), QueryFinishHooks::nested_with_hooks())\n                    .await?;\n                let datablocks: Vec<DataBlock> = stream.try_collect::<Vec<_>>().await?;\n                let num_columns = bind_context.columns.len();\n                if num_columns != self.set.idents.len() {\n                    return Err(ErrorCode::BadArguments(format!(","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/service/src/interpreters/interpreter_set.rs#L178-L214","documentation":"The SET interpreter builds a sub-SELECT for assignment sources and destructures the input plan expecting the Query variant so it can construct a SelectInterpreter. If the plan is any other variant, the invariant is broken and the code panics via unreachable!, reporting the actual variant in the message.","triggerScenarios":"Executing a SET/assignment statement whose value-producing sub-plan is not Plan::Query — e.g. an optimizer/planner change yields a different logical plan node for the assigned expression source.","commonSituations":"Internal planner regressions when new plan nodes are introduced; using SET ... = (SELECT ...) forms through code paths that reshape the sub-plan.","solutions":["Inspect the logical plan of the SET statement's right-hand side to see which non-Query variant is produced.","Fix the planner so assignment sources are wrapped in Plan::Query, or add an arm handling the new variant.","Upgrade to a version where SET source plans are guaranteed to be Query."],"exampleFix":"// before\nv => unreachable!(\"Input plan must be Query, but it's {}\", v),\n// after\nv => Err(ErrorCode::Internal(format!(\n    \"SET source must be a Query plan, got: {}\", v\n))),","handlingStrategy":"type-guard","validationCode":"// Verify the SET source plan variant before destructuring\nif !matches!(plan, Plan::Query { .. }) {\n    return Err(ErrorCode::Internal(\"SET source is not a Query plan\".into()));\n}","typeGuard":"fn is_query_plan(p: &Plan) -> bool {\n    matches!(p, Plan::Query { .. })\n}","tryCatchPattern":null,"preventionTips":["Add planner tests for SET assignment sources","Update all Plan destructuring sites when adding variants","Avoid unreachable! in user-reachable code paths"],"tags":["rust","unreachable","plan","set"],"backgroundTag":"internal-invariant-violation","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}