2019-03-30 13:49:29 +00:00
|
|
|
#pragma once
|
|
|
|
#include <vector>
|
|
|
|
#include <Storages/MergeTree/MarkRange.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2019-12-19 13:10:57 +00:00
|
|
|
/// Class contains information about index granularity in rows of IMergeTreeDataPart
|
2019-04-01 10:34:22 +00:00
|
|
|
/// Inside it contains vector of partial sums of rows after mark:
|
|
|
|
/// |-----|---|----|----|
|
|
|
|
/// | 5 | 8 | 12 | 16 |
|
|
|
|
/// If user doesn't specify setting adaptive_index_granularity_bytes for MergeTree* table
|
|
|
|
/// all values in inner vector would have constant stride (default 8192).
|
2019-03-30 13:49:29 +00:00
|
|
|
class MergeTreeIndexGranularity
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::vector<size_t> marks_rows_partial_sums;
|
|
|
|
bool initialized = false;
|
|
|
|
|
|
|
|
public:
|
|
|
|
MergeTreeIndexGranularity() = default;
|
|
|
|
explicit MergeTreeIndexGranularity(const std::vector<size_t> & marks_rows_partial_sums_);
|
|
|
|
|
2019-04-01 10:34:22 +00:00
|
|
|
/// Return count of rows between marks
|
2019-03-30 13:49:29 +00:00
|
|
|
size_t getRowsCountInRange(const MarkRange & range) const;
|
2019-04-01 10:34:22 +00:00
|
|
|
/// Return count of rows between marks
|
2019-03-30 13:49:29 +00:00
|
|
|
size_t getRowsCountInRange(size_t begin, size_t end) const;
|
2019-04-01 10:34:22 +00:00
|
|
|
/// Return sum of rows between all ranges
|
2019-03-30 13:49:29 +00:00
|
|
|
size_t getRowsCountInRanges(const MarkRanges & ranges) const;
|
|
|
|
|
2019-04-01 10:34:22 +00:00
|
|
|
/// Return amount of marks that contains amount of `number_of_rows` starting from
|
|
|
|
/// `from_mark` and possible some offset_in_rows from `from_mark`
|
|
|
|
/// 1 2 <- answer
|
|
|
|
/// |-----|---------------------------|----|----|
|
|
|
|
/// ^------------------------^-----------^
|
|
|
|
//// from_mark offset_in_rows number_of_rows
|
2022-12-05 20:10:31 +00:00
|
|
|
size_t countMarksForRows(size_t from_mark, size_t number_of_rows, size_t offset_in_rows, size_t min_marks_to_read) const;
|
2019-03-30 13:49:29 +00:00
|
|
|
|
2019-04-01 10:34:22 +00:00
|
|
|
/// Total marks
|
2019-03-30 13:49:29 +00:00
|
|
|
size_t getMarksCount() const;
|
2019-04-01 10:34:22 +00:00
|
|
|
/// Total rows
|
2019-03-30 13:49:29 +00:00
|
|
|
size_t getTotalRows() const;
|
|
|
|
|
2019-12-05 12:01:36 +00:00
|
|
|
/// Total number marks without final mark if it exists
|
|
|
|
size_t getMarksCountWithoutFinal() const { return getMarksCount() - hasFinalMark(); }
|
|
|
|
|
2019-04-01 10:34:22 +00:00
|
|
|
/// Rows after mark to next mark
|
2020-12-14 11:06:02 +00:00
|
|
|
size_t getMarkRows(size_t mark_index) const;
|
2019-03-30 13:49:29 +00:00
|
|
|
|
2019-04-01 10:34:22 +00:00
|
|
|
/// Return amount of rows before mark
|
2019-03-30 13:49:29 +00:00
|
|
|
size_t getMarkStartingRow(size_t mark_index) const;
|
|
|
|
|
2019-04-01 10:34:22 +00:00
|
|
|
/// Amount of rows after last mark
|
2019-03-30 13:49:29 +00:00
|
|
|
size_t getLastMarkRows() const
|
|
|
|
{
|
|
|
|
size_t last = marks_rows_partial_sums.size() - 1;
|
|
|
|
return getMarkRows(last);
|
|
|
|
}
|
|
|
|
|
2019-06-19 12:30:56 +00:00
|
|
|
size_t getLastNonFinalMarkRows() const
|
|
|
|
{
|
|
|
|
size_t last_mark_rows = getLastMarkRows();
|
|
|
|
if (last_mark_rows != 0)
|
|
|
|
return last_mark_rows;
|
|
|
|
return getMarkRows(marks_rows_partial_sums.size() - 2);
|
|
|
|
}
|
|
|
|
|
2019-06-18 12:54:27 +00:00
|
|
|
bool hasFinalMark() const
|
|
|
|
{
|
|
|
|
return getLastMarkRows() == 0;
|
|
|
|
}
|
|
|
|
|
2019-03-30 13:49:29 +00:00
|
|
|
bool empty() const
|
|
|
|
{
|
|
|
|
return marks_rows_partial_sums.empty();
|
|
|
|
}
|
2019-04-01 10:34:22 +00:00
|
|
|
|
2019-03-30 13:49:29 +00:00
|
|
|
bool isInitialized() const
|
|
|
|
{
|
|
|
|
return initialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setInitialized()
|
|
|
|
{
|
|
|
|
initialized = true;
|
|
|
|
}
|
2019-04-01 10:34:22 +00:00
|
|
|
/// Add new mark with rows_count
|
2019-03-30 13:49:29 +00:00
|
|
|
void appendMark(size_t rows_count);
|
2019-04-01 10:34:22 +00:00
|
|
|
|
2020-02-03 12:08:40 +00:00
|
|
|
/// Extends last mark by rows_count.
|
2019-11-27 11:35:27 +00:00
|
|
|
void addRowsToLastMark(size_t rows_count);
|
|
|
|
|
2020-02-03 12:08:40 +00:00
|
|
|
/// Drops last mark if any exists.
|
2019-11-26 09:48:22 +00:00
|
|
|
void popMark();
|
|
|
|
|
2019-04-01 10:34:22 +00:00
|
|
|
/// Add `size` of marks with `fixed_granularity` rows
|
2019-03-30 13:49:29 +00:00
|
|
|
void resizeWithFixedGranularity(size_t size, size_t fixed_granularity);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|