{"record":{"id":"532faaf68d91df54","repo":"databendlabs/databend","slug":"internal-error-entered-unreachable-code-532faa","errorCode":null,"errorMessage":"internal error: entered unreachable code","messagePattern":"internal error: entered unreachable code","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/query/storages/common/index/src/spatial_predicate.rs","lineNumber":210,"sourceCode":"            }\n            \"st_within\" | \"st_coveredby\" => {\n                if column_is_left {\n                    SpatialPredicateOp::Within\n                } else {\n                    SpatialPredicateOp::Contains\n                }\n            }\n            \"st_intersects\" => SpatialPredicateOp::Intersects,\n            \"st_dwithin\" => {\n                let Some(distance) = Self::extract_constant_arg(&args[2])\n                    .and_then(|scalar| scalar.to_distance_threshold())\n                else {\n                    return Self::visit_function_call(call, self);\n                };\n\n                SpatialPredicateOp::Distance(distance)\n            }\n            _ => unreachable!(),\n        };\n\n        let Ok(column_id) = self.schema.column_id_of(&column) else {\n            return Self::visit_function_call(call, self);\n        };\n        if let Some(spatial_index_columns) = self.spatial_index_columns {\n            if !spatial_index_columns.contains(&column_id) {\n                return Self::visit_function_call(call, self);\n            }\n        }\n\n        let Some((query_rect, query_srid)) = Self::scalar_to_query(&constant) else {\n            return Self::visit_function_call(call, self);\n        };\n\n        let placeholder = self.next_placeholder_name();\n        self.predicates.push(SpatialPredicate {\n            column_id,","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/storages/common/index/src/spatial_predicate.rs#L192-L228","documentation":"The spatial index visitor, when entering a function call, expects the top-level expression to be one of a known set of spatial functions (e.g. ST_Distance, ST_Within variants). If the function call's name maps to none of the expected arms, `_ => unreachable!()` fires, producing internal error 1001 while planning a query against a spatial index.","triggerScenarios":"Running a query whose WHERE clause contains a function call that the spatial-index rule visits but that is not one of the supported spatial predicates — i.e. the index rewrite rule is applied to a non-spatial function (optimizer scoping bug) or a new ST_* function was added without updating the visitor.","commonSituations":"Queries mixing spatial predicates with other functions on geometry columns; Databend version where a newly added spatial function isn't handled in spatial_predicate.rs.","solutions":["Simplify the WHERE clause so only supported spatial functions (e.g. ST_Distance/ST_Within against indexed geometry columns) appear, putting other predicates in a separate condition","Disable/bypass the spatial index for that query (e.g. drop the spatial index) to confirm the query itself runs","Report the query and version as a bug: the default arm should fall back to visit_function_call rather than unreachable!()"],"exampleFix":"// before\n_ => unreachable!(),\n// after\n_ => return Self::visit_function_call(call, self),\n","handlingStrategy":"try-catch","validationCode":"-- keep spatial predicates to supported functions on indexed geometry columns\n-- supported: ST_Distance(a, b) <= r, ST_Within(a, b)\n-- put other function calls outside the indexed spatial predicate","typeGuard":null,"tryCatchPattern":"try {\n  runQuery(sql);\n} catch (e) {\n  if (e.code === 1001 && /spatial|st_/i.test(sql)) {\n    // drop the spatial index or rewrite the predicate, then retry\n  }\n}","preventionTips":["Use only supported ST_* predicates in WHERE clauses against spatial-indexed columns","Re-test spatial queries after Databend upgrades (new ST_* functions may be unhandled)","Separate non-spatial predicates from the indexed spatial condition"],"tags":["rust","spatial-index","internal-error","planner","optimizer"],"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"}