diff --git a/db/schema_applier.cc b/db/schema_applier.cc index 29baeb2a19..2f9a87aa6a 100644 --- a/db/schema_applier.cc +++ b/db/schema_applier.cc @@ -335,7 +335,7 @@ static std::vector get_primary_key(const std::vector& // Build a map from primary keys to rows. static std::map, const query::result_set_row*> build_row_map(const query::result_set& result) { - const std::vector& rows = result.rows(); + const auto& rows = result.rows(); auto primary_key = get_primary_key_definition(result.schema()); std::map, const query::result_set_row*> ret; for (const auto& row: rows) { diff --git a/query/query-result-set.cc b/query/query-result-set.cc index b08af9c872..85d443f26f 100644 --- a/query/query-result-set.cc +++ b/query/query-result-set.cc @@ -17,6 +17,13 @@ namespace query { +static_assert(std::is_nothrow_move_constructible_v); +static_assert(std::is_nothrow_move_assignable_v); +static_assert(std::is_nothrow_move_constructible_v); +static_assert(std::is_nothrow_move_assignable_v); +static_assert(std::is_nothrow_move_constructible_v); +static_assert(std::is_nothrow_move_assignable_v); + class deserialization_error : public std::runtime_error { public: using runtime_error::runtime_error; @@ -28,7 +35,7 @@ public: class result_set_builder { schema_ptr _schema; const partition_slice& _slice; - std::vector _rows; + result_set::rows_type _rows; std::unordered_map _pkey_cells; uint64_t _row_count; public: @@ -47,7 +54,7 @@ private: }; std::ostream& operator<<(std::ostream& out, const result_set_row& row) { - for (auto&& cell : row._cells) { + for (auto&& cell : row.cells()) { auto&& type = static_cast(cell.second).type(); auto&& value = cell.second; out << cell.first << "=\"" << type->to_string(type->decompose(value)) << "\" "; diff --git a/query/query-result-set.hh b/query/query-result-set.hh index d85c9cfd27..22533063c2 100644 --- a/query/query-result-set.hh +++ b/query/query-result-set.hh @@ -46,7 +46,7 @@ inline bool operator==(const non_null_data_value& x, const non_null_data_value& // including regular column cells, partition keys, as well as static values. class result_set_row { schema_ptr _schema; - const std::unordered_map _cells; + std::unordered_map _cells; public: result_set_row(schema_ptr schema, std::unordered_map&& cells) : _schema{schema} @@ -54,15 +54,16 @@ public: { } result_set_row(result_set_row&&) = default; result_set_row(const result_set_row&) = delete; + result_set_row& operator=(result_set_row&&) = default; result_set_row& operator=(const result_set_row&) = delete; result_set_row copy() const { - return {_schema, std::unordered_map{_cells}}; + return {_schema, std::unordered_map{cells()}}; } // Look up a deserialized row cell value by column name const data_value* get_data_value(const sstring& column_name) const { - auto it = _cells.find(column_name); - if (it == _cells.end()) { + auto it = cells().find(column_name); + if (it == cells().end()) { return nullptr; } return &static_cast(it->second); @@ -103,11 +104,14 @@ public: // deserialized format. To obtain a result set, use the result_set_builder // class as a visitor to query_result::consume() function. class result_set { +public: + using rows_type = utils::chunked_vector; +private: schema_ptr _schema; - std::vector _rows; + rows_type _rows; public: static result_set from_raw_result(schema_ptr, const partition_slice&, const result&); - result_set(schema_ptr s, std::vector&& rows) + result_set(schema_ptr s, rows_type&& rows) : _schema(std::move(s)), _rows{std::move(rows)} { } explicit result_set(const mutation&); @@ -121,7 +125,7 @@ public: } return _rows[idx]; } - const std::vector& rows() const { + const rows_type& rows() const { return _rows; } const schema_ptr& schema() const { diff --git a/test/boost/multishard_query_test.cc b/test/boost/multishard_query_test.cc index 7e0a5c0ae8..eaabc9ec8e 100644 --- a/test/boost/multishard_query_test.cc +++ b/test/boost/multishard_query_test.cc @@ -450,7 +450,7 @@ private: schema_ptr _s; const query::partition_slice& _slice; uint64_t _page_size = 0; - std::vector _rows; + query::result_set::rows_type _rows; std::optional _last_pkey; std::optional _last_ckey; uint64_t _last_pkey_rows = 0; @@ -816,7 +816,7 @@ SEASTAR_THREAD_TEST_CASE(test_read_reversed) { auto [data_results, _np2] = read_partitions_with_generic_paged_scan(db, s, page_size, std::numeric_limits::max(), stateful, query::full_partition_range, slice); - std::vector expected_rows; + query::result_set::rows_type expected_rows; for (const auto& mut : expected_results) { auto rs = query::result_set(mut); std::ranges::copy(rs.rows() | std::views::transform([](const auto& row) { return row.copy(); }), std::back_inserter(expected_rows)); diff --git a/types/types.cc b/types/types.cc index 2b06e6b9e5..156b651d8f 100644 --- a/types/types.cc +++ b/types/types.cc @@ -37,6 +37,7 @@ #include #include #include +#include #include #include "utils/big_decimal.hh" #include "utils/date.h" @@ -55,6 +56,9 @@ #include "types/set.hh" #include "types/listlike_partial_deserializing_iterator.hh" +static_assert(std::is_nothrow_move_constructible_v); +static_assert(std::is_nothrow_move_assignable_v); + static logging::logger tlogger("types"); bytes_view_opt read_collection_value(bytes_view& in); @@ -3839,7 +3843,7 @@ data_value::data_value(const data_value& v) : _value(nullptr), _type(v._type) { } data_value& -data_value::operator=(data_value&& x) { +data_value::operator=(data_value&& x) noexcept { auto tmp = std::move(x); std::swap(tmp._value, this->_value); std::swap(tmp._type, this->_type); diff --git a/types/types.hh b/types/types.hh index 76daf59a62..f6fdbd4444 100644 --- a/types/types.hh +++ b/types/types.hh @@ -261,7 +261,7 @@ public: data_value(bool_class); data_value& operator=(const data_value&); - data_value& operator=(data_value&&); + data_value& operator=(data_value&&) noexcept; const data_type& type() const { return _type; }