Reply
Improving MySQL Performance
Old 02-11-2008, 11:38 AM Improving MySQL Performance
dartiss's Avatar
Novice Talker

Latest Blog Post:
Winding up at work
Posts: 9
Name: David Artiss
Location: Nottingham, UK
Hi,

Are there any coding techniques that are recommended for improving the reading time of small MySQL tables?

My site reads a few for page generation and, although the site is hardly slow, it's one area that could be improved.

Either SQL coding or the way my tables are defined.

If they are small, will having indexes be slowing them down? If so, should I have a unique field in preference to an index, for instance?

All help appreciated.
David.
dartiss is offline
Reply With Quote
View Public Profile Visit dartiss's homepage!
 
When You Register, These Ads Go Away!
     
Old 02-11-2008, 01:54 PM Re: Improving MySQL Performance
Learning Newbie's Avatar
Moderator

Posts: 4,811
Name: John Alexander
Indexes make it faster to find the data and slower to add or change it.

One of the biggest things is select *. If you don't need all the columns, only ask for the ones you need. If you don't need all the rows, ask for the ones you need, but ask in a way that exploits the indexes already there.

Normalize your tables. Instead of one giant Excel sheet, you want to break your data up into atomic units and make each table as narrow as possible, then join them when necessary.
__________________
4 ways to improve the lives of the "bottom billion"

"HEY YOU KIDS GET OFF MY LAWN!" -John McCain
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 02-11-2008, 02:13 PM Re: Improving MySQL Performance
dartiss's Avatar
Novice Talker

Latest Blog Post:
Winding up at work
Posts: 9
Name: David Artiss
Location: Nottingham, UK
Thanks. Some good advice.

Is it advisable then to even have indexes on small tables?

David.
dartiss is offline
Reply With Quote
View Public Profile Visit dartiss's homepage!
 
Old 02-11-2008, 05:01 PM Re: Improving MySQL Performance
Learning Newbie's Avatar
Moderator

Posts: 4,811
Name: John Alexander
On small or big tables, I would use indexes on fields used in WHERE, JOIN, and even ORDER BY clauses if reads significantly outnumber writes. If you aren't sure, you can measure both with a trace.

You don't maintain indexes - the server does. When you INSERT a new row in the table, MySQL makes a new node in the index. When you UPDATE, MySQL changes the table and the index before it returns control to your script. This is why changes are slowed down by indexes. This (and disk space) is why every column in every table doesn't get an index - just the ones that are most important.

MySQL will only use one index per table per query I think. Trying to use more than that is a very complicated operation called index intersection that only big league databases like Oracle are capable of. So that's another reason to go lightly, although one table gets used in many queries.

If a column has a unique index or constraint, and the database finds that value, it will stop reading the table data because it knows it won't find another copy. This can be expected to half execution time, but obviously only works when your data really is unique, and searchable as such.

Does MySQL support covering indexes? I'm pretty sure it allows compound indexes (ones with more than 1 column) but I don't know if, should a query only use columns that are all part of the same index, the query will be satisfied without actually touching the table physically? If that's the case, you could try and benchmark covering your small tables with a single index.

I realize this doesn't answer your question directly, but without careful and in depth study of your database and everything that uses it, a yes or no answer is impossible.
__________________
4 ways to improve the lives of the "bottom billion"

"HEY YOU KIDS GET OFF MY LAWN!" -John McCain
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 02-12-2008, 06:42 PM Re: Improving MySQL Performance
Learning Newbie's Avatar
Moderator

Posts: 4,811
Name: John Alexander
http://www.databasejournal.com/featu...le.php/1436301

FYI, your database server may choose not to use indexes on very small (around 10 rows) tables, but if they ever grow in the future this will change.
__________________
4 ways to improve the lives of the "bottom billion"

"HEY YOU KIDS GET OFF MY LAWN!" -John McCain
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 02-19-2008, 03:45 AM Re: Improving MySQL Performance
dartiss's Avatar
Novice Talker

Latest Blog Post:
Winding up at work
Posts: 9
Name: David Artiss
Location: Nottingham, UK
Thanks to everyone who replied.

I found the cause of the performance issue in the end... it was a bit of a school-boy error. Never-the-less I've improved it even further with some new indexing and some other tweaks here-and-there.

David.
dartiss is offline
Reply With Quote
View Public Profile Visit dartiss's homepage!
 
Old 02-19-2008, 10:08 PM Re: Improving MySQL Performance
Average Talker

Posts: 16
This tip depends on your version... but I think it is relevant: Are you using InnoDB ?
web-law is offline
Reply With Quote
View Public Profile
 
Old 02-20-2008, 01:50 AM Re: Improving MySQL Performance
Average Talker

Posts: 20
Name: Corrie
What was the school boy error?
__________________
http://awhost.0lx.net
The Ultimate Free Host Site
Php, 300 MB disk space, 8 GB Monthly transfer, 5 MySQL databases + MORE
awhost.0lx.net is offline
Reply With Quote
View Public Profile
 
Old 02-23-2008, 11:53 PM Re: Improving MySQL Performance
Average Talker

Posts: 19
Name: sunil
Indexing makes the data fetching very fast.
However you can do maintainance work on your database,this maintainance is available freely,search for google
sbksunil is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Improving MySQL Performance
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.18829 seconds with 13 queries