Merge 'cql3: select_statement: split and coroutinize process_results()' from Avi Kivity
Split the simple (and common) case from the complex case, and coroutinize the latter. Hopefully this generates better code for the simple case, and it makes the complex case a little nicer. Closes #12194 * github.com:scylladb/scylladb: cql3: select_statement: reindent process_results_complex() cql3: select_statement: coroutinize process_results_complex() cql3: select_statement: split process_results() into fast path and complex path
This commit is contained in:
@@ -804,35 +804,40 @@ select_statement::process_results(foreign_ptr<lw_shared_ptr<query::result>> resu
|
||||
::make_shared<metadata>(*_selection->get_result_metadata()))
|
||||
));
|
||||
}
|
||||
return process_results_complex(std::move(results), std::move(cmd), options, now);
|
||||
}
|
||||
|
||||
future<shared_ptr<cql_transport::messages::result_message>>
|
||||
select_statement::process_results_complex(foreign_ptr<lw_shared_ptr<query::result>> results,
|
||||
lw_shared_ptr<query::read_command> cmd,
|
||||
const query_options& options,
|
||||
gc_clock::time_point now) const {
|
||||
cql3::selection::result_set_builder builder(*_selection, now,
|
||||
options.get_cql_serialization_format());
|
||||
return do_with(std::move(builder), [this, cmd, results = std::move(results), options] (cql3::selection::result_set_builder& builder) mutable {
|
||||
return builder.with_thread_if_needed([this, &builder, cmd, results = std::move(results), options] {
|
||||
if (_restrictions_need_filtering) {
|
||||
results->ensure_counts();
|
||||
_stats.filtered_rows_read_total += *results->row_count();
|
||||
query::result_view::consume(*results, cmd->slice,
|
||||
cql3::selection::result_set_builder::visitor(builder, *_schema,
|
||||
*_selection, cql3::selection::result_set_builder::restrictions_filter(_restrictions, options, cmd->get_row_limit(), _schema, cmd->slice.partition_row_limit())));
|
||||
} else {
|
||||
query::result_view::consume(*results, cmd->slice,
|
||||
cql3::selection::result_set_builder::visitor(builder, *_schema,
|
||||
*_selection));
|
||||
}
|
||||
auto rs = builder.build();
|
||||
co_return co_await builder.with_thread_if_needed([&] {
|
||||
if (_restrictions_need_filtering) {
|
||||
results->ensure_counts();
|
||||
_stats.filtered_rows_read_total += *results->row_count();
|
||||
query::result_view::consume(*results, cmd->slice,
|
||||
cql3::selection::result_set_builder::visitor(builder, *_schema,
|
||||
*_selection, cql3::selection::result_set_builder::restrictions_filter(_restrictions, options, cmd->get_row_limit(), _schema, cmd->slice.partition_row_limit())));
|
||||
} else {
|
||||
query::result_view::consume(*results, cmd->slice,
|
||||
cql3::selection::result_set_builder::visitor(builder, *_schema,
|
||||
*_selection));
|
||||
}
|
||||
auto rs = builder.build();
|
||||
|
||||
if (needs_post_query_ordering()) {
|
||||
rs->sort(_ordering_comparator);
|
||||
if (_is_reversed) {
|
||||
rs->reverse();
|
||||
}
|
||||
rs->trim(cmd->get_row_limit());
|
||||
if (needs_post_query_ordering()) {
|
||||
rs->sort(_ordering_comparator);
|
||||
if (_is_reversed) {
|
||||
rs->reverse();
|
||||
}
|
||||
update_stats_rows_read(rs->size());
|
||||
_stats.filtered_rows_matched_total += _restrictions_need_filtering ? rs->size() : 0;
|
||||
return shared_ptr<cql_transport::messages::result_message>(::make_shared<cql_transport::messages::result_message::rows>(result(std::move(rs))));
|
||||
});
|
||||
rs->trim(cmd->get_row_limit());
|
||||
}
|
||||
update_stats_rows_read(rs->size());
|
||||
_stats.filtered_rows_matched_total += _restrictions_need_filtering ? rs->size() : 0;
|
||||
return shared_ptr<cql_transport::messages::result_message>(::make_shared<cql_transport::messages::result_message::rows>(result(std::move(rs))));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -79,6 +79,9 @@ protected:
|
||||
bool _range_scan = false;
|
||||
bool _range_scan_no_bypass_cache = false;
|
||||
std::unique_ptr<cql3::attributes> _attrs;
|
||||
private:
|
||||
future<shared_ptr<cql_transport::messages::result_message>> process_results_complex(foreign_ptr<lw_shared_ptr<query::result>> results,
|
||||
lw_shared_ptr<query::read_command> cmd, const query_options& options, gc_clock::time_point now) const;
|
||||
protected :
|
||||
virtual future<::shared_ptr<cql_transport::messages::result_message>> do_execute(query_processor& qp,
|
||||
service::query_state& state, const query_options& options) const;
|
||||
|
||||
Reference in New Issue
Block a user