Home » Performance » MySQL » Sorted index pages - physically reorder on disk?
Sorted index pages - physically reorder on disk? [message #1584] Mon, 13 August 2007 15:53 Go to next message
sean
Messages: 6
Registered: January 2007
Junior Member
This may apply to other engines but I'm primarily focused on myisam. When using optimize table or myisamchk --sort-index, the manual states "Sort index blocks. This speeds up 'read-next' in applications." During this process, does mysql physically sort the index pages on disk to improve sequential io?

Ex: a range lookup on a single column index... it would be great if this was sequential and only required one seek.

Thanks in advance.
Re: Sorted index pages - physically reorder on disk? [message #1586 is a reply to message #1584 ] Thu, 16 August 2007 05:25 Go to previous messageGo to next message
Peter  is currently offline Peter
Messages: 405
Registered: August 2006
Senior Member
Super Guru
During index range scans there are in fact two accesses one is index access and other is row data access.

Sorting index will help with having disk accesses more sequential but data may well require a lot of seeks.

This is one of the reasons covering indexes (when all referenced and retrieved columns are in the index) are so helpful.

In MyISAM you can also sort data in the same order as and index by using myisamchk --sort-records

But it of course only can be used for one index/access order.


Peter Zaitsev, MySQL Performance Expert
MySQL Performance Blog - http://www.mysqlperformanceblog.com
MySQL Consulting http://www.mysqlperformanceblog.com/mysql-consulting/
Re: Sorted index pages - physically reorder on disk? [message #1652 is a reply to message #1586 ] Mon, 20 August 2007 12:01 Go to previous messageGo to next message
sean
Messages: 6
Registered: January 2007
Junior Member
Thanks Peter... currently the bottleneck is IO so anything that can limit the # of seeks and/or perform sequential IO is a benefit.
Next, I'd like to look at the index block sizes and see if changing the value other than 1024 will be a benefit.
Re: Sorted index pages - physically reorder on disk? [message #1653 is a reply to message #1584 ] Mon, 20 August 2007 18:38 Go to previous messageGo to next message
sterin  is currently offline sterin
Messages: 324
Registered: March 2007
Location: Sweden
Senior Member
Some questions:
How large is your DB actually?

How much RAM do you have available on that machine?

What is your key_buffer_size set to?

Are you sure that sorts or group by queries aren't creating temporary tables on disk?
Reason for asking is that it is pretty common to miss that the default sort_buffer_size setting can be pretty small and then mysql creates an on disk temporary table used for sorting that slows down things a lot.
Re: Sorted index pages - physically reorder on disk? [message #1654 is a reply to message #1653 ] Mon, 20 August 2007 18:44 Go to previous messageGo to next message
sean
Messages: 6
Registered: January 2007
Junior Member
Sterin,

I was focusing on simple range queries (WHERE, AND, BETWEEN...) not ORDER BY and GROUP BY queries. You are correct that those queries can cause temp tables and the SQL layer variables are important (sort_buffer, read_buffer, etc...) and may require changes for optimal performance.

Re: Sorted index pages - physically reorder on disk? [message #1655 is a reply to message #1584 ] Mon, 20 August 2007 19:14 Go to previous message
sterin  is currently offline sterin
Messages: 324
Registered: March 2007
Location: Sweden
Senior Member
OK, I read that IO was the bottleneck and didn't know if you had really boiled it down to what was consuming IO.
Since if your data changes it can be a pretty big overhead to resort it all the time.

Out of curiosity how large is the DB compared to RAM size?
Previous Topic:Difference between Falcon's and InnoDB's row level locking/MVCC
Next Topic:varchar vs char
Goto Forum:
  


Current Time: Fri Jul 10 05:43:07 EDT 2009

Total time taken to generate the page: 0.01241 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 2.7.7.
Copyright ©2001-2007 FUD Forum Bulletin Board Software

MySQL is a trademark of Sun Microsystems.
InnoDB is a trademark of Oracle Corp.

Percona Performance Forums are a service of Percona, Inc.
Not affiliated with Sun Microsystems or Oracle Corp.