2019-12-10 23:18:24 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Core/SortDescription.h>
|
|
|
|
#include <Storages/MergeTree/MergeTreeData.h>
|
|
|
|
#include <Storages/SelectQueryInfo.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/** Helper class, that can analyze MergeTree order key
|
2019-12-20 13:15:17 +00:00
|
|
|
* and required sort description to get their
|
|
|
|
* common prefix, which is needed for
|
2019-12-10 23:18:24 +00:00
|
|
|
* performing reading in order of PK.
|
|
|
|
*/
|
2020-12-12 16:42:15 +00:00
|
|
|
class Context;
|
|
|
|
|
2019-12-10 23:18:24 +00:00
|
|
|
class ReadInOrderOptimizer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ReadInOrderOptimizer(
|
2021-12-14 12:54:20 +00:00
|
|
|
const ASTSelectQuery & query,
|
2019-12-10 23:18:24 +00:00
|
|
|
const ManyExpressionActions & elements_actions,
|
|
|
|
const SortDescription & required_sort_description,
|
2020-07-22 17:13:05 +00:00
|
|
|
const TreeRewriterResultPtr & syntax_result);
|
2019-12-10 23:18:24 +00:00
|
|
|
|
2021-07-13 14:24:45 +00:00
|
|
|
InputOrderInfoPtr getInputOrder(const StorageMetadataPtr & metadata_snapshot, ContextPtr context, UInt64 limit = 0) const;
|
2019-12-10 23:18:24 +00:00
|
|
|
|
|
|
|
private:
|
2021-12-14 12:54:20 +00:00
|
|
|
InputOrderInfoPtr getInputOrderImpl(
|
|
|
|
const StorageMetadataPtr & metadata_snapshot,
|
|
|
|
const SortDescription & description,
|
|
|
|
const ManyExpressionActions & actions,
|
|
|
|
UInt64 limit) const;
|
|
|
|
|
2020-02-14 07:12:04 +00:00
|
|
|
/// Actions for every element of order expression to analyze functions for monotonicity
|
2019-12-10 23:18:24 +00:00
|
|
|
ManyExpressionActions elements_actions;
|
|
|
|
NameSet forbidden_columns;
|
2021-05-21 17:01:21 +00:00
|
|
|
NameToNameMap array_join_result_to_source;
|
2019-12-11 01:34:39 +00:00
|
|
|
SortDescription required_sort_description;
|
2021-12-14 12:54:20 +00:00
|
|
|
const ASTSelectQuery & query;
|
2019-12-10 23:18:24 +00:00
|
|
|
};
|
2020-02-14 13:31:01 +00:00
|
|
|
}
|