我有桌子
| base_schedule_line_items | CREATE TABLE
base_schedule_line_items
(
id
int(10)unsigned NOT NULL AUTO_INCREMENT,
installment
int(10)unsigned NOT NULL,
on_date
日期NOT NULL,
actual_date
日期默认值,
payment_type
int(11)NOT NULL,
scheduled_principal_outstanding
十进制(65,0)NOT NULL,
scheduled_principal_due
十进制(65,0) NOT NULL,
scheduled_interest_outstanding
十进制(65,0)NOT NULL,
scheduled_interest_due
十进制(65,0)NOT NULL,
currency
int(11)NOT NULL,
updated_at
日期时间NOT NULL缺省'2013-01-06 14:29:16',
created_at
datetime NOT NULL默认值' 2013-01-06 14:29:16',
loan_base_schedule_id
int(10)unsigned NOT NULL,
lending_id
int(10)unsigned NOT NULL,
reschedule
tinyint(1)DEFAULT'0',
PRIMARY KEY(id
),
KEYindex_base_schedule_line_items_loan_base_schedule
(loan_base_schedule_id
),KEYindex_bslt_spd
(scheduled_principal_due
),
键index_bslt_lending
(lending_id
),
KEYindex_bslt_actualdate
(actual_date
),
KEYindex_bslt_spsila
(loan_base_schedule_id
,scheduled_principal_due
,scheduled_interest_due
,actual_date
),
KEYindex_bslt_ondate
(on_date
),
KEYindex_bslt_oa
(on_date
,actual_date
),
KEYindex_bslt_ol
(on_date
,loan_base_schedule_id
),
KEYindex_bslt_oli
(on_date
,lending_id
)
)ENGINE = InnoDB的AUTO_INCREMENT = 30410126默认字符集= UTF8 |
现在该表中有3000万条记录,我需要为此添加两个索引,并且添加它需要花费数年的时间。
更改表base_schedule_line_items并添加索引index_bslt_sla(scheduled_principal_due,actual_date,lending_id);
更改表base_schedule_line_items添加索引index_bslt_ssla(scheduled_principal_due,scheduled_interest_due,lending_id,actual_date);
我使用下面提到的查询来找出表的大小
SELECT table_name AS“ Tables”,圆形((((data_length + index_length)/ 1024/1024),2)“以MB为单位的大小” FROM information_schema.TABLES WHERE table_schema =“ my_database_name”;
结果出来是
base_schedule_line_items | 20111.00
我只是用来计算数据长度,而忽略了索引长度
SELECT table_name AS“ Tables”,round((((data_length)/ 1024/1024),2)“在MB中的大小” FROM information_schema.TABLES WHERE table_schema =“ my_database_name”;
结果是
base_schedule_line_items | 9497.00
指标
KEY index_bslt_actualdate(actual_date),
KEY index_bslt_spsila(loan_base_schedule_id,scheduled_principal_due,scheduled_interest_due,actual_date),
KEY index_bslt_ondate(on_date),
KEY index_bslt_oa(on_date,actual_date),
KEY index_bslt_ol(on_date,loan_base_schedule_id),
KEY index_bslt_oli(on_date,lending_id)
是由我添加的,但我不确定或添加其他索引的目的是什么。这是相当大的应用程序。现在,我需要添加上面提到的这两个索引,因为它们可以帮助我使用select语句提取报告,并且发现添加它们非常困难。任何帮助将不胜感激