问题
I have this code
UUID notUuid = UUIDs.timeBased();
PreparedStatement pstmt = cqlSession.prepare("INSERT INTO mytable(userId, notifId, notification, time, read, deleted) VALUES(?, ?, ?, ?, ?, ?)");
BoundStatement boundStatement = new BoundStatement(pstmt);
cqlSession.execute(boundStatement.bind(userId, notUuid, notfMsg, System.currentTimeMillis(), MigificConstants.UNREAD, "false"));
when i run this code, in the log it shows
Re-preparing already prepared query INSERT INTO mytable(userId, notifId, notification, time, read, deleted) VALUES(?, ?, ?, ?, ?, ?). Please note that preparing the same query more than once is generally an anti-pattern and will likely affect performance. Consider preparing the statement only once.
回答1:
Is this code part of a method that is called multiple times?
Statements need only be prepared once per Cluster instance, you should do it in some initialization part of your application.
来源:https://stackoverflow.com/questions/26922538/datastax-re-preparing-already-prepared-query-warning