indexes
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
--task 1
|
||||
create table mdrozdov.logs3
|
||||
on CLUSTER clickhouse_cluster (
|
||||
log_id Int,
|
||||
ts DateTime
|
||||
)
|
||||
engine = ReplicatedMergeTree(
|
||||
'/clickhouse/tables/{shard}/mdrozdov/logs3',
|
||||
'{replica}'
|
||||
)
|
||||
order by ts
|
||||
|
||||
alter table mdrozdov.logs3
|
||||
add index idx_ts ts type minmax GRANULARITY 2;
|
||||
|
||||
select *
|
||||
from mdrozdov.logs3
|
||||
where ts between '2024-06-02' and '2024-06-03'
|
||||
|
||||
SELECT
|
||||
query,
|
||||
read_rows,
|
||||
result_rows,
|
||||
read_bytes
|
||||
FROM system.query_log
|
||||
WHERE query LIKE '%logs%'
|
||||
ORDER BY event_time DESC
|
||||
LIMIT 1;
|
||||
|
||||
-- task 2
|
||||
create table mdrozdov.clicks
|
||||
on CLUSTER clickhouse_cluster (
|
||||
id UInt64,
|
||||
country String
|
||||
)
|
||||
engine = ReplicatedMergeTree(
|
||||
'/clickhouse/tables/{shard}/mdrozdov/clicks',
|
||||
'{replica}'
|
||||
)
|
||||
order by id
|
||||
|
||||
alter table mdrozdov.clicks
|
||||
add index idx_country type set(100) GRANULARITY 2
|
||||
|
||||
Explain
|
||||
select *
|
||||
from mdrozdov.clicks
|
||||
where country = 'RU'
|
||||
|
||||
-- task 3
|
||||
create table mdrozdov.users
|
||||
on CLUSTER clickhouse_cluster (
|
||||
id UInt64,
|
||||
email String
|
||||
)
|
||||
engine = ReplicatedMergeTree(
|
||||
'/clickhouse/tables/{shard}/mdrozdov/users',
|
||||
'{replica}'
|
||||
)
|
||||
order by id
|
||||
|
||||
ALTER TABLE users
|
||||
ADD INDEX idx_email email TYPE bloom_filter(0.01) GRANULARITY 2;
|
||||
|
||||
SELECT * FROM users WHERE email = 'alice@mail.com';
|
||||
Reference in New Issue
Block a user