aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Storages/ReadInOrderOptimizer.h
blob: 161c321ae790f5b933b23b56872d1033021196c1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#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
 *   and required sort description to get their
 *   common prefix, which is needed for
 *   performing reading in order of PK.
 */
class ReadInOrderOptimizer
{
public:
    ReadInOrderOptimizer(
        const ASTSelectQuery & query,
        const ManyExpressionActions & elements_actions,
        const SortDescription & required_sort_description,
        const TreeRewriterResultPtr & syntax_result);

    InputOrderInfoPtr getInputOrder(const StorageMetadataPtr & metadata_snapshot, ContextPtr context, UInt64 limit = 0) const;

private:
    InputOrderInfoPtr getInputOrderImpl(
        const StorageMetadataPtr & metadata_snapshot,
        const SortDescription & description,
        const ManyExpressionActions & actions,
        const ContextPtr & context,
        UInt64 limit) const;

    /// Actions for every element of order expression to analyze functions for monotonicity
    ManyExpressionActions elements_actions;
    NameSet forbidden_columns;
    NameToNameMap array_join_result_to_source;
    SortDescription required_sort_description;
    const ASTSelectQuery & query;
};
}