I have a table named t_task
and it may looks like this:
CREATE TABLE `t_task` (
`id` INT(10) NOT NULL AUTO_INCREMENT,
`status` TINYINT(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`) USING BTREE
)
COLLATE='utf8mb4_unicode_ci'
ENGINE=InnoDB
AUTO_INCREMENT=1
;
The column status
indicates the running status of a task which has four different values 0,1,2,3.
Due to some reasons, I need to process the following statements frequently:
select * from t_task where status = 0;
update t_task set status = 1 where id = the actual value of id
select * from t_task where status = 1;
update t_task set status = 2 where id = the actual value of id
select * from t_task where status = 2;
update t_task set status = 3 where id = the actual value of id
Inorder to speed up select
statement, and considering that most records in this table will eventually have its status
to be 3
, I choose to index status
column.
My Question are:
- Column
status
is oftenupdated
. It is true that index on it will cause a frequently change of structure of B+ tree? - If answer to question 1 is true. How can i prevent the frequently change of structure of B+ tree and meanwhile speed up querys for records that have status 0,1,2 ?
- Does partition helps in this situation? Since there are only few records in status 0,1,2.
discussion and anwsers