{"record":{"id":"676e68921197146f","repo":"prestodb/presto","slug":"not-found-676e68","errorCode":"NOT_FOUND","errorMessage":"Prepared statement not found: ","messagePattern":"Prepared statement not found: ","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/execution/QueryStateMachine.java","lineNumber":733,"sourceCode":"    public Set<SqlFunctionId> getRemovedSessionFunctions()\n    {\n        return removedSessionFunctions;\n    }\n\n    public void addPreparedStatement(String key, String value)\n    {\n        requireNonNull(key, \"key is null\");\n        requireNonNull(value, \"value is null\");\n\n        addedPreparedStatements.put(key, value);\n    }\n\n    public void removePreparedStatement(String key)\n    {\n        requireNonNull(key, \"key is null\");\n\n        if (!session.getPreparedStatements().containsKey(key)) {\n            throw new PrestoException(NOT_FOUND, \"Prepared statement not found: \" + key);\n        }\n        deallocatedPreparedStatements.add(key);\n    }\n\n    public void addSessionFunction(SqlFunctionId signature, SqlInvokedFunction function)\n    {\n        requireNonNull(signature, \"signature is null\");\n        requireNonNull(function, \"function is null\");\n\n        if (session.getSessionFunctions().containsKey(signature) || addedSessionFunctions.putIfAbsent(signature, function) != null) {\n            throw new PrestoException(ALREADY_EXISTS, format(\"Session function %s has already been defined\", signature));\n        }\n    }\n\n    public void removeSessionFunction(SqlFunctionId signature, boolean suppressNotFoundException)\n    {\n        requireNonNull(signature, \"signature is null\");\n","sourceCodeStart":715,"sourceCodeEnd":751,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/execution/QueryStateMachine.java#L715-L751","documentation":"Thrown by QueryStateMachine.removePreparedStatement when DEALLOCATE targets a key not present in session.getPreparedStatements(). Presto tracks prepared statements per session; deallocating an unknown key raises NOT_FOUND and, note, the key would otherwise be added to deallocatedPreparedStatements.","triggerScenarios":"Executing `DEALLOCATE PREPARE name` where name was never prepared in the current session, was already deallocated, or the session was replaced (new connection/connection pool handed a fresh session).","commonSituations":"Connection pool returning a different session than the one where PREPARE ran; DEALLOCATE executed twice; application restart clearing server-side prepared statements while client state persists.","solutions":["Verify the statement was prepared in the same session (SHOW PREPARED STATEMENTS / check addPreparedStatement path)","Fix application flow so DEALLOCATE only runs for names prepared earlier in the same connection","Guard DEALLOCATE calls to run once, or tolerate NOT_FOUND in the caller"],"exampleFix":"// before\nDEALLOCATE PREPARE my_stmt; // prepared on another connection\n// after\nPREPARE my_stmt FROM SELECT 1; // same session first\nDEALLOCATE PREPARE my_stmt;","handlingStrategy":"try-catch","validationCode":"if (session.getPreparedStatements().containsKey(name)) {\n    stateMachine.removePreparedStatement(name);\n}","typeGuard":null,"tryCatchPattern":"try { deallocate(name); } catch (PrestoException e) { if (e.getErrorCode().getCode() == StandardErrorCode.NOT_FOUND.toErrorCodeCode()) { /* already gone; idempotent no-op */ } else { throw e; } }","preventionTips":["Run DEALLOCATE on the same connection/session where PREPARE ran","Make cleanup idempotent by tolerating NOT_FOUND","Configure connection pools to reset prepared-statement state consistently on checkin/checkout"],"tags":["presto","prepared-statement","session","not-found"],"backgroundTag":"prepared-statement-not-found","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}