2019-02-05 14:50:25 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeIndexReader.h>
|
|
|
|
|
2021-08-05 18:09:17 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
using namespace DB;
|
|
|
|
|
|
|
|
std::unique_ptr<MergeTreeReaderStream> makeIndexReader(
|
|
|
|
const std::string & extension,
|
|
|
|
MergeTreeIndexPtr index,
|
|
|
|
MergeTreeData::DataPartPtr part,
|
|
|
|
size_t marks_count,
|
|
|
|
const MarkRanges & all_mark_ranges,
|
2021-08-21 17:27:22 +00:00
|
|
|
MarkCache * mark_cache,
|
|
|
|
UncompressedCache * uncompressed_cache,
|
2021-08-05 18:09:17 +00:00
|
|
|
MergeTreeReaderSettings settings)
|
|
|
|
{
|
|
|
|
return std::make_unique<MergeTreeReaderStream>(
|
2022-04-22 16:58:09 +00:00
|
|
|
part->data_part_storage,
|
|
|
|
index->getFileName(), extension, marks_count,
|
2021-08-05 18:09:17 +00:00
|
|
|
all_mark_ranges,
|
2021-08-21 17:27:22 +00:00
|
|
|
std::move(settings), mark_cache, uncompressed_cache,
|
2021-08-05 18:09:17 +00:00
|
|
|
part->getFileSizeOrZero(index->getFileName() + extension),
|
|
|
|
&part->index_granularity_info,
|
2022-05-02 18:06:47 +00:00
|
|
|
ReadBufferFromFileBase::ProfileCallback{}, CLOCK_MONOTONIC_COARSE, false);
|
2021-08-05 18:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-02-05 14:50:25 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
MergeTreeIndexReader::MergeTreeIndexReader(
|
2021-08-21 17:27:22 +00:00
|
|
|
MergeTreeIndexPtr index_,
|
|
|
|
MergeTreeData::DataPartPtr part_,
|
|
|
|
size_t marks_count_,
|
|
|
|
const MarkRanges & all_mark_ranges_,
|
|
|
|
MarkCache * mark_cache,
|
|
|
|
UncompressedCache * uncompressed_cache,
|
2020-06-25 19:31:54 +00:00
|
|
|
MergeTreeReaderSettings settings)
|
2021-08-05 18:09:17 +00:00
|
|
|
: index(index_)
|
2019-02-05 14:50:25 +00:00
|
|
|
{
|
2022-04-22 16:58:09 +00:00
|
|
|
auto index_format = index->getDeserializedFormat(part_->data_part_storage, index->getFileName());
|
2021-08-05 18:09:17 +00:00
|
|
|
|
2021-08-21 17:27:22 +00:00
|
|
|
stream = makeIndexReader(
|
|
|
|
index_format.extension,
|
|
|
|
index_,
|
|
|
|
part_,
|
|
|
|
marks_count_,
|
|
|
|
all_mark_ranges_,
|
|
|
|
mark_cache,
|
|
|
|
uncompressed_cache,
|
|
|
|
std::move(settings));
|
2021-08-05 18:09:17 +00:00
|
|
|
version = index_format.version;
|
|
|
|
|
2022-02-16 13:35:23 +00:00
|
|
|
stream->adjustRightMark(getLastMark(all_mark_ranges_));
|
2021-08-05 18:09:17 +00:00
|
|
|
stream->seekToStart();
|
2019-02-05 14:50:25 +00:00
|
|
|
}
|
|
|
|
|
2021-08-05 18:09:17 +00:00
|
|
|
MergeTreeIndexReader::~MergeTreeIndexReader() = default;
|
|
|
|
|
2019-02-05 14:50:25 +00:00
|
|
|
void MergeTreeIndexReader::seek(size_t mark)
|
|
|
|
{
|
2021-08-05 18:09:17 +00:00
|
|
|
stream->seekToMark(mark);
|
2019-02-05 14:50:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MergeTreeIndexGranulePtr MergeTreeIndexReader::read()
|
|
|
|
{
|
|
|
|
auto granule = index->createIndexGranule();
|
2022-04-29 17:39:06 +00:00
|
|
|
granule->deserializeBinary(*stream->getDataBuffer(), version);
|
2019-02-05 14:50:25 +00:00
|
|
|
return granule;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|