{"record":{"id":"45cccc61e08e09da","repo":"apache/cassandra","slug":"prepared-statement-recreation-error-removing-stat","errorCode":null,"errorMessage":"Prepared statement recreation error, removing statement: {} {} {}, error details: {}","messagePattern":"Prepared statement recreation error, removing statement: (.+?) (.+?) (.+?), error details: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/java/org/apache/cassandra/cql3/QueryProcessor.java","lineNumber":229,"sourceCode":"        int count = SystemKeyspace.loadPreparedStatements((id, query, keyspace) -> {\n            try\n            {\n                ClientState clientState = ClientState.forInternalCalls();\n                if (keyspace != null)\n                    clientState.setKeyspace(keyspace);\n\n                Prepared prepared = parseAndPrepare(query, clientState, false);\n                preparedStatements.put(id, prepared);\n\n                // Preload `null` statement for non-fully qualified statements, since it can't be parsed if loaded from cache and will be dropped\n                if (!prepared.fullyQualified)\n                    preparedStatements.get(computeId(query, null), (ignored_) -> prepared);\n                return prepared;\n            }\n            catch (RequestValidationException e)\n            {\n                JVMStabilityInspector.inspectThrowable(e);\n                logger.warn(\"Prepared statement recreation error, removing statement: {} {} {}, error details: {}\", id, query, keyspace, e.getMessage());\n                SystemKeyspace.removePreparedStatement(id);\n                return null;\n            }\n        }, pageSize);\n        long endTime = nanoTime();\n        logger.info(\"Preloaded {} prepared statements in {} ms\", count, TimeUnit.NANOSECONDS.toMillis(endTime - startTime));\n        return count;\n    }\n\n\n    /**\n     * Clears the prepared statement cache.\n     * @param memoryOnly {@code true} if only the in memory caches must be cleared, {@code false} otherwise.\n     */\n    @VisibleForTesting\n    public static void clearPreparedStatements(boolean memoryOnly)\n    {\n        preparedStatements.invalidateAll();","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/QueryProcessor.java#L211-L247","documentation":"During startup, QueryProcessor replays previously prepared statements persisted in system.prepared_statements and re-parses each query. If a stored query fails to re-prepare (RequestValidationException, e.g. schema drift or invalid CQL), this warning is logged, the statement is removed from the system table, and the node continues startup without it. It is self-healing: clients will re-prepare the statement on next use.","triggerScenarios":"Node restart with rows in system.prepared_statements whose queries no longer validate: dropped keyspaces/tables, changed types, CQL syntax no longer valid after upgrade, or corrupted rows in system.prepared_statements.","commonSituations":"Upgrades/downgrades across Cassandra versions where CQL validation changed; schema was dropped while the node was down; manual edits or corruption of the prepared statements table.","solutions":["Inspect the logged query/keyspace and fix the underlying schema (recreate the dropped keyspace/table or correct types) if the statement is still needed.","Let it self-heal: the statement is removed from system.prepared_statements and clients transparently re-prepare it; verify client applications reconnect and re-prepare.","If it persists after upgrade, check compatibility of the stored query with the new CQL version and have clients prepare updated queries.","If system.prepared_statements is corrupt, clear the offending rows (nodetool drain/stop not required; row removal is automatic) and restart."],"exampleFix":"// before: client caches a prepared statement against a table that was dropped/recreated\n// after: invalidate client prepared-statement cache on schema change and re-prepare\nsession.invalidatePreparedStatements();\nPreparedStatement ps = session.prepare(\"SELECT ... FROM ks.tbl ...\");","handlingStrategy":"validation","validationCode":"// Client-side: re-prepare on schema change and keep statement cache in sync\nif (schemaChangedNotification) {\n    preparedCache.clear(); // drop cached PreparedStatements after schema events\n}\n// Validate a query parses before persisting expectations:\n// session.prepare(query) inside try/catch(InvalidQueryException) before caching","typeGuard":null,"tryCatchPattern":"// Drivers handle this transparently: catch com.datastax.driver.core.exceptions.BootstrappingException-like\n// re-prepare triggers automatically; for core usage:\ntry {\n    PreparedStatement ps = session.prepare(query);\n} catch (InvalidQueryException e) {\n    log.warn(\"Stored prepared statement no longer valid, re-prepare with current schema\", e);\n}","preventionTips":["Invalidate application prepared-statement caches when schema changes occur (drivers do this via schema event listeners).","Avoid manual edits to system.prepared_statements.","After major upgrades, expect one-time re-preparation warnings; monitor startup logs.","Keep client driver versions in sync with server CQL capabilities."],"tags":["cassandra","prepared-statement","startup","schema-drift"],"backgroundTag":"schema-validation-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}