scylladb / scylladb

NoSQL data store using the seastar framework, compatible with Apache Cassandra
http://scylladb.com
GNU Affero General Public License v3.0
13.52k stars 1.29k forks source link

warnings vector is copied 2 times unnecessarily in query_processor::execute_direct_without_checking_exception_message() and query_processor::do_execute_direct() #20361

Open bitpathfinder opened 2 months ago

bitpathfinder commented 2 months ago

Below code at query_processor.cc:571

 auto p = get_statement(query_string, query_state.get_client_state());
    auto statement = p->statement;
    const auto warnings = std::move(p->warnings);

Makes a copy of a std::vector as p->statement is declared const in prepared_statement:

Later, at line query_processor.cc:589 the same const warnings variable attempted to be moved again:

return execute_maybe_with_guard(query_state, std::move(statement), options, &query_processor::do_execute_direct, std::move(warnings));

but, again as the variable is const, it results another copying of the vector. looking at the function do_execute_direct , moving the object is completely redundant as the variable is not moved to a co-routine, but is copied from, thus making warnings and the function parameter a const reference would work better in this case.

muthu90tech commented 2 weeks ago

https://github.com/scylladb/scylladb/pull/21083