2019-07-18 14:41:11 +00:00
|
|
|
#pragma once
|
2021-06-25 16:22:39 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeSelectProcessor.h>
|
2023-04-08 04:47:21 +00:00
|
|
|
#include <Common/logger_useful.h>
|
2019-07-18 14:41:11 +00:00
|
|
|
|
2021-07-17 18:06:46 +00:00
|
|
|
|
2019-07-18 14:41:11 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Used to read data from single part with select query
|
2021-06-25 16:22:39 +00:00
|
|
|
/// in reverse order of primary key.
|
2019-07-18 14:41:11 +00:00
|
|
|
/// Cares about PREWHERE, virtual columns, indexes etc.
|
|
|
|
/// To read data from multiple parts, Storage (MergeTree) creates multiple such objects.
|
2022-11-18 20:09:20 +00:00
|
|
|
class MergeTreeReverseSelectAlgorithm final : public MergeTreeSelectAlgorithm
|
2019-07-18 14:41:11 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-07-16 14:11:34 +00:00
|
|
|
template <typename... Args>
|
2022-11-18 20:09:20 +00:00
|
|
|
explicit MergeTreeReverseSelectAlgorithm(Args &&... args)
|
|
|
|
: MergeTreeSelectAlgorithm{std::forward<Args>(args)...}
|
2021-07-16 14:11:34 +00:00
|
|
|
{
|
2022-02-04 14:53:20 +00:00
|
|
|
LOG_TRACE(log, "Reading {} ranges in reverse order from part {}, approx. {} rows starting from {}",
|
2021-07-16 14:11:34 +00:00
|
|
|
all_mark_ranges.size(), data_part->name, total_rows,
|
|
|
|
data_part->index_granularity.getMarkStartingRow(all_mark_ranges.front().begin));
|
|
|
|
}
|
2019-07-18 14:41:11 +00:00
|
|
|
|
|
|
|
String getName() const override { return "MergeTreeReverse"; }
|
|
|
|
|
2021-06-25 16:22:39 +00:00
|
|
|
private:
|
2021-12-09 10:39:28 +00:00
|
|
|
bool getNewTaskImpl() override;
|
|
|
|
void finalizeNewTask() override {}
|
|
|
|
|
2023-02-03 13:34:18 +00:00
|
|
|
bool getNewTaskParallelReplicas();
|
|
|
|
bool getNewTaskOrdinaryReading();
|
|
|
|
|
2022-11-18 20:09:20 +00:00
|
|
|
BlockAndProgress readFromPart() override;
|
2019-07-18 14:41:11 +00:00
|
|
|
|
2022-11-18 20:09:20 +00:00
|
|
|
std::vector<BlockAndProgress> chunks;
|
2023-02-03 13:34:18 +00:00
|
|
|
|
|
|
|
/// Used for parallel replicas
|
|
|
|
bool no_more_tasks{false};
|
|
|
|
|
2020-05-30 21:57:37 +00:00
|
|
|
Poco::Logger * log = &Poco::Logger::get("MergeTreeReverseSelectProcessor");
|
2019-07-18 14:41:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|