mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-04 05:22:17 +00:00
fix
This commit is contained in:
parent
ad2a453919
commit
1b7c0aeef1
@ -208,7 +208,7 @@ public:
|
||||
ParserIndexDeclaration() {}
|
||||
|
||||
protected:
|
||||
const char * getName() const override { return "INDEX query"; }
|
||||
const char * getName() const override { return "INDEX"; }
|
||||
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
||||
};
|
||||
|
||||
|
@ -811,6 +811,8 @@ MergeTreeData::MutableDataPartPtr MergeTreeDataMergerMutator::mergePartsToTempor
|
||||
Poco::File(rows_sources_file_path).remove();
|
||||
}
|
||||
|
||||
// TODO: здесь надо как-то мержить индекс или в MergedBlockOutputStream
|
||||
|
||||
for (const auto & part : parts)
|
||||
new_data_part->minmax_idx.merge(part->minmax_idx);
|
||||
|
||||
@ -915,6 +917,8 @@ MergeTreeData::MutableDataPartPtr MergeTreeDataMergerMutator::mutatePartToTempor
|
||||
while (check_not_cancelled() && (block = in->read()))
|
||||
{
|
||||
minmax_idx.update(block, data.minmax_idx_columns);
|
||||
// TODO: насчитывать индексы
|
||||
/// Supposing data is sorted we can calculate indexes there
|
||||
out.write(block);
|
||||
}
|
||||
|
||||
@ -929,6 +933,18 @@ MergeTreeData::MutableDataPartPtr MergeTreeDataMergerMutator::mutatePartToTempor
|
||||
/// We will modify only some of the columns. Other columns and key values can be copied as-is.
|
||||
/// TODO: check that we modify only non-key columns in this case.
|
||||
|
||||
for (const auto& col : in_header.getNames()) {
|
||||
for (const auto& index_part : source_part->index_parts) {
|
||||
const auto index_cols = index_part->index->sample.getNames();
|
||||
auto it = find(cbegin(index_cols), cend(index_cols), col);
|
||||
if (it != cend(index_cols)) {
|
||||
throw Exception("You can not modify columns used in index. Index name: '"
|
||||
+ index_part->index->name
|
||||
+ "' bad column:" + *it, ErrorCodes::ILLEGAL_COLUMN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NameSet files_to_skip = {"checksums.txt", "columns.txt"};
|
||||
for (const auto & entry : in_header)
|
||||
{
|
||||
@ -999,6 +1015,7 @@ MergeTreeData::MutableDataPartPtr MergeTreeDataMergerMutator::mutatePartToTempor
|
||||
new_data_part->index = source_part->index;
|
||||
new_data_part->partition.assign(source_part->partition);
|
||||
new_data_part->minmax_idx = source_part->minmax_idx;
|
||||
new_data_part->index_parts = source_part->index_parts;
|
||||
new_data_part->modification_time = time(nullptr);
|
||||
new_data_part->bytes_on_disk = MergeTreeData::DataPart::calculateTotalSizeOnDisk(new_data_part->getFullPath());
|
||||
}
|
||||
|
@ -528,9 +528,10 @@ namespace DB
|
||||
else
|
||||
ranges.ranges = MarkRanges{MarkRange{0, part->marks_count}};
|
||||
|
||||
for (const auto index_part : part->index_parts) {
|
||||
const auto condition = index_part->createIndexConditionOnPart(
|
||||
query_info, context, index_part->index->sample.getNames(), index_part->index->expr);
|
||||
/// It can be done in multiple threads (one thread for each part).
|
||||
/// Maybe it should be moved to BlockInputStream, but it can cause some problems.
|
||||
for (auto index_part : part->index_parts) {
|
||||
auto condition = index_part->createIndexConditionOnPart(query_info, context);
|
||||
if (!condition->alwaysUnknownOrTrue()) {
|
||||
ranges.ranges = condition->filterRanges(ranges.ranges);
|
||||
}
|
||||
|
@ -11,28 +11,15 @@ namespace ErrorCodes
|
||||
}
|
||||
|
||||
|
||||
INDEX_TYPE IndexCondition::indexType() const {
|
||||
IndexType IndexCondition::indexType() const {
|
||||
return part->indexType();
|
||||
}
|
||||
|
||||
|
||||
INDEX_TYPE MergeTreeIndexPart::indexType() const {
|
||||
IndexType MergeTreeIndexPart::indexType() const {
|
||||
return index->indexType();
|
||||
}
|
||||
|
||||
void MergeTreeIndexPart::update(const Block & block, const Names & column_names) {
|
||||
/// a few checks?
|
||||
updateImpl(block, column_names);
|
||||
}
|
||||
|
||||
void MergeTreeIndexPart::merge(const MergeTreeIndexPart & other) {
|
||||
if (other.indexType() != indexType()) {
|
||||
throw Exception("MergeTreeIndexPart: Merging index part with another index type.",
|
||||
ErrorCodes::LOGICAL_ERROR);
|
||||
}
|
||||
mergeImpl(other);
|
||||
}
|
||||
|
||||
|
||||
void MergeTreeIndexFactory::registerIndex(const std::string &name, Creator creator) {
|
||||
if (!indexes.emplace(name, std::move(creator)).second)
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <memory>
|
||||
#include <Core/Block.h>
|
||||
#include <ext/singleton.h>
|
||||
#include <Storages/MergeTree/MergeTreeDataPartChecksum.h>
|
||||
#include <Storages/SelectQueryInfo.h>
|
||||
#include <Storages/MergeTree/MarkRange.h>
|
||||
#include <Interpreters/ExpressionActions.h>
|
||||
@ -14,7 +15,7 @@
|
||||
namespace DB
|
||||
{
|
||||
|
||||
enum class INDEX_TYPE {
|
||||
enum class IndexType {
|
||||
NONE = 0
|
||||
};
|
||||
|
||||
@ -22,8 +23,9 @@ enum class INDEX_TYPE {
|
||||
class MergeTreeIndex;
|
||||
struct MergeTreeIndexPart;
|
||||
|
||||
using MergeTreeIndexPtr = std::shared_ptr<MergeTreeIndex>;
|
||||
using MergeTreeIndexes = std::vector<MergeTreeIndexPtr>;
|
||||
using MergeTreeIndexPtr = std::shared_ptr<const MergeTreeIndex>;
|
||||
using MutableMergeTreeIndexPtr = std::shared_ptr<MergeTreeIndex>;
|
||||
using MergeTreeIndexes = std::vector<MutableMergeTreeIndexPtr>;
|
||||
|
||||
using MergeTreeIndexPartPtr = std::shared_ptr<MergeTreeIndexPart>;
|
||||
using MergeTreeIndexParts = std::vector<MergeTreeIndexPartPtr>;
|
||||
@ -37,7 +39,7 @@ class IndexCondition {
|
||||
public:
|
||||
virtual ~IndexCondition() = default;
|
||||
|
||||
virtual INDEX_TYPE indexType() const;
|
||||
virtual IndexType indexType() const;
|
||||
|
||||
/// Checks if this index is useful for query.
|
||||
virtual bool alwaysUnknownOrTrue() const = 0;
|
||||
@ -61,27 +63,17 @@ struct MergeTreeIndexPart
|
||||
friend MergeTreeIndex;
|
||||
|
||||
public:
|
||||
MergeTreeIndexPart() = default;
|
||||
virtual ~MergeTreeIndexPart() = default;
|
||||
|
||||
virtual INDEX_TYPE indexType() const;
|
||||
virtual IndexType indexType() const;
|
||||
|
||||
void update(const Block & block, const Names & column_names);
|
||||
void merge(const MergeTreeIndexPart & other);
|
||||
virtual MergeTreeIndexPartPtr cloneEmpty() const = 0;
|
||||
|
||||
virtual IndexConditionPtr createIndexConditionOnPart(
|
||||
const SelectQueryInfo & query_info
|
||||
, const Context & context
|
||||
, const Names & key_column_names
|
||||
, const ExpressionActionsPtr & key_expr) const = 0;
|
||||
const SelectQueryInfo & query_info, const Context & context) const = 0;
|
||||
|
||||
protected:
|
||||
MergeTreeIndexPart() = default;
|
||||
|
||||
virtual void updateImpl(const Block & block, const Names & column_names) = 0;
|
||||
virtual void mergeImpl(const MergeTreeIndexPart & other) = 0;
|
||||
|
||||
public:
|
||||
MergeTreeIndexPtr index;
|
||||
MergeTreeIndexPtr index; // if parts can migrate to another tables it can be bad
|
||||
};
|
||||
|
||||
|
||||
@ -94,9 +86,7 @@ public:
|
||||
|
||||
virtual ~MergeTreeIndex() {};
|
||||
|
||||
virtual INDEX_TYPE indexType() const = 0;
|
||||
|
||||
virtual MergeTreeIndexPartPtr createEmptyIndexPart() const = 0;
|
||||
virtual IndexType indexType() const = 0;
|
||||
|
||||
String name;
|
||||
ExpressionActionsPtr expr;
|
||||
|
Loading…
Reference in New Issue
Block a user