mysql索引 两个大于_MySQL索引大于存储的数据

我有一个具有以下统计信息的数据库

Tables Data Index Total

11 579,6 MB 0,9 GB 1,5 GB

所以你可以看到索引接近两倍.并且有一个表,约700万行,占至少99%.

我也有两个非常相似的索引

a) UNIQUE KEY `idx_customer_invoice` (`customer_id`,`invoice_no`),

b) KEY `idx_customer_invoice_order` (`customer_id`,`invoice_no`,`order_no`)

更新:这是最大表格的表定义(至少在结构上)

CREATE TABLE `invoices` (

`id` int(10) unsigned NOT NULL auto_increment,

`customer_id` int(10) unsigned NOT NULL,

`order_no` varchar(10) default NULL,

`invoice_no` varchar(20) default NULL,

`customer_no` varchar(20) default NULL,

`name` varchar(45) NOT NULL default '',

`archived` tinyint(4) default NULL,

`invoiced` tinyint(4) default NULL,

`time` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,

`group` int(11) default NULL,

`customer_group` int(11) default NULL,

PRIMARY KEY (`id`),

UNIQUE KEY `idx_customer_invoice` (`customer_id`,`invoice_no`),

KEY `idx_time` (`time`),

KEY `idx_order` (`order_no`),

KEY `idx_customer_invoice_order` (`customer_id`,`invoice_no`,`order_no`)

) ENGINE=InnoDB AUTO_INCREMENT=9146048 DEFAULT CHARSET=latin1 |

更新2:

mysql> show indexes from invoices;

+----------+------------+----------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+

| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |

+----------+------------+----------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+

| invoices | 0 | PRIMARY | 1 | id | A | 7578066 | NULL | NULL | | BTREE | |

| invoices | 0 | idx_customer_invoice | 1 | customer_id | A | 17 | NULL | NULL | | BTREE | |

| invoices | 0 | idx_customer_invoice | 2 | invoice_no | A | 7578066 | NULL | NULL | YES | BTREE | |

| invoices | 1 | idx_time | 1 | time | A | 541290 | NULL | NULL | | BTREE | |

| invoices | 1 | idx_order | 1 | order_no | A | 6091 | NULL | NULL | YES | BTREE | |

| invoices | 1 | idx_customer_invoice_order | 1 | customer_id | A | 17 | NULL | NULL | | BTREE | |

| invoices | 1 | idx_customer_invoice_order | 2 | invoice_no | A | 7578066 | NULL | NULL | YES | BTREE | |

| invoices | 1 | idx_customer_invoice_order | 3 | order_no | A | 7578066 | NULL | NULL | YES | BTREE | |

+----------+------------+----------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+

我的问题是:

>有没有办法在MySQL中找到未使用的索引?

>有什么常见的错误影响到索引的大小吗?

index可以安全地删除indexA吗?

>你如何衡量每个索引的大小?我得到的是所有索引的总和.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值