Change the way reading in order is requested from plan optimizations

This commit is contained in:
Igor Nikonov 2022-09-22 20:47:00 +00:00
parent 9ea277c047
commit 6551966dc7
4 changed files with 10 additions and 12 deletions

View File

@ -79,11 +79,8 @@ size_t tryDistinctReadInOrder(QueryPlan::Node * parent_node, QueryPlan::Nodes &)
return 0;
/// update input order info in read_from_merge_tree step
const int direction = output_sort_desc.front().direction; /// for DISTINCT direction doesn't matter, so use current direction
/// example: SELECT DISTINCT a from t ORDER BY a DESC;
InputOrderInfoPtr order_info
= std::make_shared<const InputOrderInfo>(SortDescription{}, number_of_sorted_distinct_columns, direction, pre_distinct->getLimitHint());
read_from_merge_tree->setQueryInfoInputOrderInfo(order_info);
const int direction = 0; /// for DISTINCT direction doesn't matter, ReadFromMergeTree will choose proper one
read_from_merge_tree->requestReadingInOrder(number_of_sorted_distinct_columns, direction, pre_distinct->getLimitHint());
/// update data stream's sorting properties for found transforms
const DataStream * input_stream = &read_from_merge_tree->getOutputStream();

View File

@ -101,7 +101,7 @@ size_t tryReuseStorageOrderingForWindowFunctions(QueryPlan::Node * parent_node,
if (order_info)
{
read_from_merge_tree->setQueryInfoInputOrderInfo(order_info);
read_from_merge_tree->requestReadingInOrder(order_info->used_prefix_of_sorting_key_size, order_info->direction, order_info->limit);
sorting->convertToFinishSorting(order_info->sort_description_for_merging);
}

View File

@ -1018,16 +1018,17 @@ MergeTreeDataSelectAnalysisResultPtr ReadFromMergeTree::selectRangesToRead(
return std::make_shared<MergeTreeDataSelectAnalysisResult>(MergeTreeDataSelectAnalysisResult{.result = std::move(result)});
}
void ReadFromMergeTree::setQueryInfoInputOrderInfo(InputOrderInfoPtr order_info)
void ReadFromMergeTree::requestReadingInOrder(size_t prefix_size, int direction, size_t limit)
{
/// if dirction is not set, use current one
if (!direction)
direction = getSortDirection();
auto order_info = std::make_shared<InputOrderInfo>(SortDescription{}, prefix_size, direction, limit);
if (query_info.projection)
{
query_info.projection->input_order_info = order_info;
}
else
{
query_info.input_order_info = order_info;
}
/// update sort info for output stream
SortDescription sort_description;

View File

@ -151,7 +151,7 @@ public:
const SelectQueryInfo & getQueryInfo() const { return query_info; }
StorageMetadataPtr getStorageMetadata() const { return metadata_for_reading; }
void setQueryInfoInputOrderInfo(InputOrderInfoPtr order_info);
void requestReadingInOrder(size_t prefix_size, int direction, size_t limit);
private:
int getSortDirection() const