{"record":{"id":"5fc998b8596ead03","repo":"prestodb/presto","slug":"not-found-5fc998","errorCode":"NOT_FOUND","errorMessage":"Target query not found: ${queryId}","messagePattern":"Target query not found: (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/connector/system/KillQueryProcedure.java","lineNumber":72,"sourceCode":"        QueryId query = parseQueryId(queryId);\n\n        try {\n            QueryState state = queryManager.getQueryState(query);\n\n            // check before killing to provide the proper error message (this is racy)\n            if (state.isDone()) {\n                throw new PrestoException(NOT_SUPPORTED, \"Target query is not running: \" + queryId);\n            }\n\n            queryManager.failQuery(query, createKillQueryException(message));\n\n            // verify if the query was killed (if not, we lost the race)\n            if (!ADMINISTRATIVELY_KILLED.toErrorCode().equals(queryManager.getQueryInfo(query).getErrorCode())) {\n                throw new PrestoException(NOT_SUPPORTED, \"Target query is not running: \" + queryId);\n            }\n        }\n        catch (NoSuchElementException e) {\n            throw new PrestoException(NOT_FOUND, \"Target query not found: \" + queryId);\n        }\n    }\n\n    public Procedure getProcedure()\n    {\n        return new Procedure(\n                \"runtime\",\n                \"kill_query\",\n                ImmutableList.<Argument>builder()\n                        .add(new Argument(\"query_id\", VARCHAR))\n                        .add(new Argument(\"message\", VARCHAR))\n                        .build(),\n                KILL_QUERY.bindTo(this));\n    }\n\n    public static PrestoException createKillQueryException(String message)\n    {\n        return new PrestoException(ADMINISTRATIVELY_KILLED, \"Query killed. \" +","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/connector/system/KillQueryProcedure.java#L54-L90","documentation":"kill_query translates NoSuchElementException from queryManager lookups into NOT_FOUND with 'Target query not found: <queryId>'. This means no query with that ID exists in the coordinator's (in-memory/clustering) query registry — the ID is wrong, expired, or was pruned, as opposed to error 1804/1805 where the query exists but is done.","triggerScenarios":"CALL system.kill_query(query_id => '...') where getQueryState/getQueryInfo throws NoSuchElementException because the query ID is not present in the coordinator's registry.","commonSituations":"Typos or truncation of query IDs; killing a query after coordinator restart (in-memory registry lost); old IDs beyond query max-history retention; pointing the kill at the wrong coordinator in multi-coordinator setups.","solutions":["Verify the exact queryId from the query UI/listing (system.runtime.queries) before calling kill_query.","Confirm you are connected to the coordinator that owns the query (or a cluster sharing query state).","Increase query history retention if automation needs to kill recently completed queries; treat NOT_FOUND as no-op for stale IDs."],"exampleFix":"// before\nCALL system.kill_query(query_id => '20240101_00001_0000'); -- id guessed\n// after\nSELECT query_id FROM system.runtime.queries WHERE state = 'RUNNING';\nCALL system.kill_query(query_id => '<exact_id_from_runtime_queries>');","handlingStrategy":"validation","validationCode":"boolean exists = sql(\"SELECT 1 FROM system.runtime.queries WHERE query_id = ?\").param(queryId).exists();\nif (!exists) throw new IllegalArgumentException(\"Unknown query id: \" + queryId);","typeGuard":null,"tryCatchPattern":"try { killQuery(queryId, message); }\ncatch (PrestoException e) { if (e.getErrorCode() == StandardErrorCode.NOT_FOUND.toErrorCode()) { log.warn(\"Query {} already gone from registry\", queryId); } else throw e; }","preventionTips":["Copy query IDs exactly from the UI or system.runtime.queries","Remember the registry is in-memory: coordinator restarts clear it","In multi-coordinator setups, kill via the coordinator that owns the query","Treat NOT_FOUND for stale IDs as a no-op"],"tags":["query-management","not-found","procedure"],"backgroundTag":"query-not-found","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}