I am kind of confused about when to use a secondary index. I have the following code script to define a MergeTree Table, and the table has a billion rows.
create table t_mt(
id UInt8,
name String,
job String,
birthday Date,
salary UINT8
) engine = MergeTable
primary key id
order by (id)
I would run the following aggregation query in real-time:
select job, count(1), avg(salary)
from t_mt
group by job
where salary > 20000
In the above query, I have used condition filter: salary > 20000 and group by job. I would ask whether it is a good practice to define the secondary index on the salary column.
The basic question I would ask here is whether I could think the Clickhouse secondary index as MySQL normal index. That is, if I want to filter by some column, then I can create the (secondary) index on this column for query speed up.