MySQL large databases, unique index effect on efficiency

MySQLPHP

I'm working on a table which holds around 300k records. I'm using a 3 columns unique index to prevent duplicate records. For some reason the database is taking long to insert new rows.

I have a few questions regarding UNIQUE indexes and efficiency:

  1. Will a UNIQUE index make a table much slower?

  2. Would it be useful to store old rows in another table and reduce the table to around 1k records?

  3. And most importantly is there any way to know how long my db takes to insert a row? In phpMyAdmin I can see the "time to process query" but only on SELECT queries

Best Answer

  1. Indexes do introduce some overhead for a database since the data must be inserted and then the index managed. Does it make the table much slower? That depends a lot on how many rows, how many indexes, how you organize the tablespaces, your filesystem, etc. In general, a couple of indexes on a table should not be noticeable on a properly operating database.

  2. Yes. Many database engines provide for Range Partitioning based on ideas like this, some qualification that separates older, not-changing-much data to be managed separately. This can be done by moving data to another table, or allowing the engine to manage the data with Range Partitioning. see this for MySQL

  3. You should use another client to measure this - something that can give you those statistics. MySQLWorkbench as been suggested. Other tools might include DBVisualizer, SQuirrel, etc.