user481913
user481913

Reputation: 1018

Why is Myisam faster for reads (mostly read apps) and simple queries?

I have been reading some material on Mysql , the Myysql performance blog and some books.

It is said that if you have a mostly read based application you should use Myisam as it is better than Innodb. Also Non join queries are faster for Myisam.

Why so when it supports table locks(only for writes i suppose) where as Innodb has row level locks, so it should offer better performance for both reads and writes..

I simply want to know this , why all the reading material says Myisam is faster for reads if your application is more than 95%> read, without offering any explaination for the same.

I hope someone knowledgeable would answer without down voting and closing the question

Upvotes: 1

Views: 694

Answers (1)

Peter Rowell
Peter Rowell

Reputation: 17713

Table-level locks are faster to check for, but when they exist they block all other access to the table. If you are primarily reading, then you want the fastest "I'm not locked" check you can get.

Row-level locking permits other operations to happen simultaneously on the table, but they are more expensive in space/time to implement & check for.

So if you are doing 95%+ reads on a table (typical for most web apps), then MyISAM wins. Some tables (such as session tables, or user tracking tables) have as many write as reads, and locking the whole table for every update could slow an active site to a crawl.

Try testing this by creating a "database" using index cards for the various tables and simulate what happens when one visitor at a time goes through the site. Then try it with 5, 10, or 50 visitors hitting the code simultaneously. It will quickly become apparent that the table-level lock on the session table is the show stopper.

Upvotes: 8

Related Questions