Propagate GROUP BY indices to result_set_builder

Ensure that the indices recorded in select_statement are passed to
result_set_builder when one is created for processing the cell values.

Signed-off-by: Dejan Mircevski <dejan@scylladb.com>
This commit is contained in:
Dejan Mircevski
2019-05-07 00:38:29 -04:00
parent 274a77f45e
commit c3929aee3a
4 changed files with 11 additions and 4 deletions

View File

@@ -263,9 +263,11 @@ selection::collect_metadata(schema_ptr schema, const std::vector<::shared_ptr<ra
return r;
}
result_set_builder::result_set_builder(const selection& s, gc_clock::time_point now, cql_serialization_format sf)
result_set_builder::result_set_builder(const selection& s, gc_clock::time_point now, cql_serialization_format sf,
std::vector<size_t> group_by_cell_indices)
: _result_set(std::make_unique<result_set>(::make_shared<metadata>(*(s.get_result_metadata()))))
, _selectors(s.new_selectors())
, _group_by_cell_indices(std::move(group_by_cell_indices))
, _now(now)
, _cql_serialization_format(sf)
{

View File

@@ -244,6 +244,7 @@ class result_set_builder {
private:
std::unique_ptr<result_set> _result_set;
std::unique_ptr<selectors> _selectors;
const std::vector<size_t> _group_by_cell_indices; ///< Indices in \c current of cells holding GROUP BY values.
public:
std::optional<std::vector<bytes_opt>> current;
private:
@@ -306,7 +307,8 @@ public:
bool do_filter(const selection& selection, const std::vector<bytes>& pk, const std::vector<bytes>& ck, const query::result_row_view& static_row, const query::result_row_view& row) const;
};
result_set_builder(const selection& s, gc_clock::time_point now, cql_serialization_format sf);
result_set_builder(const selection& s, gc_clock::time_point now, cql_serialization_format sf,
std::vector<size_t> group_by_cell_indices = {});
void add_empty();
void add(bytes_opt value);
void add(const column_definition& def, const query::result_atomic_cell_view& c);

View File

@@ -317,7 +317,8 @@ select_statement::do_execute(service::storage_proxy& proxy,
// An aggregation query will never be paged for the user, but we always page it internally to avoid OOM.
// If we user provided a page_size we'll use that to page internally (because why not), otherwise we use our default
// Note that if there are some nodes in the cluster with a version less than 2.0, we can't use paging (CASSANDRA-6707).
const bool aggregate = _selection->is_aggregate();
// Also note: all GROUP BY queries are considered aggregation.
const bool aggregate = _selection->is_aggregate() || has_group_by();
const bool nonpaged_filtering = restrictions_need_filtering && page_size <= 0;
if (aggregate || nonpaged_filtering) {
page_size = DEFAULT_COUNT_PAGE_SIZE;
@@ -339,7 +340,7 @@ select_statement::do_execute(service::storage_proxy& proxy,
if (aggregate || nonpaged_filtering) {
return do_with(
cql3::selection::result_set_builder(*_selection, now,
options.get_cql_serialization_format()),
options.get_cql_serialization_format(), *_group_by_cell_indices),
[this, p, page_size, now, timeout_duration, restrictions_need_filtering](auto& builder) {
return do_until([p] {return p->is_exhausted();},
[p, &builder, page_size, now, timeout_duration] {

View File

@@ -142,6 +142,8 @@ public:
::shared_ptr<restrictions::statement_restrictions> get_restrictions() const;
bool has_group_by() { return _group_by_cell_indices && !_group_by_cell_indices->empty(); }
protected:
uint32_t do_get_limit(const query_options& options, ::shared_ptr<term> limit) const;
uint32_t get_limit(const query_options& options) const {