mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
add tests for second indexes
This commit is contained in:
parent
128785e187
commit
f4808df41e
@ -211,18 +211,18 @@ QueryPlanPtr MergeTreeDataSelectExecutor::readFromParts(
|
||||
Names primary_key_columns = primary_key.column_names;
|
||||
|
||||
// query_info_for_index is a cloned SelectQueryInfo just for index
|
||||
SelectQueryInfo query_info_for_index;
|
||||
query_info_for_index.query = query_info.query->clone();
|
||||
query_info_for_index.syntax_analyzer_result = query_info.syntax_analyzer_result;
|
||||
query_info_for_index.sets = query_info.sets;
|
||||
|
||||
auto & temp_select = query_info_for_index.query->as<ASTSelectQuery &>();
|
||||
ColumnAliasesVisitor::Data aliase_column_data(metadata_snapshot->getColumns());
|
||||
ColumnAliasesVisitor aliase_column_visitor(aliase_column_data);
|
||||
if (temp_select.where())
|
||||
aliase_column_visitor.visit(temp_select.refWhere());
|
||||
if (temp_select.prewhere())
|
||||
aliase_column_visitor.visit(temp_select.refPrewhere());
|
||||
SelectQueryInfo query_info_for_index = query_info;
|
||||
if (!metadata_snapshot->getColumns().getAliases().empty())
|
||||
{
|
||||
query_info_for_index.query = query_info.query->clone();
|
||||
auto & temp_select = query_info_for_index.query->as<ASTSelectQuery &>();
|
||||
ColumnAliasesVisitor::Data aliase_column_data(metadata_snapshot->getColumns());
|
||||
ColumnAliasesVisitor aliase_column_visitor(aliase_column_data);
|
||||
if (temp_select.where())
|
||||
aliase_column_visitor.visit(temp_select.refWhere());
|
||||
if (temp_select.prewhere())
|
||||
aliase_column_visitor.visit(temp_select.refPrewhere());
|
||||
}
|
||||
|
||||
KeyCondition key_condition(query_info_for_index, context, primary_key_columns, primary_key.expression);
|
||||
|
||||
@ -573,7 +573,7 @@ QueryPlanPtr MergeTreeDataSelectExecutor::readFromParts(
|
||||
for (const auto & index : metadata_snapshot->getSecondaryIndices())
|
||||
{
|
||||
auto index_helper = MergeTreeIndexFactory::instance().get(index);
|
||||
auto condition = index_helper->createIndexCondition(query_info, context);
|
||||
auto condition = index_helper->createIndexCondition(query_info_for_index, context);
|
||||
if (!condition->alwaysUnknownOrTrue())
|
||||
useful_indices.emplace_back(index_helper, condition);
|
||||
}
|
||||
|
@ -15,3 +15,6 @@ alias2alias
|
||||
1
|
||||
1
|
||||
1
|
||||
second_index
|
||||
1
|
||||
1
|
||||
|
@ -68,3 +68,22 @@ SELECT day1 = '2020-01-04' FROM table_with_alias_column PREWHERE day1 = '2020-01
|
||||
|
||||
DROP TABLE table_with_alias_column;
|
||||
|
||||
|
||||
SELECT 'second_index';
|
||||
|
||||
DROP TABLE IF EXISTS test_index;
|
||||
CREATE TABLE test_index
|
||||
(
|
||||
`key_string` String,
|
||||
`key_uint32` ALIAS toUInt32(key_string),
|
||||
INDEX idx toUInt32(key_string) TYPE set(0) GRANULARITY 1
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
PARTITION BY tuple()
|
||||
PRIMARY KEY tuple()
|
||||
ORDER BY key_string SETTINGS index_granularity = 1;
|
||||
|
||||
INSERT INTO test_index SELECT * FROM numbers(10);
|
||||
SELECT COUNT() == 1 FROM test_index WHERE key_uint32 = 1 SETTINGS max_rows_to_read = 1;
|
||||
SELECT COUNT() == 1 FROM test_index WHERE toUInt32(key_string) = 1 SETTINGS max_rows_to_read = 1;
|
||||
DROP TABLE IF EXISTS test_index;
|
||||
|
Loading…
Reference in New Issue
Block a user