create table statement:
create table stock_master.turnover_rate_trade
(
id int auto_increment
constraint `PRIMARY`
primary key,
before_day int null,
pre_day int null,
turnover_rate double null ,
max_rise double null ,
keep_day int null ,
code varchar(50) null ,
date date null ,
real_keep int null ,
rate double null ,
create_time timestamp default CURRENT_TIMESTAMP null,
update_time timestamp default CURRENT_TIMESTAMP null,
constraint uindex
unique (before_day, pre_day, turnover_rate, max_rise, keep_day, code, date)
);
my select statement:
select id,
before_day,
pre_day,
turnover_rate,
max_rise,
keep_day,
code,
date
real_keep,
rate,
create_time,
update_time
from turnover_rate_trade
where
before_day=6 and pre_day =3 and turnover_rate=22.1 and max_rise =7.1 and keep_day=5 and
code='100000' and date='2022-02-02'
I am not a professional dba, avoid indexes invalidation as much as possible.
It is clearly written in the conditions, but doesn't work.
The table data information:
rows: 2 hundred million
before_day: 5~29
pre_day: 0~4
keep_day: 0~29
turnover_rate: 1~23
max_rise: 1~29
evenly distributed
as suggested:
It took me over an hour to delete and rebuild index.
create index turnover
on turnover_rate_trade (before_day, pre_day, turnover_rate, max_rise, keep_day, code, date)


EXPLAINoutput says it's not using the index.