prestodb/presto · error · PrestoException
NOT_FOUND
NOT_FOUND
Error message
Target query not found: ${queryId} What it means
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.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/connector/system/KillQueryProcedure.java:72
QueryId query = parseQueryId(queryId);
try {
QueryState state = queryManager.getQueryState(query);
// check before killing to provide the proper error message (this is racy)
if (state.isDone()) {
throw new PrestoException(NOT_SUPPORTED, "Target query is not running: " + queryId);
}
queryManager.failQuery(query, createKillQueryException(message));
// verify if the query was killed (if not, we lost the race)
if (!ADMINISTRATIVELY_KILLED.toErrorCode().equals(queryManager.getQueryInfo(query).getErrorCode())) {
throw new PrestoException(NOT_SUPPORTED, "Target query is not running: " + queryId);
}
}
catch (NoSuchElementException e) {
throw new PrestoException(NOT_FOUND, "Target query not found: " + queryId);
}
}
public Procedure getProcedure()
{
return new Procedure(
"runtime",
"kill_query",
ImmutableList.<Argument>builder()
.add(new Argument("query_id", VARCHAR))
.add(new Argument("message", VARCHAR))
.build(),
KILL_QUERY.bindTo(this));
}
public static PrestoException createKillQueryException(String message)
{
return new PrestoException(ADMINISTRATIVELY_KILLED, "Query killed. " +View on GitHub (pinned to 55bb57d202)
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.
Example fix
// before CALL system.kill_query(query_id => '20240101_00001_0000'); -- id guessed // after SELECT query_id FROM system.runtime.queries WHERE state = 'RUNNING'; CALL system.kill_query(query_id => '<exact_id_from_runtime_queries>');
Defensive patterns
Strategy: validation
Validate before calling
boolean exists = sql("SELECT 1 FROM system.runtime.queries WHERE query_id = ?").param(queryId).exists();
if (!exists) throw new IllegalArgumentException("Unknown query id: " + queryId); Try / catch
try { killQuery(queryId, message); }
catch (PrestoException e) { if (e.getErrorCode() == StandardErrorCode.NOT_FOUND.toErrorCode()) { log.warn("Query {} already gone from registry", queryId); } else throw e; } Prevention
- 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
When it happens
Trigger: CALL system.kill_query(query_id => '...') where getQueryState/getQueryInfo throws NoSuchElementException because the query ID is not present in the coordinator's registry.
Common situations: 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.
Understand the failure class
Background: NOT_FOUND error code: why tRPC, Harbor, Nacos and other libraries return 404 "not found" errors for resources that may still exist — this error's family across 11 libraries.
Related errors
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/5fc998b8596ead03.
Report an issue: GitHub.