DrXCheng
DrXCheng

Reputation: 4132

Improving MySQL efficiency

  1. I have a table now containing over 43 million records. To execute SELECT, I usually select records with the same field, say A. Will it be more efficient to divide the table into several tables by different A and save in the database? How much can I gain?

  2. I have one table named entry: {entryid (PK), B}, containing 6 thousand records, and several other tables with the similar structure T1: {id(PK), entryid, C, ...}, containing over millions of records. Do the following two processes have the same efficiency?

    SELECT id FROM T1, entry WHERE T1.entryid = entry.entryid AND entry.B = XXX

and

SELECT entryid FROM entry WHERE B = XXX
//format a string S as (entryid1, entryid2, ... )
//then run
SELECT id FROM T1 WHERE entryid IN S

Upvotes: 0

Views: 202

Answers (2)

Aleksandar Vucetic
Aleksandar Vucetic

Reputation: 14953

  1. You will get performance improvement. You don't have to do that manually, but use built in MySQL partitioning. How much will you get really depends on your configuration and it would be the best for you to test it. For example, if you have monster server, 43M records is nothing and you will not get that much with partitioning (but you should get improvement anyway).
  2. As for this question, I would say that first query will be a lot faster.

But it would be the best to measure your results because it may depend on your hardware coonfiguration, indexes (use EXPLAIN to check if you have correct indexes), your MySQL settings like query cache size, and engine you are using (MYISAM, InnoDB)...

Upvotes: 1

Derek Organ
Derek Organ

Reputation: 8473

Use the EXPLAIN Command to check your queries. dev.mysql.com/doc/refman/5.0/en/explain.html

Here is an explaination http://www.slideshare.net/phpcodemonkey/mysql-explain-explained

You need to make sure first and foremost you have the right indexes for a table that size especially for queries that join with other tables.

Upvotes: 0

Related Questions