{"record":{"id":"289a5d7245978c5e","repo":"databendlabs/databend","slug":"not-implemented-289a5d","errorCode":null,"errorMessage":"not implemented","messagePattern":"not implemented","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/query/service/src/physical_plans/physical_sort.rs","lineNumber":290,"sourceCode":"                Ok(())\n            }\n            SortStep::Shuffled => {\n                if Exchange::check_physical_plan(&self.input) {\n                    let exchange = TransformSortBuilder::exchange_injector();\n                    let old_inject = std::mem::replace(&mut builder.exchange_injector, exchange);\n                    self.input.build_pipeline(builder)?;\n                    builder.exchange_injector = old_inject;\n                } else {\n                    self.input.build_pipeline(builder)?;\n                }\n\n                if builder.main_pipeline.output_len() == 1 {\n                    return Ok(());\n                }\n\n                if max_threads == 1 {\n                    // TODO(Winter): the query will hang in MultiSortMergeProcessor when max_threads == 1 and output_len != 1\n                    unimplemented!();\n                }\n                sort_builder.build_bounded_merge_sort(&mut builder.main_pipeline)\n            }\n            SortStep::Route => {\n                if builder.main_pipeline.output_len() == 1 {\n                    builder\n                        .main_pipeline\n                        .add_transformer(TransformSortBuilder::build_dummy_route);\n                    Ok(())\n                } else {\n                    TransformSortBuilder::add_route(&mut builder.main_pipeline)\n                }\n            }\n        }\n    }\n}\n\nimpl Sort {","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/service/src/physical_plans/physical_sort.rs#L272-L308","documentation":"In PhysicalSort's build_pipeline2, when a sort step leaves the main pipeline with more than one output and max_threads == 1, the code deliberately panics with unimplemented!() — the comment notes the query would otherwise hang in MultiSortMergeProcessor. So single-threaded execution of this sort shape is unsupported and raises 'not implemented'.","triggerScenarios":"Executing a query with a sort (SortStep) whose pipeline output_len != 1 while running with max_threads == 1 (e.g. single-threaded query settings, constrained executor config, or resource-group limiting threads to 1).","commonSituations":"Environments that force single-threaded execution: setting max_threads=1 / max_threads setting to 1 in the query context, CI tests with single-thread runtimes, or resource-constrained deployments; certain ORDER BY queries then panic instead of completing.","solutions":["Increase max_threads to >= 2 for the session/query (SET max_threads = 2 or higher).","Remove/adjust settings or resource-group limits that pin execution to a single thread.","Rewrite the query to avoid the multi-output sort shape, or add an explicit LIMIT that lets the planner collapse outputs.","For maintainers: replace the panic by merging outputs into one stream (resize pipeline) or fixing MultiSortMergeProcessor for max_threads == 1."],"exampleFix":"-- before\nSET max_threads = 1;  -- then ORDER BY query panics\n-- after\nSET max_threads = 4;","handlingStrategy":"validation","validationCode":"-- ensure multi-threaded execution for sort-heavy queries\nSELECT if(current_setting('max_threads')::int < 2, 'raise max_threads to >= 2', 'ok') AS check;","typeGuard":"fn single_threaded(ctx: &dyn TableContext) -> bool { ctx.get_settings().get_max_threads().unwrap_or(1) <= 1 }","tryCatchPattern":"match build_pipeline2(builder, ctx) {\n    Err(e) if e.to_string().contains(\"not implemented\") && ctx.get_max_threads() == 1 => {\n        retry_with_min_threads(2)?\n    }\n    other => other?,\n}","preventionTips":["Keep max_threads >= 2 in sessions that run ORDER BY queries.","Avoid forcing max_threads = 1 globally or in resource-group limits.","Add CI coverage for ORDER BY under single-thread settings to catch regressions early.","For single-core environments, prefer queries whose plans avoid multi-output sort steps."],"tags":["unimplemented","sort","single-thread","physical-plan"],"backgroundTag":"unsupported-operation","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"}