mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 08:40:50 +00:00
Merge pull request #60675 from ClickHouse/use-minmax-indices-always-first
Always apply first minmax index among available skip indices
This commit is contained in:
commit
a3c22f9ace
@ -43,6 +43,7 @@
|
||||
#include <Processors/QueryPlan/IQueryPlanStep.h>
|
||||
#include <Parsers/parseIdentifierOrStringLiteral.h>
|
||||
#include <Parsers/ExpressionListParsers.h>
|
||||
#include <Storages/MergeTree/MergeTreeIndexMinMax.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
@ -1421,6 +1422,20 @@ static void buildIndexes(
|
||||
}
|
||||
}
|
||||
|
||||
// move minmax indices to first positions, so they will be applied first as cheapest ones
|
||||
std::stable_sort(begin(skip_indexes.useful_indices), end(skip_indexes.useful_indices), [](const auto & l, const auto & r)
|
||||
{
|
||||
const bool l_min_max = (typeid_cast<const MergeTreeIndexMinMax *>(l.index.get()));
|
||||
const bool r_min_max = (typeid_cast<const MergeTreeIndexMinMax *>(r.index.get()));
|
||||
if (l_min_max == r_min_max)
|
||||
return false;
|
||||
|
||||
if (l_min_max)
|
||||
return true; // left is min max but right is not
|
||||
|
||||
return false; // right is min max but left is not
|
||||
});
|
||||
|
||||
indexes->skip_indexes = std::move(skip_indexes);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include <base/types.h>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <Core/Field.h>
|
||||
#include <Interpreters/ExpressionActions.h>
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include <Storages/MergeTree/MergeTreeIndices.h>
|
||||
#include <Storages/MergeTree/MergeTreeData.h>
|
||||
#include <memory>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
@ -4,8 +4,6 @@
|
||||
#include <Storages/MergeTree/MergeTreeData.h>
|
||||
#include <Storages/MergeTree/KeyCondition.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
@ -5,9 +5,6 @@
|
||||
|
||||
#include <Interpreters/SetVariants.h>
|
||||
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
@ -1,12 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <mutex>
|
||||
#include <Core/Block.h>
|
||||
#include <Storages/StorageInMemoryMetadata.h>
|
||||
#include <Storages/MergeTree/GinIndexStore.h>
|
||||
|
@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include <tuple>
|
||||
#include <Storages/MarkCache.h>
|
||||
#include <Storages/MergeTree/MarkRange.h>
|
||||
#include <Storages/MergeTree/MergeTreeData.h>
|
||||
|
@ -0,0 +1,2 @@
|
||||
Name: v_mm
|
||||
Name: v_set
|
18
tests/queries/0_stateless/03000_minmax_index_first.sql
Normal file
18
tests/queries/0_stateless/03000_minmax_index_first.sql
Normal file
@ -0,0 +1,18 @@
|
||||
DROP TABLE IF EXISTS skip_table;
|
||||
|
||||
CREATE TABLE skip_table
|
||||
(
|
||||
k UInt64,
|
||||
v UInt64,
|
||||
INDEX v_set v TYPE set(100) GRANULARITY 2, -- set index is declared before minmax intentionally
|
||||
INDEX v_mm v TYPE minmax GRANULARITY 2
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
PRIMARY KEY k
|
||||
SETTINGS index_granularity = 8192;
|
||||
|
||||
INSERT INTO skip_table SELECT number, intDiv(number, 4096) FROM numbers(100000);
|
||||
|
||||
SELECT trim(explain) FROM ( EXPLAIN indexes = 1 SELECT * FROM skip_table WHERE v = 125) WHERE explain like '%Name%';
|
||||
|
||||
DROP TABLE skip_table;
|
Loading…
Reference in New Issue
Block a user