I have a table (in MySQL) called unused
with about 5.4 million rows. The table looks like this:
CREATE TABLE `unused` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`account_id` bigint(20) DEFAULT NULL,
`heading_label` varchar(255) NOT NULL,
`value` varchar(255) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`),
KEY `fk_account_id` (`account_id`),
CONSTRAINT `unused_ibfk_1` FOREIGN KEY (`account_id`) REFERENCES `account` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=80524905 DEFAULT CHARSET=latin1
I thought queries on this table might go faster if I were to add an index. I tried running this:
create index heading_label
on unused (heading_label) using btree
I let this command run for maybe an hour or two before restarting MySQL. Even though this table has over 5 million rows, it doesn't seem like it should take over an hour to run this sort of thing. But maybe that's normal. I don't really know what I'm doing. Can someone enlighten me?
The table is partitioned into 40 pieces on column text . Then creating index on the table takes about 1 hours to complete.
It takes 3600 seconds to create a index on table X, which has 3 million rows. So the metric is 3600 / 3,000,000 = 0.0012 seconds per row. So if table Y has 8 million rows, you could expect . 0012 * 8,000,000 = 9600 seconds (or 160 minutes) to create the index.
Go to Control Panel | Indexing Options to monitor the indexing. The DisableBackOff = 1 option makes the indexing go faster than the default value. You can continue to work on the computer but indexing will continue in the background and is less likely to pause when other programs are running.
It's normal depending on your server specs. The way MySQL creates indexes is by the table and then sorting and adding the indexes. This means that it needs to re-write all the data, and then sort all of the data (not cheap by any means). It depends on your server's I/O performance and how much ram you can give it.
Here are a few resources for more information...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With