0

Getting the warning:

Re-preparing already prepared query is generally an anti-pattern and will likely affect performance. Consider preparing the statement only once.

I saw various similar questions like this Datastax: Re-preparing already prepared query warning but they didn't address re-assigning the keyspace or table that the query uses.

I could generally re-use the query , but it will require caching it per keyspace and table, and I don't want to manage state. Alternatively I could rebind the keyspace and table before executing the query (and then no need to recreate):

// the insertion query I am using

def insertQuery(keyspace: String, table: String): Insert = QueryBuilder.insertInto(keyspace, table)
    .value("c1", QueryBuilder.bindMarker())
    .value("c2")
    .value(...)
    .value("c_n")

Would need something like this:

QueryBuilder.insertInto(keyspace = ???BIND MARKER????, table = ???BIND MARKER???)
Avba
  • 14,822
  • 20
  • 92
  • 192

1 Answers1

1

You can't bind keyspace & table names...

If you don't want to cache prepared queries, then you really don't need to use them - just generate SimpleStatement instead - it will be more effective because right now if you prepare on every request, you're doing 2 network roundtrips - one for preparing query, and another for its execution.

But I would recommend to prepare all necessary queries at startup/first connection, because they could bring quite significant performance improvement (if you care, of course).

Alex Ott
  • 80,552
  • 8
  • 87
  • 132